upload tizen1.0 source
[framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.0.1pre / js / jquery.mobile.init.js
1 /*
2 * "init" - Initialize the framework
3 */
4
5 (function( $, window, undefined ) {
6         var     $html = $( "html" ),
7                         $head = $( "head" ),
8                         $window = $( window );
9
10         // trigger mobileinit event - useful hook for configuring $.mobile settings before they're used
11         $( window.document ).trigger( "mobileinit" );
12
13         // support conditions
14         // if device support condition(s) aren't met, leave things as they are -> a basic, usable experience,
15         // otherwise, proceed with the enhancements
16         if ( !$.mobile.gradeA() ) {
17                 return;
18         }
19
20         // override ajaxEnabled on platforms that have known conflicts with hash history updates
21         // or generally work better browsing in regular http for full page refreshes (BB5, Opera Mini)
22         if ( $.mobile.ajaxBlacklist ) {
23                 $.mobile.ajaxEnabled = false;
24         }
25
26         // add mobile, initial load "rendering" classes to docEl
27         $html.addClass( "ui-mobile ui-mobile-rendering" );
28
29         // loading div which appears during Ajax requests
30         // will not appear if $.mobile.loadingMessage is false
31         var $loader = $( "<div class='ui-loader ui-body-a ui-corner-all'><span class='ui-icon ui-icon-loading spin'></span><h1></h1></div>" );
32
33         $.extend($.mobile, {
34                 // turn on/off page loading message.
35                 showPageLoadingMsg: function() {
36                         if ( $.mobile.loadingMessage ) {
37                                 var activeBtn = $( "." + $.mobile.activeBtnClass ).first();
38
39                                 $loader
40                                         .find( "h1" )
41                                                 .text( $.mobile.loadingMessage )
42                                                 .end()
43                                         .appendTo( $.mobile.pageContainer )
44                                         // position at y center (if scrollTop supported), above the activeBtn (if defined), or just 100px from top
45                                         .css({
46                                                 top: $.support.scrollTop && $window.scrollTop() + $window.height() / 2 ||
47                                                 activeBtn.length && activeBtn.offset().top || 100
48                                         });
49                         }
50
51                         $html.addClass( "ui-loading" );
52                 },
53
54                 hidePageLoadingMsg: function() {
55                         $html.removeClass( "ui-loading" );
56                 },
57
58                 // find and enhance the pages in the dom and transition to the first page.
59                 initializePage: function() {
60                         // find present pages
61                         var $pages = $( ":jqmData(role='page')" );
62
63                         // if no pages are found, create one with body's inner html
64                         if ( !$pages.length ) {
65                                 $pages = $( "body" ).wrapInner( "<div data-" + $.mobile.ns + "role='page'></div>" ).children( 0 );
66                         }
67
68                         // add dialogs, set data-url attrs
69                         $pages.add( ":jqmData(role='dialog')" ).each(function() {
70                                 var $this = $(this);
71
72                                 // unless the data url is already set set it to the pathname
73                                 if ( !$this.jqmData("url") ) {
74                                         $this.attr( "data-" + $.mobile.ns + "url", $this.attr( "id" ) || location.pathname + location.search );
75                                 }
76                         });
77
78                         // define first page in dom case one backs out to the directory root (not always the first page visited, but defined as fallback)
79                         $.mobile.firstPage = $pages.first();
80
81                         // define page container
82                         $.mobile.pageContainer = $pages.first().parent().addClass( "ui-mobile-viewport" );
83
84                         // alert listeners that the pagecontainer has been determined for binding
85                         // to events triggered on it
86                         $window.trigger( "pagecontainercreate" );
87
88                         // cue page loading message
89                         $.mobile.showPageLoadingMsg();
90
91                         // if hashchange listening is disabled or there's no hash deeplink, change to the first page in the DOM
92                         if ( !$.mobile.hashListeningEnabled || !$.mobile.path.stripHash( location.hash ) ) {
93                                 $.mobile.changePage( $.mobile.firstPage, { transition: "none", reverse: true, changeHash: false, fromHashChange: true } );
94                         }
95                         // otherwise, trigger a hashchange to load a deeplink
96                         else {
97                                 $window.trigger( "hashchange", [ true ] );
98                         }
99                 }
100         });
101         
102         // This function injects a meta viewport tag to prevent scaling. Off by default, on by default when touchOverflow scrolling is enabled
103         function disableZoom() {
104                 var cont = "user-scalable=no",
105                         meta = $( "meta[name='viewport']" );
106                         
107                 if( meta.length ){
108                         meta.attr( "content", meta.attr( "content" ) + ", " + cont );
109                 }
110                 else{
111                         $( "head" ).prepend( "<meta>", { "name": "viewport", "content": cont } );
112                 }
113         }
114         
115         // if touch-overflow is enabled, disable user scaling, as it creates usability issues
116         if( $.support.touchOverflow && $.mobile.touchOverflowEnabled && !$.mobile.touchOverflowZoomEnabled ){
117                 disableZoom();
118         }
119
120         // initialize events now, after mobileinit has occurred
121         $.mobile._registerInternalEvents();
122
123         // check which scrollTop value should be used by scrolling to 1 immediately at domready
124         // then check what the scroll top is. Android will report 0... others 1
125         // note that this initial scroll won't hide the address bar. It's just for the check.
126         $(function() {
127                 window.scrollTo( 0, 1 );
128
129                 // if defaultHomeScroll hasn't been set yet, see if scrollTop is 1
130                 // it should be 1 in most browsers, but android treats 1 as 0 (for hiding addr bar)
131                 // so if it's 1, use 0 from now on
132                 $.mobile.defaultHomeScroll = ( !$.support.scrollTop || $(window).scrollTop() === 1 ) ? 0 : 1;
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 })( jQuery, this );