Skip to content

Commit

Permalink
Linting the JS code
Browse files Browse the repository at this point in the history
  • Loading branch information
macdonst committed Nov 16, 2011
1 parent 29c7e12 commit 5406d6c
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 42 deletions.
31 changes: 15 additions & 16 deletions framework/assets/js/battery.js
Expand Up @@ -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);
}
Expand All @@ -98,21 +96,22 @@ 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 {
PhoneGap.fireWindowEvent("batterycritical", info);
}
}
}
me._level = info.level;
me._level = level;
me._isPlugged = info.isPlugged;
}
};
Expand Down
6 changes: 3 additions & 3 deletions framework/assets/js/camera.js
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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();
Expand Down
3 changes: 0 additions & 3 deletions framework/assets/js/capture.js
Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions framework/assets/js/compass.js
Expand Up @@ -20,15 +20,15 @@
if (!PhoneGap.hasResource("compass")) {
PhoneGap.addResource("compass");

CompassError = function(){
var CompassError = function(){
this.code = null;
};

// Capture error codes
CompassError.COMPASS_INTERNAL_ERR = 0;
CompassError.COMPASS_NOT_SUPPORTED = 20;

CompassHeading = function() {
var CompassHeading = function() {
this.magneticHeading = null;
this.trueHeading = null;
this.headingAccuracy = null;
Expand Down
22 changes: 14 additions & 8 deletions framework/assets/js/file.js
Expand Up @@ -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});
}
};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
});
Expand Down Expand Up @@ -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;
}
});
}
}
2 changes: 1 addition & 1 deletion framework/assets/js/filetransfer.js
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion framework/assets/js/media.js
Expand Up @@ -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;
}
};
Expand Down
6 changes: 3 additions & 3 deletions framework/assets/js/network.js
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions framework/assets/js/phonegap.js.base
Expand Up @@ -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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion framework/assets/js/storage.js
Expand Up @@ -428,7 +428,7 @@ PhoneGap.addConstructor(function() {
else {
return db;
}
}
};
}

if (typeof window.localStorage === "undefined") {
Expand Down
4 changes: 2 additions & 2 deletions framework/build.xml
Expand Up @@ -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 -->
Expand Down

0 comments on commit 5406d6c

Please sign in to comment.