Skip to content

Commit c7884ca

Browse files
committed
Core: Break up into data, defaults, and helpers modules
1 parent 95ead96 commit c7884ca

File tree

5 files changed

+209
-169
lines changed

5 files changed

+209
-169
lines changed

js/index.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
'events/throttledresize.js',
1919
'events/orientationchange.js',
2020
'jquery.hashchange.js',
21-
'jquery.mobile.core.js',
21+
'jquery.mobile.defaults.js',
22+
'jquery.mobile.helpers.js',
23+
'jquery.mobile.data.js',
2224
'jquery.mobile.registry.js',
2325
'widgets/page.js',
2426
'widgets/loader.js',

js/jquery.mobile.data.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2+
//>>description: Mobile versions of Data functions to allow for namespaceing
3+
//>>label: jqmData
4+
//>>group: Core
5+
//>>css.structure: ../css/structure/jquery.mobile.core.css
6+
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css
7+
8+
define( [ "jquery", "./jquery.mobile.ns", "json!../package.json" ], function( jQuery, ns, pkg, __version__ ) {
9+
//>>excludeEnd("jqmBuildExclude");
10+
(function( $, window, undefined ) {
11+
var nsNormalizeDict = {},
12+
// Monkey-patching Sizzle to filter the :jqmData selector
13+
oldFind = $.find,
14+
jqmDataRE = /:jqmData\(([^)]*)\)/g;
15+
16+
$.extend($.mobile, {
17+
18+
// Namespace used framework-wide for data-attrs. Default is no namespace
19+
20+
ns: "",
21+
22+
// Retrieve an attribute from an element and perform some massaging of the value
23+
24+
getAttribute: function( e, key, dns ) {
25+
var value;
26+
27+
if ( dns ) {
28+
key = "data-" + $.mobile.ns + key;
29+
}
30+
31+
value = e.getAttribute( key );
32+
33+
return value === "true" ? true :
34+
value === "false" ? false :
35+
value === null ? undefined : value;
36+
},
37+
38+
// Expose our cache for testing purposes.
39+
nsNormalizeDict: nsNormalizeDict,
40+
41+
// Take a data attribute property, prepend the namespace
42+
// and then camel case the attribute string. Add the result
43+
// to our nsNormalizeDict so we don't have to do this again.
44+
nsNormalize: function( prop ) {
45+
return nsNormalizeDict[ prop ] || ( nsNormalizeDict[ prop ] = $.camelCase( $.mobile.ns + prop ) );
46+
},
47+
48+
// Find the closest javascript page element to gather settings data jsperf test
49+
// http://jsperf.com/single-complex-selector-vs-many-complex-selectors/edit
50+
// possibly naive, but it shows that the parsing overhead for *just* the page selector vs
51+
// the page and dialog selector is negligable. This could probably be speed up by
52+
// doing a similar parent node traversal to the one found in the inherited theme code above
53+
closestPageData: function( $target ) {
54+
return $target
55+
.closest( ":jqmData(role='page'), :jqmData(role='dialog')" )
56+
.data( "mobile-page" );
57+
}
58+
59+
});
60+
// Mobile version of data and removeData and hasData methods
61+
// ensures all data is set and retrieved using jQuery Mobile's data namespace
62+
$.fn.jqmData = function( prop, value ) {
63+
var result;
64+
if ( typeof prop !== "undefined" ) {
65+
if ( prop ) {
66+
prop = $.mobile.nsNormalize( prop );
67+
}
68+
69+
// undefined is permitted as an explicit input for the second param
70+
// in this case it returns the value and does not set it to undefined
71+
if( arguments.length < 2 || value === undefined ){
72+
result = this.data( prop );
73+
} else {
74+
result = this.data( prop, value );
75+
}
76+
}
77+
return result;
78+
};
79+
80+
$.jqmData = function( elem, prop, value ) {
81+
var result;
82+
if ( typeof prop !== "undefined" ) {
83+
result = $.data( elem, prop ? $.mobile.nsNormalize( prop ) : prop, value );
84+
}
85+
return result;
86+
};
87+
88+
$.fn.jqmRemoveData = function( prop ) {
89+
return this.removeData( $.mobile.nsNormalize( prop ) );
90+
};
91+
92+
$.jqmRemoveData = function( elem, prop ) {
93+
return $.removeData( elem, $.mobile.nsNormalize( prop ) );
94+
};
95+
96+
97+
$.find = function( selector, context, ret, extra ) {
98+
selector = selector.replace( jqmDataRE, "[data-" + ( $.mobile.ns || "" ) + "$1]" );
99+
100+
return oldFind.call( this, selector, context, ret, extra );
101+
};
102+
103+
$.extend( $.find, oldFind );
104+
105+
})( jQuery, this );
106+
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
107+
});
108+
//>>excludeEnd("jqmBuildExclude");

