diff --git a/src/tags-input.js b/src/tags-input.js index 4f5e07a..6d79870 100644 --- a/src/tags-input.js +++ b/src/tags-input.js @@ -140,6 +140,14 @@ export default function tagsInput(input) { base.input.focus(); }); + input.addEventListener('change', () => { + let currentValue = getValue(); + if(currentValue !== input.value) { + setValue(input.value); + base.input.focus(); + } + }); + base.input.addEventListener('focus', () => { base.classList.add('focus'); select(); diff --git a/tags-input.js b/tags-input.js index 7abf0e5..bc18f5e 100644 --- a/tags-input.js +++ b/tags-input.js @@ -1,2 +1,2 @@ -(function(global,factory){if(typeof define === 'function' && define.amd){define(['exports','module'],factory);}else if(typeof exports !== 'undefined' && typeof module !== 'undefined'){factory(exports,module);}else {var mod={exports:{}};factory(mod.exports,mod);global.tagsInput = mod.exports;}})(this,function(exports,module){'use strict';module.exports = tagsInput;var BACKSPACE=8,TAB=9,ENTER=13,LEFT=37,RIGHT=39,DELETE=46,COMMA=188;var SEPERATOR=',';var COPY_PROPS='placeholder pattern spellcheck autocomplete autocapitalize autofocus accessKey accept lang minLength maxLength required'.split(' ');function tagsInput(input){function createElement(type,name,text,attributes){var el=document.createElement(type);if(name)el.className = name;if(text)el.textContent = text;for(var key in attributes) {el.setAttribute('data-' + key,attributes[key]);}return el;}function $(selector,all){return all === true?Array.prototype.slice.call(base.querySelectorAll(selector)):base.querySelector(selector);}function getValue(){return $('.tag',true).map(function(tag){return tag.textContent;}).concat(base.input.value || []).join(SEPERATOR);}function setValue(value){$('.tag',true).forEach(function(t){return base.removeChild(t);});savePartialInput(value);}function save(){input.value = getValue();input.dispatchEvent(new Event('change'));}function addTag(text){if(~text.indexOf(SEPERATOR))text = text.split(SEPERATOR);if(Array.isArray(text))return text.forEach(addTag);var tag=text && text.trim();if(!tag)return false;if(!input.getAttribute('duplicates')){var _ret=(function(){var exisingTag=$('[data-tag="' + tag + '"]');if(exisingTag){exisingTag.classList.add('dupe');setTimeout(function(){return exisingTag.classList.remove('dupe');},100);return {v:false};}})();if(typeof _ret === 'object')return _ret.v;}base.insertBefore(createElement('span','tag',tag,{tag:tag}),base.input);}function select(el){var sel=$('.selected');if(sel)sel.classList.remove('selected');if(el)el.classList.add('selected');}function setInputWidth(){var last=$('.tag',true).pop(),w=base.offsetWidth;if(!w)return;base.input.style.width = Math.max(w - (last?last.offsetLeft + last.offsetWidth:5) - 5,w / 4) + 'px';}function savePartialInput(value){if(typeof value !== 'string' && !Array.isArray(value)){value = base.input.value;}if(addTag(value) !== false){base.input.value = '';save();setInputWidth();}}function refocus(e){if(e.target.classList.contains('tag'))select(e.target);if(e.target === base.input)return select();base.input.focus();e.preventDefault();return false;}var base=createElement('div','tags-input'),sib=input.nextSibling;input.parentNode[sib?'insertBefore':'appendChild'](base,sib);input.style.cssText = 'position:absolute;left:0;top:-99px;width:1px;height:1px;opacity:0.01;';input.tabIndex = -1;base.input = createElement('input');base.input.setAttribute('type','text');COPY_PROPS.forEach(function(prop){if(input[prop] !== base.input[prop]){base.input[prop] = input[prop];try{delete input[prop];}catch(e) {}}});base.appendChild(base.input);input.addEventListener('focus',function(){base.input.focus();});base.input.addEventListener('focus',function(){base.classList.add('focus');select();});base.input.addEventListener('blur',function(){base.classList.remove('focus');select();savePartialInput();});base.input.addEventListener('keydown',function(e){var el=base.input,key=e.keyCode || e.which,selectedTag=$('.tag.selected'),pos=el.selectionStart === el.selectionEnd && el.selectionStart,last=$('.tag',true).pop();setInputWidth();if(key === ENTER || key === COMMA || key === TAB){if(!el.value && key !== COMMA)return;savePartialInput();}else if(key === DELETE && selectedTag){if(selectedTag.nextSibling !== base.input)select(selectedTag.nextSibling);base.removeChild(selectedTag);setInputWidth();save();}else if(key === BACKSPACE){if(selectedTag){select(selectedTag.previousSibling);base.removeChild(selectedTag);setInputWidth();save();}else if(last && pos === 0){select(last);}else {return;}}else if(key === LEFT){if(selectedTag){if(selectedTag.previousSibling){select(selectedTag.previousSibling);}}else if(pos !== 0){return;}else {select(last);}}else if(key === RIGHT){if(!selectedTag)return;select(selectedTag.nextSibling);}else {return select();}e.preventDefault();return false;});base.input.addEventListener('input',function(){input.value = getValue();input.dispatchEvent(new Event('input'));});base.input.addEventListener('paste',function(){return setTimeout(savePartialInput,0);});base.addEventListener('mousedown',refocus);base.addEventListener('touchstart',refocus);base.setValue = setValue;base.getValue = getValue;savePartialInput(input.value);}tagsInput.enhance = tagsInput.tagsInput = tagsInput;}); +(function(global,factory){if(typeof define === 'function' && define.amd){define(['exports','module'],factory);}else if(typeof exports !== 'undefined' && typeof module !== 'undefined'){factory(exports,module);}else {var mod={exports:{}};factory(mod.exports,mod);global.tagsInput = mod.exports;}})(this,function(exports,module){'use strict';module.exports = tagsInput;var BACKSPACE=8,TAB=9,ENTER=13,LEFT=37,RIGHT=39,DELETE=46,COMMA=188;var SEPERATOR=',';var COPY_PROPS='placeholder pattern spellcheck autocomplete autocapitalize autofocus accessKey accept lang minLength maxLength required'.split(' ');function tagsInput(input){function createElement(type,name,text,attributes){var el=document.createElement(type);if(name)el.className = name;if(text)el.textContent = text;for(var key in attributes) {el.setAttribute('data-' + key,attributes[key]);}return el;}function $(selector,all){return all === true?Array.prototype.slice.call(base.querySelectorAll(selector)):base.querySelector(selector);}function getValue(){return $('.tag',true).map(function(tag){return tag.textContent;}).concat(base.input.value || []).join(SEPERATOR);}function setValue(value){$('.tag',true).forEach(function(t){return base.removeChild(t);});savePartialInput(value);}function save(){input.value = getValue();input.dispatchEvent(new Event('change'));}function addTag(text){if(~text.indexOf(SEPERATOR))text = text.split(SEPERATOR);if(Array.isArray(text))return text.forEach(addTag);var tag=text && text.trim();if(!tag)return false;if(!input.getAttribute('duplicates')){var _ret=(function(){var exisingTag=$('[data-tag="' + tag + '"]');if(exisingTag){exisingTag.classList.add('dupe');setTimeout(function(){return exisingTag.classList.remove('dupe');},100);return {v:false};}})();if(typeof _ret === 'object')return _ret.v;}base.insertBefore(createElement('span','tag',tag,{tag:tag}),base.input);}function select(el){var sel=$('.selected');if(sel)sel.classList.remove('selected');if(el)el.classList.add('selected');}function setInputWidth(){var last=$('.tag',true).pop(),w=base.offsetWidth;if(!w)return;base.input.style.width = Math.max(w - (last?last.offsetLeft + last.offsetWidth:5) - 5,w / 4) + 'px';}function savePartialInput(value){if(typeof value !== 'string' && !Array.isArray(value)){value = base.input.value;}if(addTag(value) !== false){base.input.value = '';save();setInputWidth();}}function refocus(e){if(e.target.classList.contains('tag'))select(e.target);if(e.target === base.input)return select();base.input.focus();e.preventDefault();return false;}function caretAtStart(el){try{return el.selectionStart === 0 && el.selectionEnd === 0;}catch(e) {return el.value === '';}}var base=createElement('div','tags-input'),sib=input.nextSibling;input.parentNode[sib?'insertBefore':'appendChild'](base,sib);input.style.cssText = 'position:absolute;left:0;top:-99px;width:1px;height:1px;opacity:0.01;';input.tabIndex = -1;var inputType=input.getAttribute('type');if(!inputType || inputType === 'tags'){inputType = 'text';}base.input = createElement('input');base.input.setAttribute('type',inputType);COPY_PROPS.forEach(function(prop){if(input[prop] !== base.input[prop]){base.input[prop] = input[prop];try{delete input[prop];}catch(e) {}}});base.appendChild(base.input);input.addEventListener('focus',function(){base.input.focus();});input.addEventListener('change',function(){var currentValue=getValue();if(currentValue !== input.value){setValue(input.value);base.input.focus();}});base.input.addEventListener('focus',function(){base.classList.add('focus');select();});base.input.addEventListener('blur',function(){base.classList.remove('focus');select();savePartialInput();});base.input.addEventListener('keydown',function(e){var el=base.input,key=e.keyCode || e.which,selectedTag=$('.tag.selected'),atStart=caretAtStart(el),last=$('.tag',true).pop();setInputWidth();if(key === ENTER || key === COMMA || key === TAB){if(!el.value && key !== COMMA)return;savePartialInput();}else if(key === DELETE && selectedTag){if(selectedTag.nextSibling !== base.input)select(selectedTag.nextSibling);base.removeChild(selectedTag);setInputWidth();save();}else if(key === BACKSPACE){if(selectedTag){select(selectedTag.previousSibling);base.removeChild(selectedTag);setInputWidth();save();}else if(last && atStart){select(last);}else {return;}}else if(key === LEFT){if(selectedTag){if(selectedTag.previousSibling){select(selectedTag.previousSibling);}}else if(!atStart){return;}else {select(last);}}else if(key === RIGHT){if(!selectedTag)return;select(selectedTag.nextSibling);}else {return select();}e.preventDefault();return false;});base.input.addEventListener('input',function(){input.value = getValue();input.dispatchEvent(new Event('input'));});base.input.addEventListener('paste',function(){return setTimeout(savePartialInput,0);});base.addEventListener('mousedown',refocus);base.addEventListener('touchstart',refocus);base.setValue = setValue;base.getValue = getValue;savePartialInput(input.value);}tagsInput.enhance = tagsInput.tagsInput = tagsInput;}); //# sourceMappingURL=tags-input.js.map \ No newline at end of file diff --git a/tags-input.js.map b/tags-input.js.map index 29ab320..39b3e3d 100644 --- a/tags-input.js.map +++ b/tags-input.js.map @@ -1 +1 @@ -{"version":3,"sources":["src/tags-input.js"],"names":[],"mappings":"oWAYwB,SAAS,CAZjC,IAAM,SAAS,CAAG,CAAC,CAClB,GAAG,CAAG,CAAC,CACP,KAAK,CAAG,EAAE,CACV,IAAI,CAAG,EAAE,CACT,KAAK,CAAG,EAAE,CACV,MAAM,CAAG,EAAE,CACX,KAAK,CAAG,GAAG,CAAC,AAEb,IAAM,SAAS,CAAG,GAAG,CAAC,AAEtB,IAAM,UAAU,CAAG,yHAAyH,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,AAEzI,SAAS,SAAS,CAAC,KAAK,CAAE,CACxC,SAAS,aAAa,CAAC,IAAI,CAAE,IAAI,CAAE,IAAI,CAAE,UAAU,CAAE,CACpD,IAAI,EAAE,CAAG,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,AACtC,GAAI,IAAI,CAAE,EAAE,CAAC,SAAS,GAAG,IAAI,CAAC,AAC9B,GAAI,IAAI,CAAE,EAAE,CAAC,WAAW,GAAG,IAAI,CAAC,AAChC,IAAK,IAAI,GAAG,IAAI,UAAU,EAAE,CAC3B,EAAE,CAAC,YAAY,WAAS,GAAG,CAAI,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAChD,AACD,OAAO,EAAE,CAAC,CACV,AAED,SAAS,CAAC,CAAC,QAAQ,CAAE,GAAG,CAAE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AAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CACxC,CAAC,CAAC,AAGH,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,OAAO,CAAE,kBAAM,UAAU,CAAC,gBAAgB,CAAE,CAAC,CAAC,EAAA,CAAC,CAAC,AAE5E,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAE,OAAO,CAAC,CAAC,AAC5C,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAE,OAAO,CAAC,CAAC,AAE7C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,AACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,AAGzB,gBAAgB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAC9B,AAGD,SAAS,CAAC,OAAO,GAAG,SAAS,CAAC,SAAS,GAAG,SAAS,CAAC","file":"tags-input.js","sourceRoot":"src","sourcesContent":["const BACKSPACE = 8,\n\tTAB = 9,\n\tENTER = 13,\n\tLEFT = 37,\n\tRIGHT = 39,\n\tDELETE = 46,\n\tCOMMA = 188;\n\nconst SEPERATOR = ',';\n\nconst COPY_PROPS = 'placeholder pattern spellcheck autocomplete autocapitalize autofocus accessKey accept lang minLength maxLength required'.split(' ');\n\nexport default function tagsInput(input) {\n\tfunction createElement(type, name, text, attributes) {\n\t\tlet el = document.createElement(type);\n\t\tif (name) el.className = name;\n\t\tif (text) el.textContent = text;\n\t\tfor (let key in attributes) {\n\t\t\tel.setAttribute(`data-${key}`, attributes[key]);\n\t\t}\n\t\treturn el;\n\t}\n\n\tfunction $(selector, all) {\n\t\treturn all===true ? Array.prototype.slice.call(base.querySelectorAll(selector)) : base.querySelector(selector);\n\t}\n\n\tfunction getValue() {\n\t\treturn $('.tag', true)\n\t\t\t.map( tag => tag.textContent )\n\t\t\t.concat(base.input.value || [])\n\t\t\t.join(SEPERATOR);\n\t}\n\n\tfunction setValue(value) {\n\t\t$('.tag', true).forEach( t => base.removeChild(t) );\n\t\tsavePartialInput(value);\n\t}\n\n\tfunction save() {\n\t\tinput.value = getValue();\n\t\tinput.dispatchEvent(new Event('change'));\n\t}\n\n\t// Return false if no need to add a tag\n\tfunction addTag(text) {\n\t\t// Add multiple tags if the user pastes in data with SEPERATOR already in it\n\t\tif (~text.indexOf(SEPERATOR)) text = text.split(SEPERATOR);\n\t\tif (Array.isArray(text)) return text.forEach(addTag);\n\n\t\tlet tag = text && text.trim();\n\t\t// Ignore if text is empty\n\t\tif (!tag) return false;\n\n\t\t// For duplicates, briefly highlight the existing tag\n\t\tif (!input.getAttribute('duplicates')) {\n\t\t\tlet exisingTag = $(`[data-tag=\"${tag}\"]`);\n\t\t\tif (exisingTag) {\n\t\t\t\texisingTag.classList.add('dupe');\n\t\t\t\tsetTimeout( () => exisingTag.classList.remove('dupe') , 100);\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tbase.insertBefore(\n\t\t\tcreateElement('span', 'tag', tag, { tag }),\n\t\t\tbase.input\n\t\t);\n\t}\n\n\tfunction select(el) {\n\t\tlet sel = $('.selected');\n\t\tif (sel) sel.classList.remove('selected');\n\t\tif (el) el.classList.add('selected');\n\t}\n\n\tfunction setInputWidth() {\n\t\tlet last = $('.tag',true).pop(),\n\t\t\tw = base.offsetWidth;\n\t\tif (!w) return;\n\t\tbase.input.style.width = Math.max(\n\t\t\tw - (last ? (last.offsetLeft+last.offsetWidth) : 5) - 5,\n\t\t\tw/4\n\t\t) + 'px';\n\t}\n\n\tfunction savePartialInput(value) {\n\t\tif (typeof value!=='string' && !Array.isArray(value)) {\n\t\t\t// If the base input does not contain a value, default to the original element passed\n\t\t\tvalue = base.input.value;\n\t\t}\n\t\tif (addTag(value)!==false) {\n\t\t\tbase.input.value = '';\n\t\t\tsave();\n\t\t\tsetInputWidth();\n\t\t}\n\t}\n\n\tfunction refocus(e) {\n\t\tif (e.target.classList.contains('tag')) select(e.target);\n\t\tif (e.target===base.input) return select();\n\t\tbase.input.focus();\n\t\te.preventDefault();\n\t\treturn false;\n\t}\n\n\tlet base = createElement('div', 'tags-input'),\n\t\tsib = input.nextSibling;\n\tinput.parentNode[sib?'insertBefore':'appendChild'](base, sib);\n\n\tinput.style.cssText = 'position:absolute;left:0;top:-99px;width:1px;height:1px;opacity:0.01;';\n\tinput.tabIndex = -1;\n\n\tbase.input = createElement('input');\n\tbase.input.setAttribute('type', 'text');\n\tCOPY_PROPS.forEach( prop => {\n\t\tif (input[prop]!==base.input[prop]) {\n\t\t\tbase.input[prop] = input[prop];\n\t\t\ttry { delete input[prop]; }catch(e){}\n\t\t}\n\t});\n\tbase.appendChild(base.input);\n\n\tinput.addEventListener('focus', () => {\n\t\tbase.input.focus();\n\t});\n\n\tbase.input.addEventListener('focus', () => {\n\t\tbase.classList.add('focus');\n\t\tselect();\n\t});\n\n\tbase.input.addEventListener('blur', () => {\n\t\tbase.classList.remove('focus');\n\t\tselect();\n\t\tsavePartialInput();\n\t});\n\n\tbase.input.addEventListener('keydown', e => {\n\t\tlet el = base.input,\n\t\t\tkey = e.keyCode || e.which,\n\t\t\tselectedTag = $('.tag.selected'),\n\t\t\tpos = el.selectionStart===el.selectionEnd && el.selectionStart,\n\t\t\tlast = $('.tag',true).pop();\n\n\t\tsetInputWidth();\n\n\t\tif (key===ENTER || key===COMMA || key===TAB) {\n\t\t\tif (!el.value && key!==COMMA) return;\n\t\t\tsavePartialInput();\n\t\t}\n\t\telse if (key===DELETE && selectedTag) {\n\t\t\tif (selectedTag.nextSibling!==base.input) select(selectedTag.nextSibling);\n\t\t\tbase.removeChild(selectedTag);\n\t\t\tsetInputWidth();\n\t\t\tsave();\n\t\t}\n\t\telse if (key===BACKSPACE) {\n\t\t\tif (selectedTag) {\n\t\t\t\tselect(selectedTag.previousSibling);\n\t\t\t\tbase.removeChild(selectedTag);\n\t\t\t\tsetInputWidth();\n\t\t\t\tsave();\n\t\t\t}\n\t\t\telse if (last && pos===0) {\n\t\t\t\tselect(last);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\telse if (key===LEFT) {\n\t\t\tif (selectedTag) {\n\t\t\t\tif (selectedTag.previousSibling) {\n\t\t\t\t\tselect(selectedTag.previousSibling);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (pos!==0) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tselect(last);\n\t\t\t}\n\t\t}\n\t\telse if (key===RIGHT) {\n\t\t\tif (!selectedTag) return;\n\t\t\tselect(selectedTag.nextSibling);\n\t\t}\n\t\telse {\n\t\t\treturn select();\n\t\t}\n\n\t\te.preventDefault();\n\t\treturn false;\n\t});\n\n\t// Proxy \"input\" (live change) events , update the first tag live as the user types\n\t// This means that users who only want one thing don't have to enter commas\n\tbase.input.addEventListener('input', () => {\n\t\tinput.value = getValue();\n\t\tinput.dispatchEvent(new Event('input'));\n\t});\n\n\t// One tick after pasting, parse pasted text as CSV:\n\tbase.input.addEventListener('paste', () => setTimeout(savePartialInput, 0));\n\n\tbase.addEventListener('mousedown', refocus);\n\tbase.addEventListener('touchstart', refocus);\n\n\tbase.setValue = setValue;\n\tbase.getValue = getValue;\n\n\t// Add tags for existing values\n\tsavePartialInput(input.value);\n}\n\n// make life easier:\ntagsInput.enhance = tagsInput.tagsInput = tagsInput;\n"]} \ No newline at end of file +{"version":3,"sources":["src/tags-input.js"],"names":[],"mappings":"oWAYwB,SAAS,CAZjC,IAAM,SAAS,CAAG,CAAC,CAClB,GAAG,CAAG,CAAC,CACP,KAAK,CAAG,EAAE,CACV,IAAI,CAAG,EAAE,CACT,KAAK,CAAG,EAAE,CACV,MAAM,CAAG,EAAE,CACX,KAAK,CAAG,GAAG,CAAC,AAEb,IAAM,SAAS,CAAG,GAAG,CAAC,AAEtB,IAAM,UAAU,CAAG,yHAAyH,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,AAEzI,SAAS,SAAS,CAAC,KAAK,CAAE,CACxC,SAAS,aAAa,CAAC,IAAI,CAAE,IAAI,CAAE,IAAI,C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AAC5C,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAE,OAAO,CAAC,CAAC,AAE7C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,AACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,AAGzB,gBAAgB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAC9B,AAGD,SAAS,CAAC,OAAO,GAAG,SAAS,CAAC,SAAS,GAAG,SAAS,CAAC","file":"tags-input.js","sourceRoot":"src","sourcesContent":["const BACKSPACE = 8,\r\n\tTAB = 9,\r\n\tENTER = 13,\r\n\tLEFT = 37,\r\n\tRIGHT = 39,\r\n\tDELETE = 46,\r\n\tCOMMA = 188;\r\n\r\nconst SEPERATOR = ',';\r\n\r\nconst COPY_PROPS = 'placeholder pattern spellcheck autocomplete autocapitalize autofocus accessKey accept lang minLength maxLength required'.split(' ');\r\n\r\nexport default function tagsInput(input) {\r\n\tfunction createElement(type, name, text, attributes) {\r\n\t\tlet el = document.createElement(type);\r\n\t\tif (name) el.className = name;\r\n\t\tif (text) el.textContent = text;\r\n\t\tfor (let key in attributes) {\r\n\t\t\tel.setAttribute(`data-${key}`, attributes[key]);\r\n\t\t}\r\n\t\treturn el;\r\n\t}\r\n\r\n\tfunction $(selector, all) {\r\n\t\treturn all===true ? Array.prototype.slice.call(base.querySelectorAll(selector)) : base.querySelector(selector);\r\n\t}\r\n\r\n\tfunction getValue() {\r\n\t\treturn $('.tag', true)\r\n\t\t\t.map( tag => tag.textContent )\r\n\t\t\t.concat(base.input.value || [])\r\n\t\t\t.join(SEPERATOR);\r\n\t}\r\n\r\n\tfunction setValue(value) {\r\n\t\t$('.tag', true).forEach( t => base.removeChild(t) );\r\n\t\tsavePartialInput(value);\r\n\t}\r\n\r\n\tfunction save() {\r\n\t\tinput.value = getValue();\r\n\t\tinput.dispatchEvent(new Event('change'));\r\n\t}\r\n\r\n\t// Return false if no need to add a tag\r\n\tfunction addTag(text) {\r\n\t\t// Add multiple tags if the user pastes in data with SEPERATOR already in it\r\n\t\tif (~text.indexOf(SEPERATOR)) text = text.split(SEPERATOR);\r\n\t\tif (Array.isArray(text)) return text.forEach(addTag);\r\n\r\n\t\tlet tag = text && text.trim();\r\n\t\t// Ignore if text is empty\r\n\t\tif (!tag) return false;\r\n\r\n\t\t// For duplicates, briefly highlight the existing tag\r\n\t\tif (!input.getAttribute('duplicates')) {\r\n\t\t\tlet exisingTag = $(`[data-tag=\"${tag}\"]`);\r\n\t\t\tif (exisingTag) {\r\n\t\t\t\texisingTag.classList.add('dupe');\r\n\t\t\t\tsetTimeout( () => exisingTag.classList.remove('dupe') , 100);\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tbase.insertBefore(\r\n\t\t\tcreateElement('span', 'tag', tag, { tag }),\r\n\t\t\tbase.input\r\n\t\t);\r\n\t}\r\n\r\n\tfunction select(el) {\r\n\t\tlet sel = $('.selected');\r\n\t\tif (sel) sel.classList.remove('selected');\r\n\t\tif (el) el.classList.add('selected');\r\n\t}\r\n\r\n\tfunction setInputWidth() {\r\n\t\tlet last = $('.tag',true).pop(),\r\n\t\t\tw = base.offsetWidth;\r\n\t\tif (!w) return;\r\n\t\tbase.input.style.width = Math.max(\r\n\t\t\tw - (last ? (last.offsetLeft+last.offsetWidth) : 5) - 5,\r\n\t\t\tw/4\r\n\t\t) + 'px';\r\n\t}\r\n\r\n\tfunction savePartialInput(value) {\r\n\t\tif (typeof value!=='string' && !Array.isArray(value)) {\r\n\t\t\t// If the base input does not contain a value, default to the original element passed\r\n\t\t\tvalue = base.input.value;\r\n\t\t}\r\n\t\tif (addTag(value)!==false) {\r\n\t\t\tbase.input.value = '';\r\n\t\t\tsave();\r\n\t\t\tsetInputWidth();\r\n\t\t}\r\n\t}\r\n\r\n\tfunction refocus(e) {\r\n\t\tif (e.target.classList.contains('tag')) select(e.target);\r\n\t\tif (e.target===base.input) return select();\r\n\t\tbase.input.focus();\r\n\t\te.preventDefault();\r\n\t\treturn false;\r\n\t}\r\n\r\n\tfunction caretAtStart(el) {\r\n\t\ttry {\r\n\t\t\treturn el.selectionStart === 0 && el.selectionEnd === 0;\r\n\t\t}\r\n\t\tcatch(e) {\r\n\t\t\treturn el.value === '';\r\n\t\t}\r\n\t}\r\n\r\n\r\n\tlet base = createElement('div', 'tags-input'),\r\n\t\tsib = input.nextSibling;\r\n\r\n\tinput.parentNode[sib?'insertBefore':'appendChild'](base, sib);\r\n\r\n\tinput.style.cssText = 'position:absolute;left:0;top:-99px;width:1px;height:1px;opacity:0.01;';\r\n\tinput.tabIndex = -1;\r\n\r\n\tlet inputType = input.getAttribute('type');\r\n\tif (!inputType || inputType === 'tags') {\r\n\t\tinputType = 'text';\r\n\t}\r\n\tbase.input = createElement('input');\r\n\tbase.input.setAttribute('type', inputType);\r\n\tCOPY_PROPS.forEach( prop => {\r\n\t\tif (input[prop]!==base.input[prop]) {\r\n\t\t\tbase.input[prop] = input[prop];\r\n\t\t\ttry { delete input[prop]; }catch(e){}\r\n\t\t}\r\n\t});\r\n\tbase.appendChild(base.input);\r\n\r\n\tinput.addEventListener('focus', () => {\r\n\t\tbase.input.focus();\r\n\t});\r\n\r\n\tinput.addEventListener('change', () => {\r\n\t\tlet currentValue = getValue();\r\n\t\tif(currentValue !== input.value) {\r\n\t\t\tsetValue(input.value);\r\n\t\t\tbase.input.focus();\r\n\t\t}\r\n\t});\r\n\r\n\tbase.input.addEventListener('focus', () => {\r\n\t\tbase.classList.add('focus');\r\n\t\tselect();\r\n\t});\r\n\r\n\tbase.input.addEventListener('blur', () => {\r\n\t\tbase.classList.remove('focus');\r\n\t\tselect();\r\n\t\tsavePartialInput();\r\n\t});\r\n\r\n\tbase.input.addEventListener('keydown', e => {\r\n\t\tlet el = base.input,\r\n\t\t\tkey = e.keyCode || e.which,\r\n\t\t\tselectedTag = $('.tag.selected'),\r\n\t\t\tatStart = caretAtStart(el),\r\n\t\t\tlast = $('.tag',true).pop();\r\n\r\n\t\tsetInputWidth();\r\n\r\n\t\tif (key===ENTER || key===COMMA || key===TAB) {\r\n\t\t\tif (!el.value && key!==COMMA) return;\r\n\t\t\tsavePartialInput();\r\n\t\t}\r\n\t\telse if (key===DELETE && selectedTag) {\r\n\t\t\tif (selectedTag.nextSibling!==base.input) select(selectedTag.nextSibling);\r\n\t\t\tbase.removeChild(selectedTag);\r\n\t\t\tsetInputWidth();\r\n\t\t\tsave();\r\n\t\t}\r\n\t\telse if (key===BACKSPACE) {\r\n\t\t\tif (selectedTag) {\r\n\t\t\t\tselect(selectedTag.previousSibling);\r\n\t\t\t\tbase.removeChild(selectedTag);\r\n\t\t\t\tsetInputWidth();\r\n\t\t\t\tsave();\r\n\t\t\t}\r\n\t\t\telse if (last && atStart) {\r\n\t\t\t\tselect(last);\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t}\r\n\t\telse if (key===LEFT) {\r\n\t\t\tif (selectedTag) {\r\n\t\t\t\tif (selectedTag.previousSibling) {\r\n\t\t\t\t\tselect(selectedTag.previousSibling);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse if (!atStart) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tselect(last);\r\n\t\t\t}\r\n\t\t}\r\n\t\telse if (key===RIGHT) {\r\n\t\t\tif (!selectedTag) return;\r\n\t\t\tselect(selectedTag.nextSibling);\r\n\t\t}\r\n\t\telse {\r\n\t\t\treturn select();\r\n\t\t}\r\n\r\n\t\te.preventDefault();\r\n\t\treturn false;\r\n\t});\r\n\r\n\t// Proxy \"input\" (live change) events , update the first tag live as the user types\r\n\t// This means that users who only want one thing don't have to enter commas\r\n\tbase.input.addEventListener('input', () => {\r\n\t\tinput.value = getValue();\r\n\t\tinput.dispatchEvent(new Event('input'));\r\n\t});\r\n\r\n\t// One tick after pasting, parse pasted text as CSV:\r\n\tbase.input.addEventListener('paste', () => setTimeout(savePartialInput, 0));\r\n\r\n\tbase.addEventListener('mousedown', refocus);\r\n\tbase.addEventListener('touchstart', refocus);\r\n\r\n\tbase.setValue = setValue;\r\n\tbase.getValue = getValue;\r\n\r\n\t// Add tags for existing values\r\n\tsavePartialInput(input.value);\r\n}\r\n\r\n// make life easier:\r\ntagsInput.enhance = tagsInput.tagsInput = tagsInput;\r\n"]} \ No newline at end of file