Index: trunk/extensions/Wikidata/OmegaWiki/HTMLtable.php |
— | — | @@ -4,12 +4,6 @@ |
5 | 5 | require_once("Record.php"); |
6 | 6 | require_once("RecordSet.php"); |
7 | 7 | |
8 | | -global |
9 | | - $wgStylePath; |
10 | | - |
11 | | -$URL = "$wgStylePath/common/images/sort_none.gif"; |
12 | | -define ('SORT_IMAGE', ' <img src="' . $URL . '"></img>'); |
13 | | - |
14 | 8 | function parityClass($value) { |
15 | 9 | if ($value % 2 == 0) |
16 | 10 | return "even"; |
— | — | @@ -75,23 +69,22 @@ |
76 | 70 | $columnIndex . '); </script>' |
77 | 71 | . EOL; |
78 | 72 | $leftmost = False; # There can be only one. |
79 | | - } else { |
| 73 | + } |
| 74 | + else |
80 | 75 | $leftsort=""; |
81 | | - } |
82 | 76 | |
83 | 77 | $class = ' class="' . $type . ' sortable"' . $onclick; |
84 | | - $sort_image = SORT_IMAGE; |
85 | | - } else { |
| 78 | + } |
| 79 | + else { |
86 | 80 | $class = ''; |
87 | 81 | $sort = ''; |
88 | | - $sort_image = ''; |
89 | 82 | $leftsort=''; |
90 | 83 | } |
91 | 84 | |
92 | 85 | $rowSpan = $height - $childNode->height; |
93 | 86 | $rows[$currentDepth] .= '<th id="'.$idPath->getId().'-h" '. $class . |
94 | 87 | ' colspan="'. $childNode->width . '" rowspan="'. $rowSpan . |
95 | | - '">'. $attribute->name . $sort_image . $leftsort .'</th>'; |
| 88 | + '">'. $attribute->name . $leftsort .'</th>'; |
96 | 89 | |
97 | 90 | addChildNodesToRows($childNode, $rows, $currentDepth + $rowSpan, $columnOffset,$idPath, $leftmost); |
98 | 91 | $idPath->popAttribute(); |
Index: trunk/extensions/Wikidata/OmegaWiki/suggest.js |
— | — | @@ -36,8 +36,6 @@ |
37 | 37 | return sString; |
38 | 38 | } |
39 | 39 | |
40 | | - |
41 | | - |
42 | 40 | function updateSuggestions(suggestPrefix) { |
43 | 41 | var http = getHTTPObject(); |
44 | 42 | var table = document.getElementById(suggestPrefix + "table"); |
— | — | @@ -592,6 +590,73 @@ |
593 | 591 | return result; |
594 | 592 | } |
595 | 593 | |
| 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 | + |
596 | 661 | function sortTable(columnNode, skipRows, columnIndex) { |
597 | 662 | var tableNode = getParentNode(columnNode, 'table'); |
598 | 663 | var rowsToSort = new Array(); |
— | — | @@ -613,6 +678,7 @@ |
614 | 679 | tableNode.tBodies[0].appendChild(rowsToSort[i]); |
615 | 680 | |
616 | 681 | tableNode.setAttribute('sort-order', sortOrder.toText()); |
| 682 | + changeSortIcons(tableNode, columnNode, sortOrder.getColumn(0).direction); |
617 | 683 | } |
618 | 684 | |
619 | 685 | function changePopupLinkArrow(popupLink, newArrow) { |
Index: trunk/extensions/Wikidata/OmegaWiki/tables.css |
— | — | @@ -27,8 +27,23 @@ |
28 | 28 | |
29 | 29 | .wiki-data-table th.sortable { |
30 | 30 | cursor: pointer; |
31 | | -} |
| 31 | +} |
32 | 32 | |
| 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 | + |
33 | 48 | .wiki-data-table td.column-odd { |
34 | 49 | background-color: #F6F6F6; |
35 | 50 | } |