1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-23 16:52:26 +02:00
TableFilter/src/modules/alternateRows.js

98 lines
2.7 KiB
JavaScript
Raw Normal View History

2014-11-15 15:34:32 +01:00
define(["exports", "../dom"], function (exports, _dom) {
"use strict";
2014-11-09 09:31:15 +01:00
2014-11-15 15:34:32 +01:00
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
2014-11-09 09:31:15 +01:00
2014-11-16 01:29:07 +01:00
var Dom = _dom.Dom;
2014-11-15 15:34:32 +01:00
var AlternateRows = (function () {
var AlternateRows = function AlternateRows(tf) {
var f = tf.fObj;
//defines css class for even rows
this.evenCss = f.even_row_css_class || "even";
//defines css class for odd rows
this.oddCss = f.odd_row_css_class || "odd";
2014-11-09 09:31:15 +01:00
2014-11-15 15:34:32 +01:00
this.tf = tf;
};
_classProps(AlternateRows, null, {
2014-11-16 01:29:07 +01:00
init: {
2014-11-15 15:34:32 +01:00
writable: true,
value: function () {
if (!this.tf.hasGrid && !this.tf.isFirstLoad) {
2014-11-09 09:31:15 +01:00
return;
2014-11-15 15:34:32 +01:00
}
var rows = this.tf.tbl.rows;
var noValidRowsIndex = this.tf.validRowsIndex === null;
//1st index
var beginIndex = noValidRowsIndex ? this.tf.refRow : 0;
// nb indexes
var indexLen = noValidRowsIndex ? this.tf.nbFilterableRows + beginIndex : this.tf.validRowsIndex.length;
var idx = 0;
2014-11-09 09:31:15 +01:00
2014-11-15 15:34:32 +01:00
//alternates bg color
for (var j = beginIndex; j < indexLen; j++) {
2014-11-09 09:31:15 +01:00
var rowIdx = noValidRowsIndex ? j : this.tf.validRowsIndex[j];
this.setRowBg(rowIdx, idx);
idx++;
2014-11-15 15:34:32 +01:00
}
2014-11-09 09:31:15 +01:00
}
2014-11-15 15:34:32 +01:00
},
setRowBg: {
writable: true,
value: function (rowIdx, idx) {
if (!this.tf.alternateBgs || isNaN(rowIdx)) {
2014-11-09 09:31:15 +01:00
return;
2014-11-15 15:34:32 +01:00
}
var rows = this.tf.tbl.rows;
var i = !idx ? rowIdx : idx;
this.removeRowBg(rowIdx);
2014-11-16 01:29:07 +01:00
Dom.addClass(rows[rowIdx], (i % 2) ? this.evenCss : this.oddCss);
2014-11-09 09:31:15 +01:00
}
2014-11-15 15:34:32 +01:00
},
removeRowBg: {
writable: true,
value: function (idx) {
if (isNaN(idx)) {
2014-11-09 09:31:15 +01:00
return;
2014-11-15 15:34:32 +01:00
}
var rows = this.tf.tbl.rows;
2014-11-16 01:29:07 +01:00
Dom.removeClass(rows[idx], this.oddCss);
Dom.removeClass(rows[idx], this.evenCss);
2014-11-09 09:31:15 +01:00
}
2014-11-15 15:34:32 +01:00
},
remove: {
writable: true,
value: function () {
if (!this.tf.hasGrid) {
2014-11-09 09:31:15 +01:00
return;
2014-11-15 15:34:32 +01:00
}
var row = this.tf.tbl.rows;
for (var i = this.tf.refRow; i < this.tf.nbRows; i++) {
2014-11-09 09:31:15 +01:00
this.removeRowBg(i);
2014-11-15 15:34:32 +01:00
}
this.tf.isStartBgAlternate = true;
2014-11-09 09:31:15 +01:00
}
2014-11-15 15:34:32 +01:00
},
enable: {
writable: true,
value: function () {
this.tf.alternateBgs = true;
}
},
disable: {
writable: true,
value: function () {
this.tf.alternateBgs = false;
}
}
});
2014-11-09 09:31:15 +01:00
return AlternateRows;
2014-11-15 15:34:32 +01:00
})();
exports.AlternateRows = AlternateRows;
});