Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #16252 from mcav/jslint-clock
Browse files Browse the repository at this point in the history
Bug 972463 - [Clock] jslintify all the things. r=millermedeiros
  • Loading branch information
mcav committed Feb 14, 2014
2 parents 6e9b110 + 55ec172 commit 4830eed
Show file tree
Hide file tree
Showing 53 changed files with 158 additions and 167 deletions.
15 changes: 11 additions & 4 deletions apps/clock/.jshintrc
@@ -1,7 +1,14 @@
{
"extends": "../../.jshintrc",
"predef": [
"define",
"require"
]
"globals": {
"define": false,
"require": false,
"KeyEvent": false,
"requirejs": false,
"indexedDB": false,
"mozRequestAnimationFrame": false,
"requestAnimationFrame": false,
"cancelAnimationFrame": false,
"Event": false
}
}
5 changes: 3 additions & 2 deletions apps/clock/build/make_gaia_shared.js
@@ -1,10 +1,11 @@
'use strict';
/**
* Scans the built directory's JS and CSS files looking for shared resources
* to generate a gaia_shared.json
*/
/*jshint moz: true */
/*global load, requirejs, Components */

/*global load */
/* jshint unused:false */
var requirejsAsLib = true;
load('../../build/r.js');

Expand Down
2 changes: 0 additions & 2 deletions apps/clock/js/active_alarm.js
Expand Up @@ -81,8 +81,6 @@ define(function(require) {
this.ringerWaitList.push(callback.bind(null, this.childwindow));
} else {
// prepare to pop out attention screen, ring the ringtone, vibrate
var protocol = window.location.protocol;
var host = window.location.host;
var childwindow = this.childwindow = window.open(
window.location.origin + '/onring.html', '_blank', 'attention');
this.ringerWaitList.push(callback.bind(null, childwindow));
Expand Down
15 changes: 9 additions & 6 deletions apps/clock/js/alarm.js
Expand Up @@ -164,10 +164,11 @@ define(function(require, exports, module) {

summarizeDaysOfWeek: function alarm_summarizeRepeat() {
var _ = mozL10n.get;
var i, dayName;
// Build a bitset
var value = 0;
for (var i = 0; i < constants.DAYS.length; i++) {
var dayName = constants.DAYS[i];
for (i = 0; i < constants.DAYS.length; i++) {
dayName = constants.DAYS[i];
if (this.repeat[dayName] === true) {
value |= (1 << i);
}
Expand All @@ -181,8 +182,8 @@ define(function(require, exports, module) {
summary = _('weekends');
} else if (value !== 0) { // any day was true
var weekdays = [];
for (var i = 0; i < constants.DAYS.length; i++) {
var dayName = constants.DAYS[i];
for (i = 0; i < constants.DAYS.length; i++) {
dayName = constants.DAYS[i];
if (this.repeat[dayName]) {
// Note: here, Monday is the first day of the week
// whereas in JS Date(), it's Sunday -- hence the (+1) here.
Expand Down Expand Up @@ -360,10 +361,11 @@ define(function(require, exports, module) {
return;
}
this.cancel(options.type);
var firedate;
if (options.type === 'normal') {
var firedate = this.getNextAlarmFireTime();
firedate = this.getNextAlarmFireTime();
} else if (options.type === 'snooze') {
var firedate = this.getNextSnoozeFireTime();
firedate = this.getNextSnoozeFireTime();
}
this.scheduleHelper(options.type, firedate, callback);
},
Expand All @@ -372,6 +374,7 @@ define(function(require, exports, module) {
// cancel an alarm type ('normal' or 'snooze')
// type == false to cancel all
function removeAlarm(type, id) {
/* jshint validthis:true */
navigator.mozAlarms.remove(id);
var registeredAlarms = this.registeredAlarms;
delete registeredAlarms[type];
Expand Down
5 changes: 5 additions & 0 deletions apps/clock/js/alarm_edit.js
Expand Up @@ -38,6 +38,11 @@ var AlarmEdit = {
return document.getElementById('repeat-select-sunday');
},

get alarmTitle() {
delete this.alarmTitle;
return (this.alarmTitle = document.getElementById('alarm-title'));
},

init: function aev_init() {
this.selects = {};
[
Expand Down
2 changes: 2 additions & 0 deletions apps/clock/js/alarm_manager.js
@@ -1,4 +1,5 @@
define(function(require) {
'use strict';
/* An Alarm's ID:
* ID in Clock app ID in mozAlarms API
* id (unique) id (unique)
Expand Down Expand Up @@ -65,6 +66,7 @@ var AlarmManager = {
},

updateAlarmStatusBar: function am_updateAlarmStatusBar() {
/* jshint loopfunc:true */
var request = navigator.mozAlarms.getAll();
request.onsuccess = function(e) {
var hasAlarmEnabled = false;
Expand Down
10 changes: 5 additions & 5 deletions apps/clock/js/alarmsdb.js
Expand Up @@ -149,17 +149,17 @@ function convertTo12(alarm) {
repeat: {}
}, alarm);
if (typeof alarm.enabled !== 'undefined') {
delete ret['enabled'];
delete ret.enabled;
}
// Extract a normalAlarmId
if (typeof alarm.normalAlarmId !== 'undefined') {
ret.registeredAlarms['normal'] = alarm.normalAlarmId;
delete ret['normalAlarmId'];
ret.registeredAlarms.normal = alarm.normalAlarmId;
delete ret.normalAlarmId;
}
// Extract a snoozeAlarmId
if (typeof alarm.snoozeAlarmId !== 'undefined') {
ret.registeredAlarms['snooze'] = alarm.snoozeAlarmId;
delete ret['snoozeAlarmId'];
ret.registeredAlarms.snooze = alarm.snoozeAlarmId;
delete ret.snoozeAlarmId;
}
// Map '1111100' string bitmap to a 1.2 repeat object with day name
// properties.
Expand Down
3 changes: 1 addition & 2 deletions apps/clock/js/banner.js
@@ -1,5 +1,4 @@
define(function(require) {

'use strict';

var Template = require('shared/js/template');
Expand All @@ -25,7 +24,7 @@ define(function(require) {
constructor: Banner,

render: function bn_render(alarmTime) {
var timeLeft, displayTime, tl, countdownType, localTimes, unitObj;
var timeLeft, tl, countdownType, localTimes, unitObj;

timeLeft = +alarmTime - Date.now();
// generate human readable numbers to pass to localization function
Expand Down
14 changes: 7 additions & 7 deletions apps/clock/js/clock_view.js
Expand Up @@ -56,33 +56,33 @@ var ClockView = {

get digital() {
delete this.digital;
return this.digital = document.getElementById('digital-clock');
return (this.digital = document.getElementById('digital-clock'));
},

get analog() {
delete this.analog;
return this.analog = document.getElementById('analog-clock');
return (this.analog = document.getElementById('analog-clock'));
},

get time() {
delete this.time;
return this.time = document.getElementById('clock-time');
return (this.time = document.getElementById('clock-time'));
},

get hourState() {
delete this.hourState;
return this.hourState = document.getElementById('clock-hour24-state');
return (this.hourState = document.getElementById('clock-hour24-state'));
},

get dayDate() {
delete this.dayDate;
return this.dayDate = document.getElementById('clock-day-date');
return (this.dayDate = document.getElementById('clock-day-date'));
},

get container() {
delete this.container;
return this.container =
document.getElementById('analog-clock-container');
return (this.container =
document.getElementById('analog-clock-container'));
},
isInitialized: false,

Expand Down
13 changes: 6 additions & 7 deletions apps/clock/js/constants.js
@@ -1,25 +1,24 @@
define(function(require, exports) {

'use strict';

// ---------------------------------------------------------
// Constants

var DAYS = exports.DAYS = [
exports.DAYS = [
'monday', 'tuesday', 'wednesday', 'thursday', 'friday',
'saturday', 'sunday'
];

var RDAYS = exports.RDAYS = DAYS.map(function(_, n) {
exports.RDAYS = exports.DAYS.map(function(_, n) {
return n;
});

var WEEKDAYS = exports.WEEKDAYS = [0, 1, 2, 3, 4].map(function(x) {
return DAYS[x];
exports.WEEKDAYS = [0, 1, 2, 3, 4].map(function(x) {
return exports.DAYS[x];
});

var WEEKENDS = exports.WEEKENDS = [5, 6].map(function(x) {
return DAYS[x];
exports.WEEKENDS = [5, 6].map(function(x) {
return exports.DAYS[x];
});

});
1 change: 1 addition & 0 deletions apps/clock/js/css.js
@@ -1,3 +1,4 @@
'use strict';
// Loader plugin for loading CSS. Does not guarantee loading via onload
// watching, just inserts link tag.
define({
Expand Down
17 changes: 9 additions & 8 deletions apps/clock/js/database.js
@@ -1,5 +1,6 @@
define(function(require) {
'use strict';
/* global LazyLoader */

var Utils = require('utils');

Expand Down Expand Up @@ -167,8 +168,6 @@ define(function(require) {
// ===========================================================
// Database Singletons

var databaseSingletons = new Map();

Database.singleton = Utils.singleton(Database, function(args) {
return args[0].name;
});
Expand Down Expand Up @@ -413,7 +412,7 @@ define(function(require) {
* there is no upgrade path defined, we default to destroying the
* existing database and initializing a new one of this.version.
*/
var mutators, direction;
var mutators, direction, i;
if (newVersion === oldVersion) {
return;
} else if (newVersion > oldVersion) {
Expand All @@ -435,7 +434,7 @@ define(function(require) {
return m.version > version;
}
};
for (var i = first.index;
for (i = first.index;
i >= 0 && i < mutators.length &&
isApplicableMutator(mutators[i], direction, newVersion);
i += direction) {
Expand Down Expand Up @@ -471,8 +470,10 @@ define(function(require) {
});
}
}).bind(this);
var last = finalizer;
for (var i = plan.length - 1; i >= 0; i--) {
last = finalizer;
// Ignore that we put a function in a loop.
/*jshint loopfunc: true */
for (i = plan.length - 1; i >= 0; i--) {
last = (function(converter, version, cb) {
// de-duplicate the callbacks
var dedup = Utils.async.namedParallel(['converter'], cb);
Expand All @@ -484,8 +485,8 @@ define(function(require) {
this.requestMutatorTransaction(function(err, transaction) {
try {
converter.call(transaction, transaction, dedup.converter);
} catch (err) {
dedup.converter(err);
} catch (e) {
dedup.converter(e);
} finally {
transaction.db.close();
}
Expand Down
2 changes: 1 addition & 1 deletion apps/clock/js/emitter.js
Expand Up @@ -125,7 +125,7 @@ Emitter.prototype.emit = function(type, data) {
events.once.length = 0;

if (allEvents.length) {
while (event = allEvents.shift()) {
while ((event = allEvents.shift())) {
event.call(this, data);
}
}
Expand Down
1 change: 1 addition & 0 deletions apps/clock/js/l10n.js
Expand Up @@ -4,5 +4,6 @@
// that this module exports the "l10n" module's global variable only after both
// shared libraries have been loaded in the correct order.
define(['shared/js/l10n_date'], function() {
'use strict';
return navigator.mozL10n;
});
14 changes: 8 additions & 6 deletions apps/clock/js/onring.js
@@ -1,5 +1,5 @@
define(function(require) {
'use strict';
define(function(require) {

var Utils = require('utils');
var mozL10n = require('l10n');
Expand Down Expand Up @@ -34,7 +34,7 @@ RingView.prototype = {};
RingView.prototype.handleMessage = function rv_handleMessage(ev) {
Utils.safeWakeLock({type: 'cpu', timeoutMs: 5000}, function(done) {
var err = [];
var data = ev.data, source = ev.source;
var data = ev.data;
var messageTypes = data.type.split(' ');
var gen = Utils.async.generator(done);
var lp = gen();
Expand All @@ -60,6 +60,7 @@ RingView.prototype.handleMessage = function rv_handleMessage(ev) {
};

function isVisibleWorkaround(callback) {
/* jshint validthis:true */
// See https://bugzilla.mozilla.org/show_bug.cgi?id=810431
document.addEventListener('visibilitychange', this);
if (!document.hidden) {
Expand Down Expand Up @@ -246,7 +247,7 @@ RingView.prototype.handleEvent = function rv_handleEvent(evt) {
}
};

RingView.prototype.onVisibilityChange = domEventMap['visibilitychange'] =
RingView.prototype.onVisibilityChange = domEventMap.visibilitychange =
function rv_onVisibilityChange(evt) {
// There's chance to miss the hidden state when initiated,
// before setVisible take effects, there may be a latency.
Expand All @@ -255,7 +256,7 @@ RingView.prototype.onVisibilityChange = domEventMap['visibilitychange'] =
}
};

RingView.prototype.onMozInterruptBegin = domEventMap['onmozinterruptbegin'] =
RingView.prototype.onMozInterruptBegin = domEventMap.mozinterruptbegin =
function rv_onMozInterruptBegin(evt) {
// Only ringer/telephony channel audio could trigger 'mozinterruptbegin'
// event on the 'alarm' channel audio element.
Expand All @@ -264,11 +265,12 @@ RingView.prototype.onMozInterruptBegin = domEventMap['onmozinterruptbegin'] =
this.stopNotify(true);
};

RingView.prototype.onClick = domEventMap['click'] =
RingView.prototype.onClick = domEventMap.click =
function rv_onClick(evt) {
var input = evt.target;
if (!input)
if (!input) {
return;
}
switch (input.id) {
case 'ring-button-snooze':
this.stopNotify();
Expand Down
3 changes: 2 additions & 1 deletion apps/clock/js/picker/spinner.js
Expand Up @@ -19,6 +19,7 @@ define(function(require) {
var DRAGGING_TIMEOUT = 200;

function calculateSpeed(previous, current) {
/* jshint validthis:true */
var motion = (previous.y - current.y) / this.unitHeight;
var delta = current.time - previous.time;
var speed = motion / delta;
Expand Down Expand Up @@ -164,7 +165,7 @@ define(function(require) {
Spinner.prototype.onpan = function(event) {
event.stopPropagation();
var position = event.detail.position;
var diff, moving;
var diff;

// If this is the first pan event after a swipe...
if (this.element.classList.contains('animation-on')) {
Expand Down
3 changes: 2 additions & 1 deletion apps/clock/js/startup.js
@@ -1,6 +1,7 @@
define('startup_init', function(require) {
'use strict';

define('startup_init', function(require) {

var App = require('app');
var ClockView = require('clock_view');
var AlarmList = require('alarm_list');
Expand Down

0 comments on commit 4830eed

Please sign in to comment.