From 1c901fdb624847d569a448f517d1bcf1b4b67e79 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Mon, 1 Jun 2015 09:26:47 +0200 Subject: js: Extract data from HTML DOM --- data/script.js | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'data') 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 { -- cgit v1.2.3