openEventsPlatformApp/plugins/cordova-plugin-file/www/ProgressEvent.js
plugins/cordova-plugin-file/www/ProgressEvent.jsRaw
1/*
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20*/
21
22// If ProgressEvent exists in global context, use it already, otherwise use our own polyfill
23// Feature test: See if we can instantiate a native ProgressEvent;
24// if so, use that approach,
25// otherwise fill-in with our own implementation.
26//
27// 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.
28var ProgressEvent = (function() {
29 /*
30 var createEvent = function(data) {
31 var event = document.createEvent('Events');
32 event.initEvent('ProgressEvent', false, false);
33 if (data) {
34 for (var i in data) {
35 if (data.hasOwnProperty(i)) {
36 event[i] = data[i];
37 }
38 }
39 if (data.target) {
40 // TODO: cannot call <some_custom_object>.dispatchEvent
41 // need to first figure out how to implement EventTarget
42 }
43 }
44 return event;
45 };
46 try {
47 var ev = createEvent({type:"abort",target:document});
48 return function ProgressEvent(type, data) {
49 data.type = type;
50 return createEvent(data);
51 };
52 } catch(e){
53 */
54 return function ProgressEvent(type, dict) {
55 this.type = type;
56 this.bubbles = false;
57 this.cancelBubble = false;
58 this.cancelable = false;
59 this.lengthComputable = false;
60 this.loaded = dict && dict.loaded ? dict.loaded : 0;
61 this.total = dict && dict.total ? dict.total : 0;
62 this.target = dict && dict.target ? dict.target : null;
63 };
64 //}
65})();
66
67module.exports = ProgressEvent;