wishthis/node_modules/fomantic-ui/dist/components/search.min.js

11 lines
19 KiB
JavaScript
Raw Normal View History

2022-01-13 13:00:31 +00:00
/*
2022-05-29 09:24:36 +00:00
* # Fomantic UI - 2.8.8
2022-01-13 13:00:31 +00:00
* https://github.com/fomantic/Fomantic-UI
* http://fomantic-ui.com/
*
2022-05-29 09:24:36 +00:00
* Copyright 2021 Contributors
2022-01-13 13:00:31 +00:00
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
*/
2022-05-29 09:24:36 +00:00
!function(q,k,D,E){"use strict";q.isFunction=q.isFunction||function(e){return"function"==typeof e&&"number"!=typeof e.nodeType},k=void 0!==k&&k.Math==Math?k:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),q.fn.search=function(u){var x,C=q(this),w=C.selector||"",S=(new Date).getTime(),T=[],F=u,j="string"==typeof F,A=[].slice.call(arguments,1);return q(this).each(function(){var f,l=q.isPlainObject(u)?q.extend(!0,{},q.fn.search.settings,u):q.extend({},q.fn.search.settings),g=l.className,d=l.metadata,n=l.regExp,i=l.fields,h=l.selector,p=l.error,e=l.namespace,r="."+e,t=e+"-module",m=q(this),v=m.find(h.prompt),s=m.find(h.searchButton),a=m.find(h.results),o=m.find(h.result),y=(m.find(h.category),this),c=m.data(t),b=!1,R=!1;f={initialize:function(){f.verbose("Initializing module"),f.get.settings(),f.determine.searchFields(),f.bind.events(),f.set.type(),f.create.results(),f.instantiate()},instantiate:function(){f.verbose("Storing instance of module",f),c=f,m.data(t,f)},destroy:function(){f.verbose("Destroying instance"),m.off(r).removeData(t)},refresh:function(){f.debug("Refreshing selector cache"),v=m.find(h.prompt),s=m.find(h.searchButton),m.find(h.category),a=m.find(h.results),o=m.find(h.result)},refreshResults:function(){a=m.find(h.results),o=m.find(h.result)},bind:{events:function(){f.verbose("Binding events to search"),l.automatic&&(m.on(f.get.inputEvent()+r,h.prompt,f.event.input),v.attr("autocomplete",f.is.chrome()?"fomantic-search":"off")),m.on("focus"+r,h.prompt,f.event.focus).on("blur"+r,h.prompt,f.event.blur).on("keydown"+r,h.prompt,f.handleKeyboard).on("click"+r,h.searchButton,f.query).on("mousedown"+r,h.results,f.event.result.mousedown).on("mouseup"+r,h.results,f.event.result.mouseup).on("click"+r,h.result,f.event.result.click)}},determine:{searchFields:function(){u&&u.searchFields!==E&&(l.searchFields=u.searchFields)}},event:{input:function(){l.searchDelay?(clearTimeout(f.timer),f.timer=setTimeout(function(){f.is.focused()&&f.query()},l.searchDelay)):f.query()},focus:function(){f.set.focus(),l.searchOnFocus&&f.has.minimumCharacters()&&f.query(function(){f.can.show()&&f.showResults()})},blur:function(e){function t(){f.cancel.query(),f.remove.focus(),f.timer=setTimeout(f.hideResults,l.hideDelay)}var s=D.activeElement===this;s||(R=!1,f.resultsClicked?(f.debug("Determining if user action caused search to close"),m.one("click.close"+r,h.results,function(e){f.is.inMessage(e)||b?v.focus():(b=!1,f.is.animating()||f.is.hidden()||t())})):(f.debug("Input blurred without user action, closing results"),t()))},result:{mousedown:function(){f.resultsClicked=!0},mouseup:function(){f.resultsClicked=!1},click:function(e){f.debug("Search result selected");var t=q(this),s=t.find(h.title).eq(0),n=t.is("a[href]")?t:t.find("a[href]").eq(0),r=n.attr("href")||!1,i=n.attr("target")||!1,a=0<s.length&&s.text(),o=f.get.results(),c=t.data(d.result)||f.get.result(a,o),u=f.get.value();if(q.isFunction(l.onSelect)&&!1===l.onSelect.call(y,c,o))return f.debug("Custom onSelect callback cancelled default select action"),void(b=!0);f.hideResults(),a&&f.get.value()===u&&f.set.value(a),r&&(e.preventDefault(),f.verbose("Opening search link found in result",n),"_blank"==i||e.ctrlKey?k.open(r):k.location.href=r)}}},ensureVisible:function(e){var t,s,n,r;0!==e.length&&(s=(t=e.position().top)+e.outerHeight(!0),n=a.scrollTop(),r=a.height(),t<0?a.scrollTop(n+t):r<s&&a.scrollTop(n+(s-r)))},handleKeyboard:function(e){var t,s=m.find(h.result),n=m.find(h.category),r=s.filter("."+g.active),i=s.index(r),a=s.length,o=0<r.length,c=e.which,u=13,l=38,d=40;if(c==27&&(f.verbose("Escape key pressed, blurring search field"),f.hideResults(),R=!0),f.is.visible())if(c==u){if(f.verbose("Enter key pressed, selecting active result"),0<s.filter("."+g.active).length)return f.event.result.click.call(s.filter("."+g.active),e),e.preventDefault(),!1}else c==l&&o?(f.verbose("Up key pressed, changing active result"),t=i-1<0?i:i-1,n.removeClass(g.active),s.removeClass(g.active).eq(t).addClass(g.active).closest(n).addClass(g.active),f.ensureVisible(s.eq(t)),e.preventD