Skip to content

Commit

Permalink
cordova no likely dynamic load of cordova.js. Wait for 2.0 to try again.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrburke committed Jul 16, 2012
1 parent acb2813 commit 4668ade
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
22 changes: 22 additions & 0 deletions code/www/index.html
Expand Up @@ -9,6 +9,28 @@
<link rel="stylesheet" media="only screen and (max-device-width: 480px)" href="iphone.css" type="text/css" />
-->

<!-- TODO: revisit dynamic loading of cordova.js when its 2.0 is released -->
<script>
(function () {
var pathRegExp = /(\/|^)env\/|\{env\}/,
value = 'web',
platform = navigator.platform.toLowerCase(),
ua = typeof navigator !== 'undefined' && navigator.userAgent;

//A device installation. Nothing says quality like UA sniffing.
//If you know of a better way to do this, speak up.
if (platform.indexOf('iphone') !== -1 ||
platform.indexOf('ipad') !== -1 ||
platform.indexOf('ipod') !== -1) {
value = 'ios';
} else if (/android/i.test(ua)) {
value = 'android';
}

document.write('<script src="js/lib/' + value + '/cordova.js">\<\/script>');
}());
</script>

<script data-main="js/app" src="js/lib/require.js"></script>
</head>
<body>
Expand Down
5 changes: 2 additions & 3 deletions code/www/js/app/main.js
@@ -1,11 +1,10 @@

/*global define, console, document, navigator */
/*global define, console, document, navigator, location */

define(function (require) {
'use strict';

var $ = require('jquery'),
cordova = require('env!cordova');
var $ = require('jquery');

//Dependencies that do not have a module value
require('cordovaReload');
Expand Down
17 changes: 9 additions & 8 deletions code/www/js/lib/env.js
Expand Up @@ -15,16 +15,17 @@ define(function () {

var pathRegExp = /(\/|^)env\/|\{env\}/,
value = 'web',
platform = navigator.platform.toLowerCase(),
ua = typeof navigator !== 'undefined' && navigator.userAgent;

if (typeof location !== 'undefined' && location.protocol === 'file:') {
//A device installation. Nothing says quality like UA sniffing.
//If you know of a better way to do this, speak up.
if (/iphone/i.test(ua)) {
value = 'ios';
} else if (/android/i.test(ua)) {
value = 'android';
}
//A device installation. Nothing says quality like UA sniffing.
//If you know of a better way to do this, speak up.
if (platform.indexOf('iphone') !== -1 ||
platform.indexOf('ipad') !== -1 ||
platform.indexOf('ipod') !== -1) {
value = 'ios';
} else if (/android/i.test(ua)) {
value = 'android';
}

function env() {
Expand Down
4 changes: 2 additions & 2 deletions code/www/js/lib/web/cordova.js
Expand Up @@ -2,7 +2,7 @@

//Just a shim for some things set up by cordova, so the code can run in a
//web browser.
define(['jquery'], function ($) {
(function () {
'use strict';

//document.addEventListener("deviceready"...
Expand All @@ -13,4 +13,4 @@ define(['jquery'], function ($) {
};
}

});
}());

0 comments on commit 4668ade

Please sign in to comment.