text: if("undefined"==typeof jQuery.aljs)throw new Error("Please include the ALJS initializer file");!function(s){var e,t='<div class="slds-pill_container slds-hide"></div>',l='<span class="slds-pill slds-size--1-of-1"><span class="slds-icon_container slds-icon-standard-account slds-pill__icon_container{{hasIcon}}" title="{{objectLabel}}"><svg aria-hidden="true" class="{{objectIconClass}} slds-icon slds-pill__icon"><use xlink:href="{{objectIconUrl}}"></use></svg><span class="slds-assistive-text">{{objectLabel}}</span></span><span class="slds-pill__label" title="{{selectedResultLabel}}">{{selectedResultLabel}}</span><button class="slds-button slds-button--icon-bare slds-pill__remove"><svg aria-hidden="true" class="slds-button__icon"><use xlink:href="{{assetsLocation}}/assets/icons/utility-sprite/svg/symbols.svg#close"></use></svg><span class="slds-assistive-text">Remove</span></button></span>',i='<span class="slds-pill slds-size--1-of-1"><span class="slds-icon_container slds-icon-standard-account slds-pill__icon_container{{hasIcon}}" title="{{objectLabel}}"><img class="{{objectIconClass}} slds-icon slds-pill__icon" src="{{objectLabel}}"/><span class="slds-assistive-text">{{objectLabel}}</span></span><span class="slds-pill__label" title="{{selectedResultLabel}}">{{selectedResultLabel}}</span><button class="slds-button slds-button--icon-bare slds-pill__remove"><svg aria-hidden="true" class="slds-button__icon"><use xlink:href="{{assetsLocation}}/assets/icons/utility-sprite/svg/symbols.svg#close"></use></svg><span class="slds-assistive-text">Remove</span></button></span>',o='<div class="slds-lookup__menu"><ul class="slds-lookup__list" role="listbox"></ul></div>',a='<li role="presentation"><span class="slds-lookup__item-action slds-lookup__item-action--label" role="option" tabindex="1"><svg aria-hidden="true" class="slds-icon slds-icon--x-small slds-icon-text-default"><use xlink:href="{{assetsLocation}}/assets/icons/utility-sprite/svg/symbols.svg#search"></use></svg><span class="slds-truncate">&quot;{{searchTerm}}&quot; in {{objectPluralLabel}}</span></span></li>',n='<div class="slds-lookup__item--label slds-text-body--small">{{recentLabel}}</div>',c='<li role="presentation"><span class="slds-lookup__item-action slds-lookup__item-action--label" role="option" tabindex="1"><svg aria-hidden="true" class="slds-icon slds-icon--x-small slds-icon-text-default"><use xlink:href="{{assetsLocation}}/assets/icons/utility-sprite/svg/symbols.svg#add"></use></svg><span class="slds-truncate">New {{objectLabel}}</span></span></li>',r='<li role="presentation"><span class="slds-lookup__item-action slds-media" id="{{resultId}}" role="option" tabindex="1"><svg aria-hidden="true" class="{{objectIconClass}} slds-icon slds-icon--small slds-media__figure{{hasIcon}}"><use xlink:href="{{objectIconUrl}}"></use></svg><div class="slds-media__body"><div class="slds-lookup__result-text">{{resultLabel}}</div>{{metaLabel}}</div></span></li>',d='<li role="presentation"><span class="slds-lookup__item-action slds-media" id="{{resultId}}" role="option" tabindex="1"><img class="{{objectIconClass}} slds-icon slds-icon--small slds-media__figure{{hasIcon}}" src="{{objectIconUrl}}"/><div class="slds-media__body"><div class="slds-lookup__result-text">{{resultLabel}}</div>{{metaLabel}}</div></span></li>',u=function(e,l){this.$el=s(e),this.$lookupContainer=this.$el.closest(".slds-lookup"),this.isSingle="single"===this.$lookupContainer.data("select"),this.settings=l,this.isSingle?this.$singleSelect=s(t).insertBefore(this.$el):(this.$multiSelect=s(t).insertAfter(this.$lookupContainer.find(".slds-form-element__label")),this.selectedResults=[],this.$multiSelect.css({padding:0,"margin-top":"-2px","margin-left":"-2px",border:"none"})),this.isStringEmpty(l.searchTerm)?l.initialSelection&&this.setSelection(l.initialSelection):(this.$el.val(l.searchTerm),this.setSingleSelect()),this.initLookup()},h=function(e){var t=s(e.currentTarget);if(t.removeClass("slds-has-focus"),38===e.which||40===e.which){e.preventDefault();var l=s(".slds-lookup .slds-lookup__list > li:first-child").is(".slds-lookup__item--label")?".slds-lookup .slds-lookup__list > li:nth-child(2) .slds-lookup__item-action":".slds-lookup .slds-lookup__list > li:first-child .slds-lookup__item-action";38===e.which?t.is(l)?s(".slds-lookup .slds-lookup__list > li:last-child .slds-lookup__item-action").focus().addClass("slds-has-focus"):t.closest("li").prev().find(".slds-lookup__item-action").focus().addClass("slds-has-focus"):t.is(".slds-lookup .slds-lookup__list > li:last-child .slds-lookup__item-action")?s(l).focus().addClass("slds-has-focus"):t.closest("li").next().find(".slds-lookup__item-action").focus().addClass("slds-has-focus")}else 13===e.which&&t.click()};u.prototype={constructor:u,isStringEmpty:function(s){return null===s||"undefined"==typeof s||""===s.trim()},initLookup:function(){this.$el.on("focus",this,this.runSearch).on("blur",this,this.handleBlur).on("keyup",this,this.handleKeyup),s("body").off("keyup",".slds-lookup .slds-lookup__list .slds-lookup__item-action",h),s("body").on("keyup",".slds-lookup .slds-lookup__list .slds-lookup__item-action",h)},handleKeyup:function(e){40===e.which?s(".slds-lookup .slds-lookup__list .slds-lookup__item-action").first().focus().addClass("slds-has-focus"):e.data.runSearch(e)},runSearch:function(s){var t=s.data;e&&(t.settings.showDebugLog&&console.log("Cancelling search ",e),clearTimeout(e)),e=setTimeout(function(){var s=t.$el.val();t.isStringEmpty(s)?t.getDefaultResults():t.getSearchTermResults(s)},t.settings.searchDelay)},setMultiSelect:function(e){var t=this,o=this.$multiSelect.html(""),a=(this.$lookupContainer,t.settings.useImgTag?i:l);e.length>0?(e.forEach(function(e){var l=s(a.replace("{{objectIconUrl}}",t.settings.objectIconUrl).replace("{{objectIconClass}}",t.settings.objectIconClass).replace("{{hasIcon}}",""!==t.settings.objectIconUrl?"":" slds-hide").replace("{{assetsLocation}}",t.settings.assetsLocation).replace(/{{objectLabel}}/g,t.settings.objectLabel).replace(/{{selectedResultLabel}}/g,e.label));l.removeClass("slds-size--1-of-1").attr("id",e.id).on("click","a, button",t,t.clearMultiSelectResult).css({margin:"2px",display:"inline-flex"}).find(".slds-pill__remove").css({"vertical-align":"1px","margin-left":"0.25rem"}),o.append(l)}),o.addClass("slds-show").removeClass("slds-hide")):(o.html(""),o.addClass("slds-hide").removeClass("slds-show"))},setSingleSelect:function(s){var e=this,t=s||"",o=e.settings.useImgTag?i:l;this.$singleSelect.html(o.replace("{{objectIconUrl}}",this.settings.objectIconUrl).replace("{{objectIconClass}}",e.settings.objectIconClass).replace("{{hasIcon}}",""!==e.settings.objectIconUrl?"":" slds-hide").replace("{{assetsLocation}}",this.settings.assetsLocation).replace(/{{objectLabel}}/g,e.settings.objectLabel).replace(/{{selectedResultLabel}}/g,t)),s?(this.$singleSelect.addClass("slds-show").removeClass("slds-hide"),this.$el.addClass("slds-hide"),this.$lookupContainer.addClass("slds-has-selection"),this.$singleSelect.one("click","button",this,this.clearSingleSelect)):(this.$singleSelect.addClass("slds-hide").removeClass("slds-show"),this.$el.val("").removeClass("slds-hide"),this.$lookupContainer.removeClass("slds-has-selection"),setTimeout(function(){e.$el.focus()},100))},getSearchTermResults:function(s){var e=this;if(this.settings.items.length>0)this.searchResults=this.settings.items.filter(function(e){return null!==e.label.toLowerCase().match(s.toLowerCase())}),this.renderSearchResults();else{var t=function(s){e.searchResults=s,e.renderSearchResults()};this.settings.filledSearchTermQuery(s,t)}},getDefaultResults:function(){var s=this;if(this.settings.items.length>0)this.searchResults=this.settings.items,this.renderSearchResults();else{var e=function(e){s.searchResults=e,s.renderSearchResults()};this.settings.emptySearchTermQuery(e)}},renderSearchResults:function(){this.closeSearchDropdown();var e=s(o),t=e.find("ul.slds-lookup__list"),l=this.$el.val(),i=new RegExp("("+l+")","gi"),u=this,h=!1;if(!u.isStringEmpty(l)&&l.length?u.settings.showSearch&&(h=!0,t.prepend(a.replace("{{searchTerm}}",l).replace("{{objectPluralLabel}}",u.settings.objectPluralLabel).replace("{{assetsLocation}}",s.aljs.assetsLocation))):u.settings.recentLabel&&t.before(n.replace("{{recentLabel}}",u.settings.recentLabel)),this.searchResults.forEach(function(e){var l,o=u.settings.useImgTag?d:r,a=e.label.replace(i,"<mark>$1</mark>");if(u.isSingle)l=t.append(o.replace("{{resultLabel}}",a).replace("{{hasIcon}}",""!==u.settings.objectIconUrl?"":" slds-hide").replace("{{resultId}}",e.id).replace("{{objectIconUrl}}",u.settings.objectIconUrl).replace("{{objectIconClass}}",u.settings.objectIconClass).replace("{{metaLabel}}",e.metaLabel?'<span class="slds-lookup__result-meta slds-text-body--small">'+e.metaLabel+"</span>":""));else if(u.selectedResults){var n=u.selectedResults.map(function(s){return s.id});0!==n.length&&n.indexOf(e.id)!==-1||(l=t.append(o.replace("{{resultLabel}}",a).replace("{{hasIcon}}",""!==u.settings.objectIconUrl?"":" slds-hide").replace("{{resultId}}",e.id).replace("{{objectIconUrl}}",u.settings.objectIconUrl).replace("{{objectIconClass}}",u.settings.objectIconClass).replace("{{metaLabel}}",e.metaLabel?'<span class="slds-lookup__result-meta slds-text-body--small">'+e.metaLabel+"</span>":"")))}l&&l.find(".slds-lookup__item-action[id]").on("focus",function(){u.$el.attr("aria-activedescendant",s(this).attr("id"))}).on("blur",u,u.handleBlur)}),this.settings.onClickNew){var p=t.append(c.replace("{{objectLabel}}",this.settings.objectLabel).replace("{{assetsLocation}}",s.aljs.assetsLocation));p.next().on("click",function(){p.off("click"),u.settings.onClickNew()})}t.one("click",".slds-lookup__item-action[id]",this,this.clickResult),this.$lookupSearchContainer=e.appendTo(this.$lookupContainer);var g=this.searchResults.length>0&&this.$el.closest(".slds-form-element").find(".slds-lookup__list > li").length>0||this.settings.onClickNew||h;g?this.$el.attr("aria-expanded","true").closest(".slds-lookup").addClass("slds-is-open"):this.$lookupSearchContainer.remove()},closeSearchDropdown:function(){this.$lookupSearchContainer&&(this.$lookupSearchContainer.remove(),this.$lookupSearchContainer=null),this.$el.attr("aria-expanded","false").attr("aria-activedescendant",null).closest(".slds-lookup").removeClass("slds-is-open")},handleBlur:function(e){var t=e.data;0===s(e.relatedTarget).closest(".slds-lookup.slds-is-open").length&&t.$lookupSearchContainer&&t.closeSearchDropdown()},clickResult:function(e){var t=e.data,l=s(this).attr("id");t.selectResult(l)},selectResult:function(s){var e=this.searchResults.filter(function(e){return e.id==s});this.closeSearchDropdown(),this.isSingle?(this.selectedResult=e.length>0?e[0]:null,this.setSingleSelect(this.selectedResult.label),this.settings.onChange(this.selectedResult,!0)):(e.length>0&&(this.selectedResults.push(e[0]),this.setMultiSelect(this.selectedResults),this.$el.val("")),this.settings.onChange(this.selectedResults,!0))},clearSingleSelect:function(s){var e=s.data;e.selectedResult=null,e.setSingleSelect(),e.settings.onChange(e.selectedResult,!1)},clearMultiSelectResult:function(e){var t,l=e.data,i=s(this).closest("span.slds-pill"),o=i.attr("id");l.closeSearchDropdown(),l.selectedResults.forEach(function(s,e){s.id==o&&(t=e)}),"undefined"!=typeof t&&null!==t&&(l.selectedResults.splice(t,1),l.setMultiSelect(l.selectedResults),l.settings.onChange(l.selectedResults,!1))},getSelection:function(){return this.isSingle?this.selectedResult||null:this.selectedResults||null},setSelection:function(e){var t=this;if(!e||"object"!=typeof e)throw new Error("setSelection must be called with either a valid result object or an array of result objects.");s.isEmptyObject(e)?t.isSingle?(t.selectedResult=null,t.setSingleSelect(),t.settings.onChange(t.selectedResult,!1)):(t.selectedResults=[],t.setMultiSelect(t.selectedResults),t.settings.onChange(t.selectedResults,!1)):e instanceof Array?(this.searchResults=e,this.selectedResults=[],e.forEach(function(s){t.selectResult(s.id)})):(this.selectedResult=null,this.searchResults=[e],t.selectResult(e.id))}},s.fn.lookup=function(e){var t,l=arguments,i=s.extend({assetsLocation:s.aljs.assetsLocation,objectPluralLabel:"Objects",objectLabel:"Object",useImgTag:!1,objectIconUrl:s.aljs.assetsLocation+"/assets/icons/standard-sprite/svg/symbols.svg#account",objectIconClass:"slds-icon-standard-account",searchTerm:"",items:[],emptySearchTermQuery:function(s){s([])},filledSearchTermQuery:function(s,e){e([])},onClickNew:null,onChange:function(){},initialSelection:null,recentLabel:"Recent Objects",showSearch:!1,searchDelay:500},"object"==typeof e?e:{});if(this.each(function(){var o=s(this),a=o.data("aljs-lookup");if(!a){var n=new u(this,i);o.data("aljs-lookup",a=n)}"string"==typeof e&&(t=a[e](l[1],l[2]))}),void 0===t||t instanceof u)return this;if(this.length>1)throw new Error("Using only allowed for the collection of a single element ("+option+" function)");return t}}(jQuery);