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