bazarr/static/semantic/components/search.min.js

1 line
17 KiB
JavaScript
Raw Normal View History

2017-09-28 01:55:21 +00:00
!function(e,t,s,n){"use strict";t=void 0!==t&&t.Math==Math?t:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),e.fn.search=function(n){var i,r=e(this),a=r.selector||"",o=(new Date).getTime(),c=[],u=arguments[0],l="string"==typeof u,d=[].slice.call(arguments,1);return e(this).each(function(){var f,v=e.isPlainObject(n)?e.extend(!0,{},e.fn.search.settings,n):e.extend({},e.fn.search.settings),g=v.className,h=v.metadata,p=v.regExp,m=v.fields,b=v.selector,y=v.error,R=v.namespace,C="."+R,w=R+"-module",x=e(this),F=x.find(b.prompt),j=x.find(b.searchButton),k=x.find(b.results),A=x.find(b.result),q=x.find(b.category),S=this,E=x.data(w),T=!1,D=!1;f={initialize:function(){f.verbose("Initializing module"),f.determine.searchFields(),f.bind.events(),f.set.type(),f.create.results(),f.instantiate()},instantiate:function(){f.verbose("Storing instance of module",f),E=f,x.data(w,f)},destroy:function(){f.verbose("Destroying instance"),x.off(C).removeData(w)},refresh:function(){f.debug("Refreshing selector cache"),F=x.find(b.prompt),j=x.find(b.searchButton),q=x.find(b.category),k=x.find(b.results),A=x.find(b.result)},refreshResults:function(){k=x.find(b.results),A=x.find(b.result)},bind:{events:function(){f.verbose("Binding events to search"),v.automatic&&(x.on(f.get.inputEvent()+C,b.prompt,f.event.input),F.attr("autocomplete","off")),x.on("focus"+C,b.prompt,f.event.focus).on("blur"+C,b.prompt,f.event.blur).on("keydown"+C,b.prompt,f.handleKeyboard).on("click"+C,b.searchButton,f.query).on("mousedown"+C,b.results,f.event.result.mousedown).on("mouseup"+C,b.results,f.event.result.mouseup).on("click"+C,b.result,f.event.result.click)}},determine:{searchFields:function(){n&&void 0!==n.searchFields&&(v.searchFields=n.searchFields)}},event:{input:function(){v.searchDelay?(clearTimeout(f.timer),f.timer=setTimeout(function(){f.is.focused()&&f.query()},v.searchDelay)):f.query()},focus:function(){f.set.focus(),v.searchOnFocus&&f.has.minimumCharacters()&&f.query(function(){f.can.show()&&f.showResults()})},blur:function(e){var t=s.activeElement===this,n=function(){f.cancel.query(),f.remove.focus(),f.timer=setTimeout(f.hideResults,v.hideDelay)};t||(D=!1,f.resultsClicked?(f.debug("Determining if user action caused search to close"),x.one("click.close"+C,b.results,function(e){if(f.is.inMessage(e)||T)return void F.focus();T=!1,f.is.animating()||f.is.hidden()||n()})):(f.debug("Input blurred without user action, closing results"),n()))},result:{mousedown:function(){f.resultsClicked=!0},mouseup:function(){f.resultsClicked=!1},click:function(s){f.debug("Search result selected");var n=e(this),i=n.find(b.title).eq(0),r=n.is("a[href]")?n:n.find("a[href]").eq(0),a=r.attr("href")||!1,o=r.attr("target")||!1,c=(i.html(),i.length>0&&i.text()),u=f.get.results(),l=n.data(h.result)||f.get.result(c,u);if(e.isFunction(v.onSelect)&&!1===v.onSelect.call(S,l,u))return f.debug("Custom onSelect callback cancelled default select action"),void(T=!0);f.hideResults(),c&&f.set.value(c),a&&(f.verbose("Opening search link found in result",r),"_blank"==o||s.ctrlKey?t.open(a):t.location.href=a)}}},handleKeyboard:function(e){var t,s=x.find(b.result),n=x.find(b.category),i=s.filter("."+g.active),r=s.index(i),a=s.length,o=i.length>0,c=e.which,u={backspace:8,enter:13,escape:27,upArrow:38,downArrow:40};if(c==u.escape&&(f.verbose("Escape key pressed, blurring search field"),f.hideResults(),D=!0),f.is.visible())if(c==u.enter){if(f.verbose("Enter key pressed, selecting active result"),s.filter("."+g.active).length>0)return f.event.result.click.call(s.filter("."+g.active),e),e.preventDefault(),!1}else c==u.upArrow&&o?(f.verbose("Up key pressed, changing active result"),t=r-1<0?r:r-1,n.removeClass(g.active),s.removeClass(g.active).eq(t).addClass(g.active).closest(n).addClass(g.active),e.preventDefault()):c==u.downArrow&&(f.verbose("Down key pressed, changing active result"),t=r+1>=a?r:r+1,n.removeClass(g.active),s.removeClass(g.active).eq(t).addClass(g.active).closest(n).addClass(g.active),e.preventDefault());else c==u.enter&&(f.verbose("Enter key pressed, executing query"),f.qu