|
|
/*! * # Semantic UI 2.0.0 - Search * http://github.com/semantic-org/semantic-ui/
* * * Copyright 2015 Contributors * Released under the MIT license * http://opensource.org/licenses/MIT
* */ !function(e,t,s,n){"use strict";e.fn.search=function(r){var a,i=e(this),c=i.selector||"",o=(new Date).getTime(),u=[],l=arguments[0],d="string"==typeof l,f=[].slice.call(arguments,1);return e(this).each(function(){var g,p=e.isPlainObject(r)?e.extend(!0,{},e.fn.search.settings,r):e.extend({},e.fn.search.settings),v=p.className,h=p.metadata,m=p.regExp,b=p.selector,y=p.error,C=p.namespace,R="."+C,w=C+"-module",x=e(this),q=x.find(b.prompt),j=x.find(b.searchButton),k=x.find(b.results),A=(x.find(b.result),x.find(b.category),this),E=x.data(w);g={initialize:function(){g.verbose("Initializing module"),g.determine.searchFields(),g.bind.events(),g.set.type(),g.create.results(),g.instantiate()},instantiate:function(){g.verbose("Storing instance of module",g),E=g,x.data(w,g)},destroy:function(){g.verbose("Destroying instance"),x.off(R).removeData(w)},bind:{events:function(){g.verbose("Binding events to search"),p.automatic&&(x.on(g.get.inputEvent()+R,b.prompt,g.event.input),q.attr("autocomplete","off")),x.on("focus"+R,b.prompt,g.event.focus).on("blur"+R,b.prompt,g.event.blur).on("keydown"+R,b.prompt,g.handleKeyboard).on("click"+R,b.searchButton,g.query).on("mousedown"+R,b.results,g.event.result.mousedown).on("mouseup"+R,b.results,g.event.result.mouseup).on("click"+R,b.result,g.event.result.click)}},determine:{searchFields:function(){r&&r.searchFields!==n&&(p.searchFields=r.searchFields)}},event:{input:function(){clearTimeout(g.timer),g.timer=setTimeout(g.query,p.searchDelay)},focus:function(){g.set.focus(),g.has.minimumCharacters()&&(g.query(),g.showResults())},blur:function(e){var t=s.activeElement===this;t||g.resultsClicked||(g.cancel.query(),g.remove.focus(),g.timer=setTimeout(g.hideResults,p.hideDelay))},result:{mousedown:function(){g.resultsClicked=!0},mouseup:function(){g.resultsClicked=!1},click:function(s){g.debug("Search result selected");var n=e(this),r=n.find(b.title).eq(0),a=n.find("a[href]").eq(0),i=a.attr("href")||!1,c=a.attr("target")||!1,o=(r.html(),r.length>0?r.text():!1),u=g.get.results(),l=n.data(h.result)||g.get.result(o,u);return e.isFunction(p.onSelect)&&p.onSelect.call(A,l,u)===!1?void g.debug("Custom onSelect callback cancelled default select action"):(g.hideResults(),o&&g.set.value(o),void(i&&(g.verbose("Opening search link found in result",a),"_blank"==c||s.ctrlKey?t.open(i):t.location.href=i)))}}},handleKeyboard:function(e){var t,s=x.find(b.result),n=x.find(b.category),r=s.index(s.filter("."+v.active)),a=s.length,i=e.which,c={backspace:8,enter:13,escape:27,upArrow:38,downArrow:40};if(i==c.escape&&(g.verbose("Escape key pressed, blurring search field"),q.trigger("blur")),g.is.visible())if(i==c.enter){if(g.verbose("Enter key pressed, selecting active result"),s.filter("."+v.active).length>0)return g.event.result.click.call(s.filter("."+v.active),e),e.preventDefault(),!1}else i==c.upArrow?(g.verbose("Up key pressed, changing active result"),t=0>r-1?r:r-1,n.removeClass(v.active),s.removeClass(v.active).eq(t).addClass(v.active).closest(n).addClass(v.active),e.preventDefault()):i==c.downArrow&&(g.verbose("Down key pressed, changing active result"),t=r+1>=a?r:r+1,n.removeClass(v.active),s.removeClass(v.active).eq(t).addClass(v.active).closest(n).addClass(v.active),e.preventDefault());else i==c.enter&&(g.verbose("Enter key pressed, executing query"),g.query(),g.set.buttonPressed(),q.one("keyup",g.remove.buttonFocus))},setup:{api:function(){var e={debug:p.debug,on:!1,cache:"local",action:"search",onError:g.error};g.verbose("First request, initializing API"),x.api(e)}},can:{useAPI:function(){return e.fn.api!==n},transition:function(){return p.transition&&e.fn.transition!==n&&x.transition("is supported")}},is:{empty:function(){return""===k.html()},visible:function(){return k.filter(":visible").length>0},focused:function(){return q.filter(":focus").length>0}},get:{inputEvent:function(){var e=q[0],t=e!==n&&e.oninput!==n?"input":e!==n&&e.onpropertychange!==n?"propertychange":"keyup";return t},value:function(){return q.val()},results:function(){var e=x.data(h.results);return e},result:function(t,s){var r=["title","id"],a=
|