git-svn-id: svn://euphorik.ch/pompage@45 02bbb61a-6d21-0410-aba0-cb053bdfd66a
[pompage.git] / doc / webdeveloper / generated / table_pivot.js
diff --git a/doc/webdeveloper/generated/table_pivot.js b/doc/webdeveloper/generated/table_pivot.js
new file mode 100644 (file)
index 0000000..23fa404
--- /dev/null
@@ -0,0 +1,79 @@
+// Makes all tables on the page with a cell with a pivot class pivotable
+function webdeveloper_makeTablesPivotable()
+{
+    var tableCellList   = webdeveloper_evaluateXPath(document, "//td[@class='pivot']");
+    var tableCellLength = tableCellList.length;
+
+    // Loop through the table cells
+    for(var i = 0; i < tableCellLength; i++)
+    {
+        tableCellList[i].addEventListener("click", webdeveloper_pivotTable, false);
+    }
+}
+
+// Pivots a table
+function webdeveloper_pivotTable(event)
+{
+    // If the event is set
+    if(event)
+    {
+        var hide      = true;
+        var pivotRow  = event.target.parentNode;
+        var tableCell = null;
+        var tableRow  = pivotRow;
+
+        // If the pivot row class attribute is set to collapsed
+        if(pivotRow.getAttribute("class") == "collapsed")
+        {
+            hide = false;
+
+            pivotRow.setAttribute("class", "expanded");
+        }
+        else
+        {
+            pivotRow.setAttribute("class", "collapsed");
+        }
+
+        // Loop through the table rows
+        while((tableRow = tableRow.nextSibling) != null)
+        {
+            tableCell = tableRow.firstChild;
+
+            // If the table cell is set and has a class attribute set to indent
+            if(tableCell && tableCell.hasAttribute("class") && tableCell.getAttribute("class") == "indent")
+            {
+                // If the table row has a class attribute that contains shaded
+                if(tableRow.hasAttribute("class") && tableRow.getAttribute("class").indexOf("shaded") != -1)
+                {
+                    // If hiding the row
+                    if(hide)
+                    {
+                        tableRow.setAttribute("class", "hidden shaded");
+                    }
+                    else
+                    {
+                        tableRow.setAttribute("class", "shaded");
+                    }
+                }
+                else
+                {
+                    // If hiding the row
+                    if(hide)
+                    {
+                        tableRow.setAttribute("class", "hidden");
+                    }
+                    else
+                    {
+                        tableRow.removeAttribute("class");
+                    }
+                }
+            }
+            else
+            {
+                break;
+            }
+        }
+    }
+}
+
+webdeveloper_makeTablesPivotable();