//# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //
//# RESPONSIVETABLE
(function($) {
var defaults,
_responsiveTable = 'responsiveTable',
_container = 'Container',
_overflow = 'overflow',
_static = 'Static',
_overflowContainer = _overflow + _container,
_staticContainer = 'static' + _container,
_nthChild = 'nth-child',
_divClass = '
<< ' + options.scrollHintText + ' >>
');
$('.' + _overflowContainer).prepend(uiHint);
if ( table.find('caption').length != 0 ) {
captionHeight = table.find('caption').height();
}
uiHint
.css({
'position' : 'absolute',
'top' : '50%',
'left' : '50%',
'z-index' : 1000000,
'color' : '#eeeeee',
'font-size' : '11px',
'border-radius' : '6px 6px 6px 6px',
'padding' : '5px 10px 5px 10px',
'background-color' : '#888888'
})
.css({
'margin-top' : -((uiHint.height() / 2) - captionHeight),
'margin-left' : -(uiHint.width() / 2)
});
}
//consoleLog( table ); //: Test
setTimeout('$("#' + uid + '").hide();', options.scrollHintDuration);
}
function getResponsiveContainers(table) {
var oc = table.parent();
return {
rtc: oc.parent(),
oc: oc,
sc: oc.parent().find('.' + _staticContainer)
};
}
function resizeResponsiveTable(table, trim) {
responsiveContainers = getResponsiveContainers(table);
responsiveContainers.oc.width(responsiveContainers.rtc.innerWidth() - responsiveContainers.sc.outerWidth() - trim);
if ( options.scrollRight ) {
responsiveContainers.oc.scrollLeft(table.width());
}
}
function setResponsiveTable(table) {
if ( !table.parent().hasClass(_overflowContainer) ) {
var tos = table.offset();
table.wrap(_divClass + _responsiveTable + _container + '" style="' + _overflow + ':hidden;"/>');
tableStatic = $('');
$.each(table[0].attributes, function (index, a) {
if ( a.name !== 'id' ) {
tableStatic.attr(a.name, a.value);
}
});
tableStatic.addClass(_responsiveTable + _static)
.css('border-right', 'ridge')
.width(0);
$.each(rPaths, function (i, rp) {
table.find(rp).each(function (j, rs) {
rRows = $(rs).find('>tr');
if ( rRows.length > 0 ) {
rRoot = tableStatic;
if ( rp != '' ) {
rRoot = $('<' + rp + '/>');
}
$.each(rRows, function (k, r) {
tableStaticRow = $('
');
tableStaticRow.outerHeight($(r).outerHeight());
$.each(r.attributes, function (index, a) {
if ( a.name !== 'id' ) {
tableStaticRow.attr(a.name, a.value);
}
});
rowCells = $(r).find('>th:' + _nthChild + '(-n+' + options.staticColumns + '),>td:' + _nthChild + '(-n+' + options.staticColumns + ')');
rowCells.appendTo(tableStaticRow);
$(rRoot).append(tableStaticRow);
});
if ( rp != '' ) {
tableStatic.append(rRoot);
}
}
});
});
table.before(tableStatic);
table.wrap(_divClass + _overflowContainer + '" style="position:relative; float:left;' + _overflow + ':scroll;' + _overflow + '-y:hidden;" />');
tableStatic.wrap(_divClass + _staticContainer + '" style="float:left;"/>');
if ( options.scrollHintEnabled ) {
setupScrollHint(table, tos);
}
}
resizeResponsiveTable(table, 0);
responsiveContainers = getResponsiveContainers(table);
trim = 0;
while ( responsiveContainers.sc.position().top < responsiveContainers.oc.position().top && responsiveContainers.oc.width() > 0 ) {
trim++;
resizeResponsiveTable(table, trim);
}
}
function unsetResponsiveTable(table) {
if ( table.parent().hasClass(_overflowContainer) ) {
responsiveContainers = getResponsiveContainers(table);
tableStatic = responsiveContainers.sc.find('.' + _responsiveTable + _static);
$.each(rPaths, function (i, rp) {
tableStatic.find(rp).each(function (j, rs) {
rRows = $(rs).find('>tr');
if ( rRows.length > 0 ) {
rRoot = table;
if ( rp != '' ) {
rRoot = table.find(rp + ':eq' + '(' + j + ')');
}
$.each(rRows, function (k, r) {
var nc = k + 1;
rowCells = $(r).find('>th,>td');
rowCells.prependTo(rRoot.find('>tr:' + _nthChild + '(' + nc + ')'));
});
}
});
});
responsiveContainers.sc.remove();
table.unwrap().unwrap();
}
}
function setupResponsiveTable(table) {
tableWidth = table.width();
if ( table.parent().hasClass(_overflowContainer) ) {
tableWidth += $('.' + _staticContainer).width();
}
isResponsive = false;
table.parents().each(function () {
if ( !$(this).hasClass(_overflowContainer) && tableWidth > $(this).width() ) {
isResponsive = true;
return (false);
}
});
if ( isResponsive ) {
setResponsiveTable(table);
}
else {
unsetResponsiveTable(table);
}
}
return this.each(function () {
var $this = $(this);
if ( !$this.hasClass(_responsiveTable + _static) ) {
w.on('resize orientationchange', function () {
setupResponsiveTable($this);
});
setupResponsiveTable($this);
}
});
};
})(jQuery);