2.0_beta sync to rsa
[framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.1.0 / tools / page-change-time.js
1 /*!
2  * jQuery Mobile v@VERSION
3  * http://jquerymobile.com/
4  *
5  * Copyright 2011, jQuery Project
6  * Dual licensed under the MIT or GPL Version 2 licenses.
7  * http://jquery.org/license
8  */
9
10 // This is code that can be used as a simple bookmarklet for timing
11 // the load, enhancment, and transition of a changePage() request.
12
13 (function( $, window, undefined ) {
14
15
16         function getTime() {
17                 return ( new Date() ).getTime();
18         }
19
20         var startChange, stopChange, startLoad, stopLoad,  startEnhance, stopEnhance, startTransition, stopTransition, lock = 0;
21
22         $( document )
23                 .bind( "pagebeforechange", function( e, data) {
24                                 if ( typeof data.toPage === "string" ) {
25                                         startChange = stopChange = startLoad = stopLoad = startEnhance = stopEnhance = startTransition = stopTransition = getTime();
26                                 }
27                         })
28                 .bind( "pagebeforeload", function() {
29                                 startLoad = stopLoad = getTime();
30                         })
31                 .bind( "pagebeforecreate", function() {
32                                 if ( ++lock === 1 ) {
33                                         stopLoad = startEnhance = stopEnhance = getTime();
34                                 }
35                         })
36                 .bind( "pageinit", function() {
37                                 if ( --lock === 0 ) {
38                                         stopEnhance = getTime();
39                                 }
40                         })
41                 .bind( "pagebeforeshow", function() {
42                                 startTransition = stopTransition = getTime();
43                         })
44                 .bind( "pageshow", function() {
45                                 stopTransition = getTime();
46                         })
47                 .bind( "pagechange", function( e, data ) {
48                                 if ( typeof data.toPage === "object" ) {
49                                         stopChange = getTime();
50
51                                         alert("load + processing: " + ( stopLoad - startLoad )
52                                                         + "\nenhance: " + ( stopEnhance - startEnhance )
53                                                         + "\ntransition: " + ( stopTransition - startTransition )
54                                                         + "\ntotalTime: " + ( stopChange - startChange ) );
55
56                                         startChange = stopChange = startLoad = stopLoad = startEnhance = stopEnhance = startTransition = stopTransition = 0;
57                                 }
58                         });
59
60
61 })( jQuery, window );