1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 18:29:17 +02:00

Fix various JSHint warnings in client-side code.

This commit is contained in:
Simo Kinnunen 2014-03-26 16:06:13 +09:00
parent a6aed5416f
commit 8b13a1c945
25 changed files with 188 additions and 130 deletions

View file

@ -4,7 +4,7 @@
"freeze": true, "freeze": true,
"immed": true, "immed": true,
"latedef": "nofunc", "latedef": "nofunc",
"newcap": true, "newcap": false,
"noarg": true, "noarg": true,
"noempty": true, "noempty": true,
"nonbsp": true, "nonbsp": true,
@ -24,6 +24,7 @@
"beforeEach": false, "beforeEach": false,
"after": false, "after": false,
"afterEach": false, "afterEach": false,
"expect": true,
"inject": false, "inject": false,
"angular": false "angular": false
} }

View file

@ -11,13 +11,13 @@ describe('clearButton', function () {
it('should ...', function () { it('should ...', function () {
/* /*
To test your directive, you need to create some html that would use your directive, To test your directive, you need to create some html that would use your
send that through compile() then compare the results. directive, send that through compile() then compare the results.
var element = compile('<div clear-button name="name">hi</div>')(scope); var element = compile('<div clear-button name="name">hi</div>')(scope);
expect(element.text()).toBe('hello, world'); expect(element.text()).toBe('hello, world');
*/ */
}); });
}); });

View file

@ -11,13 +11,13 @@ describe('filterButton', function () {
it('should ...', function () { it('should ...', function () {
/* /*
To test your directive, you need to create some html that would use your directive, To test your directive, you need to create some html that would use your
send that through compile() then compare the results. directive, send that through compile() then compare the results.
var element = compile('<div clear-button name="name">hi</div>')(scope); var element = compile('<div clear-button name="name">hi</div>')(scope);
expect(element.text()).toBe('hello, world'); expect(element.text()).toBe('hello, world');
*/ */
}); });
}); });

View file

@ -5,7 +5,7 @@ module.exports = function refreshPageDirective() {
scope: { scope: {
}, },
template: require('./refresh-page.jade'), template: require('./refresh-page.jade'),
link: function (scope, element, attrs) { link: function () {
// TODO: reload with $route.reload() // TODO: reload with $route.reload()
} }
} }

View file

@ -11,13 +11,13 @@ describe('refreshPage', function () {
it('should ...', function () { it('should ...', function () {
/* /*
To test your directive, you need to create some html that would use your directive, To test your directive, you need to create some html that would use your
send that through compile() then compare the results. directive, send that through compile() then compare the results.
var element = compile('<div refresh-page name="name">hi</div>')(scope); var element = compile('<div refresh-page name="name">hi</div>')(scope);
expect(element.text()).toBe('hello, world'); expect(element.text()).toBe('hello, world');
*/ */
}); });
}); });

View file

