Skip to content
This repository has been archived by the owner on Apr 18, 2019. It is now read-only.

Commit

Permalink
Making all JS files pass jshint.
Browse files Browse the repository at this point in the history
  • Loading branch information
bshepherdson committed Jan 6, 2014
1 parent cd3ae66 commit cc307cc
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 113 deletions.
6 changes: 3 additions & 3 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"noempty": true,
"nonew": true,
"plusplus": false,
"quotmark": "double",
"quotmark": "single",
"strict": false,
"trailing": true,
"undef": true,
Expand All @@ -27,5 +27,5 @@
"devel":true,

//other
"globals": {"angular": false, "Q": false, "cordova" : false }
}
"globals": {"angular": false, "cordova" : false }
}
6 changes: 3 additions & 3 deletions www/cdvah/js/AddCtrl.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(function(){
"use strict";
'use strict';

/* global myApp */
myApp.controller("AddCtrl", ["$q", "notifier", "$location", "$rootScope", "$scope", "$window", "AppsService", function($q, notifier, $location, $rootScope, $scope, $window, AppsService) {
myApp.controller('AddCtrl', ['$q', 'notifier', '$location', '$rootScope', '$scope', '$window', 'AppsService', function($q, notifier, $location, $rootScope, $scope, $window, AppsService) {

$rootScope.appTitle = 'Add App';

Expand Down Expand Up @@ -30,7 +30,7 @@
};

// True if the optional barcodescanner plugin is installed.
$scope.qr_enabled = !!(cordova.plugins && cordova.plugins.barcodeScanner);
$scope.qrEnabled = !!(cordova.plugins && cordova.plugins.barcodeScanner);

// Scans a QR code, placing the URL into the currently selected of source and pattern.
$scope.fetchQR = function() {
Expand Down
10 changes: 6 additions & 4 deletions www/cdvah/js/AppsService.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function() {
"use strict";
'use strict';
/* global myApp */
myApp.factory("AppsService", ["$q", "ResourcesLoader", "INSTALL_DIRECTORY", "APPS_JSON", "pluginMetadata", function($q, ResourcesLoader, INSTALL_DIRECTORY, APPS_JSON, pluginMetadata) {
myApp.factory('AppsService', ['$q', 'ResourcesLoader', 'INSTALL_DIRECTORY', 'APPS_JSON', 'pluginMetadata', function($q, ResourcesLoader, INSTALL_DIRECTORY, APPS_JSON, pluginMetadata) {

// Map of type -> installer.
var _installerFactories = {};
Expand All @@ -11,7 +11,8 @@
function createInstallHandlersFromJson(json) {
var appList = json.appList || [];
var ret = [];
for (var i = 0, entry; entry = appList[i]; ++i) {
for (var i = 0; i < appList.length; i++) {
var entry = appList[i];
var factory = _installerFactories[entry.appType];
var installer = factory.createFromJson(entry.appUrl, entry.appId);
installer.lastUpdated = entry.lastUpdated && new Date(entry.lastUpdated);
Expand Down Expand Up @@ -49,7 +50,8 @@
var appsJson = {
'appList': []
};
for (var i = 0, installer; installer = _installers[i]; ++i) {
for (var i = 0; i < _installers.length; ++i) {
var installer = _installers[i];
appsJson.appList.push({
'appId' : installer.appId,
'appType' : installer.type,
Expand Down
22 changes: 11 additions & 11 deletions www/cdvah/js/CdvhPackageHandler.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
(function(){
"use strict";
'use strict';
/* global myApp */
myApp.run(["$q", "AppsService", "ResourcesLoader", "ContextMenuInjectScript", function($q, AppsService, ResourcesLoader, ContextMenuInjectScript){
myApp.run(['$q', 'AppsService', 'ResourcesLoader', 'ContextMenuInjectScript', function($q, AppsService, ResourcesLoader, ContextMenuInjectScript){

var platformId = cordova.require("cordova/platform").id;
var platformId = cordova.require('cordova/platform').id;

function copyFile(startUrl, targetLocation){
/************ Begin Work around for File system bug ************/
if(targetLocation.indexOf("file://") === 0) {
targetLocation = targetLocation.substring("file://".length);
if(targetLocation.indexOf('file://') === 0) {
targetLocation = targetLocation.substring('file://'.length);
}
/************ End Work around for File system bug **************/
return ResourcesLoader.xhrGet(startUrl)
Expand All @@ -20,12 +20,12 @@
});
}

AppsService.registerPackageHandler("cdvh", {
AppsService.registerPackageHandler('cdvh', {
extractPackageToDirectory : function (appName, fileName, outputDirectory){
var dataToAppend = ContextMenuInjectScript.getInjectString(appName);
var platformDirectory = outputDirectory + "/" + platformId + "/www/";
var cordovaFile = platformDirectory + "cordova.js";
var pluginsFile = platformDirectory + "cordova_plugins.js";
var platformDirectory = outputDirectory + '/' + platformId + '/www/';
var cordovaFile = platformDirectory + 'cordova.js';
var pluginsFile = platformDirectory + 'cordova_plugins.js';

// We need to
// 1) Modify the cordova.js file
Expand All @@ -39,10 +39,10 @@
if(fileExists){
return $q.all([
ResourcesLoader.appendFileContents(cordovaFile, dataToAppend),
copyFile("app-bundle:///cdvh_files/www/cordova_plugins.js", pluginsFile)
copyFile('app-bundle:///cdvh_files/www/cordova_plugins.js', pluginsFile)
]);
} else {
throw new Error("The package does not seem to have the files required for the platform: " + platformId);
throw new Error('The package does not seem to have the files required for the platform: ' + platformId);
}
});
}
Expand Down
15 changes: 8 additions & 7 deletions www/cdvah/js/ContextMenuInjectScript.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
(function() {
"use strict";
'use strict';
/* global myApp */
myApp.factory("ContextMenuInjectScript", [ function () {
/* global appIndexPlaceHolder */
myApp.factory('ContextMenuInjectScript', [ function () {
var toInject = function() {
console.log("Menu script injected.");
var contextScript = document.createElement("script");
contextScript.setAttribute("src", "app-harness:///cdvahcm/ContextMenu.js");
console.log('Menu script injected.');
var contextScript = document.createElement('script');
contextScript.setAttribute('src', 'app-harness:///cdvahcm/ContextMenu.js');
window.__cordovaAppHarnessData = {
'appIndex': appIndexPlaceHolder,
'appName': 'appNamePlaceHolder'
};
document.getElementsByTagName("head")[0].appendChild(contextScript);
document.getElementsByTagName('head')[0].appendChild(contextScript);
};

return {
getInjectString : function(appName, appIndex) {
var string = "\n(" + toInject.toString() + ")();";
var string = '\n(' + toInject.toString() + ')();';
string = string.replace('appNamePlaceHolder', appName);
string = string.replace('appIndexPlaceHolder', appIndex);
return string;
Expand Down
34 changes: 17 additions & 17 deletions www/cdvah/js/CrxPackageHandler.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
(function(){
"use strict";
'use strict';
/* global myApp */
myApp.run(["$q", "AppsService", "ResourcesLoader", "ContextMenuInjectScript", function($q, AppsService, ResourcesLoader, ContextMenuInjectScript){
myApp.run(['$q', 'AppsService', 'ResourcesLoader', 'ContextMenuInjectScript', function($q, AppsService, ResourcesLoader, ContextMenuInjectScript){

var platformId = cordova.require("cordova/platform").id;
var platformId = cordova.require('cordova/platform').id;

function copyFile(startUrl, targetLocation){
/************ Begin Work around for File system bug ************/
if(targetLocation.indexOf("file://") === 0) {
targetLocation = targetLocation.substring("file://".length);
if(targetLocation.indexOf('file://') === 0) {
targetLocation = targetLocation.substring('file://'.length);
}
/************ End Work around for File system bug **************/
return ResourcesLoader.xhrGet(startUrl)
Expand All @@ -20,13 +20,13 @@
});
}

AppsService.registerPackageHandler("crx", {
AppsService.registerPackageHandler('crx', {
extractPackageToDirectory : function (appName, fileName, outputDirectory){
console.log('extracting the crx');
var dataToAppend = ContextMenuInjectScript.getInjectString(appName);
var platformDirectory = outputDirectory + "/" + platformId + "/";
var platformWWWDirectory = platformDirectory + "www/";
var cordovaFile = platformWWWDirectory + "cordova.js";
var platformDirectory = outputDirectory + '/' + platformId + '/';
var platformWWWDirectory = platformDirectory + 'www/';
var cordovaFile = platformWWWDirectory + 'cordova.js';

// We need to
// 1) Copy over the files required to convert a crx to a normal web app
Expand All @@ -39,18 +39,18 @@
}

var copies = [
copyFile("app-bundle:///cordova.js", cordovaFile),
copyFile("app-bundle:///crx_files/config." + platformId + ".xml", platformDirectory + "config.xml"),
copyFile("app-bundle:///cordova_plugins.js", platformWWWDirectory + "cordova_plugins.js"),
copyFile("app-bundle:///chromeapp.html", platformWWWDirectory + "chromeapp.html"),
copyFile("app-bundle:///chromeappstyles.css", platformWWWDirectory + "chromeappstyles.css"),
copyFile("app-bundle:///chromebgpage.html", platformWWWDirectory + "chromebgpage.html"),
copyFile("app-bundle:///cdvah_js/ContextMenu.js", platformWWWDirectory + "ContextMenu.js")
copyFile('app-bundle:///cordova.js', cordovaFile),
copyFile('app-bundle:///crx_files/config.' + platformId + '.xml', platformDirectory + 'config.xml'),
copyFile('app-bundle:///cordova_plugins.js', platformWWWDirectory + 'cordova_plugins.js'),
copyFile('app-bundle:///chromeapp.html', platformWWWDirectory + 'chromeapp.html'),
copyFile('app-bundle:///chromeappstyles.css', platformWWWDirectory + 'chromeappstyles.css'),
copyFile('app-bundle:///chromebgpage.html', platformWWWDirectory + 'chromebgpage.html'),
copyFile('app-bundle:///cdvah_js/ContextMenu.js', platformWWWDirectory + 'ContextMenu.js')
];

for(var i = 0; i < plugins.length; i++) {
console.log('copying ' + plugins[i].file);
copies.push(copyFile("app-bundle:///" + plugins[i].file, platformWWWDirectory + plugins[i].file));
copies.push(copyFile('app-bundle:///' + plugins[i].file, platformWWWDirectory + plugins[i].file));
}

return $q.all(copies);
Expand Down
16 changes: 8 additions & 8 deletions www/cdvah/js/Installer.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
(function(){
"use strict";
'use strict';
/* global myApp */
myApp.factory("Installer", ["$q", "UrlRemap", "ResourcesLoader", "ContextMenuInjectScript", function($q, UrlRemap, ResourcesLoader, ContextMenuInjectScript) {
myApp.factory('Installer', ['$q', 'UrlRemap', 'ResourcesLoader', 'ContextMenuInjectScript', function($q, UrlRemap, ResourcesLoader, ContextMenuInjectScript) {

function getAppStartPageFromConfig(configFile) {
return ResourcesLoader.readFileContents(configFile)
.then(function(contents) {
if(!contents) {
throw new Error("Config file is empty. Unable to find a start page for your app.");
throw new Error('Config file is empty. Unable to find a start page for your app.');
} else {
var startLocation = 'index.html';
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(contents, "text/xml");
var els = xmlDoc.getElementsByTagName("content");
var xmlDoc = parser.parseFromString(contents, 'text/xml');
var els = xmlDoc.getElementsByTagName('content');

if(els.length > 0) {
// go through all "content" elements looking for the "src" attribute in reverse order
// go through all 'content' elements looking for the 'src' attribute in reverse order
for(var i = els.length - 1; i >= 0; i--) {
var el = els[i];
var srcValue = el.getAttribute("src");
var srcValue = el.getAttribute('src');
if (srcValue) {
startLocation = srcValue;
break;
Expand Down Expand Up @@ -104,7 +104,7 @@
// The work-around (using loadData:) breaks history.back().
// So, for file:// start pages, we just point to the install location.
if (cordova.platformId == 'ios') {
startLocation = startLocation.replace(harnessDir, installUrl + '/www')
startLocation = startLocation.replace(harnessDir, installUrl + '/www');
}

// Inject the context menu script for all pages except the harness menu.
Expand Down
26 changes: 13 additions & 13 deletions www/cdvah/js/ListCtrl.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
(function(){
"use strict";
'use strict';
/* global myApp */
myApp.controller("ListCtrl", ['$location', "notifier", "$rootScope", "$scope", "$routeParams", "AppsService", function ($location, notifier, $rootScope, $scope, $routeParams, AppsService) {
myApp.controller('ListCtrl', ['$location', 'notifier', '$rootScope', '$scope', '$routeParams', 'AppsService', function ($location, notifier, $rootScope, $scope, $routeParams, AppsService) {
$scope.appList = [];
$rootScope.appTitle = 'Cordova App Harness';

function initialise() {
return $scope.loadAppsList()
.then(AppsService.getAppList)
.then(function(appList) {
var action = $routeParams['action'];
var action = $routeParams.action;
if (action) {
var appIndex = +$routeParams['appIndex'];
var appIndex = +$routeParams.appIndex;
var activeApp = appList[appIndex];
if (action == 'restart') {
return AppsService.launchApp(activeApp)
.then(null, function(e){
console.error("Error launching last run app: " + e);
console.error('Error launching last run app: ' + e);
notifier.error('' + e);
});
} else if (action == 'update') {
Expand All @@ -25,7 +25,7 @@
.then(function() {
return AppsService.launchApp(activeApp);
}).then(null, function(e){
console.error("Error updating last run app: " + e);
console.error('Error updating last run app: ' + e);
notifier.error('' + e);
});
}
Expand All @@ -46,33 +46,33 @@
});
$scope.appList = newAppsList;
}, function(error){
var str = "There was an error retrieving the apps list";
console.error(str + ": " + error);
var str = 'There was an error retrieving the apps list';
console.error(str + ': ' + error);
notifier.error('' + error);
});
};

$scope.launchApp = function(app){
return AppsService.launchApp(app)
.then(null, function(error){
console.error("Error during loading of app " + app.appId + ": " + error);
console.error('Error during loading of app ' + app.appId + ': ' + error);
notifier.error('' + error);
});
};

$scope.updateApp = function(app) {
return AppsService.updateApp(app)
.then(function(){
notifier.success("Updated successfully");
notifier.success('Updated successfully');
console.log('successfully updated');
}, function(error){
console.error("Error during updating of app " + app.appId + ": " + error);
console.error('Error during updating of app ' + app.appId + ': ' + error);
notifier.error('' + error);
});
};

$scope.removeApp = function(app) {
var shouldUninstall = confirm("Are you sure you want to uninstall " + app.appId + "?");
var shouldUninstall = confirm('Are you sure you want to uninstall ' + app.appId + '?');
if(shouldUninstall) {
return AppsService.uninstallApp(app)
.then(function() {
Expand All @@ -82,7 +82,7 @@
notifier.error('' + error);
});
}
}
};

initialise();
}]);
Expand Down
6 changes: 3 additions & 3 deletions www/cdvah/js/Notify.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
(function() {
"use strict";
'use strict';
/* global myApp */
myApp.directive("cdvahNotify", [ "$rootScope", function($rootScope) {
myApp.directive('cdvahNotify', [ '$rootScope', function($rootScope) {
return {
scope: {},
restrict: 'E',
template: '<div class="notification-container" ng-click="showNotify=false" ng-show="showNotify"><div class="notification" ng-class="notification.css">{{ notification.message }}</div></div>',
replace: true,
link: function(scope, element, attrs) {
link: function(scope) {
$rootScope.$watch('notification', function(newValue) {
scope.showNotify = !!newValue;
if (newValue) {
Expand Down
Loading

0 comments on commit cc307cc

Please sign in to comment.