This repository has been archived by the owner on Oct 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
page-change-time.js
61 lines (51 loc) · 1.79 KB
/
page-change-time.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*!
* jQuery Mobile v@VERSION
* http://jquerymobile.com/
*
* Copyright 2012 jQuery Foundation and other contributors
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*/
// This is code that can be used as a simple bookmarklet for timing
// the load, enhancment, and transition of a changePage() request.
(function( $, window, undefined ) {
function getTime() {
return ( new Date() ).getTime();
}
var startChange, stopChange, startLoad, stopLoad, startEnhance, stopEnhance, startTransition, stopTransition, lock = 0;
$( document )
.bind( "pagebeforechange", function( e, data) {
if ( typeof data.toPage === "string" ) {
startChange = stopChange = startLoad = stopLoad = startEnhance = stopEnhance = startTransition = stopTransition = getTime();
}
})
.bind( "pagebeforeload", function() {
startLoad = stopLoad = getTime();
})
.bind( "pagebeforecreate", function() {
if ( ++lock === 1 ) {
stopLoad = startEnhance = stopEnhance = getTime();
}
})
.bind( "pageinit", function() {
if ( --lock === 0 ) {
stopEnhance = getTime();
}
})
.bind( "pagebeforeshow", function() {
startTransition = stopTransition = getTime();
})
.bind( "pageshow", function() {
stopTransition = getTime();
})
.bind( "pagechange", function( e, data ) {
if ( typeof data.toPage === "object" ) {
stopChange = getTime();
alert("load + processing: " + ( stopLoad - startLoad )
+ "\nenhance: " + ( stopEnhance - startEnhance )
+ "\ntransition: " + ( stopTransition - startTransition )
+ "\ntotalTime: " + ( stopChange - startChange ) );
startChange = stopChange = startLoad = stopLoad = startEnhance = stopEnhance = startTransition = stopTransition = 0;
}
});
})( jQuery, window );