Skip to content

Instantly share code, notes, and snippets.

@max-mapper
Created August 31, 2012 23:33
Show Gist options
  • Save max-mapper/3561076 to your computer and use it in GitHub Desktop.
Save max-mapper/3561076 to your computer and use it in GitHub Desktop.
phonegap conditional script loader
// require this script before your document is done loading
;(function () {
var isDroid = navigator.userAgent.match(/Android/)
var isiOS = navigator.userAgent.match(/(iPhone|iPod|iPad)/)
var droidScripts = [
"script/cordova-android.js",
"script/android-utils.js",
"script/cdv-plugin-childbrowser-android.js",
"script/cdv-plugin-datepicker.js",
"script/cdv-plugin-statusbarnotification.js",
"script/cdv-plugin-gcm.js"
]
var iosScripts = [
"script/cordova-ios.js",
"script/cdv-plugin-pushnotification.js",
"script/cdv-plugin-childbrowser-ios.js"
]
if (isDroid) droidScripts.forEach(loadScript)
if (isiOS) iosScripts.forEach(loadScript)
function loadScript(src) {
var line = '<script type="text/javascript" charset="utf-8" src="' + src + '"></script>';
document.writeln(line);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment