incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject [19/35] git commit: do a little feature detection to use either built-in ProgressEvents or our own polyfill in FileWriter
Date Thu, 23 Feb 2012 17:53:19 GMT
do a little feature detection to use either built-in ProgressEvents or our own polyfill in
FileWriter


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/428521a1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/428521a1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/428521a1

Branch: refs/heads/ios
Commit: 428521a1b5725d9d436024a088c2bcf04e2f88c1
Parents: 2c3d0bb
Author: Fil Maj <filip.maj@nitobi.com>
Authored: Fri Feb 17 10:39:41 2012 -0800
Committer: Fil Maj <filip.maj@nitobi.com>
Committed: Fri Feb 17 10:39:41 2012 -0800

----------------------------------------------------------------------
 lib/plugin/FileWriter.js |   30 +++++++++++++++++++++++++++---
 1 files changed, 27 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/428521a1/lib/plugin/FileWriter.js
----------------------------------------------------------------------
diff --git a/lib/plugin/FileWriter.js b/lib/plugin/FileWriter.js
index b85d885..83c94bd 100644
--- a/lib/plugin/FileWriter.js
+++ b/lib/plugin/FileWriter.js
@@ -1,7 +1,31 @@
 var exec = require('cordova/exec'),
-    FileError = require('cordova/plugin/FileError'),
-    // if ProgressEvent exists in global context, use it already, otherwise use our own polyfill
-    ProgressEvent = window.ProgressEvent || require('cordova/plugin/ProgressEvent');
+    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');
+    }
+})();
 
 /**
  * This class writes to the mobile device file system.


Mime
View raw message