Created
October 6, 2010 14:09
-
-
Save 3rd-Eden/613397 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
$.fn.autoShortener = function(options){ | |
// merge the options with the default settings before looping over each node that is | |
// found by the css selector engine | |
var settings = { | |
"length":10, | |
"message":"Show More" | |
}; | |
if(options) $.extend(settings, options); | |
return this.each( | |
function() { | |
//get the children | |
var item = $(this); | |
var kids = item.children(); | |
if(kids.length > settings.length) { | |
kids.slice(settings.length).hide(); | |
$(this).append("<a href='#' class='showMoreLink'>" + settings.message + "</a>"); | |
$(".showMoreLink", item).click(function(e) { | |
item.children().show(); | |
$(this).hide(); | |
e.preventDefault(); | |
}); | |
} | |
} | |
); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment