substring - Read More jQuery plugin failing with HTML -


I am using this code so that I only show the first 500 characters (and cut only after a full word) But it apparently fails when it gets some HTML code in the "500" threshold

In that case, it just adds "..." and then the text continues (And it also shows the "see more" link).

Example:

  Lorem & lt; Strong & gt; Impressum Dollar & lt; / Strong> Sit amet etcà © tera   

Suppose it should be cut between "empsum" and "dollar". The result is:

  Lorem & lt; Strong> Impsum ... & lt; Span class = "hidden" style = "display: none;" & Gt; Color and  & lt; / Strong> Sit amet etcà © tera & Lt; A href = "#" & gt; See more & lt; / A & gt;   

It should be:

  Lorem & lt; Strong> Impsum ... & lt; Span class = "hidden" style = "display: none;" & Gt; Weeds & lt; / Strong> Sit amet ATC Ettera & lt; / Span & gt; & Lt; A href = "#" & gt; See more & lt; / A & gt;   

or ... Lorem < Strong & gt; Impsum dolor & lt; / Strong> ... & lt; Span class = "hidden" style = "display: none;" ATACATA & lt; / Span & lt; A href = "#" & gt; See more & lt; / A & gt;

Anyway, I want to cut the text after that. Is there any way to fix this?

code:

  (function ($) {$ .fn.readmore = function (settings) {$ ('. Home_excerpt'). RemoveClass ('home_excerpt') ; Var opts = $ .extend ({}, $ .fn.readmore.defaults, settings); this.each (function () {$ (this) .data ("opts", opts); if ($ (this) .html () Length & gt; opts.substr_len) {Aparige ($); Linkage ($ (this));}}); Functions Link (AMM) {elem.append (elem.data ("opts "). $ (" .sext_seemore "). (Function () {$ (this) .hide (); $ (this) .siblings (" span: not (.hidden) "). Hide () sister ( "Span.hidden"). Show (); Return Back;});} Function Abridge (AMM) {var opts = elem.data ("opts"); var txt = elem.html (); var len = Opts Substr_len; var dots = "& lt; span & gt;" + opts.ellips Es + "& lt; / span & gt; var variables = txt.substr (lane, 1); while (lenan & lt; txt.length &! / \ S / .test (charAtLen)) {len + +; CharAtLen = txt.substr (len, 1)}} shown = txt.substring (0, len) + dots; var hidden = '& lt; span class = "hidden" style = "display: none ; "& Gt; '+ Txt.substring (lane, txt.length) +' & lt; / Span & gt; '; Elem.html (shown + hidden); } Return it; }; $ .fn.readmore.defaults = {substr_len: 500, ellipses: '& amp; # 8230; ', more_link:' & lt; Br / & gt; & Lt; A href = "#" class = "text_seemore" & gt; View & amp; Nbsp; ; More & lt; / A & gt; '}; }) (JQuery); I just found this jquery plugin that works perfect with HTML tags:    



Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -