You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by an...@apache.org on 2012/04/28 02:27:55 UTC

[3/17] bada-wac commit: adding cordova.js

adding cordova.js


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada-wac/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada-wac/commit/fdb75da0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada-wac/tree/fdb75da0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada-wac/diff/fdb75da0

Branch: refs/heads/master
Commit: fdb75da09d87d5b99dd1977f44efe405e44e0e17
Parents: 8ba2525
Author: Anis Kadri <an...@gmail.com>
Authored: Fri Apr 27 17:18:50 2012 -0700
Committer: Anis Kadri <an...@gmail.com>
Committed: Fri Apr 27 17:18:50 2012 -0700

----------------------------------------------------------------------
 Res/js/cordova.bada.js |  320 +++++++++++++++++++++++++------------------
 1 files changed, 187 insertions(+), 133 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-bada-wac/blob/fdb75da0/Res/js/cordova.bada.js
----------------------------------------------------------------------
diff --git a/Res/js/cordova.bada.js b/Res/js/cordova.bada.js
index 93483b0..e5c767e 100644
--- a/Res/js/cordova.bada.js
+++ b/Res/js/cordova.bada.js
@@ -1,6 +1,6 @@
-// commit 2557edf051775692a8277a6c1f4859f26e46ca0c
+// commit 16863d60915915ee30cd370a87513ed44cc9a3c9
 
