This repository has been archived on 2024-01-26. You can view files and clone it, but cannot push or open issues or pull requests.
calcifer/web/semantic/dist/components/search.min.js

11 lines
13 KiB
JavaScript
Raw Normal View History

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