UNPKG

coveo-search-ui

Version:

Coveo JavaScript Search Framework

1,066 lines (1,028 loc) • 114 kB
webpackJsonpCoveo__temporary([15,19],{ /***/ 118: /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var Component_1 = __webpack_require__(7); var ResultList_1 = __webpack_require__(93); var Dom_1 = __webpack_require__(1); var underscore_1 = __webpack_require__(0); var Logger_1 = __webpack_require__(9); var ResultListUtils = /** @class */ (function () { function ResultListUtils() { } ResultListUtils.hideIfInfiniteScrollEnabled = function (cmp) { var infiniteScrollEnabled = ResultListUtils.isInfiniteScrollEnabled(cmp.searchInterface.element); if (infiniteScrollEnabled) { cmp.disable(); Dom_1.$$(cmp.element).hide(); ResultListUtils.warnIfComponentNotNeeded(cmp); } else { cmp.enable(); Dom_1.$$(cmp.element).unhide(); } }; ResultListUtils.isInfiniteScrollEnabled = function (root) { var resultList = ResultListUtils.getMainResultList(root); return resultList ? !!resultList.options.enableInfiniteScroll : false; }; ResultListUtils.scrollToTop = function (root) { var resultList = ResultListUtils.getMainResultList(root); if (!resultList) { new Logger_1.Logger(this).warn('No active ResultList, scrolling to the top of the Window'); return window.scrollTo(0, 0); } var searchInterfacePosition = resultList.searchInterface.element.getBoundingClientRect().top; if (searchInterfacePosition > 0) { return; } window.scrollTo(0, window.pageYOffset + searchInterfacePosition); }; ResultListUtils.getMainResultList = function (root) { var resultLists = ResultListUtils.getResultLists(root); return underscore_1.find(resultLists, function (resultList) { var isRecInterface = resultList.searchInterface.element.classList.contains('CoveoRecommendation'); return !resultList.disabled && !isRecInterface; }); }; ResultListUtils.getResultLists = function (root) { return Dom_1.$$(root) .findAll("." + ResultListUtils.cssClass()) .map(function (el) { return Component_1.Component.get(el, ResultList_1.ResultList); }); }; ResultListUtils.cssClass = function () { return Component_1.Component.computeCssClassName(ResultList_1.ResultList); }; ResultListUtils.warnIfComponentNotNeeded = function (cmp) { var root = cmp.searchInterface.root; var allListsUseInfiniteScroll = ResultListUtils.allResultListsUseInfiniteScroll(root); allListsUseInfiniteScroll && ResultListUtils.notNeededComponentWarning(cmp); }; ResultListUtils.allResultListsUseInfiniteScroll = function (root) { var listsWithInfiniteScrollDisabled = ResultListUtils.getResultLists(root).filter(function (resultList) { return !resultList.options.enableInfiniteScroll; }); return listsWithInfiniteScrollDisabled.length === 0; }; ResultListUtils.notNeededComponentWarning = function (cmp) { var cmpCssClass = Component_1.Component.computeCssClassNameForType(cmp.type); var message = "The " + cmpCssClass + " component is not needed because all " + ResultListUtils.cssClass() + " components have enableInfiniteScroll set to 'true'.\n For the best performance, remove the " + cmpCssClass + " component from your search page."; new Logger_1.Logger(cmp).warn(message); }; return ResultListUtils; }()); exports.ResultListUtils = ResultListUtils; /***/ }), /***/ 215: /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var Component_1 = __webpack_require__(7); var _ = __webpack_require__(0); var ResultListRenderer = /** @class */ (function () { function ResultListRenderer(resultListOptions, autoCreateComponentsFn) { this.resultListOptions = resultListOptions; this.autoCreateComponentsFn = autoCreateComponentsFn; } ResultListRenderer.prototype.renderResults = function (resultElements, append, resultDisplayedCallback) { var _this = this; if (append === void 0) { append = false; } return Promise.all([this.getStartFragment(resultElements, append), this.getEndFragment(resultElements, append)]).then(function (_a) { var startFrag = _a[0], endFrag = _a[1]; var resultsFragment = document.createDocumentFragment(); if (startFrag) { resultsFragment.appendChild(startFrag); } _.each(resultElements, function (resultElement) { resultsFragment.appendChild(resultElement); resultDisplayedCallback(Component_1.Component.getResult(resultElement), resultElement); }); if (endFrag) { resultsFragment.appendChild(endFrag); } _this.resultListOptions.resultsContainer.appendChild(resultsFragment); }); }; ResultListRenderer.prototype.getStartFragment = function (resultElements, append) { return Promise.resolve(document.createDocumentFragment()); }; ResultListRenderer.prototype.getEndFragment = function (resultElements, append) { return Promise.resolve(document.createDocumentFragment()); }; return ResultListRenderer; }()); exports.ResultListRenderer = ResultListRenderer; /***/ }), /***/ 277: /***/ (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 }); __webpack_require__(667); var _ = __webpack_require__(0); var InitializationEvents_1 = __webpack_require__(17); var QueryEvents_1 = __webpack_require__(11); var ResultListEvents_1 = __webpack_require__(29); var GlobalExports_1 = __webpack_require__(3); var Assert_1 = __webpack_require__(5); var Model_1 = __webpack_require__(18); var QueryStateModel_1 = __webpack_require__(13); var Strings_1 = __webpack_require__(6); var AccessibleButton_1 = __webpack_require__(15); var DeviceUtils_1 = __webpack_require__(24); var Dom_1 = __webpack_require__(1); var ResultListUtils_1 = __webpack_require__(118); var AnalyticsActionListMeta_1 = __webpack_require__(10); var Component_1 = __webpack_require__(7); var ComponentOptions_1 = __webpack_require__(8); var Initialization_1 = __webpack_require__(2); var underscore_1 = __webpack_require__(0); /** * The ResultsPerPage component attaches itself to a `div` and allows the end user to choose how many results to * display per page. * * **Note:** Adding a ResultPerPage component to your page overrides the value of * {@link SearchInterface.options.resultsPerPage}. */ var ResultsPerPage = /** @class */ (function (_super) { __extends(ResultsPerPage, _super); /** * Creates a new ResultsPerPage. The component renders itself on every query success. * @param element The HTMLElement on which to instantiate the component (normally a `div`). * @param options The options for the ResultsPerPage 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). */ function ResultsPerPage(element, options, bindings) { var _this = _super.call(this, element, ResultsPerPage.ID, bindings) || this; _this.element = element; _this.options = options; _this.options = ComponentOptions_1.ComponentOptions.initComponentOptions(element, ResultsPerPage, options); _this.bind.onRootElement(InitializationEvents_1.InitializationEvents.afterInitialization, function () { return _this.resolveInitialState(); }); _this.bind.onRootElement(QueryEvents_1.QueryEvents.querySuccess, function (args) { return _this.handleQuerySuccess(args); }); _this.bind.onRootElement(QueryEvents_1.QueryEvents.queryError, function () { return _this.handleQueryError(); }); _this.bind.onRootElement(QueryEvents_1.QueryEvents.noResults, function (args) { return _this.handleNoResults(); }); _this.bind.onQueryState(Model_1.MODEL_EVENTS.CHANGE_ONE, QueryStateModel_1.QUERY_STATE_ATTRIBUTES.NUMBER_OF_RESULTS, function (args) { return _this.handleQueryStateModelChanged(args); }); _this.addAlwaysActiveListeners(); _this.initComponent(); return _this; } /** * Sets the current number of results per page, then executes a query. * * Also logs an event in the usage analytics (`pagerResize` by default) with the new current number of results per * page as meta data. * @param resultsPerPage The new number of results per page to select. * @param analyticCause The event to log in the usage analytics. */ ResultsPerPage.prototype.setResultsPerPage = function (resultsPerPage, analyticCause) { if (analyticCause === void 0) { analyticCause = AnalyticsActionListMeta_1.analyticsActionCauseList.pagerResize; } Assert_1.Assert.exists(resultsPerPage); Assert_1.Assert.check(this.isValidChoice(resultsPerPage), 'The specified number of results is not available in the options.'); this.updateResultsPerPage(resultsPerPage); this.updateQueryStateModelResultsPerPage(); this.logAnalyticsEvent(analyticCause); this.executeQuery(); }; Object.defineProperty(ResultsPerPage.prototype, "resultsPerPage", { /** * Returns the current number of results per page. */ get: function () { return this.currentResultsPerPage; }, enumerable: true, configurable: true }); ResultsPerPage.prototype.updateResultsPerPage = function (resultsPerPage) { this.queryController.options.resultsPerPage = resultsPerPage; this.searchInterface.resultsPerPage = resultsPerPage; this.currentResultsPerPage = resultsPerPage; }; ResultsPerPage.prototype.updateQueryStateModelResultsPerPage = function () { this.queryStateModel.set(QueryStateModel_1.QueryStateModel.attributesEnum.numberOfResults, this.currentResultsPerPage); }; ResultsPerPage.prototype.logAnalyticsEvent = function (analyticCause) { this.usageAnalytics.logCustomEvent(analyticCause, { currentResultsPerPage: this.currentResultsPerPage }, this.element); }; ResultsPerPage.prototype.executeQuery = function () { this.queryController.executeQuery({ ignoreWarningSearchEvent: true, keepLastSearchUid: true, origin: this }); }; ResultsPerPage.prototype.handleQueryStateModelChanged = function (args) { var valueToSet = args.value; if (!this.isValidChoice(valueToSet)) { this.logInvalidConfiguredChoiceWarning(valueToSet); this.resolveInitialState(); } else { this.updateResultsPerPage(valueToSet); } }; ResultsPerPage.prototype.addAlwaysActiveListeners = function () { var _this = this; this.searchInterface.element.addEventListener(ResultListEvents_1.ResultListEvents.newResultsDisplayed, function () { return ResultListUtils_1.ResultListUtils.hideIfInfiniteScrollEnabled(_this); }); }; ResultsPerPage.prototype.resolveInitialState = function () { this.updateResultsPerPage(this.getInitialChoice()); this.updateQueryStateModelResultsPerPage(); }; ResultsPerPage.prototype.getInitialChoice = function () { var firstDisplayedChoice = this.options.choicesDisplayed[0]; var configuredChoice = this.options.initialChoice; var queryStateModelChoice = this.queryStateModel.get(QueryStateModel_1.QueryStateModel.attributesEnum.numberOfResults); var queryStateModelChoiceIsNotDefault = queryStateModelChoice !== QueryStateModel_1.QueryStateModel.defaultAttributes.numberOfResults; if (queryStateModelChoiceIsNotDefault && this.isValidChoice(queryStateModelChoice)) { return queryStateModelChoice; } if (configuredChoice !== undefined) { if (this.isValidChoice(configuredChoice)) { return configuredChoice; } this.logInvalidConfiguredChoiceWarning(configuredChoice); } return firstDisplayedChoice; }; ResultsPerPage.prototype.isValidChoice = function (choice) { return this.options.choicesDisplayed.indexOf(choice) !== -1; }; ResultsPerPage.prototype.logInvalidConfiguredChoiceWarning = function (configuredChoice) { var validChoices = this.options.choicesDisplayed; this.logger.warn("The choice " + configuredChoice + " is not within the choices displayed. Consider setting a value that is valid: " + validChoices + ". The first choice will be selected instead."); }; ResultsPerPage.prototype.initComponent = function () { this.span = Dom_1.$$('span', { id: underscore_1.uniqueId('coveo-results-per-page-text-'), className: 'coveo-results-per-page-text' }, Strings_1.l('ResultsPerPage')).el; this.element.appendChild(this.span); this.list = Dom_1.$$('ul', { className: 'coveo-results-per-page-list', 'aria-labelledby': this.span.id }).el; this.element.appendChild(this.list); }; ResultsPerPage.prototype.render = function () { var _this = this; Dom_1.$$(this.span).removeClass('coveo-results-per-page-no-results'); var numResultsList = this.options.choicesDisplayed; var _loop_1 = function () { var listItem = Dom_1.$$('li', { className: 'coveo-results-per-page-list-item' }).el; var resultsPerPage = numResultsList[i]; var isActive = resultsPerPage === this_1.currentResultsPerPage; if (isActive) { Dom_1.$$(listItem).addClass('coveo-active'); } var clickAction = function (e) { e.stopPropagation(); _this.handleClickPage(resultsPerPage); }; var button = Dom_1.$$('span', { className: 'coveo-results-per-page-list-item-text', tabindex: 0, ariaPressed: isActive.toString() }, numResultsList[i].toString()).el; listItem.appendChild(button); listItem.addEventListener('click', function (e) { return clickAction(e); }); new AccessibleButton_1.AccessibleButton() .withElement(button) .withLabel(Strings_1.l('DisplayResultsPerPage', numResultsList[i].toString())) .withClickAction(clickAction) .withEnterKeyboardAction(clickAction) .build(); this_1.list.appendChild(listItem); }; var this_1 = this; for (var i = 0; i < numResultsList.length; i++) { _loop_1(); } }; ResultsPerPage.prototype.handleQueryError = function () { this.reset(); }; ResultsPerPage.prototype.handleNoResults = function () { this.reset(); }; ResultsPerPage.prototype.handleQuerySuccess = function (data) { if (this.searchInterface.isResultsPerPageModifiedByPipeline) { this.logger.info('Results per page was modified by backend code (query pipeline). ResultsPerPage component will be hidden', this); this.reset(); var resultsPerPage = this.getInitialChoice(); this.updateResultsPerPage(resultsPerPage); return; } if (data.results.results.length != 0) { this.reset(); this.render(); } }; ResultsPerPage.prototype.handleClickPage = function (resultsPerPage) { Assert_1.Assert.exists(resultsPerPage); this.setResultsPerPage(resultsPerPage); }; ResultsPerPage.prototype.reset = function () { Dom_1.$$(this.span).addClass('coveo-results-per-page-no-results'); Dom_1.$$(this.list).empty(); }; ResultsPerPage.ID = 'ResultsPerPage'; ResultsPerPage.doExport = function () { GlobalExports_1.exportGlobally({ ResultsPerPage: ResultsPerPage }); }; /** * The options for the ResultsPerPage * @componentOptions */ ResultsPerPage.options = { /** * Specifies the possible values of number of results to display per page that the end user can select from. * * See also {@link ResultsPerPage.options.initialChoice}. * * Default value is `[10, 25, 50, 100]`. */ choicesDisplayed: ComponentOptions_1.ComponentOptions.buildCustomListOption(function (list) { var values = _.map(list, function (value) { return parseInt(value, 10); }); return values.length == 0 ? null : values; }, { defaultFunction: function () { if (DeviceUtils_1.DeviceUtils.isMobileDevice()) { return [10, 25, 50]; } else { return [10, 25, 50, 100]; } } }), /** * Specifies the value to select by default for the number of results to display per page. * * Default value is the first value of {@link ResultsPerPage.options.choicesDisplayed}. */ initialChoice: ComponentOptions_1.ComponentOptions.buildNumberOption() }; return ResultsPerPage; }(Component_1.Component)); exports.ResultsPerPage = ResultsPerPage; Initialization_1.Initialization.registerAutoCreateComponent(ResultsPerPage); /***/ }), /***/ 40: /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /// <reference path='Facet.ts' /> var StringUtils_1 = __webpack_require__(22); var QueryUtils_1 = __webpack_require__(21); var FileTypes_1 = __webpack_require__(121); var DateUtils_1 = __webpack_require__(33); var Utils_1 = __webpack_require__(4); var Dom_1 = __webpack_require__(1); var _ = __webpack_require__(0); var Strings_1 = __webpack_require__(6); var FacetUtils = /** @class */ (function () { function FacetUtils() { } FacetUtils.getRegexToUseForFacetSearch = function (value, ignoreAccent) { return new RegExp(StringUtils_1.StringUtils.stringToRegex(value, ignoreAccent), 'i'); }; FacetUtils.getDisplayValueFromValueCaption = function (value, field, valueCaption) { var returnValue = this.tryToGetTranslatedCaption(field, value, false); return valueCaption[value] || returnValue; }; FacetUtils.getValuesToUseForSearchInFacet = function (original, facet) { var ret = [original]; var regex = this.getRegexToUseForFacetSearch(original, facet.options.facetSearchIgnoreAccents); if (facet.options.valueCaption) { _.chain(facet.options.valueCaption) .pairs() .filter(function (pair) { return regex.test(pair[1]); }) .each(function (match) { ret.push(match[0]); }); if (QueryUtils_1.QueryUtils.isStratusAgnosticField(facet.options.field, '@objecttype') || QueryUtils_1.QueryUtils.isStratusAgnosticField(facet.options.field, '@filetype')) { _.each(FileTypes_1.FileTypes.getFileTypeCaptions(), function (value, key) { if (!(key in facet.options.valueCaption) && regex.test(value)) { ret.push(key); } }); } } else if (QueryUtils_1.QueryUtils.isStratusAgnosticField(facet.options.field, '@objecttype') || QueryUtils_1.QueryUtils.isStratusAgnosticField(facet.options.field, '@filetype')) { _.each(_.filter(_.pairs(FileTypes_1.FileTypes.getFileTypeCaptions()), function (pair) { return regex.test(pair[1]); }), function (match) { ret.push(match[0]); }); } else if (QueryUtils_1.QueryUtils.isStratusAgnosticField(facet.options.field, '@month')) { _.each(_.range(1, 13), function (month) { if (regex.test(DateUtils_1.DateUtils.monthToString(month - 1))) { ret.push(('0' + month.toString()).substr(-2)); } }); } return ret; }; FacetUtils.buildFacetSearchPattern = function (values) { values = _.map(values, function (value) { return Utils_1.Utils.escapeRegexCharacter(value); }); values[0] = '.*' + values[0] + '.*'; return values.join('|'); }; FacetUtils.needAnotherFacetSearch = function (currentSearchLength, newSearchLength, oldSearchLength, desiredSearchLength) { // Something was removed (currentSearch < newSearch) // && we might want to display more facet search result(currentSearch < desiredSearch) // && the new query returned more stuff than the old one so there's still more results(currentSearchLength > oldLength) return currentSearchLength < newSearchLength && currentSearchLength < desiredSearchLength && currentSearchLength > oldSearchLength; }; FacetUtils.addNoStateCssClassToFacetValues = function (facet, container) { // This takes care of adding the correct css class on each facet value checkbox (empty white box) if at least one value is selected in that facet if (facet.values.getSelected().length != 0) { var noStates = Dom_1.$$(container).findAll('li:not(.coveo-selected)'); _.each(noStates, function (noState) { Dom_1.$$(noState).addClass('coveo-no-state'); }); } }; FacetUtils.tryToGetTranslatedCaption = function (field, value, fallbackOnLocalization) { if (fallbackOnLocalization === void 0) { fallbackOnLocalization = true; } var found; if (QueryUtils_1.QueryUtils.isStratusAgnosticField(field.toLowerCase(), '@filetype')) { found = FileTypes_1.FileTypes.getFileType(value, fallbackOnLocalization).caption; } else if (QueryUtils_1.QueryUtils.isStratusAgnosticField(field.toLowerCase(), '@objecttype')) { found = FileTypes_1.FileTypes.getObjectType(value, fallbackOnLocalization).caption; } else if (FacetUtils.isMonthFieldValue(field, value)) { var month = parseInt(value, 10); found = DateUtils_1.DateUtils.monthToString(month - 1); } else if (fallbackOnLocalization) { found = Strings_1.l(value); } return found != undefined && Utils_1.Utils.isNonEmptyString(found) ? found : value; }; FacetUtils.isMonthFieldValue = function (field, value) { if (!QueryUtils_1.QueryUtils.isStratusAgnosticField(field.toLowerCase(), '@month')) { return false; } var asInt = parseInt(value, 10); if (isNaN(asInt)) { return false; } if (asInt < 1 || asInt > 12) { return false; } return true; }; return FacetUtils; }()); exports.FacetUtils = FacetUtils; /***/ }), /***/ 470: /***/ (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 Template_1 = __webpack_require__(27); var TemplateList_1 = __webpack_require__(96); var _ = __webpack_require__(0); var TableTemplate = /** @class */ (function (_super) { __extends(TableTemplate, _super); function TableTemplate() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.defaultTemplate = "<td><a class=\"CoveoResultLink\"></a></td>\n <td><span class=\"CoveoExcerpt\"></span></td>\n <td><span class=\"CoveoFieldValue\" data-field=\"@date\" data-helper=\"date\"></span></td>"; _this.defaultRoledTemplates = { 'table-header': "<th style=\"width: 40%\">Link</th>\n <th>Excerpt</th>\n <th style=\"width: 20%\"\n class=\"CoveoSort coveo-table-header-sort\"\n data-sort-criteria=\"date ascending,date descending\"\n data-display-unselected-icon=\"false\">Date</th>", 'table-footer': "<th>Link</th>\n <th>Excerpt</th>\n <th>Date</th>" }; return _this; } TableTemplate.prototype.instantiateRoleToString = function (role) { var roledTemplate = _.find(this.templates, function (t) { return t.role === role; }); if (roledTemplate) { return roledTemplate.instantiateToString(undefined, {}); } else { return this.defaultRoledTemplates[role]; } }; TableTemplate.prototype.instantiateRoleToElement = function (role) { var _this = this; var roledTemplate = _.find(this.templates, function (t) { return t.role === role; }); if (roledTemplate) { return roledTemplate.instantiateToElement(undefined, {}); } else { var tmpl = new Template_1.Template(function () { return _this.defaultRoledTemplates[role]; }); tmpl.layout = 'table'; return tmpl.instantiateToElement(undefined); } }; TableTemplate.prototype.getFallbackTemplate = function () { var _this = this; return new Template_1.Template(function () { return _this.defaultTemplate; }); }; TableTemplate.prototype.hasTemplateWithRole = function (role) { return _.find(this.templates, function (t) { return t.role === role; }); }; return TableTemplate; }(TemplateList_1.TemplateList)); exports.TableTemplate = TableTemplate; /***/ }), /***/ 472: /***/ (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 Template_1 = __webpack_require__(27); var DefaultRecommendationTemplate = /** @class */ (function (_super) { __extends(DefaultRecommendationTemplate, _super); function DefaultRecommendationTemplate() { return _super !== null && _super.apply(this, arguments) || this; } DefaultRecommendationTemplate.prototype.instantiateToString = function (object) { var template = "<div class=\"coveo-result-frame\">\n <div class=\"coveo-result-row\">\n <div class=\"coveo-result-cell\" style=\"width:40px;text-align:center;vertical-align:middle;\">\n <span class=\"CoveoIcon\" data-small=\"true\" data-with-label=\"false\">\n </span>\n </div>\n <div class=\"coveo-result-cell\" style=\"padding:0 0 3px 5px;vertical-align:middle\">\n <div class=\"coveo-result-row\">\n <div class=\"coveo-result-cell\" style=\"font-size:10pt;\">\n <a class=\"CoveoResultLink\" style=\"display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis\">\n </a>\n </div>\n </div>\n </div>\n </div>\n </div>"; return template; }; DefaultRecommendationTemplate.prototype.instantiateToElement = function (object) { var _this = this; return new Promise(function (resolve, reject) { var div = document.createElement('div'); div.innerHTML = _this.instantiateToString(object); resolve(div); }); }; return DefaultRecommendationTemplate; }(Template_1.Template)); exports.DefaultRecommendationTemplate = DefaultRecommendationTemplate; /***/ }), /***/ 473: /***/ (function(module, exports, __webpack_require__) { "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [0, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); var Core_1 = __webpack_require__(20); var ResultList_1 = __webpack_require__(93); var underscore_1 = __webpack_require__(0); var Dom_1 = __webpack_require__(1); var Logger_1 = __webpack_require__(9); var TemplateToHtml = /** @class */ (function () { function TemplateToHtml(args) { this.args = args; } TemplateToHtml.prototype.buildResults = function (results, layout, currentlyDisplayedResults) { return __awaiter(this, void 0, void 0, function () { var _this = this; var res, resultsPromises; return __generator(this, function (_a) { res = []; resultsPromises = underscore_1.map(results.results, function (result, index) { return _this.buildResult(result, layout, currentlyDisplayedResults).then(function (resultElement) { if (resultElement != null) { res.push({ elem: resultElement, idx: index }); } ResultList_1.ResultList.resultCurrentlyBeingRendered = null; return resultElement; }); }); // We need to sort by the original index order, because in lazy loading mode, it's possible that results does not gets rendered // in the correct order returned by the index, depending on the time it takes to load all the results component for a given result template return [2 /*return*/, Promise.all(resultsPromises).then(function () { return underscore_1.pluck(underscore_1.sortBy(res, 'idx'), 'elem'); })]; }); }); }; TemplateToHtml.prototype.buildResult = function (result, layout, currentlyDisplayedResults) { return __awaiter(this, void 0, void 0, function () { var resultElement; return __generator(this, function (_a) { switch (_a.label) { case 0: Core_1.Assert.exists(result); Core_1.QueryUtils.setStateObjectOnQueryResult(this.args.queryStateModel.get(), result); Core_1.QueryUtils.setSearchInterfaceObjectOnQueryResult(this.args.searchInterface, result); ResultList_1.ResultList.resultCurrentlyBeingRendered = result; return [4 /*yield*/, this.createHtmlElement(result, layout)]; case 1: resultElement = _a.sent(); if (resultElement != null) { Core_1.Component.bindResultToElement(resultElement, result); } currentlyDisplayedResults.push(result); return [4 /*yield*/, this.autoCreateComponentsInsideResult(resultElement, result).initResult]; case 2: _a.sent(); this.verifyChildren(resultElement); return [2 /*return*/, resultElement]; } }); }); }; TemplateToHtml.prototype.autoCreateComponentsInsideResult = function (element, result) { Core_1.Assert.exists(element); return Core_1.Initialization.automaticallyCreateComponentsInsideResult(element, result); }; TemplateToHtml.prototype.createHtmlElement = function (result, layout) { return this.args.resultTemplate.instantiateToElement(result, { wrapInDiv: true, checkCondition: true, currentLayout: layout, responsiveComponents: this.args.searchInterface.responsiveComponents }); }; TemplateToHtml.prototype.verifyChildren = function (element) { var containsResultLink = !!Dom_1.$$(element).find('.CoveoResultLink'); if (containsResultLink) { return; } var msg = "Result does not contain a \"CoveoResultLink\" component, please verify the result template"; new Logger_1.Logger(element).warn(msg, this.args.resultTemplate); }; return TemplateToHtml; }()); exports.TemplateToHtml = TemplateToHtml; /***/ }), /***/ 474: /***/ (function(module, exports, __webpack_require__) { "use strict"; var __assign = (this && this.__assign) || Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); var TemplateHelpers_1 = __webpack_require__(122); var HighlightUtils_1 = __webpack_require__(69); var DateUtils_1 = __webpack_require__(33); var CurrencyUtils_1 = __webpack_require__(135); var HtmlUtils_1 = __webpack_require__(179); var Utils_1 = __webpack_require__(4); var StringUtils_1 = __webpack_require__(22); var TimeSpanUtils_1 = __webpack_require__(73); var EmailUtils_1 = __webpack_require__(178); var QueryUtils_1 = __webpack_require__(21); var DeviceUtils_1 = __webpack_require__(24); var Dom_1 = __webpack_require__(1); var SearchEndpoint_1 = __webpack_require__(53); var StreamHighlightUtils_1 = __webpack_require__(120); var FacetUtils_1 = __webpack_require__(40); var Globalize = __webpack_require__(23); var _ = __webpack_require__(0); var Component_1 = __webpack_require__(7); var TemplateCache_1 = __webpack_require__(68); var CoreHelpers = /** @class */ (function () { function CoreHelpers() { } /** * For backward compatibility reason, the "global" template helper should be available under the * coveo namespace. * @param scope */ CoreHelpers.exportAllHelpersGlobally = function (scope) { _.each(TemplateHelpers_1.TemplateHelpers.getHelpers(), function (helper, name) { if (scope[name] == undefined) { scope[name] = helper; } }); }; return CoreHelpers; }()); exports.CoreHelpers = CoreHelpers; TemplateHelpers_1.TemplateHelpers.registerFieldHelper('javascriptEncode', function (value) { return Utils_1.Utils.exists(value) ? StringUtils_1.StringUtils.javascriptEncode(value) : undefined; }); var executeShorten = function (content, options) { var strAndHoles = HighlightUtils_1.StringAndHoles.shortenString(content, options.length, '...'); if (Utils_1.Utils.exists(options.highlights)) { return HighlightUtils_1.HighlightUtils.highlightString(strAndHoles.value, options.highlights, strAndHoles.holes, options.cssClass || 'highlight'); } else { return strAndHoles.value; } }; TemplateHelpers_1.TemplateHelpers.registerTemplateHelper('shorten', function (content, length, highlights, cssClass) { return executeShorten(content, { length: length, highlights: highlights, cssClass: cssClass }); }); TemplateHelpers_1.TemplateHelpers.registerTemplateHelper('shortenv2', function (content, options) { return executeShorten(content, options); }); var executeShortenPath = function (content, options) { var strAndHoles = HighlightUtils_1.StringAndHoles.shortenPath(content, options.length); if (Utils_1.Utils.exists(options.highlights)) { return HighlightUtils_1.HighlightUtils.highlightString(strAndHoles.value, options.highlights, strAndHoles.holes, options.cssClass || 'highlight'); } else { return strAndHoles.value; } }; TemplateHelpers_1.TemplateHelpers.registerTemplateHelper('shortenPath', function (content, length, highlights, cssClass) { return executeShortenPath(content, { length: length, highlights: highlights, cssClass: cssClass }); }); TemplateHelpers_1.TemplateHelpers.registerFieldHelper('shortenPathv2', function (content, options) { return executeShortenPath(content, options); }); var executeShortenUri = function (content, options) { var strAndHoles = HighlightUtils_1.StringAndHoles.shortenUri(content, options.length); if (Utils_1.Utils.exists(options.highlights)) { return HighlightUtils_1.HighlightUtils.highlightString(strAndHoles.value, options.highlights, strAndHoles.holes, options.cssClass || 'highlight'); } else { return strAndHoles.value; } }; TemplateHelpers_1.TemplateHelpers.registerTemplateHelper('shortenUri', function (content, length, highlights, cssClass) { return executeShortenUri(content, { length: length, highlights: highlights, cssClass: cssClass }); }); TemplateHelpers_1.TemplateHelpers.registerTemplateHelper('shortenUriv2', function (content, options) { return executeShortenUri(content, options); }); var executeHighlight = function (content, options) { if (Utils_1.Utils.exists(content)) { if (Utils_1.Utils.exists(options.highlights)) { return HighlightUtils_1.HighlightUtils.highlightString(content, options.highlights, null, options.cssClass || 'highlight'); } else { return content; } } else { return undefined; } }; TemplateHelpers_1.TemplateHelpers.registerTemplateHelper('highlight', function (content, highlights, cssClass) { return executeHighlight(content, { highlights: highlights, cssClass: cssClass }); }); TemplateHelpers_1.TemplateHelpers.registerTemplateHelper('highlightv2', function (content, options) { return executeHighlight(content, options); }); var executeHighlightStreamText = function (content, options) { if (Utils_1.Utils.exists(content) && Utils_1.Utils.exists(options.termsToHighlight) && Utils_1.Utils.exists(options.phrasesToHighlight)) { if (termsToHighlightAreDefined(options.termsToHighlight, options.phrasesToHighlight)) { return StreamHighlightUtils_1.StreamHighlightUtils.highlightStreamText(content, options.termsToHighlight, options.phrasesToHighlight, options.opts); } else { return content; } } else { return undefined; } }; TemplateHelpers_1.TemplateHelpers.registerTemplateHelper('highlightStreamText', function (content, termsToHighlight, phrasesToHighlight, opts) { if (termsToHighlight === void 0) { termsToHighlight = resolveTermsToHighlight(); } if (phrasesToHighlight === void 0) { phrasesToHighlight = resolvePhrasesToHighlight(); } return executeHighlightStreamText(content, { termsToHighlight: termsToHighlight, phrasesToHighlight: phrasesToHighlight, opts: opts }); }); TemplateHelpers_1.TemplateHelpers.registerTemplateHelper('highlightStreamTextv2', function (content, options) { var mergedOptions = __assign({ termsToHighlight: resolveTermsToHighlight(), phrasesToHighlight: resolvePhrasesToHighlight() }, options); return executeHighlightStreamText(content, mergedOptions); }); var executeHighlightStreamHTML = function (content, options) { if (Utils_1.Utils.exists(content) && Utils_1.Utils.exists(options.termsToHighlight) && Utils_1.Utils.exists(options.phrasesToHighlight)) { if (termsToHighlightAreDefined(options.termsToHighlight, options.phrasesToHighlight)) { return StreamHighlightUtils_1.StreamHighlightUtils.highlightStreamHTML(content, options.termsToHighlight, options.phrasesToHighlight, options.opts); } else { return content; } } else { return undefined; } }; TemplateHelpers_1.TemplateHelpers.registerTemplateHelper('highlightStreamHTML', function (content, termsToHighlight, phrasesToHighlight, opts) { if (termsToHighlight === void 0) { termsToHighlight = resolveTermsToHighlight(); } if (phrasesToHighlight === void 0) { phrasesToHighlight = resolvePhrasesToHighlight(); } return executeHighlightStreamHTML(content, { termsToHighlight: termsToHighlight, phrasesToHighlight: phrasesToHighlight, opts: opts }); }); TemplateHelpers_1.TemplateHelpers.registerTemplateHelper('highlightStreamHTMLv2', function (content, options) { var mergedOptions = __assign({ termsToHighlight: resolveTermsToHighlight(), phrasesToHighlight: resolvePhrasesToHighlight() }, options); return executeHighlightStreamHTML(content, mergedOptions); }); TemplateHelpers_1.TemplateHelpers.registerFieldHelper('number', function (value, options) { if (!Utils_1.Utils.exists(value)) { return undefined; } var numberValue = Number(value); var format = _.isString(options) ? options : options && options.format; if (!format) { return StringUtils_1.StringUtils.htmlEncode(numberValue.toString()); } return StringUtils_1.StringUtils.htmlEncode(Globalize.format(numberValue, format)); }); TemplateHelpers_1.TemplateHelpers.registerFieldHelper('date', function (value, options) { return DateUtils_1.DateUtils.dateToString(DateUtils_1.DateUtils.convertFromJsonDateIfNeeded(value), options); }); TemplateHelpers_1.TemplateHelpers.registerFieldHelper('time', function (value, options) { return DateUtils_1.DateUtils.timeToString(DateUtils_1.DateUtils.convertFromJsonDateIfNeeded(value), options); }); TemplateHelpers_1.TemplateHelpers.registerFieldHelper('dateTime', function (value, options) { return DateUtils_1.DateUtils.dateTimeToString(DateUtils_1.DateUtils.convertFromJsonDateIfNeeded(value), options); }); TemplateHelpers_1.TemplateHelpers.registerFieldHelper('emailDateTime', function (value, options) { var defaultOptions = {}; defaultOptions.includeTimeIfThisWeek = true; var optionsToUse = _.extend(options, defaultOptions); return value ? DateUtils_1.DateUtils.dateTimeToString(DateUtils_1.DateUtils.convertFromJsonDateIfNeeded(value), optionsToUse) : undefined; }); TemplateHelpers_1.TemplateHelpers.registerFieldHelper('currency', function (value, options) { return CurrencyUtils_1.CurrencyUtils.currencyToString(value, options); }); TemplateHelpers_1.TemplateHelpers.registerFieldHelper('timeSpan', function (value, options) { if (options === void 0) { options = { isMilliseconds: false }; } return new TimeSpanUtils_1.TimeSpan(value, options.isMilliseconds).getHHMMSS(); }); TemplateHelpers_1.TemplateHelpers.registerFieldHelper('email', function (value) { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } // support old arguments (value: any, companyDomain: string, me: string, lengthLimit = 2, truncateName = false) var companyDomain; var me; var lengthLimit; var truncateName; if (_.isObject(args[0])) { companyDomain = args[0]['companyDomain']; me = args[0]['me']; lengthLimit = args[0]['lengthLimit']; truncateName = args[0]['truncateName']; } else { companyDomain = args[0]; me = args[1]; lengthLimit = args[2]; truncateName = args[3]; } if (lengthLimit == undefined) { lengthLimit = 2; } if (truncateName == undefined) { truncateName = false; } if (_.isString(value)) { var listOfAddresses = EmailUtils_1.EmailUtils.splitSemicolonSeparatedListOfEmailAddresses(value); return EmailUtils_1.EmailUtils.emailAddressesToHyperlinks(listOfAddresses, companyDomain, me, lengthLimit, truncateName); } else if (_.isArray(value)) { return EmailUtils_1.EmailUtils.emailAddressesToHyperlinks(value, companyDomain, me, lengthLimit, truncateName); } else { return undefined; } }); TemplateHelpers_1.TemplateHelpers.registerTemplateHelper('excessEmailToggle', function (target) { Dom_1.$$(target).removeClass('coveo-active'); if (Dom_1.$$(target).hasClass('coveo-emails-excess-collapsed')) { _.each(Dom_1.$$(target).siblings('.coveo-emails-excess-expanded'), function (sibling) { Dom_1.$$(sibling).addClass('coveo-active'); }); } else if (Dom_1.$$(target).hasClass('coveo-hide-expanded')) { Dom_1.$$(target.parentElement).addClass('coveo-inactive'); _.each(Dom_1.$$(target.parentElement).siblings('.coveo-emails-excess-collapsed'), function (sibling) { Dom_1.$$(sibling).addClass('coveo-active'); }); } return undefined; }); TemplateHelpers_1.TemplateHelpers.registerFieldHelper('anchor', function (href, options) { return HtmlUtils_1.AnchorUtils.buildAnchor(href, options); }); TemplateHelpers_1.TemplateHelpers.registerFieldHelper('image', function (src, options, result) { if (result === void 0) { result = resolveQueryResult(); } if (options && options.srcTemplate) { return HtmlUtils_1.ImageUtils.buildImage(StringUtils_1.StringUtils.buildStringTemplateFromResult(options.srcTemplate, result), { alt: options.alt, height: options.height, width: options.width }); } return HtmlUtils_1.ImageUtils.buildImage(src, options); }); TemplateHelpers_1.TemplateHelpers.registerTemplateHelper('thumbnail', function (result, endpoint, options) { if (result === void 0) { result = resolveQueryResult(); } if (endpoint === void 0) { endpoint = 'default'; } if (QueryUtils_1.QueryUtils.hasThumbnail(result)) { return HtmlUtils_1.ImageUtils.buildImageFromResult(result, SearchEndpoint_1.SearchEndpoint.endpoints[endpoint], options); } }); TemplateHelpers_1.TemplateHelpers.registerTemplateHelper('fromFileTypeToIcon', function (result, options) { if (result === void 0) { result = resolveQueryResult(); } if (options === void 0) { options = {}; } var icon = Component_1.Component.getComponentRef('Icon'); if (icon) { return icon.createIcon(result, options).outerHTML; } }); TemplateHelpers_1.TemplateHelpers.registerTemplateHelper('attrEncode', function (value) { return ('' + value) /* Forces the conversion to string. */ .replace(/&/g, '&amp;') /* This MUST be the 1st replacement. */ .replace(/'/g, '&apos;') /* The 4 other predefined entities, required. */ .replace(/'/g, '&quot;') .replac