Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
Core: Break up into data, defaults, and helpers modules
Browse files Browse the repository at this point in the history
  • Loading branch information
arschmitz committed Jun 21, 2013
1 parent 95ead96 commit c7884ca
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 169 deletions.
4 changes: 3 additions & 1 deletion js/index.php
Expand Up @@ -18,7 +18,9 @@
'events/throttledresize.js',
'events/orientationchange.js',
'jquery.hashchange.js',
'jquery.mobile.core.js',
'jquery.mobile.defaults.js',
'jquery.mobile.helpers.js',
'jquery.mobile.data.js',
'jquery.mobile.registry.js',
'widgets/page.js',
'widgets/loader.js',
Expand Down
108 changes: 108 additions & 0 deletions js/jquery.mobile.data.js
@@ -0,0 +1,108 @@
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
//>>description: Mobile versions of Data functions to allow for namespaceing
//>>label: jqmData
//>>group: Core
//>>css.structure: ../css/structure/jquery.mobile.core.css
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css

define( [ "jquery", "./jquery.mobile.ns", "json!../package.json" ], function( jQuery, ns, pkg, __version__ ) {
//>>excludeEnd("jqmBuildExclude");
(function( $, window, undefined ) {
var nsNormalizeDict = {},
// Monkey-patching Sizzle to filter the :jqmData selector
oldFind = $.find,
jqmDataRE = /:jqmData\(([^)]*)\)/g;

$.extend($.mobile, {

// Namespace used framework-wide for data-attrs. Default is no namespace

ns: "",

// Retrieve an attribute from an element and perform some massaging of the value

getAttribute: function( e, key, dns ) {
var value;

if ( dns ) {
key = "data-" + $.mobile.ns + key;
}

value = e.getAttribute( key );

return value === "true" ? true :
value === "false" ? false :
value === null ? undefined : value;
},

// Expose our cache for testing purposes.
nsNormalizeDict: nsNormalizeDict,

// Take a data attribute property, prepend the namespace
// and then camel case the attribute string. Add the result
// to our nsNormalizeDict so we don't have to do this again.
nsNormalize: function( prop ) {
return nsNormalizeDict[ prop ] || ( nsNormalizeDict[ prop ] = $.camelCase( $.mobile.ns + prop ) );
},

// Find the closest javascript page element to gather settings data jsperf test
// http://jsperf.com/single-complex-selector-vs-many-complex-selectors/edit
// possibly naive, but it shows that the parsing overhead for *just* the page selector vs
// the page and dialog selector is negligable. This could probably be speed up by
// doing a similar parent node traversal to the one found in the inherited theme code above
closestPageData: function( $target ) {
return $target
.closest( ":jqmData(role='page'), :jqmData(role='dialog')" )
.data( "mobile-page" );
}

});
// Mobile version of data and removeData and hasData methods
// ensures all data is set and retrieved using jQuery Mobile's data namespace
$.fn.jqmData = function( prop, value ) {
var result;
if ( typeof prop !== "undefined" ) {
if ( prop ) {
prop = $.mobile.nsNormalize( prop );
}

// undefined is permitted as an explicit input for the second param
// in this case it returns the value and does not set it to undefined
if( arguments.length < 2 || value === undefined ){
result = this.data( prop );
} else {
result = this.data( prop, value );
}
}
return result;
};

$.jqmData = function( elem, prop, value ) {
var result;
if ( typeof prop !== "undefined" ) {
result = $.data( elem, prop ? $.mobile.nsNormalize( prop ) : prop, value );
}
return result;
};

$.fn.jqmRemoveData = function( prop ) {
return this.removeData( $.mobile.nsNormalize( prop ) );
};

$.jqmRemoveData = function( elem, prop ) {
return $.removeData( elem, $.mobile.nsNormalize( prop ) );
};


$.find = function( selector, context, ret, extra ) {
selector = selector.replace( jqmDataRE, "[data-" + ( $.mobile.ns || "" ) + "$1]" );

return oldFind.call( this, selector, context, ret, extra );
};

$.extend( $.find, oldFind );

})( jQuery, this );
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
});
//>>excludeEnd("jqmBuildExclude");
90 changes: 90 additions & 0 deletions js/jquery.mobile.defaults.js
@@ -0,0 +1,90 @@
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
//>>description: Default values for jQuery Mobile
//>>label: Defaults
//>>group: Core
//>>css.structure: ../css/structure/jquery.mobile.core.css
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css

define( [ "jquery", "./jquery.mobile.ns", "json!../package.json" ], function( jQuery, ns, pkg, __version__ ) {
//>>excludeEnd("jqmBuildExclude");
(function( $, window, undefined ) {
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
__version__ = ( pkg && pkg.version ) || "dev";
//>>excludeEnd("jqmBuildExclude");
$.extend($.mobile, {

// Version of the jQuery Mobile Framework
version: __version__,

// Define the url parameter used for referencing widget-generated sub-pages.
// Translates to to example.html&ui-page=subpageIdentifier
// hash segment before &ui-page= is used to make Ajax request
subPageUrlKey: "ui-page",

// Class assigned to page currently in view, and during transitions
activePageClass: "ui-page-active",

// Class used for "active" button state, from CSS framework
activeBtnClass: "ui-btn-active",

// Class used for "focus" form element state, from CSS framework
focusClass: "ui-focus",

// Automatically handle clicks and form submissions through Ajax, when same-domain
ajaxEnabled: true,

// Automatically load and show pages based on location.hash
hashListeningEnabled: true,

// disable to prevent jquery from bothering with links
linkBindingEnabled: true,

// Set default page transition - 'none' for no transitions
defaultPageTransition: "fade",

// Set maximum window width for transitions to apply - 'false' for no limit
maxTransitionWidth: false,

// Minimum scroll distance that will be remembered when returning to a page
minScrollBack: 250,

// DEPRECATED: the following property is no longer in use, but defined until 2.0 to prevent conflicts
touchOverflowEnabled: false,

// Set default dialog transition - 'none' for no transitions
defaultDialogTransition: "pop",

// Error response message - appears when an Ajax page request fails
pageLoadErrorMessage: "Error Loading Page",

// For error messages, which theme does the box uses?
pageLoadErrorMessageTheme: "e",

// replace calls to window.history.back with phonegaps navigation helper
// where it is provided on the window object
phonegapNavigationEnabled: false,

//automatically initialize the DOM when it's ready
autoInitializePage: true,

pushStateEnabled: true,

// allows users to opt in to ignoring content by marking a parent element as
// data-ignored
ignoreContentEnabled: false,

buttonMarkup: {
hoverDelay: 200
},

// disable the alteration of the dynamic base tag or links in the case
// that a dynamic base tag isn't supported
dynamicBaseEnabled: true,

// default the property to remove dependency on assignment in init module
pageContainer: $()
});
})( jQuery, this );
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
});
//>>excludeEnd("jqmBuildExclude");

0 comments on commit c7884ca

Please sign in to comment.