-// File generated at :: Tue Apr 24 2012 11:57:57 GMT-0700 (Pacific Daylight Time)
+// File generated at :: Fri Apr 27 2012 17:10:12 GMT-0700 (Pacific Daylight Time)
 
 /*
  Licensed to the Apache Software Foundation (ASF) under one
@@ -101,27 +101,27 @@ document.addEventListener = function(evt, handler, capture) {
     if (e == 'deviceready') {
         channel.onDeviceReady.subscribeOnce(handler);
     } else if (e == 'resume') {
-      channel.onResume.subscribe(handler);
-      // if subscribing listener after event has already fired, invoke the handler
-      if (channel.onResume.fired && handler instanceof Function) {
-          handler();
-      }
+        channel.onResume.subscribe(handler);
+        // if subscribing listener after event has already fired, invoke the handler
+        if (channel.onResume.fired && typeof handler == 'function') {
+            handler();
+        }
     } else if (e == 'pause') {
-      channel.onPause.subscribe(handler);
+        channel.onPause.subscribe(handler);
     } else if (typeof documentEventHandlers[e] != 'undefined') {
-      documentEventHandlers[e].subscribe(handler);
+        documentEventHandlers[e].subscribe(handler);
     } else {
-      m_document_addEventListener.call(document, evt, handler, capture);
+        m_document_addEventListener.call(document, evt, handler, capture);
     }
 };
 
 window.addEventListener = function(evt, handler, capture) {
-  var e = evt.toLowerCase();
-  if (typeof windowEventHandlers[e] != 'undefined') {
-    windowEventHandlers[e].subscribe(handler);
-  } else {
-    m_window_addEventListener.call(window, evt, handler, capture);
-  }
+    var e = evt.toLowerCase();
+    if (typeof windowEventHandlers[e] != 'undefined') {
+        windowEventHandlers[e].subscribe(handler);
+    } else {
+        m_window_addEventListener.call(window, evt, handler, capture);
+    }
 };
 
 document.removeEventListener = function(evt, handler, capture) {
@@ -140,30 +140,29 @@ document.removeEventListener = function(evt, handler, capture) {
 };
 
 window.removeEventListener = function(evt, handler, capture) {
-  var e = evt.toLowerCase();
-  // If unsubcribing from an event that is handled by a plugin
-  if (typeof windowEventHandlers[e] != "undefined") {
-    windowEventHandlers[e].unsubscribe(handler);
-  } else {
-    m_window_removeEventListener.call(window, evt, handler, capture);
-  }
+    var e = evt.toLowerCase();
+    // If unsubcribing from an event that is handled by a plugin
+    if (typeof windowEventHandlers[e] != "undefined") {
+        windowEventHandlers[e].unsubscribe(handler);
+    } else {
+        m_window_removeEventListener.call(window, evt, handler, capture);
+    }
 };
 
 function createEvent(type, data) {
-  var event = document.createEvent('Events');
-  event.initEvent(type, false, false);
-  if (data) {
-    for (var i in data) {
-      if (data.hasOwnProperty(i)) {
-        event[i] = data[i];
-      }
+    var event = document.createEvent('Events');
+    event.initEvent(type, false, false);
+    if (data) {
+        for (var i in data) {
+            if (data.hasOwnProperty(i)) {
+                event[i] = data[i];
+            }
+        }
     }
-  }
-  return event;
+    return event;
 }
 
-if(typeof window.console === "undefined")
-{
+if(typeof window.console === "undefined") {
     window.console = {
         log:function(){}
     };
@@ -176,16 +175,16 @@ var cordova = {
      * Methods to add/remove your own addEventListener hijacking on document + window.
      */
     addWindowEventHandler:function(event, opts) {
-      return (windowEventHandlers[event] = channel.create(event, opts));
+        return (windowEventHandlers[event] = channel.create(event, opts));
     },
     addDocumentEventHandler:function(event, opts) {
-      return (documentEventHandlers[event] = channel.create(event, opts));
+        return (documentEventHandlers[event] = channel.create(event, opts));
     },
     removeWindowEventHandler:function(event) {
-      delete windowEventHandlers[event];
+        delete windowEventHandlers[event];
     },
     removeDocumentEventHandler:function(event) {
-      delete documentEventHandlers[event];
+        delete documentEventHandlers[event];
     },
     /**
      * Retreive original event handlers that were replaced by Cordova
@@ -200,20 +199,20 @@ var cordova = {
      * Method to fire event from native code
      */
     fireDocumentEvent: function(type, data) {
-      var evt = createEvent(type, data);
-      if (typeof documentEventHandlers[type] != 'undefined') {
-        documentEventHandlers[type].fire(evt);
-      } else {
-        document.dispatchEvent(evt);
-      }
+        var evt = createEvent(type, data);
+        if (typeof documentEventHandlers[type] != 'undefined') {
+            documentEventHandlers[type].fire(evt);
+        } else {
+            document.dispatchEvent(evt);
+        }
     },
     fireWindowEvent: function(type, data) {
-      var evt = createEvent(type,data);
-      if (typeof windowEventHandlers[type] != 'undefined') {
-        windowEventHandlers[type].fire(evt);
-      } else {
-        window.dispatchEvent(evt);
-      }
+        var evt = createEvent(type,data);
+        if (typeof windowEventHandlers[type] != 'undefined') {
+            windowEventHandlers[type].fire(evt);
+        } else {
+            window.dispatchEvent(evt);
+        }
     },
     // TODO: this is Android only; think about how to do this better
     shuttingDown:false,
@@ -319,15 +318,41 @@ var cordova = {
     }
 };
 
