Skip to content

Instantly share code, notes, and snippets.

@ArnaudD
Created November 25, 2009 15:12
Show Gist options
  • Save ArnaudD/242771 to your computer and use it in GitHub Desktop.
Save ArnaudD/242771 to your computer and use it in GitHub Desktop.
;(function($) {
$.fn.resizable = function () {
var mouseStartY = null;
var startHeight = null;
var resizableObject = $(this);
var columnsCount = $('tr:eq(0) th, tr:eq(0) td', resizableObject).length;
resizableObject.append ('<tfoot><tr><td colspan="'+columnsCount+'" class="resize_bar"></tr></tfoot>');
resizableObject.find ('.resize_bar').mousedown (function (event) {
if(event.preventDefault) // Prevent FF default d'n'drop
event.preventDefault();
mouseStartY = event.pageY;
startHeight = _getViewport ().height ();
$(document).mousemove (_drag).one ('mouseup', null, _drop);
});
function _drag (event) {
var deltaY = event.pageY - mouseStartY;
_getViewport ().height (startHeight + deltaY)
}
function _drop (event) {
$(document).unbind ('mousemove', _drag);
}
function _getViewport () {
return $('tbody', resizableObject);
}
return resizableObject;
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment