Note that there are some explanatory texts on larger screens.

plurals
  1. PO3 Questions Jquery readmore plugin confused me
    primarykey
    data
    text
    <p>i see in other example jquery code like below, Why he make variable like this</p> <p><strong>var moreLink = $('.truncate_more_link', obj);</strong><br> why not <strong>var moreLink = $('.truncate_more_link');</strong> </p> <p>and i got confuse what a minTrail do in defaults object?? </p> <p>and onother confused in this example below what he means, Why body.length - 1 do??</p> <p><strong>var str2 = body.substring(splitLocation, body.length - 1);</strong> </p> <p>las thing when we want to use indexof in proper condition...??</p> <h2>full example of code:</h2> <pre><code>(function($){ $.fn.truncate = function(options) { var defaults = { length: 300, **minTrail: 20,** moreText: "more", lessText: "less", ellipsisText: "..." }; var options = $.extend(defaults, options); return this.each(function() { obj = $(this); var body = obj.html(); if(body.length &gt; options.length + **options.minTrail**) { var splitLocation = body.indexOf(' ', options.length); if(splitLocation != -1) { // truncate tip var splitLocation = body.indexOf(' ', options.length); var str1 = body.substring(0, splitLocation); **var str2 = body.substring(splitLocation, body.length - 1);** obj.html(str1 + '&lt;span class="truncate_ellipsis"&gt;' + options.ellipsisText + '&lt;/span&gt;' + '&lt;span class="truncate_more"&gt;' + str2 + '&lt;/span&gt;'); obj.find('.truncate_more').css("display", "none"); // insert more link obj.append( '&lt;div class="clearboth"&gt;' + '&lt;a href="#" class="truncate_more_link"&gt;' + options.moreText + '&lt;/a&gt;' + '&lt;/div&gt;' ); // set onclick event for more/less link **var moreLink = $('.truncate_more_link', obj);** **var moreContent = $('.truncate_more', obj);** **var ellipsis = $('.truncate_ellipsis', obj);** moreLink.click(function() { if(moreLink.text() == options.moreText) { moreContent.show('normal'); moreLink.text(options.lessText); ellipsis.css("display", "none"); } else { moreContent.hide('normal'); moreLink.text(options.moreText); ellipsis.css("display", "inline"); } return false; }); } } // end if }); }; })(jQuery); </code></pre> <p><em><strong>Thank's Hopefully Your answer!!</em></strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload