{"version":3,"sources":["PromotedResultsBadge.min__d67acfe80778de2e04cc.js","./src/ui/PromotedResultsBadge/PromotedResultsBadge.ts"],"names":["webpackJsonpCoveo__temporary","290","module","exports","__webpack_require__","__extends","this","extendStatics","Object","setPrototypeOf","__proto__","Array","d","b","p","hasOwnProperty","__","constructor","prototype","create","defineProperty","value","element","options","bindings","PromotedResultsBadge","ID","ComponentOptions","initComponentOptions","bind","onRootElement","ResultListEvents","newResultDisplayed","args","badge","buildBadge","result","item","appendBadge","_this","resultElement","shouldShowABadge","$$","className","getClassName","applyTagline","applyColor","isCardLayout","addBadgeToCardLayout","prepend","el","container","parentElement","insertBefore","append","isFeatured","colorForFeaturedResults","style","backgroundColor","isRecommended","colorForRecommendedResults","showBadgeForFeaturedResults","text","captionForFeatured","showBadgeForRecommendedResults","captionForRecommended","isTopResult","isRecommendation","isTableLayout","hasClass","doExport","exportGlobally","buildBooleanOption","defaultValue","buildLocalizedStringOption","localizedString","l","depend","buildColorOption","Component","Initialization","registerAutoCreateComponent","680"],"mappings":"AAAAA,8BAA8B,KAExBC,IACA,SAAUC,EAAQC,EAASC,GAEjC,YAEA,IAAIC,GAAaC,MAAQA,KAAKD,WAAc,WACxC,GAAIE,GAAgBC,OAAOC,iBACpBC,uBAA2BC,QAAS,SAAUC,EAAGC,GAAKD,EAAEF,UAAYG,IACvE,SAAUD,EAAGC,GAAK,IAAK,GAAIC,KAAKD,GAAOA,EAAEE,eAAeD,KAAIF,EAAEE,GAAKD,EAAEC,IACzE,OAAO,UAAUF,EAAGC,GAEhB,QAASG,KAAOV,KAAKW,YAAcL,EADnCL,EAAcK,EAAGC,GAEjBD,EAAEM,UAAkB,OAANL,EAAaL,OAAOW,OAAON,IAAMG,EAAGE,UAAYL,EAAEK,UAAW,GAAIF,OAGvFR,QAAOY,eAAejB,EAAS,cAAgBkB,OAAO,ICjBtD,MACA,aAEA,OAEA,OAsBA,cA4EE,WAAmBC,EAA6BC,EAA8CC,GAA9F,MACE,YAAMF,EA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,GAAAtD,uBAqLb,EAAAuD,eAAeC,4BAA4BxD,IDXrCyD,IACA,SAAUhF,EAAQC","file":"PromotedResultsBadge.min__d67acfe80778de2e04cc.js","sourcesContent":["webpackJsonpCoveo__temporary([68],{\n\n/***/ 290:\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\nvar __extends = (this && this.__extends) || (function () {\n    var extendStatics = Object.setPrototypeOf ||\n        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n    return function (d, b) {\n        extendStatics(d, b);\n        function __() { this.constructor = d; }\n        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n    };\n})();\nObject.defineProperty(exports, \"__esModule\", { value: true });\n__webpack_require__(680);\nvar Core_1 = __webpack_require__(20);\nvar GlobalExports_1 = __webpack_require__(3);\nvar Component_1 = __webpack_require__(7);\n/**\n * Depending on its configuration, this component will render badges on query result items whose ranking scores were increased by [featured results](https://docs.coveo.com/en/1961/) query pipeline rules and/or [Coveo ML ART](https://docs.coveo.com/en/1671/#automatic-relevance-tuning-art-feature).\n *\n * This component can be put anywhere in the markup configuration of a search interface. However, it is meant to be initialized only once, and should thus never be included in a result template.\n *\n * @externaldocs [Adding Promoted Results Badges](https://docs.coveo.com/en/3123/)\n * @availablesince [July 2018 Release (v2.4382.10)](https://docs.coveo.com/en/1360/)\n */\nvar PromotedResultsBadge = /** @class */ (function (_super) {\n    __extends(PromotedResultsBadge, _super);\n    function PromotedResultsBadge(element, options, bindings) {\n        var _this = _super.call(this, element, PromotedResultsBadge.ID, bindings) || this;\n        _this.element = element;\n        _this.options = options;\n        _this.bindings = bindings;\n        _this.options = Core_1.ComponentOptions.initComponentOptions(element, PromotedResultsBadge, options);\n        _this.bind.onRootElement(Core_1.ResultListEvents.newResultDisplayed, function (args) {\n            var badge = _this.buildBadge(args.result, args.item);\n            if (badge) {\n                _this.appendBadge(badge, args.item);\n            }\n        });\n        return _this;\n    }\n    PromotedResultsBadge.prototype.buildBadge = function (result, resultElement) {\n        if (!this.shouldShowABadge(result, resultElement)) {\n            return null;\n        }\n        var badge = Core_1.$$('div', {\n            className: this.getClassName(result)\n        });\n        this.applyTagline(result, badge);\n        this.applyColor(result, badge);\n        return badge;\n    };\n    PromotedResultsBadge.prototype.appendBadge = function (badge, resultElement) {\n        if (this.isCardLayout(resultElement)) {\n            this.addBadgeToCardLayout(badge, resultElement);\n        }\n        else {\n            Core_1.$$(resultElement).prepend(badge.el);\n        }\n    };\n    PromotedResultsBadge.prototype.addBadgeToCardLayout = function (badge, resultElement) {\n        var container;\n        if (resultElement.parentElement == null) {\n            container = Core_1.$$('div', {\n                className: 'coveo-promoted-result-badge-container-card-layout'\n            });\n            container.insertBefore(resultElement);\n        }\n        else {\n            container = Core_1.$$(resultElement.parentElement);\n        }\n        container.append(badge.el);\n        container.append(resultElement);\n    };\n    PromotedResultsBadge.prototype.applyColor = function (result, badge) {\n        if (this.isFeatured(result) && this.options.colorForFeaturedResults) {\n            badge.el.style.backgroundColor = this.options.colorForFeaturedResults;\n        }\n        if (this.isRecommended(result) && this.options.colorForRecommendedResults) {\n            badge.el.style.backgroundColor = this.options.colorForRecommendedResults;\n        }\n    };\n    PromotedResultsBadge.prototype.applyTagline = function (result, badge) {\n        if (this.isFeatured(result) && this.options.showBadgeForFeaturedResults) {\n            badge.text(this.options.captionForFeatured);\n        }\n        if (this.isRecommended(result) && this.options.showBadgeForRecommendedResults) {\n            return badge.text(this.options.captionForRecommended);\n        }\n    };\n    PromotedResultsBadge.prototype.isFeatured = function (result) {\n        return result.isTopResult;\n    };\n    PromotedResultsBadge.prototype.isRecommended = function (result) {\n        return result.isRecommendation && !result.isTopResult;\n    };\n    PromotedResultsBadge.prototype.isTableLayout = function (resultElement) {\n        return Core_1.$$(resultElement).hasClass('coveo-table-layout');\n    };\n    PromotedResultsBadge.prototype.isCardLayout = function (resultElement) {\n        return Core_1.$$(resultElement).hasClass('coveo-card-layout');\n    };\n    PromotedResultsBadge.prototype.getClassName = function (result) {\n        return \"coveo-promoted-result-badge coveo-\" + (this.isFeatured(result) ? 'featured' : 'recommended') + \"-result-badge\";\n    };\n    PromotedResultsBadge.prototype.shouldShowABadge = function (result, resultElement) {\n        if (this.isTableLayout(resultElement)) {\n            return false;\n        }\n        if (this.isFeatured(result) && this.options.showBadgeForFeaturedResults) {\n            return true;\n        }\n        if (this.isRecommended(result) && this.options.showBadgeForRecommendedResults) {\n            return true;\n        }\n        return false;\n    };\n    PromotedResultsBadge.ID = 'PromotedResultsBadge';\n    PromotedResultsBadge.doExport = function () {\n        GlobalExports_1.exportGlobally({\n            PromotedResultsBadge: PromotedResultsBadge\n        });\n    };\n    /**\n     * @componentOptions\n     */\n    PromotedResultsBadge.options = {\n        /**\n         * Whether to show a badge when a result was promoted by a featured results query pipeline rule.\n         */\n        showBadgeForFeaturedResults: Core_1.ComponentOptions.buildBooleanOption({ defaultValue: true }),\n        /**\n         * Whether to show a badge when a result was promoted by Coveo ML ART.\n         */\n        showBadgeForRecommendedResults: Core_1.ComponentOptions.buildBooleanOption({ defaultValue: false }),\n        /**\n         * The caption to show on the badge for results promoted by Coveo ML ART.\n         *\n         * Default value is the localized string for `Recommended`.\n         *\n         * @examples Recommended by Coveo ML\n         */\n        captionForRecommended: Core_1.ComponentOptions.buildLocalizedStringOption({\n            localizedString: function () { return Core_1.l('Recommended'); },\n            depend: 'showBadgeForRecommendedResults'\n        }),\n        /**\n         * The caption to show on the badge for results promoted by a _featured results_ query pipeline rule.\n         *\n         * Default value is the localized string for `Featured`.\n         *\n         * @examples Recommended by ACME\n         */\n        captionForFeatured: Core_1.ComponentOptions.buildLocalizedStringOption({\n            localizedString: function () { return Core_1.l('Featured'); },\n            depend: 'showBadgeForFeaturedResults'\n        }),\n        /**\n         * The badge color for results promoted by a _featured results_ query pipeline rule.\n         *\n         * Can be specified using:\n         * - a hexadecimal value\n         * - an RGB value\n         * - a CSS color name\n         *\n         * @examples #f58020, rgb(125 10 36), red\n         *\n         * Default value is controlled through the default stylesheet of the framework.\n         */\n        colorForFeaturedResults: Core_1.ComponentOptions.buildColorOption({ depend: 'showBadgeForFeaturedResults' }),\n        /**\n         * The badge color for results promoted by Coveo ML ART.\n         *\n         * Can be specified using:\n         * - a hexadecimal value\n         * - an RGB value\n         * - a CSS color name\n         *\n         * @examples #f58020, rgb(125 10 36), red\n         *\n         * Default value is controlled through the default stylesheet of the framework.\n         */\n        colorForRecommendedResults: Core_1.ComponentOptions.buildColorOption({ depend: 'showBadgeForRecommendedResults' })\n    };\n    return PromotedResultsBadge;\n}(Component_1.Component));\nexports.PromotedResultsBadge = PromotedResultsBadge;\nCore_1.Initialization.registerAutoCreateComponent(PromotedResultsBadge);\n\n\n/***/ }),\n\n/***/ 680:\n/***/ (function(module, exports) {\n\n// removed by extract-text-webpack-plugin\n\n/***/ })\n\n});\n\n\n// WEBPACK FOOTER //\n// PromotedResultsBadge.min__d67acfe80778de2e04cc.js","import 'styling/_PromotedResultsBadge';\nimport { $$, ComponentOptions, Dom, Initialization, l, ResultListEvents } from '../../Core';\nimport { IDisplayedNewResultEventArgs } from '../../events/ResultListEvents';\nimport { exportGlobally } from '../../GlobalExports';\nimport { IQueryResult } from '../../rest/QueryResult';\nimport { Component } from '../../ui/Base/Component';\nimport { IComponentBindings } from '../Base/ComponentBindings';\n\nexport interface IPromotedResultsBadgeOptions {\n  showBadgeForFeaturedResults: boolean;\n  showBadgeForRecommendedResults: boolean;\n\n  captionForRecommended: string;\n  captionForFeatured: string;\n\n  colorForFeaturedResults: string;\n  colorForRecommendedResults: string;\n}\n\n/**\n * Depending on its configuration, this component will render badges on query result items whose ranking scores were increased by [featured results](https://docs.coveo.com/en/1961/) query pipeline rules and/or [Coveo ML ART](https://docs.coveo.com/en/1671/#automatic-relevance-tuning-art-feature).\n *\n * This component can be put anywhere in the markup configuration of a search interface. However, it is meant to be initialized only once, and should thus never be included in a result template.\n *\n * @externaldocs [Adding Promoted Results Badges](https://docs.coveo.com/en/3123/)\n * @availablesince [July 2018 Release (v2.4382.10)](https://docs.coveo.com/en/1360/)\n */\nexport class PromotedResultsBadge extends Component {\n  static ID = 'PromotedResultsBadge';\n\n  static doExport = () => {\n    exportGlobally({\n      PromotedResultsBadge\n    });\n  };\n\n  /**\n   * @componentOptions\n   */\n  static options: IPromotedResultsBadgeOptions = {\n    /**\n     * Whether to show a badge when a result was promoted by a featured results query pipeline rule.\n     */\n    showBadgeForFeaturedResults: ComponentOptions.buildBooleanOption({ defaultValue: true }),\n\n    /**\n     * Whether to show a badge when a result was promoted by Coveo ML ART.\n     */\n    showBadgeForRecommendedResults: ComponentOptions.buildBooleanOption({ defaultValue: false }),\n\n    /**\n     * The caption to show on the badge for results promoted by Coveo ML ART.\n     *\n     * Default value is the localized string for `Recommended`.\n     *\n     * @examples Recommended by Coveo ML\n     */\n    captionForRecommended: ComponentOptions.buildLocalizedStringOption({\n      localizedString: () => l('Recommended'),\n      depend: 'showBadgeForRecommendedResults'\n    }),\n\n    /**\n     * The caption to show on the badge for results promoted by a _featured results_ query pipeline rule.\n     *\n     * Default value is the localized string for `Featured`.\n     *\n     * @examples Recommended by ACME\n     */\n    captionForFeatured: ComponentOptions.buildLocalizedStringOption({\n      localizedString: () => l('Featured'),\n      depend: 'showBadgeForFeaturedResults'\n    }),\n\n    /**\n     * The badge color for results promoted by a _featured results_ query pipeline rule.\n     *\n     * Can be specified using:\n     * - a hexadecimal value\n     * - an RGB value\n     * - a CSS color name\n     *\n     * @examples #f58020, rgb(125 10 36), red\n     *\n     * Default value is controlled through the default stylesheet of the framework.\n     */\n    colorForFeaturedResults: ComponentOptions.buildColorOption({ depend: 'showBadgeForFeaturedResults' }),\n\n    /**\n     * The badge color for results promoted by Coveo ML ART.\n     *\n     * Can be specified using:\n     * - a hexadecimal value\n     * - an RGB value\n     * - a CSS color name\n     *\n     * @examples #f58020, rgb(125 10 36), red\n     *\n     * Default value is controlled through the default stylesheet of the framework.\n     */\n    colorForRecommendedResults: ComponentOptions.buildColorOption({ depend: 'showBadgeForRecommendedResults' })\n  };\n\n  constructor(public element: HTMLElement, public options: IPromotedResultsBadgeOptions, public bindings: IComponentBindings) {\n    super(element, PromotedResultsBadge.ID, bindings);\n    this.options = ComponentOptions.initComponentOptions(element, PromotedResultsBadge, options);\n    this.bind.onRootElement(ResultListEvents.newResultDisplayed, (args: IDisplayedNewResultEventArgs) => {\n      const badge = this.buildBadge(args.result, args.item);\n      if (badge) {\n        this.appendBadge(badge, args.item);\n      }\n    });\n  }\n\n  private buildBadge(result: IQueryResult, resultElement: HTMLElement): Dom {\n    if (!this.shouldShowABadge(result, resultElement)) {\n      return null;\n    }\n    const badge = $$('div', {\n      className: this.getClassName(result)\n    });\n\n    this.applyTagline(result, badge);\n    this.applyColor(result, badge);\n    return badge;\n  }\n\n  private appendBadge(badge: Dom, resultElement: HTMLElement) {\n    if (this.isCardLayout(resultElement)) {\n      this.addBadgeToCardLayout(badge, resultElement);\n    } else {\n      $$(resultElement).prepend(badge.el);\n    }\n  }\n\n  private addBadgeToCardLayout(badge: Dom, resultElement: HTMLElement): void {\n    let container: Dom;\n\n    if (resultElement.parentElement == null) {\n      container = $$('div', {\n        className: 'coveo-promoted-result-badge-container-card-layout'\n      });\n\n      container.insertBefore(resultElement);\n    } else {\n      container = $$(resultElement.parentElement);\n    }\n\n    container.append(badge.el);\n    container.append(resultElement);\n  }\n\n  private applyColor(result: IQueryResult, badge: Dom) {\n    if (this.isFeatured(result) && this.options.colorForFeaturedResults) {\n      badge.el.style.backgroundColor = this.options.colorForFeaturedResults;\n    }\n\n    if (this.isRecommended(result) && this.options.colorForRecommendedResults) {\n      badge.el.style.backgroundColor = this.options.colorForRecommendedResults;\n    }\n  }\n\n  private applyTagline(result: IQueryResult, badge: Dom): string {\n    if (this.isFeatured(result) && this.options.showBadgeForFeaturedResults) {\n      badge.text(this.options.captionForFeatured);\n    }\n    if (this.isRecommended(result) && this.options.showBadgeForRecommendedResults) {\n      return badge.text(this.options.captionForRecommended);\n    }\n  }\n\n  private isFeatured(result: IQueryResult): boolean {\n    return result.isTopResult;\n  }\n\n  private isRecommended(result: IQueryResult): boolean {\n    return result.isRecommendation && !result.isTopResult;\n  }\n\n  private isTableLayout(resultElement: HTMLElement): boolean {\n    return $$(resultElement).hasClass('coveo-table-layout');\n  }\n\n  private isCardLayout(resultElement: HTMLElement): boolean {\n    return $$(resultElement).hasClass('coveo-card-layout');\n  }\n\n  private getClassName(result: IQueryResult) {\n    return `coveo-promoted-result-badge coveo-${this.isFeatured(result) ? 'featured' : 'recommended'}-result-badge`;\n  }\n\n  private shouldShowABadge(result: IQueryResult, resultElement: HTMLElement): boolean {\n    if (this.isTableLayout(resultElement)) {\n      return false;\n    }\n\n    if (this.isFeatured(result) && this.options.showBadgeForFeaturedResults) {\n      return true;\n    }\n\n    if (this.isRecommended(result) && this.options.showBadgeForRecommendedResults) {\n      return true;\n    }\n\n    return false;\n  }\n}\n\nInitialization.registerAutoCreateComponent(PromotedResultsBadge);\n\n\n\n// WEBPACK FOOTER //\n// ./src/ui/PromotedResultsBadge/PromotedResultsBadge.ts"],"sourceRoot":""}