Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kangax
committed
Jun 19, 2008
1 parent
a23e5d5
commit c3b885e
Showing
2 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,52 @@ | |||
/* | |||
Reports: | |||
- number of event handlers on a page | |||
- non-unique ID's | |||
- collapsing names/ID's (IE bug) | |||
Requires: | |||
prototype.js v. 1.6.0.3 | |||
*/ | |||
|
|||
function report() { | |||
function isUnique(arr, value) { | |||
var idx = arr.indexOf(value); | |||
return arr.indexOf(value, idx + 1) == -1; | |||
} | |||
// event handlers | |||
var results = 0, c = Event.cache; | |||
for (var element in c) { | |||
for (var handler in c[element]) { | |||
for (var eventName in c[element]) { | |||
if (eventName == 'element') continue; | |||
results += c[element][eventName].length; | |||
} | |||
} | |||
} | |||
// find non-unique ids | |||
var ids = $$('*').pluck('id').without(''); | |||
var nonUnique = []; | |||
ids.each(function(id) { | |||
if (!isUnique(ids, id)) | |||
(nonUnique.indexOf(id) == -1) && nonUnique.push(id); | |||
}) | |||
|
|||
// find collapsing names/ids (IE) | |||
var withName = $$('*[name]'); | |||
var withId = $$('*[id]'); | |||
var collapsing = []; | |||
withId.each(function(el) { | |||
var collapsed = withName.find(function(_el){ return (_el.name == el.id) && _el != el }) | |||
if (collapsed) { | |||
collapsing.push(el, collapsed); | |||
} | |||
}); | |||
|
|||
// return result | |||
return ['Event handlers: ', results, | |||
'\nNon-Unique ID\'s: ', (nonUnique.length ? nonUnique : 'none'), | |||
'\nCollapsing names/ID\'s: ', (collapsing.length ? collapsing : 'none') | |||
].join(''); | |||
} |