squidanalyzer/resources/sorttable.js

14 lines
8.3 KiB
JavaScript
Raw Normal View History

var stIsIE=
/*@cc_on!@*/
false;sorttable={init:function(){if(arguments.callee.done){return}arguments.callee.done=true;if(_timer){clearInterval(_timer)}if(!document.createElement||!document.getElementsByTagName){return}sorttable.DATE_RE=/^(\d\d?)[\/\.-](\d\d?)[\/\.-]((\d\d)?\d\d)$/;forEach(document.getElementsByTagName("table"),function(a){if(a.className.search(/\bsortable\b/)!=-1){sorttable.makeSortable(a)}})},makeSortable:function(b){if(b.getElementsByTagName("thead").length==0){the=document.createElement("thead");the.appendChild(b.rows[0]);b.insertBefore(the,b.firstChild)}if(b.tHead==null){b.tHead=b.getElementsByTagName("thead")[0]}if(b.tHead.rows.length!=1){return}sortbottomrows=[];for(var a=0;a<b.rows.length;a++){if(b.rows[a].className.search(/\bsortbottom\b/)!=-1){sortbottomrows[sortbottomrows.length]=b.rows[a]}}if(sortbottomrows){if(b.tFoot==null){tfo=document.createElement("tfoot");b.appendChild(tfo)}for(var a=0;a<sortbottomrows.length;a++){tfo.appendChild(sortbottomrows[a])}delete sortbottomrows}headrow=b.tHead.rows[0].cells;for(var a=0;a<headrow.length;a++){if(!headrow[a].className.match(/\bsorttable_nosort\b/)){mtch=headrow[a].className.match(/\bsorttable_([a-z0-9]+)\b/);if(mtch){override=mtch[1]}if(mtch&&typeof sorttable["sort_"+override]=="function"){headrow[a].sorttable_sortfunction=sorttable["sort_"+override]}else{headrow[a].sorttable_sortfunction=sorttable.guessType(b,a)}headrow[a].sorttable_columnindex=a;headrow[a].sorttable_tbody=b.tBodies[0];dean_addEvent(headrow[a],"click",sorttable.innerSortFunction=function(f){if(this.className.search(/\bsorttable_sorted\b/)!=-1){sorttable.reverse(this.sorttable_tbody);this.className=this.className.replace("sorttable_sorted","sorttable_sorted_reverse");this.removeChild(document.getElementById("sorttable_sortfwdind"));sortrevind=document.createElement("span");sortrevind.id="sorttable_sortrevind";sortrevind.innerHTML=stIsIE?'&nbsp<font face="webdings">5</font>':"&nbsp;&#x25B4;";this.appendChild(sortrevind);return}if(this.className.search(/\bsorttable_sorted_reverse\b/)!=-1){sorttable.reverse(this.sorttable_tbody);this.className=this.className.replace("sorttable_sorted_reverse","sorttable_sorted");this.removeChild(document.getElementById("sorttable_sortrevind"));sortfwdind=document.createElement("span");sortfwdind.id="sorttable_sortfwdind";sortfwdind.innerHTML=stIsIE?'&nbsp<font face="webdings">6</font>':"&nbsp;&#x25BE;";this.appendChild(sortfwdind);return}theadrow=this.parentNode;forEach(theadrow.childNodes,function(e){if(e.nodeType==1){e.className=e.className.replace("sorttable_sorted_reverse","");e.className=e.className.replace("sorttable_sorted","")}});sortfwdind=document.getElementById("sorttable_sortfwdind");if(sortfwdind){sortfwdind.parentNode.removeChild(sortfwdind)}sortrevind=document.getElementById("sorttable_sortrevind");if(sortrevind){sortrevind.parentNode.removeChild(sortrevind)}this.className+=" sorttable_sorted";sortfwdind=document.createElement("span");sortfwdind.id="sorttable_sortfwdind";sortfwdind.innerHTML=stIsIE?'&nbsp<font face="webdings">6</font>':"&nbsp;&#x25BE;";this.appendChild(sortfwdind);row_array=[];col=this.sorttable_columnindex;rows=this.sorttable_tbody.rows;for(var c=0;c<rows.length;c++){row_array[row_array.length]=[sorttable.getInnerText(rows[c].cells[col]),rows[c]]}row_array.sort(this.sorttable_sortfunction);row_array.reverse();tb=this.sorttable_tbody;for(var c=0;c<row_array.length;c++){tb.appendChild(row_array[c][1])}delete row_array})}}},guessType:function(c,b){sortfn=sorttable.sort_alpha;for(var a=0;a<c.tBodies[0].rows.length;a++){text=sorttable.getInnerText(c.tBodies[0].rows[a].cells[b]);if(text!=""){if(text.match(/^-?[<5B>$<24>]?[\d,.]+%?$/)){return sorttable.sort_numeric}possdate=text.match(sorttable.DATE_RE);if(possdate){first=parseInt(possdate[1]);second=parseInt(possdate[2]);if(first>12){return sorttable.sort_ddmm}else{if(second>12){return sorttable.sort_mmdd}else{sortfn=sorttable.sort_ddmm}}}}}return sortfn},getInnerText:function(b){if(!b){return""}hasInputs=(typeof b.getElementsByTagName=="function")&&b.getElementsByTagName("input").length;if(b.getAttr
2012-12-02 21:24:19 +01:00
/*@cc_on @*/
/*@if (@_win32)
document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
if (this.readyState == "complete") {
sorttable.init(); // call the onload handler
}
};
/*@end @*/
}if(/WebKit/i.test(navigator.userAgent)){var _timer=setInterval(function(){if(/loaded|complete/.test(document.readyState)){sorttable.init()}},10)}window.onload=sorttable.init;function dean_addEvent(b,e,c){if(b.addEventListener){b.addEventListener(e,c,false)}else{if(!c.$$guid){c.$$guid=dean_addEvent.guid++}if(!b.events){b.events={}}var a=b.events[e];if(!a){a=b.events[e]={};if(b["on"+e]){a[0]=b["on"+e]}}a[c.$$guid]=c;b["on"+e]=handleEvent}}dean_addEvent.guid=1;function removeEvent(a,c,b){if(a.removeEventListener){a.removeEventListener(c,b,false)}else{if(a.events&&a.events[c]){delete a.events[c][b.$$guid]}}}function handleEvent(e){var c=true;e=e||fixEvent(((this.ownerDocument||this.document||this).parentWindow||window).event);var a=this.events[e.type];for(var b in a){this.$$handleEvent=a[b];if(this.$$handleEvent(e)===false){c=false}}return c}function fixEvent(a){a.preventDefault=fixEvent.preventDefault;a.stopPropagation=fixEvent.stopPropagation;return a}fixEvent.preventDefault=function(){this.returnValue=false};fixEvent.stopPropagation=function(){this.cancelBubble=true};if(!Array.forEach){Array.forEach=function(e,c,b){for(var a=0;a<e.length;a++){c.call(b,e[a],a,e)}}}Function.prototype.forEach=function(a,e,c){for(var b in a){if(typeof this.prototype[b]=="undefined"){e.call(c,a[b],b,a)}}};String.forEach=function(a,c,b){Array.forEach(a.split(""),function(f,e){c.call(b,f,e,a)})};var forEach=function(a,e,b){if(a){var c=Object;if(a instanceof Function){c=Function}else{if(a.forEach instanceof Function){a.forEach(e,b);return}else{if(typeof a=="string"){c=String}else{if(typeof a.length=="number"){c=Array}}}}c.forEach(a,e,b)}};