Created
January 22, 2015 08:33
-
-
Save rakuishi/89ead9c0d49858f436fb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/*! Table Expander jQuery Plugin | (c) 2014 rakuishi | MIT license */ | |
;(function($) { | |
$.fn.tableExpander = function(options) { | |
var defaults = { | |
'expandClassName' : 'expand', | |
'backgroundColor' : 'transparent', | |
'hoverBackgroundColor' : '#f0f0f0', | |
}; | |
var setting = $.extend(defaults, options); | |
var trArray = $('> tbody tr', this); | |
function onExpand(event) { | |
for (var i = event.data.num + 1; i < trArray.length; i++) { | |
if (trArray[i].className === setting['expandClassName']) { break; } | |
if ($(trArray[i]).is(':hidden')) { | |
$(trArray[i]).show(); | |
} else { | |
$(trArray[i]).hide(); | |
} | |
} | |
} | |
for (var i = 0; i < trArray.length; i++) { | |
if (trArray[i].className === setting['expandClassName']) { | |
$(trArray[i]) | |
.bind('click', {num: i}, onExpand) | |
.css('cursor', 'pointer') | |
.css('background-color', setting['backgroundColor']) | |
.mouseout(function() { $(this).css('background-color', setting['backgroundColor']); }) | |
.mouseover(function() { $(this).css('background-color', setting['hoverBackgroundColor']); }); | |
} else { | |
$(trArray[i]).hide(); | |
} | |
} | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment