From fdb76a6f346d14349b9b2aad8eac3b6083efeed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Vigh?= Date: Thu, 13 Oct 2016 15:29:16 +0200 Subject: [PATCH 1/9] add wrap to options --- dist/truncate.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/dist/truncate.js b/dist/truncate.js index fd72ee6..6e3c3f7 100644 --- a/dist/truncate.js +++ b/dist/truncate.js @@ -351,7 +351,8 @@ * ellipsis: '… ', * showMore: 'Show More', * showLess: 'Show Less', - * position: "start" + * position: "start", + * wrap: 'word' * }); * * // Update HTML @@ -377,7 +378,8 @@ showMore: '', showLess: '', position: 'end', - lineHeight: 'auto' + lineHeight: 'auto', + wrap: 'word' }; this.config(options); @@ -420,6 +422,10 @@ this.options.position = 'end'; } + if (this.options.wrap === undefined) { + this.options.wrap = 'word'; + } + this.$clipNode = $($.parseHTML(this.options.showMore), this.$element); // Forced update if plugin already initialized @@ -514,7 +520,7 @@ */ collapse: function (retruncate) { this.isExplicitlyCollapsed = true; - + if (this.isCollapsed) { return; } From 55766f43a20ff0b7ad97ee22034c6bcc9459b09b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Vigh?= Date: Thu, 13 Oct 2016 15:30:15 +0200 Subject: [PATCH 2/9] add replaceNbsps function --- dist/truncate.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dist/truncate.js b/dist/truncate.js index 6e3c3f7..f10b207 100644 --- a/dist/truncate.js +++ b/dist/truncate.js @@ -13,6 +13,11 @@ return text.replace(/\s*$/,""); } + function replaceNbsps(str) { + var rep = new RegExp(String.fromCharCode(160), "g"); + return str.replace(rep, " "); + } + function setText(element, text) { if (element.innerText) { element.innerText = text; From e5b42330a661b8de3902609f3ff5d4560ed84c34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Vigh?= Date: Thu, 13 Oct 2016 15:41:27 +0200 Subject: [PATCH 3/9] call replaceNbsps if wrap is set to word --- dist/truncate.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/dist/truncate.js b/dist/truncate.js index f10b207..436903f 100644 --- a/dist/truncate.js +++ b/dist/truncate.js @@ -18,7 +18,10 @@ return str.replace(rep, " "); } - function setText(element, text) { + function setText(element, text, options) { + if ( options.wrap === 'word' ){ + text = replaceNbsps(text); + } if (element.innerText) { element.innerText = text; } else if (element.nodeValue) { @@ -71,7 +74,7 @@ // Because traversal is in-order so the algorithm already checked that // this point meets the height requirement. As such, it's safe to truncate here. - setText($prevSibling[0], $prevSibling.text() + options.ellipsis); + setText($prevSibling[0], $prevSibling.text() + options.ellipsis, options); $parent.remove(); if ($clipNode.length) { @@ -98,7 +101,7 @@ mid = low + ((high - low) >> 1); // Integer division chunk = options.ellipsis + trimRight(original.substr(mid - 1, original.length)); - setText(element, chunk); + setText(element, chunk, options); if ($rootNode.height() > options.maxHeight) { // too big, reduce the chunk @@ -112,7 +115,7 @@ } if (maxChunk.length > 0) { - setText(element, maxChunk); + setText(element, maxChunk, options); return true; } else { return truncateNearestSibling($element, $rootNode, $clipNode, options); @@ -134,7 +137,7 @@ mid = low + ((high - low) >> 1); // Integer division chunk = trimRight(original.substr(0, mid + 1)) + options.ellipsis; - setText(element, chunk); + setText(element, chunk, options); if ($rootNode.height() > options.maxHeight) { // too big, reduce the chunk @@ -147,7 +150,7 @@ } if (maxChunk.length > 0) { - setText(element, maxChunk); + setText(element, maxChunk, options); return true; } else { return truncateNearestSibling($element, $rootNode, $clipNode, options); @@ -169,7 +172,7 @@ mid = low + ((high - low) >> 1); // Integer division chunk = trimRight(original.substr(0, mid)) + options.ellipsis + original.substr(len - mid, len - mid); - setText(element, chunk); + setText(element, chunk, options); if ($rootNode.height() > options.maxHeight) { // too big, reduce the chunk @@ -184,7 +187,7 @@ } if (maxChunk.length > 0) { - setText(element, maxChunk); + setText(element, maxChunk, options); return true; } else { return truncateNearestSibling($element, $rootNode, $clipNode, options); From aef5e4c325d84009348527f60ea4eb04061e93f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Vigh?= Date: Thu, 13 Oct 2016 15:45:52 +0200 Subject: [PATCH 4/9] add truncateWordChunk function --- dist/truncate.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dist/truncate.js b/dist/truncate.js index 436903f..c2de81c 100644 --- a/dist/truncate.js +++ b/dist/truncate.js @@ -18,6 +18,14 @@ return str.replace(rep, " "); } + function truncateWordChunk(str,ellipsis){ + + var endChunk = str.substr( text.lastIndexOf(" "),text.length-1 ); + str = str.replace(endChunk,ellipsis); + + return str; + } + function setText(element, text, options) { if ( options.wrap === 'word' ){ text = replaceNbsps(text); From 94f4a4ab2e6ae766397ed6a89787709b4054dd09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Vigh?= Date: Thu, 13 Oct 2016 15:52:57 +0200 Subject: [PATCH 5/9] call truncateWordchunk if wrap set to word --- dist/truncate.js | 1 + 1 file changed, 1 insertion(+) diff --git a/dist/truncate.js b/dist/truncate.js index c2de81c..bb6b9a4 100644 --- a/dist/truncate.js +++ b/dist/truncate.js @@ -29,6 +29,7 @@ function setText(element, text, options) { if ( options.wrap === 'word' ){ text = replaceNbsps(text); + text = truncateWordChunk(text,options.ellipsis); } if (element.innerText) { element.innerText = text; From 0b49619d0034cb1df1dfca6d4282d0fca06575a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Vigh?= Date: Thu, 13 Oct 2016 15:53:16 +0200 Subject: [PATCH 6/9] set default option to wrap by letter --- dist/truncate.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/truncate.js b/dist/truncate.js index bb6b9a4..bb6d8c5 100644 --- a/dist/truncate.js +++ b/dist/truncate.js @@ -369,7 +369,7 @@ * showMore: 'Show More', * showLess: 'Show Less', * position: "start", - * wrap: 'word' + * wrap: 'letter' * }); * * // Update HTML @@ -396,7 +396,7 @@ showLess: '', position: 'end', lineHeight: 'auto', - wrap: 'word' + wrap: 'letter' }; this.config(options); @@ -440,7 +440,7 @@ } if (this.options.wrap === undefined) { - this.options.wrap = 'word'; + this.options.wrap = 'letter'; } this.$clipNode = $($.parseHTML(this.options.showMore), this.$element); From e8de05be8af512511d9c9218376881afc3a2d860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Vigh?= Date: Thu, 13 Oct 2016 15:56:10 +0200 Subject: [PATCH 7/9] apply changes to the original truncate.js file --- truncate.js | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/truncate.js b/truncate.js index fd72ee6..5069a39 100644 --- a/truncate.js +++ b/truncate.js @@ -13,7 +13,24 @@ return text.replace(/\s*$/,""); } - function setText(element, text) { + function replaceNbsps(str) { + var rep = new RegExp(String.fromCharCode(160), "g"); + return str.replace(rep, " "); + } + + function truncateWordChunk(str,ellipsis){ + + var endChunk = str.substr( text.lastIndexOf(" "),text.length-1 ); + str = str.replace(endChunk,ellipsis); + + return str; + } + + function setText(element, text, options) { + if ( options.wrap === 'word' ){ + text = replaceNbsps(text); + text = truncateWordChunk(text,options.ellipsis); + } if (element.innerText) { element.innerText = text; } else if (element.nodeValue) { @@ -66,7 +83,7 @@ // Because traversal is in-order so the algorithm already checked that // this point meets the height requirement. As such, it's safe to truncate here. - setText($prevSibling[0], $prevSibling.text() + options.ellipsis); + setText($prevSibling[0], $prevSibling.text() + options.ellipsis, options); $parent.remove(); if ($clipNode.length) { @@ -93,7 +110,7 @@ mid = low + ((high - low) >> 1); // Integer division chunk = options.ellipsis + trimRight(original.substr(mid - 1, original.length)); - setText(element, chunk); + setText(element, chunk, options); if ($rootNode.height() > options.maxHeight) { // too big, reduce the chunk @@ -107,7 +124,7 @@ } if (maxChunk.length > 0) { - setText(element, maxChunk); + setText(element, maxChunk, options); return true; } else { return truncateNearestSibling($element, $rootNode, $clipNode, options); @@ -129,7 +146,7 @@ mid = low + ((high - low) >> 1); // Integer division chunk = trimRight(original.substr(0, mid + 1)) + options.ellipsis; - setText(element, chunk); + setText(element, chunk, options); if ($rootNode.height() > options.maxHeight) { // too big, reduce the chunk @@ -142,7 +159,7 @@ } if (maxChunk.length > 0) { - setText(element, maxChunk); + setText(element, maxChunk, options); return true; } else { return truncateNearestSibling($element, $rootNode, $clipNode, options); @@ -164,7 +181,7 @@ mid = low + ((high - low) >> 1); // Integer division chunk = trimRight(original.substr(0, mid)) + options.ellipsis + original.substr(len - mid, len - mid); - setText(element, chunk); + setText(element, chunk, options); if ($rootNode.height() > options.maxHeight) { // too big, reduce the chunk @@ -179,7 +196,7 @@ } if (maxChunk.length > 0) { - setText(element, maxChunk); + setText(element, maxChunk, options); return true; } else { return truncateNearestSibling($element, $rootNode, $clipNode, options); @@ -351,7 +368,8 @@ * ellipsis: '… ', * showMore: 'Show More', * showLess: 'Show Less', - * position: "start" + * position: "start", + * wrap: 'letter' * }); * * // Update HTML @@ -377,7 +395,8 @@ showMore: '', showLess: '', position: 'end', - lineHeight: 'auto' + lineHeight: 'auto', + wrap: 'letter' }; this.config(options); @@ -403,7 +422,7 @@ if (this.options.lineHeight === 'auto') { var lineHeightCss = this.$element.css('line-height'), - lineHeight = 18; // for Normal we return the default value: 18px + lineHeight = 18; // for Normal we return the default value: 18px if (lineHeightCss !== "normal") { lineHeight = parseInt(lineHeightCss, 10); @@ -420,6 +439,10 @@ this.options.position = 'end'; } + if (this.options.wrap === undefined) { + this.options.wrap = 'letter'; + } + this.$clipNode = $($.parseHTML(this.options.showMore), this.$element); // Forced update if plugin already initialized @@ -514,7 +537,7 @@ */ collapse: function (retruncate) { this.isExplicitlyCollapsed = true; - + if (this.isCollapsed) { return; } From 4370c417e1d9c447bd915254834517f369bf3c69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Vigh?= Date: Thu, 13 Oct 2016 16:00:30 +0200 Subject: [PATCH 8/9] fix truncateWordChunk's text to str --- truncate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/truncate.js b/truncate.js index 5069a39..6d23dbc 100644 --- a/truncate.js +++ b/truncate.js @@ -20,7 +20,7 @@ function truncateWordChunk(str,ellipsis){ - var endChunk = str.substr( text.lastIndexOf(" "),text.length-1 ); + var endChunk = str.substr( str.lastIndexOf(" "),str.length-1 ); str = str.replace(endChunk,ellipsis); return str; From 33f1e11416704b5055e8961fcc61fa724898876a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Vigh?= Date: Thu, 13 Oct 2016 16:14:51 +0200 Subject: [PATCH 9/9] add wrap option to README.md --- README.md | 1 + dist/truncate.js | 2 +- dist/truncate.min.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4fda463..b91c468 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ Truncate.js currently depends on jQuery. There are two ways to use Truncate.js: - `showLess`: HTML to insert when .expand() is called. Useful for a "Show Less" button. _default: ""_ - `position`: Position of the truncation. Possible values: `start`, `middle`, `end`. _default: "end"_ - `maxHeight`: Truncate the content to fit in the specified height (in px). +- `wrap`: Prevent words to be broken at truncation. Content breaks on full words if wrap is set to `word`. _default: "letter"_ ---- diff --git a/dist/truncate.js b/dist/truncate.js index bb6d8c5..5069a39 100644 --- a/dist/truncate.js +++ b/dist/truncate.js @@ -422,7 +422,7 @@ if (this.options.lineHeight === 'auto') { var lineHeightCss = this.$element.css('line-height'), - lineHeight = 18; // for Normal we return the default value: 18px + lineHeight = 18; // for Normal we return the default value: 18px if (lineHeightCss !== "normal") { lineHeight = parseInt(lineHeightCss, 10); diff --git a/dist/truncate.min.js b/dist/truncate.min.js index a0e5355..c0a3dd0 100644 --- a/dist/truncate.min.js +++ b/dist/truncate.min.js @@ -1 +1 @@ -!function(t,e,i){function n(t){return t.replace(/\s*$/,"")}function s(t,e){if(t.innerText)t.innerText=e;else if(t.nodeValue)t.nodeValue=e;else{if(!t.textContent)return!1;t.textContent=e}}function o(t,e,i,n){var o,h=t.parent();t.remove();var r=i?i.length:0;if(h.contents().length>r)return o=h.contents().eq(-1-r),a(o,e,i,n);var l=h.prev();return o=l.contents().eq(-1),!!o.length&&(s(o[0],o.text()+n.ellipsis),h.remove(),i.length&&l.append(i),!0)}function h(t,e,i,h){for(var r,l,a=t[0],p=t.text(),d="",c=0,u=p.length;c<=u;)r=c+(u-c>>1),l=h.ellipsis+n(p.substr(r-1,p.length)),s(a,l),e.height()>h.maxHeight?c=r+1:(u=r-1,d=d.length>l.length?d:l);return d.length>0?(s(a,d),!0):o(t,e,i,h)}function r(t,e,i,h){for(var r,l,a=t[0],p=t.text(),d="",c=0,u=p.length;c<=u;)r=c+(u-c>>1),l=n(p.substr(0,r+1))+h.ellipsis,s(a,l),e.height()>h.maxHeight?u=r-1:(c=r+1,d=d.length>l.length?d:l);return d.length>0?(s(a,d),!0):o(t,e,i,h)}function l(t,e,i,h){for(var r,l,a=t[0],p=t.text(),d="",c=0,u=p.length,g=u>>1;c<=g;)r=c+(g-c>>1),l=n(p.substr(0,r))+h.ellipsis+p.substr(u-r,u-r),s(a,l),e.height()>h.maxHeight?g=r-1:(c=r+1,d=d.length>l.length?d:l);return d.length>0?(s(a,d),!0):o(t,e,i,h)}function a(t,e,i,n){return"end"===n.position?r(t,e,i,n):"start"===n.position?h(t,e,i,n):l(t,e,i,n)}function p(t,i,n,s){var o,h,r=t[0],l=t.contents(),p=l.length,d=p-1,u=!1;for(t.empty();d>=0&&!u;d--)o=l.eq(d),h=o[0],8!==h.nodeType&&(r.insertBefore(h,r.firstChild),n.length&&(e.inArray(r.tagName.toLowerCase(),g)>=0?t.after(n):t.append(n)),i.height()>s.maxHeight&&(u=3===h.nodeType?a(o,i,n,s):c(o,i,n,s)),!u&&n.length&&n.remove());return u}function d(t,i,n,s){var o,h,r=t[0],l=t.contents(),p=0,d=l.length,u=!1;for(t.empty();p=0?t.after(n):t.append(n)),i.height()>s.maxHeight&&(u=3===h.nodeType?a(o,i,n,s):c(o,i,n,s)),!u&&n.length&&n.remove());return u}function c(t,e,i,n){return"end"===n.position?d(t,e,i,n):"start"===n.position?p(t,e,i,n):d(t,e,i,n)}function u(t,i){this.element=t,this.$element=e(t),this._name="truncate",this._defaults={lines:1,ellipsis:"…",showMore:"",showLess:"",position:"end",lineHeight:"auto"},this.config(i),this.original=this.cached=t.innerHTML,this.isTruncated=!1,this.isCollapsed=!0,this.update()}var g=["table","thead","tbody","tfoot","tr","col","colgroup","object","embed","param","ol","ul","dl","blockquote","select","optgroup","option","textarea","script","style"];u.prototype={config:function(t){if(this.options=e.extend({},this._defaults,t),"auto"===this.options.lineHeight){var n=this.$element.css("line-height"),s=18;"normal"!==n&&(s=parseInt(n,10)),this.options.lineHeight=s}this.options.maxHeight===i&&(this.options.maxHeight=parseInt(this.options.lines,10)*parseInt(this.options.lineHeight,10)),"start"!==this.options.position&&"middle"!==this.options.position&&"end"!==this.options.position&&(this.options.position="end"),this.$clipNode=e(e.parseHTML(this.options.showMore),this.$element),this.original&&this.update()},update:function(t){var e=!this.isCollapsed;"undefined"!=typeof t?this.original=this.element.innerHTML=t:this.isCollapsed&&this.element.innerHTML===this.cached&&(this.element.innerHTML=this.original);var i=this.$element.wrapInner("
").children();i.css({border:"none",margin:0,padding:0,width:"auto",height:"auto","word-wrap":"break-word"}),this.isTruncated=!1,i.height()>this.options.maxHeight?(this.isTruncated=c(i,i,this.$clipNode,this.options),this.isExplicitlyCollapsed&&(this.isCollapsed=!0,e=!1)):this.isCollapsed=!1,i.replaceWith(i.contents()),this.cached=this.element.innerHTML,e&&(this.element.innerHTML=this.original)},expand:function(){var t=!0;this.isExplicitlyCollapsed&&(this.isExplicitlyCollapsed=!1,t=!1),this.isCollapsed&&(this.isCollapsed=!1,this.element.innerHTML=this.isTruncated?this.original+(t?this.options.showLess:""):this.original)},collapse:function(t){this.isExplicitlyCollapsed=!0,this.isCollapsed||(this.isCollapsed=!0,t=t||!1,t?this.update():this.element.innerHTML=this.cached)}},e.fn.truncate=function(t){var i=e.makeArray(arguments).slice(1);return this.each(function(){var n=e.data(this,"jquery-truncate");n?"function"==typeof n[t]&&n[t].apply(n,i):e.data(this,"jquery-truncate",new u(this,t))})},t.Truncate=u}(this,jQuery); \ No newline at end of file +!function(t,e,i){function n(t){return t.replace(/\s*$/,"")}function s(t){var e=new RegExp(String.fromCharCode(160),"g");return t.replace(e," ")}function o(t,e){var i=t.substr(text.lastIndexOf(" "),text.length-1);return t=t.replace(i,e)}function r(t,e,i){if("word"===i.wrap&&(e=s(e),e=o(e,i.ellipsis)),t.innerText)t.innerText=e;else if(t.nodeValue)t.nodeValue=e;else{if(!t.textContent)return!1;t.textContent=e}}function h(t,e,i,n){var s,o=t.parent();t.remove();var h=i?i.length:0;if(o.contents().length>h)return s=o.contents().eq(-1-h),d(s,e,i,n);var l=o.prev();return s=l.contents().eq(-1),!!s.length&&(r(s[0],s.text()+n.ellipsis,n),o.remove(),i.length&&l.append(i),!0)}function l(t,e,i,s){for(var o,l,a=t[0],p=t.text(),d="",u=0,c=p.length;u<=c;)o=u+(c-u>>1),l=s.ellipsis+n(p.substr(o-1,p.length)),r(a,l,s),e.height()>s.maxHeight?u=o+1:(c=o-1,d=d.length>l.length?d:l);return d.length>0?(r(a,d,s),!0):h(t,e,i,s)}function a(t,e,i,s){for(var o,l,a=t[0],p=t.text(),d="",u=0,c=p.length;u<=c;)o=u+(c-u>>1),l=n(p.substr(0,o+1))+s.ellipsis,r(a,l,s),e.height()>s.maxHeight?c=o-1:(u=o+1,d=d.length>l.length?d:l);return d.length>0?(r(a,d,s),!0):h(t,e,i,s)}function p(t,e,i,s){for(var o,l,a=t[0],p=t.text(),d="",u=0,c=p.length,g=c>>1;u<=g;)o=u+(g-u>>1),l=n(p.substr(0,o))+s.ellipsis+p.substr(c-o,c-o),r(a,l,s),e.height()>s.maxHeight?g=o-1:(u=o+1,d=d.length>l.length?d:l);return d.length>0?(r(a,d,s),!0):h(t,e,i,s)}function d(t,e,i,n){return"end"===n.position?a(t,e,i,n):"start"===n.position?l(t,e,i,n):p(t,e,i,n)}function u(t,i,n,s){var o,r,h=t[0],l=t.contents(),a=l.length,p=a-1,u=!1;for(t.empty();p>=0&&!u;p--)o=l.eq(p),r=o[0],8!==r.nodeType&&(h.insertBefore(r,h.firstChild),n.length&&(e.inArray(h.tagName.toLowerCase(),m)>=0?t.after(n):t.append(n)),i.height()>s.maxHeight&&(u=3===r.nodeType?d(o,i,n,s):g(o,i,n,s)),!u&&n.length&&n.remove());return u}function c(t,i,n,s){var o,r,h=t[0],l=t.contents(),a=0,p=l.length,u=!1;for(t.empty();a=0?t.after(n):t.append(n)),i.height()>s.maxHeight&&(u=3===r.nodeType?d(o,i,n,s):g(o,i,n,s)),!u&&n.length&&n.remove());return u}function g(t,e,i,n){return"end"===n.position?c(t,e,i,n):"start"===n.position?u(t,e,i,n):c(t,e,i,n)}function f(t,i){this.element=t,this.$element=e(t),this._name="truncate",this._defaults={lines:1,ellipsis:"…",showMore:"",showLess:"",position:"end",lineHeight:"auto",wrap:"letter"},this.config(i),this.original=this.cached=t.innerHTML,this.isTruncated=!1,this.isCollapsed=!0,this.update()}var m=["table","thead","tbody","tfoot","tr","col","colgroup","object","embed","param","ol","ul","dl","blockquote","select","optgroup","option","textarea","script","style"];f.prototype={config:function(t){if(this.options=e.extend({},this._defaults,t),"auto"===this.options.lineHeight){var n=this.$element.css("line-height"),s=18;"normal"!==n&&(s=parseInt(n,10)),this.options.lineHeight=s}this.options.maxHeight===i&&(this.options.maxHeight=parseInt(this.options.lines,10)*parseInt(this.options.lineHeight,10)),"start"!==this.options.position&&"middle"!==this.options.position&&"end"!==this.options.position&&(this.options.position="end"),this.options.wrap===i&&(this.options.wrap="letter"),this.$clipNode=e(e.parseHTML(this.options.showMore),this.$element),this.original&&this.update()},update:function(t){var e=!this.isCollapsed;"undefined"!=typeof t?this.original=this.element.innerHTML=t:this.isCollapsed&&this.element.innerHTML===this.cached&&(this.element.innerHTML=this.original);var i=this.$element.wrapInner("
").children();i.css({border:"none",margin:0,padding:0,width:"auto",height:"auto","word-wrap":"break-word"}),this.isTruncated=!1,i.height()>this.options.maxHeight?(this.isTruncated=g(i,i,this.$clipNode,this.options),this.isExplicitlyCollapsed&&(this.isCollapsed=!0,e=!1)):this.isCollapsed=!1,i.replaceWith(i.contents()),this.cached=this.element.innerHTML,e&&(this.element.innerHTML=this.original)},expand:function(){var t=!0;this.isExplicitlyCollapsed&&(this.isExplicitlyCollapsed=!1,t=!1),this.isCollapsed&&(this.isCollapsed=!1,this.element.innerHTML=this.isTruncated?this.original+(t?this.options.showLess:""):this.original)},collapse:function(t){this.isExplicitlyCollapsed=!0,this.isCollapsed||(this.isCollapsed=!0,t=t||!1,t?this.update():this.element.innerHTML=this.cached)}},e.fn.truncate=function(t){var i=e.makeArray(arguments).slice(1);return this.each(function(){var n=e.data(this,"jquery-truncate");n?"function"==typeof n[t]&&n[t].apply(n,i):e.data(this,"jquery-truncate",new f(this,t))})},t.Truncate=f}(this,jQuery); \ No newline at end of file