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