var Dotdotdot=function(){function d(b,c){void 0===c&&(c=d.options);var e=this,a;for(a in this.container=b,this.options=c||{},this.watchTimeout=null,this.watchInterval=null,this.resizeEvent=null,d.options)d.options.hasOwnProperty(a)&&void 0===this.options[a]&&(this.options[a]=d.options[a]);(a=this.container.dotdotdot)&&a.destroy();this.API={};["truncate","restore","destroy","watch","unwatch"].forEach(function(a){e.API[a]=function(){return e[a].call(e)}});this.container.dotdotdot=this.API;this.originalStyle=
this.container.getAttribute("style")||"";this.originalContent=this._getOriginalContent();this.ellipsis=document.createTextNode(this.options.ellipsis);a=window.getComputedStyle(this.container);"break-word"!==a["word-wrap"]&&(this.container.style["word-wrap"]="break-word");"pre"===a["white-space"]?this.container.style["white-space"]="pre-wrap":"nowrap"===a["white-space"]&&(this.container.style["white-space"]="normal");null===this.options.height&&(this.options.height=this._getMaxHeight());this.truncate();
this.options.watch&&this.watch()}return d.prototype.restore=function(){var b=this;this.unwatch();this.container.setAttribute("style",this.originalStyle);this.container.classList.remove("ddd-truncated");this.container.innerHTML="";this.originalContent.forEach(function(c){b.container.append(c)})},d.prototype.destroy=function(){this.restore();this.container.dotdotdot=null},d.prototype.watch=function(){var b=this;this.unwatch();var c={width:null,height:null},e=function(a,e,d){return b.container.offsetWidth||
b.container.offsetHeight||b.container.getClientRects().length?(a={width:a[e],height:a[d]},c.width==a.width&&c.height==a.height||b.truncate(),a):c};"window"===this.options.watch?(this.resizeEvent=function(a){b.watchTimeout&&clearTimeout(b.watchTimeout);b.watchTimeout=setTimeout(function(){c=e(window,"innerWidth","innerHeight")},100)},window.addEventListener("resize",this.resizeEvent)):this.watchInterval=setInterval(function(){c=e(b.container,"clientWidth","clientHeight")},1E3)},d.prototype.unwatch=
function(){this.resizeEvent&&(window.removeEventListener("resize",this.resizeEvent),this.resizeEvent=null);this.watchInterval&&clearInterval(this.watchInterval);this.watchTimeout&&clearTimeout(this.watchTimeout)},d.prototype.truncate=function(){var b=this,c=!1;return this.container.innerHTML="",this.originalContent.forEach(function(c){b.container.append(c.cloneNode(!0))}),this.maxHeight=this._getMaxHeight(),this._fits()||(c=!0,this._truncateToNode(this.container)),this.container.classList[c?"add":
"remove"]("ddd-truncated"),this.options.callback.call(this.container,c),c},d.prototype._truncateToNode=function(b){var c=[],e=[];if(d.$.contents(b).forEach(function(a){if(1!=a.nodeType||!a.matches(".ddd-keep")){var b=document.createComment("");a.replaceWith(b);e.push(a);c.push(b)}}),e.length){for(b=0;b<e.length;b++){c[b].replaceWith(e[b]);var a=this.ellipsis.cloneNode(!0);switch(e[b].nodeType){case 1:e[b].append(a);break;case 3:e[b].after(a)}var f=this._fits();if(a.parentElement.removeChild(a),!f){if("node"==
this.options.truncate&&1<b)return void e[b-2].remove();break}}for(a=b;a<c.length;a++)c[a].remove();a=e[Math.max(0,Math.min(b,e.length-1))];1==a.nodeType&&(f=document.createElement(a.nodeName),f.append(this.ellipsis),a.replaceWith(f),this._fits()?f.replaceWith(a):(f.remove(),a=e[Math.max(0,b-1)]));1==a.nodeType?this._truncateToNode(a):this._truncateToWord(a)}},d.prototype._truncateToWord=function(b){for(var c=b.textContent,e=-1!==c.indexOf(" ")?" ":"\u3000",c=c.split(e),a=c.length;0<=a;a--)if(b.textContent=
this._addEllipsis(c.slice(0,a).join(e)),this._fits()){"letter"==this.options.truncate&&(b.textContent=c.slice(0,a+1).join(e),this._truncateToLetter(b));break}},d.prototype._truncateToLetter=function(b){for(var c=b.textContent.split(""),e="",a=c.length;0<=a&&(!(e=c.slice(0,a).join("")).length||(b.textContent=this._addEllipsis(e),!this._fits()));a--);},d.prototype._fits=function(){return this.container.scrollHeight<=this.maxHeight+this.options.tolerance},d.prototype._addEllipsis=function(b){for(var c=
" \u3000,;.!?".split("");-1<c.indexOf(b.slice(-1));)b=b.slice(0,-1);return b+this.ellipsis.textContent},d.prototype._getOriginalContent=function(){var b="script, style";this.options.keep&&(b+=", "+this.options.keep);d.$.find(b,this.container).forEach(function(b){b.classList.add("ddd-keep")});[this.container].concat(d.$.find("*",this.container)).forEach(function(b){b.normalize();d.$.contents(b).forEach(function(a){8==a.nodeType&&b.removeChild(a)});d.$.contents(b).forEach(function(a){if(3==a.nodeType&&
""==a.textContent.trim()){var c=a.previousSibling,d=a.nextSibling;(a.parentElement.matches("table, thead, tbody, tfoot, tr, dl, ul, ol, video")||!c||1==c.nodeType&&c.matches("div, section, article, header, footer, p, h1, h2, h3, h4, h5, h6, table, td, td, dt, dd, li")||!d||1==d.nodeType&&d.matches("div, section, article, header, footer, p, h1, h2, h3, h4, h5, h6, table, td, td, dt, dd, li"))&&b.removeChild(a)}})});var c=[];return d.$.contents(this.container).forEach(function(b){c.push(b.cloneNode(!0))}),
c},d.prototype._getMaxHeight=function(){if("number"==typeof this.options.height)return this.options.height;for(var b=window.getComputedStyle(this.container),c=["maxHeight","height"],d=0,a=0;a<c.length;a++)if("px"==(f=b[c[a]]).slice(-2)){d=parseFloat(f);break}if("border-box"==b.boxSizing)for(c=["borderTopWidth","borderBottomWidth","paddingTop","paddingBottom"],a=0;a<c.length;a++){var f;"px"==(f=b[c[a]]).slice(-2)&&(d-=parseFloat(f))}return Math.max(d,0)},d.version="4.1.0",d.options={ellipsis:"\u2026 ",
callback:function(b){},truncate:"word",tolerance:0,keep:null,watch:"window",height:null},d.$={find:function(b,c){return c=c||document,Array.prototype.slice.call(c.querySelectorAll(b))},contents:function(b){return b=b||document,Array.prototype.slice.call(b.childNodes)}},d}();!function(d){void 0!==d&&(d.fn.dotdotdot=function(b){return this.each(function(c,d){var a=new Dotdotdot(d,b);d.dotdotdot=a.API})})}(window.Zepto||window.jQuery);
