Skip to content

Commit

Permalink
report function for IE debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
kangax committed Jun 19, 2008
1 parent a23e5d5 commit c3b885e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
17 changes: 16 additions & 1 deletion array.extensions.js
Expand Up @@ -20,4 +20,19 @@ Array.prototype.sum = function() {
**/ **/
Array.prototype.clone = function() { Array.prototype.clone = function() {
return this.concat(); return this.concat();
} }

/**
* Array#isUnique(value) -> Boolean
* returns true if a specified value is unique in an array
* (or if it's not in an array)
*
* [1,2,3].isUnique(1); // true
* [1,2,3,1].isUnique(1); // false
* [5,6,'a'].isUnique('foo'); // true
*
**/
Array.prototype.isUnique = function(value){
var idx = this.indexOf(value);
return this.indexOf(value, idx + 1) == -1;
};
52 changes: 52 additions & 0 deletions experimental/report.js
@@ -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('');
}

0 comments on commit c3b885e

Please sign in to comment.