Merge branch 'colresize' into aris

This commit is contained in:
Aris Feryanto 2011-05-27 19:09:38 +07:00
commit 36680cff27
5 changed files with 185 additions and 0 deletions

145
js/makegrid.js Normal file
View File

@ -0,0 +1,145 @@
(function ($) {
$.grid = function(t) {
// prepare the grid
var g = {
// constant
minColWidth: 5,
// functions
dragStartRsz: function(e, obj) {
var n = $('div', this.cRsz).index(obj);
this.colRsz = {
x0: e.screenX,
n: n,
obj: obj,
objLeft: parseInt(obj.style.left),
objWidth: $('th div:eq(' + (1 + n) + ')', this.t).width()
};
$('body').css('cursor', 'col-resize');
$('body').noSelect();
},
dragMove: function(e) {
if (this.colRsz) {
var dx = e.screenX - this.colRsz.x0;
if (this.colRsz.objWidth + dx > this.minColWidth)
$(this.colRsz.obj).css('left', this.colRsz.objLeft + dx);
}
},
dragEnd: function(e) {
if (this.colRsz) {
var dx = e.screenX - this.colRsz.x0;
var nw = this.colRsz.objWidth + dx;
if (nw < this.minColWidth) {
nw = this.minColWidth;
}
var n = this.colRsz.n;
$('tr', this.t).each(function() {
$('th:eq(' + (1 + n) + ') div, td:eq(' + (5 + n) + ') div', this).each(function() {
$(this).css('width', nw + 'px');
});
});
$('body').css('cursor', 'default');
this.reposRsz();
this.colRsz = false;
}
},
reposRsz: function() {
$(this.t).find('thead tr:first th:gt(0)').each(function() {
$this = $(this);
var n = $this.index();
$cb = $('div:eq(' + (n - 1) + ')', g.cRsz); // column border
$cb.css('left', $this.position().left + $this.width());
});
}
}
g.gDiv = document.createElement('div'); // create global div
g.cRsz = document.createElement('div'); // column resizer
g.t = t;
// create column borders
$(t).find('thead tr:first th:gt(0)').each(function() {
$this = $(this);
var cb = document.createElement('div'); // column border
cb.style.left = $this.position().left + $this.width() + 'px';
cb.style.height = '100%';
cb.className = 'colborder';
$(cb).mousedown(function(e) {
g.dragStartRsz(e, this);
});
$(g.cRsz).append(cb);
});
// wrap all cells with div
$(t).find('th, td').each(function() {
$(this).wrapInner('<div />');
});
// register events
$(document).mousemove(function(e) {
g.dragMove(e);
});
$(document).mouseup(function(e) {
g.dragEnd(e);
});
// add table class
$(t).addClass('pma_table');
// link all divs
$(t).before(g.gDiv);
$(g.gDiv).append(t);
$(g.gDiv).prepend(g.cRsz);
// some adjustment
g.cRsz.className = 'cRsz';
$(g.cRsz).css('height', $(t).height());
$(t).removeClass('data');
$(g.gDiv).addClass('data');
};
// document ready checking
var docready = false;
$(document).ready(function() {
docready = true;
});
// Additional jQuery functions
$.fn.makegrid = function() {
return this.each(function() {
if (!docready) {
var t = this;
$(document).ready(function() {
$.grid(t);
});
} else {
$.grid(this);
}
});
};
$.fn.noSelect = function (p) { //no select plugin by Paulo P.Marinas
var prevent = (p == null) ? true : p;
if (prevent) {
return this.each(function () {
if ($.browser.msie || $.browser.safari) $(this).bind('selectstart', function () {
return false;
});
else if ($.browser.mozilla) {
$(this).css('MozUserSelect', 'none');
$('body').trigger('focus');
} else if ($.browser.opera) $(this).bind('mousedown', function () {
return false;
});
else $(this).attr('unselectable', 'on');
});
} else {
return this.each(function () {
if ($.browser.msie || $.browser.safari) $(this).unbind('selectstart');
else if ($.browser.mozilla) $(this).css('MozUserSelect', 'inherit');
else if ($.browser.opera) $(this).unbind('mousedown');
else $(this).removeAttr('unselectable', 'on');
});
}
}; //end noSelect
})(jQuery);

View File

@ -1142,6 +1142,11 @@ $(document).ready(function() {
$('.column_heading').live('click', function() {
PMA_changeClassForColumn($(this), 'marked');
});
/**
* create resizable table
*/
$('#table_results').makegrid();
})
/**#@- */

View File

@ -840,6 +840,7 @@ else {
$GLOBALS['js_include'][] = 'functions.js';
$GLOBALS['js_include'][] = 'sql.js';
$GLOBALS['js_include'][] = 'makegrid.js';
unset($message);

View File

@ -1771,3 +1771,21 @@ fieldset .disabled-field td {
-webkit-box-sizing: border-box;
}
.colborder {
border-right: solid 1px #FFFFFF;
cursor: col-resize;
margin-left: 5px;
position: absolute;
width: 3px;
}
.pma_table thead th div, .pma_table tbody td div {
display: block;
overflow: hidden;
}
.cRsz {
position: absolute;
}

View File

@ -2126,3 +2126,19 @@ fieldset .disabled-field td {
margin: 0 6px;
}
.colborder {
border-right: solid 1px #FFFFFF;
cursor: col-resize;
margin-left: -1px;
position: absolute;
width: 3px;
}
.pma_table thead th div, .pma_table tbody td div {
display: block;
overflow: hidden;
}
.cRsz {
position: absolute;
}