-
Notifications
You must be signed in to change notification settings - Fork 1
/
textsplitr.min.js
2 lines (2 loc) · 1.28 KB
/
textsplitr.min.js
1
2
// https://github.com/titoasty/textsplitr
!function(e,t){function n(e,t){if(this.chars=[],this.words=[],this.options=t,this.options={type:"chars"},t)for(var n in t)this.options[n]=t[n];for(var i=e.innerHTML,r=this.options.type.indexOf("chars")>=0,o=this.options.type.indexOf("words")>=0,s=[],a=i.match(/<span[^>]*>(.*?)<\/span>/g),h=0;h<a.length;h++){var d=i.indexOf(a[h]);s[d]=a[h]}e.innerHTML="";for(var h=0,p=!0,c=null;h<i.length;)if(s[h]){var l=s[h];h+=l.length,e.insertAdjacentHTML("beforeEnd",l);var u=e.childNodes[e.childNodes.length-1];this.words.push(u),this.chars.push(u)}else{var f=i.charAt(h),v=" "==f;r&&!o&&(v?e.appendChild(document.createTextNode(" ")):e.appendChild(this.createCharContainer(f))),o&&(v?(e.appendChild(document.createTextNode(" ")),p=!0):(p&&(p=!1,c=this.createWordContainer(""),e.appendChild(c)),r?c.appendChild(this.createCharContainer(f)):c.innerHTML+=f)),h++}}n.prototype.createCharContainer=function(e){var t=document.createElement("div");return t.style.display="inline-block",t.style.position="relative",t.innerHTML=e,this.chars.push(t),t},n.prototype.createWordContainer=function(e){var t=document.createElement("div");return t.style.display="inline-block",t.style.position="relative",t.innerHTML=e,this.words.push(t),t},e=n,t.TextSplitr=e}({},function(){return this}());