From 53d475285a6d042372ada8ba534b373d7a6e8686 Mon Sep 17 00:00:00 2001 From: Krister Date: Thu, 29 Oct 2020 10:29:33 +0100 Subject: [PATCH] update version so that dist folder reflects changes --- dist/bootstrap-suggest.css | 4 +- dist/bootstrap-suggest.js | 24 +- dist/bootstrap-suggest.min.js | 6 +- package-lock.json | 546 ++++++++++++++++++---------------- package.json | 2 +- 5 files changed, 311 insertions(+), 271 deletions(-) diff --git a/dist/bootstrap-suggest.css b/dist/bootstrap-suggest.css index 9ff70c6..744f7fd 100644 --- a/dist/bootstrap-suggest.css +++ b/dist/bootstrap-suggest.css @@ -1,6 +1,6 @@ /*! - * bootstra-suggest - v2.0.1 (https://github.com/lodev09/bootstrap-suggest#readme) - * Copyright 2013-2019 Jovanni Lo (lodev09@gmail.com) + * bootstra-suggest - v2.1.0 (https://github.com/lodev09/bootstrap-suggest#readme) + * Copyright 2013-2020 Jovanni Lo (lodev09@gmail.com) * Licensed under MIT (https://github.com/lodev09/bootstrap-suggest/blob/master/LICENSE) */ diff --git a/dist/bootstrap-suggest.js b/dist/bootstrap-suggest.js index a978209..3445636 100644 --- a/dist/bootstrap-suggest.js +++ b/dist/bootstrap-suggest.js @@ -180,12 +180,13 @@ for (var i = currentPos; i >= 0; i--) { var subChar = $.trim(val.substring(i-1, i)); - if (!subChar) { + if (!subChar && this.options.respectWhitespace) { this.hide(); break; } - if (subChar === this.key && $.trim(val.substring(i-2, i-1)) == '') { + var isSpaceBefore = $.trim(val.substring(i - 2, i - 1)) == ''; + if (subChar === this.key && (isSpaceBefore || !this.options.respectWhitespace)) { this.query = val.substring(i, currentPos); this._queryPos = [i, currentPos]; this._keyPos = i; @@ -223,6 +224,7 @@ if (that.isShown) { switch (e.keyCode) { case 13: // enter key + case 9: // tab key $visibleItems = that.__getVisibleItems(); $visibleItems.each(function(index) { if ($(this).is('.active')) @@ -277,7 +279,8 @@ var itemHtml, that = this, _item = { text: '', - value: '' + value: '', + class: '' }; if (this.options.map) { @@ -288,13 +291,14 @@ if (dataItem instanceof Object) { _item.text = dataItem.text || ''; _item.value = dataItem.value || ''; + _item.class = dataItem.class || ''; } else { _item.text = dataItem; _item.value = dataItem; } return $('', { - 'class': 'dropdown-item', + 'class': 'dropdown-item' + ' ' + _item.class, 'data-value': _item.value, href: '#', html: _item.text @@ -302,13 +306,15 @@ }, __select: function(index) { + var endKey = this.options.endKey || ''; var $el = this.$element, el = $el.get(0), val = $el.val(), item = this.get(index), setCaretPos = this._keyPos + item.value.length + 1; - $el.val(val.slice(0, this._keyPos) + item.value + ' ' + val.slice(this.__getSelection(el).start)); + $el.val(val.slice(0, this._keyPos) + item.value + endKey + ' ' + val.slice(this.__getSelection(el).start)); + $el.blur(); if (el.setSelectionRange) { el.setSelectionRange(setCaretPos, setCaretPos); @@ -372,12 +378,14 @@ if (q === '') return index < options.filter.limit; var value = $(this).text(); + var selectorValue = $(this).data().value; if (!options.filter.casesensitive) { value = value.toLowerCase(); q = q.toLowerCase(); + selectorValue = selectorValue.toLowerCase(); } - return value.indexOf(q) != -1; + return value.indexOf(q) != -1 || selectorValue.indexOf(q) != -1; }).slice(0, options.filter.limit).removeClass('d-none active'); return this.__getVisibleItems(); }, @@ -574,6 +582,8 @@ }, dropdownClass: '', position: 'caret', + endKey: '', + respectWhitespace: true, // events hook onshow: function(e) {}, onselect: function(e, item) {}, @@ -588,4 +598,4 @@ return this; } -}( jQuery )); \ No newline at end of file +}( jQuery )); diff --git a/dist/bootstrap-suggest.min.js b/dist/bootstrap-suggest.min.js index 036ad6d..aef8f8a 100644 --- a/dist/bootstrap-suggest.min.js +++ b/dist/bootstrap-suggest.min.js @@ -1,7 +1,7 @@ /*! - * bootstra-suggest - v2.0.1 (https://github.com/lodev09/bootstrap-suggest#readme) - * Copyright 2013-2019 Jovanni Lo (lodev09@gmail.com) + * bootstra-suggest - v2.1.0 (https://github.com/lodev09/bootstrap-suggest#readme) + * Copyright 2013-2020 Jovanni Lo (lodev09@gmail.com) * Licensed under MIT (https://github.com/lodev09/bootstrap-suggest/blob/master/LICENSE) */ -!function(l){"use strict";var a=function(t,e,i){this.$element=l(t),this.$items=void 0,this.options=l.extend(!0,{},l.fn.suggest.defaults,i,this.$element.data(),this.$element.data("options")),this.key=e,this.isShown=!1,this.query="",this._queryPos=[],this._keyPos=-1,this.$dropdown=l("
",{class:"dropdown suggest "+this.options.dropdownClass,html:l("
",{class:"dropdown-menu",role:"menu"}),"data-key":this.key}),this.load()};a.prototype={__setListener:function(){return this.$element.on("suggest.show",l.proxy(this.options.onshow,this)).on("suggest.select",l.proxy(this.options.onselect,this)).on("suggest.lookup",l.proxy(this.options.onlookup,this)).on("keyup",l.proxy(this.__keyup,this)),this},__getCaretPos:function(t){var h=["direction","boxSizing","width","height","overflowX","overflowY","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","paddingTop","paddingRight","paddingBottom","paddingLeft","fontStyle","fontVariant","fontWeight","fontStretch","fontSize","fontSizeAdjust","lineHeight","fontFamily","textAlign","textTransform","textIndent","textDecoration","letterSpacing","wordSpacing"],d=!(null==window.mozInnerScreenX);return function(t,e,i){var o=document.createElement("div");o.id="input-textarea-caret-position-mirror-div",document.body.appendChild(o);var s=o.style,n=window.getComputedStyle?getComputedStyle(t):t.currentStyle;s.whiteSpace="pre-wrap","INPUT"!==t.nodeName&&(s.wordWrap="break-word"),s.position="absolute",s.visibility="hidden",l.each(h,function(t,e){s[e]=n[e]}),d?(s.width=parseInt(n.width)-2+"px",t.scrollHeight>parseInt(n.height)&&(s.overflowY="scroll")):s.overflow="hidden",o.textContent=t.value.substring(0,e),"INPUT"===t.nodeName&&(o.textContent=o.textContent.replace(/\s/g," "));var r=document.createElement("span");r.textContent=t.value.substring(e)||".",o.appendChild(r);var a={top:r.offsetTop+parseInt(n.borderTopWidth),left:r.offsetLeft+parseInt(n.borderLeftWidth)};return document.body.removeChild(o),a}(this.$element.get(0),t)},__keyup:function(t){switch(t.keyCode){case 27:return void this.hide();case 13:return!0}if(-1===l.inArray(t.keyCode,[38,40,37,39,17,18,9,16,20,91,93,36,35,45,33,34,144,112,113,114,115,116,117,118,119,120,121,122,123,145,19]))for(var e=this.$element,i=e.val(),o=this.__getSelection(e.get(0)).start,s=o;0<=s;s--){var n=l.trim(i.substring(s-1,s));if(!n){this.hide();break}if(n===this.key&&""==l.trim(i.substring(s-2,s-1))){this.query=i.substring(s,o),this._queryPos=[s,o],this._keyPos=s,this.lookup(this.query);break}}},__getVisibleItems:function(){return this.$items?this.$items.not(".d-none"):l()},__build:function(){var t=this.$dropdown,e=this,i=function(t){e.hide()};t.on("click","a.dropdown-item",function(t){t.preventDefault(),e.__select(l(this).index()),e.$element.focus()}).on("mouseover","a.dropdown-item",function(t){e.$element.off("blur",i)}).on("mouseout","a.dropdown-item",function(t){e.$element.on("blur",i)}),this.$element.before(t).on("blur",i).on("keydown",function(t){var o;if(e.isShown)switch(t.keyCode){case 13:return(o=e.__getVisibleItems()).each(function(t){l(this).is(".active")&&e.__select(l(this).index())}),!1;case 40:return(o=e.__getVisibleItems()).last().is(".active")||o.each(function(t){var e=l(this),i=o.eq(t+1);if(e.is(".active"))return i.is(".d-none")||(e.removeClass("active"),i.addClass("active")),!1}),!1;case 38:return(o=e.__getVisibleItems()).first().is(".active")||o.each(function(t){var e=l(this),i=o.eq(t-1);if(e.is(".active"))return i.is(".d-none")||(e.removeClass("active"),i.addClass("active")),!1}),!1}})},__mapItem:function(t){var e={text:"",value:""};return!(this.options.map&&!(t=this.options.map(t)))&&(t instanceof Object?(e.text=t.text||"",e.value=t.value||""):(e.text=t,e.value=t),l("",{class:"dropdown-item","data-value":e.value,href:"#",html:e.text}))},__select:function(t){var e=this.$element,i=e.get(0),o=e.val(),s=this.get(t),n=this._keyPos+s.value.length+1;if(e.val(o.slice(0,this._keyPos)+s.value+" "+o.slice(this.__getSelection(i).start)),i.setSelectionRange)i.setSelectionRange(n,n);else if(i.createTextRange){var r=i.createTextRange();r.collapse(!0),r.moveEnd("character",n),r.moveStart("character",n),r.select()}e.trigger(l.extend({type:"suggest.select"},this),s),this.hide()},__getSelection:function(t){return t.focus(),{start:t.selectionStart,end:t.selectionEnd}},__buildItems:function(t){var e=this.$dropdown.find(".dropdown-menu");if(e.empty(),t&&t instanceof Array)for(var i in t){var o=this.__mapItem(t[i]);o&&e.append(o)}return e.find("a.dropdown-item")},__lookup:function(t,e){e.eq(0).addClass("active");this.$element.trigger(l.extend({type:"suggest.lookup"},this),[t,e]),e&&e.length?this.show():this.hide()},__filterData:function(i,t){var o=this.options;return this.$items.addClass("d-none"),this.$items.filter(function(t){if(""===i)return t",{class:"dropdown suggest "+this.options.dropdownClass,html:l("
",{class:"dropdown-menu",role:"menu"}),"data-key":this.key}),this.load()};a.prototype={__setListener:function(){return this.$element.on("suggest.show",l.proxy(this.options.onshow,this)).on("suggest.select",l.proxy(this.options.onselect,this)).on("suggest.lookup",l.proxy(this.options.onlookup,this)).on("keyup",l.proxy(this.__keyup,this)),this},__getCaretPos:function(t){var h=["direction","boxSizing","width","height","overflowX","overflowY","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","paddingTop","paddingRight","paddingBottom","paddingLeft","fontStyle","fontVariant","fontWeight","fontStretch","fontSize","fontSizeAdjust","lineHeight","fontFamily","textAlign","textTransform","textIndent","textDecoration","letterSpacing","wordSpacing"],d=!(null==window.mozInnerScreenX);return function(t,e,i){var s=document.createElement("div");s.id="input-textarea-caret-position-mirror-div",document.body.appendChild(s);var o=s.style,n=window.getComputedStyle?getComputedStyle(t):t.currentStyle;o.whiteSpace="pre-wrap","INPUT"!==t.nodeName&&(o.wordWrap="break-word"),o.position="absolute",o.visibility="hidden",l.each(h,function(t,e){o[e]=n[e]}),d?(o.width=parseInt(n.width)-2+"px",t.scrollHeight>parseInt(n.height)&&(o.overflowY="scroll")):o.overflow="hidden",s.textContent=t.value.substring(0,e),"INPUT"===t.nodeName&&(s.textContent=s.textContent.replace(/\s/g," "));var r=document.createElement("span");r.textContent=t.value.substring(e)||".",s.appendChild(r);var a={top:r.offsetTop+parseInt(n.borderTopWidth),left:r.offsetLeft+parseInt(n.borderLeftWidth)};return document.body.removeChild(s),a}(this.$element.get(0),t)},__keyup:function(t){switch(t.keyCode){case 27:return void this.hide();case 13:return!0}if(-1===l.inArray(t.keyCode,[38,40,37,39,17,18,9,16,20,91,93,36,35,45,33,34,144,112,113,114,115,116,117,118,119,120,121,122,123,145,19]))for(var e=this.$element,i=e.val(),s=this.__getSelection(e.get(0)).start,o=s;0<=o;o--){var n=l.trim(i.substring(o-1,o));if(!n&&this.options.respectWhitespace){this.hide();break}var r=""==l.trim(i.substring(o-2,o-1));if(n===this.key&&(r||!this.options.respectWhitespace)){this.query=i.substring(o,s),this._queryPos=[o,s],this._keyPos=o,this.lookup(this.query);break}}},__getVisibleItems:function(){return this.$items?this.$items.not(".d-none"):l()},__build:function(){var t=this.$dropdown,e=this,i=function(t){e.hide()};t.on("click","a.dropdown-item",function(t){t.preventDefault(),e.__select(l(this).index()),e.$element.focus()}).on("mouseover","a.dropdown-item",function(t){e.$element.off("blur",i)}).on("mouseout","a.dropdown-item",function(t){e.$element.on("blur",i)}),this.$element.before(t).on("blur",i).on("keydown",function(t){var s;if(e.isShown)switch(t.keyCode){case 13:case 9:return(s=e.__getVisibleItems()).each(function(t){l(this).is(".active")&&e.__select(l(this).index())}),!1;case 40:return(s=e.__getVisibleItems()).last().is(".active")||s.each(function(t){var e=l(this),i=s.eq(t+1);if(e.is(".active"))return i.is(".d-none")||(e.removeClass("active"),i.addClass("active")),!1}),!1;case 38:return(s=e.__getVisibleItems()).first().is(".active")||s.each(function(t){var e=l(this),i=s.eq(t-1);if(e.is(".active"))return i.is(".d-none")||(e.removeClass("active"),i.addClass("active")),!1}),!1}})},__mapItem:function(t){var e={text:"",value:"",class:""};return!(this.options.map&&!(t=this.options.map(t)))&&(t instanceof Object?(e.text=t.text||"",e.value=t.value||"",e.class=t.class||""):(e.text=t,e.value=t),l("",{class:"dropdown-item "+e.class,"data-value":e.value,href:"#",html:e.text}))},__select:function(t){var e=this.options.endKey||"",i=this.$element,s=i.get(0),o=i.val(),n=this.get(t),r=this._keyPos+n.value.length+1;if(i.val(o.slice(0,this._keyPos)+n.value+e+" "+o.slice(this.__getSelection(s).start)),i.blur(),s.setSelectionRange)s.setSelectionRange(r,r);else if(s.createTextRange){var a=s.createTextRange();a.collapse(!0),a.moveEnd("character",r),a.moveStart("character",r),a.select()}i.trigger(l.extend({type:"suggest.select"},this),n),this.hide()},__getSelection:function(t){return t.focus(),{start:t.selectionStart,end:t.selectionEnd}},__buildItems:function(t){var e=this.$dropdown.find(".dropdown-menu");if(e.empty(),t&&t instanceof Array)for(var i in t){var s=this.__mapItem(t[i]);s&&e.append(s)}return e.find("a.dropdown-item")},__lookup:function(t,e){e.eq(0).addClass("active");this.$element.trigger(l.extend({type:"suggest.lookup"},this),[t,e]),e&&e.length?this.show():this.hide()},__filterData:function(s,t){var o=this.options;return this.$items.addClass("d-none"),this.$items.filter(function(t){if(""===s)return t