Skip to content

Commit

Permalink
Add jshint checking to sherd code
Browse files Browse the repository at this point in the history
Mediathread has a stricter `.jshintrc` than SherdJS did, so
there were some changes needed to get this passing.

`escape()` and `unescape()` are deprecated -- I've converted
them to `encodeURI` / `decodeURI`.
http://www.w3schools.com/jsref/jsref_escape.asp
http://www.w3schools.com/jsref/jsref_unescape.asp
  • Loading branch information
nikolas committed Nov 4, 2015
1 parent e685a88 commit 5374e2e
Show file tree
Hide file tree
Showing 22 changed files with 49 additions and 26 deletions.
6 changes: 3 additions & 3 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"trailing": true,
"undef": true,
"browser": true,
"eqeqeq": true,
"curly": true,
"eqeqeq": true,
"curly": true,
"predef": [
"$",
"confirm",
"confirm",
"jQuery"
]
}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jenkins: ./ve/bin/python validate jshint jscs flake8 test
./bootstrap.py

jshint: node_modules/jshint/bin/jshint
./node_modules/jshint/bin/jshint --config=.jshintrc media/js/app/
./node_modules/jshint/bin/jshint --config=.jshintrc media/js/app/ media/js/lib/sherdjs/src

jscs: node_modules/jscs/bin/jscs
./node_modules/jscs/bin/jscs media/js/app/
Expand Down
5 changes: 3 additions & 2 deletions media/js/lib/sherdjs/src/assets.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global Sherd: true */
if (typeof Sherd === 'undefined') {
Sherd = {};
}
Expand Down Expand Up @@ -159,8 +160,8 @@ if (!Sherd.GenericAssetView) {
}
} else {
if (window.console) {
console.log(options);
console.log(self.settings);
window.console.log(options);
window.console.log(self.settings);
}
throw new Error("Your asset does not have a (supported) type marked.");
}
Expand Down
3 changes: 2 additions & 1 deletion media/js/lib/sherdjs/src/base.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global Sherd: true, MochiKit: true */
if (typeof Sherd === 'undefined' || !Sherd) {
Sherd = {};
}
Expand Down Expand Up @@ -134,7 +135,7 @@ Sherd.Base = {
} else if (typeof possiblePromise === 'object') {
self.components = possiblePromise;
} else {
console.error('components error:', possiblePromise);
window.console.error('components error:', possiblePromise);
}
} else {
self.components = {
Expand Down
4 changes: 2 additions & 2 deletions media/js/lib/sherdjs/src/configs/demo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var annotations=[
/* global Sherd: true */
var annotations = [
{type:'annotation',
view:{editable:true,color:'red'},
metadata:{title:'My favorite part'},
Expand Down
9 changes: 5 additions & 4 deletions media/js/lib/sherdjs/src/configs/djangosherd.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global Sherd: true, djangosherd: true */
function DjangoSherd_NoteForm() {
var self = this;
Sherd.Base.DomObject.apply(this, arguments);// inherit
Expand Down Expand Up @@ -124,7 +125,7 @@ function DjangoSherd_AssetMicroFormat() {
// /use getAttribute rather than href, to avoid
// urlencodings
/// unescape necessary for IE7 (and sometimes 8)
rv[reg[1]] = unescape(elt.getAttribute('href'));
rv[reg[1]] = decodeURI(elt.getAttribute('href'));
// /TODO: maybe look for some data attributes here, too,
// when we put them there.
var metadata = elt.getAttribute('data-metadata');
Expand Down Expand Up @@ -315,7 +316,7 @@ CitationView.prototype.decorateElementLinks = function (element) {
jQuery(this).addClass('active-annotation');
} catch (e) {
if (window.console) {
console.log('ERROR opening citation:' + e.message);
window.console.log('ERROR opening citation:' + e.message);
}
}
evt.preventDefault();
Expand Down Expand Up @@ -538,7 +539,7 @@ function DjangoSherd_Storage() {
errorCallback();
}
if (window.console) {
console.log(textStatus);
window.console.log(textStatus);
}
}
});
Expand Down Expand Up @@ -670,4 +671,4 @@ window.DjangoSherd_Colors = {

};

DjangoSherd_Colors.reset();
window.DjangoSherd_Colors.reset();
1 change: 1 addition & 0 deletions media/js/lib/sherdjs/src/image/annotators/fsiviewer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global Sherd: true */
if (!Sherd) { Sherd = {}; }
if (!Sherd.Image) { Sherd.Image = {}; }
if (!Sherd.Image.Annotators) { Sherd.Image.Annotators = {}; }
Expand Down
1 change: 1 addition & 0 deletions media/js/lib/sherdjs/src/image/annotators/openlayers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global Sherd: true, OpenLayers: true */
if (!Sherd) { Sherd = {}; }
if (!Sherd.Image) { Sherd.Image = {}; }
if (!Sherd.Image.Annotators) { Sherd.Image.Annotators = {}; }
Expand Down
1 change: 1 addition & 0 deletions media/js/lib/sherdjs/src/image/views/fsiviewer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global Sherd: true */
//jQuery dependencies
if (!Sherd) { Sherd = {}; }
if (!Sherd.Image) { Sherd.Image = {}; }
Expand Down
1 change: 1 addition & 0 deletions media/js/lib/sherdjs/src/image/views/openlayers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global Sherd: true, OpenLayers: true */
/****
An annotation looks like this:
///1
Expand Down
1 change: 1 addition & 0 deletions media/js/lib/sherdjs/src/video/annotators/clipform.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global Sherd: true */
///clipform-display
///1. update noteform field: DjangoSherd_UpdateHack()
///2. initialize clipform field vals
Expand Down
2 changes: 1 addition & 1 deletion media/js/lib/sherdjs/src/video/annotators/clipstrip.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

/* global Sherd: true */
//Use Cases:
//Default
//-- starttime:0, endtime:0, duration:0
Expand Down
9 changes: 6 additions & 3 deletions media/js/lib/sherdjs/src/video/views/flowplayer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global Sherd: true, flowplayer: true, $f: true */
/*
* Using Flowplayer to support the flash video and mp4 formats
* Support for the Flowplayer js-enabled player. documentation at:
Expand Down Expand Up @@ -169,7 +170,7 @@ if (!Sherd.Video.Flowplayer && Sherd.Video.Base) {
var newUrl = self.microformat._getPlayerParams(obj);
if (newUrl.url && document.getElementById(self.components.playerID) && self.media.state() > 0) {
var playlist = self.components.player.getPlaylist();
if (playlist[0].url == newUrl.url) {
if (playlist[0].url === newUrl.url) {
// If the url is the same as the previous, just seek to the right spot.
// This works just fine.
rc = true;
Expand Down Expand Up @@ -234,7 +235,7 @@ if (!Sherd.Video.Flowplayer && Sherd.Video.Base) {
if (queryString === 'start={start}') {
queryString = 'start=${start}';
}
rc.queryString = escape('?' + queryString);
rc.queryString = encodeURI('?' + queryString);
rc.url = pieces.join('?');
}
return rc;
Expand Down Expand Up @@ -388,7 +389,9 @@ if (!Sherd.Video.Flowplayer && Sherd.Video.Base) {
options);

// Save reference to the player
self.components.player = $f(create_obj.playerID);
if (typeof $f === 'function') {
self.components.player = $f(create_obj.playerID);
}
self.components.provider = create_obj.playerParams.provider;

// Setup timers to watch for readiness to seek/setState
Expand Down
3 changes: 2 additions & 1 deletion media/js/lib/sherdjs/src/video/views/flowplayer5.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global Sherd: true, flowplayer: true */
/*
* Using Flowplayer 5 to support the flash video and mp4 formats
* Support for the Flowplayer js-enabled player. documentation at:
Expand Down Expand Up @@ -131,7 +132,7 @@ if (!Sherd.Video.Flowplayer && Sherd.Video.Base) {
var rc = false;
var newUrl = self.microformat._getPlayerParams(obj);
if (newUrl.url && document.getElementById(self.components.playerID) && self.media.ready()) {
if (self.components.player.video.url == newUrl.url) {
if (self.components.player.video.url === newUrl.url) {
// If the url is the same as the previous, just seek to the right spot.
// This works just fine.
rc = true;
Expand Down
5 changes: 3 additions & 2 deletions media/js/lib/sherdjs/src/video/views/jwplayer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global Sherd: true, jwplayer: true */
/*
* Using Flowplayer 5 to support the flash video and mp4 formats
* Support for the Flowplayer js-enabled player. documentation at:
Expand Down Expand Up @@ -109,7 +110,7 @@ if (!Sherd.Video.JWPlayer && Sherd.Video.Base) {
var newUrl = obj.mp4_audio;
if (newUrl && document.getElementById(self.components.playerID) && self.state.ready) {
var playlist = self.components.player.getPlaylistItem(0);
if (playlist.file == newUrl) {
if (playlist.file === newUrl) {
// If the url is the same as the previous, just seek to the right spot.
// This works just fine.
rc = true;
Expand Down Expand Up @@ -196,7 +197,7 @@ if (!Sherd.Video.JWPlayer && Sherd.Video.Base) {
};

this.media.isPlaying = function () {
return self.components.player && self.components.player.getState() == 'PLAYING';
return self.components.player && self.components.player.getState() === 'PLAYING';
};

this.media.ready = function () {
Expand Down
3 changes: 2 additions & 1 deletion media/js/lib/sherdjs/src/video/views/kaltura.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global Sherd: true */
/*
Support for the Kaltura js-enabled player. documentation at:
http://Kaltura.com/api/docs/oembed
Expand Down Expand Up @@ -288,4 +289,4 @@ if (!Sherd.Video.Kaltura && Sherd.Video.Base) {
};
};
};
}
}
3 changes: 3 additions & 0 deletions media/js/lib/sherdjs/src/video/views/quicktime.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* global Sherd: true */
/* global onQuicktimePlay: true, onQuicktimePause: true */
/* global onQuicktimeFinish: true */
/*
http://developer.apple.com/mac/library/documentation/QuickTime/Conceptual/QTScripting_JavaScript/aQTScripting_Javascro_AIntro/Introduction%20to%20JavaScript%20QT.html
http://developer.apple.com/safari/library/documentation/QuickTime/Conceptual/QTScripting_JavaScript/bQTScripting_JavaScri_Document/QuickTimeandJavaScri.html
Expand Down
3 changes: 2 additions & 1 deletion media/js/lib/sherdjs/src/video/views/realplayer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global Sherd: true */
/*
Documentation:
http://service.real.com/help/library/guides/ScriptingGuide/HTML/samples/javaembed/JAVAFrames.htm
Expand Down Expand Up @@ -292,4 +293,4 @@ if (!Sherd.Video.RealPlayer && Sherd.Video.Base) {

}; //Sherd.Video.RealPlayer

}
}
1 change: 1 addition & 0 deletions media/js/lib/sherdjs/src/video/views/video.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global Sherd: true */
/**
* baseline video helper functions:
*
Expand Down
3 changes: 2 additions & 1 deletion media/js/lib/sherdjs/src/video/views/videotag.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global Sherd: true */
/*
Documentation:
Expand Down Expand Up @@ -262,4 +263,4 @@ if (!Sherd.Video.Videotag) {

}; //Sherd.Video.Videotag

}
}
3 changes: 2 additions & 1 deletion media/js/lib/sherdjs/src/video/views/vimeo.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global Sherd: true */
/*
Support for the Vimeo js-enabled player. documentation at:
http://vimeo.com/api/docs/oembed
Expand Down Expand Up @@ -338,4 +339,4 @@ if (!Sherd.Video.Vimeo) {
return self.components.player.api_getVideoUrl();
};
};
}
}
6 changes: 4 additions & 2 deletions media/js/lib/sherdjs/src/video/views/youtube.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global Sherd: true, console: true, getYouTubeID: true */
/* global YT: true */
/*
Support for the YouTube js-enabled player. documentation at:
http://code.google.com/apis/youtube/js_api_reference.html
Expand Down Expand Up @@ -227,7 +229,7 @@ if (!Sherd.Video.YouTube) {

// Global function required for the player
window.onPlayerReady = function() {
if (unescape(self.playerID) === self.components.playerID) {
if (decodeURI(self.playerID) === self.components.playerID) {
self.media._ready = true;

// Once the player is ready -- sort out any autoplay+seek requests
Expand All @@ -254,7 +256,7 @@ if (!Sherd.Video.YouTube) {
} else {
console.error(
'playerID mismatch:',
unescape(self.playerID),
decodeURI(self.playerID),
self.components.playerID);
}
};
Expand Down

0 comments on commit 5374e2e

Please sign in to comment.