Skip to content

Instantly share code, notes, and snippets.

@3rd-Eden
Created October 6, 2010 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3rd-Eden/613397 to your computer and use it in GitHub Desktop.
Save 3rd-Eden/613397 to your computer and use it in GitHub Desktop.
(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