summaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2015-06-01 09:26:47 +0200
committerLars-Dominik Braun <lars@6xq.net>2015-06-01 09:26:47 +0200
commit1c901fdb624847d569a448f517d1bcf1b4b67e79 (patch)
tree41becedf583409b8d257150b56abfccd0239132c /data
parent4b67b0bcdc719e30265f57efd3e3b2b9bd83ed23 (diff)
downloadcomatose-1c901fdb624847d569a448f517d1bcf1b4b67e79.tar.gz
comatose-1c901fdb624847d569a448f517d1bcf1b4b67e79.tar.bz2
comatose-1c901fdb624847d569a448f517d1bcf1b4b67e79.zip
js: Extract data from HTML DOM
Diffstat (limited to 'data')
-rw-r--r--data/script.js30
1 files changed, 25 insertions, 5 deletions
diff --git a/data/script.js b/data/script.js
index 84cb562..43f2d05 100644
--- a/data/script.js
+++ b/data/script.js
@@ -9,15 +9,35 @@
(function(b,c){var $=b.jQuery||b.Cowboy||(b.Cowboy={}),a;$.throttle=a=function(e,f,j,i){var h,d=0;if(typeof f!=="boolean"){i=j;j=f;f=c}function g(){var o=this,m=+new Date()-d,n=arguments;function l(){d=+new Date();j.apply(o,n)}function k(){h=c}if(i&&!h){l()}h&&clearTimeout(h);if(i===c&&m>e){l()}else{if(f!==true){h=setTimeout(i?k:l,i===c?e-m:e)}}}if($.guid){g.guid=j.guid=j.guid||$.guid++}return g};$.debounce=function(d,e,f){return f===c?a(d,e,false):a(d,f,e!==false)}})(this);
$(document).ready (function () {
+ var protocache = {};
+
+ function extract (n) {
+ var e = protocache[n.attr ('id')];
+ if (e) {
+ return e;
+ }
+ e = {
+ 'name': n.children ('.name').first ().text (),
+ 'rank': parseFloat (n.data ('rank')),
+ }
+ var year = n.find ('dl dd.ref * .year').first ();
+ if (year.length == 1) {
+ e['year'] = parseInt (year.text ());
+ } else {
+ e['year'] = 0;
+ }
+
+ protocache[n.attr ('id')] = e;
+ return e;
+ }
+
function sortproto (by) {
var protolist = $('#protocols');
var items = protolist.children ('.protocol');
items.detach ().sort (function (nodeA, nodeB) {
- var a = $(nodeA).data (by);
- var b = $(nodeB).data (by);
+ var a = extract ($(nodeA))[by];
+ var b = extract ($(nodeB))[by];
if (by == 'rank' || by == 'year') {
- a = parseFloat (a);
- b = parseFloat (b);
return a > b ? 1 : (a < b ? -1 : 0);
} else {
return a.localeCompare (b);
@@ -30,7 +50,7 @@ $(document).ready (function () {
var items = $('#protocols .protocol');
for (var i = 0; i < items.length; i++) {
var e = $(items[i]);
- var val = e.data ('name') + ' ' + e.data ('longname') + ' ' + e.data ('author');
+ var val = extract (e)['name'];
if (val.toLowerCase ().indexOf (search) >= 0) {
e.show ();
} else {