Revert "Export"
[framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.1.0 / js / jquery.mobile.core.js
1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: Base file for jQuery Mobile
3 //>>label: Core
4 //>>group: Core
5 //>>required: true
6 //>>css: ../css/structure/jquery.mobile.core.css
7
8 define( [ "jquery", "../external/requirejs/text!../version.txt", "./jquery.mobile.widget" ], function( $, __version__ ) {
9 //>>excludeEnd("jqmBuildExclude");
10 (function( $, window, undefined ) {
11
12         var nsNormalizeDict = {};
13
14         // jQuery.mobile configurable options
15         $.mobile = $.extend( {}, {
16
17                 // Version of the jQuery Mobile Framework
18                 version: __version__,
19
20                 // Namespace used framework-wide for data-attrs. Default is no namespace
21                 ns: "",
22
23                 // Define the url parameter used for referencing widget-generated sub-pages.
24                 // Translates to to example.html&ui-page=subpageIdentifier
25                 // hash segment before &ui-page= is used to make Ajax request
26                 subPageUrlKey: "ui-page",
27
28                 // Class assigned to page currently in view, and during transitions
29                 activePageClass: "ui-page-active",
30
31                 // Class used for "active" button state, from CSS framework
32                 activeBtnClass: "ui-btn-active",
33
34                 // Class used for "focus" form element state, from CSS framework
35                 focusClass: "ui-focus",
36
37                 // Automatically handle clicks and form submissions through Ajax, when same-domain
38                 ajaxEnabled: true,
39
40                 // Automatically load and show pages based on location.hash
41                 hashListeningEnabled: true,
42
43                 // disable to prevent jquery from bothering with links
44                 linkBindingEnabled: true,
45
46                 // Set default page transition - 'none' for no transitions
47                 defaultPageTransition: "fade",
48
49                 // Set maximum window width for transitions to apply - 'false' for no limit
50                 maxTransitionWidth: false,
51
52                 // Minimum scroll distance that will be remembered when returning to a page
53                 minScrollBack: 250,
54
55                 // DEPRECATED: the following property is no longer in use, but defined until 2.0 to prevent conflicts
56                 touchOverflowEnabled: false,
57
58                 // Set default dialog transition - 'none' for no transitions
59                 defaultDialogTransition: "pop",
60
61                 // Show loading message during Ajax requests
62                 // if false, message will not appear, but loading classes will still be toggled on html el
63                 loadingMessage: "loading",
64
65                 // Error response message - appears when an Ajax page request fails
66                 pageLoadErrorMessage: "Error Loading Page",
67
68                 // Should the text be visble in the loading message?
69                 loadingMessageTextVisible: false,
70
71                 // When the text is visible, what theme does the loading box use?
72                 loadingMessageTheme: "a",
73
74                 // For error messages, which theme does the box uses?
75                 pageLoadErrorMessageTheme: "e",
76
77                 //automatically initialize the DOM when it's ready
78                 autoInitializePage: true,
79
80                 pushStateEnabled: true,
81
82                 // allows users to opt in to ignoring content by marking a parent element as
83                 // data-ignored
84                 ignoreContentEnabled: false,
85
86                 // turn of binding to the native orientationchange due to android orientation behavior
87                 orientationChangeEnabled: true,
88
89                 buttonMarkup: {
90                         hoverDelay: 200
91                 },
92
93                 // TODO might be useful upstream in jquery itself ?
94                 keyCode: {
95                         ALT: 18,
96                         BACKSPACE: 8,
97                         CAPS_LOCK: 20,
98                         COMMA: 188,
99                         COMMAND: 91,
100                         COMMAND_LEFT: 91, // COMMAND
101                         COMMAND_RIGHT: 93,
102                         CONTROL: 17,
103                         DELETE: 46,
104                         DOWN: 40,
105                         END: 35,
106                         ENTER: 13,
107                         ESCAPE: 27,
108                         HOME: 36,
109                         INSERT: 45,
110                         LEFT: 37,
111                         MENU: 93, // COMMAND_RIGHT
112                         NUMPAD_ADD: 107,
113                         NUMPAD_DECIMAL: 110,
114                         NUMPAD_DIVIDE: 111,
115                         NUMPAD_ENTER: 108,
116                         NUMPAD_MULTIPLY: 106,
117                         NUMPAD_SUBTRACT: 109,
118                         PAGE_DOWN: 34,
119                         PAGE_UP: 33,
120                         PERIOD: 190,
121                         RIGHT: 39,
122                         SHIFT: 16,
123                         SPACE: 32,
124                         TAB: 9,
125                         UP: 38,
126                         WINDOWS: 91 // COMMAND
127                 },
128
129                 // Scroll page vertically: scroll to 0 to hide iOS address bar, or pass a Y value
130                 silentScroll: function( ypos ) {
131                         if ( $.type( ypos ) !== "number" ) {
132                                 ypos = $.mobile.defaultHomeScroll;
133                         }
134
135                         // prevent scrollstart and scrollstop events
136                         $.event.special.scrollstart.enabled = false;
137
138                         setTimeout(function() {
139                                 window.scrollTo( 0, ypos );
140                                 $( document ).trigger( "silentscroll", { x: 0, y: ypos });
141                         }, 20 );
142
143                         setTimeout(function() {
144                                 $.event.special.scrollstart.enabled = true;
145                         }, 150 );
146                 },
147
148                 // Expose our cache for testing purposes.
149                 nsNormalizeDict: nsNormalizeDict,
150
151                 // Take a data attribute property, prepend the namespace
152                 // and then camel case the attribute string. Add the result
153                 // to our nsNormalizeDict so we don't have to do this again.
154                 nsNormalize: function( prop ) {
155                         if ( !prop ) {
156                                 return;
157                         }
158
159                         return nsNormalizeDict[ prop ] || ( nsNormalizeDict[ prop ] = $.camelCase( $.mobile.ns + prop ) );
160                 },
161
162                 getInheritedTheme: function( el, defaultTheme ) {
163
164                         // Find the closest parent with a theme class on it. Note that
165                         // we are not using $.fn.closest() on purpose here because this
166                         // method gets called quite a bit and we need it to be as fast
167                         // as possible.
168
169                         var e = el[ 0 ],
170                                 ltr = "",
171                                 re = /ui-(bar|body|overlay)-([a-z])\b/,
172                                 c, m;
173
174                         while ( e ) {
175                                 var c = e.className || "";
176                                 if ( ( m = re.exec( c ) ) && ( ltr = m[ 2 ] ) ) {
177                                         // We found a parent with a theme class
178                                         // on it so bail from this loop.
179                                         break;
180                                 }
181                                 e = e.parentNode;
182                         }
183
184                         // Return the theme letter we found, if none, return the
185                         // specified default.
186
187                         return ltr || defaultTheme || "a";
188                 },
189
190                 // TODO the following $ and $.fn extensions can/probably should be moved into jquery.mobile.core.helpers
191                 //
192                 // Find the closest javascript page element to gather settings data jsperf test
193                 // http://jsperf.com/single-complex-selector-vs-many-complex-selectors/edit
194                 // possibly naive, but it shows that the parsing overhead for *just* the page selector vs
195                 // the page and dialog selector is negligable. This could probably be speed up by
196                 // doing a similar parent node traversal to the one found in the inherited theme code above
197                 closestPageData: function( $target ) {
198                         return $target
199                                 .closest(':jqmData(role="page"), :jqmData(role="dialog")')
200                                 .data("page");
201                 },
202
203                 enhanceable: function( $set ) {
204                         return this.haveParents( $set, "enhance" );
205                 },
206
207                 hijackable: function( $set ) {
208                         return this.haveParents( $set, "ajax" );
209                 },
210
211                 haveParents: function( $set, attr ) {
212                         if( !$.mobile.ignoreContentEnabled ){
213                                 return $set;
214                         }
215
216                         var count = $set.length,
217                                 $newSet = $(),
218                                 e, $element, excluded;
219
220                         for ( var i = 0; i < count; i++ ) {
221                                 $element = $set.eq( i );
222                                 excluded = false;
223                                 e = $set[ i ];
224
225                                 while ( e ) {
226                                         var c = e.getAttribute ? e.getAttribute( "data-" + $.mobile.ns + attr ) : "";
227
228                                         if ( c === "false" ) {
229                                                 excluded = true;
230                                                 break;
231                                         }
232
233                                         e = e.parentNode;
234                                 }
235
236                                 if ( !excluded ) {
237                                         $newSet = $newSet.add( $element );
238                                 }
239                         }
240
241                         return $newSet;
242                 }
243         }, $.mobile );
244
245         // Mobile version of data and removeData and hasData methods
246         // ensures all data is set and retrieved using jQuery Mobile's data namespace
247         $.fn.jqmData = function( prop, value ) {
248                 var result;
249                 if ( typeof prop != "undefined" ) {
250                         if ( prop ) {
251                                 prop = $.mobile.nsNormalize( prop );
252                         }
253                         result = this.data.apply( this, arguments.length < 2 ? [ prop ] : [ prop, value ] );
254                 }
255                 return result;
256         };
257
258         $.jqmData = function( elem, prop, value ) {
259                 var result;
260                 if ( typeof prop != "undefined" ) {
261                         result = $.data( elem, prop ? $.mobile.nsNormalize( prop ) : prop, value );
262                 }
263                 return result;
264         };
265
266         $.fn.jqmRemoveData = function( prop ) {
267                 return this.removeData( $.mobile.nsNormalize( prop ) );
268         };
269
270         $.jqmRemoveData = function( elem, prop ) {
271                 return $.removeData( elem, $.mobile.nsNormalize( prop ) );
272         };
273
274         $.fn.removeWithDependents = function() {
275                 $.removeWithDependents( this );
276         };
277
278         $.removeWithDependents = function( elem ) {
279                 var $elem = $( elem );
280
281                 ( $elem.jqmData('dependents') || $() ).remove();
282                 $elem.remove();
283         };
284
285         $.fn.addDependents = function( newDependents ) {
286                 $.addDependents( $(this), newDependents );
287         };
288
289         $.addDependents = function( elem, newDependents ) {
290                 var dependents = $(elem).jqmData( 'dependents' ) || $();
291
292                 $(elem).jqmData( 'dependents', $.merge(dependents, newDependents) );
293         };
294
295         // note that this helper doesn't attempt to handle the callback
296         // or setting of an html elements text, its only purpose is
297         // to return the html encoded version of the text in all cases. (thus the name)
298         $.fn.getEncodedText = function() {
299                 return $( "<div/>" ).text( $(this).text() ).html();
300         };
301
302         // fluent helper function for the mobile namespaced equivalent
303         $.fn.jqmEnhanceable = function() {
304                 return $.mobile.enhanceable( this );
305         };
306
307         $.fn.jqmHijackable = function() {
308                 return $.mobile.hijackable( this );
309         };
310
311         // Monkey-patching Sizzle to filter the :jqmData selector
312         var oldFind = $.find,
313                 jqmDataRE = /:jqmData\(([^)]*)\)/g;
314
315         $.find = function( selector, context, ret, extra ) {
316                 selector = selector.replace( jqmDataRE, "[data-" + ( $.mobile.ns || "" ) + "$1]" );
317
318                 return oldFind.call( this, selector, context, ret, extra );
319         };
320
321         $.extend( $.find, oldFind );
322
323         $.find.matches = function( expr, set ) {
324                 return $.find( expr, null, null, set );
325         };
326
327         $.find.matchesSelector = function( node, expr ) {
328                 return $.find( expr, null, null, [ node ] ).length > 0;
329         };
330 })( jQuery, this );
331 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
332 });
333 //>>excludeEnd("jqmBuildExclude");
334