Permalink
Browse files

Merge branch 'almond'

  • Loading branch information...
2 parents a1bed08 + 8b101ca commit 51d347cab183a033221c14b25f271b9ba1ea45a9 @gtanner gtanner committed Dec 14, 2011
View
@@ -6,15 +6,15 @@ module.exports = {
var util = require('util'),
fs = require('fs'),
files = [
+ "lib/utils.js",
"lib/plugin/navigator.js",
"lib/plugin/notification.js",
"lib/plugin/accelerometer.js",
"lib/plugin/Connection.js",
"lib/plugin/network.js",
"lib/plugin/" + platform + "/device.js",
- "lib/Channel.js",
+ "lib/channel.js",
"lib/builder.js",
- "lib/utils.js",
"lib/exec/" +platform + ".js"
],
include = function (files, transform) {
@@ -32,24 +32,24 @@ module.exports = {
});
//include require
- output += include("thirdparty/browser-require/require.js");
+ output += include("thirdparty/almond.js");
//include modules
output += include(files, function (file, path) {
- return "require.define('" + path.replace(/lib\//, "phonegap/").replace(/\.js$/, '') +
- "', function (require, module, exports) {\n" + file + "});\n";
+ var id = path.replace(/lib\//, "phonegap/").replace(/\.js$/, '');
+ return "define('" + id + "', function (require, exports, module) {\n" + file + "});\n";
});
//include platform
output += include('lib/platform/' + platform + '.js', function (file, path) {
- return "require.define('phonegap/platform'" +
- ", function (require, module, exports) {\n" + file + "});\n";
+ return "define('phonegap/platform'" +
+ ", function (require, exports, module) {\n" + file + "});\n";
});
//include phonegap
output += include('lib/phonegap.js', function (file, path) {
- return "require.define('phonegap'" +
- ", function (require, module, exports) {\n" + file + "});\n";
+ return "define('phonegap'" +
+ ", function (require, exports, module) {\n" + file + "});\n";
});
//include bootstrap
View
@@ -1,45 +1,45 @@
(function (context) {
- var Channel = require("phonegap/Channel"),
+ var channel = require("phonegap/channel"),
/**
* onDOMContentLoaded channel is fired when the DOM content
* of the page has been parsed.
*/
- onDOMContentLoaded = new Channel('onDOMContentLoaded'),
+ onDOMContentLoaded = channel.create('onDOMContentLoaded'),
/**
* onNativeReady channel is fired when the PhoneGap native code
* has been initialized.
*/
- onNativeReady = new Channel('onNativeReady'),
+ onNativeReady = channel.create('onNativeReady'),
/**
* onPhoneGapReady channel is fired when the JS PhoneGap objects have been created.
*/
- onPhoneGapReady = new Channel('onPhoneGapReady'),
+ onPhoneGapReady = channel.create('onPhoneGapReady'),
/**
* onPhoneGapInfoReady channel is fired when the PhoneGap device properties
* has been set.
*/
- onPhoneGapInfoReady = new Channel('onPhoneGapInfoReady'),
+ onPhoneGapInfoReady = channel.create('onPhoneGapInfoReady'),
/**
* onPhoneGapConnectionReady channel is fired when the PhoneGap connection properties
* has been set.
*/
- onPhoneGapConnectionReady = new Channel('onPhoneGapConnectionReady'),
+ onPhoneGapConnectionReady = channel.create('onPhoneGapConnectionReady'),
/**
* onResume channel is fired when the PhoneGap native code
* resumes.
*/
- onResume = new Channel('onResume'),
+ onResume = channel.create('onResume'),
/**
* onPause channel is fired when the PhoneGap native code
* pauses.
*/
- onPause = new Channel('onPause'),
+ onPause = channel.create('onPause'),
/**
* onDeviceReady is fired only after all PhoneGap objects are created and
* the device properties are set.
*/
- onDeviceReady = new Channel('onDeviceReady'),
+ onDeviceReady = channel.create('onDeviceReady'),
/**
* PhoneGap Channels that must fire before "deviceready" is fired.
*/
@@ -56,7 +56,7 @@
* Listen for DOMContentLoaded and notify our channel subscribers.
*/
document.addEventListener('DOMContentLoaded', function() {
- Channel["onDOMContentLoaded"].fire();
+ channel.onDOMContentLoaded.fire();
}, false);
/**
@@ -68,15 +68,15 @@
document.addEventListener = function(evt, handler, capture) {
var e = evt.toLowerCase();
if (e == 'deviceready') {
- Channel["onDeviceReady"].subscribeOnce(handler);
+ channel.onDeviceReady.subscribeOnce(handler);
} else if (e == 'resume') {
- Channel["onResume"].subscribe(handler);
+ channel.onResume.subscribe(handler);
// if subscribing listener after event has already fired, invoke the handler
- if (Channel["onResume"].fired && handler instanceof Function) {
+ if (channel.onResume.fired && handler instanceof Function) {
handler();
}
} else if (e == 'pause') {
- Channel["onPause"].subscribe(handler);
+ channel.onPause.subscribe(handler);
} else {
m_document_addEventListener.call(document, evt, handler, capture);
}
@@ -85,7 +85,7 @@
/**
* Create all PhoneGap objects once page has fully loaded and native side is ready.
*/
- Channel.join(function() {
+ channel.join(function() {
var builder = require('phonegap/builder'),
platform = require('phonegap/platform');
@@ -101,7 +101,7 @@
// Fire onDeviceReady event once all constructors have run and
// PhoneGap info has been received from native side.
- Channel.join(function() {
+ channel.join(function() {
onDeviceReady.fire();
// Fire the onresume event, since first one happens before JavaScript is loaded
@@ -117,7 +117,7 @@
// it may be called before any PhoneGap JS is ready.
if (window._nativeReady) {
_self.boot();
- Channel["onNativeReady"].fire();
+ channel.onNativeReady.fire();
}
}(window));
@@ -7,10 +7,29 @@ var Channel = function(type) {
this.guid = 0;
this.fired = false;
this.enabled = true;
-
- Channel[type] = this;
},
- utils = require('./utils');
+ channel = {
+ /**
+ * Calls the provided function only after all of the channels specified
+ * have been fired.
+ */
+ join: function (h, c) {
+ var i = c.length;
+ var len = i;
+ var f = function() {
+ if (!(--i)) h();
+ };
+ for (var j=0; j<len; j++) {
+ (!c[j].fired?c[j].subscribeOnce(f):i--);
+ }
+ if (!i) h();
+ },
+ create: function (type) {
+ channel[type] = new Channel(type);
+ return channel[type];
+ }
+ },
+ utils = require('phonegap/utils');
/**
* Subscribes the given function to the channel. Any time that
@@ -82,20 +101,4 @@ Channel.prototype.fire = function(e) {
return true;
};
-/**
- * Calls the provided function only after all of the channels specified
- * have been fired.
- */
-Channel.join = function(h, c) {
- var i = c.length;
- var len = i;
- var f = function() {
- if (!(--i)) h();
- };
- for (var j=0; j<len; j++) {
- (!c[j].fired?c[j].subscribeOnce(f):i--);
- }
- if (!i) h();
-};
-
-module.exports = Channel;
+module.exports = channel;
View
@@ -1,9 +1,9 @@
// This queue holds the currently executing command and all pending
// commands executed with PhoneGap.exec().
-var commandQueue: [],
+var commandQueue = [],
// Indicates if we're currently in the middle of flushing the command
// queue on the native side.
- commandQueueFlushing: false,
+ commandQueueFlushing = false,
/**
* Creates a gap bridge iframe used to notify the native code about queued
* commands.
@@ -17,7 +17,7 @@
* under the License.
*/
-var Channel = require('phonegap/Channel');
+var channel = require('phonegap/channel');
/**
* This represents the mobile device, and provides properties for inspecting the model, version, UUID of the
@@ -41,7 +41,7 @@ function Device() {
me.name = info.name;
me.uuid = info.uuid;
me.phonegap = info.phonegap;
- Channel.onPhoneGapInfoReady.fire();
+ channel.onPhoneGapInfoReady.fire();
},
function(e) {
me.available = false;
@@ -15,12 +15,12 @@ var device = navigator.device || {},
uuid: phonegap.device.uuid,
phonegap: phonegap.device.phonegap
},
- Channel = require('phonegap/Channel'),
+ channel = require('phonegap/channel'),
key;
for (key in props) {
device[key] = props[key];
}
-Channel.onPhoneGapInfoReady.fire();
+channel.onPhoneGapInfoReady.fire();
module.exports = device;
View
@@ -7,7 +7,7 @@
* Copyright (c) 2010-2011, IBM Corporation
*/
-var Channel = require('phonegap/Channel'),
+var channel = require('phonegap/channel'),
NetworkConnection = function () {
this.type = null;
this._firstRun = true;
@@ -23,15 +23,15 @@ var Channel = require('phonegap/Channel'),
// should only fire this once
if (me._firstRun) {
me._firstRun = false;
- Channel["onPhoneGapConnectionReady"].fire();
+ channel.onPhoneGapConnectionReady.fire();
}
},
function (e) {
// If we can't get the network info we should still tell PhoneGap
// to fire the deviceready event.
if (me._firstRun) {
me._firstRun = false;
- Channel["onPhoneGapConnectionReady"].fire();
+ channel.onPhoneGapConnectionReady.fire();
}
console.log("Error initializing Network Connection: " + e);
});
View
@@ -8,13 +8,6 @@
<link rel="stylesheet" type="text/css" href="../thirdparty/jasmine/jasmine.css">
<script type="text/javascript" src="../thirdparty/jasmine/jasmine.js"></script>
<script type="text/javascript" src="../thirdparty/jasmine/jasmine-html.js"></script>
- <script type="text/javascript" src="../thirdparty/browser-require/require.js"></script>
-
-
- <script type="text/javascript" src="../pkg/phonegap.blackberry.js"></script>
-
- <!-- include tests files here... -->
- <script type="text/javascript" src="test.accelerometer.js"></script>
<script type="text/javascript">
(function() {
@@ -29,17 +22,28 @@
return trivialReporter.specFilter(spec);
};
+ //HACK: until we clean up and modulerize the bridge
+ window.PhoneGap = {
+ exec: jasmine.createSpy("PhoneGap.exec")
+ };
+
+ window.phonegap = {
+ platform: ""
+ };
+
window.addEventListener("load", function () {
- //HACK: until we clean up and modulerize the bridge
- window.PhoneGap = {
- exec: jasmine.createSpy("PhoneGap.exec")
- };
jasmineEnv.execute();
});
})();
</script>
+ <script type="text/javascript" src="../pkg/phonegap.ios.js"></script>
+
+ <!-- include tests files here... -->
+ <script type="text/javascript" src="test.accelerometer.js"></script>
+
+
</head>
<body>
Oops, something went wrong.

0 comments on commit 51d347c

Please sign in to comment.