Created
October 9, 2013 12:59
-
-
Save s2b/6900845 to your computer and use it in GitHub Desktop.
Require.js plugin to detect the global jQuery version and use a local jQuery if the global version is too old.
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
// Map jquery module to the plugin | |
// Credits to jburke | |
// https://github.com/jrburke/requirejs/issues/451#issuecomment-8442745 | |
require.config({ | |
map: { | |
'*': { | |
'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(["versionCompare"], function (versionCompare) { | |
// Specify the required jQuery version here | |
var jQueryVersion = '1.10'; | |
return { | |
load: function (name, parentRequire, onLoad, config) { | |
if ($ in window && versionCompare(window.$.fn.jquery, jQueryVersion, '>=')) { | |
// Return global jQuery version | |
onLoad(window.$); | |
} else { | |
// Load and use local jQuery version (of course jquery-ui can be omitted here) | |
parentRequire(["lib/jquery", "lib/jquery-ui"], function (jQuery) { | |
// No conflict with existing jQuery | |
jQuery.noConflict(); | |
// More jQuery initialization (like event proxying between the jQuery versions) | |
// can be put here | |
// window.$: global jQuery | |
// jQuery: local jQuery | |
// Return local jQuery | |
onLoad(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(function () { | |
// versionCompare module could return a function like this: | |
// http://phpjs.org/functions/version_compare/ | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment