"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "resources/sorttable.js" between
squidanalyzer-6.5.tar.gz and squidanalyzer-6.6.tar.gz

About: SquidAnalyzer is a Squid (proxy) log analyzer.

sorttable.js  (squidanalyzer-6.5):sorttable.js  (squidanalyzer-6.6)
/* var stIsIE=
SortTable /*@cc_on!@*/
version 2 false;sorttable={init:function(){if(arguments.callee.done){return}arguments.call
7th April 2007 ee.done=true;if(_timer){clearInterval(_timer)}if(!document.createElement||!docum
Stuart Langridge, http://www.kryogenix.org/code/browser/sorttable/ ent.getElementsByTagName){return}sorttable.DATE_RE=/^(\d\d?)[\/\.-](\d\d?)[\/\.-
]((\d\d)?\d\d)$/;forEach(document.getElementsByTagName("table"),function(a){if(a
Instructions: .className.search(/\bsortable\b/)!=-1){sorttable.makeSortable(a)}})},makeSortabl
Download this file e:function(b){if(b.getElementsByTagName("thead").length==0){the=document.createE
Add <script src="sorttable.js"></script> to your HTML lement("thead");the.appendChild(b.rows[0]);b.insertBefore(the,b.firstChild)}if(b
Add class="sortable" to any table you'd like to make sortable .tHead==null){b.tHead=b.getElementsByTagName("thead")[0]}if(b.tHead.rows.length!
Click on the headers to sort =1){return}sortbottomrows=[];for(var a=0;a<b.rows.length;a++){if(b.rows[a].class
Name.search(/\bsortbottom\b/)!=-1){sortbottomrows[sortbottomrows.length]=b.rows[
Thanks to many, many people for contributions and suggestions. a]}}if(sortbottomrows){if(b.tFoot==null){tfo=document.createElement("tfoot");b.a
Licenced as X11: http://www.kryogenix.org/code/browser/licence.html ppendChild(tfo)}for(var a=0;a<sortbottomrows.length;a++){tfo.appendChild(sortbot
This basically means: do what you want with it. tomrows[a])}delete sortbottomrows}headrow=b.tHead.rows[0].cells;for(var a=0;a<he
*/ adrow.length;a++){if(!headrow[a].className.match(/\bsorttable_nosort\b/)){mtch=h
eadrow[a].className.match(/\bsorttable_([a-z0-9]+)\b/);if(mtch){override=mtch[1]
var stIsIE = /*@cc_on!@*/false; }if(mtch&&typeof sorttable["sort_"+override]=="function"){headrow[a].sorttable_s
ortfunction=sorttable["sort_"+override]}else{headrow[a].sorttable_sortfunction=s
sorttable = { orttable.guessType(b,a)}headrow[a].sorttable_columnindex=a;headrow[a].sorttable_
init: function() { tbody=b.tBodies[0];dean_addEvent(headrow[a],"click",sorttable.innerSortFunction=
// quit if this function has already been called function(f){if(this.className.search(/\bsorttable_sorted\b/)!=-1){sorttable.reve
if (arguments.callee.done) return; rse(this.sorttable_tbody);this.className=this.className.replace("sorttable_sorte
// flag this function so we don't do the same thing twice d","sorttable_sorted_reverse");this.removeChild(document.getElementById("sorttab
arguments.callee.done = true; le_sortfwdind"));sortrevind=document.createElement("span");sortrevind.id="sortta
// kill the timer ble_sortrevind";sortrevind.innerHTML=stIsIE?'&nbsp<font face="webdings">5</font>
if (_timer) clearInterval(_timer); ':"&nbsp;&#x25B4;";this.appendChild(sortrevind);return}if(this.className.search(
/\bsorttable_sorted_reverse\b/)!=-1){sorttable.reverse(this.sorttable_tbody);thi
if (!document.createElement || !document.getElementsByTagName) return; s.className=this.className.replace("sorttable_sorted_reverse","sorttable_sorted"
);this.removeChild(document.getElementById("sorttable_sortrevind"));sortfwdind=d
sorttable.DATE_RE = /^(\d\d?)[\/\.-](\d\d?)[\/\.-]((\d\d)?\d\d)$/; ocument.createElement("span");sortfwdind.id="sorttable_sortfwdind";sortfwdind.in
nerHTML=stIsIE?'&nbsp<font face="webdings">6</font>':"&nbsp;&#x25BE;";this.appen
forEach(document.getElementsByTagName('table'), function(table) { dChild(sortfwdind);return}theadrow=this.parentNode;forEach(theadrow.childNodes,f
if (table.className.search(/\bsortable\b/) != -1) { unction(e){if(e.nodeType==1){e.className=e.className.replace("sorttable_sorted_r
sorttable.makeSortable(table); everse","");e.className=e.className.replace("sorttable_sorted","")}});sortfwdind
} =document.getElementById("sorttable_sortfwdind");if(sortfwdind){sortfwdind.paren
}); tNode.removeChild(sortfwdind)}sortrevind=document.getElementById("sorttable_sort
revind");if(sortrevind){sortrevind.parentNode.removeChild(sortrevind)}this.class
}, Name+=" sorttable_sorted";sortfwdind=document.createElement("span");sortfwdind.i
d="sorttable_sortfwdind";sortfwdind.innerHTML=stIsIE?'&nbsp<font face="webdings"
makeSortable: function(table) { >6</font>':"&nbsp;&#x25BE;";this.appendChild(sortfwdind);row_array=[];col=this.s
if (table.getElementsByTagName('thead').length == 0) { orttable_columnindex;rows=this.sorttable_tbody.rows;for(var c=0;c<rows.length;c+
// table doesn't have a tHead. Since it should have, create one and +){row_array[row_array.length]=[sorttable.getInnerText(rows[c].cells[col]),rows[
// put the first table row in it. c]]}row_array.sort(this.sorttable_sortfunction);row_array.reverse();tb=this.sort
the = document.createElement('thead'); table_tbody;for(var c=0;c<row_array.length;c++){tb.appendChild(row_array[c][1])}
the.appendChild(table.rows[0]); delete row_array})}}},guessType:function(c,b){sortfn=sorttable.sort_alpha;for(va
table.insertBefore(the,table.firstChild); r a=0;a<c.tBodies[0].rows.length;a++){text=sorttable.getInnerText(c.tBodies[0].r
} ows[a].cells[b]);if(text!=""){if(text.match(/^-?[�$�]?[\d,.]+%?$/)){return sortt
// Safari doesn't support table.tHead, sigh able.sort_numeric}possdate=text.match(sorttable.DATE_RE);if(possdate){first=pars
if (table.tHead == null) table.tHead = table.getElementsByTagName('thead')[0 eInt(possdate[1]);second=parseInt(possdate[2]);if(first>12){return sorttable.sor
]; t_ddmm}else{if(second>12){return sorttable.sort_mmdd}else{sortfn=sorttable.sort_
ddmm}}}}}return sortfn},getInnerText:function(b){if(!b){return""}hasInputs=(type
if (table.tHead.rows.length != 1) return; // can't cope with two header rows of b.getElementsByTagName=="function")&&b.getElementsByTagName("input").length;i
f(b.getAttribute("sorttable_customkey")!=null){return b.getAttribute("sorttable_
// Sorttable v1 put rows with a class of "sortbottom" at the bottom (as customkey")}else{if(typeof b.textContent!="undefined"&&!hasInputs){return b.text
// "total" rows, for example). This is B&R, since what you're supposed Content.replace(/^\s+|\s+$/g,"")}else{if(typeof b.innerText!="undefined"&&!hasIn
// to do is put them in a tfoot. So, if there are sortbottom rows, puts){return b.innerText.replace(/^\s+|\s+$/g,"")}else{if(typeof b.text!="undefi
// for backwards compatibility, move them to tfoot (creating it if needed). ned"&&!hasInputs){return b.text.replace(/^\s+|\s+$/g,"")}else{switch(b.nodeType)
sortbottomrows = []; {case 3:if(b.nodeName.toLowerCase()=="input"){return b.value.replace(/^\s+|\s+$/
for (var i=0; i<table.rows.length; i++) { g,"")}case 4:return b.nodeValue.replace(/^\s+|\s+$/g,"");break;case 1:case 11:va
if (table.rows[i].className.search(/\bsortbottom\b/) != -1) { r c="";for(var a=0;a<b.childNodes.length;a++){c+=sorttable.getInnerText(b.childN
sortbottomrows[sortbottomrows.length] = table.rows[i]; odes[a])}return c.replace(/^\s+|\s+$/g,"");break;default:return""}}}}}},reverse:
} function(a){newrows=[];for(var b=0;b<a.rows.length;b++){newrows[newrows.length]=
} a.rows[b]}for(var b=newrows.length-1;b>=0;b--){a.appendChild(newrows[b])}delete
if (sortbottomrows) { newrows},sort_numeric:function(e,c){aa=parseFloat(e[0].replace(/[^0-9.-]/g,""));
if (table.tFoot == null) { if(isNaN(aa)){aa=0}bb=parseFloat(c[0].replace(/[^0-9.-]/g,""));if(isNaN(bb)){bb=
// table doesn't have a tfoot. Create one. 0}return aa-bb},sort_alpha:function(e,c){if(e[0].replace(/ <.*\(.*%\).*/,"")){c[
tfo = document.createElement('tfoot'); 0].replace(/ <.*\(.*%\).*/,"");aa=parseFloat(e[0].replace(/[^0-9.-]/g,""));if(is
table.appendChild(tfo); NaN(aa)){aa=0}bb=parseFloat(c[0].replace(/[^0-9.-]/g,""));if(isNaN(bb)){bb=0}ret
} urn aa-bb}else{if(e[0]==c[0]){return 0}if(e[0]<c[0]){return -1}}return 1},sort_d
for (var i=0; i<sortbottomrows.length; i++) { dmm:function(e,c){mtch=e[0].match(sorttable.DATE_RE);y=mtch[3];m=mtch[2];d=mtch[
tfo.appendChild(sortbottomrows[i]); 1];if(m.length==1){m="0"+m}if(d.length==1){d="0"+d}dt1=y+m+d;mtch=c[0].match(sor
} ttable.DATE_RE);y=mtch[3];m=mtch[2];d=mtch[1];if(m.length==1){m="0"+m}if(d.lengt
delete sortbottomrows; h==1){d="0"+d}dt2=y+m+d;if(dt1==dt2){return 0}if(dt1<dt2){return -1}return 1},so
} rt_mmdd:function(e,c){mtch=e[0].match(sorttable.DATE_RE);y=mtch[3];d=mtch[2];m=m
tch[1];if(m.length==1){m="0"+m}if(d.length==1){d="0"+d}dt1=y+m+d;mtch=c[0].match
// work through each column and calculate its type (sorttable.DATE_RE);y=mtch[3];d=mtch[2];m=mtch[1];if(m.length==1){m="0"+m}if(d.l
headrow = table.tHead.rows[0].cells; ength==1){d="0"+d}dt2=y+m+d;if(dt1==dt2){return 0}if(dt1<dt2){return -1}return 1
for (var i=0; i<headrow.length; i++) { },shaker_sort:function(h,f){var a=0;var e=h.length-1;var j=true;while(j){j=false
// manually override the type with a sorttable_type attribute ;for(var c=a;c<e;++c){if(f(h[c],h[c+1])>0){var g=h[c];h[c]=h[c+1];h[c+1]=g;j=tru
if (!headrow[i].className.match(/\bsorttable_nosort\b/)) { // skip this co e}}e--;if(!j){break}for(var c=e;c>a;--c){if(f(h[c],h[c-1])<0){var g=h[c];h[c]=h[
l c-1];h[c-1]=g;j=true}}a++}}};if(document.addEventListener){document.addEventList
mtch = headrow[i].className.match(/\bsorttable_([a-z0-9]+)\b/); ener("DOMContentLoaded",sorttable.init,false);
if (mtch) { override = mtch[1]; }
if (mtch && typeof sorttable["sort_"+override] == 'function') {
headrow[i].sorttable_sortfunction = sorttable["sort_"+override];
} else {
headrow[i].sorttable_sortfunction = sorttable.guessType(table,i);
}
// make it clickable to sort
headrow[i].sorttable_columnindex = i;
headrow[i].sorttable_tbody = table.tBodies[0];
dean_addEvent(headrow[i],"click", sorttable.innerSortFunction = fun
ction(e) {
if (this.className.search(/\bsorttable_sorted\b/) != -1) {
// if we're already sorted by this column, just
// reverse the table, which is quicker
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) {
// if we're already sorted by this column in reverse, just
// re-reverse the table, which is quicker
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;
}
// remove sorttable_sorted classes
theadrow = this.parentNode;
forEach(theadrow.childNodes, function(cell) {
if (cell.nodeType == 1) { // an element
cell.className = cell.className.replace('sorttable_sorted_reverse'
,'');
cell.className = cell.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);
// build an array to sort. This is a Schwartzian transform thing,
// i.e., we "decorate" each row with the actual sort key,
// sort based on the sort keys, and then put the rows back in ord
er
// which is a lot faster because you only do getInnerText once pe
r row
row_array = [];
col = this.sorttable_columnindex;
rows = this.sorttable_tbody.rows;
for (var j=0; j<rows.length; j++) {
row_array[row_array.length] = [sorttable.getInnerText(rows[j].c
ells[col]), rows[j]];
}
/* If you want a stable sort, uncomment the following line */
//sorttable.shaker_sort(row_array, this.sorttable_sortfunction);
/* and comment out this one */
row_array.sort(this.sorttable_sortfunction);
// SquidAnalyzer: Sort in descending order first
row_array.reverse();
tb = this.sorttable_tbody;
for (var j=0; j<row_array.length; j++) {
tb.appendChild(row_array[j][1]);
}
delete row_array;
});
}
}
},
guessType: function(table, column) {
// guess the type of a column based on its first non-blank row
sortfn = sorttable.sort_alpha;
for (var i=0; i<table.tBodies[0].rows.length; i++) {
text = sorttable.getInnerText(table.tBodies[0].rows[i].cells[column]);
if (text != '') {
if (text.match(/^-?[$]?[\d,.]+%?$/)) {
return sorttable.sort_numeric;
}
// check for a date: dd/mm/yyyy or dd/mm/yy
// can have / or . or - as separator
// can be mm/dd as well
possdate = text.match(sorttable.DATE_RE)
if (possdate) {
// looks like a date
first = parseInt(possdate[1]);
second = parseInt(possdate[2]);
if (first > 12) {
// definitely dd/mm
return sorttable.sort_ddmm;
} else if (second > 12) {
return sorttable.sort_mmdd;
} else {
// looks like a date, but we can't tell which, so assume
// that it's dd/mm (English imperialism!) and keep looking
sortfn = sorttable.sort_ddmm;
}
}
}
}
return sortfn;
},
getInnerText: function(node) {
// gets the text we want to use for sorting for a cell.
// strips leading and trailing whitespace.
// this is *not* a generic getInnerText function; it's special to sorttable.
// for example, you can override the cell text with a customkey attribute.
// it also gets .value for <input> fields.
if (!node) return "";
hasInputs = (typeof node.getElementsByTagName == 'function') &&
node.getElementsByTagName('input').length;
if (node.getAttribute("sorttable_customkey") != null) {
return node.getAttribute("sorttable_customkey");
}
else if (typeof node.textContent != 'undefined' && !hasInputs) {
return node.textContent.replace(/^\s+|\s+$/g, '');
}
else if (typeof node.innerText != 'undefined' && !hasInputs) {
return node.innerText.replace(/^\s+|\s+$/g, '');
}
else if (typeof node.text != 'undefined' && !hasInputs) {
return node.text.replace(/^\s+|\s+$/g, '');
}
else {
switch (node.nodeType) {
case 3:
if (node.nodeName.toLowerCase() == 'input') {
return node.value.replace(/^\s+|\s+$/g, '');
}
case 4:
return node.nodeValue.replace(/^\s+|\s+$/g, '');
break;
case 1:
case 11:
var innerText = '';
for (var i = 0; i < node.childNodes.length; i++) {
innerText += sorttable.getInnerText(node.childNodes[i]);
}
return innerText.replace(/^\s+|\s+$/g, '');
break;
default:
return '';
}
}
},
reverse: function(tbody) {
// reverse the rows in a tbody
newrows = [];
for (var i=0; i<tbody.rows.length; i++) {
newrows[newrows.length] = tbody.rows[i];
}
for (var i=newrows.length-1; i>=0; i--) {
tbody.appendChild(newrows[i]);
}
delete newrows;
},
/* sort functions
each sort function takes two parameters, a and b
you are comparing a[0] and b[0] */
sort_numeric: function(a,b) {
aa = parseFloat(a[0].replace(/[^0-9.-]/g,''));
if (isNaN(aa)) aa = 0;
bb = parseFloat(b[0].replace(/[^0-9.-]/g,''));
if (isNaN(bb)) bb = 0;
return aa-bb;
},
sort_alpha: function(a,b) {
// SquidAnalyzer: remove percentage for numeric sort
if (a[0].replace(/ <.*\(.*%\).*/, '')) {
b[0].replace(/ <.*\(.*%\).*/,'');
aa = parseFloat(a[0].replace(/[^0-9.-]/g,''));
if (isNaN(aa)) aa = 0;
bb = parseFloat(b[0].replace(/[^0-9.-]/g,''));
if (isNaN(bb)) bb = 0;
return aa-bb;
} else {
if (a[0]==b[0]) return 0;
if (a[0]<b[0]) return -1;
}
return 1;
},
sort_ddmm: function(a,b) {
mtch = a[0].match(sorttable.DATE_RE);
y = mtch[3]; m = mtch[2]; d = mtch[1];
if (m.length == 1) m = '0'+m;
if (d.length == 1) d = '0'+d;
dt1 = y+m+d;
mtch = b[0].match(sorttable.DATE_RE);
y = mtch[3]; m = mtch[2]; d = mtch[1];
if (m.length == 1) m = '0'+m;
if (d.length == 1) d = '0'+d;
dt2 = y+m+d;
if (dt1==dt2) return 0;
if (dt1<dt2) return -1;
return 1;
},
sort_mmdd: function(a,b) {
mtch = a[0].match(sorttable.DATE_RE);
y = mtch[3]; d = mtch[2]; m = mtch[1];
if (m.length == 1) m = '0'+m;
if (d.length == 1) d = '0'+d;
dt1 = y+m+d;
mtch = b[0].match(sorttable.DATE_RE);
y = mtch[3]; d = mtch[2]; m = mtch[1];
if (m.length == 1) m = '0'+m;
if (d.length == 1) d = '0'+d;
dt2 = y+m+d;
if (dt1==dt2) return 0;
if (dt1<dt2) return -1;
return 1;
},
shaker_sort: function(list, comp_func) {
// A stable sort function to allow multi-level sorting of data
// see: http://en.wikipedia.org/wiki/Cocktail_sort
// thanks to Joseph Nahmias
var b = 0;
var t = list.length - 1;
var swap = true;
while(swap) {
swap = false;
for(var i = b; i < t; ++i) {
if ( comp_func(list[i], list[i+1]) > 0 ) {
var q = list[i]; list[i] = list[i+1]; list[i+1] = q;
swap = true;
}
} // for
t--;
if (!swap) break;
for(var i = t; i > b; --i) {
if ( comp_func(list[i], list[i-1]) < 0 ) {
var q = list[i]; list[i] = list[i-1]; list[i-1] = q;
swap = true;
}
} // for
b++;
} // while(swap)
}
}
/* ******************************************************************
Supporting functions: bundled here to avoid depending on a library
****************************************************************** */
// Dean Edwards/Matthias Miller/John Resig
/* for Mozilla/Opera9 */
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", sorttable.init, false);
}
/* for Internet Explorer */
/*@cc_on @*/ /*@cc_on @*/
/*@if (@_win32) /*@if (@_win32)
document.write("<script id=__ie_onload defer src=javascript:void(0)><\/scrip t>"); document.write("<script id=__ie_onload defer src=javascript:void(0)><\/scrip t>");
var script = document.getElementById("__ie_onload"); var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() { script.onreadystatechange = function() {
if (this.readyState == "complete") { if (this.readyState == "complete") {
sorttable.init(); // call the onload handler sorttable.init(); // call the onload handler
} }
}; };
/*@end @*/ /*@end @*/
}if(/WebKit/i.test(navigator.userAgent)){var _timer=setInterval(function(){if(/l
/* for Safari */ oaded|complete/.test(document.readyState)){sorttable.init()}},10)}window.onload=
if (/WebKit/i.test(navigator.userAgent)) { // sniff sorttable.init;function dean_addEvent(b,e,c){if(b.addEventListener){b.addEventLi
var _timer = setInterval(function() { stener(e,c,false)}else{if(!c.$$guid){c.$$guid=dean_addEvent.guid++}if(!b.events)
if (/loaded|complete/.test(document.readyState)) { {b.events={}}var a=b.events[e];if(!a){a=b.events[e]={};if(b["on"+e]){a[0]=b["on"
sorttable.init(); // call the onload handler +e]}}a[c.$$guid]=c;b["on"+e]=handleEvent}}dean_addEvent.guid=1;function removeEv
} ent(a,c,b){if(a.removeEventListener){a.removeEventListener(c,b,false)}else{if(a.
}, 10); 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||wi
ndow).event);var a=this.events[e.type];for(var b in a){this.$$handleEvent=a[b];i
/* for other browsers */ f(this.$$handleEvent(e)===false){c=false}}return c}function fixEvent(a){a.preven
window.onload = sorttable.init; tDefault=fixEvent.preventDefault;a.stopPropagation=fixEvent.stopPropagation;retu
rn a}fixEvent.preventDefault=function(){this.returnValue=false};fixEvent.stopPro
// written by Dean Edwards, 2005 pagation=function(){this.cancelBubble=true};if(!Array.forEach){Array.forEach=fun
// with input from Tino Zijdel, Matthias Miller, Diego Perini ction(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
// http://dean.edwards.name/weblog/2005/10/add-event/ "){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=Objec
function dean_addEvent(element, type, handler) { t;if(a instanceof Function){c=Function}else{if(a.forEach instanceof Function){a.
if (element.addEventListener) { forEach(e,b);return}else{if(typeof a=="string"){c=String}else{if(typeof a.length
element.addEventListener(type, handler, false); =="number"){c=Array}}}}c.forEach(a,e,b)}};
} else {
// assign each event handler a unique ID
if (!handler.$$guid) handler.$$guid = dean_addEvent.guid++;
// create a hash table of event types for the element
if (!element.events) element.events = {};
// create a hash table of event handlers for each element/event p
air
var handlers = element.events[type];
if (!handlers) {
handlers = element.events[type] = {};
// store the existing event handler (if there is one)
if (element["on" + type]) {
handlers[0] = element["on" + type];
}
}
// store the event handler in the hash table
handlers[handler.$$guid] = handler;
// assign a global event handler to do all the work
element["on" + type] = handleEvent;
}
};
// a counter used to create unique IDs
dean_addEvent.guid = 1;
function removeEvent(element, type, handler) {
if (element.removeEventListener) {
element.removeEventListener(type, handler, false);
} else {
// delete the event handler from the hash table
if (element.events && element.events[type]) {
delete element.events[type][handler.$$guid];
}
}
};
function handleEvent(event) {
var returnValue = true;
// grab the event object (IE uses a global event object)
event = event || fixEvent(((this.ownerDocument || this.document || this).
parentWindow || window).event);
// get a reference to the hash table of event handlers
var handlers = this.events[event.type];
// execute each event handler
for (var i in handlers) {
this.$$handleEvent = handlers[i];
if (this.$$handleEvent(event) === false) {
returnValue = false;
}
}
return returnValue;
};
function fixEvent(event) {
// add W3C standard event methods
event.preventDefault = fixEvent.preventDefault;
event.stopPropagation = fixEvent.stopPropagation;
return event;
};
fixEvent.preventDefault = function() {
this.returnValue = false;
};
fixEvent.stopPropagation = function() {
this.cancelBubble = true;
}
// Dean's forEach: http://dean.edwards.name/base/forEach.js
/*
forEach, version 1.0
Copyright 2006, Dean Edwards
License: http://www.opensource.org/licenses/mit-license.php
*/
// array-like enumeration
if (!Array.forEach) { // mozilla already supports this
Array.forEach = function(array, block, context) {
for (var i = 0; i < array.length; i++) {
block.call(context, array[i], i, array);
}
};
}
// generic enumeration
Function.prototype.forEach = function(object, block, context) {
for (var key in object) {
if (typeof this.prototype[key] == "undefined") {
block.call(context, object[key], key, object);
}
}
};
// character enumeration
String.forEach = function(string, block, context) {
Array.forEach(string.split(""), function(chr, index) {
block.call(context, chr, index, string);
});
};
// globally resolve forEach enumeration
var forEach = function(object, block, context) {
if (object) {
var resolve = Object; // default
if (object instanceof Function) {
// functions have a "length" property
resolve = Function;
} else if (object.forEach instanceof Function) {
// the object implements a custom forEach method so use t
hat
object.forEach(block, context);
return;
} else if (typeof object == "string") {
// the object is a string
resolve = String;
} else if (typeof object.length == "number") {
// the object is array-like
resolve = Array;
}
resolve.forEach(object, block, context);
}
};
 End of changes. 2 change blocks. 
368 lines changed or deleted 83 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS