Created
November 8, 2012 05:55
-
-
Save jrburke/4037081 to your computer and use it in GitHub Desktop.
RequireJS jQuery adapter approach
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Set up the adapter config, so that any module asking | |
//for jquery gets an adapter module that has modified | |
//jquery before other modules can use it. | |
//Needs RequireJS 2.0+ to work correctly | |
//More info on map config: | |
//http://requirejs.org/docs/api.html#config-map | |
requirejs.config({ | |
map: { | |
'*': { | |
'jquery': 'jquery.adapter' | |
}, | |
'jquery.adapter': { | |
'jquery': 'jquery' | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(['jquery'], function ($) { | |
//Modify jQuery here. | |
//If you wanted, this module can | |
//also list some jquery plugins to have them already | |
//attached to the jquery object. However, if you do | |
//that, then you need to set up the requirejs config | |
//to either specify a map config for those plugins so | |
//that they get the real jquery, or use shim config that | |
//specifies 'jquery.adapter' as a dependency instead of 'jquery', | |
//if the jquery plugins do not call define() themselves. | |
//Return jQuery to set this module value; | |
return $; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you can use the same pattern to avoid exposing globals:
been doing it on almost all projects.