You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2012/02/23 18:53:19 UTC

[18/35] git commit: fixes to progressevent and filereader/writer

fixes to progressevent and filereader/writer


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/99676a40
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/99676a40
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/99676a40

Branch: refs/heads/ios
Commit: 99676a4008f5404876a8017f024ad58e07aea93f
Parents: 428521a
Author: Fil Maj <fi...@nitobi.com>
Authored: Fri Feb 17 11:09:43 2012 -0800
Committer: Fil Maj <fi...@nitobi.com>
Committed: Fri Feb 17 11:09:43 2012 -0800

----------------------------------------------------------------------
 lib/plugin/FileReader.js    |    4 +--
 lib/plugin/FileWriter.js    |   27 +------------------
 lib/plugin/ProgressEvent.js |   54 +++++++++++++++++++++++++++++++-------
 3 files changed, 46 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/99676a40/lib/plugin/FileReader.js
----------------------------------------------------------------------
diff --git a/lib/plugin/FileReader.js b/lib/plugin/FileReader.js
index 353ecb3..d2d0017 100644
--- a/lib/plugin/FileReader.js
+++ b/lib/plugin/FileReader.js
@@ -1,7 +1,6 @@
 var exec = require('cordova/exec'),
     FileError = require('cordova/plugin/FileError'),
-    // if ProgressEvent exists natively in global context then use that, otherwise use our polyfill
-    ProgressEvent = window.ProgressEvent || require('cordova/plugin/ProgressEvent');
+    ProgressEvent = require('cordova/plugin/ProgressEvent');
 
 /**
  * This class reads the mobile device file system.
@@ -99,7 +98,6 @@ FileReader.prototype.readAsText = function(file, encoding) {
             if (me.readyState === FileReader.DONE) {
                 return;
             }
-
             // Save result
             me.result = r;
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/99676a40/lib/plugin/FileWriter.js
----------------------------------------------------------------------
diff --git a/lib/plugin/FileWriter.js b/lib/plugin/FileWriter.js
index 83c94bd..97df438 100644
--- a/lib/plugin/FileWriter.js
+++ b/lib/plugin/FileWriter.js
@@ -1,31 +1,6 @@
 var exec = require('cordova/exec'),
     FileError = require('cordova/plugin/FileError');
-
-// If ProgressEvent exists in global context, use it already, otherwise use our own polyfill
-// Feature test: See if we can instantiate a native ProgressEvent; if so, use that approach, otherwise fill-in with our own implementation.
-var ProgressEvent = (function() {
-    var createEvent = function(data) {
-      var event = document.createEvent('Events');
-      event.initEvent('ProgressEvent', false, false);
-      if (data) {
-        for (var i in data) {
-          if (data.hasOwnProperty(i)) {
-            event[i] = data[i];
-          }
-        }
-      }
-      return event;
-    };
-    try {
-      var ev = createEvent({type:"abort",target:document});
-      return function(type, data) {
-          data.type = type;
-          return createEvent(data);
-      };
-    } catch(e){
-      return require('cordova/plugin/ProgressEvent');
-    }
-})();
+    ProgressEvent = require('cordova/plugin/ProgressEvent');
 
 /**
  * This class writes to the mobile device file system.

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/99676a40/lib/plugin/ProgressEvent.js
----------------------------------------------------------------------
diff --git a/lib/plugin/ProgressEvent.js b/lib/plugin/ProgressEvent.js
index 6ef219b..d8e41c1 100644
--- a/lib/plugin/ProgressEvent.js
+++ b/lib/plugin/ProgressEvent.js
@@ -1,12 +1,46 @@
-function ProgressEvent(type, dict) {
-    this.type = type;
-    this.bubbles = false;
-    this.cancelBubble = false;
-    this.cancelable = false;
-    this.lengthComputable = false;
-    this.loaded = dict && dict.loaded ? dict.loaded : 0;
-    this.total = dict && dict.total ? dict.total : 0;
-    this.target = dict && dict.target ? dict.target : null;
-}
+// If ProgressEvent exists in global context, use it already, otherwise use our own polyfill
+// Feature test: See if we can instantiate a native ProgressEvent;
+// if so, use that approach,
+// otherwise fill-in with our own implementation.
+//
+// NOTE: right now we always fill in with our own. Down the road would be nice if we can use whatever is native in the webview.
+var ProgressEvent = (function() {
+    /*
+    var createEvent = function(data) {
+        var event = document.createEvent('Events');
+        event.initEvent('ProgressEvent', false, false);
+        if (data) {
+            for (var i in data) {
+                if (data.hasOwnProperty(i)) {
+                    event[i] = data[i];
+                }
+            }
+            if (data.target) {
+                // TODO: cannot call <some_custom_object>.dispatchEvent
+                // need to first figure out how to implement EventTarget
+            }
+        }
+        return event;
+    };
+    try {
+        var ev = createEvent({type:"abort",target:document});
+        return function ProgressEvent(type, data) {
+            data.type = type;
+            return createEvent(data);
+        };
+    } catch(e){
+    */
+        return function ProgressEvent(type, dict) {
+            this.type = type;
+            this.bubbles = false;
+            this.cancelBubble = false;
+            this.cancelable = false;
+            this.lengthComputable = false;
+            this.loaded = dict && dict.loaded ? dict.loaded : 0;
+            this.total = dict && dict.total ? dict.total : 0;
+            this.target = dict && dict.target ? dict.target : null;
+        };
+    //}
+})();
 
 module.exports = ProgressEvent;