Skip to content

Commit

Permalink
Merge pull request #175 from fmtvp/strict-mode-compatibility
Browse files Browse the repository at this point in the history
Strict mode compatibility
  • Loading branch information
tsadler1988 committed Sep 10, 2014
2 parents 68ab0a4 + 398e31d commit d69c98b
Show file tree
Hide file tree
Showing 98 changed files with 356 additions and 88 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ chromedriver.log
/.settings
libpeerconnection.log
*.iml
node_modules
37 changes: 37 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"globals": {
"jQuery": true,
"console": true,
"module": true,
"document": true,
"require": true,
"window": true,
"Image": true,
"XMLHttpRequest": true,
"setTimeout": true,
"clearTimeout": true,
"clearInterval": true,
"navigator": true,
"setInterval": true,
"define": true,
"HTMLMediaElement": true,
"alert": true,
"antie": true,
"history": true,
"unescape": true
},
"asi": true,
"laxbreak": true,
"strict": true,
"noarg": true,
"validthis": true,
"latedef": "nofunc",
"undef": true,
"funcscope": true,
"-W041": false, // Treble equals
"-W058": false, // Missing "()" invoking a constructor
"-W065": false, // Missing radix parameter
"boss": true,
"newcap": false,
"es3": true
}
31 changes: 31 additions & 0 deletions gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* jshint node: true */
module.exports = function (grunt) {
"use strict";

grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
jshint: {
files: ['static/script/**/*.js'],
options: {
jshintrc: '.jshintrc',
// options here to override JSHint defaults
ignores: [
'static/script/lib/*',
'static/script/devices/googletv.js',
'static/script/devices/data/json2.js',
'static/script/widgets/horizontalcarousel.js'

]
}
},
watch: {
jshint: {
files: ["static/script/**/*.js"],
tasks: ["jshint"]
}
}
});

grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-contrib-jshint");
};
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "bbc-fmtvp-tal",
"version": "0.0.0",
"description": "Library for building applications for Connected TV devices",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-cli": "~0.1.6",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-watch": "~0.6.1"
}
}
6 changes: 4 additions & 2 deletions static/script/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ require.def('antie/application',
'antie/devices/device'
],
function(Class, RuntimeContext, ComponentContainer, Button, List, Device) {

'use strict';

/**
* Abstract base class for Bigscreen applications.
* @name antie.Application
Expand All @@ -54,6 +55,7 @@ require.def('antie/application',
* @constructor
* @ignore
*/

init: function(rootElement, styleBaseUrl, imageBaseUrl, onReadyHandler, configOverride) {
RuntimeContext.setCurrentApplication(this);

Expand Down Expand Up @@ -184,7 +186,7 @@ require.def('antie/application',
if(callback) {
var currentlyLoadingIndex = -1;
var self = this;
function cssLoadedCallback() {
var cssLoadedCallback = function() {
if(++currentlyLoadingIndex < css.length) {
self._device.loadStyleSheet(styleBaseUrl + css[currentlyLoadingIndex], cssLoadedCallback);
} else {
Expand Down
2 changes: 2 additions & 0 deletions static/script/audiosource.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
require.def('antie/audiosource',
['antie/mediasource'],
function(MediaSource) {
'use strict';

/**
* An audio media source. Provides storage of source and type information about an audio media source.
* @name antie.AudioSource
Expand Down
94 changes: 48 additions & 46 deletions static/script/class.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* Surpression of JSHint 'Don't make functions within a loop'*/
/* jshint -W083 */
/**
* @fileOverview Requirejs module containing antie.Class top-level base class.
*
Expand All @@ -8,16 +10,16 @@
*/

require.def('antie/class', function() {

var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
"use strict";
var initializing = false, fnTest = /var xyz/.test(function () { var xyz; }) ? /\b_super\b/ : /.*/;

/**
* The base Class implementation (does nothing)
* @name antie.Class
* @class
* @abstract
*/
var Class = function(){};
function Class(){}

/**
* Create a new Class that inherits from this class
Expand All @@ -28,56 +30,56 @@ require.def('antie/class', function() {
* @param {Object} prop Prototype to add to the new extended class.
*/
Class.extend = function(prop) {
var _super = this.prototype;

var _super = this.prototype;
// Instantiate a base class (but only create the instance,
// don't run the init constructor)
initializing = true;
var prototype = new this();
var proto = new this();
initializing = false;

// Copy the properties over onto the new prototype
for (var name in prop) {
// Check if we're overwriting an existing function
prototype[name] = typeof prop[name] == "function" &&
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
(function(name, fn){
return function() {
var tmp = this._super;

// Add a new ._super() method that is the same method
// but on the super-class
this._super = _super[name];

// The method only need to be bound temporarily, so we
// remove it when we're done executing
var ret = fn.apply(this, arguments);
this._super = tmp;

return ret;
};
})(name, prop[name]) :
prop[name];
}

// Copy the properties over onto the new prototype
for (var name in prop) {
// Check if we're overwriting an existing function
proto[name] = typeof prop[name] === "function" &&
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
(function(name, fn){
return function() {
var tmp = this._super;
// Add a new ._super() method that is the same method
// but on the super-class
this._super = _super[name];
// The method only need to be bound temporarily, so we
// remove it when we're done executing
var ret = fn.apply(this, arguments);
this._super = tmp;
return ret;
};
})(name, prop[name]) :
prop[name];
}
// The dummy class constructor
function Class() {
var newClass = function() {
// All construction is actually done in the init method
if ( !initializing && this.init )
this.init.apply(this, arguments);
}

// Populate our constructed prototype object
Class.prototype = prototype;

// Enforce the constructor to be what we expect
Class.constructor = Class;

// And make this class extendable
Class.extend = arguments.callee;

return Class;
};
};
// Populate our constructed prototype object
newClass.prototype = proto;
// Enforce the constructor to be what we expect
proto.constructor = newClass;
// And make this class extendable
newClass.extend = Class.extend;
return newClass;
};

return Class;
return Class;
});
12 changes: 9 additions & 3 deletions static/script/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
require.def('antie/datasource',
['antie/class'],
function(Class) {
'use strict';

/**
* Utility class to wrap disparate functions into a common interface for binding to lists.
* @name antie.DataSource
Expand All @@ -48,13 +50,17 @@ require.def('antie/datasource',
this._obj = obj;
this._func = func;
this._args = args;



if(component) {
var self = this;
component.addEventListener('beforehide', function() {
component.removeEventListener('beforehide', arguments.callee);

var beforeHideListener = function() {
component.removeEventListener('beforehide', beforeHideListener);
self.abort();
});
};
component.addEventListener('beforehide', beforeHideListener);
}
},
/**
Expand Down
2 changes: 2 additions & 0 deletions static/script/devices/anim/noanim.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ require.def(
['antie/devices/browserdevice',
'antie/devices/anim/shared/transitionendpoints'],
function(Device, TransitionEndPoints) {
'use strict';

/* documented in antie.devices.Device */
Device.prototype.scrollElementTo = function(options) {
if(new RegExp("_mask$").test(options.el.id)) {
Expand Down
2 changes: 2 additions & 0 deletions static/script/devices/anim/styletopleft.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ require.def(
'antie/devices/anim/tween'
],
function(Device, TransitionEndPoints) {
'use strict';

function movesScroll( startLeft, startTop, changeLeft, changeTop, options ){
var to, from;
if ((changeLeft === 0) && (changeTop === 0)) {
Expand Down
2 changes: 2 additions & 0 deletions static/script/devices/anim/tween.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ require.def(
'antie/lib/shifty'
],
function(Device, Tweenable) {
'use strict';

// A set of queues of DOM updates to perform. Each animation framerate gets its own queue
// so they are in sync between themselves.
var animQueues = {};
Expand Down
2 changes: 2 additions & 0 deletions static/script/devices/broadcastsource/basetvsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ require.def('antie/devices/broadcastsource/basetvsource',
'antie/devices/browserdevice'
],
function (Class, Device) {
'use strict';

/**
* Contains an abstract implementation of the antie base broadcast TV source.
* @private
Expand Down
1 change: 1 addition & 0 deletions static/script/devices/broadcastsource/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ require.def('antie/devices/broadcastsource/channel',
'antie/class'
],
function (Class) {
'use strict';

/**
* Class representing information about a channel.
Expand Down
2 changes: 2 additions & 0 deletions static/script/devices/broadcastsource/hbbtvsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ require.def('antie/devices/broadcastsource/hbbtvsource',
'antie/events/tunerstoppedevent'
],
function (Device, BaseTvSource, RuntimeContext, Channel, TunerUnavailableEvent, TunerPresentingEvent, TunerStoppedEvent ) {
'use strict';

/**
* Contains a HBBTV implementation of the antie broadcast TV source.
*/
Expand Down
4 changes: 4 additions & 0 deletions static/script/devices/broadcastsource/samsungtvsource.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global webapis */

/**
* @fileOverview Requirejs module containing the antie.devices.broadcastsource.samsungtvsource class.
*
Expand Down Expand Up @@ -35,6 +37,8 @@ require.def('antie/devices/broadcastsource/samsungtvsource',
'antie/events/tunerpresentingevent'
],
function (Device, BaseTvSource, RuntimeContext, Channel, TunerUnavailableEvent, TunerStoppedEvent, TunerPresentingEvent) {
'use strict';

/**
* Contains a Samsung Maple implementation of the antie broadcast TV source.
* @see http://www.samsungdforum.com/Guide/ref00014/PL_WINDOW_SOURCE.html
Expand Down
8 changes: 5 additions & 3 deletions static/script/devices/browserdevice.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* jshint -W030 */
/**
* @fileOverview Requirejs module containing the antie.BrowserDevice class.
*
Expand Down Expand Up @@ -31,6 +32,7 @@ require.def("antie/devices/browserdevice",
"antie/historian"
],
function(Device, KeyEvent, Historian) {
'use strict';

function trim(str) {
return str.replace(/^\s+/, '').replace(/\s+$/, '');
Expand Down Expand Up @@ -216,7 +218,7 @@ require.def("antie/devices/browserdevice",
// http://www.backalleycoder.com/2011/03/20/link-tag-css-stylesheet-load-event/
if (callback) {
var img = this._createElement("img");
function done() {
var done = function() {
img.onerror = function() {};
callback(url);
img.parentNode.removeChild(img);
Expand Down Expand Up @@ -514,8 +516,8 @@ require.def("antie/devices/browserdevice",
stylesheetElements.push(linkElements[i]);
}

for (var i = 0; i < styleElements.length; i++) {
stylesheetElements.push(styleElements[i]);
for (var j = 0; j < styleElements.length; j++) {
stylesheetElements.push(styleElements[j]);
}

return stylesheetElements;
Expand Down
2 changes: 2 additions & 0 deletions static/script/devices/data/nativejson.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ require.def(
"antie/devices/data/nativejson",
['antie/devices/browserdevice'],
function(Device) {
'use strict';

/* Patch Device.prototype.encodeJson and Device.prototype.decodeJson */
Device.prototype.decodeJson = function(json) {
return JSON.parse(json);
Expand Down
Loading

0 comments on commit d69c98b

Please sign in to comment.