Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function($) {
- $.fn.truncate = function(options) {
- options = $.extend({ limit: 50, more: '...', words: true }, options);
- return this.each(function() {
- var el = $(this), original = el.html(), truncated;
- if (options.words) {
- truncated = el.text().substr(0, options.limit + 1);
- var pos = truncated.lastIndexOf(' ');
- if (pos === -1) {
- pos = options.limit;
- }
- truncated = truncated.substr(0, pos);
- } else {
- truncated = el.text().substr(0, options.limit);
- }
- var link = $('<a href="#" class="more"></a>').html(options.more).click(function() {
- $(this).parent().html(original);
- return false;
- });
- el.html(truncated).append(link);
- });
- };
- })(jQuery);
Add Comment
Please, Sign In to add comment