+// Adds deprecation warnings to functions of an object (but only logs a message once)
+function deprecateFunctions(obj, objLabel) {
+    var newObj = {};
+    var logHash = {};
+    for (var i in obj) {
+        if (obj.hasOwnProperty(i)) {
+            if (typeof obj[i] == 'function') {
+                newObj[i] = (function(prop){
+                    var oldFunk = obj[prop];
+                    var funkId = objLabel + '_' + prop;
+                    return function() {
+                        if (!logHash[funkId]) {
+                            console.log('[DEPRECATION NOTICE] The "' + objLabel + '" global will be removed in version 2.0, please use lowercase "cordova".');
+                            logHash[funkId] = true;
+                        }
+                        oldFunk.apply(obj, arguments);
+                    };
+                })(i);
+            } else {
+                newObj[i] = (function(prop) { return obj[prop]; })(i);
+            }
+        }
+    }
+    return newObj;
+}
+
 /**
  * Legacy variable for plugin support
  * TODO: remove in 2.0.
  */
 if (!window.PhoneGap) {
-    window.PhoneGap = cordova;
+    window.PhoneGap = deprecateFunctions(cordova, 'PhoneGap');
 }
 if (!window.Cordova) {
-    window.Cordova = cordova;
+    window.Cordova = deprecateFunctions(cordova, 'Cordova');
 }
 
 /**
@@ -437,6 +462,8 @@ module.exports = {
 
 // file: lib\common\channel.js
 define("cordova/channel", function(require, exports, module) {
+var utils = require('cordova/utils');
+
 /**
  * Custom pub-sub "channel" that can have functions subscribed to it
  * This object is used to define and control firing of events for
@@ -484,21 +511,21 @@ define("cordova/channel", function(require, exports, module) {
  *                       context to the Channel.
  */
 var Channel = function(type, opts) {
-        this.type = type;
-        this.handlers = {};
-        this.numHandlers = 0;
-        this.guid = 0;
-        this.fired = false;
-        this.enabled = true;
-        this.events = {
-          onSubscribe:null,
-          onUnsubscribe:null
-        };
-        if (opts) {
-          if (opts.onSubscribe) this.events.onSubscribe = opts.onSubscribe;
-          if (opts.onUnsubscribe) this.events.onUnsubscribe = opts.onUnsubscribe;
-        }
-    },
+    this.type = type;
+    this.handlers = {};
+    this.numHandlers = 0;
+    this.guid = 0;
+    this.fired = false;
+    this.enabled = true;
+    this.events = {
+        onSubscribe:null,
+        onUnsubscribe:null
+    };
+    if (opts) {
+        if (opts.onSubscribe) this.events.onSubscribe = opts.onSubscribe;
+        if (opts.onUnsubscribe) this.events.onUnsubscribe = opts.onUnsubscribe;
+    }
+},
     channel = {
         /**
          * Calls the provided function only after all of the channels specified
@@ -558,8 +585,11 @@ var Channel = function(type, opts) {
                 c.fire();
             }
         }
-    },
-    utils = require('cordova/utils');
+    };
+
+function forceFunction(f) {
+    if (f === null || f === undefined || typeof f != 'function') throw "Function required as first argument!";
+}
 
 /**
  * Subscribes the given function to the channel. Any time that
@@ -570,10 +600,10 @@ var Channel = function(type, opts) {
  */
 Channel.prototype.subscribe = function(f, c, g) {
     // need a function to call
-    if (f === null || f === undefined) { return; }
+    forceFunction(f);
 
     var func = f;
-    if (typeof c == "object" && f instanceof Function) { func = utils.close(c, f); }
+    if (typeof c == "object") { func = utils.close(c, f); }
 
     g = g || func.observer_guid || f.observer_guid || this.guid++;
     func.observer_guid = g;
@@ -590,7 +620,7 @@ Channel.prototype.subscribe = function(f, c, g) {
  */
 Channel.prototype.subscribeOnce = function(f, c) {
     // need a function to call
-    if (f === null || f === undefined) { return; }
+    forceFunction(f);
 
     var g = null;
     var _this = this;
@@ -599,7 +629,7 @@ Channel.prototype.subscribeOnce = function(f, c) {
         _this.unsubscribe(g);
     };
     if (this.fired) {
-        if (typeof c == "object" && f instanceof Function) { f = utils.close(c, f); }
+        if (typeof c == "object") { f = utils.close(c, f); }
         f.apply(this, this.fireArgs);
     } else {
         g = this.subscribe(m);
@@ -612,9 +642,9 @@ Channel.prototype.subscribeOnce = function(f, c) {
  */
 Channel.prototype.unsubscribe = function(g) {
     // need a function to unsubscribe
-    if (g === null || g === undefined) { return; }
+    if (g === null || g === undefined) { throw "You must pass _something_ into Channel.unsubscribe"; }
 
-    if (g instanceof Function) { g = g.observer_guid; }
+    if (typeof g == 'function') { g = g.observer_guid; }
     this.handlers[g] = null;
     delete this.handlers[g];
     this.numHandlers--;
@@ -630,7 +660,7 @@ Channel.prototype.fire = function(e) {
         this.fired = true;
         for (var item in this.handlers) {
             var handler = this.handlers[item];
-            if (handler instanceof Function) {
+            if (typeof handler == 'function') {
                 var rv = (handler.apply(this, arguments)===false);
                 fail = fail || rv;
             }
@@ -676,6 +706,7 @@ channel.waitForInitialization('onCordovaInfoReady');
 channel.waitForInitialization('onCordovaConnectionReady');
 
 module.exports = channel;
+
 });
 
 // file: lib\common\common.js
@@ -868,7 +899,8 @@ var plugins = {
     "Device": require('cordova/plugin/bada/device'),
     "NetworkStatus": require('cordova/plugin/bada/NetworkStatus'),
     "Accelerometer": require('cordova/plugin/bada/Accelerometer'),
-    "Notification": require('cordova/plugin/bada/Notification')
+    "Notification": require('cordova/plugin/bada/Notification'),
+    "Compass": require('cordova/plugin/bada/Compass')
 };
 
 module.exports = function(success, fail, service, action, args) {
@@ -1224,14 +1256,14 @@ function convertOut(contact) {
     var value = contact.birthday;
     if (value !== null) {
         // try to make it a Date object if it is not already
-        if (!value instanceof Date){
+        if (!utils.isDate(value)){
             try {
                 value = new Date(value);
             } catch(exception){
                 value = null;
             }
         }
-        if (value instanceof Date){
+        if (utils.isDate(value)){
             value = value.valueOf(); // convert to milliseconds
         }
         contact.birthday = value;
@@ -1374,6 +1406,7 @@ Contact.prototype.save = function(successCB, errorCB) {
 
 
 module.exports = Contact;
+
 });
 
 // file: lib\common\plugin\ContactAddress.js
@@ -1442,8 +1475,8 @@ define("cordova/plugin/ContactField", function(require, exports, module) {
 */
 var ContactField = function(type, value, pref) {
     this.id = null;
-    this.type = type || null;
-    this.value = value || null;
+    this.type = (type && type.toString()) || null;
+    this.value = (value && value.toString()) || null;
     this.pref = (typeof pref != 'undefined' ? pref : false);
 };
 
@@ -2328,7 +2361,7 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro
         fileKey = options.fileKey;
         fileName = options.fileName;
         mimeType = options.mimeType;
-        if (options.chunkedMode !== null || typeof options.chunkedMode !== "undefined") {
+        if (options.chunkedMode !== null || typeof options.chunkedMode != "undefined") {
             chunkedMode = options.chunkedMode;
         }
         if (options.params) {
@@ -2944,7 +2977,7 @@ var utils = require('cordova/utils'),
  * size {Number} size of the file in bytes
  */
 var MediaFile = function(name, fullPath, type, lastModifiedDate, size){
-  MediaFile.__super__.constructor.apply(this, arguments);
+    MediaFile.__super__.constructor.apply(this, arguments);
 };
 
 utils.extend(MediaFile, File);
@@ -2959,10 +2992,11 @@ MediaFile.prototype.getFormatData = function(successCallback, errorCallback) {
     if (typeof this.fullPath === "undefined" || this.fullPath === null) {
         errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
     } else {
-    exec(successCallback, errorCallback, "Capture", "getFormatData", [this.fullPath, this.type]);
+        exec(successCallback, errorCallback, "Capture", "getFormatData", [this.fullPath, this.type]);
     }
 };
 
+// TODO: can we axe this?
 /**
  * Casts a PluginResult message property  (array of objects) to an array of MediaFile objects
  * (used in Objective-C and Android)
@@ -2970,22 +3004,22 @@ MediaFile.prototype.getFormatData = function(successCallback, errorCallback) {
  * @param {PluginResult} pluginResult
  */
 MediaFile.cast = function(pluginResult) {
-  var mediaFiles = [];
-  var i;
-  for (i=0; i<pluginResult.message.length; i++) {
-    var mediaFile = new MediaFile();
-    mediaFile.name = pluginResult.message[i].name;
-    mediaFile.fullPath = pluginResult.message[i].fullPath;
-    mediaFile.type = pluginResult.message[i].type;
-    mediaFile.lastModifiedDate = pluginResult.message[i].lastModifiedDate;
-    mediaFile.size = pluginResult.message[i].size;
-    mediaFiles.push(mediaFile);
-  }
-  pluginResult.message = mediaFiles;
-  return pluginResult;
+    var mediaFiles = [];
+    for (var i=0; i<pluginResult.message.length; i++) {
+        var mediaFile = new MediaFile();
+        mediaFile.name = pluginResult.message[i].name;
+        mediaFile.fullPath = pluginResult.message[i].fullPath;
+        mediaFile.type = pluginResult.message[i].type;
+        mediaFile.lastModifiedDate = pluginResult.message[i].lastModifiedDate;
+        mediaFile.size = pluginResult.message[i].size;
+        mediaFiles.push(mediaFile);
+    }
+    pluginResult.message = mediaFiles;
+    return pluginResult;
 };
 
 module.exports = MediaFile;
+
 });
 
 // file: lib\common\plugin\MediaFileData.js
@@ -3259,14 +3293,13 @@ module.exports = {
        var self = this;
        var onCreatePreviewNodeSuccess = function(previewObject) {
            var previewDiv = document.getElementById("preview");
-           previewId = previewObject.id;
            previewDiv.appendChild(previewObject);
            previewObject.style.visibility = "visible";
        };
        var error = function(e) {
            alert("An error occured: " + e.message);
        };
-        
+
        var success = function(cams) {
            if (cams.length > 0) {
             self._cams = cams;
@@ -3287,26 +3320,50 @@ module.exports = {
 define("cordova/plugin/bada/Capture", function(require, exports, module) {
 module.exports = {
     captureAudio: function() {
-      console.log("navigator.capture.captureAudio unsupported!");
+        console.log("navigator.capture.captureAudio unsupported!");
     },
     captureVideo: function(success, fail, options) {
-          var camera = navigator.camera._mainCamera;
-      camera.startVideoCapture(success, fail, options);
-          if(options.duration) {
+        var camera = navigator.camera._mainCamera;
+        camera.startVideoCapture(success, fail, options);
+        if(options.duration) {
             Osp.Core.Function.delay(camera.stopVideoCapture, options.duration, camera);
-          }
+        }
     },
     stopVideoCapture: function() {
-      navigator.camera._mainCamera.stopVideoCapture();
+        navigator.camera._mainCamera.stopVideoCapture();
     },
     captureImage: function(success, fail, options) {
-      try {
-        navigator.camera._mainCamera.captureImage(success, fail, options);
-      } catch(exp) {
-        alert("Exception :[" + exp.code + "] " + exp.message);
-      }
+        try {
+            navigator.camera._mainCamera.captureImage(success, fail, options);
+        } catch(exp) {
+            alert("Exception :[" + exp.code + "] " + exp.message);
+        }
     }
-}
+};
+
+});
+
+// file: lib\bada\plugin\bada\Compass.js
+define("cordova/plugin/bada/Compass", function(require, exports, module) {
+var CompassHeading = require('cordova/plugin/CompassHeading');
+
+module.exports = {
+        getHeading: function(compassSuccess, compassError, compassOptions) {
+            if(deviceapis.orientation === undefined) {
+                console.log("navigator.compass.getHeading", "Operation not supported!");
+                return -1;
+            }
+            var success = function(orientation) {
+                var heading = 360 - orientation.alpha;
+                var compassHeading = new CompassHeading(heading, heading, 0);
+                compassSuccess(compassHeading);
+            };
+            var error = function(error) {
+                compassError(error);
+            };
+            deviceapis.orientation.getCurrentOrientation(success, error);
+        }
+};
 
 });
 
@@ -3323,7 +3380,7 @@ module.exports = {
        var Connection = require("cordova/plugin/Connection");
        var connectionType = Connection.NONE;
        deviceapis.devicestatus.getPropertyValue(function(value) {
-               console.log("Device WiFi network status: "+value);
+               //console.log("Device WiFi network status: "+value);
                if(value == "connected") {
                    connectionType = Connection.WIFI;
                }
@@ -3460,27 +3517,27 @@ Device.prototype.getInfo = function(success, fail, args) {
    };
 
    info.getPropertyValue(function(value) {
-           console.log("Device IMEI: "+value);
+           //console.log("Device IMEI: "+value);
            uuid = value;
            checkProperties();
            }, fail, {aspect: "Device", property: "imei"});
    info.getPropertyValue(function(value) {
-           console.log("Device name: "+value);
+           //console.log("Device name: "+value);
            name = value;
            checkProperties();
            }, fail, {aspect: "Device", property: "version"});
    info.getPropertyValue(function(value) {
-           console.log("OperatingSystem name: "+value);
+           //console.log("OperatingSystem name: "+value);
            os_name = value;
            checkProperties();
            }, fail, {aspect: "OperatingSystem", property: "name"});
    info.getPropertyValue(function(value) {
-           console.log("OperatingSystem version: "+value);
+           //console.log("OperatingSystem version: "+value);
            os_version = value;
            checkProperties();
            }, fail, {aspect: "OperatingSystem", property: "version"});
    info.getPropertyValue(function(value) {
-           console.log("OperatingSystem vendor: "+value);
+           //console.log("OperatingSystem vendor: "+value);
            os_vendor = value;
            checkProperties();
            }, fail, {aspect: "OperatingSystem", property: "vendor"});
@@ -3767,6 +3824,7 @@ module.exports = compass;
 define("cordova/plugin/contacts", function(require, exports, module) {
 var exec = require('cordova/exec'),
     ContactError = require('cordova/plugin/ContactError'),
+    utils = require('cordova/utils'),
     Contact = require('cordova/plugin/Contact');
 
 /**
@@ -3786,7 +3844,7 @@ var contacts = {
         if (!successCB) {
             throw new TypeError("You must specify a success callback for the find command.");
         }
-        if (!fields || (fields instanceof Array && fields.length === 0)) {
+        if (!fields || (utils.isArray(fields) && fields.length === 0)) {
             if (typeof errorCB === "function") {
                 errorCB(new ContactError(ContactError.INVALID_ARGUMENT_ERROR));
             }
@@ -3822,6 +3880,7 @@ var contacts = {
 };
 
 module.exports = contacts;
+
 });
 
 // file: lib\common\plugin\geolocation.js
@@ -4152,17 +4211,23 @@ function UUIDcreatePart(length) {
 }
 
 var _self = {
+    isArray:function(a) {
+        return Object.prototype.toString.call(a) == '[object Array]';
+    },
+    isDate:function(d) {
+        return Object.prototype.toString.call(d) == '[object Date]';
+    },
     /**
      * Does a deep clone of the object.
      */
     clone: function(obj) {
-        if(!obj) {
+        if(!obj || typeof obj == 'function' || _self.isDate(obj) || typeof obj != 'object') {
             return obj;
         }
 
         var retVal, i;
 
-        if(obj instanceof Array){
+        if(_self.isArray(obj)){
             retVal = [];
             for(i = 0; i < obj.length; ++i){
                 retVal.push(_self.clone(obj[i]));
@@ -4170,18 +4235,6 @@ var _self = {
             return retVal;
         }
 
-        if (obj instanceof Function) {
-            return obj;
-        }
-
-        if(!(obj instanceof Object)){
-            return obj;
-        }
-
-        if(obj instanceof Date){
-            return obj;
-        }
-
         retVal = {};
         for(i in obj){
             if(!(i in retVal) || retVal[i] != obj[i]) {
@@ -4192,7 +4245,7 @@ var _self = {
     },
 
     close: function(context, func, params) {
-        if (typeof params === 'undefined') {
+        if (typeof params == 'undefined') {
             return function() {
                 return func.apply(context, arguments);
             };
@@ -4243,6 +4296,7 @@ var _self = {
 };
 
 module.exports = _self;
+
 });