Thread: [Phpcms-plugins-cvs] admin4phpCMS/tools .cvsignore,NONE,1.1 tablesort.js,NONE,1.1
Brought to you by:
mjahn
From: Martin J. <mj...@us...> - 2005-04-07 14:09:13
|
Update of /cvsroot/phpcms-plugins/admin4phpCMS/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15012/tools Added Files: .cvsignore tablesort.js Log Message: Commit as backup during development --- NEW FILE: .cvsignore --- PHP_Compat-1.3.1.tgz table.js --- NEW FILE: tablesort.js --- var tables = new Array (); var sortIndex = 0; var descending = true; var recDelimiter = '|'; var linkEventString = // What's insider <a> tag 'onclick=\'sortTable('; // Configurable constants var ascChr = "⇑"; // Symbol for ascending sort var desChr = "⇓"; // Symbol for descending sort var titleFace = 'em'; function tablesort (obj) { this.domok=document.all||document.getElementById; this.data = new Array (); this.rowContent = new Array (); this.sortMode = new Array (); this.sort = mySortTable; this.update = myUpdateTable; this.rowSort = new Array (); if (!this.domok) { return false; } // Initializing global table object variable if (obj.tagName && obj.tagName == "TABLE") { // Assumes that the obj is THE OBJECT this.table = obj; } else { // Assumes that the obj is the id of the object this.table = document.getElementById (obj); } // Check whether it's an object if (this.table == null) { return false; } // Check whether it's a table if (this.table.tagName != "TABLE") { return false; } // Setting the number of rows this.nRow = this.table.rows.length; // Should have at least 1 row if (this.nRow < 1) { return false; } // extract the content of the cells and put them into an array var j = 0; var i = 0; var temp = ''; for (i=0; i < this.table.tBodies [0].rows.length; i++) { temp = this.table.tBodies [0].rows [i].cells [0].innerHTML; for (j=1; j < this.table.tBodies [0].rows [i].cells.length; j++) { temp = temp + recDelimiter + this.table.tBodies [0].rows [i].cells [j].innerHTML; } this.rowContent [i] = temp; /* document.write (this.rowContent[i] + '<br />');*/ } // prepare the head-cells with onclick-handler // Re-drawing the title row var cellText = ''; var nChildNodes = 0; var innerMostNode = 0; for (j=0; j < this.table.tHead.rows [0].cells.length; j++) { // If for some reason, the rows do NOT have any child, then // simply return ... if (this.table.tHead.rows [0].childNodes.length == 0) { return false; } if (this.table.tHead.rows [0].cells [j].firstChild != null) { nChildNodes = this.table.tHead.rows [0].cells [j].firstChild.childNodes.length; innerMostNode = this.table.tHead.rows [0].cells [j].firstChild; while ( nChildNodes != 0) { innerMostNode = innerMostNode.firstChild; nChildNodes = innerMostNode.childNodes.length; } cellText = innerMostNode.data; } else { cellText = "column(" + j + ")"; } this.table.tHead.rows [0].cells [j].innerHTML = '<a ' + linkEventString + j + ',' + '"' + this.table.id + '"' + ');\'>' + '<' + titleFace + '>' + cellText + '</' + titleFace +'></a>'; } return true; } function mySortTable (column) { sortIndex = column; if (this.rowSort [column]) { this.rowSort [column] = -this.rowSort [column]; } else { this.rowSort [column] = 1; } descending = this.rowSort [column]; this.rowContent.sort (compare); this.update (); } function myUpdateTable () { var j = 0; var i = 0; var temp = ''; // Re-drawing the title row /* for (j=0; j<maxNCol; j++) { cellText = titleRowArray[j]; cellText = '<' + titleFace +'>' + cellText + '</' + titleFace + '></a>'; newTitle = '<a ' + linkEventString + j + ',' + '"' + table.id + '"' + ');\'>' + cellText + '</a>'; if (j == sortIndex) { newTitle += ' <span style="color:' + updownColor + ';">'; if (descending) newTitle += desChr; else newTitle += ascChr; newTitle += '</span>'; } titleRowCellArray[j].innerHTML = newTitle; } */ for (i = 0; i < this.table.tBodies [0].rows.length; i++) { temp = this.rowContent [i].split (recDelimiter); for (j = 0; j < this.table.tBodies [0].rows [i].cells.length; j++) { this.table.tBodies [0].rows [i].cells [j].innerHTML = temp [j]; } } } //***************************************************************************** // Function to be used for Array sorting //***************************************************************************** function compare(a, b) { // Getting the element array for inputs (a,b) var aRowContent = a.split(recDelimiter); var bRowContent = b.split(recDelimiter); // Needed in case the data conversion is necessary var aToBeCompared, bToBeCompared; if (! isNaN(aRowContent[sortIndex])) aToBeCompared = parseInt(aRowContent[sortIndex], 10); else aToBeCompared = aRowContent[sortIndex]; if (! isNaN(bRowContent[sortIndex])) bToBeCompared = parseInt(bRowContent[sortIndex], 10); else bToBeCompared = bRowContent[sortIndex]; if (aToBeCompared < bToBeCompared) { return descending; } if (aToBeCompared > bToBeCompared) { return -descending; } return 0; } function initTable (id) { if (tables [id]) { return false; } tables [id] = new tablesort (id); return true; } function sortTable (column, id) { // alert ('sort table ' + id + ' for column ' + column); if (!tables [id]) { return false; } tables [id].sort (column); return true; } |