Skip to content
Permalink
Browse files
Revert "Revert "Merge branch 'master' into browserify""
This reverts commit 68ab22d.

Conflicts:
	package.json
  • Loading branch information
Anis Kadri committed Apr 30, 2014
1 parent 087412e commit 51a5a39d2d85eca8802d8a8816adaad4f4df9546
Showing 10 changed files with 674 additions and 1 deletion.
@@ -33,6 +33,19 @@ module.exports = function(grunt) {
"ubuntu": {},
"browser": {}
},
"compile-browserify": {
"amazon-fireos": {},
"android": {},
"blackberry10": {},
"ios": {},
"osx": {},
//"test": {},
"windows8": { useWindowsLineEndings: true },
"windowsphone": { useWindowsLineEndings: true },
"firefoxos": {},
"ubuntu": {},
"browser": {}
},
clean: ['pkg'],
jshint: {
options: {
@@ -42,7 +42,7 @@
},
{
"name": "Anis Kadri",
"email": ""
"email": "anis@apache.org"
},
{
"name": "Dan Silivestru",
@@ -60,5 +60,10 @@
"grunt": "~0.4.1",
"grunt-contrib-clean": "~0.4.1",
"grunt-contrib-jshint": "~0.6.0"
},
"dependencies": {
"uglify-js": "2.4.x",
"browserify": "3.2.0",
"through": "2.3.4"
}
}
@@ -235,6 +235,7 @@ channel.createSticky('onNativeReady');
channel.createSticky('onCordovaReady');

// Event to indicate that all automatically loaded JS plugins are loaded and ready.
// FIXME remove this
channel.createSticky('onPluginsReady');

// Event to indicate that Cordova is ready
@@ -0,0 +1,120 @@
/*
*
* 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.
*
*/

var channel = require('cordova/channel');
var cordova = require('cordova');
var platform = require('cordova/platform');

var platformInitChannelsArray = [channel.onDOMContentLoaded, channel.onNativeReady];

// setting exec
cordova.exec = require('cordova/exec');

function logUnfiredChannels(arr) {
for (var i = 0; i < arr.length; ++i) {
if (arr[i].state != 2) {
console.log('Channel not fired: ' + arr[i].type);
}
}
}

window.setTimeout(function() {
if (channel.onDeviceReady.state != 2) {
console.log('deviceready has not fired after 5 seconds.');
logUnfiredChannels(platformInitChannelsArray);
logUnfiredChannels(channel.deviceReadyChannelsArray);
}
}, 5000);

// Replace navigator before any modules are required(), to ensure it happens as soon as possible.
// We replace it so that properties that can't be clobbered can instead be overridden.
function replaceNavigator(origNavigator) {
var CordovaNavigator = function() {};
CordovaNavigator.prototype = origNavigator;
var newNavigator = new CordovaNavigator();
// This work-around really only applies to new APIs that are newer than Function.bind.
// Without it, APIs such as getGamepads() break.
if (CordovaNavigator.bind) {
for (var key in origNavigator) {
if (typeof origNavigator[key] == 'function') {
newNavigator[key] = origNavigator[key].bind(origNavigator);
}
}
}
return newNavigator;
}
if (window.navigator) {
window.navigator = replaceNavigator(window.navigator);
}

if (!window.console) {
window.console = {
log: function(){}
};
}
if (!window.console.warn) {
window.console.warn = function(msg) {
this.log("warn: " + msg);
};
}

// Register pause, resume and deviceready channels as events on document.
channel.onPause = cordova.addDocumentEventHandler('pause');
channel.onResume = cordova.addDocumentEventHandler('resume');
channel.onDeviceReady = cordova.addStickyDocumentEventHandler('deviceready');

// Listen for DOMContentLoaded and notify our channel subscribers.
if (document.readyState == 'complete' || document.readyState == 'interactive') {
channel.onDOMContentLoaded.fire();
} else {
document.addEventListener('DOMContentLoaded', function() {
channel.onDOMContentLoaded.fire();
}, false);
}

// _nativeReady is global variable that the native side can set
// to signify that the native code is ready. It is a global since
// it may be called before any cordova JS is ready.
if (window._nativeReady) {
channel.onNativeReady.fire();
}

// Call the platform-specific initialization.
platform.bootstrap && platform.bootstrap();

/**
* Create all cordova objects once native side is ready.
*/
channel.join(function() {

platform.initialize && platform.initialize();

// Fire event to notify that all objects are created
channel.onCordovaReady.fire();

// Fire onDeviceReady event once page has fully loaded, all
// constructors have run and cordova info has been received from native
// side.
channel.join(function() {
require('cordova').fireDocumentEvent('deviceready');
}, channel.deviceReadyChannelsArray);

}, platformInitChannelsArray);

0 comments on commit 51a5a39

Please sign in to comment.