差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
programming:javascript [2008/11/13 00:10] – nakayama | programming:javascript [2019/05/18 02:23] (現在) – 外部編集 非ログインユーザー | ||
---|---|---|---|
行 1: | 行 1: | ||
< | < | ||
<style type=" | <style type=" | ||
- | thead { background: #aaf no-repeat right center; } | + | |
+ | margin: 0.5em 0; | ||
+ | border: 1px solid black; border-collapse: | ||
+ | font-size: small; | ||
+ | font-family: | ||
+ | } | ||
+ | td, th { | ||
+ | padding: 0.2em 0.3em; | ||
+ | border: 1px solid silver; | ||
+ | } | ||
+ | th { | ||
+ | text-align: left; | ||
+ | padding-right: | ||
+ | cursor: default; | ||
+ | } | ||
+ | |||
+ | | ||
+ | | ||
+ | } | ||
+ | thead th.sort-desc { background-image: | ||
tr.alternate * { background-color: | tr.alternate * { background-color: | ||
</ | </ | ||
- | <script type=" | + | <script type=" |
<script type=" | <script type=" | ||
+ | Element.addMethods({ | ||
+ | collectTextNodes: | ||
+ | return $A($(element).childNodes).collect( function(node) { | ||
+ | return (node.nodeType==3 ? node.nodeValue : | ||
+ | (node.hasChildNodes() ? Element.collectTextNodes(node) : '' | ||
+ | }).flatten().join('' | ||
+ | } | ||
+ | }); | ||
+ | |||
var TableSorter = Class.create({ | var TableSorter = Class.create({ | ||
initialize: function(element) { | initialize: function(element) { | ||
行 13: | 行 41: | ||
this.initDOMReferences(); | this.initDOMReferences(); | ||
this.initEventHandlers(); | this.initEventHandlers(); | ||
- | }, // | + | }, // initialize |
- | + | ||
initDOMReferences: | initDOMReferences: | ||
var head = this.element.down(' | var head = this.element.down(' | ||
行 20: | 行 48: | ||
if (!head || !body) | if (!head || !body) | ||
throw ' | throw ' | ||
- | this.headers = head.down(' | + | this.headers = head.down(' |
- | this.headers.each(function(e, | + | this.headers.each(function(e, |
e._colIndex = i; | e._colIndex = i; | ||
}); | }); | ||
this.body = body; | this.body = body; | ||
}, // initDOMReferences | }, // initDOMReferences | ||
- | | + | |
initEventHandlers: | initEventHandlers: | ||
+ | this.handler = this.handleHeaderClick.bind(this); | ||
+ | this.element.observe(' | ||
}, // initEventHandlers | }, // initEventHandlers | ||
- | }; | + | |
+ | handleHeaderClick: | ||
+ | var element = e.element(); | ||
+ | if (!(' | ||
+ | element = element.ancestors().find(function(elt) { | ||
+ | return ' | ||
+ | | ||
+ | if (!((element) && ' | ||
+ | return; | ||
+ | } | ||
+ | this.sort(element._colIndex); | ||
+ | }, // handleHeaderClick | ||
+ | |||
+ | adjustSortMarkers: | ||
+ | if (this.sortIndex != -1) | ||
+ | this.headers[this.sortIndex].removeClassName(' | ||
+ | this.sortOrder); | ||
+ | if (this.sortIndex != index) { | ||
+ | this.sortOrder = ' | ||
+ | this.sortIndex = index; | ||
+ | } else | ||
+ | this.sortOrder = (' | ||
+ | this.headers[index].addClassName(' | ||
+ | }, // adjustSortMarkers | ||
+ | |||
+ | sort: function(index) { | ||
+ | this.adjustSortMarkers(index); | ||
+ | var rows = this.body.childElements(); | ||
+ | rows = rows.sortBy(function(row) { | ||
+ | return row.childElements()[this.sortIndex].collectTextNodes(); | ||
+ | }.bind(this)); | ||
+ | if (' | ||
+ | rows.reverse(); | ||
+ | rows.reverse().each(function(row, | ||
+ | if (index > 0) | ||
+ | this.body.insertBefore(row, | ||
+ | }.bind(this)); | ||
+ | rows.reverse().each(function(row, | ||
+ | row[(1 == index % 2 ? ' | ||
+ | }); | ||
+ | } // sort | ||
+ | }); // TableSorter | ||
+ | |||
+ | document.observe(' | ||
+ | $$(' | ||
+ | }); | ||
</ | </ | ||
- | <table id="table_sort" | + | <table id="netfw"> |
< | < | ||
<tr> | <tr> | ||
- | <td>.NET バージョン</ | + | <th>.NET バージョン</ |
- | <td> | + | <th> |
- | <td> | + | <th> |
+ | </tr> | ||
</ | </ | ||
< | < | ||
行 151: | 行 227: | ||
</ | </ | ||
</ | </ | ||
+ | <table id=" | ||
+ | < | ||
+ | <tr> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </tr> | ||
+ | </ | ||
+ | < | ||
+ | <tr> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </tr> | ||
+ | <tr class=" | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | |||
+ | </tr> | ||
+ | <tr> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </tr> | ||
+ | </ | ||
+ | </ | ||
</ | </ |