Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(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