Skip to content

Instantly share code, notes, and snippets.

@zonak
Created April 5, 2012 17:48
Show Gist options
  • Save zonak/2312804 to your computer and use it in GitHub Desktop.
Save zonak/2312804 to your computer and use it in GitHub Desktop.
jQuery mobile issue with r.js optimization
// Spot A
window.document.onmobileinit = function() {
// this happens in both regular and optimized version
$.mobile.ajaxEnabled = false;
$.mobile.hashListeningEnabled = false;
$.mobile.pushStateEnabled = false;
$.mobile.linkBindingEnabled = false;
};
require.config({
paths: {
jquery: 'libs/jquery',
jquerymobile: 'libs/jquery.mobile'
// ...
}
});
require(['jquery', 'ns', 'json2'], function($, NS) {
// Spot B
$(window.document).on('mobileinit', function() {
// this happens ONLY in the regular version, NOT in the optimized version
$.mobile.ajaxEnabled = false;
$.mobile.hashListeningEnabled = false;
$.mobile.pushStateEnabled = false;
$.mobile.linkBindingEnabled = false;
});
// This is where jQuery mobile is loaded and at which point 'mobileinit' should be fired
require(['jquerymobile'], function() {
// ...
});
});
@jrburke
Copy link

jrburke commented Apr 5, 2012

require(['jquery', 'ns', 'json2'], function($, NS) {

  // This is where jQuery mobile is loaded and at which point 'mobileinit' should be fired
  return require('jquerymobile'], function() {
      //Spot B
      //Maybe this is too late for this to run?
      $.mobile.ajaxEnabled = false;  
      $.mobile.hashListeningEnabled = false;
      $.mobile.pushStateEnabled = false;
      $.mobile.linkBindingEnabled = false;
  });

});

@zonak
Copy link
Author

zonak commented Apr 5, 2012

Slight update on the matter.

For the time being, I took the following approach:

 require(['order!jqmconfig', 'order!jquerymobile'], function() {
    // ...
  });

where jqmconfig is a small module containing a definition of a listener with the necessary jQuery mobile overrides:

$(window.document).on('mobileinit', function() {
    // this happens ONLY in the regular version, NOT in the optimized version
    $.mobile.ajaxEnabled = false;
    $.mobile.hashListeningEnabled = false;
    $.mobile.pushStateEnabled = false;
    $.mobile.linkBindingEnabled = false;
  });

the order plugin helps in making sure that the proper order of things is retained - defining the listener before the mobileinit event fires.

@jrburke thank you again for looking into it. Looking forward to 1.1 - hopefully it will render this workaround unnecessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment