Linting the JS code

This commit is contained in:
macdonst 2011-11-08 06:54:15 +08:00
parent 29c7e12505
commit 5406d6c98f
11 changed files with 44 additions and 42 deletions

View File

@ -49,35 +49,33 @@ Battery.prototype.eventHandler = function(eventType, handler, add) {
// Register the event listener in the proper array
if (eventType === "batterystatus") {
var pos = me._batteryListener.indexOf(handler);
if (pos === -1) {
me._batteryListener.push(handler);
if (me._batteryListener.indexOf(handler) === -1) {
me._batteryListener.push(handler);
}
} else if (eventType === "batterylow") {
var pos = me._lowListener.indexOf(handler);
if (pos === -1) {
me._lowListener.push(handler);
if (me._lowListener.indexOf(handler) === -1) {
me._lowListener.push(handler);
}
} else if (eventType === "batterycritical") {
var pos = me._criticalListener.indexOf(handler);
if (pos === -1) {
me._criticalListener.push(handler);
if (me._criticalListener.indexOf(handler) === -1) {
me._criticalListener.push(handler);
}
}
} else {
var pos = -1;
// Remove the event listener from the proper array
if (eventType === "batterystatus") {
var pos = me._batteryListener.indexOf(handler);
pos = me._batteryListener.indexOf(handler);
if (pos > -1) {
me._batteryListener.splice(pos, 1);
}
} else if (eventType === "batterylow") {
var pos = me._lowListener.indexOf(handler);
pos = me._lowListener.indexOf(handler);
if (pos > -1) {
me._lowListener.splice(pos, 1);
}
} else if (eventType === "batterycritical") {
var pos = me._criticalListener.indexOf(handler);
pos = me._criticalListener.indexOf(handler);
if (pos > -1) {
me._criticalListener.splice(pos, 1);
}
@ -98,13 +96,14 @@ Battery.prototype.eventHandler = function(eventType, handler, add) {
Battery.prototype._status = function(info) {
if (info) {
var me = this;
if (me._level != info.level || me._isPlugged != info.isPlugged) {
var level = info.level;
if (me._level !== level || me._isPlugged !== info.isPlugged) {
// Fire batterystatus event
PhoneGap.fireWindowEvent("batterystatus", info);
// Fire low battery event
if (info.level == 20 || info.level == 5) {
if (info.level == 20) {
if (level === 20 || level === 5) {
if (level === 20) {
PhoneGap.fireWindowEvent("batterylow", info);
}
else {
@ -112,7 +111,7 @@ Battery.prototype._status = function(info) {
}
}
}
me._level = info.level;
me._level = level;
me._isPlugged = info.isPlugged;
}
};

View File

@ -124,7 +124,7 @@ Camera.prototype.getPicture = function(successCallback, errorCallback, options)
options.quality = 80;
}
if (options.maxResolution === null || typeof options.maxResolution === "undefined") {
options.maxResolution = 0;
options.maxResolution = 0;
}
if (options.destinationType === null || typeof options.destinationType === "undefined") {
options.destinationType = Camera.DestinationType.DATA_URL;
@ -141,7 +141,7 @@ Camera.prototype.getPicture = function(successCallback, errorCallback, options)
if (options.targetWidth === null || typeof options.targetWidth === "undefined") {
options.targetWidth = -1;
}
else if (typeof options.targetWidth == "string") {
else if (typeof options.targetWidth === "string") {
var width = new Number(options.targetWidth);
if (isNaN(width) === false) {
options.targetWidth = width.valueOf();
@ -150,7 +150,7 @@ Camera.prototype.getPicture = function(successCallback, errorCallback, options)
if (options.targetHeight === null || typeof options.targetHeight === "undefined") {
options.targetHeight = -1;
}
else if (typeof options.targetHeight == "string") {
else if (typeof options.targetHeight === "string") {
var height = new Number(options.targetHeight);
if (isNaN(height) === false) {
options.targetHeight = height.valueOf();

View File

@ -192,9 +192,6 @@ var CaptureAudioOptions = function(){
};
PhoneGap.addConstructor(function(){
if (typeof navigator.device === "undefined") {
navigator.device = window.device = new Device();
}
if (typeof navigator.device.capture === "undefined") {
navigator.device.capture = window.device.capture = new Capture();
}

View File

@ -20,7 +20,7 @@
if (!PhoneGap.hasResource("compass")) {
PhoneGap.addResource("compass");
CompassError = function(){
var CompassError = function(){
this.code = null;
};
@ -28,7 +28,7 @@ CompassError = function(){
CompassError.COMPASS_INTERNAL_ERR = 0;
CompassError.COMPASS_NOT_SUPPORTED = 20;
CompassHeading = function() {
var CompassHeading = function() {
this.magneticHeading = null;
this.trueHeading = null;
this.headingAccuracy = null;

View File

@ -385,7 +385,7 @@ FileWriter.prototype.abort = function() {
this.readyState = FileWriter.DONE;
// If write end callback
if (typeof this.onwriteend == "function") {
if (typeof this.onwriteend === "function") {
this.onwriteend({"type":"writeend", "target":this});
}
};
@ -843,14 +843,14 @@ FileEntry.prototype.createWriter = function(successCallback, errorCallback) {
var writer = new FileWriter(filePointer);
if (writer.fileName === null || writer.fileName === "") {
if (typeof errorCallback == "function") {
if (typeof errorCallback === "function") {
errorCallback({
"code": FileError.INVALID_STATE_ERR
});
}
}
if (typeof successCallback == "function") {
if (typeof successCallback === "function") {
successCallback(writer);
}
}, errorCallback);
@ -885,7 +885,7 @@ LocalFileSystem.APPLICATION = 3;
*/
LocalFileSystem.prototype.requestFileSystem = function(type, size, successCallback, errorCallback) {
if (type < 0 || type > 3) {
if (typeof errorCallback == "function") {
if (typeof errorCallback === "function") {
errorCallback({
"code": FileError.SYNTAX_ERR
});
@ -993,8 +993,14 @@ LocalFileSystem.prototype._castDate = function(pluginResult) {
PhoneGap.addConstructor(function() {
var pgLocalFileSystem = new LocalFileSystem();
// Needed for cast methods
if(typeof window.localFileSystem == "undefined") window.localFileSystem = pgLocalFileSystem;
if(typeof window.requestFileSystem == "undefined") window.requestFileSystem = pgLocalFileSystem.requestFileSystem;
if(typeof window.resolveLocalFileSystemURI == "undefined") window.resolveLocalFileSystemURI = pgLocalFileSystem.resolveLocalFileSystemURI;
if (typeof window.localFileSystem === "undefined") {
window.localFileSystem = pgLocalFileSystem;
}
if (typeof window.requestFileSystem === "undefined") {
window.requestFileSystem = pgLocalFileSystem.requestFileSystem;
}
if (typeof window.resolveLocalFileSystemURI === "undefined") {
window.resolveLocalFileSystemURI = pgLocalFileSystem.resolveLocalFileSystemURI;
}
});
}
}

View File

@ -69,7 +69,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) {

View File

@ -226,7 +226,7 @@ PhoneGap.Media.onStatus = function(id, msg, value) {
media.errorCallback({"code":value});
}
}
else if (msg == Media.MEDIA_POSITION) {
else if (msg === Media.MEDIA_POSITION) {
media._position = value;
}
};

View File

@ -35,7 +35,7 @@ var Connection = function() {
this.getInfo(
function(type) {
// Need to send events if we are on or offline
if (type == "none") {
if (type === "none") {
// set a timer if still offline at the end of timer send the offline event
me._timer = setTimeout(function(){
me.type = type;
@ -44,7 +44,7 @@ var Connection = function() {
}, me.timeout);
} else {
// If there is a current offline event pending clear it
if (me._timer != null) {
if (me._timer !== null) {
clearTimeout(me._timer);
me._timer = null;
}
@ -91,7 +91,7 @@ Connection.prototype.getInfo = function(successCallback, errorCallback) {
PhoneGap.addConstructor(function() {
if (typeof navigator.network === "undefined") {
navigator.network = new Object();
navigator.network = {};
}
if (typeof navigator.network.connection === "undefined") {
navigator.network.connection = new Connection();

View File

@ -386,7 +386,7 @@ PhoneGap.m_window_addEventListener = window.addEventListener;
*/
PhoneGap.addWindowEventHandler = function(event, callback) {
PhoneGap.windowEventHandler[event] = callback;
}
};
/**
* Add a custom document event handler.
@ -396,7 +396,7 @@ PhoneGap.addWindowEventHandler = function(event, callback) {
*/
PhoneGap.addDocumentEventHandler = function(event, callback) {
PhoneGap.documentEventHandler[event] = callback;
}
};
/**
* Intercept adding document event listeners and handle our own

View File

@ -428,7 +428,7 @@ PhoneGap.addConstructor(function() {
else {
return db;
}
}
};
}
if (typeof window.localStorage === "undefined") {

View File

@ -130,8 +130,8 @@
<!-- Create uncompressed JS file -->
<concat destfile="assets/www/phonegap-${version}.js">
<fileset dir="assets/js" includes="phonegap.js.base" />
<fileset dir="assets/js" includes="*.js" />
<filelist dir="assets/js" files="phonegap.js.base,device.js"/>
<fileset dir="assets/js" includes="*.js" excludes="phonegap.js.base,device.js"/>
</concat>
<!-- update project files to reference phonegap-x.x.x.min.js -->