mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-26 03:53:09 +08:00
Ticket #90: Move _createEvent from File to PhoneGap
Got rid of _createEvent from file.js as it is redundant code.
This commit is contained in:
parent
21a34a8980
commit
1fc56921aa
@ -39,22 +39,6 @@ function File(name, fullPath, type, lastModifiedDate, size) {
|
|||||||
this.size = size || 0;
|
this.size = size || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an event object since we can't set target on DOM event.
|
|
||||||
*
|
|
||||||
* @param type
|
|
||||||
* @param target
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
File._createEvent = function(type, target) {
|
|
||||||
// Can't create event object, since we can't set target (its readonly)
|
|
||||||
//var evt = document.createEvent('Events');
|
|
||||||
//evt.initEvent("onload", false, false);
|
|
||||||
var evt = {"type": type};
|
|
||||||
evt.target = target;
|
|
||||||
return evt;
|
|
||||||
};
|
|
||||||
|
|
||||||
function FileError() {
|
function FileError() {
|
||||||
this.code = null;
|
this.code = null;
|
||||||
}
|
}
|
||||||
@ -185,18 +169,15 @@ FileReader.prototype.abort = function() {
|
|||||||
|
|
||||||
// If error callback
|
// If error callback
|
||||||
if (typeof this.onerror === "function") {
|
if (typeof this.onerror === "function") {
|
||||||
evt = File._createEvent("error", this);
|
this.onerror({"type":"error", "target":this});
|
||||||
this.onerror(evt);
|
|
||||||
}
|
}
|
||||||
// If abort callback
|
// If abort callback
|
||||||
if (typeof this.onabort === "function") {
|
if (typeof this.onabort === "function") {
|
||||||
evt = File._createEvent("abort", this);
|
this.oneabort({"type":"abort", "target":this});
|
||||||
this.onabort(evt);
|
|
||||||
}
|
}
|
||||||
// If load end callback
|
// If load end callback
|
||||||
if (typeof this.onloadend === "function") {
|
if (typeof this.onloadend === "function") {
|
||||||
evt = File._createEvent("loadend", this);
|
this.onloadend({"type":"loadend", "target":this});
|
||||||
this.onloadend(evt);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -219,8 +200,7 @@ FileReader.prototype.readAsText = function(file, encoding) {
|
|||||||
|
|
||||||
// If loadstart callback
|
// If loadstart callback
|
||||||
if (typeof this.onloadstart === "function") {
|
if (typeof this.onloadstart === "function") {
|
||||||
var evt = File._createEvent("loadstart", this);
|
this.onloadstart({"type":"loadstart", "target":this});
|
||||||
this.onloadstart(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default encoding is UTF-8
|
// Default encoding is UTF-8
|
||||||
@ -245,8 +225,6 @@ FileReader.prototype.readAsText = function(file, encoding) {
|
|||||||
|
|
||||||
// If onload callback
|
// If onload callback
|
||||||
if (typeof me.onload === "function") {
|
if (typeof me.onload === "function") {
|
||||||
evt = File._createEvent("load", me);
|
|
||||||
me.onload(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DONE state
|
// DONE state
|
||||||
@ -254,8 +232,7 @@ FileReader.prototype.readAsText = function(file, encoding) {
|
|||||||
|
|
||||||
// If onloadend callback
|
// If onloadend callback
|
||||||
if (typeof me.onloadend === "function") {
|
if (typeof me.onloadend === "function") {
|
||||||
evt = File._createEvent("loadend", me);
|
me.onloadend({"type":"loadend", "target":me});
|
||||||
me.onloadend(evt);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -272,8 +249,7 @@ FileReader.prototype.readAsText = function(file, encoding) {
|
|||||||
|
|
||||||
// If onerror callback
|
// If onerror callback
|
||||||
if (typeof me.onerror === "function") {
|
if (typeof me.onerror === "function") {
|
||||||
evt = File._createEvent("error", me);
|
me.onerror({"type":"error", "target":me});
|
||||||
me.onerror(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DONE state
|
// DONE state
|
||||||
@ -281,8 +257,7 @@ FileReader.prototype.readAsText = function(file, encoding) {
|
|||||||
|
|
||||||
// If onloadend callback
|
// If onloadend callback
|
||||||
if (typeof me.onloadend === "function") {
|
if (typeof me.onloadend === "function") {
|
||||||
evt = File._createEvent("loadend", me);
|
me.onloadend({"type":"loadend", "target":me});
|
||||||
me.onloadend(evt);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -309,8 +284,7 @@ FileReader.prototype.readAsDataURL = function(file) {
|
|||||||
|
|
||||||
// If loadstart callback
|
// If loadstart callback
|
||||||
if (typeof this.onloadstart === "function") {
|
if (typeof this.onloadstart === "function") {
|
||||||
var evt = File._createEvent("loadstart", this);
|
this.onloadstart({"type":"loadstart", "target":this});
|
||||||
this.onloadstart(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var me = this;
|
var me = this;
|
||||||
@ -332,8 +306,7 @@ FileReader.prototype.readAsDataURL = function(file) {
|
|||||||
|
|
||||||
// If onload callback
|
// If onload callback
|
||||||
if (typeof me.onload === "function") {
|
if (typeof me.onload === "function") {
|
||||||
evt = File._createEvent("load", me);
|
me.onload({"type":"load", "target":me});
|
||||||
me.onload(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DONE state
|
// DONE state
|
||||||
@ -341,8 +314,7 @@ FileReader.prototype.readAsDataURL = function(file) {
|
|||||||
|
|
||||||
// If onloadend callback
|
// If onloadend callback
|
||||||
if (typeof me.onloadend === "function") {
|
if (typeof me.onloadend === "function") {
|
||||||
evt = File._createEvent("loadend", me);
|
me.onloadend({"type":"loadend", "target":me});
|
||||||
me.onloadend(evt);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -359,8 +331,7 @@ FileReader.prototype.readAsDataURL = function(file) {
|
|||||||
|
|
||||||
// If onerror callback
|
// If onerror callback
|
||||||
if (typeof me.onerror === "function") {
|
if (typeof me.onerror === "function") {
|
||||||
evt = File._createEvent("error", me);
|
me.onerror({"type":"error", "target":me});
|
||||||
me.onerror(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DONE state
|
// DONE state
|
||||||
@ -368,8 +339,7 @@ FileReader.prototype.readAsDataURL = function(file) {
|
|||||||
|
|
||||||
// If onloadend callback
|
// If onloadend callback
|
||||||
if (typeof me.onloadend === "function") {
|
if (typeof me.onloadend === "function") {
|
||||||
evt = File._createEvent("loadend", me);
|
me.onloadend({"type":"loadend", "target":me});
|
||||||
me.onloadend(evt);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -456,115 +426,21 @@ FileWriter.prototype.abort = function() {
|
|||||||
|
|
||||||
// If error callback
|
// If error callback
|
||||||
if (typeof this.onerror === "function") {
|
if (typeof this.onerror === "function") {
|
||||||
evt = File._createEvent("error", this);
|
this.onerror({"type":"error", "target":this});
|
||||||
this.onerror(evt);
|
|
||||||
}
|
}
|
||||||
// If abort callback
|
// If abort callback
|
||||||
if (typeof this.onabort === "function") {
|
if (typeof this.onabort === "function") {
|
||||||
evt = File._createEvent("abort", this);
|
this.oneabort({"type":"abort", "target":this});
|
||||||
this.onabort(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.readyState = FileWriter.DONE;
|
this.readyState = FileWriter.DONE;
|
||||||
|
|
||||||
// If write end callback
|
// If write end callback
|
||||||
if (typeof this.onwriteend == "function") {
|
if (typeof this.onwriteend == "function") {
|
||||||
evt = File._createEvent("writeend", this);
|
this.onwriteend({"type":"writeend", "target":this});
|
||||||
this.onwriteend(evt);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @Deprecated: use write instead
|
|
||||||
*
|
|
||||||
* @param file to write the data to
|
|
||||||
* @param text to be written
|
|
||||||
* @param bAppend if true write to end of file, otherwise overwrite the file
|
|
||||||
*/
|
|
||||||
FileWriter.prototype.writeAsText = function(file, text, bAppend) {
|
|
||||||
// Throw an exception if we are already writing a file
|
|
||||||
if (this.readyState === FileWriter.WRITING) {
|
|
||||||
throw FileError.INVALID_STATE_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bAppend !== true) {
|
|
||||||
bAppend = false; // for null values
|
|
||||||
}
|
|
||||||
|
|
||||||
this.fileName = file;
|
|
||||||
|
|
||||||
// WRITING state
|
|
||||||
this.readyState = FileWriter.WRITING;
|
|
||||||
|
|
||||||
var me = this;
|
|
||||||
|
|
||||||
// If onwritestart callback
|
|
||||||
if (typeof me.onwritestart === "function") {
|
|
||||||
var evt = File._createEvent("writestart", me);
|
|
||||||
me.onwritestart(evt);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write file
|
|
||||||
navigator.fileMgr.writeAsText(file, text, bAppend,
|
|
||||||
|
|
||||||
// Success callback
|
|
||||||
function(r) {
|
|
||||||
var evt;
|
|
||||||
|
|
||||||
// If DONE (cancelled), then don't do anything
|
|
||||||
if (me.readyState === FileWriter.DONE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save result
|
|
||||||
me.result = r;
|
|
||||||
|
|
||||||
// If onwrite callback
|
|
||||||
if (typeof me.onwrite === "function") {
|
|
||||||
evt = File._createEvent("write", me);
|
|
||||||
me.onwrite(evt);
|
|
||||||
}
|
|
||||||
|
|
||||||
// DONE state
|
|
||||||
me.readyState = FileWriter.DONE;
|
|
||||||
|
|
||||||
// If onwriteend callback
|
|
||||||
if (typeof me.onwriteend === "function") {
|
|
||||||
evt = File._createEvent("writeend", me);
|
|
||||||
me.onwriteend(evt);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// Error callback
|
|
||||||
function(e) {
|
|
||||||
var evt;
|
|
||||||
|
|
||||||
// If DONE (cancelled), then don't do anything
|
|
||||||
if (me.readyState === FileWriter.DONE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save error
|
|
||||||
me.error = e;
|
|
||||||
|
|
||||||
// If onerror callback
|
|
||||||
if (typeof me.onerror === "function") {
|
|
||||||
evt = File._createEvent("error", me);
|
|
||||||
me.onerror(evt);
|
|
||||||
}
|
|
||||||
|
|
||||||
// DONE state
|
|
||||||
me.readyState = FileWriter.DONE;
|
|
||||||
|
|
||||||
// If onwriteend callback
|
|
||||||
if (typeof me.onwriteend === "function") {
|
|
||||||
evt = File._createEvent("writeend", me);
|
|
||||||
me.onwriteend(evt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes data to the file
|
* Writes data to the file
|
||||||
*
|
*
|
||||||
@ -583,8 +459,7 @@ FileWriter.prototype.write = function(text) {
|
|||||||
|
|
||||||
// If onwritestart callback
|
// If onwritestart callback
|
||||||
if (typeof me.onwritestart === "function") {
|
if (typeof me.onwritestart === "function") {
|
||||||
var evt = File._createEvent("writestart", me);
|
me.onwritestart({"type":"writestart", "target":me});
|
||||||
me.onwritestart(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write file
|
// Write file
|
||||||
@ -605,8 +480,7 @@ FileWriter.prototype.write = function(text) {
|
|||||||
|
|
||||||
// If onwrite callback
|
// If onwrite callback
|
||||||
if (typeof me.onwrite === "function") {
|
if (typeof me.onwrite === "function") {
|
||||||
evt = File._createEvent("write", me);
|
me.onwrite({"type":"write", "target":me});
|
||||||
me.onwrite(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DONE state
|
// DONE state
|
||||||
@ -614,8 +488,7 @@ FileWriter.prototype.write = function(text) {
|
|||||||
|
|
||||||
// If onwriteend callback
|
// If onwriteend callback
|
||||||
if (typeof me.onwriteend === "function") {
|
if (typeof me.onwriteend === "function") {
|
||||||
evt = File._createEvent("writeend", me);
|
me.onwriteend({"type":"writeend", "target":me});
|
||||||
me.onwriteend(evt);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -633,8 +506,7 @@ FileWriter.prototype.write = function(text) {
|
|||||||
|
|
||||||
// If onerror callback
|
// If onerror callback
|
||||||
if (typeof me.onerror === "function") {
|
if (typeof me.onerror === "function") {
|
||||||
evt = File._createEvent("error", me);
|
me.onerror({"type":"error", "target":me});
|
||||||
me.onerror(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DONE state
|
// DONE state
|
||||||
@ -642,8 +514,7 @@ FileWriter.prototype.write = function(text) {
|
|||||||
|
|
||||||
// If onwriteend callback
|
// If onwriteend callback
|
||||||
if (typeof me.onwriteend === "function") {
|
if (typeof me.onwriteend === "function") {
|
||||||
evt = File._createEvent("writeend", me);
|
me.onwriteend({"type":"writeend", "target":me});
|
||||||
me.onwriteend(evt);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -703,8 +574,7 @@ FileWriter.prototype.truncate = function(size) {
|
|||||||
|
|
||||||
// If onwritestart callback
|
// If onwritestart callback
|
||||||
if (typeof me.onwritestart === "function") {
|
if (typeof me.onwritestart === "function") {
|
||||||
var evt = File._createEvent("writestart", me);
|
me.onwritestart({"type":"writestart", "target":this});
|
||||||
me.onwritestart(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write file
|
// Write file
|
||||||
@ -724,8 +594,7 @@ FileWriter.prototype.truncate = function(size) {
|
|||||||
|
|
||||||
// If onwrite callback
|
// If onwrite callback
|
||||||
if (typeof me.onwrite === "function") {
|
if (typeof me.onwrite === "function") {
|
||||||
evt = File._createEvent("write", me);
|
me.onwrite({"type":"write", "target":me});
|
||||||
me.onwrite(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DONE state
|
// DONE state
|
||||||
@ -733,8 +602,7 @@ FileWriter.prototype.truncate = function(size) {
|
|||||||
|
|
||||||
// If onwriteend callback
|
// If onwriteend callback
|
||||||
if (typeof me.onwriteend === "function") {
|
if (typeof me.onwriteend === "function") {
|
||||||
evt = File._createEvent("writeend", me);
|
me.onwriteend({"type":"writeend", "target":me});
|
||||||
me.onwriteend(evt);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -751,8 +619,7 @@ FileWriter.prototype.truncate = function(size) {
|
|||||||
|
|
||||||
// If onerror callback
|
// If onerror callback
|
||||||
if (typeof me.onerror === "function") {
|
if (typeof me.onerror === "function") {
|
||||||
evt = File._createEvent("error", me);
|
me.onerror({"type":"error", "target":me});
|
||||||
me.onerror(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DONE state
|
// DONE state
|
||||||
@ -760,8 +627,7 @@ FileWriter.prototype.truncate = function(size) {
|
|||||||
|
|
||||||
// If onwriteend callback
|
// If onwriteend callback
|
||||||
if (typeof me.onwriteend === "function") {
|
if (typeof me.onwriteend === "function") {
|
||||||
evt = File._createEvent("writeend", me);
|
me.onwriteend({"type":"writeend", "target":me});
|
||||||
me.onwriteend(evt);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user