You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openpower.foundation/themes/openpowerfoundation/static/lib/semantic-ui/components/search.min.js

1 line
17 KiB
JavaScript

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