191297d283fcb1d23095697962c254c24cfc902c
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.0.1pre / js / jquery.mobile.core.js
1 /* 
2 * "core" - The base file for jQm
3 */
4
5 (function( $, window, undefined ) {
6
7         var nsNormalizeDict = {};
8
9         // jQuery.mobile configurable options
10         $.extend( $.mobile, {
11
12                 // Namespace used framework-wide for data-attrs. Default is no namespace
13                 ns: "",
14
15                 // Define the url parameter used for referencing widget-generated sub-pages.
16                 // Translates to to example.html&ui-page=subpageIdentifier
17                 // hash segment before &ui-page= is used to make Ajax request
18                 subPageUrlKey: "ui-page",
19
20                 // Class assigned to page currently in view, and during transitions
21                 activePageClass: "ui-page-active",
22
23                 // Class used for "active" button state, from CSS framework
24                 activeBtnClass: "ui-btn-active",
25
26                 // Automatically handle clicks and form submissions through Ajax, when same-domain
27                 ajaxEnabled: true,
28
29                 // Automatically load and show pages based on location.hash
30                 hashListeningEnabled: true,
31
32                 // disable to prevent jquery from bothering with links
33                 linkBindingEnabled: true,
34
35                 // Set default page transition - 'none' for no transitions
36                 defaultPageTransition: "slide",
37
38                 // Minimum scroll distance that will be remembered when returning to a page
39                 minScrollBack: 250,
40
41                 // Set default dialog transition - 'none' for no transitions
42                 defaultDialogTransition: "pop",
43
44                 // Show loading message during Ajax requests
45                 // if false, message will not appear, but loading classes will still be toggled on html el
46                 loadingMessage: "loading",
47
48                 // Error response message - appears when an Ajax page request fails
49                 pageLoadErrorMessage: "Error Loading Page",
50
51                 //automatically initialize the DOM when it's ready
52                 autoInitializePage: true,
53
54                 pushStateEnabled: true,
55
56                 // turn of binding to the native orientationchange due to android orientation behavior
57                 orientationChangeEnabled: true,
58
59                 // Support conditions that must be met in order to proceed
60                 // default enhanced qualifications are media query support OR IE 7+
61                 gradeA: function(){
62                         return $.support.mediaquery || $.mobile.browser.ie && $.mobile.browser.ie >= 7;
63                 },
64
65                 // TODO might be useful upstream in jquery itself ?
66                 keyCode: {
67                         ALT: 18,
68                         BACKSPACE: 8,
69                         CAPS_LOCK: 20,
70                         COMMA: 188,
71                         COMMAND: 91,
72                         COMMAND_LEFT: 91, // COMMAND
73                         COMMAND_RIGHT: 93,
74                         CONTROL: 17,
75                         DELETE: 46,
76                         DOWN: 40,
77                         END: 35,
78                         ENTER: 13,
79                         ESCAPE: 27,
80                         HOME: 36,
81                         INSERT: 45,
82                         LEFT: 37,
83                         MENU: 93, // COMMAND_RIGHT
84                         NUMPAD_ADD: 107,
85                         NUMPAD_DECIMAL: 110,
86                         NUMPAD_DIVIDE: 111,
87                         NUMPAD_ENTER: 108,
88                         NUMPAD_MULTIPLY: 106,
89                         NUMPAD_SUBTRACT: 109,
90                         PAGE_DOWN: 34,
91                         PAGE_UP: 33,
92                         PERIOD: 190,
93                         RIGHT: 39,
94                         SHIFT: 16,
95                         SPACE: 32,
96                         TAB: 9,
97                         UP: 38,
98                         WINDOWS: 91 // COMMAND
99                 },
100
101                 // Scroll page vertically: scroll to 0 to hide iOS address bar, or pass a Y value
102                 silentScroll: function( ypos ) {
103                         if ( $.type( ypos ) !== "number" ) {
104                                 ypos = $.mobile.defaultHomeScroll;
105                         }
106
107                         // prevent scrollstart and scrollstop events
108                         $.event.special.scrollstart.enabled = false;
109
110                         setTimeout(function() {
111                                 window.scrollTo( 0, ypos );
112                                 $( document ).trigger( "silentscroll", { x: 0, y: ypos });
113                         }, 20 );
114
115                         setTimeout(function() {
116                                 $.event.special.scrollstart.enabled = true;
117                         }, 150 );
118                 },
119
120                 // Expose our cache for testing purposes.
121                 nsNormalizeDict: nsNormalizeDict,
122
123                 // Take a data attribute property, prepend the namespace
124                 // and then camel case the attribute string. Add the result
125                 // to our nsNormalizeDict so we don't have to do this again.
126                 nsNormalize: function( prop ) {
127                         if ( !prop ) {
128                                 return;
129                         }
130
131                         return nsNormalizeDict[ prop ] || ( nsNormalizeDict[ prop ] = $.camelCase( $.mobile.ns + prop ) );
132                 },
133
134                 getInheritedTheme: function( el, defaultTheme ) {
135
136                         // Find the closest parent with a theme class on it. Note that
137                         // we are not using $.fn.closest() on purpose here because this
138                         // method gets called quite a bit and we need it to be as fast
139                         // as possible.
140
141                         var e = el[ 0 ],
142                                 ltr = "",
143                                 re = /ui-(bar|body)-([a-z])\b/,
144                                 c, m;
145
146                         while ( e ) {
147                                 var c = e.className || "";
148                                 if ( ( m = re.exec( c ) ) && ( ltr = m[ 2 ] ) ) {
149                                         // We found a parent with a theme class
150                                         // on it so bail from this loop.
151                                         break;
152                                 }
153                                 e = e.parentNode;
154                         }
155                         
156                         // Return the theme letter we found, if none, return the
157                         // specified default.
158
159                         return ltr || defaultTheme || "a";
160                 }
161         });
162
163         // Mobile version of data and removeData and hasData methods
164         // ensures all data is set and retrieved using jQuery Mobile's data namespace
165         $.fn.jqmData = function( prop, value ) {
166                 var result;
167                 if ( typeof prop != "undefined" ) {
168                         result = this.data( prop ? $.mobile.nsNormalize( prop ) : prop, value );
169                 }
170                 return result;
171         };
172
173         $.jqmData = function( elem, prop, value ) {
174                 var result;
175                 if ( typeof prop != "undefined" ) {
176                         result = $.data( elem, prop ? $.mobile.nsNormalize( prop ) : prop, value );
177                 }
178                 return result;
179         };
180
181         $.fn.jqmRemoveData = function( prop ) {
182                 return this.removeData( $.mobile.nsNormalize( prop ) );
183         };
184
185         $.jqmRemoveData = function( elem, prop ) {
186                 return $.removeData( elem, $.mobile.nsNormalize( prop ) );
187         };
188
189         $.fn.removeWithDependents = function() {
190                 $.removeWithDependents( this );
191         };
192
193         $.removeWithDependents = function( elem ) {
194                 var $elem = $( elem );
195
196                 ( $elem.jqmData('dependents') || $() ).remove();
197                 $elem.remove();
198         };
199
200         $.fn.addDependents = function( newDependents ) {
201                 $.addDependents( $(this), newDependents );
202         };
203
204         $.addDependents = function( elem, newDependents ) {
205                 var dependents = $(elem).jqmData( 'dependents' ) || $();
206
207                 $(elem).jqmData( 'dependents', $.merge(dependents, newDependents) );
208         };
209
210         // note that this helper doesn't attempt to handle the callback
211         // or setting of an html elements text, its only purpose is
212         // to return the html encoded version of the text in all cases. (thus the name)
213         $.fn.getEncodedText = function() {
214                 return $( "<div/>" ).text( $(this).text() ).html();
215         };
216
217         // Monkey-patching Sizzle to filter the :jqmData selector
218         var oldFind = $.find,
219                 jqmDataRE = /:jqmData\(([^)]*)\)/g;
220
221         $.find = function( selector, context, ret, extra ) {
222                 selector = selector.replace( jqmDataRE, "[data-" + ( $.mobile.ns || "" ) + "$1]" );
223
224                 return oldFind.call( this, selector, context, ret, extra );
225         };
226
227         $.extend( $.find, oldFind );
228
229         $.find.matches = function( expr, set ) {
230                 return $.find( expr, null, null, set );
231         };
232
233         $.find.matchesSelector = function( node, expr ) {
234                 return $.find( expr, null, null, [ node ] ).length > 0;
235         };
236 })( jQuery, this );
237