@ -1,4 +1,9 @@
module.exports = function ControlServiceFactory($rootScope, $upload, socket, TransactionService) { module.exports = function ControlServiceFactory(
$rootScope
, $upload
, socket
, TransactionService
) {
var controlService = { var controlService = {
} }

View file

@ -1,6 +1,5 @@
var oboe = require('oboe') var oboe = require('oboe')
var _ = require('lodash') var _ = require('lodash')
var Promise = require('bluebird')
module.exports = function DeviceServiceFactory($rootScope, $http, socket) { module.exports = function DeviceServiceFactory($rootScope, $http, socket) {
var deviceService = {} var deviceService = {}

View file

@ -1,12 +1,11 @@
// Based from https://ryankaskel.com/blog/2013/05/27/a-different-approach-to-angularjs-navigation-menus /* Based on https://ryankaskel.com/blog/2013/05/27/
a-different-approach-to-angularjs-navigation-menus */
module.exports = function ($location) { module.exports = function ($location) {
return function (scope, element, attrs) { return function (scope, element, attrs) {
var links = element.find('a') var links = element.find('a')
var onClass = attrs.navMenu || 'current' var onClass = attrs.navMenu || 'current'
var routePattern var routePattern
var routeBasePattern = /\/#[^/]*/ // TODO: add regex to remove last part of the url
var link var link
var url var url
var currentLink var currentLink
@ -50,4 +49,4 @@ module.exports = function ($location) {
activateLink() activateLink()
scope.$on('$routeChangeStart', activateLink) scope.$on('$routeChangeStart', activateLink)
} }
} }

View file

@ -11,13 +11,13 @@ describe('navMenu', function () {
it('should ...', function () { it('should ...', function () {
/* /*
To test your directive, you need to create some html that would use your directive, To test your directive, you need to create some html that would use your
send that through compile() then compare the results. directive, send that through compile() then compare the results.
var element = compile('<div nav-menu name="name">hi</div>')(scope); var element = compile('<div nav-menu name="name">hi</div>')(scope);
expect(element.text()).toBe('hello, world'); expect(element.text()).toBe('hello, world');
*/ */
}); });
}); });

View file

@ -1,19 +1,22 @@
module.exports = function pageVisibilityDirective($document, $rootScope) { module.exports = function pageVisibilityDirective($document, $rootScope) {
return { return {
restrict: 'A', restrict: 'A',
link: function (scope, element, attrs) { link: function (scope) {
function pageVisibilityChanged() { function pageVisibilityChanged() {
if (document.hidden) { if (document.hidden) {
$rootScope.$broadcast('pageHidden') $rootScope.$broadcast('pageHidden')
} else { } else {
$rootScope.$broadcast('pageVisible'); $rootScope.$broadcast('pageVisible')
// Application is visible to the user // Application is visible to the user
// Adjust polling rates and display update for active display mode // Adjust polling rates and display update for active display mode
} }
} }
document.addEventListener('visibilitychange', pageVisibilityChanged, false) document.addEventListener(
'visibilitychange'
, pageVisibilityChanged
, false
)
scope.$on('$destroy', function () { scope.$on('$destroy', function () {
angular.element(document).unbind('visibilitychange'); angular.element(document).unbind('visibilitychange');

View file

@ -11,13 +11,13 @@ describe('pageVisibility', function () {
it('should ...', function () { it('should ...', function () {
/* /*
To test your directive, you need to create some html that would use your directive, To test your directive, you need to create some html that would use your
send that through compile() then compare the results. directive, send that through compile() then compare the results.
var element = compile('<div page-visibility name="name">hi</div>')(scope); var element = compile('<div page-visibility name="name">hi</div>')(scope);
expect(element.text()).toBe('hello, world'); expect(element.text()).toBe('hello, world');
*/ */
}); });
}); });

View file

@ -7,19 +7,6 @@
function CanvasRender(canvasElement, options) { function CanvasRender(canvasElement, options) {
var checkForCanvasElement = function checkForCanvasElement() {
if (!canvasElement) {
throw new Error('Needs a canvas element')
}
this.displayWidth = canvasElement.offsetWidth
this.displayHeight = canvasElement.offsetHeight
if (!this.displayWidth || !this.displayHeight) {
throw new Error('Unable to get display size canvas must have dimensions')
}
}
this.options = options this.options = options
this.context = canvasElement.getContext('2d') this.context = canvasElement.getContext('2d')
} }
@ -35,7 +22,9 @@ CanvasRender.prototype.clear = function () {
// ------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------
// Based on http://www-cs-students.stanford.edu/~eparker/files/crunch/renderer.js /*
Based on http://www-cs-students.stanford.edu/~eparker/files/crunch/renderer.js
*/
/** /**
* Constructs a renderer object. * Constructs a renderer object.
@ -114,13 +103,15 @@ var Renderer = function (gl) {
var count = gl.getProgramParameter(this.program_, gl.ACTIVE_UNIFORMS); var count = gl.getProgramParameter(this.program_, gl.ACTIVE_UNIFORMS);
for (var i = 0; i < /** @type {number} */(count); i++) { for (var i = 0; i < /** @type {number} */(count); i++) {
var infoU = gl.getActiveUniform(this.program_, i); var infoU = gl.getActiveUniform(this.program_, i);
this.uniformLocations_[infoU.name] = gl.getUniformLocation(this.program_, infoU.name); this.uniformLocations_[infoU.name] =
gl.getUniformLocation(this.program_, infoU.name);
} }
count = gl.getProgramParameter(this.program_, gl.ACTIVE_ATTRIBUTES); count = gl.getProgramParameter(this.program_, gl.ACTIVE_ATTRIBUTES);
for (var j = 0; j < /** @type {number} */(count); j++) { for (var j = 0; j < /** @type {number} */(count); j++) {
var infoA = gl.getActiveAttrib(this.program_, j); var infoA = gl.getActiveAttrib(this.program_, j);
this.attribLocations_[infoA.name] = gl.getAttribLocation(this.program_, infoA.name); this.attribLocations_[infoA.name] =
gl.getAttribLocation(this.program_, infoA.name);
} }
}; };
@ -130,7 +121,12 @@ Renderer.prototype.finishInit = function () {
}; };
Renderer.prototype.createDxtTexture = function (dxtData, width, height, format) { Renderer.prototype.createDxtTexture = function (
dxtData
, width
, height
, format
) {
var gl = this.gl_; var gl = this.gl_;
var tex = gl.createTexture(); var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex); gl.bindTexture(gl.TEXTURE_2D, tex);
@ -242,20 +238,7 @@ Renderer.fragmentShaderSource_ = [
// ------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------
function WebGLRender(canvasElement, options) { function WebGLRender(canvasElement) {
var checkForCanvasElement = function checkForCanvasElement() {
if (!canvasElement) {
throw new Error('Needs a canvas element')
}
this.displayWidth = canvasElement.offsetWidth
this.displayHeight = canvasElement.offsetHeight
if (!this.displayWidth || !this.displayHeight) {
throw new Error('Unable to get display size canvas must have dimensions')
}
}
this.options = { this.options = {
// alpha: this.transparent, // alpha: this.transparent,
// antialias: !!antialias, // antialias: !!antialias,
@ -270,7 +253,8 @@ function WebGLRender(canvasElement, options) {
this.ctx = canvasElement.getContext('webgl', this.options) this.ctx = canvasElement.getContext('webgl', this.options)
} catch (e2) { } catch (e2) {
// fail, not able to get a context // fail, not able to get a context
throw new Error('This browser does not support webGL. Try using the canvas renderer' + this) throw new Error('This browser does not support webGL. Try using the' +
'canvas renderer' + this)
} }
} }
@ -332,9 +316,19 @@ WebGLRender.prototype.setup = function () {
this.vertexBuff = this.ctx.createBuffer() this.vertexBuff = this.ctx.createBuffer()
this.ctx.bindBuffer(this.ctx.ARRAY_BUFFER, this.vertexBuff) this.ctx.bindBuffer(this.ctx.ARRAY_BUFFER, this.vertexBuff)
this.ctx.bufferData( this.ctx.bufferData(
this.ctx.ARRAY_BUFFER, this.ctx.ARRAY_BUFFER
new Float32Array([-1 / 8, 1 / 6, -1 / 8, -1 / 6, 1 / 8, -1 / 6, 1 / 8, 1 / 6]), , new Float32Array([
this.ctx.STATIC_DRAW) -1 / 8
, 1 / 6
, -1 / 8
, -1 / 6
, 1 / 8
, -1 / 6
, 1 / 8
, 1 / 6
])
, this.ctx.STATIC_DRAW
)
this.texBuff = this.ctx.createBuffer() this.texBuff = this.ctx.createBuffer()
this.ctx.bindBuffer(this.ctx.ARRAY_BUFFER, this.texBuff) this.ctx.bindBuffer(this.ctx.ARRAY_BUFFER, this.texBuff)
@ -358,15 +352,43 @@ WebGLRender.prototype.draw = function (image) {
WebGLRender.prototype.drawOld = function (image) { WebGLRender.prototype.drawOld = function (image) {
var tex = this.ctx.createTexture() var tex = this.ctx.createTexture()
this.ctx.bindTexture(this.ctx.TEXTURE_2D, tex) this.ctx.bindTexture(this.ctx.TEXTURE_2D, tex)
this.ctx.texParameteri(this.ctx.TEXTURE_2D, this.ctx.TEXTURE_MIN_FILTER, this.ctx.NEAREST) this.ctx.texParameteri(
this.ctx.texParameteri(this.ctx.TEXTURE_2D, this.ctx.TEXTURE_MAG_FILTER, this.ctx.NEAREST) this.ctx.TEXTURE_2D
// this.ctx.texParameteri(this.ctx.TEXTURE_2D, this.ctx.TEXTURE_MIN_FILTER, this.ctx.LINEAR); , this.ctx.TEXTURE_MIN_FILTER
, this.ctx.NEAREST
// this.ctx.texParameteri(this.ctx.TEXTURE_2D, this.ctx.TEXTURE_WRAP_S, this.ctx.CLAMP_TO_EDGE); )
// this.ctx.texParameteri(this.ctx.TEXTURE_2D, this.ctx.TEXTURE_WRAP_T, this.ctx.CLAMP_TO_EDGE); this.ctx.texParameteri(
this.ctx.TEXTURE_2D
, this.ctx.TEXTURE_MAG_FILTER
, this.ctx.NEAREST
)
/*
this.ctx.texParameteri(
this.ctx.TEXTURE_2D
, this.ctx.TEXTURE_MIN_FILTER
, this.ctx.LINEAR
)
this.ctx.texParameteri(
this.ctx.TEXTURE_2D
, this.ctx.TEXTURE_WRAP_S
, this.ctx.CLAMP_TO_EDGE
)
this.ctx.texParameteri(
this.ctx.TEXTURE_2D
, this.ctx.TEXTURE_WRAP_T
, this.ctx.CLAMP_TO_EDGE
)
*/
this.ctx.generateMipmap(this.ctx.TEXTURE_2D) this.ctx.generateMipmap(this.ctx.TEXTURE_2D)
this.ctx.texImage2D(this.ctx.TEXTURE_2D, 0, this.ctx.RGBA, this.ctx.RGBA, this.ctx.UNSIGNED_BYTE, image) this.ctx.texImage2D(
this.ctx.TEXTURE_2D
, 0
, this.ctx.RGBA
, this.ctx.RGBA
, this.ctx.UNSIGNED_BYTE
, image
)
this.ctx.enableVertexAttribArray(this.vloc) this.ctx.enableVertexAttribArray(this.vloc)
this.ctx.bindBuffer(this.ctx.ARRAY_BUFFER, this.vertexBuff) this.ctx.bindBuffer(this.ctx.ARRAY_BUFFER, this.vertexBuff)
@ -440,7 +462,7 @@ FastImageRender.prototype.load = function (url, type) {
var texture = null var texture = null
if (type) { if (type) {
texture = this.render.ctx.createTexture(); texture = this.render.ctx.createTexture();
this.textureLoader.loadEx(url, texture, true, function (tex) { this.textureLoader.loadEx(url, texture, true, function () {
if (typeof(that.onLoad) === 'function') { if (typeof(that.onLoad) === 'function') {
that.onLoad(texture) that.onLoad(texture)
} }

View file

@ -7,14 +7,22 @@ var frame = {
current: 0 current: 0
} }
var imageRender = new FastImageRender(canvasElement, {render: 'canvas', textureLoader: false}) var imageRender = new FastImageRender(
canvasElement
, {
render: 'canvas'
, textureLoader: false
}
)
function loadNext() { function loadNext() {
console.time('load') console.time('load')
// var width = 300 // var width = 300
// var height = 300 // var height = 300
// loader.src = 'http://placehold.it/' + width + 'x' + height + '?' + Date.now() // loader.src = 'http://placehold.it/' + width + 'x' + height + '?' +
// loader.src = 'http://lorempixel.com/' + width + '/' + height + '/abstract/Frame-' + frames.current + '/?' + Date.now() // Date.now()
// loader.src = 'http://lorempixel.com/' + width + '/' + height +
// '/abstract/Frame-' + frames.current + '/?' + Date.now()
imageRender.load('images/screen.jpg?' + Date.now()) imageRender.load('images/screen.jpg?' + Date.now())
// imageRender.load('images/screen.jpg') // imageRender.load('images/screen.jpg')
} }
@ -39,4 +47,3 @@ imageRender.onLoad = function (image) {
totalTimeElement.innerHTML = totalTime / 1000 + ' seconds' totalTimeElement.innerHTML = totalTime / 1000 + ' seconds'
} }
} }

View file

@ -4,7 +4,7 @@ module.exports = function DeviceScreenDirective($document, ScalingService) {
return { return {
restrict: 'E', restrict: 'E',
template: require('./screen.jade'), template: require('./screen.jade'),
link: function (scope, element, attrs) { link: function (scope, element) {
var canvas = element.find('canvas')[0] var canvas = element.find('canvas')[0]
, imageRender = new FastImageRender(canvas, {render: 'canvas'}) , imageRender = new FastImageRender(canvas, {render: 'canvas'})
, finger = element.find('span') , finger = element.find('span')

View file

@ -1,42 +1,39 @@
var _ = require('lodash') module.exports = function GroupServiceFactory(
socket
module.exports = function GroupServiceFactory(socket, UserService, TransactionService) { , TransactionService
) {
var groupService = { var groupService = {
} }
groupService.invite = function (device) { groupService.invite = function (device) {
return UserService.user().then(function (user) { var tx = TransactionService.create([device])
var tx = TransactionService.create([device]) socket.emit('group.invite', device.channel, tx.channel, {
socket.emit('group.invite', device.channel, tx.channel, { serial: {
serial: { value: device.serial
value: device.serial , match: 'exact'
, match: 'exact' }
} })
}) return tx.promise.then(function(results) {
return tx.promise.then(function(results) { if (!results[0].success) {
if (!results[0].success) { throw new Error('Device refused to join the group')
throw new Error('Device refused to join the group') }
} return results[0].device
return results[0].device
})
}) })
} }
groupService.kick = function (device) { groupService.kick = function (device) {
return UserService.user().then(function (user) { var tx = TransactionService.create([device])
var tx = TransactionService.create([device]) socket.emit('group.kick', device.channel, tx.channel, {
socket.emit('group.kick', device.channel, tx.channel, { serial: {
serial: { value: device.serial
value: device.serial , match: 'exact'
, match: 'exact' }
} })
}) return tx.promise.then(function(results) {
return tx.promise.then(function(results) { if (!results[0].success) {
if (!results[0].success) { throw new Error('Device refused to be kicked from the group')
throw new Error('Device refused to be kicked from the group') }
} return results[0].device
return results[0].device
})
}) })
} }

View file

@ -1,3 +1,3 @@
module.exports = function($scope) { module.exports = function ControlPanesCtrl() {
} }

View file

@ -1,4 +1,11 @@
module.exports = function DeviceControlCtrl($scope, $routeParams, $location, DeviceService, GroupService, ControlService) { module.exports = function DeviceControlCtrl(
$scope
, $routeParams
, $location
, DeviceService
, GroupService
, ControlService
) {
$scope.control = null $scope.control = null
$scope.device = null $scope.device = null
$scope.control = null $scope.control = null
@ -12,7 +19,7 @@ module.exports = function DeviceControlCtrl($scope, $routeParams, $location, Dev
$scope.control = ControlService.forOne(device, device.channel) $scope.control = ControlService.forOne(device, device.channel)
return device return device
}) })
.catch(function(err) { .catch(function() {
$location.path('/') $location.path('/')
}) })
} }

View file

@ -1,2 +1,2 @@
module.exports = function LayoutCtrl($scope) { module.exports = function LayoutCtrl() {
} }

View file

@ -1,3 +1,3 @@
module.exports = function MenuCtrl($scope) { module.exports = function MenuCtrl() {
} }

View file

@ -2,7 +2,10 @@ module.exports = angular.module('stf-ui-language', [
require('stf/settings').name require('stf/settings').name
]) ])
.run(["$templateCache", function($templateCache) { .run(["$templateCache", function($templateCache) {
$templateCache.put('settings/language/language.jade', require('./language.jade')) $templateCache.put(
'settings/language/language.jade'
, require('./language.jade')
)
}]) }])
.factory('LanguageService', require('./language-service')) .factory('LanguageService', require('./language-service'))
.controller('LanguageCtrl', require('./language-controller')) .controller('LanguageCtrl', require('./language-controller'))

View file

@ -1,6 +1,10 @@
var _ = require('lodash') var _ = require('lodash')
module.exports = function LanguageServiceFactory(SettingsService, $q, gettextCatalog) { module.exports = function LanguageServiceFactory(
SettingsService
, $q
, gettextCatalog
) {
var LanguageService = {} var LanguageService = {}
LanguageService.supportedLanguages = [ LanguageService.supportedLanguages = [
@ -10,7 +14,10 @@ module.exports = function LanguageServiceFactory(SettingsService, $q, gettextCat
var browserLocale = navigator.language || navigator.userLanguage || 'en-US' var browserLocale = navigator.language || navigator.userLanguage || 'en-US'
var browserLanguage = browserLocale.substring(0, 2) var browserLanguage = browserLocale.substring(0, 2)
var detectedLanguage = _.some(LanguageService.supportedLanguages, {code: browserLanguage}) ? browserLanguage : 'en' var detectedLanguage =
_.some(LanguageService.supportedLanguages, {code: browserLanguage}) ?
browserLanguage :
'en'
var defaultLanguage = 'ja' var defaultLanguage = 'ja'
LanguageService.detectedLanguage = defaultLanguage LanguageService.detectedLanguage = defaultLanguage
LanguageService.selectedLanguage = null LanguageService.selectedLanguage = null
@ -29,9 +36,10 @@ module.exports = function LanguageServiceFactory(SettingsService, $q, gettextCat
if (data) { if (data) {
deferred.resolve(data) deferred.resolve(data)
} else { } else {
LanguageService.setSelectedLanguage(LanguageService.detectedLanguage).then(function () { LanguageService.setSelectedLanguage(LanguageService.detectedLanguage)
deferred.resolve(LanguageService.detectedLanguage) .then(function () {
}) deferred.resolve(LanguageService.detectedLanguage)
})
} }
}) })
} }

View file

@ -8,6 +8,9 @@ module.exports = angular.module('ui-local-settings', [
//'dialogs' //'dialogs'
]) ])
.run(["$templateCache", function ($templateCache) { .run(["$templateCache", function ($templateCache) {
$templateCache.put('settings/local/local-settings.jade', require('./local-settings.jade')) $templateCache.put(
'settings/local/local-settings.jade'
, require('./local-settings.jade')
)
}]) }])
.controller('LocalSettingsCtrl', require('./local-settings-controller')) .controller('LocalSettingsCtrl', require('./local-settings-controller'))

View file

@ -8,7 +8,8 @@ module.exports = function ($scope, SettingsService) {
// $scope.resetSettings = function () { // $scope.resetSettings = function () {
// var title = 'Reset Settings'; // var title = 'Reset Settings';
// var msg = 'Are you sure you want to revert all settings to their default values?'; // var msg = 'Are you sure you want to revert all settings to ' +
// 'their default values?';
// var btns = [ // var btns = [
// {result: 'cancel', label: 'Cancel'}, // {result: 'cancel', label: 'Cancel'},
// {result: 'ok', label: 'OK', cssClass: 'btn-primary'} // {result: 'ok', label: 'OK', cssClass: 'btn-primary'}

View file

@ -2,7 +2,10 @@ module.exports = angular.module('settings-notifications', [
require('stf/settings').name require('stf/settings').name
]) ])
.run(["$templateCache", function($templateCache) { .run(["$templateCache", function($templateCache) {
$templateCache.put('settings/notifications/notifications.jade', require('./notifications.jade')) $templateCache.put(
'settings/notifications/notifications.jade'
, require('./notifications.jade')
)
}]) }])
.factory('NotificationsService', require('./notifications-service')) .factory('NotificationsService', require('./notifications-service'))
.controller('NotificationsCtrl', require('./notifications-controller')) .controller('NotificationsCtrl', require('./notifications-controller'))

View file

@ -1,3 +1,3 @@
module.exports = function($scope) { module.exports = function NotificationsCtrl() {
} }