Permalink
Browse files

report function for IE debugging

  • Loading branch information...
1 parent a23e5d5 commit c3b885e686fdb2c4d8bba89903c0f7b8d1233eb4 kangax committed Jun 19, 2008
Showing with 68 additions and 1 deletion.
  1. +16 −1 array.extensions.js
  2. +52 −0 experimental/report.js
View
17 array.extensions.js
@@ -20,4 +20,19 @@ Array.prototype.sum = function() {
**/
Array.prototype.clone = function() {
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;
+};
View
52 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.