UNPKG

coveo-search-ui

Version:

Coveo JavaScript Search Framework

184 lines (175 loc) • 8 kB
webpackJsonpCoveo__temporary([59],{ /***/ 288: /***/ (function(module, exports, __webpack_require__) { "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var Component_1 = __webpack_require__(7); var ComponentOptions_1 = __webpack_require__(8); var Assert_1 = __webpack_require__(5); var QueryEvents_1 = __webpack_require__(11); var Dom_1 = __webpack_require__(1); var AnalyticsActionListMeta_1 = __webpack_require__(10); var QueryStateModel_1 = __webpack_require__(13); var Initialization_1 = __webpack_require__(2); var underscore_1 = __webpack_require__(0); var GlobalExports_1 = __webpack_require__(3); __webpack_require__(679); var UtilsModules_1 = __webpack_require__(74); function isTriggerNotify(trigger) { return trigger.type === 'notify'; } function isTriggerRedirect(trigger) { return trigger.type === 'redirect'; } function isTriggerQuery(trigger) { return trigger.type === 'query'; } function isTriggerExecute(trigger) { return trigger.type === 'execute'; } /** * The Triggers component enables the use of triggers (`notify`, `execute`, `query`, `redirect`) generated by the Coveo * Search API (see [Trigger](https://docs.coveo.com/en/1458/)) in the query pipeline (see * [Managing the Query Pipeline](https://docs.coveo.com/en/1450/)). * * To enable the triggers functionality in your JavaScript Search Framework interface, incorporate a div with the `coveoTriggers` class. For example: `<div class="coveoTriggers"></div>`. * * Note: adding the Triggers component gives query pipeline administrators the power to influence users' search experience. * Bad actors will be able to perform XSS attacks, or redirect users to dangerous sites. Make sure only individuals you trust * have query pipeline edit privileges. */ var Triggers = /** @class */ (function (_super) { __extends(Triggers, _super); /** * Creates a new Triggers component. * @param element The HTMLElement on which to instantiate the component. * @param options The options for the Triggers component. * @param bindings The bindings that the component requires to function normally. If not set, these will be * automatically resolved (with a slower execution time). * @param _window The window on which to execute the triggers. */ function Triggers(element, options, bindings, _window) { var _this = _super.call(this, element, Triggers.ID, bindings) || this; _this.element = element; _this.options = options; _this.bindings = bindings; _this._window = _window; _this._window = _this._window || window; _this.options = ComponentOptions_1.ComponentOptions.initComponentOptions(element, Triggers, options); Assert_1.Assert.exists(element); Assert_1.Assert.exists(_this.options); _this.notifications = []; _this.bind.onRootElement(QueryEvents_1.QueryEvents.querySuccess, _this.handleProcessNewQueryResults); return _this; } Triggers.prototype.handleProcessNewQueryResults = function (data) { Assert_1.Assert.exists(data); Assert_1.Assert.exists(data.results); Dom_1.$$(this.element).empty(); this.notifications = []; if (UtilsModules_1.Utils.isNullOrUndefined(data.results.triggers)) { Dom_1.$$(this.element).removeClass('coveo-visible'); return; } var notifyTriggers = []; var redirectTrigger = null; var queryTrigger = null; var executeTrigger = null; data.results.triggers.forEach(function (trigger) { if (isTriggerNotify(trigger)) { notifyTriggers.push(trigger); } else if (isTriggerRedirect(trigger)) { redirectTrigger = redirectTrigger || trigger; } else if (isTriggerQuery(trigger)) { queryTrigger = queryTrigger || trigger; } else if (isTriggerExecute(trigger)) { executeTrigger = executeTrigger || trigger; } }); if (notifyTriggers.length) { this.processNotifyTriggers(notifyTriggers); Dom_1.$$(this.element).addClass('coveo-visible'); } redirectTrigger && this.processRedirectTrigger(redirectTrigger); queryTrigger && this.processQueryTrigger(queryTrigger); executeTrigger && this.processExecuteTrigger(executeTrigger, data.query); }; Triggers.prototype.processNotifyTriggers = function (triggers) { var _this = this; this.usageAnalytics.logCustomEvent(AnalyticsActionListMeta_1.analyticsActionCauseList.triggerNotify, { notifications: triggers.map(function (trigger) { return trigger.content; }) }, this.element); triggers.forEach(function (trigger) { _this.notifications.push(trigger.content); _this.element.appendChild(Dom_1.$$('div', { className: 'coveo-trigger-notify' }, trigger.content).el); }); }; Triggers.prototype.processRedirectTrigger = function (trigger) { this.usageAnalytics.logCustomEvent(AnalyticsActionListMeta_1.analyticsActionCauseList.triggerRedirect, { redirectedTo: trigger.content }, this.element); this._window.location.replace(trigger.content); }; Triggers.prototype.processQueryTrigger = function (trigger) { var _this = this; this.queryStateModel.set(QueryStateModel_1.QueryStateModel.attributesEnum.q, trigger.content); this.queryController.executeQuery({ beforeExecuteQuery: function () { _this.usageAnalytics.logCustomEvent(AnalyticsActionListMeta_1.analyticsActionCauseList.triggerQuery, { query: trigger.content }, _this.element); } }); }; Triggers.prototype.processExecuteTrigger = function (trigger, query) { try { var func = this._window['' + trigger.content.name]; if (typeof func === 'function') { var params = underscore_1.object(underscore_1.map(trigger.content.params, function (value, index) { return ['param' + (index + 1), value]; })); params['element'] = this.element; this.usageAnalytics.logCustomEvent(AnalyticsActionListMeta_1.analyticsActionCauseList.triggerExecute, { executions: [{ functionName: trigger.content.name, params: trigger.content.params }] }, this.element); func.apply(this._window, [params]); } else { this.logger.error("A trigger tried to call the function '" + trigger.content.name + "', which doesn't exist.", this, query, trigger); } } catch (error) { this.logger.error("A trigger called the function '" + trigger.content.name + "', which threw an error.", this, query, trigger); } }; Triggers.ID = 'Triggers'; Triggers.options = {}; Triggers.doExport = function () { GlobalExports_1.exportGlobally({ Triggers: Triggers }); }; return Triggers; }(Component_1.Component)); exports.Triggers = Triggers; Initialization_1.Initialization.registerAutoCreateComponent(Triggers); /***/ }), /***/ 679: /***/ (function(module, exports) { // removed by extract-text-webpack-plugin /***/ }) }); //# sourceMappingURL=Triggers__65d8de8a9f769489e2ff.js.map