};
/*
- * Remove a class name from the class attribute
+ * Remove a class name from the class attribute of an element
+ *
+ * @param object el: the element
+ * @param string className: the class name to remove
+ * @param boolean substring: if true, remove the first class name starting with the given string
+ * @return void
*/
-HTMLArea._removeClass = function(el, removeClassName) {
- if(!(el && el.className)) return;
- var cls = el.className.trim().split(" ");
- var ar = new Array();
- for (var i = cls.length; i > 0;) {
- if (cls[--i] != removeClassName) ar[ar.length] = cls[i];
+HTMLArea._removeClass = function(el, className, substring) {
+ if (!el || !el.className) return;
+ var classes = el.className.trim().split(" ");
+ var newClasses = new Array();
+ for (var i = classes.length; --i >= 0;) {
+ if (!substring) {
+ if (classes[i] != className) {
+ newClasses[newClasses.length] = classes[i];
+ }
+ } else if (classes[i].indexOf(className) != 0) {
+ newClasses[newClasses.length] = classes[i];
+ }
}
- if (ar.length == 0) {
+ if (newClasses.length == 0) {
if (!HTMLArea.is_opera) el.removeAttribute(HTMLArea.is_gecko ? "class" : "className");
else el.className = '';
-
- } else el.className = ar.join(" ");
+ } else {
+ el.className = newClasses.join(" ");
+ }
};
/*
};
/*
- * Check if a class name is in the class attribute
+ * Check if a class name is in the class attribute of an element
+ *
+ * @param object el: the element
+ * @param string className: the class name to look for
+ * @param boolean substring: if true, look for a class name starting with the given string
+ * @return boolean true if the class name was found
*/
-HTMLArea._hasClass = function(el, className) {
+HTMLArea._hasClass = function(el, className, substring) {
if (!el || !el.className) return false;
- var cls = el.className.split(" ");
- for (var i = cls.length; i > 0;) {
- if(cls[--i] == className) return true;
+ var classes = el.className.trim().split(" ");
+ for (var i = classes.length; --i >= 0;) {
+ if (classes[i] == className || (substring && classes[i].indexOf(className) == 0)) return true;
}
return false;
};
},
/*
- * Applies to rows/cells the alternating classes of an alternating style scheme
+ * Applies to rows/cells the alternating and counting classes of an alternating or counting style scheme
*
* @param object table: the table to be re-styled
*
*/
reStyleTable : function (table) {
if (table) {
- if (this.classesUrl && typeof(HTMLArea.classesAlternating) === "undefined") {
+ if (this.classesUrl && (typeof(HTMLArea.classesAlternating) === "undefined" || typeof(HTMLArea.classesCounting) === "undefined")) {
this.getJavascriptFile(this.classesUrl);
}
var classNames = table.className.trim().split(" ");
this.alternateColumns(table, classConfiguration);
}
}
+ classConfiguration = HTMLArea.classesCounting[classNames[i]];
+ if (classConfiguration && classConfiguration.rows) {
+ if (classConfiguration.rows.rowClass) {
+ this.countRows(table, classConfiguration);
+ }
+ }
+ if (classConfiguration && classConfiguration.columns) {
+ if (classConfiguration.columns.columnClass) {
+ this.countColumns(table, classConfiguration);
+ }
+ }
}
}
},
}
},
+ /*
+ * Removes from rows/cells the counting classes of an counting style scheme
+ *
+ * @param object table: the table to be re-styled
+ * @param string removeClass: the name of the class that identifies the counting style scheme
+ *
+ * @return void
+ */
+ removeCountingClasses : function (table, removeClass) {
+ if (table) {
+ if (this.classesUrl && typeof(HTMLArea.classesCounting) === "undefined") {
+ this.getJavascriptFile(this.classesUrl);
+ }
+ var classConfiguration = HTMLArea.classesCounting[removeClass];
+ if (classConfiguration) {
+ if (classConfiguration.rows && classConfiguration.rows.rowClass) {
+ this.countRows(table, classConfiguration, true);
+ }
+ if (classConfiguration.columns && classConfiguration.columns.columnClass) {
+ this.countColumns(table, classConfiguration, true);
+ }
+ }
+ }
+ },
+
+ /*
+ * Applies/removes the counting classes of an counting rows style scheme
+ *
+ * @param object table: the table to be re-styled
+ * @param object classConfifuration: the counting sub-array of the configuration of the class
+ * @param boolean remove: if true, the classes are removed
+ *
+ * @return void
+ */
+ countRows : function (table, classConfiguration, remove) {
+ var rowClass = { tbody : classConfiguration.rows.rowClass, thead : classConfiguration.rows.rowHeaderClass };
+ var rowLastClass = { tbody : classConfiguration.rows.rowLastClass, thead : classConfiguration.rows.rowHeaderLastClass };
+ var startAt = parseInt(classConfiguration.rows.startAt);
+ startAt = remove ? 1 : (startAt ? startAt : 1);
+ var rows = table.rows, type, baseClassName, rowClassName, lastRowClassName;
+ // Loop through the rows
+ for (var i = startAt-1, n = rows.length; i < n; i++) {
+ var row = rows[i];
+ type = (row.parentNode.nodeName.toLowerCase() == "thead") ? "thead" : "tbody";
+ baseClassName = rowClass[type];
+ rowClassName = baseClassName + (i+1);
+ lastRowClassName = rowLastClass[type];
+ if (remove) {
+ if (baseClassName) {
+ HTMLArea._removeClass(row, rowClassName);
+ }
+ if (lastRowClassName && i == n-1) {
+ HTMLArea._removeClass(row, lastRowClassName);
+ }
+ } else {
+ if (baseClassName) {
+ if (HTMLArea._hasClass(row, baseClassName, true)) {
+ HTMLArea._removeClass(row, baseClassName, true);
+ }
+ HTMLArea._addClass(row, rowClassName);
+ }
+ if (lastRowClassName) {
+ if (i == n-1) {
+ HTMLArea._addClass(row, lastRowClassName);
+ } else if (HTMLArea._hasClass(row, lastRowClassName)) {
+ HTMLArea._removeClass(row, lastRowClassName);
+ }
+ }
+ }
+ }
+ },
+
+ /*
+ * Applies/removes the counting classes of a counting columns style scheme
+ *
+ * @param object table: the table to be re-styled
+ * @param object classConfifuration: the counting sub-array of the configuration of the class
+ * @param boolean remove: if true, the classes are removed
+ *
+ * @return void
+ */
+ countColumns : function (table, classConfiguration, remove) {
+ var columnClass = { td : classConfiguration.columns.columnClass, th : classConfiguration.columns.columnHeaderClass };
+ var columnLastClass = { td : classConfiguration.columns.columnLastClass, th : classConfiguration.columns.columnHeaderLastClass };
+ var startAt = parseInt(classConfiguration.columns.startAt);
+ startAt = remove ? 1 : (startAt ? startAt : 1);
+ var rows = table.rows, type, baseClassName, columnClassName, lastColumnClassName;
+ // Loop through the rows of the table
+ for (var i = rows.length; --i >= 0;) {
+ // Loop through the cells
+ var cells = rows[i].cells;
+ for (var j = startAt-1, n = cells.length; j < n; j++) {
+ var cell = cells[j];
+ type = cell.nodeName.toLowerCase();
+ baseClassName = columnClass[type];
+ columnClassName = baseClassName + (j+1);
+ lastColumnClassName = columnLastClass[type];
+ if (remove) {
+ if (baseClassName) {
+ HTMLArea._removeClass(cell, columnClassName);
+ }
+ if (lastColumnClassName && j == n-1) {
+ HTMLArea._removeClass(cell, lastColumnClassName);
+ }
+ } else {
+ if (baseClassName) {
+ if (HTMLArea._hasClass(cell, baseClassName, true)) {
+ HTMLArea._removeClass(cell, baseClassName, true);
+ }
+ HTMLArea._addClass(cell, columnClassName);
+ }
+ if (lastColumnClassName) {
+ if (j == n-1) {
+ HTMLArea._addClass(cell, lastColumnClassName);
+ } else if (HTMLArea._hasClass(cell, lastColumnClassName)) {
+ HTMLArea._removeClass(cell, lastColumnClassName);
+ }
+ }
+ }
+ }
+ }
+ },
+
/*
* This function sets the headers cells on the table (top, left, both or none)
*