Permalink
Browse files

Added wrapper to export as an AMD modules

removed jquery.mobile.exports
  • Loading branch information...
1 parent caca24a commit 5b8f2be9d22131a3eceeb20d012402c1aba6121c @gseguin gseguin committed Jan 13, 2012
Showing with 17 additions and 8 deletions.
  1. +3 −1 Makefile
  2. +2 −0 build/wrap.end
  3. +12 −0 build/wrap.start
  4. +0 −7 js/jquery.mobile.exports.js
View
@@ -117,9 +117,11 @@ js: init
-classpath build/js.jar:build/google-compiler-20111003.jar org.mozilla.javascript.tools.shell.Main \
external/r.js/dist/r.js \
-o baseUrl="js" \
- include=jquery.mobile,jquery.mobile.exports exclude=jquery,order \
+ include=jquery.mobile exclude=jquery,order \
out=${OUTPUT}/${NAME}.compiled.js \
pragmasOnSave.jqmBuildExclude=true \
+ wrap.start=build/wrap.start \
+ wrap.end=build/wrap.end \
findNestedDependencies=true \
skipModuleInsertion=true \
optimize=none
View
@@ -0,0 +1,2 @@
+
+}));
View
@@ -0,0 +1,12 @@
+(function ( root, doc, factory ) {
+ if ( typeof define === "function" && define.amd ) {
@cjolif

cjolif May 11, 2012

jQuery itself initializes AMD only on

if ( typeof define === "function" && define.amd && define.amd.jQuery ) {

I think the exact same test must be used here otherwise jQuery Mobile might try to use AMD while jQuery itself did not initialize with AMD.

@gseguin

gseguin May 11, 2012

Member

That would be a question for @jrburke

@jrburke

jrburke May 14, 2012

Contributor

That define.amd.jQuery check is explained in this amdjs wiki page. It was done to be cautious with rolling out AMD registration since jQuery is used on many pages, and there are use cases where two different versions are included on the page.

The jQuery mobile case is a bit different though -- it is a higher level library, even a framework, where it only makes sense to have one version of it on a page (AFAIK, if not, please let me know).

I am hopeful that over time that define.amd.jQuery check can be removed from jQuery, so I am reluctant to suggest its use here, particularly given that it should only show up once on a page.

The use case where I think it may fail is in an AMD loader that does not set that flag, but this library is used. It is hard for me to see that use case though, why would a page use and AMD loader that would not get the jQuery exports but sill use jQuery Mobile? Let's explore that a bit more, @cjolif, if you have seen a case where that happens, describing it will help.

@cjolif

cjolif May 15, 2012

@jrburke my use-case is an application using dojox/app application framework with jQuery mobile views. It is relying on Dojo loader that does not define define.amd.jQuery.

@jrburke

jrburke May 15, 2012

Contributor

@cjolif: How is jQuery used/referenced in that app? If there is a pointer to the app, feel free to let me know, curious how those things interact.

@cjolif

cjolif May 16, 2012

@jrburke well to be honest for now this is just a demo app not a real one. You can checkout the jquery code in that app here: https://github.com/cjolif/dojo-todo-app/blob/jquery/views/details/repeat.js. That is the only piece that is jquery (with the corresponding .html) in the middle of the Dojo application.

+ // AMD. Register as an anonymous module.
+ define( [ "jquery" ], function ( $ ) {
+ factory( $, root, doc );
+ return $.mobile;
+ });
+ } else {
+ // Browser globals
+ factory( root.jQuery, root, doc );
+ }
+}( this, document, function ( $, window, document, undefined ) {
@@ -1,7 +0,0 @@
-(function( $ ) {
-
-if ( typeof define === "function" && define.amd ) {
- define( "jquery.mobile", [], function () { return $.mobile; } );
-}
-
-}( jQuery ));

0 comments on commit 5b8f2be

Please sign in to comment.