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