js/jquery.mobile.defaults.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2+
//>>description: Default values for jQuery Mobile
3+
//>>label: Defaults
4+
//>>group: Core
5+
//>>css.structure: ../css/structure/jquery.mobile.core.css
6+
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css
7+
8+
define( [ "jquery", "./jquery.mobile.ns", "json!../package.json" ], function( jQuery, ns, pkg, __version__ ) {
9+
//>>excludeEnd("jqmBuildExclude");
10+
(function( $, window, undefined ) {
11+
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
12+
__version__ = ( pkg && pkg.version ) || "dev";
13+
//>>excludeEnd("jqmBuildExclude");
14+
$.extend($.mobile, {
15+
16+
// Version of the jQuery Mobile Framework
17+
version: __version__,
18+
19+
// Define the url parameter used for referencing widget-generated sub-pages.
20+
// Translates to to example.html&ui-page=subpageIdentifier
21+
// hash segment before &ui-page= is used to make Ajax request
22+
subPageUrlKey: "ui-page",
23+
24+
// Class assigned to page currently in view, and during transitions
25+
activePageClass: "ui-page-active",
26+
27+
// Class used for "active" button state, from CSS framework
28+
activeBtnClass: "ui-btn-active",
29+
30+
// Class used for "focus" form element state, from CSS framework
31+
focusClass: "ui-focus",
32+
33+
// Automatically handle clicks and form submissions through Ajax, when same-domain
34+
ajaxEnabled: true,
35+
36+
// Automatically load and show pages based on location.hash
37+
hashListeningEnabled: true,
38+
39+
// disable to prevent jquery from bothering with links
40+
linkBindingEnabled: true,
41+
42+
// Set default page transition - 'none' for no transitions
43+
defaultPageTransition: "fade",
44+
45+
// Set maximum window width for transitions to apply - 'false' for no limit
46+
maxTransitionWidth: false,
47+
48+
// Minimum scroll distance that will be remembered when returning to a page
49+
minScrollBack: 250,
50+
51+
// DEPRECATED: the following property is no longer in use, but defined until 2.0 to prevent conflicts
52+
touchOverflowEnabled: false,
53+
54+
// Set default dialog transition - 'none' for no transitions
55+
defaultDialogTransition: "pop",
56+
57+
// Error response message - appears when an Ajax page request fails
58+
pageLoadErrorMessage: "Error Loading Page",
59+
60+
// For error messages, which theme does the box uses?
61+
pageLoadErrorMessageTheme: "e",
62+
63+
// replace calls to window.history.back with phonegaps navigation helper
64+
// where it is provided on the window object
65+
phonegapNavigationEnabled: false,
66+
67+
//automatically initialize the DOM when it's ready
68+
autoInitializePage: true,
69+
70+
pushStateEnabled: true,
71+
72+
// allows users to opt in to ignoring content by marking a parent element as
73+
// data-ignored
74+
ignoreContentEnabled: false,
75+
76+
buttonMarkup: {
77+
hoverDelay: 200
78+
},
79+
80+
// disable the alteration of the dynamic base tag or links in the case
81+
// that a dynamic base tag isn't supported
82+
dynamicBaseEnabled: true,
83+
84+
// default the property to remove dependency on assignment in init module
85+
pageContainer: $()
86+
});
87+
})( jQuery, this );
88+
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
89+
});
90+
//>>excludeEnd("jqmBuildExclude");

0 commit comments

Comments
 (0)