UNPKG

coveo-search-ui

Version:

Coveo JavaScript Search Framework

2 lines 9.82 kB
webpackJsonpCoveo__temporary([43],{201:function(t,e,o){"use strict";var s=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o])};return function(e,o){function s(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(s.prototype=o.prototype,new s)}}();Object.defineProperty(e,"__esModule",{value:!0}),o(662);var n=o(0),i=o(17),r=o(11),u=o(134),a=o(29),l=o(5),c=o(18),y=o(13),h=o(3),p=o(6),d=o(1),L=o(16),f=o(12),v=o(4),b=o(10),m=o(7),g=o(8),C=o(2),S=o(663),A=o(15);e.defaultLayout="list";var R=function(t){function e(o,s,n){var u=t.call(this,o,e.ID,n)||this;return u.element=o,u.options=s,u.preferredLayout=null,u.options=g.ComponentOptions.initComponentOptions(o,e,s),u.currentActiveLayouts={},u.bind.onQueryState(c.MODEL_EVENTS.CHANGE_ONE,y.QUERY_STATE_ATTRIBUTES.LAYOUT,u.handleQueryStateChanged.bind(u)),u.bind.onRootElement(r.QueryEvents.querySuccess,function(t){return u.handleQuerySuccess(t)}),u.bind.onRootElement(r.QueryEvents.queryError,function(t){return u.handleQueryError(t)}),u.resultLayoutSection=d.$$(u.element).closest(".coveo-result-layout-section"),u.bind.oneRootElement(i.InitializationEvents.afterComponentsInitialization,function(){return u.populate()}),u.bind.oneRootElement(i.InitializationEvents.afterInitialization,function(){return u.handleQueryStateChanged()}),S.ResponsiveResultLayout.init(u.root,u,{}),u}return s(e,t),Object.defineProperty(e.prototype,"activeLayouts",{get:function(){return this.searchInterface.responsiveComponents.isLargeScreenWidth()?n.pick(this.currentActiveLayouts,this.options.desktopLayouts):this.searchInterface.responsiveComponents.isMediumScreenWidth()?n.pick(this.currentActiveLayouts,this.options.tabletLayouts):this.searchInterface.responsiveComponents.isSmallScreenWidth()?n.pick(this.currentActiveLayouts,this.options.mobileLayouts):this.currentActiveLayouts},enumerable:!0,configurable:!0}),e.prototype.changeLayout=function(t){this.preferredLayout=null,this.performLayoutChange(t)},e.prototype.getCurrentLayout=function(){return this.currentLayout},e.prototype.disableLayouts=function(t){var e=this;if(v.Utils.isNonEmptyArray(t)){n.each(t,function(t){return e.disableLayout(t)});var o=n.difference(n.keys(this.currentActiveLayouts),t);if(this.preferredLayout=this.currentLayout,n.isEmpty(o)){this.logger.error("Cannot disable the last valid layout ... Re-enabling the first one possible");var s=n.keys(this.currentActiveLayouts)[0];this.enableLayout(s),this.setLayout(s)}else{var i=n.contains(o,this.currentLayout)?this.currentLayout:o[0];this.performLayoutChange(i)}}},e.prototype.enableLayouts=function(t){var e=this;n.each(t,function(t){return e.enableLayout(t)}),n.find(t,function(t){return t===e.preferredLayout})&&this.restorePreferredLayout()},e.prototype.restorePreferredLayout=function(){this.performLayoutChange(this.preferredLayout),this.preferredLayout=null},e.prototype.performLayoutChange=function(t){if(l.Assert.check(this.isLayoutDisplayedByButton(t),"Layout not available or invalid"),t!==this.currentLayout||""===this.getModelValue()){this.setModelValue(t);var e=this.queryController.getLastResults();this.setLayout(t,e),e?this.usageAnalytics.logCustomEvent(b.analyticsActionCauseList.resultsLayoutChange,{resultsLayoutChangeTo:t},this.element):(this.usageAnalytics.logSearchEvent(b.analyticsActionCauseList.resultsLayoutChange,{resultsLayoutChangeTo:t}),this.queryController.firstQuery||this.queryController.executeQuery())}},e.prototype.disableLayout=function(t){this.isLayoutDisplayedByButton(t)&&this.hideButton(t)},e.prototype.enableLayout=function(t){var e=this.resultLists;n.find(e,function(e){return e.options.layout==t})&&this.isLayoutDisplayedByButton(t)&&(this.showButton(t),this.updateSelectorAppearance())},Object.defineProperty(e.prototype,"resultLists",{get:function(){return this.searchInterface.getComponents("ResultList")},enumerable:!0,configurable:!0}),e.prototype.hideButton=function(t){if(this.isLayoutDisplayedByButton(t)){var e=this.currentActiveLayouts[t].button;d.$$(e.el).addClass("coveo-hidden"),e.visible=!1,this.updateSelectorAppearance()}},e.prototype.showButton=function(t){if(this.isLayoutDisplayedByButton(t)){var e=this.currentActiveLayouts[t].button;d.$$(e.el).removeClass("coveo-hidden"),e.visible=!0}},e.prototype.setLayout=function(t,e){t&&(this.currentLayout&&(d.$$(this.currentActiveLayouts[this.currentLayout].button.el).removeClass("coveo-selected"),d.$$(this.currentActiveLayouts[this.currentLayout].button.el).setAttribute("aria-pressed",(!1).toString())),d.$$(this.currentActiveLayouts[t].button.el).addClass("coveo-selected"),d.$$(this.currentActiveLayouts[t].button.el).setAttribute("aria-pressed",(!0).toString()),this.currentLayout=t,d.$$(this.element).trigger(a.ResultListEvents.changeLayout,{layout:t,results:e}))},e.prototype.handleQuerySuccess=function(t){this.hasNoResults=0==t.results.results.length,this.shouldShowSelector()?this.show():this.hide()},e.prototype.handleQueryStateChanged=function(t){var e=this.getModelValue(),o=n.find(n.keys(this.currentActiveLayouts),function(t){return t===e});void 0!==o?this.setLayout(o):this.setLayout(n.keys(this.currentActiveLayouts)[0])},e.prototype.handleQueryError=function(t){this.hasNoResults=!0,this.hide()},e.prototype.updateSelectorAppearance=function(){this.shouldShowSelector()?this.show():this.hide()},e.prototype.populate=function(){var t=this,o={layouts:[]};d.$$(this.root).trigger(u.ResultLayoutEvents.populateResultLayout,o);var s=n.uniq(o.layouts.map(function(t){return t.toLowerCase()}));n.each(s,function(t){return l.Assert.check(n.contains(e.validLayouts,t),"Invalid layout")}),n.isEmpty(s)||(n.each(s,function(e){return t.addButton(e)}),this.shouldShowSelector()||this.hide())},e.prototype.addButton=function(t){var e=this,o=d.$$("span",{className:"coveo-result-layout-selector"}),s=d.$$("span",{className:"coveo-result-layout-selector-caption"},p.l(t));o.append(s.el);var n=d.$$("span",{className:"coveo-icon coveo-"+t+"-layout-icon"},f.SVGIcons.icons[t+"Layout"]);L.SVGDom.addClassToSVGInContainer(n.el,"coveo-"+t+"-svg"),o.prepend(n.el);var i=function(){return e.changeLayout(t)};(new A.AccessibleButton).withElement(o).withLabel(p.l("DisplayResultsAs",p.l(t))).withSelectAction(i).withOwner(this.bind).build();var r=t===this.currentLayout;o.toggleClass("coveo-selected",r),o.setAttribute("aria-pressed",r.toString()),d.$$(this.element).append(o.el),this.currentActiveLayouts[t]={button:{visible:!0,el:o.el},enabled:!0}},e.prototype.hide=function(){var t=this.resultLayoutSection||this.element;d.$$(t).addClass("coveo-result-layout-hidden")},e.prototype.show=function(){var t=this.resultLayoutSection||this.element;d.$$(t).removeClass("coveo-result-layout-hidden")},e.prototype.getModelValue=function(){return this.queryStateModel.get(y.QueryStateModel.attributesEnum.layout)},e.prototype.setModelValue=function(t){this.queryStateModel.set(y.QueryStateModel.attributesEnum.layout,t)},e.prototype.shouldShowSelector=function(){return n.keys(this.currentActiveLayouts).length>1&&n.filter(this.currentActiveLayouts,function(t){return t.button.visible}).length>1&&!this.hasNoResults},e.prototype.isLayoutDisplayedByButton=function(t){return n.contains(n.keys(this.currentActiveLayouts),t)},e.ID="ResultLayoutSelector",e.aliases=["ResultLayout"],e.doExport=function(){h.exportGlobally({ResultLayoutSelector:e,ResultLayout:e})},e.validLayouts=["list","card","table"],e.options={mobileLayouts:g.ComponentOptions.buildListOption({defaultValue:["card","table"]}),tabletLayouts:g.ComponentOptions.buildListOption({defaultValue:["list","card","table"]}),desktopLayouts:g.ComponentOptions.buildListOption({defaultValue:["list","card","table"]})},e}(m.Component);e.ResultLayoutSelector=R,C.Initialization.registerAutoCreateComponent(R)},662:function(t,e){},663:function(t,e,o){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var s=o(0),n=o(9),i=o(1),r=o(7),u=o(201),a=o(19),l=o(62),c=function(){function t(t,e,o,s){var n=this;this.coveoRoot=t,this.ID=e,this.searchInterface=r.Component.get(this.coveoRoot.el,a.SearchInterface,!1),t.on("state:change:t",function(){n.handleResizeEvent()})}return t.init=function(e,o,s){if(!i.$$(e).find("."+r.Component.computeCssClassName(u.ResultLayoutSelector))){return void new n.Logger("ResponsiveResultLayout").trace("No ResultLayout component found : Cannot instantiate ResponsiveResultLayout")}l.ResponsiveComponentsManager.register(t,i.$$(e),u.ResultLayoutSelector.ID,o,s)},t.prototype.registerComponent=function(t){return t instanceof u.ResultLayoutSelector&&(this.resultLayout=t,!0)},t.prototype.handleResizeEvent=function(){this.needSmallMode()?this.enableAndDisableLayouts(this.resultLayout.options.mobileLayouts):this.needMediumMode()?this.enableAndDisableLayouts(this.resultLayout.options.tabletLayouts):this.enableAndDisableLayouts(this.resultLayout.options.desktopLayouts)},t.prototype.enableAndDisableLayouts=function(t){var e=s.difference(u.ResultLayoutSelector.validLayouts,t),o=s.intersection(u.ResultLayoutSelector.validLayouts,t);this.resultLayout.disableLayouts(e),this.resultLayout.enableLayouts(o)},t.prototype.needSmallMode=function(){switch(this.searchInterface.responsiveComponents.getResponsiveMode()){case"small":return!0;case"auto":return this.coveoRoot.width()<=this.searchInterface.responsiveComponents.getSmallScreenWidth();default:return!1}},t.prototype.needMediumMode=function(){switch(this.searchInterface.responsiveComponents.getResponsiveMode()){case"medium":return!0;case"auto":return this.coveoRoot.width()<=this.searchInterface.responsiveComponents.getMediumScreenWidth();default:return!1}},t}();e.ResponsiveResultLayout=c}}); //# sourceMappingURL=ResultLayoutSelector.min__cf4c4f4dd6c8a707e936.js.map