mirror of
https://github.com/j-a-n/raspberrymatic-addon-rmupdate.git
synced 2023-10-10 13:37:40 +02:00
1 line
17 KiB
JavaScript
1 line
17 KiB
JavaScript
|
!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 f,u=q.isPlainObject(o)?q.extend(!0,{},q.fn.search.settings,o):q.extend({},q.fn.search.settings),g=u.className,l=u.metadata,d=u.regExp,i=u.fields,h=u.selector,p=u.error,e=u.namespace,n="."+e,t=e+"-module",m=q(this),v=m.find(h.prompt),s=m.find(h.searchButton),r=m.find(h.results),a=m.find(h.result),y=(m.find(h.category),this),c=m.data(t),b=!1,R=!1;f={initialize:function(){f.verbose("Initializing module"),f.get.settings(),f.determine.searchFields(),f.bind.events(),f.set.type(),f.create.results(),f.instantiate()},instantiate:function(){f.verbose("Storing instance of module",f),c=f,m.data(t,f)},destroy:function(){f.verbose("Destroying instance"),m.off(n).removeData(t)},refresh:function(){f.debug("Refreshing selector cache"),v=m.find(h.prompt),s=m.find(h.searchButton),m.find(h.category),r=m.find(h.results),a=m.find(h.result)},refreshResults:function(){r=m.find(h.results),a=m.find(h.result)},bind:{events:function(){f.verbose("Binding events to search"),u.automatic&&(m.on(f.get.inputEvent()+n,h.prompt,f.event.input),v.attr("autocomplete","off")),m.on("focus"+n,h.prompt,f.event.focus).on("blur"+n,h.prompt,f.event.blur).on("keydown"+n,h.prompt,f.handleKeyboard).on("click"+n,h.searchButton,f.query).on("mousedown"+n,h.results,f.event.result.mousedown).on("mouseup"+n,h.results,f.event.result.mouseup).on("click"+n,h.result,f.event.result.click)}},determine:{searchFields:function(){o&&o.searchFields!==D&&(u.searchFields=o.searchFields)}},event:{input:function(){u.searchDelay?(clearTimeout(f.timer),f.timer=setTimeout(function(){f.is.focused()&&f.query()},u.searchDelay)):f.query()},focus:function(){f.set.focus(),u.searchOnFocus&&f.has.minimumCharacters()&&f.query(function(){f.can.show()&&f.showResults()})},blur:function(e){var t=E.activeElement===this,s=function(){f.cancel.query(),f.remove.focus(),f.timer=setTimeout(f.hideResults,u.hideDelay)};t||(R=!1,f.resultsClicked?(f.debug("Determining if user action caused search to close"),m.one("click.close"+n,h.results,function(e){f.is.inMessage(e)||b?v.focus():(b=!1,f.is.animating()||f.is.hidden()||s())})):(f.debug("Input blurred without user action, closing results"),s()))},result:{mousedown:function(){f.resultsClicked=!0},mouseup:function(){f.resultsClicked=!1},click:function(e){f.debug("Search result selected");var t=q(this),s=t.find(h.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=f.get.results(),o=t.data(l.result)||f.get.result(a,c);if(q.isFunction(u.onSelect)&&!1===u.onSelect.call(y,o,c))return f.debug("Custom onSelect callback cancelled default select action"),void(b=!0);f.hideResults(),a&&f.set.value(a),r&&(f.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=m.find(h.result),n=m.find(h.category),r=s.filter("."+g.active),i=s.index(r),a=s.length,c=0<r.length,o=e.which,u=13,l=38,d=40;if(o==27&&(f.verbose("Escape key pressed, blurring search field"),f.hideResults(),R=!0),f.is.visible())if(o==u){if(f.verbose("Enter key pressed, selecting active result"),0<s.filter("."+g.active).length)return f.event.result.click.call(s.filter("."+g.active),e),e.preventDefault(),!1}else o==l&&c?(f.verbose("Up key pressed, changing active result"),t=i-1<0?i:i-1,n.removeClass(g.active),s.removeClass(g.active).eq(t).addClass(g.active).closest(n).addClass(g.active),e.preventDefault()):o==d&&(f.verbose("Down key pressed, changing active result"),t=a<=i+1?i:i+1,n.removeClass(g.active),s.removeClass(g.active).eq(t).addClass(g.active).closest(n).addClass(g.active),e.preventDefault());else o==u&&(f.verbose("Enter key pressed, executing query"),f.query(),f.set.buttonPressed(),v.one("keyup",f.remove.buttonFocus))},setup:{api:function(t,s){var
|