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

11 lines
20 KiB
JavaScript
Raw Normal View History

2022-01-13 13:00:31 +00:00
/*
2023-08-17 09:47:40 +00:00
* # Fomantic UI - 2.9.2
2022-01-13 13:00:31 +00:00
* https://github.com/fomantic/Fomantic-UI
2023-08-17 09:47:40 +00:00
* https://fomantic-ui.com/
2022-01-13 13:00:31 +00:00
*
2023-08-17 09:47:40 +00:00
* Copyright 2023 Contributors
2022-01-13 13:00:31 +00:00
* Released under the MIT license
2023-08-17 09:47:40 +00:00
* https://opensource.org/licenses/MIT
2022-01-13 13:00:31 +00:00
*
*/
2023-08-17 09:47:40 +00:00
!function(F,k,D){"use strict";function E(e){return"function"==typeof e&&"number"!=typeof e.nodeType}k=void 0!==k&&k.Math===Math?k:globalThis,F.fn.search=function(R){var S,x=F(this),C=x.selector||"",w=Date.now(),T=[],A=R,j="string"==typeof A,q=[].slice.call(arguments,1);return x.each(function(){var d=F.isPlainObject(R)?F.extend(!0,{},F.fn.search.settings,R):F.extend({},F.fn.search.settings),f=d.className,c=d.metadata,r=d.regExp,i=d.fields,g=d.selector,h=d.error,e=d.namespace,n="."+e,t=e+"-module",v=F(this),p=v.find(g.prompt),s=v.find(g.searchButton),a=v.find(g.results),o=v.find(g.result),u=(v.find(g.category),this),l=v.data(t),m=!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),l=b,v.data(t,b)},destroy:function(){b.verbose("Destroying instance"),v.off(n).removeData(t)},refresh:function(){b.debug("Refreshing selector cache"),p=v.find(g.prompt),s=v.find(g.searchButton),v.find(g.category),a=v.find(g.results),o=v.find(g.result)},refreshResults:function(){a=v.find(g.results),o=v.find(g.result)},bind:{events:function(){b.verbose("Binding events to search"),d.automatic&&(v.on(b.get.inputEvent()+n,g.prompt,b.event.input),p.attr("autocomplete",b.is.chrome()?"fomantic-search":"off")),v.on("focus"+n,g.prompt,b.event.focus).on("blur"+n,g.prompt,b.event.blur).on("keydown"+n,g.prompt,b.handleKeyboard).on("click"+n,g.searchButton,b.query).on("mousedown"+n,g.results,b.event.result.mousedown).on("mouseup"+n,g.results,b.event.result.mouseup).on("click"+n,g.result,b.event.result.click)}},determine:{searchFields:function(){R&&void 0!==R.searchFields&&(d.searchFields=R.searchFields)}},event:{input:function(){d.searchDelay?(clearTimeout(b.timer),b.timer=setTimeout(function(){b.is.focused()&&b.query()},d.searchDelay)):b.query()},focus:function(){b.set.focus(),d.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,d.hideDelay)}var s=D.activeElement===this;s||(y=!1,b.resultsClicked?(b.debug("Determining if user action caused search to close"),v.one("click.close"+n,g.results,function(e){b.is.inMessage(e)||m?p.trigger("focus"):(m=!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=F(this),s=t.find(g.title).eq(0),r=t.is("a[href]")?t:t.find("a[href]").eq(0),n=r.attr("href")||!1,i=r.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(E(d.onSelect)&&!1===d.onSelect.call(u,t,a))return b.debug("Custom onSelect callback cancelled default select action"),void(m=!0);b.hideResults(),s&&b.get.value()===o&&b.set.value(s),n&&(e.preventDefault(),b.verbose("Opening search link found in result",r),"_blank"===i||e.ctrlKey?k.open(n):k.location.href=n)}}},ensureVisible:function(e){var t,s,r;0!==e.length&&(e=(t=e.position().top)+e.outerHeight(!0),s=a.scrollTop(),r=a.height(),t<0?a.scrollTop(s+t):r<e&&a.scrollTop(s+(e-r)))},handleKeyboard:function(e){var t,s=v.find(g.result),r=v.find(g.category),n=s.filter("."+f.active),i=s.index(n),a=s.length,n=0<n.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"),p.trigger("blur")),e.stopPropagation(),y=!0),b.is.visible())if(o===c){if(b.verbose("Enter key pressed, selecting active result"),0<s.filter("."+f.active).length)return b.event.result.click.call(s.filter("."+f.active),e),e.preventDefault(),!1}else o===u&&n?(b.verbose("Up key pressed, changing active result"),t=i-1<0?i:i-1,r.removeClass(f.active),s.removeClass(f.active).eq(t).addClass(f.active).closest(r).addClass(f.active),b.ensureVisible(s.eq(t)),e.preventDefault()):o===l&&(b.verbose("Down key pressed,