From ff7552cbfae19941c6c96ac6315493b5df67e9a0 Mon Sep 17 00:00:00 2001 From: Zarino Zappia Date: Tue, 29 May 2018 14:26:49 +0100 Subject: [PATCH 1/2] Alias HTMLElement->Element in IE8 polyfill --- example/js/taggle.min.js | 2 +- src/taggle-ie8.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/example/js/taggle.min.js b/example/js/taggle.min.js index 29efd04..4e26630 100644 --- a/example/js/taggle.min.js +++ b/example/js/taggle.min.js @@ -5,4 +5,4 @@ * @license MIT * @description Taggle is a dependency-less tagging library */ -!function(){Function.prototype.bind||(Function.prototype.bind=function(a){if("function"!=typeof this)throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");var b=Array.prototype.slice.call(arguments,1),c=this,d=function(){},e=function(){return c.apply(this instanceof d&&a?this:a,b.concat(Array.prototype.slice.call(arguments)))};return d.prototype=this.prototype,e.prototype=new d,e}),window.getComputedStyle||(window.getComputedStyle=function(a){return a.currentStyle}),Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b,c,d=Object(this),e=d.length>>>0;if(0===e)return-1;if(b=0,arguments.length>1&&(b=Number(arguments[1]),b!=b?b=0:0!=b&&b!=1/0&&b!=-(1/0)&&(b=(b>0||-1)*Math.floor(Math.abs(b)))),b>=e)return-1;for(c=b>=0?b:Math.max(e-Math.abs(b),0);e>c;c++)if(c in d&&d[c]===a)return c;return-1}),Array.prototype.forEach||(Array.prototype.forEach=function(a,b){var c,d;if(null==this)throw new TypeError(" this is null or not defined");var e=Object(this),f=e.length>>>0;if("function"!=typeof a)throw new TypeError(a+" is not a function");for(arguments.length>1&&(c=b),d=0;f>d;){var g;d in e&&(g=e[d],a.call(c,g,d,e)),d++}}),Array.prototype.map||(Array.prototype.map=function(a,b){var c,d,e;if(null==this)throw new TypeError(" this is null or not defined");var f=Object(this),g=f.length>>>0;if("function"!=typeof a)throw new TypeError(a+" is not a function");for(arguments.length>1&&(c=b),d=new Array(g),e=0;g>e;){var h,i;e in f&&(h=f[e],i=a.call(c,h,e,f),d[e]=i),e++}return d})}(),function(){"undefined"==typeof document||"classList"in document.documentElement||!function(a){"use strict";if("HTMLElement"in a||"Element"in a){var b="classList",c="prototype",d=(a.HTMLElement||a.Element)[c],e=Object,f=String[c].trim||function(){return this.replace(/^\s+|\s+$/g,"")},g=Array[c].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1},h=function(a,b){this.name=a,this.code=DOMException[a],this.message=b},i=function(a,b){if(""===b)throw new h("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(b))throw new h("INVALID_CHARACTER_ERR","String contains an invalid character");return g.call(a,b)},j=function(a){for(var b=f.call(a.className),c=b?b.split(/\s+/):[],d=0,e=c.length;e>d;d++)this.push(c[d]);this._updateClassName=function(){a.className=this.toString()}},k=j[c]=[],l=function(){return new j(this)};if(h[c]=Error[c],k.item=function(a){return this[a]||null},k.contains=function(a){return a+="",-1!==i(this,a)},k.add=function(){var a,b=arguments,c=0,d=b.length,e=!1;do a=b[c]+"",-1===i(this,a)&&(this.push(a),e=!0);while(++cb;b++){var d=arguments[b];for(var e in d)d.hasOwnProperty(e)&&(a[e]=d[e])}return a}function b(a){return Array.isArray?Array.isArray(a):"[object Array]"===Object.prototype.toString.call(a)}function c(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent?a.attachEvent("on"+b,c):a["on"+b]=c}function d(a,b,c){a.removeEventListener?a.removeEventListener(b,c,!1):a.detachEvent?a.detachEvent("on"+b,c):a["on"+b]=null}function e(a){return a.replace(/^\s+|\s+$/g,"")}function f(a,b){window.attachEvent&&!window.addEventListener?a.innerText=b:a.textContent=b}var g=function(){},h=function(){return!0},i=8,j=188,k=9,l=13,m={additionalTagClasses:"",allowDuplicates:!1,saveOnBlur:!1,clearOnBlur:!0,duplicateTagClass:"",containerFocusClass:"active",focusInputOnContainerClick:!0,hiddenInputName:"taggles[]",tags:[],delimeter:",",delimiter:"",attachTagId:!1,allowedTags:[],disallowedTags:[],maxTags:null,tabIndex:1,placeholder:"Enter tags...",submitKeys:[j,k,l],preserveCase:!1,inputFormatter:g,tagFormatter:g,onBeforeTagAdd:g,onTagAdd:g,onBeforeTagRemove:h,onTagRemove:g},n=function(b,c){this.settings=a({},m,c),this.measurements={container:{rect:null,style:null,padding:null}},this.container=b,this.tag={values:[],elements:[]},this.list=document.createElement("ul"),this.inputLi=document.createElement("li"),this.input=document.createElement("input"),this.sizer=document.createElement("div"),this.pasting=!1,this.placeholder=null,this.data=null,this.settings.placeholder&&(this.placeholder=document.createElement("span")),"string"==typeof b&&(this.container=document.getElementById(b)),this._id=0,this._closeEvents=[],this._closeButtons=[],this._setMeasurements(),this._setupTextarea(),this._attachEvents()};return n.prototype._setMeasurements=function(){this.measurements.container.rect=this.container.getBoundingClientRect(),this.measurements.container.style=window.getComputedStyle(this.container);var a=this.measurements.container.style,b=parseInt(a["padding-left"]||a.paddingLeft,10),c=parseInt(a["padding-right"]||a.paddingRight,10),d=parseInt(a["border-left-width"]||a.borderLeftWidth,10),e=parseInt(a["border-right-width"]||a.borderRightWidth,10);this.measurements.container.padding=b+c+d+e},n.prototype._setupTextarea=function(){var a;if(this.list.className="taggle_list",this.input.type="text",this.input.style.paddingLeft=0,this.input.style.paddingRight=0,this.input.className="taggle_input",this.input.tabIndex=this.settings.tabIndex,this.sizer.className="taggle_sizer",this.settings.tags.length)for(var b=0,c=this.settings.tags.length;c>b;b++){var d=this._createTag(this.settings.tags[b]);this.list.appendChild(d)}this.placeholder&&(this.placeholder.style.opacity=0,this.placeholder.classList.add("taggle_placeholder"),this.container.appendChild(this.placeholder),f(this.placeholder,this.settings.placeholder),this.settings.tags.length||this._showPlaceholder());var e=this.settings.inputFormatter(this.input);e&&(this.input=e),this.inputLi.appendChild(this.input),this.list.appendChild(this.inputLi),this.container.appendChild(this.list),this.container.appendChild(this.sizer),a=window.getComputedStyle(this.input).fontSize,this.sizer.style.fontSize=a},n.prototype._attachEvents=function(){function a(){b.input.focus()}var b=this;return this._eventsAttached?!1:(this._eventsAttached=!0,this.settings.focusInputOnContainerClick&&(this._handleContainerClick=a.bind(this),c(this.container,"click",this._handleContainerClick)),this._handleFocus=this._focusInput.bind(this),this._handleBlur=this._blurEvent.bind(this),this._handleKeydown=this._keydownEvents.bind(this),this._handleKeyup=this._keyupEvents.bind(this),c(this.input,"focus",this._handleFocus),c(this.input,"blur",this._handleBlur),c(this.input,"keydown",this._handleKeydown),c(this.input,"keyup",this._handleKeyup),!0)},n.prototype._detachEvents=function(){if(!this._eventsAttached)return!1;var a=this;return this._eventsAttached=!1,d(this.container,"click",this._handleContainerClick),d(this.input,"focus",this._handleFocus),d(this.input,"blur",this._handleBlur),d(this.input,"keydown",this._handleKeydown),d(this.input,"keyup",this._handleKeyup),this._closeButtons.forEach(function(b,c){var e=a._closeEvents[c];d(b,"click",e)}),!0},n.prototype._fixInputWidth=function(){var a,b,c,d,e;this._setMeasurements(),this._setInputWidth(),b=this.input.getBoundingClientRect(),c=this.measurements.container.rect,a=c.width,a||(a=c.right-c.left),d=b.left-c.left,e=this.measurements.container.padding,this._setInputWidth(Math.floor(a-d-e))},n.prototype._canAdd=function(a,b){if(!b)return!1;var c=this.settings.maxTags;if(null!==c&&c<=this.getTagValues().length)return!1;if(this.settings.onBeforeTagAdd(a,b)===!1)return!1;if(!this.settings.allowDuplicates&&this._hasDupes(b))return!1;var d=this.settings.preserveCase,e=this.settings.allowedTags;if(e.length&&!this._tagIsInArray(b,e,d))return!1;var f=this.settings.disallowedTags;return!f.length||!this._tagIsInArray(b,f,d)},n.prototype._tagIsInArray=function(a,b,c){if(c)return-1!==b.indexOf(a);var d=[].slice.apply(b).map(function(a){return a.toLowerCase()});return-1!==d.indexOf(a)},n.prototype._add=function(a,b){var c=this,d=b||"";"string"!=typeof b&&(d=e(this.input.value));var f=this.settings.delimiter||this.settings.delimeter;d.split(f).map(function(a){return c._formatTag(a)}).forEach(function(b){if(c._canAdd(a,b)){var d=c._createTag(b),e=c.list.children,f=e[e.length-1];c.list.insertBefore(d,f),b=c.tag.values[c.tag.values.length-1],c.settings.onTagAdd(a,b),c.input.value="",c._fixInputWidth(),c._focusInput()}})},n.prototype._checkLastTag=function(a){a=a||window.event;var b=this.container.querySelectorAll(".taggle"),c=b[b.length-1],d="taggle_hot",e=this.input.classList.contains("taggle_back");""!==this.input.value||a.keyCode!==i||e?c.classList.contains(d)&&c.classList.remove(d):c.classList.contains(d)?(this.input.classList.add("taggle_back"),this._remove(c,a),this._fixInputWidth(),this._focusInput()):c.classList.add(d)},n.prototype._setInputWidth=function(a){this.input.style.width=(a||10)+"px"},n.prototype._hasDupes=function(a){var b,c=this.tag.values.indexOf(a),d=this.container.querySelector(".taggle_list");if(this.settings.duplicateTagClass){b=d.querySelectorAll("."+this.settings.duplicateTagClass);for(var e=0,f=b.length;f>e;e++)b[e].classList.remove(this.settings.duplicateTagClass)}return c>-1?(this.settings.duplicateTagClass&&d.childNodes[c].classList.add(this.settings.duplicateTagClass),!0):!1},n.prototype._isConfirmKey=function(a){var b=!1;return this.settings.submitKeys.indexOf(a)>-1&&(b=!0),b},n.prototype._focusInput=function(){this._fixInputWidth(),this.container.classList.contains(this.settings.containerFocusClass)||this.container.classList.add(this.settings.containerFocusClass),this.placeholder&&(this.placeholder.style.opacity=0)},n.prototype._blurEvent=function(a){if(this.container.classList.contains(this.settings.containerFocusClass)&&this.container.classList.remove(this.settings.containerFocusClass),this.settings.saveOnBlur){if(a=a||window.event,this._listenForEndOfContainer(),""!==this.input.value)return void this._confirmValidTagEvent(a);this.tag.values.length&&this._checkLastTag(a)}else this.settings.clearOnBlur&&(this.input.value="",this._setInputWidth());this.tag.values.length||this.input.value||this._showPlaceholder()},n.prototype._keydownEvents=function(a){a=a||window.event;var b=a.keyCode;return this.pasting=!1,this._listenForEndOfContainer(),86===b&&a.metaKey&&(this.pasting=!0),this._isConfirmKey(b)&&""!==this.input.value?void this._confirmValidTagEvent(a):void(this.tag.values.length&&this._checkLastTag(a))},n.prototype._keyupEvents=function(a){a=a||window.event,this.input.classList.remove("taggle_back"),f(this.sizer,this.input.value),this.pasting&&""!==this.input.value&&(this._add(a),this.pasting=!1)},n.prototype._confirmValidTagEvent=function(a){a=a||window.event,a.preventDefault?a.preventDefault():a.returnValue=!1,this._add(a)},n.prototype._listenForEndOfContainer=function(){var a=this.sizer.getBoundingClientRect().width,b=this.measurements.container.rect.width-this.measurements.container.padding,c=parseInt(this.sizer.style.fontSize,10);a+1.5*c>parseInt(this.input.style.width,10)&&(this.input.style.width=b+"px")},n.prototype._createTag=function(a){var b=document.createElement("li"),d=document.createElement("button"),e=document.createElement("input"),g=document.createElement("span");a=this._formatTag(a),d.innerHTML="×",d.className="close",d.type="button";var h=this._remove.bind(this,d);c(d,"click",h),f(g,a),g.className="taggle_text",b.className="taggle "+this.settings.additionalTagClasses,e.type="hidden",e.value=a,e.name=this.settings.hiddenInputName,b.appendChild(g),b.appendChild(d),b.appendChild(e);var i=this.settings.tagFormatter(b);if("undefined"!=typeof i&&(b=i),!(b instanceof HTMLElement)||"LI"!==b.tagName)throw new Error("tagFormatter must return an li element");return this.settings.attachTagId&&(this._id+=1,a={text:a,id:this._id}),this.tag.values.push(a),this.tag.elements.push(b),this._closeEvents.push(h),this._closeButtons.push(d),b},n.prototype._showPlaceholder=function(){this.placeholder&&(this.placeholder.style.opacity=1)},n.prototype._remove=function(a,b){function c(c){if(!c){var f=h._closeEvents[g],i=h._closeButtons[g];d(i,"click",f),a.parentNode.removeChild(a),h.tag.elements.splice(g,1),h.tag.values.splice(g,1),h.settings.onTagRemove(b,e),h._focusInput()}}var e,f,g,h=this;"li"!==a.tagName.toLowerCase()&&(a=a.parentNode),f="a"===a.tagName.toLowerCase()?a.parentNode:a,g=this.tag.elements.indexOf(f),e=this.tag.values[g];var i=this.settings.onBeforeTagRemove(b,e,c);i&&c()},n.prototype._formatTag=function(a){return this.settings.preserveCase?a:a.toLowerCase()},n.prototype.getTags=function(){return{elements:this.getTagElements(),values:this.getTagValues()}},n.prototype.getTagElements=function(){return this.tag.elements},n.prototype.getTagValues=function(){return[].slice.apply(this.tag.values)},n.prototype.getInput=function(){return this.input},n.prototype.getContainer=function(){return this.container},n.prototype.add=function(a){var c=b(a);if(c)for(var d=0,e=a.length;e>d;d++)"string"==typeof a[d]&&this._add(null,a[d]);else this._add(null,a);return this},n.prototype.remove=function(a,b){for(var c=this.tag.values.length-1,d=!1;c>-1;){var e=this.tag.values[c];if(this.settings.attachTagId&&(e=e.text),e===a&&(d=!0,this._remove(this.tag.elements[c])),d&&!b)break;c--}return this},n.prototype.removeAll=function(){for(var a=this.tag.values.length-1;a>=0;a--)this._remove(this.tag.elements[a]);return this._showPlaceholder(),this},n.prototype.setOptions=function(b){return this.settings=a({},this.settings,b||{}),this},n.prototype.enable=function(){var a=[].slice.call(this.container.querySelectorAll("button")),b=[].slice.call(this.container.querySelectorAll("input"));return a.concat(b).forEach(function(a){a.removeAttribute("disabled")}),this},n.prototype.disable=function(){var a=[].slice.call(this.container.querySelectorAll("button")),b=[].slice.call(this.container.querySelectorAll("input"));return a.concat(b).forEach(function(a){a.setAttribute("disabled","")}),this},n.prototype.setData=function(a){return this.data=a,this},n.prototype.getData=function(){return this.data},n.prototype.attachEvents=function(){var a=this,b=this._attachEvents();return b&&this._closeButtons.forEach(function(b,d){var e=a._closeEvents[d];c(b,"click",e)}),this},n.prototype.removeEvents=function(){return this._detachEvents(),this},n}); \ No newline at end of file +!function(){Function.prototype.bind||(Function.prototype.bind=function(a){if("function"!=typeof this)throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");var b=Array.prototype.slice.call(arguments,1),c=this,d=function(){},e=function(){return c.apply(this instanceof d&&a?this:a,b.concat(Array.prototype.slice.call(arguments)))};return d.prototype=this.prototype,e.prototype=new d,e}),window.getComputedStyle||(window.getComputedStyle=function(a){return a.currentStyle}),Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b,c,d=Object(this),e=d.length>>>0;if(0===e)return-1;if(b=0,arguments.length>1&&(b=Number(arguments[1]),b!=b?b=0:0!=b&&b!=1/0&&b!=-(1/0)&&(b=(b>0||-1)*Math.floor(Math.abs(b)))),b>=e)return-1;for(c=b>=0?b:Math.max(e-Math.abs(b),0);c>>0;if("function"!=typeof a)throw new TypeError(a+" is not a function");for(arguments.length>1&&(c=b),d=0;d>>0;if("function"!=typeof a)throw new TypeError(a+" is not a function");for(arguments.length>1&&(c=b),d=new Array(g),e=0;e-1&&(this.settings.duplicateTagClass&&d.childNodes[c].classList.add(this.settings.duplicateTagClass),!0)},n.prototype._isConfirmKey=function(a){var b=!1;return this.settings.submitKeys.indexOf(a)>-1&&(b=!0),b},n.prototype._focusInput=function(){this._fixInputWidth(),this.container.classList.contains(this.settings.containerFocusClass)||this.container.classList.add(this.settings.containerFocusClass),this.placeholder&&(this.placeholder.style.opacity=0)},n.prototype._blurEvent=function(a){if(this.container.classList.contains(this.settings.containerFocusClass)&&this.container.classList.remove(this.settings.containerFocusClass),this.settings.saveOnBlur){if(a=a||window.event,this._listenForEndOfContainer(),""!==this.input.value)return void this._confirmValidTagEvent(a);this.tag.values.length&&this._checkLastTag(a)}else this.settings.clearOnBlur&&(this.input.value="",this._setInputWidth());this.tag.values.length||this.input.value||this._showPlaceholder()},n.prototype._keydownEvents=function(a){a=a||window.event;var b=a.keyCode;return this.pasting=!1,this._listenForEndOfContainer(),86===b&&a.metaKey&&(this.pasting=!0),this._isConfirmKey(b)&&""!==this.input.value?void this._confirmValidTagEvent(a):void(this.tag.values.length&&this._checkLastTag(a))},n.prototype._keyupEvents=function(a){a=a||window.event,this.input.classList.remove("taggle_back"),f(this.sizer,this.input.value),this.pasting&&""!==this.input.value&&(this._add(a),this.pasting=!1)},n.prototype._confirmValidTagEvent=function(a){a=a||window.event,a.preventDefault?a.preventDefault():a.returnValue=!1,this._add(a)},n.prototype._listenForEndOfContainer=function(){var a=this.sizer.getBoundingClientRect().width,b=this.measurements.container.rect.width-this.measurements.container.padding,c=parseInt(this.sizer.style.fontSize,10);a+1.5*c>parseInt(this.input.style.width,10)&&(this.input.style.width=b+"px")},n.prototype._createTag=function(a){var b=document.createElement("li"),d=document.createElement("button"),e=document.createElement("input"),g=document.createElement("span");a=this._formatTag(a),d.innerHTML="×",d.className="close",d.type="button";var h=this._remove.bind(this,d);c(d,"click",h),f(g,a),g.className="taggle_text",b.className="taggle "+this.settings.additionalTagClasses,e.type="hidden",e.value=a,e.name=this.settings.hiddenInputName,b.appendChild(g),b.appendChild(d),b.appendChild(e);var i=this.settings.tagFormatter(b);if("undefined"!=typeof i&&(b=i),!(b instanceof HTMLElement)||"LI"!==b.tagName)throw new Error("tagFormatter must return an li element");return this.settings.attachTagId&&(this._id+=1,a={text:a,id:this._id}),this.tag.values.push(a),this.tag.elements.push(b),this._closeEvents.push(h),this._closeButtons.push(d),b},n.prototype._showPlaceholder=function(){this.placeholder&&(this.placeholder.style.opacity=1)},n.prototype._remove=function(a,b){function c(c){if(!c){var f=h._closeEvents[g],i=h._closeButtons[g];d(i,"click",f),a.parentNode.removeChild(a),h.tag.elements.splice(g,1),h.tag.values.splice(g,1),h.settings.onTagRemove(b,e),h._focusInput()}}var e,f,g,h=this;"li"!==a.tagName.toLowerCase()&&(a=a.parentNode),f="a"===a.tagName.toLowerCase()?a.parentNode:a,g=this.tag.elements.indexOf(f),e=this.tag.values[g];var i=this.settings.onBeforeTagRemove(b,e,c);i&&c()},n.prototype._formatTag=function(a){return this.settings.preserveCase?a:a.toLowerCase()},n.prototype.getTags=function(){return{elements:this.getTagElements(),values:this.getTagValues()}},n.prototype.getTagElements=function(){return this.tag.elements},n.prototype.getTagValues=function(){return[].slice.apply(this.tag.values)},n.prototype.getInput=function(){return this.input},n.prototype.getContainer=function(){return this.container},n.prototype.add=function(a){var c=b(a);if(c)for(var d=0,e=a.length;d-1;){var e=this.tag.values[c];if(this.settings.attachTagId&&(e=e.text),e===a&&(d=!0,this._remove(this.tag.elements[c])),d&&!b)break;c--}return this},n.prototype.removeAll=function(){for(var a=this.tag.values.length-1;a>=0;a--)this._remove(this.tag.elements[a]);return this._showPlaceholder(),this},n.prototype.setOptions=function(b){return this.settings=a({},this.settings,b||{}),this},n.prototype.enable=function(){var a=[].slice.call(this.container.querySelectorAll("button")),b=[].slice.call(this.container.querySelectorAll("input"));return a.concat(b).forEach(function(a){a.removeAttribute("disabled")}),this},n.prototype.disable=function(){var a=[].slice.call(this.container.querySelectorAll("button")),b=[].slice.call(this.container.querySelectorAll("input"));return a.concat(b).forEach(function(a){a.setAttribute("disabled","")}),this},n.prototype.setData=function(a){return this.data=a,this},n.prototype.getData=function(){return this.data},n.prototype.attachEvents=function(){var a=this,b=this._attachEvents();return b&&this._closeButtons.forEach(function(b,d){var e=a._closeEvents[d];c(b,"click",e)}),this},n.prototype.removeEvents=function(){return this._detachEvents(),this},n}); \ No newline at end of file diff --git a/src/taggle-ie8.js b/src/taggle-ie8.js index 4b8f809..c7b23a3 100644 --- a/src/taggle-ie8.js +++ b/src/taggle-ie8.js @@ -215,4 +215,9 @@ if (!Array.prototype.map) { }; } +// IE8 has no HTMLElement, but it does have Element. +if (typeof window.HTMLElement === 'undefined' && window.Element) { + window.HTMLElement = window.Element; +} + })(); From 535eb46db15651e027203634ea2a95587daab977 Mon Sep 17 00:00:00 2001 From: Zarino Zappia Date: Tue, 29 May 2018 14:28:47 +0100 Subject: [PATCH 2/2] Set Close button `type` attribute rather than property IE8 does not allow you to change the `type` property of a button after it has been created (eg: by createElement). But it *does* seem to allow you to change the `type` *attribute*, which is good enough for our needs (preventing the parent form from being submitted when the Close button on a Taggle tag is clicked). --- example/js/taggle.min.js | 2 +- src/taggle.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/example/js/taggle.min.js b/example/js/taggle.min.js index 4e26630..0716fdc 100644 --- a/example/js/taggle.min.js +++ b/example/js/taggle.min.js @@ -5,4 +5,4 @@ * @license MIT * @description Taggle is a dependency-less tagging library */ -!function(){Function.prototype.bind||(Function.prototype.bind=function(a){if("function"!=typeof this)throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");var b=Array.prototype.slice.call(arguments,1),c=this,d=function(){},e=function(){return c.apply(this instanceof d&&a?this:a,b.concat(Array.prototype.slice.call(arguments)))};return d.prototype=this.prototype,e.prototype=new d,e}),window.getComputedStyle||(window.getComputedStyle=function(a){return a.currentStyle}),Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b,c,d=Object(this),e=d.length>>>0;if(0===e)return-1;if(b=0,arguments.length>1&&(b=Number(arguments[1]),b!=b?b=0:0!=b&&b!=1/0&&b!=-(1/0)&&(b=(b>0||-1)*Math.floor(Math.abs(b)))),b>=e)return-1;for(c=b>=0?b:Math.max(e-Math.abs(b),0);c>>0;if("function"!=typeof a)throw new TypeError(a+" is not a function");for(arguments.length>1&&(c=b),d=0;d>>0;if("function"!=typeof a)throw new TypeError(a+" is not a function");for(arguments.length>1&&(c=b),d=new Array(g),e=0;e-1&&(this.settings.duplicateTagClass&&d.childNodes[c].classList.add(this.settings.duplicateTagClass),!0)},n.prototype._isConfirmKey=function(a){var b=!1;return this.settings.submitKeys.indexOf(a)>-1&&(b=!0),b},n.prototype._focusInput=function(){this._fixInputWidth(),this.container.classList.contains(this.settings.containerFocusClass)||this.container.classList.add(this.settings.containerFocusClass),this.placeholder&&(this.placeholder.style.opacity=0)},n.prototype._blurEvent=function(a){if(this.container.classList.contains(this.settings.containerFocusClass)&&this.container.classList.remove(this.settings.containerFocusClass),this.settings.saveOnBlur){if(a=a||window.event,this._listenForEndOfContainer(),""!==this.input.value)return void this._confirmValidTagEvent(a);this.tag.values.length&&this._checkLastTag(a)}else this.settings.clearOnBlur&&(this.input.value="",this._setInputWidth());this.tag.values.length||this.input.value||this._showPlaceholder()},n.prototype._keydownEvents=function(a){a=a||window.event;var b=a.keyCode;return this.pasting=!1,this._listenForEndOfContainer(),86===b&&a.metaKey&&(this.pasting=!0),this._isConfirmKey(b)&&""!==this.input.value?void this._confirmValidTagEvent(a):void(this.tag.values.length&&this._checkLastTag(a))},n.prototype._keyupEvents=function(a){a=a||window.event,this.input.classList.remove("taggle_back"),f(this.sizer,this.input.value),this.pasting&&""!==this.input.value&&(this._add(a),this.pasting=!1)},n.prototype._confirmValidTagEvent=function(a){a=a||window.event,a.preventDefault?a.preventDefault():a.returnValue=!1,this._add(a)},n.prototype._listenForEndOfContainer=function(){var a=this.sizer.getBoundingClientRect().width,b=this.measurements.container.rect.width-this.measurements.container.padding,c=parseInt(this.sizer.style.fontSize,10);a+1.5*c>parseInt(this.input.style.width,10)&&(this.input.style.width=b+"px")},n.prototype._createTag=function(a){var b=document.createElement("li"),d=document.createElement("button"),e=document.createElement("input"),g=document.createElement("span");a=this._formatTag(a),d.innerHTML="×",d.className="close",d.type="button";var h=this._remove.bind(this,d);c(d,"click",h),f(g,a),g.className="taggle_text",b.className="taggle "+this.settings.additionalTagClasses,e.type="hidden",e.value=a,e.name=this.settings.hiddenInputName,b.appendChild(g),b.appendChild(d),b.appendChild(e);var i=this.settings.tagFormatter(b);if("undefined"!=typeof i&&(b=i),!(b instanceof HTMLElement)||"LI"!==b.tagName)throw new Error("tagFormatter must return an li element");return this.settings.attachTagId&&(this._id+=1,a={text:a,id:this._id}),this.tag.values.push(a),this.tag.elements.push(b),this._closeEvents.push(h),this._closeButtons.push(d),b},n.prototype._showPlaceholder=function(){this.placeholder&&(this.placeholder.style.opacity=1)},n.prototype._remove=function(a,b){function c(c){if(!c){var f=h._closeEvents[g],i=h._closeButtons[g];d(i,"click",f),a.parentNode.removeChild(a),h.tag.elements.splice(g,1),h.tag.values.splice(g,1),h.settings.onTagRemove(b,e),h._focusInput()}}var e,f,g,h=this;"li"!==a.tagName.toLowerCase()&&(a=a.parentNode),f="a"===a.tagName.toLowerCase()?a.parentNode:a,g=this.tag.elements.indexOf(f),e=this.tag.values[g];var i=this.settings.onBeforeTagRemove(b,e,c);i&&c()},n.prototype._formatTag=function(a){return this.settings.preserveCase?a:a.toLowerCase()},n.prototype.getTags=function(){return{elements:this.getTagElements(),values:this.getTagValues()}},n.prototype.getTagElements=function(){return this.tag.elements},n.prototype.getTagValues=function(){return[].slice.apply(this.tag.values)},n.prototype.getInput=function(){return this.input},n.prototype.getContainer=function(){return this.container},n.prototype.add=function(a){var c=b(a);if(c)for(var d=0,e=a.length;d-1;){var e=this.tag.values[c];if(this.settings.attachTagId&&(e=e.text),e===a&&(d=!0,this._remove(this.tag.elements[c])),d&&!b)break;c--}return this},n.prototype.removeAll=function(){for(var a=this.tag.values.length-1;a>=0;a--)this._remove(this.tag.elements[a]);return this._showPlaceholder(),this},n.prototype.setOptions=function(b){return this.settings=a({},this.settings,b||{}),this},n.prototype.enable=function(){var a=[].slice.call(this.container.querySelectorAll("button")),b=[].slice.call(this.container.querySelectorAll("input"));return a.concat(b).forEach(function(a){a.removeAttribute("disabled")}),this},n.prototype.disable=function(){var a=[].slice.call(this.container.querySelectorAll("button")),b=[].slice.call(this.container.querySelectorAll("input"));return a.concat(b).forEach(function(a){a.setAttribute("disabled","")}),this},n.prototype.setData=function(a){return this.data=a,this},n.prototype.getData=function(){return this.data},n.prototype.attachEvents=function(){var a=this,b=this._attachEvents();return b&&this._closeButtons.forEach(function(b,d){var e=a._closeEvents[d];c(b,"click",e)}),this},n.prototype.removeEvents=function(){return this._detachEvents(),this},n}); \ No newline at end of file +!function(){Function.prototype.bind||(Function.prototype.bind=function(a){if("function"!=typeof this)throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");var b=Array.prototype.slice.call(arguments,1),c=this,d=function(){},e=function(){return c.apply(this instanceof d&&a?this:a,b.concat(Array.prototype.slice.call(arguments)))};return d.prototype=this.prototype,e.prototype=new d,e}),window.getComputedStyle||(window.getComputedStyle=function(a){return a.currentStyle}),Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b,c,d=Object(this),e=d.length>>>0;if(0===e)return-1;if(b=0,arguments.length>1&&(b=Number(arguments[1]),b!=b?b=0:0!=b&&b!=1/0&&b!=-(1/0)&&(b=(b>0||-1)*Math.floor(Math.abs(b)))),b>=e)return-1;for(c=b>=0?b:Math.max(e-Math.abs(b),0);c>>0;if("function"!=typeof a)throw new TypeError(a+" is not a function");for(arguments.length>1&&(c=b),d=0;d>>0;if("function"!=typeof a)throw new TypeError(a+" is not a function");for(arguments.length>1&&(c=b),d=new Array(g),e=0;e-1&&(this.settings.duplicateTagClass&&d.childNodes[c].classList.add(this.settings.duplicateTagClass),!0)},n.prototype._isConfirmKey=function(a){var b=!1;return this.settings.submitKeys.indexOf(a)>-1&&(b=!0),b},n.prototype._focusInput=function(){this._fixInputWidth(),this.container.classList.contains(this.settings.containerFocusClass)||this.container.classList.add(this.settings.containerFocusClass),this.placeholder&&(this.placeholder.style.opacity=0)},n.prototype._blurEvent=function(a){if(this.container.classList.contains(this.settings.containerFocusClass)&&this.container.classList.remove(this.settings.containerFocusClass),this.settings.saveOnBlur){if(a=a||window.event,this._listenForEndOfContainer(),""!==this.input.value)return void this._confirmValidTagEvent(a);this.tag.values.length&&this._checkLastTag(a)}else this.settings.clearOnBlur&&(this.input.value="",this._setInputWidth());this.tag.values.length||this.input.value||this._showPlaceholder()},n.prototype._keydownEvents=function(a){a=a||window.event;var b=a.keyCode;return this.pasting=!1,this._listenForEndOfContainer(),86===b&&a.metaKey&&(this.pasting=!0),this._isConfirmKey(b)&&""!==this.input.value?void this._confirmValidTagEvent(a):void(this.tag.values.length&&this._checkLastTag(a))},n.prototype._keyupEvents=function(a){a=a||window.event,this.input.classList.remove("taggle_back"),f(this.sizer,this.input.value),this.pasting&&""!==this.input.value&&(this._add(a),this.pasting=!1)},n.prototype._confirmValidTagEvent=function(a){a=a||window.event,a.preventDefault?a.preventDefault():a.returnValue=!1,this._add(a)},n.prototype._listenForEndOfContainer=function(){var a=this.sizer.getBoundingClientRect().width,b=this.measurements.container.rect.width-this.measurements.container.padding,c=parseInt(this.sizer.style.fontSize,10);a+1.5*c>parseInt(this.input.style.width,10)&&(this.input.style.width=b+"px")},n.prototype._createTag=function(a){var b,d=document.createElement("li"),e=document.createElement("input"),g=document.createElement("span");try{b=document.createElement('