Skip to content

Instantly share code, notes, and snippets.

@kechol
Last active December 11, 2015 17:28
Show Gist options
  • Select an option

  • Save kechol/4634253 to your computer and use it in GitHub Desktop.

Select an option

Save kechol/4634253 to your computer and use it in GitHub Desktop.
use jQuery and jQuery Mobile with RequireJS. NOTES: * do NOT use require-jquery.js * use shim config * load jquerymobile at last * do NOT add jquerymobile to deps array in scripts
define(['jquery'], function($) { // do NOT add jquerymobile in deps array.
$(document).on("pageinit", "#alpha", function() { // #alpha => the id attr of div[data-role="page"]
// your scripts...
});
});
({
// no minification, is done by the min task
//optimize: 'none',
baseUrl: 'scripts',
appDir: "../",
name: "main",
out: 'scripts/main.js'
paths: {
"jquery": "vendor/jquery.min",
"jquerymobile": "vendor/jquerymobile.min",
"jquery.validate": "vendor/jquery.validate.min",
"underscore": "vendor/lodash.min",
},
shim: {
'underscore': { exports: "_" },
'jquery': { exports: "$" },
'jquery.validate': ['jquery'],
'jquerymobile': ['jquery', 'mobileinit']
}
})
require.config( {
paths: {
"jquery": "vendor/jquery.min",
"jquerymobile": "vendor/jquerymobile.min",
"jquery.validate": "vendor/jquery.validate.min",
"underscore": "vendor/lodash.min"
},
shim: {
'underscore': { exports: "_" },
'jquery': { exports: "$" },
'jquery.validate': ['jquery'],
'jquerymobile': ['jquery', 'mobileinit']
}
});
// Includes File Dependencies
require([
// libraries
"jquery",
"underscore",
"jquery.validate",
// other files
"alpha",
"beta",
"jquerymobile" // load last
]);
define(['jquery'], function($) {
$(document).on("mobileinit", function() {
//jqm configuration
//$.mobile.ajaxEnabled = false;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment