pgweb/static/js/bootstrap3-typeahead.min.js

1 line
9.1 KiB
JavaScript
Raw Normal View History

2017-10-06 10:15:44 -04:00
!function(a,b){"use strict";"undefined"!=typeof module&&module.exports?module.exports=b(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],function(a){return b(a)}):b(a.jQuery)}(this,function(a){"use strict";var b=function(c,d){this.$element=a(c),this.options=a.extend({},b.defaults,d),this.matcher=this.options.matcher||this.matcher,this.sorter=this.options.sorter||this.sorter,this.select=this.options.select||this.select,this.autoSelect="boolean"!=typeof this.options.autoSelect||this.options.autoSelect,this.highlighter=this.options.highlighter||this.highlighter,this.render=this.options.render||this.render,this.updater=this.options.updater||this.updater,this.displayText=this.options.displayText||this.displayText,this.source=this.options.source,this.delay=this.options.delay,this.$menu=a(this.options.menu),this.$appendTo=this.options.appendTo?a(this.options.appendTo):null,this.fitToElement="boolean"==typeof this.options.fitToElement&&this.options.fitToElement,this.shown=!1,this.listen(),this.showHintOnFocus=("boolean"==typeof this.options.showHintOnFocus||"all"===this.options.showHintOnFocus)&&this.options.showHintOnFocus,this.afterSelect=this.options.afterSelect,this.addItem=!1,this.value=this.$element.val()||this.$element.text(),this.keyPressed=!1};b.prototype={constructor:b,select:function(){var a=this.$menu.find(".active").data("value");if(this.$element.data("active",a),this.autoSelect||a){var b=this.updater(a);b||(b=""),this.$element.val(this.displayText(b)||b).text(this.displayText(b)||b).change(),this.afterSelect(b)}return this.hide()},updater:function(a){return a},setSource:function(a){this.source=a},show:function(){var b,c=a.extend({},this.$element.position(),{height:this.$element[0].offsetHeight}),d="function"==typeof this.options.scrollHeight?this.options.scrollHeight.call():this.options.scrollHeight;if(this.shown?b=this.$menu:this.$appendTo?(b=this.$menu.appendTo(this.$appendTo),this.hasSameParent=this.$appendTo.is(this.$element.parent())):(b=this.$menu.insertAfter(this.$element),this.hasSameParent=!0),!this.hasSameParent){b.css("position","fixed");var e=this.$element.offset();c.top=e.top,c.left=e.left}var f=a(b).parent().hasClass("dropup"),g=f?"auto":c.top+c.height+d,h=a(b).hasClass("dropdown-menu-right"),i=h?"auto":c.left;return b.css({top:g,left:i}).show(),!0===this.options.fitToElement&&b.css("width",this.$element.outerWidth()+"px"),this.shown=!0,this},hide:function(){return this.$menu.hide(),this.shown=!1,this},lookup:function(b){if(this.query=void 0!==b&&null!==b?b:this.$element.val()||this.$element.text()||"",this.query.length<this.options.minLength&&!this.options.showHintOnFocus)return this.shown?this.hide():this;var c=a.proxy(function(){a.isFunction(this.source)&&3===this.source.length?this.source(this.query,a.proxy(this.process,this),a.proxy(this.process,this)):a.isFunction(this.source)?this.source(this.query,a.proxy(this.process,this)):this.source&&this.process(this.source)},this);clearTimeout(this.lookupWorker),this.lookupWorker=setTimeout(c,this.delay)},process:function(b){var c=this;return b=a.grep(b,function(a){return c.matcher(a)}),b=this.sorter(b),b.length||this.options.addItem?(b.length>0?this.$element.data("active",b[0]):this.$element.data("active",null),"all"!=this.options.items&&(b=b.slice(0,this.options.items)),this.options.addItem&&b.push(this.options.addItem),this.render(b).show()):this.shown?this.hide():this},matcher:function(a){return~this.displayText(a).toLowerCase().indexOf(this.query.toLowerCase())},sorter:function(a){for(var b,c=[],d=[],e=[];b=a.shift();){var f=this.displayText(b);f.toLowerCase().indexOf(this.query.toLowerCase())?~f.indexOf(this.query)?d.push(b):e.push(b):c.push(b)}return c.concat(d,e)},highlighter:function(a){var b=this.query;if(""===b)return a;var c,d=a.match(/(>)([^<]*)(<)/g),e=[],f=[];if(d&&d.length)for(c=0;c<d.length;++c)d[c].length>2&&e.push(d[c]);else e=[],e.push(a);b=b.replace(/[\(\)\/\.\*\+\?\[\]]/g,function(a){return"\\"+a});var g,h=new RegExp(b,"g");for(c=0;c<e.length;++c)(g=e[c].match(h))&&g.length>0&&f.push(e[c]);for(c=0;c<f.leng