jsperformance
Advanced tools
Comparing version 0.0.2 to 0.0.3
130
index.js
@@ -77,59 +77,82 @@ | ||
WebPerformance.prototype.addEvents = function(type) { | ||
WebPerformance.prototype.addEachEvents = function(evts) { | ||
var self = this; | ||
return function (evts) { | ||
if (typeof evts === 'string') { | ||
var events = [evts] || ['hashchange']; | ||
} | ||
else if (Object.prototype.toString.call(evts) === '[object Array]') { | ||
var events = evts; | ||
} | ||
for (var i = 0; i < events.length; i++) { | ||
(function(eventName) { | ||
var eventCallback = function(e) { | ||
var e = e || window.event; | ||
var eventHookTime = 0; | ||
var timeAfterEvent = function(time) { | ||
eventHookTime = eventHookTime + time; | ||
}; | ||
self.on('executing', timeAfterEvent); | ||
window.removeEventListener(eventName, eventCallback); | ||
setTimeout(function() { | ||
if (type === 'slow' && eventHookTime > self.slowStandard) { | ||
self.trigger('slowEventHook', { | ||
type: 'slowEvent', | ||
event: eventName, | ||
time: eventHookTime, | ||
location: location.href, | ||
name: self.name, | ||
domClass: e.target.className, | ||
domName: e.target.tagName, | ||
domId: e.target.id, | ||
// domEvent: e | ||
}); | ||
} | ||
else { | ||
self.trigger('eachEventHook', { | ||
type: 'eachEvent', | ||
event: eventName, | ||
time: eventHookTime, | ||
location: location.href, | ||
name: self.name, | ||
domClass: e.target.className, | ||
domName: e.target.tagName, | ||
domId: e.target.id, | ||
// domEvent: e | ||
}); | ||
} | ||
window.addEventListener(eventName, eventCallback, false); | ||
}, self.eventTimeout); | ||
} | ||
window.addEventListener(eventName, eventCallback, false); | ||
})(events[i]) | ||
} | ||
} | ||
if (typeof evts === 'string') { | ||
var events = [evts] || ['hashchange']; | ||
} | ||
else if (Object.prototype.toString.call(evts) === '[object Array]') { | ||
var events = evts; | ||
} | ||
for (var i = 0; i < events.length; i++) { | ||
(function(eventName) { | ||
var eventCallback = function(e) { | ||
var e = e || window.event; | ||
var eventHookTime = 0; | ||
var timeAfterEvent = function(time) { | ||
eventHookTime = eventHookTime + time; | ||
}; | ||
self.on('executing', timeAfterEvent); | ||
window.removeEventListener(eventName, eventCallback); | ||
setTimeout(function() { | ||
self.trigger('eachEventHook', { | ||
type: 'eachEvent', | ||
event: eventName, | ||
time: eventHookTime, | ||
location: location.href, | ||
name: self.name, | ||
domClass: e.target.className, | ||
domName: e.target.tagName, | ||
domId: e.target.id, | ||
// domEvent: e | ||
}); | ||
window.addEventListener(eventName, eventCallback, false); | ||
}, self.eventTimeout); | ||
} | ||
window.addEventListener(eventName, eventCallback, false); | ||
})(events[i]) | ||
} | ||
}; | ||
WebPerformance.prototype.addSlowEvents = function(evts) { | ||
var self = this; | ||
if (typeof evts === 'string') { | ||
var events = [evts] || ['hashchange']; | ||
} | ||
else if (Object.prototype.toString.call(evts) === '[object Array]') { | ||
var events = evts; | ||
} | ||
for (var i = 0; i < events.length; i++) { | ||
(function(eventName) { | ||
var eventCallback = function(e) { | ||
var e = e || window.event; | ||
var eventHookTime = 0; | ||
var timeAfterEvent = function(time) { | ||
eventHookTime = eventHookTime + time; | ||
}; | ||
self.on('executing', timeAfterEvent); | ||
window.removeEventListener(eventName, eventCallback); | ||
setTimeout(function() { | ||
if (eventHookTime > self.slowStandard) { | ||
self.trigger('slowEventHook', { | ||
type: 'slowEvent', | ||
event: eventName, | ||
time: eventHookTime, | ||
location: location.href, | ||
name: self.name, | ||
domClass: e.target.className, | ||
domName: e.target.tagName, | ||
domId: e.target.id, | ||
// domEvent: e | ||
}); | ||
} | ||
window.addEventListener(eventName, eventCallback, false); | ||
}, self.eventTimeout); | ||
} | ||
window.addEventListener(eventName, eventCallback, false); | ||
})(events[i]) | ||
} | ||
}; | ||
WebPerformance.prototype.setOptions = function () { | ||
@@ -151,4 +174,3 @@ this.onSlowFunc = this.options.onSlowFunc; | ||
var self = this; | ||
this.addEachEvents = this.addEvents('each'); | ||
this.addSlowEvents = this.addEvents('slow'); | ||
function timeout() { | ||
@@ -155,0 +177,0 @@ if (requestAnimationFrame) { |
{ | ||
"name": "jsperformance", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "get web performance", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10314
213