You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by lo...@apache.org on 2013/05/14 20:33:10 UTC
[28/33] js commit: [BlackBerry10] Switch module loading to
cordova_plugins.json
[BlackBerry10] Switch module loading to cordova_plugins.json
Note: this includes a change to plugin_loader.js that should be applied to all platforms
Revewied by Bryan Higgins <bh...@blackberry.com>
Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/ea8515b6
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/ea8515b6
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/ea8515b6
Branch: refs/heads/master
Commit: ea8515b666a8710863af14a6d4abeba1f2491bfd
Parents: 6d6478e
Author: Hasan Ahmad <ha...@blackberry.com>
Authored: Thu Apr 25 15:56:36 2013 -0400
Committer: Bryan Higgins <bh...@blackberry.com>
Committed: Fri May 3 09:50:05 2013 -0400
----------------------------------------------------------------------
lib/blackberry10/platform.js | 1 -
.../plugin/blackberry10/pluginUtils.js | 88 --------
lib/scripts/bootstrap-blackberry10.js | 22 +--
test/blackberry10/test.pluginUtils.js | 156 ---------------
4 files changed, 6 insertions(+), 261 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/ea8515b6/lib/blackberry10/platform.js
----------------------------------------------------------------------
diff --git a/lib/blackberry10/platform.js b/lib/blackberry10/platform.js
index 5f11f7c..3d68cd8 100644
--- a/lib/blackberry10/platform.js
+++ b/lib/blackberry10/platform.js
@@ -32,6 +32,5 @@ module.exports = {
modulemapper.clobbers('cordova/plugin/File', 'navigator.File');
modulemapper.merges('cordova/plugin/blackberry10/compass', 'navigator.compass');
- modulemapper.mapModules(window);
}
};
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/ea8515b6/lib/blackberry10/plugin/blackberry10/pluginUtils.js
----------------------------------------------------------------------
diff --git a/lib/blackberry10/plugin/blackberry10/pluginUtils.js b/lib/blackberry10/plugin/blackberry10/pluginUtils.js
deleted file mode 100644
index ed41518..0000000
--- a/lib/blackberry10/plugin/blackberry10/pluginUtils.js
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-function build(plugins) {
- var builder = require('cordova/builder'),
- plugin;
- for (plugin in plugins) {
- if (plugins.hasOwnProperty(plugin)) {
- if (plugins[plugin].clobbers) {
- builder.buildIntoAndClobber(plugins[plugin].clobbers, window);
- }
- if (plugins[plugin].merges) {
- builder.buildIntoAndMerge(plugins[plugin].merges, window);
- }
- }
- }
-}
-
-module.exports = {
-
- loadClientJs: function (plugins, callback) {
- var plugin,
- script,
- i,
- count = 0;
- for (plugin in plugins) {
- if (plugins.hasOwnProperty(plugin) && plugins[plugin].modules) {
- for (i = 0; i < plugins[plugin].modules.length; i++) {
- script = document.createElement('script');
- script.src = 'local:///plugins/' + plugin + '/' + plugins[plugin].modules[i];
- script.onload = function () {
- if (--count === 0 && typeof callback === 'function') {
- build(plugins);
- callback();
- }
- };
- count++;
- document.head.appendChild(script);
- }
- }
- }
- if (count === 0) {
- callback();
- }
- },
-
- getPlugins: function (success, error) {
- var request,
- response;
- request = new XMLHttpRequest();
- request.open('GET', 'local:///plugins/plugins.json', true);
- request.onreadystatechange = function () {
- if (request.readyState === 4) {
- if (request.status === 200) {
- try {
- response = JSON.parse(decodeURIComponent(request.responseText));
- success(response);
- }
- catch (e) {
- error(e);
- }
- }
- else {
- error(request.status);
- }
- }
- };
- request.send(null);
- }
-};
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/ea8515b6/lib/scripts/bootstrap-blackberry10.js
----------------------------------------------------------------------
diff --git a/lib/scripts/bootstrap-blackberry10.js b/lib/scripts/bootstrap-blackberry10.js
index 836880f..351411c 100644
--- a/lib/scripts/bootstrap-blackberry10.js
+++ b/lib/scripts/bootstrap-blackberry10.js
@@ -20,8 +20,7 @@
*/
(function () {
- var pluginUtils = require('cordova/plugin/blackberry10/pluginUtils'),
- docAddEventListener = document.addEventListener,
+ var docAddEventListener = document.addEventListener,
webworksReady = false,
alreadyFired = false,
listenerRegistered = false;
@@ -124,20 +123,11 @@
event: require("cordova/plugin/blackberry10/event")
};
- //Fire webworks ready once plugin javascript has been loaded
- pluginUtils.getPlugins(
- function (plugins) {
- pluginUtils.loadClientJs(plugins, function () {
- webworksReady = true;
- fireWebworksReadyEvent();
- });
- },
- function () {
- console.log('Unable to load plugins.json');
- webworksReady = true;
- fireWebworksReadyEvent();
- }
- );
+ require("cordova/channel").onPluginsReady.subscribe(function () {
+ require("cordova/modulemapper").mapModules(window);
+ webworksReady = true;
+ fireWebworksReadyEvent();
+ });
}());
document.addEventListener("DOMContentLoaded", function () {
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/ea8515b6/test/blackberry10/test.pluginUtils.js
----------------------------------------------------------------------
diff --git a/test/blackberry10/test.pluginUtils.js b/test/blackberry10/test.pluginUtils.js
deleted file mode 100644
index 3fe83bb..0000000
--- a/test/blackberry10/test.pluginUtils.js
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-describe('blackberry10 pluginUtils', function () {
-
- var pluginUtils = require('cordova/plugin/blackberry10/pluginUtils'),
- builder = require('cordova/builder');
-
- describe('loadClientJs', function () {
-
- var callback,
- script;
-
- beforeEach(function () {
- script = {};
- spyOn(document, "createElement").andCallFake(function () {
- return script;
- });
- spyOn(document.head, "appendChild");
- callback = jasmine.createSpy();
- spyOn(builder, "buildIntoAndClobber");
- spyOn(builder, "buildIntoAndMerge");
- });
-
- it('does nothing for 0 plugins', function () {
- var plugins = {};
- pluginUtils.loadClientJs(plugins, callback);
- expect(document.createElement).not.toHaveBeenCalled();
- expect(document.head.appendChild).not.toHaveBeenCalled();
- expect(callback).toHaveBeenCalled();
- });
-
- it('adds a script tag for 1 plugin', function () {
- var plugins = { foo : { modules: ['bar.js'] } };
- pluginUtils.loadClientJs(plugins, callback);
- expect(document.createElement).toHaveBeenCalled();
- expect(script.src).toEqual('local:///plugins/foo/bar.js');
- expect(document.head.appendChild).toHaveBeenCalled();
- script.onload();
- expect(callback).toHaveBeenCalled();
- });
-
- it('adds multiple script tags for 1 plugin', function () {
- var plugins = { foo: { modules: ['bar.js', '2.js'] } };
- pluginUtils.loadClientJs(plugins, callback);
- expect(document.createElement.callCount).toBe(2);
- expect(document.head.appendChild.callCount).toBe(2);
- script.onload();
- script.onload();
- expect(callback.callCount).toBe(1);
- });
-
- it('adds script tags for multiple plugins', function () {
- var plugins = { foo: { modules: ['1.js'] }, bar: { modules: ['1.js', '2.js' ] } };
- pluginUtils.loadClientJs(plugins, callback);
- expect(document.createElement.callCount).toBe(3);
- expect(document.head.appendChild.callCount).toBe(3);
- script.onload();
- script.onload();
- script.onload();
- expect(callback.callCount).toBe(1);
- });
-
- it('calls clobber', function () {
- var plugins = { foo: { modules : ['bar.js'], clobbers: { bar: { path: 'foo.bar' } } } };
- pluginUtils.loadClientJs(plugins, callback);
- script.onload();
- expect(callback.callCount).toBe(1);
- expect(builder.buildIntoAndClobber).toHaveBeenCalledWith(plugins.foo.clobbers, window);
- });
-
- it('calls merge', function () {
- var plugins = { foo: { modules : ['bar.js'], merges: { bar: { path: 'foo.bar' } } } };
- pluginUtils.loadClientJs(plugins, callback);
- script.onload();
- expect(callback.callCount).toBe(1);
- expect(builder.buildIntoAndMerge).toHaveBeenCalledWith(plugins.foo.merges, window);
- });
-
- });
-
- describe('getPlugins', function () {
-
- var success,
- error,
- xhr;
-
- beforeEach(function () {
- GLOBAL.XMLHttpRequest = function () {
- this.open = jasmine.createSpy();
- this.send = jasmine.createSpy();
- xhr = this;
- };
- success = jasmine.createSpy();
- error = jasmine.createSpy();
- });
-
- afterEach(function () {
- delete GLOBAL.XMLHttpRequest;
- });
-
- it('sends XHR for plugins.json', function () {
- pluginUtils.getPlugins(success, error);
- expect(xhr.open).toHaveBeenCalledWith('GET', 'local:///plugins/plugins.json', true);
- expect(xhr.send).toHaveBeenCalled();
- });
-
- it('calls success with JSON response', function () {
- pluginUtils.getPlugins(success, error);
- xhr.readyState = 4;
- xhr.status = 200;
- xhr.responseText = '{ "hello" : "World" }';
- xhr.onreadystatechange();
- expect(success).toHaveBeenCalledWith({ hello: "World"});
- expect(error).not.toHaveBeenCalled();
- });
-
- it('calls error with status', function () {
- pluginUtils.getPlugins(success, error);
- xhr.readyState = 4;
- xhr.status = 500;
- xhr.onreadystatechange();
- expect(error).toHaveBeenCalledWith(500);
- expect(success).not.toHaveBeenCalled();
- });
-
- it('calls error with parse exception', function () {
- pluginUtils.getPlugins(success, error);
- xhr.readyState = 4;
- xhr.status = 200;
- xhr.responseText = 'INVALID';
- xhr.onreadystatechange();
- expect(error).toHaveBeenCalled();
- expect(success).not.toHaveBeenCalled();
- });
-
- });
-});