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,
"immed": true,
"latedef": "nofunc",
"newcap": true,
"newcap": false,
"noarg": true,
"noempty": true,
"nonbsp": true,
@ -24,6 +24,7 @@
"beforeEach": false,
"after": false,
"afterEach": false,
"expect": true,
"inject": false,
"angular": false
}

View file

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

View file

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

View file

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

View file

@ -12,8 +12,8 @@ describe('refreshPage', function () {
it('should ...', function () {
/*
To test your directive, you need to create some html that would use your directive,
send that through compile() then compare the results.
To test your directive, you need to create some html that would use your
directive, send that through compile() then compare the results.
var element = compile('<div refresh-page name="name">hi</div>')(scope);
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 = {
}

View file

@ -1,6 +1,5 @@
var oboe = require('oboe')
var _ = require('lodash')
var Promise = require('bluebird')
module.exports = function DeviceServiceFactory($rootScope, $http, socket) {
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) {
return function (scope, element, attrs) {
var links = element.find('a')
var onClass = attrs.navMenu || 'current'
var routePattern
var routeBasePattern = /\/#[^/]*/ // TODO: add regex to remove last part of the url
var link
var url
var currentLink

View file

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

View file

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

View file

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

View file

@ -7,19 +7,6 @@
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.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.
@ -114,13 +103,15 @@ var Renderer = function (gl) {
var count = gl.getProgramParameter(this.program_, gl.ACTIVE_UNIFORMS);
for (var i = 0; i < /** @type {number} */(count); 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);
for (var j = 0; j < /** @type {number} */(count); 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 tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
@ -242,20 +238,7 @@ Renderer.fragmentShaderSource_ = [
// -------------------------------------------------------------------------------------------------
function WebGLRender(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')
}
}
function WebGLRender(canvasElement) {
this.options = {
// alpha: this.transparent,
// antialias: !!antialias,
@ -270,7 +253,8 @@ function WebGLRender(canvasElement, options) {
this.ctx = canvasElement.getContext('webgl', this.options)
} catch (e2) {
// 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.ctx.bindBuffer(this.ctx.ARRAY_BUFFER, this.vertexBuff)
this.ctx.bufferData(
this.ctx.ARRAY_BUFFER,
new Float32Array([-1 / 8, 1 / 6, -1 / 8, -1 / 6, 1 / 8, -1 / 6, 1 / 8, 1 / 6]),
this.ctx.STATIC_DRAW)
this.ctx.ARRAY_BUFFER
, new Float32Array([
-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.ctx.bindBuffer(this.ctx.ARRAY_BUFFER, this.texBuff)
@ -358,15 +352,43 @@ WebGLRender.prototype.draw = function (image) {
WebGLRender.prototype.drawOld = function (image) {
var tex = this.ctx.createTexture()
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.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.texParameteri(
this.ctx.TEXTURE_2D
, this.ctx.TEXTURE_MIN_FILTER
, this.ctx.NEAREST
)
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.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.bindBuffer(this.ctx.ARRAY_BUFFER, this.vertexBuff)
@ -440,7 +462,7 @@ FastImageRender.prototype.load = function (url, type) {
var texture = null
if (type) {
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') {
that.onLoad(texture)
}

View file

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

View file

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

View file

@ -1,11 +1,11 @@
var _ = require('lodash')
module.exports = function GroupServiceFactory(socket, UserService, TransactionService) {
module.exports = function GroupServiceFactory(
socket
, TransactionService
) {
var groupService = {
}
groupService.invite = function (device) {
return UserService.user().then(function (user) {
var tx = TransactionService.create([device])
socket.emit('group.invite', device.channel, tx.channel, {
serial: {
@ -19,11 +19,9 @@ module.exports = function GroupServiceFactory(socket, UserService, TransactionSe
}
return results[0].device
})
})
}
groupService.kick = function (device) {
return UserService.user().then(function (user) {
var tx = TransactionService.create([device])
socket.emit('group.kick', device.channel, tx.channel, {
serial: {
@ -37,7 +35,6 @@ module.exports = function GroupServiceFactory(socket, UserService, TransactionSe
}
return results[0].device
})
})
}
return groupService

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.device = null
$scope.control = null
@ -12,7 +19,7 @@ module.exports = function DeviceControlCtrl($scope, $routeParams, $location, Dev
$scope.control = ControlService.forOne(device, device.channel)
return device
})
.catch(function(err) {
.catch(function() {
$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
])
.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'))
.controller('LanguageCtrl', require('./language-controller'))

View file

@ -1,6 +1,10 @@
var _ = require('lodash')
module.exports = function LanguageServiceFactory(SettingsService, $q, gettextCatalog) {
module.exports = function LanguageServiceFactory(
SettingsService
, $q
, gettextCatalog
) {
var LanguageService = {}
LanguageService.supportedLanguages = [
@ -10,7 +14,10 @@ module.exports = function LanguageServiceFactory(SettingsService, $q, gettextCat
var browserLocale = navigator.language || navigator.userLanguage || 'en-US'
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'
LanguageService.detectedLanguage = defaultLanguage
LanguageService.selectedLanguage = null
@ -29,7 +36,8 @@ module.exports = function LanguageServiceFactory(SettingsService, $q, gettextCat
if (data) {
deferred.resolve(data)
} else {
LanguageService.setSelectedLanguage(LanguageService.detectedLanguage).then(function () {
LanguageService.setSelectedLanguage(LanguageService.detectedLanguage)
.then(function () {
deferred.resolve(LanguageService.detectedLanguage)
})
}

View file

@ -8,6 +8,9 @@ module.exports = angular.module('ui-local-settings', [
//'dialogs'
])
.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'))

View file

@ -8,7 +8,8 @@ module.exports = function ($scope, SettingsService) {
// $scope.resetSettings = function () {
// 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 = [
// {result: 'cancel', label: 'Cancel'},
// {result: 'ok', label: 'OK', cssClass: 'btn-primary'}

View file

@ -2,7 +2,10 @@ module.exports = angular.module('settings-notifications', [
require('stf/settings').name
])
.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'))
.controller('NotificationsCtrl', require('./notifications-controller'))

View file

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