[TemporaryStorage] add files required for SDK build
[samples/web/TemporaryStorage.git] / tizen-web-ui-fw / latest / js / src / jquery.mobile.init.js
1 (function( $, window, undefined ) {
2         var     $html = $( "html" ),
3                         $head = $( "head" ),
4                         $window = $.mobile.$window;
5
6         //remove initial build class (only present on first pageshow)
7         function hideRenderingClass() {
8                 $html.removeClass( "ui-mobile-rendering" );
9         }
10
11         // trigger mobileinit event - useful hook for configuring $.mobile settings before they're used
12         $( window.document ).trigger( "mobileinit" );
13
14         // support conditions
15         // if device support condition(s) aren't met, leave things as they are -> a basic, usable experience,
16         // otherwise, proceed with the enhancements
17         if ( !$.mobile.gradeA() ) {
18                 return;
19         }
20
21         // override ajaxEnabled on platforms that have known conflicts with hash history updates
22         // or generally work better browsing in regular http for full page refreshes (BB5, Opera Mini)
23         if ( $.mobile.ajaxBlacklist ) {
24                 $.mobile.ajaxEnabled = false;
25         }
26
27         // Add mobile, initial load "rendering" classes to docEl
28         $html.addClass( "ui-mobile ui-mobile-rendering" );
29
30         // This is a fallback. If anything goes wrong (JS errors, etc), or events don't fire,
31         // this ensures the rendering class is removed after 5 seconds, so content is visible and accessible
32         setTimeout( hideRenderingClass, 5000 );
33
34         $.extend( $.mobile, {
35                 addEventBlocker: function () {
36                         $html.addClass( "ui-blocker" );
37                         $html.bind( "touchstart touchend vclick mousedown mouseup click", function () {
38                                 return false;
39                         } );
40                 },
41
42                 removeEventBlocker: function () {
43                         $html.removeClass( "ui-blocker" );
44                         $html.unbind( "touchstart touchend vclick mousedown mouseup click" );
45                 },
46
47                 // find and enhance the pages in the dom and transition to the first page.
48                 initializePage: function() {
49                         // find present pages
50                         var $pages = $( ":jqmData(role='page'), :jqmData(role='dialog')" ),
51                                 hash = $.mobile.path.parseLocation().hash.replace("#", ""),
52                                 hashPage = document.getElementById( hash );
53
54                         // if no pages are found, create one with body's inner html
55                         if ( !$pages.length ) {
56                                 $pages = $( "body" ).wrapInner( "<div data-" + $.mobile.ns + "role='page'></div>" ).children( 0 );
57                         }
58
59                         // add dialogs, set data-url attrs
60                         $pages.each(function() {
61                                 var $this = $( this );
62
63                                 // unless the data url is already set set it to the pathname
64                                 if ( !$this[0].getAttribute( "data-" + $.mobile.ns + "url" ) ) {
65                                         $this.attr( "data-" + $.mobile.ns + "url", $this.attr( "id" ) || location.pathname + location.search );
66                                 }
67                         });
68
69                         // define first page in dom case one backs out to the directory root (not always the first page visited, but defined as fallback)
70                         $.mobile.firstPage = $pages.first();
71
72                         // define page container
73                         $.mobile.pageContainer = $.mobile.firstPage.parent().addClass( "ui-mobile-viewport" );
74
75                         // alert listeners that the pagecontainer has been determined for binding
76                         // to events triggered on it
77                         $window.trigger( "pagecontainercreate" );
78
79                         // cue page loading message
80                         $.mobile.showPageLoadingMsg();
81                         $.mobile.addEventBlocker();
82
83                         //remove initial build class (only present on first pageshow)
84                         hideRenderingClass();
85
86                         // if hashchange listening is disabled, there's no hash deeplink,
87                         // the hash is not valid (contains more than one # or does not start with #)
88                         // or there is no page with that hash, change to the first page in the DOM
89                         // Remember, however, that the hash can also be a path!
90                         if ( ! ( $.mobile.hashListeningEnabled &&
91                                 $.mobile.path.isHashValid( location.hash ) &&
92                                 ( $( hashPage ).is( ':jqmData(role="page")' ) ||
93                                         $.mobile.path.isPath( hash ) ||
94                                         hash === $.mobile.dialogHashKey ) ) ) {
95
96                                 // Store the initial destination
97                                 if ( $.mobile.path.isHashValid( location.hash ) ) {
98                                         $.mobile.urlHistory.initialDst = hash.replace( "#", "" );
99                                 }
100                                 $.mobile.changePage( $.mobile.firstPage, { transition: "none", reverse: true, changeHash: false, fromHashChange: true } );
101                         }
102                         // otherwise, trigger a hashchange to load a deeplink
103                         else {
104                                 $window.trigger( "hashchange", [ true ] );
105                         }
106                 }
107         });
108
109         // initialize events now, after mobileinit has occurred
110         $.mobile.navreadyDeferred.resolve();
111
112         // check which scrollTop value should be used by scrolling to 1 immediately at domready
113         // then check what the scroll top is. Android will report 0... others 1
114         // note that this initial scroll won't hide the address bar. It's just for the check.
115         $(function() {
116                 window.scrollTo( 0, 1 );
117
118                 // if defaultHomeScroll hasn't been set yet, see if scrollTop is 1
119                 // it should be 1 in most browsers, but android treats 1 as 0 (for hiding addr bar)
120                 // so if it's 1, use 0 from now on
121                 $.mobile.defaultHomeScroll = ( !$.support.scrollTop || $.mobile.$window.scrollTop() === 1 ) ? 0 : 1;
122
123
124                 // TODO: Implement a proper registration mechanism with dependency handling in order to not have exceptions like the one below
125                 //auto self-init widgets for those widgets that have a soft dependency on others
126                 if ( $.fn.controlgroup ) {
127                         $.mobile.$document.bind( "pagecreate create", function( e ) {
128                                 $( ":jqmData(role='controlgroup')", e.target )
129                                         .jqmEnhanceable()
130                                         .controlgroup({ excludeInvisible: false });
131                         });
132                 }
133
134                 //dom-ready inits
135                 if ( $.mobile.autoInitializePage ) {
136                         $.mobile.initializePage();
137                 }
138
139                 // window load event
140                 // hide iOS browser chrome on load
141                 $window.load( $.mobile.silentScroll );
142
143                 if ( !$.support.cssPointerEvents ) {
144                         // IE and Opera don't support CSS pointer-events: none that we use to disable link-based buttons
145                         // by adding the 'ui-disabled' class to them. Using a JavaScript workaround for those browser.
146                         // https://github.com/jquery/jquery-mobile/issues/3558
147
148                         $.mobile.$document.delegate( ".ui-disabled", "vclick",
149                                 function( e ) {
150                                         e.preventDefault();
151                                         e.stopImmediatePropagation();
152                                 }
153                         );
154                 }
155         });
156 }( jQuery, this ));