').appendTo(e),V(t,o,i,n),t.setExchangeFilter(i),!0)}function L(t){var e=v(t,t.$filterContainer);return t.selectExchangeFilter(),e}function A(t,e,i){this._container=t,this._tickerRegExp=e,this._translationCache=i,this._exchangeNameCache=this._roots={},this._itemsByTicker={}}var F,O,V,D,P,M=[{name:"input",immediate:!0},{name:"sync",immediate:!0},{name:"keypress"},{name:"keydown"},{name:"keyup"},{name:"mousedown"},{name:"mouseup"},{name:"cut"},{name:"paste"}],N=!0;return N=!1,F=[/^e\-m/i],O=/<\/?[^>]+(>|$)/g,t.registerAutoFocus=function(e){if(e instanceof jQuery&&(e=e.data("symbol-search-instance")),!(e instanceof t))throw new TypeError("arg must be an SymbolSearch instance of jQuery input with bound SymbolSearch object");c.registerListener("symbolEdit",function(t){if(T(t)){t.preventDefault(),this.resetState(),this._skipAutoFocus=!0,this._inputElement.focus();var e=String.fromCharCode(t.charCode);"function"==typeof this._setInputValue?this._setInputValue(e):this._inputElement.value=e,this._eventListener()}}.bind(e))},t.prototype.searchRequestDelay=0,t.setSearchRequestDelay=function(e){t.prototype.searchRequestDelay=e},t.prototype.resetState=function(){this._state={}},t.prototype.typeFilter=function(t){if(!(arguments.length>0))return this._state.typeFilter;t!==this._state.typeFilter&&(null==t?delete this._state.typeFilter:this._state.typeFilter=t+"",delete this._state.keepListFor,this._onSelectionChanged(),this.selectExchangeFilter())},t.prototype.setExchangeFilter=function(t){t!==this._state.exchangeFilter&&(null==t?delete this._state.exchangeFilter:this._state.exchangeFilter=t+"",delete this._state.keepListFor,this._onSelectionChanged())},t.prototype.setTradableFilter=function(t){t!==this._state.tradableFilter&&(this._state.tradableFilter=t,this._onSelectionChanged())},t.prototype.getExchangeFilter=function(){return this._state.exchangeFilter},
t.prototype.destroy=function(){$(this._inputElement).off(),$(this._inputElement).removeData("symbol-search-instance")},t.prototype._moveSelection=function(t,e){var i,n,s,o,r,a,l,c;this.$list&&(n=(i=this.$list.find("table.symbol-edit-popup")).find("tr:not(.hidden)"),(o=0!==(s=i.find("tr.symbol-edit-popup-active").removeClass("symbol-edit-popup-active")).length?n.index(s):-1)!==(r=1===t?s.get(0)===n.get(-1)?0:o+t:Math.max(-1,o+t))&&(a=n.get(r))&&(l=this._getItemByElement(a),A.isRoot(l)?(c=a.getAttribute("data-root"),a.classList.add("symbol-edit-popup-active"),this._scrollHighlightIntoView(),c?(this._state.highlightedItem=null,this._selectedGroupRoot=c):(this._state.highlightedItem=l,this._replaceCurrentSymbol(e))):(delete this._selectedGroupRoot,this._highlightItem(l,!0,e))))},t.prototype._groupToggleCollapsed=function(t,e){this._groupListHandler&&this._groupListHandler.toggleCollapsed(t,e)},t.prototype._onKeyDown=function(t){t.keyCode!==g.DOWN_ARROW&&t.keyCode!==g.UP_ARROW||(this._moveSelection(t.keyCode===g.DOWN_ARROW?1:-1,!0),t.preventDefault(),t.stopPropagation()),t.keyCode===g.ENTER&&t.stopPropagation(),!this._selectedGroupRoot||t.keyCode!==g.LEFT_ARROW&&t.keyCode!==g.RIGHT_ARROW||(this._groupToggleCollapsed(this._selectedGroupRoot,t.keyCode===g.LEFT_ARROW),t.preventDefault())},t.prototype._onKeyPress=function(t){if(t.keyCode===g.DOWN_ARROW||t.keyCode===g.UP_ARROW){if(t.charCode)return;if(this._boundOnKeyDown)return $(this._inputElement).off("keydown",this._boundOnKeyDown),delete this._boundOnKeyDown,void t.preventDefault();this._moveSelection(t.keyCode===g.DOWN_ARROW?1:-1),t.preventDefault()}t.keyCode===g.ENTER&&(this._selectedGroupRoot?(this._groupToggleCollapsed(this._selectedGroupRoot,!1),t.preventDefault()):this.acceptTypeIn())},t.prototype._eventListener=function(t,i){var n,s,o,r,a,l=this._inputElement,c=this._getInputValue();e.enabled("uppercase_instrument_names")&&(c=c.toUpperCase()),n=!1,s=!1,this._state.value!==c&&(this._state.hasOwnProperty("value")&&this._onValueChanged&&this._onValueChanged(c),this._state.value=c,n=!0,this._inputParserMixin&&this._inputParserMixin.parse()),this._fixIntervalCase(),o=this._limitInputSelectionValue("selectionStart"),this._state.selectionStart!==o&&(this._state.selectionStart=o,s=!0),r=this._limitInputSelectionValue("selectionEnd"),this._state.selectionEnd!==r&&(this._state.selectionEnd=r,s=!0),this._state.selectionDirection!==l.selectionDirection&&(this._state.selectionDirection=l.selectionDirection,s=!0),(n||s&&this._inputParserMixin)&&(this._onSelectionChanged(void 0,i),a=!1,this._getInputValue()!==this._state.value&&(this._setInputValue(this._state.value),a=!0),(a||this._state.selectionStart!==this._limitInputSelectionValue("selectionStart")||this._state.selectionEnd!==this._limitInputSelectionValue("selectionEnd"))&&l.setSelectionRange&&l.setSelectionRange(this._state.selectionStart,this._state.selectionEnd,this._state.selectionDirection))},t.prototype._fixIntervalCase=function(){if(this._selectionInsideInterval()){var e=t.detachInterval(this._inputElement.value)
;/[a-z]/.test(e.detached)&&(this._inputElement.value=e.rest+e.detached.toUpperCase())}},t.prototype._selectionInsideInterval=function(e){if(this._ignoreInterval)return!1;var i=t.detachInterval(this._inputElement.value);return!!i&&("string"==typeof e?this._inputElement[e]>i.rest.length:this._inputElement.selectionStart>i.rest.length&&this._inputElement.selectionEnd>i.rest.length)},t.prototype._limitInputSelectionValue=function(e){return this._selectionInsideInterval(e)?t.detachInterval(this._inputElement.value).rest.length:e in this._inputElement?this._inputElement[e]:this._inputElement.value.length},t.prototype._getInputValue=function(){if(this._ignoreInterval)return this._inputElement.value;var e=t.detachStoreInterval(this._inputElement.value);return $(this._inputElement).toggleClass("interval-error",t.intervalError()),e},t.prototype._setInputValue=function(e){this._ignoreInterval?this._inputElement.value=e:this._inputElement.value=t.recallAttachInterval(e)},t.prototype._onSelectionChanged=function(t,e){function i(t,e,i,n,o){s._state.contextTicker=t,s._state.contextExchange=e,s._state.contextType=i,s._state.contextTradable=o,s._state.keepListFor&&s._state.keepListFor===n||(s._getSuggestList(),delete s._state.keepListFor)}var n,s=this,o=F.some(function(t){return t.test(s._state.value)});!o&&(this._isSpreadInInput()||this._inputParserMixin&&!0!==e)?this._inputParserMixin.onSelectionChanged(i):this.$list&&(this._state._selectedTicker=null,n=this._state.value,this._isSpreadInInput()&&this._state.contextToken&&(n=this._state.contextToken.value),i(n,this.getExchangeFilter(),this._state.typeFilter,n,this._state.tradableFilter))},t.prototype._clearSelectionState=function(){delete this._state.contextTicker,delete this._state.contextExchange,delete this._state.contextType,delete this._state.contextToken,delete this._state.keepListFor},t.prototype._clearSearchTimeout=function(){this._searchTimeout&&(clearTimeout(this._searchTimeout),this._searchTimeout=null)},t.prototype._doGetSuggestList=function(){var t,e,i,n,o,r,a,l;this._clearSearchTimeout(),t=s(),e=this._state.contextTicker||"",i=this._state.contextExchange||this.getExchangeFilter()||"",n=this._state.typeFilter||"",o=t&&this._state.tradableFilter,r=this._getUnhideSymbolSearchGroups(),a=window.language||"",this._showLoading(),l=this,ChartApiInstance.searchSymbols(e,i,n,a,N,!1,t,o,r,function(t){e!==(l._state.contextTicker||"")||i!==(l._state.contextExchange||l.getExchangeFilter()||"")||n!==(l._state.typeFilter||"")||(n===d.types.QUANDL&&(t=l._processQuandlResponse(t)),l._renderSuggestList(t),l._onResponse(t))})},t.prototype._getSuggestList=function(){this._clearSearchTimeout(),this._searchTimeout=setTimeout(this._doGetSuggestList.bind(this),t.prototype.searchRequestDelay)},t.prototype._showLoading=function(){if(this.$list&&!this._spinner){this._clearSuggestList();var t=$('
').appendTo(this.$list);this._spinner=new p("medium").spin(t.get(0))}},t.prototype._groupContracts=function(t){var e,i,n,s,o,r=ChartApiInstance.futuresRegex(),a={},l=[]
;for(e=0;e1?"g":"")),delete s.highlightedItem,this._hidePro&&(i=i.filter(function(t){return!t.params||-1===t.params.indexOf("pro")})),0!==i.length){for((a=document.createElement("table")).setAttribute("class","symbol-edit-popup"),l={},c=new t.GroupListHandler(a,r,l),p=null,this._renderedResponse=[],u=0;u'+$.t("No symbols matched your criteria")+"
")},t.prototype._isEmptySuggestList=function(){return!Boolean(this._renderedResponse&&this._renderedResponse.length)},t.prototype._isSpreadInInput=function(){return this._inputParserMixin&&this._state.parsed&&this._state.parsed.length>1},t.prototype._getItemByElement=function(t){return this._renderedResponse&&this._groupListHandler?this._groupListHandler.getItemByTicker(t.getAttribute("data-item-ticker")):null},t.prototype._getElementByItem=function(t){return this._renderedResponse&&this.$list?this.$list.get(0).querySelector('tr[data-item-ticker="'+(t.ticker||t.full_name)+'"]'):null},t.prototype._highlightItem=function(t,e,i){var n,s,o=this._state;o.highlightedItem&&(n=this._getElementByItem(o.highlightedItem))&&$(n).removeClass("symbol-edit-popup-active"),o.highlightedItem=t,(s=this._getElementByItem(o.highlightedItem))&&($(s).addClass("symbol-edit-popup-active"),this._scrollHighlightIntoView()),e&&this._replaceCurrentSymbol(i)},t.prototype._scrollHighlightIntoView=function(){var t=this.$list.find("tr.symbol-edit-popup-active");t.length&&(t.offset().top
this.$list.offset().top+this.$list.outerHeight()&&this.$list.scrollTop(this.$list.scrollTop()+(t.offset().top+t.outerHeight()-(this.$list.offset().top+this.$list.outerHeight()))))},t.prototype._clearSuggestList=function(){this._renderedResponse=null,this._spinner&&(this._spinner.stop(),delete this._spinner),this.$list&&this.$list.empty()},
t.prototype._showErrorNotice=function(){this.$list&&(this._clearSuggestList(),this.$list.text("Invalid expression"))},t.prototype._replaceCurrentSymbol=function(t){var e,i,n,s,o=this._state;if(o.highlightedItem){if(e=o.highlightedItem,i="",n=0,this._isSpreadInInput()||this._inputParserMixin&&!0!==t){if(!(s=this._inputParserMixin.replaceCurrentSymbol(e)).ok)return;i=s.newValue,n=s.newCaretPos,o.keepListFor=s.keepListFor}else this._state._selectedTicker=e.ticker||e.symbol,o.keepListFor=this._state._selectedTicker,n=(i=!0===t&&e.full_name&&this._inputParserMixin?e.full_name:e.symbol).length;this._setInputValue(N?i.replace(O,""):i),this._inputElement.setSelectionRange?this._inputElement.setSelectionRange(n,n):this._inputElement.select(),this._eventListener(void 0,t)}},t.prototype.splitAndAcceptUserInput=function(){var t,e=this._getInputValue().split(",");for(t=0;t0&&(this._state.typeFilter===d.types.QUANDL&&this._showNotification())},t.prototype._showNotification=function(){var t,e;TVSettings.getBool("symboledit.show_quandl_notification",!0)&&(t=$.t("Quandl is a huge financial database that we have connected to TradingView. Most of its data is EOD and is not updated in real-time, however the information may be extremely useful for fundamental analysis.")+' '+$.t("Read our blog for more info!")+"",(e=$('').prependTo(this.$list)).html(t),e.find("a").click(function(t){t.preventDefault();var e=$(this).attr("href");window.open(e,"_blank")}),$('
').appendTo(e).click(function(){
TVSettings.setValue("symboledit.show_quandl_notification",!1),e.remove()}))},t.prototype._processQuandlResponse=function(t){return t.datasets.filter(function(t){return!t.premium}).map(function(t){return{description:t.name,exchange:t.database_code,full_name:"QUANDL:"+t.database_code+"/"+t.dataset_code,params:["eod"],symbol:t.dataset_code,type:"quandl"}})},t.prototype._getUnhideSymbolSearchGroups=function(){var t,e="",i=n();return i&&(t=i.metainfo().configFlags.supportUnhideSymbolSearchGroups,i.connectionStatus()===CONNECTSTATUSES.CONNECTED&&t&&(e=i.unhideSymbolSearchGroups().join(",")),tradingService().trackEvent("Symbol Search Tradable checkbox",s()&&this._state.tradableFilter?"on":"off")),e},t.prototype.forceFocus=function(){this._inputElement.focus()},t.createSuggestListRow=function(e,i,n,s){var a,l,c,p,u,h,d,g,f,_,m,y,v,b;return s||(s={}),a=document.createElement("tr"),l="symbol-edit-popup",s.addClass&&(l+=" "+s.addClass),a.setAttribute("class",l),c=!N||"quandl"===e.type,(p=document.createElement("td")).setAttribute("class","symbol-edit-popup-td name apply-overflow-tooltip apply-overflow-tooltip--allow-text"),u=c?e.symbol.replace(i,"$&"):e.symbol,h=s.nameContent||u,e.broker_symbol&&(h=h+" ("+(c?e.broker_symbol.replace(i,"$&"):e.broker_symbol)+")"),p.innerHTML=h,(d=document.createElement("td")).setAttribute("class","symbol-edit-popup-td desc apply-overflow-tooltip"),g=e.description.toUpperCase(),w&&e.contractDescription&&(g+=(f=R.exec(e.contractDescription))?" ("+r(n,f[1])+" "+f[2]+")":" ("+r(n,e.contractDescription)+")"),d.innerHTML=!c||i.test(e.symbol)?g:g.replace(i,"$&"),(_=document.createElement("td")).setAttribute("class","symbol-edit-popup-td type apply-overflow-tooltip"),m="",s.typeContent?m=s.typeContent:(e.params&&~e.params.indexOf("eod")&&(m='eod '),y=r(n,e.type),e.exchange?m+=y+" - "+o(e):m+=y),_.innerHTML=m,(v=document.createElement("td")).setAttribute("class","symbol-edit-popup-td flag apply-overflow-tooltip"),v.innerHTML=t.getItemFlag(e),(b=v.getElementsByTagName("svg")[0])&&b.setAttribute("class","flag"),a.appendChild(p),a.appendChild(d),a.appendChild(_),a.appendChild(v),a},t.getItemFlag=function(t){return""},V=function(t,i,n,s){!(i=l.displayedExchangesFilter(i)).some(function(t){return t.value===n})&&i.length>0&&(n=i[0].value);var o=$("