r23942 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23941‎ | r23942 | r23943 >
Date:08:58, 10 July 2007
Author:proes
Status:old
Tags:
Comment:
Show sort order for sorted tables
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/HTMLtable.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/suggest.js (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/tables.css (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/HTMLtable.php
@@ -4,12 +4,6 @@
55 require_once("Record.php");
66 require_once("RecordSet.php");
77
8 -global
9 - $wgStylePath;
10 -
11 -$URL = "$wgStylePath/common/images/sort_none.gif";
12 -define ('SORT_IMAGE', ' <img src="' . $URL . '"></img>');
13 -
148 function parityClass($value) {
159 if ($value % 2 == 0)
1610 return "even";
@@ -75,23 +69,22 @@
7670 $columnIndex . '); </script>'
7771 . EOL;
7872 $leftmost = False; # There can be only one.
79 - } else {
 73+ }
 74+ else
8075 $leftsort="";
81 - }
8276
8377 $class = ' class="' . $type . ' sortable"' . $onclick;
84 - $sort_image = SORT_IMAGE;
85 - } else {
 78+ }
 79+ else {
8680 $class = '';
8781 $sort = '';
88 - $sort_image = '';
8982 $leftsort='';
9083 }
9184
9285 $rowSpan = $height - $childNode->height;
9386 $rows[$currentDepth] .= '<th id="'.$idPath->getId().'-h" '. $class .
9487 ' colspan="'. $childNode->width . '" rowspan="'. $rowSpan .
95 - '">'. $attribute->name . $sort_image . $leftsort .'</th>';
 88+ '">'. $attribute->name . $leftsort .'</th>';
9689
9790 addChildNodesToRows($childNode, $rows, $currentDepth + $rowSpan, $columnOffset,$idPath, $leftmost);
9891 $idPath->popAttribute();
Index: trunk/extensions/Wikidata/OmegaWiki/suggest.js
@@ -36,8 +36,6 @@
3737 return sString;
3838 }
3939
40 -
41 -
4240 function updateSuggestions(suggestPrefix) {
4341 var http = getHTTPObject();
4442 var table = document.getElementById(suggestPrefix + "table");
@@ -592,6 +590,73 @@
593591 return result;
594592 }
595593
 594+function getAllColumnHeaders(tableNode) {
 595+ var headerRowCount = 0;
 596+
 597+ while (headerRowCount < tableNode.rows.length && tableNode.rows[headerRowCount].cells[0].nodeName.toLowerCase() == "th")
 598+ headerRowCount++;
 599+
 600+ var result = new Array();
 601+
 602+ for (i = 0; i < headerRowCount; i++) {
 603+ var headerRow = tableNode.rows[i];
 604+
 605+ for (j = 0; j < headerRow.cells.length; j++)
 606+ result.push(headerRow.cells[j]);
 607+ }
 608+
 609+ return result;
 610+}
 611+
 612+function nodeHasClass(node, class) {
 613+ var classes = node.className.split(' ');
 614+ var result = false;
 615+ var i = 0;
 616+
 617+ while (!result && i < classes.length)
 618+ if (classes[i] == class)
 619+ result = true;
 620+ else
 621+ i++;
 622+
 623+ return result;
 624+}
 625+
 626+function removeNodeClass(node, class) {
 627+ var classes = node.className.split(' ');
 628+ var newClasses = new Array();
 629+
 630+ for (var i = 0; i < classes.length; i++)
 631+ if (classes[i] != class)
 632+ newClasses.push(classes[i]);
 633+
 634+ node.className = newClasses.join(" ");
 635+}
 636+
 637+function columnIsSortable(sortedColumnNode) {
 638+ return nodeHasClass(sortedColumnNode, "sortable");
 639+}
 640+
 641+function changeSortIcons(tableNode, sortedColumnNode, sortDirection) {
 642+ var columnHeaders = getAllColumnHeaders(tableNode);
 643+
 644+ for (var i = 0; i < columnHeaders.length; i++) {
 645+ var columnHeader = columnHeaders[i];
 646+
 647+ if (columnIsSortable(columnHeader)) {
 648+ removeNodeClass(columnHeader, "sortedUp");
 649+ removeNodeClass(columnHeader, "sortedDown");
 650+
 651+ if (columnHeader == sortedColumnNode) {
 652+ if (sortDirection == -1)
 653+ columnHeader.className += " sortedUp";
 654+ else
 655+ columnHeader.className += " sortedDown";
 656+ }
 657+ }
 658+ }
 659+}
 660+
596661 function sortTable(columnNode, skipRows, columnIndex) {
597662 var tableNode = getParentNode(columnNode, 'table');
598663 var rowsToSort = new Array();
@@ -613,6 +678,7 @@
614679 tableNode.tBodies[0].appendChild(rowsToSort[i]);
615680
616681 tableNode.setAttribute('sort-order', sortOrder.toText());
 682+ changeSortIcons(tableNode, columnNode, sortOrder.getColumn(0).direction);
617683 }
618684
619685 function changePopupLinkArrow(popupLink, newArrow) {
Index: trunk/extensions/Wikidata/OmegaWiki/tables.css
@@ -27,8 +27,23 @@
2828
2929 .wiki-data-table th.sortable {
3030 cursor: pointer;
31 -}
 31+}
3232
 33+.wiki-data-table th.sortedUp {
 34+ padding-right: 15px;
 35+ background-image: url('../../../skins/common/images/sort_up.gif');
 36+ background-repeat: no-repeat;
 37+ background-position: bottom right;
 38+}
 39+
 40+.wiki-data-table th.sortedDown {
 41+ padding-right: 15px;
 42+
 43+ background-image: url('../../../skins/common/images/sort_down.gif');
 44+ background-repeat: no-repeat;
 45+ background-position: bottom right;
 46+}
 47+
3348 .wiki-data-table td.column-odd {
3449 background-color: #F6F6F6;
3550 }

Status & tagging log