updated cordova.js for 2.1.0
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/commit/1e9b4fee Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/tree/1e9b4fee Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/diff/1e9b4fee Branch: refs/heads/master Commit: 1e9b4feed239af2e4f31aa83396292a6e9b935bc Parents: 1925d76 Author: Jesse MacFadyen <purplecabb...@gmail.com> Authored: Tue Sep 11 17:13:34 2012 -0700 Committer: Jesse MacFadyen <purplecabb...@gmail.com> Committed: Tue Sep 11 17:13:34 2012 -0700 ---------------------------------------------------------------------- example/www/cordova-2.1.0.js | 119 ++++++++++++++++-------- templates/full/www/cordova-2.1.0.js | 118 ++++++++++++++++-------- templates/standalone/www/cordova-2.1.0.js | 118 ++++++++++++++++-------- 3 files changed, 234 insertions(+), 121 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/1e9b4fee/example/www/cordova-2.1.0.js ---------------------------------------------------------------------- diff --git a/example/www/cordova-2.1.0.js b/example/www/cordova-2.1.0.js index 7db46ec..0cf8025 100644 --- a/example/www/cordova-2.1.0.js +++ b/example/www/cordova-2.1.0.js @@ -1,6 +1,6 @@ -// commit 2aa46aa0eef2ba641cf91793735152d7fb5b6998 +// commit a91a8f60b9f12bb74fa3a7f6c640308903ab73bf -// File generated at :: Fri Aug 31 2012 14:36:02 GMT-0700 (Pacific Daylight Time) +// File generated at :: Tue Sep 11 2012 17:11:06 GMT-0700 (Pacific Daylight Time) /* Licensed to the Apache Software Foundation (ASF) under one @@ -186,13 +186,19 @@ var cordova = { }, /** * Method to fire event from native code + * bNoDetach is required for events which cause an exception which needs to be caught in native code */ - fireDocumentEvent: function(type, data) { + fireDocumentEvent: function(type, data, bNoDetach) { var evt = createEvent(type, data); if (typeof documentEventHandlers[type] != 'undefined') { - setTimeout(function() { - documentEventHandlers[type].fire(evt); - }, 0); + if( bNoDetach ) { + documentEventHandlers[type].fire(evt); + } + else { + setTimeout(function() { + documentEventHandlers[type].fire(evt); + }, 0); + } } else { document.dispatchEvent(evt); } @@ -902,7 +908,6 @@ module.exports = function(success, fail, service, action, args) { { if(typeof args[n] !== "string") { - console.log("Extra encoding :: " + n); args[n] = JSON.stringify(args[n]); } } @@ -3038,34 +3043,39 @@ Media.prototype.setVolume = function(volume) { * PRIVATE * * @param id The media object id (string) - * @param status The status code (int) - * @param msg The status message (string) + * @param msgType The 'type' of update this is + * @param value Use of value is determined by the msgType */ -Media.onStatus = function(id, msg, value) { +Media.onStatus = function(id, msgType, value) { + var media = mediaObjects[id]; - // If state update - if (msg === Media.MEDIA_STATE) { - if (media.statusCallback) { - media.statusCallback(value); - } - if (value === Media.MEDIA_STOPPED) { - if (media.successCallback) { - media.successCallback(); - } - } - } - else if (msg === Media.MEDIA_DURATION) { - media._duration = value; - } - else if (msg === Media.MEDIA_ERROR) { - if (media.errorCallback) { - // value should be a MediaError object when msg == MEDIA_ERROR - media.errorCallback(value); + + if(media) { + switch(msgType) { + case Media.MEDIA_STATE : + media.statusCallback && media.statusCallback(value); + if(value == Media.MEDIA_STOPPED) { + media.successCallback && media.successCallback(); + } + break; + case Media.MEDIA_DURATION : + media._duration = value; + break; + case Media.MEDIA_ERROR : + media.errorCallback && media.errorCallback(value); + break; + case Media.MEDIA_POSITION : + media._position = Number(value); + break; + default : + console && console.error && console.error("Unhandled Media.onStatus :: " + msgType); + break; } } - else if (msg === Media.MEDIA_POSITION) { - media._position = value; + else { + console && console.error && console.error("Received Media.onStatus callback for unknown media :: " + id); } + }; module.exports = Media; @@ -3075,20 +3085,36 @@ module.exports = Media; define("cordova/plugin/MediaError", function(require, exports, module) { /** * This class contains information about any Media errors. - * @constructor +*/ +/* + According to :: http://dev.w3.org/html5/spec-author-view/video.html#mediaerror + We should never be creating these objects, we should just implement the interface + which has 1 property for an instance, 'code' + + instead of doing : + errorCallbackFunction( new MediaError(3,'msg') ); +we should simply use a literal : + errorCallbackFunction( {'code':3} ); */ -var MediaError = function(code, msg) { - this.code = (code !== undefined ? code : null); - this.message = msg || ""; -}; -MediaError.MEDIA_ERR_NONE_ACTIVE = 0; -MediaError.MEDIA_ERR_ABORTED = 1; -MediaError.MEDIA_ERR_NETWORK = 2; -MediaError.MEDIA_ERR_DECODE = 3; -MediaError.MEDIA_ERR_NONE_SUPPORTED = 4; +if(!MediaError) { + var MediaError = function(code, msg) { + this.code = (typeof code != 'undefined') ? code : null; + this.message = msg || ""; // message is NON-standard! do not use! + }; +} + +MediaError.MEDIA_ERR_NONE_ACTIVE = MediaError.MEDIA_ERR_NONE_ACTIVE || 0; +MediaError.MEDIA_ERR_ABORTED = MediaError.MEDIA_ERR_ABORTED || 1; +MediaError.MEDIA_ERR_NETWORK = MediaError.MEDIA_ERR_NETWORK || 2; +MediaError.MEDIA_ERR_DECODE = MediaError.MEDIA_ERR_DECODE || 3; +MediaError.MEDIA_ERR_NONE_SUPPORTED = MediaError.MEDIA_ERR_NONE_SUPPORTED || 4; +// TODO: MediaError.MEDIA_ERR_NONE_SUPPORTED is legacy, the W3 spec now defines it as below. +// as defined by http://dev.w3.org/html5/spec-author-view/video.html#error-codes +MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED = MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED || 4; module.exports = MediaError; + }); // file: lib\common\plugin\MediaFile.js @@ -4680,7 +4706,8 @@ var channel = require('cordova/channel'); module.exports = function(status,callbackId,args,cast) { if(status === "backbutton") { - cordova.fireDocumentEvent("backbutton"); + // do not detach backbutton event, as we need to be able to catch exceptions + cordova.fireDocumentEvent("backbutton", undefined, true); return "true"; } else if(status === "resume") { @@ -4735,7 +4762,11 @@ var Media = require('cordova/plugin/Media'); module.exports = function(args) { try { + var res = JSON.parse(args); + if(res.msg == Media.MEDIA_ERROR) { + res.value = {'code':res.value}; + } Media.onStatus(res.id, res.msg, res.value); } catch(e) { @@ -5292,6 +5323,12 @@ var debugConsole = { } }; +var oldOnError = window.onerror; +window.onerror = function(msg,fileName,line) { + oldOnError && oldOnError(msg,fileName,line); + debugConsole.error(msg + " file:" + fileName + " Line:" + line); +}; + module.exports = debugConsole; }); http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/1e9b4fee/templates/full/www/cordova-2.1.0.js ---------------------------------------------------------------------- diff --git a/templates/full/www/cordova-2.1.0.js b/templates/full/www/cordova-2.1.0.js index e45a94d..0cf8025 100644 --- a/templates/full/www/cordova-2.1.0.js +++ b/templates/full/www/cordova-2.1.0.js @@ -1,6 +1,6 @@ -// commit 2aa46aa0eef2ba641cf91793735152d7fb5b6998 +// commit a91a8f60b9f12bb74fa3a7f6c640308903ab73bf -// File generated at :: Fri Aug 31 2012 14:36:02 GMT-0700 (Pacific Daylight Time) +// File generated at :: Tue Sep 11 2012 17:11:06 GMT-0700 (Pacific Daylight Time) /* Licensed to the Apache Software Foundation (ASF) under one @@ -186,13 +186,19 @@ var cordova = { }, /** * Method to fire event from native code + * bNoDetach is required for events which cause an exception which needs to be caught in native code */ - fireDocumentEvent: function(type, data) { + fireDocumentEvent: function(type, data, bNoDetach) { var evt = createEvent(type, data); if (typeof documentEventHandlers[type] != 'undefined') { - setTimeout(function() { - documentEventHandlers[type].fire(evt); - }, 0); + if( bNoDetach ) { + documentEventHandlers[type].fire(evt); + } + else { + setTimeout(function() { + documentEventHandlers[type].fire(evt); + }, 0); + } } else { document.dispatchEvent(evt); } @@ -3037,34 +3043,39 @@ Media.prototype.setVolume = function(volume) { * PRIVATE * * @param id The media object id (string) - * @param status The status code (int) - * @param msg The status message (string) + * @param msgType The 'type' of update this is + * @param value Use of value is determined by the msgType */ -Media.onStatus = function(id, msg, value) { +Media.onStatus = function(id, msgType, value) { + var media = mediaObjects[id]; - // If state update - if (msg === Media.MEDIA_STATE) { - if (media.statusCallback) { - media.statusCallback(value); - } - if (value === Media.MEDIA_STOPPED) { - if (media.successCallback) { - media.successCallback(); - } - } - } - else if (msg === Media.MEDIA_DURATION) { - media._duration = value; - } - else if (msg === Media.MEDIA_ERROR) { - if (media.errorCallback) { - // value should be a MediaError object when msg == MEDIA_ERROR - media.errorCallback(value); + + if(media) { + switch(msgType) { + case Media.MEDIA_STATE : + media.statusCallback && media.statusCallback(value); + if(value == Media.MEDIA_STOPPED) { + media.successCallback && media.successCallback(); + } + break; + case Media.MEDIA_DURATION : + media._duration = value; + break; + case Media.MEDIA_ERROR : + media.errorCallback && media.errorCallback(value); + break; + case Media.MEDIA_POSITION : + media._position = Number(value); + break; + default : + console && console.error && console.error("Unhandled Media.onStatus :: " + msgType); + break; } } - else if (msg === Media.MEDIA_POSITION) { - media._position = value; + else { + console && console.error && console.error("Received Media.onStatus callback for unknown media :: " + id); } + }; module.exports = Media; @@ -3074,20 +3085,36 @@ module.exports = Media; define("cordova/plugin/MediaError", function(require, exports, module) { /** * This class contains information about any Media errors. - * @constructor +*/ +/* + According to :: http://dev.w3.org/html5/spec-author-view/video.html#mediaerror + We should never be creating these objects, we should just implement the interface + which has 1 property for an instance, 'code' + + instead of doing : + errorCallbackFunction( new MediaError(3,'msg') ); +we should simply use a literal : + errorCallbackFunction( {'code':3} ); */ -var MediaError = function(code, msg) { - this.code = (code !== undefined ? code : null); - this.message = msg || ""; -}; -MediaError.MEDIA_ERR_NONE_ACTIVE = 0; -MediaError.MEDIA_ERR_ABORTED = 1; -MediaError.MEDIA_ERR_NETWORK = 2; -MediaError.MEDIA_ERR_DECODE = 3; -MediaError.MEDIA_ERR_NONE_SUPPORTED = 4; +if(!MediaError) { + var MediaError = function(code, msg) { + this.code = (typeof code != 'undefined') ? code : null; + this.message = msg || ""; // message is NON-standard! do not use! + }; +} + +MediaError.MEDIA_ERR_NONE_ACTIVE = MediaError.MEDIA_ERR_NONE_ACTIVE || 0; +MediaError.MEDIA_ERR_ABORTED = MediaError.MEDIA_ERR_ABORTED || 1; +MediaError.MEDIA_ERR_NETWORK = MediaError.MEDIA_ERR_NETWORK || 2; +MediaError.MEDIA_ERR_DECODE = MediaError.MEDIA_ERR_DECODE || 3; +MediaError.MEDIA_ERR_NONE_SUPPORTED = MediaError.MEDIA_ERR_NONE_SUPPORTED || 4; +// TODO: MediaError.MEDIA_ERR_NONE_SUPPORTED is legacy, the W3 spec now defines it as below. +// as defined by http://dev.w3.org/html5/spec-author-view/video.html#error-codes +MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED = MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED || 4; module.exports = MediaError; + }); // file: lib\common\plugin\MediaFile.js @@ -4679,7 +4706,8 @@ var channel = require('cordova/channel'); module.exports = function(status,callbackId,args,cast) { if(status === "backbutton") { - cordova.fireDocumentEvent("backbutton"); + // do not detach backbutton event, as we need to be able to catch exceptions + cordova.fireDocumentEvent("backbutton", undefined, true); return "true"; } else if(status === "resume") { @@ -4734,7 +4762,11 @@ var Media = require('cordova/plugin/Media'); module.exports = function(args) { try { + var res = JSON.parse(args); + if(res.msg == Media.MEDIA_ERROR) { + res.value = {'code':res.value}; + } Media.onStatus(res.id, res.msg, res.value); } catch(e) { @@ -5291,6 +5323,12 @@ var debugConsole = { } }; +var oldOnError = window.onerror; +window.onerror = function(msg,fileName,line) { + oldOnError && oldOnError(msg,fileName,line); + debugConsole.error(msg + " file:" + fileName + " Line:" + line); +}; + module.exports = debugConsole; }); http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/1e9b4fee/templates/standalone/www/cordova-2.1.0.js ---------------------------------------------------------------------- diff --git a/templates/standalone/www/cordova-2.1.0.js b/templates/standalone/www/cordova-2.1.0.js index e45a94d..0cf8025 100644 --- a/templates/standalone/www/cordova-2.1.0.js +++ b/templates/standalone/www/cordova-2.1.0.js @@ -1,6 +1,6 @@ -// commit 2aa46aa0eef2ba641cf91793735152d7fb5b6998 +// commit a91a8f60b9f12bb74fa3a7f6c640308903ab73bf -// File generated at :: Fri Aug 31 2012 14:36:02 GMT-0700 (Pacific Daylight Time) +// File generated at :: Tue Sep 11 2012 17:11:06 GMT-0700 (Pacific Daylight Time) /* Licensed to the Apache Software Foundation (ASF) under one @@ -186,13 +186,19 @@ var cordova = { }, /** * Method to fire event from native code + * bNoDetach is required for events which cause an exception which needs to be caught in native code */ - fireDocumentEvent: function(type, data) { + fireDocumentEvent: function(type, data, bNoDetach) { var evt = createEvent(type, data); if (typeof documentEventHandlers[type] != 'undefined') { - setTimeout(function() { - documentEventHandlers[type].fire(evt); - }, 0); + if( bNoDetach ) { + documentEventHandlers[type].fire(evt); + } + else { + setTimeout(function() { + documentEventHandlers[type].fire(evt); + }, 0); + } } else { document.dispatchEvent(evt); } @@ -3037,34 +3043,39 @@ Media.prototype.setVolume = function(volume) { * PRIVATE * * @param id The media object id (string) - * @param status The status code (int) - * @param msg The status message (string) + * @param msgType The 'type' of update this is + * @param value Use of value is determined by the msgType */ -Media.onStatus = function(id, msg, value) { +Media.onStatus = function(id, msgType, value) { + var media = mediaObjects[id]; - // If state update - if (msg === Media.MEDIA_STATE) { - if (media.statusCallback) { - media.statusCallback(value); - } - if (value === Media.MEDIA_STOPPED) { - if (media.successCallback) { - media.successCallback(); - } - } - } - else if (msg === Media.MEDIA_DURATION) { - media._duration = value; - } - else if (msg === Media.MEDIA_ERROR) { - if (media.errorCallback) { - // value should be a MediaError object when msg == MEDIA_ERROR - media.errorCallback(value); + + if(media) { + switch(msgType) { + case Media.MEDIA_STATE : + media.statusCallback && media.statusCallback(value); + if(value == Media.MEDIA_STOPPED) { + media.successCallback && media.successCallback(); + } + break; + case Media.MEDIA_DURATION : + media._duration = value; + break; + case Media.MEDIA_ERROR : + media.errorCallback && media.errorCallback(value); + break; + case Media.MEDIA_POSITION : + media._position = Number(value); + break; + default : + console && console.error && console.error("Unhandled Media.onStatus :: " + msgType); + break; } } - else if (msg === Media.MEDIA_POSITION) { - media._position = value; + else { + console && console.error && console.error("Received Media.onStatus callback for unknown media :: " + id); } + }; module.exports = Media; @@ -3074,20 +3085,36 @@ module.exports = Media; define("cordova/plugin/MediaError", function(require, exports, module) { /** * This class contains information about any Media errors. - * @constructor +*/ +/* + According to :: http://dev.w3.org/html5/spec-author-view/video.html#mediaerror + We should never be creating these objects, we should just implement the interface + which has 1 property for an instance, 'code' + + instead of doing : + errorCallbackFunction( new MediaError(3,'msg') ); +we should simply use a literal : + errorCallbackFunction( {'code':3} ); */ -var MediaError = function(code, msg) { - this.code = (code !== undefined ? code : null); - this.message = msg || ""; -}; -MediaError.MEDIA_ERR_NONE_ACTIVE = 0; -MediaError.MEDIA_ERR_ABORTED = 1; -MediaError.MEDIA_ERR_NETWORK = 2; -MediaError.MEDIA_ERR_DECODE = 3; -MediaError.MEDIA_ERR_NONE_SUPPORTED = 4; +if(!MediaError) { + var MediaError = function(code, msg) { + this.code = (typeof code != 'undefined') ? code : null; + this.message = msg || ""; // message is NON-standard! do not use! + }; +} + +MediaError.MEDIA_ERR_NONE_ACTIVE = MediaError.MEDIA_ERR_NONE_ACTIVE || 0; +MediaError.MEDIA_ERR_ABORTED = MediaError.MEDIA_ERR_ABORTED || 1; +MediaError.MEDIA_ERR_NETWORK = MediaError.MEDIA_ERR_NETWORK || 2; +MediaError.MEDIA_ERR_DECODE = MediaError.MEDIA_ERR_DECODE || 3; +MediaError.MEDIA_ERR_NONE_SUPPORTED = MediaError.MEDIA_ERR_NONE_SUPPORTED || 4; +// TODO: MediaError.MEDIA_ERR_NONE_SUPPORTED is legacy, the W3 spec now defines it as below. +// as defined by http://dev.w3.org/html5/spec-author-view/video.html#error-codes +MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED = MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED || 4; module.exports = MediaError; + }); // file: lib\common\plugin\MediaFile.js @@ -4679,7 +4706,8 @@ var channel = require('cordova/channel'); module.exports = function(status,callbackId,args,cast) { if(status === "backbutton") { - cordova.fireDocumentEvent("backbutton"); + // do not detach backbutton event, as we need to be able to catch exceptions + cordova.fireDocumentEvent("backbutton", undefined, true); return "true"; } else if(status === "resume") { @@ -4734,7 +4762,11 @@ var Media = require('cordova/plugin/Media'); module.exports = function(args) { try { + var res = JSON.parse(args); + if(res.msg == Media.MEDIA_ERROR) { + res.value = {'code':res.value}; + } Media.onStatus(res.id, res.msg, res.value); } catch(e) { @@ -5291,6 +5323,12 @@ var debugConsole = { } }; +var oldOnError = window.onerror; +window.onerror = function(msg,fileName,line) { + oldOnError && oldOnError(msg,fileName,line); + debugConsole.error(msg + " file:" + fileName + " Line:" + line); +}; + module.exports = debugConsole; });