text: /*
   * The MIT License (MIT)
   *
   * Copyright (c) 2015 - Studionet
   *
   * Permission is hereby granted, free of charge, to any person obtaining a copy
   * of this software and associated documentation files (the "Software"), to deal
   * in the Software without restriction, including without limitation the rights
   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   * copies of the Software, and to permit persons to whom the Software is
   * furnished to do so, subject to the following conditions:
   *
   * The above copyright notice and this permission notice shall be included in
   * all copies or substantial portions of the Software.
   *
   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   * THE SOFTWARE.
   */
  (function(){var t,e=[].indexOf||function(t){for(var e=0,n=this.length;n>e;e++)if(e in this&&this[e]===t)return e;return-1};window.Tag=t=function(){function t(t,e){var n,i,r,s,o,a,l;if(this.element=t,this.options=e,l=this,this.options=this.configureOptions(),this.container=document.createElement("ul"),r=this.createPlaceHolder(),this.element.parentNode.insertBefore(this.container,this.element.nextSibling),this.container.style.position="relative",this.container.style.left=0,this.container.style.height="auto",this.container.style.minHeight=this.element.offsetHeight+"px",this.container.classList.add("tag-input"),this.container.classList.add("container"),this.container.addEventListener("click",function(t){return t.target===l.container?l.createTag():void 0}),this.container.addEventListener("DOMNodeInserted",function(t){r=document.querySelector(".tag-input > .placeholder"),t.target!==r&&r&&l.container.children.length>1&&r.remove()}),this.container.addEventListener("DOMNodeRemoved",function(t){l.container.childNodes.length-1===0&&l.createPlaceHolder()}),this.container.addEventListener("mousedown",function(t){return t.target===l.container?t.preventDefault():void 0}),a=this.element.getAttribute("value")){for(s=a.split(this.options.formSeparator),n=0,i=s.length;i>n;n++)o=s[n],this.createTag(o);this.container.lastChild.firstChild.blur()}}return t.prototype.element=null,t.prototype.options=null,t.prototype.deleted=!1,t.prototype.terms=null,t.prototype.requestInstances=[],t.prototype.defaultOptions={tooltip:!0,tooltipText:"Right click to delete",formSeparator:",",nextTagCodes:[13,188,9],autocomplete:null,autofield:"value",automin:3,autolimit:5,placeholder:null},t.prototype.configureOptions=function(){var t,e,n,i;if(e=this.defaultOptions,"object"!=typeof this.options)return e;i=this.options;for(t in i){if(n=i[t],"undefined"===e[t])throw"`"+t+"` option doesn't exist";e[t]=n}return e},t.prototype.createPlaceHolder=function(){var t;return this.options.placeholder?(t=document.createElement("span"),t.innerHTML=this.options.placeholder,t.classList.add("placeholder"),this.container.appendChild(t),t):null},t.prototype.createTag=function(t){var n,i,r,s;return r=this,i=document.createElement("li"),i.classList.add("tag-input"),i.classList.add("tag"),n=document.createElement("span"),n.classList.add("tag-content"),n.contentEditable=!0,t&&(n.innerHTML=t),i.appendChild(n),this.container.appendChild(i),this.options.tooltip&&(s=document.createElement("span"),s.classList.add("tag-tooltip"),s.innerHTML=this.options.tooltipText,i.appendChild(s)),this.createFocus(i),i.firstChild.addEventListener("blur",function(){return this.innerHTML?(sessionStorage.removeItem("tags-input-autocomplete"),r.fillInput()):void this.parentNode.remove()}),i.addEventListener("keydown",function(n){var i;return i=n.keyCode,e.call(r.options.nextTagCodes,i)>=0&&(n.preventDefault(),t=sessionStorage.getItem("tags-input-autocomplete"),t&&(this.firstChild.innerHTML=t),this.firstChild.innerHTML)?(r.createTag(),!1):sessionStorage.removeItem("tags-input-autocomplete")}),i.firstChild.addEventListener("input",function(t){var e,n;return e=r.options.automin,sessionStorage.setItem("tags-input-value",this.innerHTML),n=window.getSelection().getRangeAt(0),r.clearRequests(),!r.options.autocomplete||this.innerHTML.length<e||n.startOffset!==this.innerHTML.length?void 0:(clearTimeout(r.timer),r.requestTerm(this.parentNode))}),i.addEventListener("contextmenu",function(t){return this.remove(),r.fillInput(),t.preventDefault(),!1})},t.prototype.createFocus=function(t){return this.terms&&this.terms.remove(),this.terms=null,t.firstChild.focus()},t.prototype.requestTerm=function(t){var e,n,i,r;return i=this,r=t.firstChild.innerHTML,e=this.options.autocomplete.replace("%search%",r),n=new XMLHttpRequest,n.open("GET",e,!0),n.addEventListener("readystatechange",function(e){var n,s,o;return s=e.target,4===s.readyState&&200===s.status?(n=JSON.parse(s.responseText),o=i.autocomplete(n,r),i.showTerms(o,t)):void 0}),n.send(null),this.requestInstances.push(n)},t.prototype.clearRequests=function(){var t,e,n,i,r;if(this.requestInstances.length>0){for(i=this.requestInstances,r=[],t=0,n=i.length;n>t;t++)e=i[t],e.abort(),r.push(this.requestInstances.slice(this.requestInstances.indexOf(e),1));return r}},t.prototype.searchTerm=function(t,e){var n,i,r,s;r=[];for(i in t)s=t[i],s instanceof Object&&(n=this.searchTerm(s,e),n.length&&(r=r.concat(n))),i===this.options.autofield&&(r=r.concat(s));return r},t.prototype.autocomplete=function(t,e){var n,i,r;if(t&&e){i=[];for(n in t)r=t[n],r instanceof Array&&(i=i.concat(this.searchTerm(r,e)));return i.slice(0,this.options.autolimit)}},t.prototype.showTerms=function(t,e){var n,i,r,s,o,a;for(a=this,this.terms||(this.terms=document.createElement("div"),this.terms.classList.add("tag-input"),this.terms.classList.add("terms"),this.container.appendChild(this.terms));this.terms.firstChild;)this.terms.removeChild(this.terms.firstChild);for(s=[],n=0,i=t.length;i>n;n++)o=t[n],r=document.createElement("div"),r.classList.add("tag-input"),r.classList.add("link-term"),r.innerHTML=o,r.addEventListener("click",function(t){return e.firstChild.innerHTML=t.target.innerHTML,a.terms.remove(),a.terms=null}),s.push(this.terms.appendChild(r));return s},t.prototype.fillInput=function(){var t,e,n,i,r;for(r=this.container.childNodes,t=[],e=0,n=r.length;n>e;e++)i=r[e],t.push(i.firstChild.innerHTML);return this.element.setAttribute("value",t.join(this.options.formSeparator))},t.guess=function(e,n){var i,r,s,o;for(o=[],r=0,s=e.length;s>r;r++)i=e[r],o.push(new t(i,n));return o},t}()}).call(this);