|
|
/*! * # 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 i,a=e(this),c=a.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,v=e.isPlainObject(r)?e.extend(!0,{},e.fn.search.settings,r):e.extend({},e.fn.search.settings),p=v.className,h=v.metadata,m=v.regExp,b=v.selector,y=v.error,R=v.namespace,w="."+R,C=R+"-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),F=x.data(C);g={initialize:function(){g.verbose("Initializing module"),g.determine.searchFields(),g.bind.events(),g.instantiate()},instantiate:function(){g.verbose("Storing instance of module",g),F=g,x.data(C,g)},destroy:function(){g.verbose("Destroying instance"),x.off(w).removeData(C)},bind:{events:function(){g.verbose("Binding events to search"),v.automatic&&(x.on(g.get.inputEvent()+w,b.prompt,g.event.input),q.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)}},determine:{searchFields:function(){r&&r.searchFields!==n&&(v.searchFields=r.searchFields)}},event:{input:function(){clearTimeout(g.timer),g.timer=setTimeout(g.query,v.searchDelay)},focus:function(){g.set.focus(),g.has.minimumCharacters()&&(g.query(),g.showResults())},blur:function(){var e=s.activeElement===this;e||g.resultsClicked||(g.cancel.query(),g.remove.focus(),g.timer=setTimeout(g.hideResults,v.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),i=n.find("a[href]").eq(0),a=i.attr("href")||!1,c=i.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(v.onSelect)&&v.onSelect.call(A,l,u)===!1?void g.debug("Custom onSelect callback cancelled default select action"):(g.hideResults(),o&&g.set.value(o),void(a&&(g.verbose("Opening search link found in result",i),"_blank"==c||s.ctrlKey?t.open(a):t.location.href=a)))}}},handleKeyboard:function(e){var t,s=x.find(b.result),n=x.find(b.category),r=s.index(s.filter("."+p.active)),i=s.length,a=e.which,c={backspace:8,enter:13,escape:27,upArrow:38,downArrow:40};if(a==c.escape&&(g.verbose("Escape key pressed, blurring search field"),q.trigger("blur")),g.is.visible())if(a==c.enter){if(g.verbose("Enter key pressed, selecting active result"),s.filter("."+p.active).length>0)return g.event.result.click.call(s.filter("."+p.active),e),e.preventDefault(),!1}else a==c.upArrow?(g.verbose("Up key pressed, changing active result"),t=0>r-1?r:r-1,n.removeClass(p.active),s.removeClass(p.active).eq(t).addClass(p.active).closest(n).addClass(p.active),e.preventDefault()):a==c.downArrow&&(g.verbose("Down key pressed, changing active result"),t=r+1>=i?r:r+1,n.removeClass(p.active),s.removeClass(p.active).eq(t).addClass(p.active).closest(n).addClass(p.active),e.preventDefault());else a==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:v.debug,on:!1,action:"search",onFailure:g.error};g.verbose("First request, initializing API"),x.api(e)}},can:{useAPI:function(){return e.fn.api!==n},transition:function(){return v.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"],i=!1;return t=t!==n?t:g.get.value(),s=s!==n?s:g
|