Skip to content

Commit

Permalink
Tightening down jshint and added some ignores where needed for now.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeoMix committed May 6, 2015
1 parent 9714a41 commit 2447c81
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 95 deletions.
7 changes: 3 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ module.exports = function(grunt) {
quotmark: 'single',
jquery: true,
maxparams: 5,
// TODO: Reduce these values.
maxdepth: 4,
maxstatements: 50,
maxcomplexity: 13,
maxlen: 90001,
maxstatements: 25,
maxcomplexity: 10,
maxlen: 200,
// Don't validate third-party libraries
ignores: ['src/js/thirdParty/**/*.js']
},
Expand Down
2 changes: 1 addition & 1 deletion src/js/background/collection/playlists.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
break;
}

// sendResponse becomes invalid when the event listener returns, unless you return true from the event listener to indicate you wish to send a response asynchronously (this will keep the message channel open to the other end until sendResponse is called).
// sendResponse becomes invalid after returning you return true to indicate a response will be sent asynchronously.
return sendAsynchronousResponse;
},

Expand Down
7 changes: 6 additions & 1 deletion src/js/background/collection/streamItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
},

addSongs: function(songs, options) {
// TODO: reduce cyclomatic complexity.
/* jshint ignore:start */
options = _.isUndefined(options) ? {} : options;
songs = songs instanceof Backbone.Collection ? songs.models : _.isArray(songs) ? songs : [songs];

Expand Down Expand Up @@ -125,6 +127,7 @@
}

return createdStreamItems;
/* jshint ignore:end */
},

_onAdd: function(model) {
Expand Down Expand Up @@ -267,7 +270,9 @@

_onChromeCommandsCommand: function(command) {
// Only respond to a subset of commands because all commands get broadcast, but not all are for this entity.
if (command === ChromeCommand.ShowSongDetails || command === ChromeCommand.DeleteSong || command === ChromeCommand.CopySongUrl || command === ChromeCommand.CopySongTitleAndUrl || command === ChromeCommand.SaveSong) {
var streamItemsCommands = [ChromeCommand.ShowSongDetails, ChromeCommand.DeleteSong, ChromeCommand.CopySongUrl, ChromeCommand.CopySongTitleAndUrl, ChromeCommand.SaveSong];

if (_.contains(streamItemsCommands, command)) {
if (this.length === 0) {
Streamus.channels.notification.commands.trigger('show:notification', {
title: chrome.i18n.getMessage('keyboardCommandFailure'),
Expand Down
144 changes: 75 additions & 69 deletions src/js/background/model/backgroundArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,27 @@
var ShuffleButton = require('background/model/buttons/shuffleButton');

var BackgroundArea = Backbone.Model.extend({
defaults: {
youTubePlayer: null,
analyticsManager: null,
foregroundUnloadTimeout: null
defaults: function() {
return {
browserSettings: new BrowserSettings(),
settings: new Settings(),
youTubePlayer: new YouTubePlayer(),
radioButton: new RadioButton(),
shuffleButton: new ShuffleButton(),
repeatButton: new RepeatButton(),
search: new Search(),
tabManager: new TabManager(),
signInManager: new SignInManager(),
analyticsManager: new AnalyticsManager(),
dataSourceManager: new DataSourceManager(),
player: null,
stream: null,
nextButton: null,
playPauseButton: null,
previousButton: null,

foregroundUnloadTimeout: null
};
},

initialize: function() {
Expand All @@ -36,101 +53,70 @@
this.listenTo(Streamus.channels.foreground.vent, 'endUnload', this._onForegroundEndUnload.bind(this));
chrome.runtime.onMessageExternal.addListener(this._onChromeRuntimeMessageExternal.bind(this));

var browserSettings = new BrowserSettings();
var settings = new Settings();

var youTubePlayer = new YouTubePlayer();
this.set('youTubePlayer', youTubePlayer);

var player = new Player({
settings: settings,
youTubePlayer: youTubePlayer
settings: this.get('settings'),
youTubePlayer: this.get('youTubePlayer')
});

var radioButton = new RadioButton();
var shuffleButton = new ShuffleButton();
var repeatButton = new RepeatButton();
this.set('player', player);

var stream = new Stream({
player: player,
shuffleButton: shuffleButton,
radioButton: radioButton,
repeatButton: repeatButton
shuffleButton: this.get('shuffleButton'),
radioButton: this.get('radioButton'),
repeatButton: this.get('repeatButton')
});
this.set('stream', stream);

var tabManager = new TabManager();
var signInManager = new SignInManager();
signInManager.signInWithGoogle();

var search = new Search();
// TODO: Do this via an event instead.
this.get('signInManager').signInWithGoogle();

var chromeContextMenusManager = new ChromeContextMenusManager({
browserSettings: browserSettings,
tabManager: tabManager,
signInManager: signInManager,
browserSettings: this.get('browserSettings'),
tabManager: this.get('tabManager'),
signInManager: this.get('signInManager'),
streamItems: stream.get('items')
});

var chromeIconManager = new ChromeIconManager({
player: player,
streamItems: stream.get('items'),
settings: settings,
tabManager: tabManager
settings: this.get('settings'),
tabManager: this.get('tabManager')
});

var chromeNotificationsManager = new ChromeNotificationsManager({
tabManager: tabManager,
settings: settings
tabManager: this.get('tabManager'),
settings: this.get('settings')
});

var chromeOmniboxManager = new ChromeOmniboxManager({
streamItems: stream.get('items')
});

var clientErrorManager = new ClientErrorManager({
signInManager: signInManager
signInManager: this.get('signInManager')
});

var nextButton = new NextButton({
this.set('nextButton', new NextButton({
stream: stream,
radioButton: radioButton,
shuffleButton: shuffleButton,
repeatButton: repeatButton
});
radioButton: this.get('radioButton'),
shuffleButton: this.get('shuffleButton'),
repeatButton: this.get('repeatButton')
}));

var playPauseButton = new PlayPauseButton({
this.set('playPauseButton', new PlayPauseButton({
player: player,
streamItems: stream.get('items')
});
}));

var previousButton = new PreviousButton({
this.set('previousButton', new PreviousButton({
player: player,
shuffleButton: shuffleButton,
repeatButton: repeatButton,
shuffleButton: this.get('shuffleButton'),
repeatButton: this.get('repeatButton'),
stream: stream
});

var dataSourceManager = new DataSourceManager();

var analyticsManager = new AnalyticsManager();
this.set('analyticsManager', analyticsManager);
}));

// Exposed globally so that the foreground can access the same instance through chrome.extension.getBackgroundPage()
window.analyticsManager = analyticsManager;
window.browserSettings = browserSettings;
window.tabManager = tabManager;
window.signInManager = signInManager;
window.settings = settings;
window.stream = stream;
window.nextButton = nextButton;
window.playPauseButton = playPauseButton;
window.previousButton = previousButton;
window.radioButton = radioButton;
window.repeatButton = repeatButton;
window.shuffleButton = shuffleButton;
window.search = search;
window.player = player;
window.dataSourceManager = dataSourceManager;
this._exposeProperties();
},

_onForegroundStarted: function() {
Expand All @@ -155,18 +141,38 @@
this._clearForegroundUnloadTimeout();
},

_clearForegroundUnloadTimeout: function() {
clearTimeout(this.get('foregroundUnloadTimeout'));
this.set('foregroundUnloadTimeout', null);
},

// Allow external websites to ping the extension to find out whether the extension is installed or not
_onChromeRuntimeMessageExternal: function(request, sender, sendResponse) {
if (request.message === 'isInstalled') {
sendResponse({
isInstalled: true
});
}
},

_clearForegroundUnloadTimeout: function() {
clearTimeout(this.get('foregroundUnloadTimeout'));
this.set('foregroundUnloadTimeout', null);
},

_exposeProperties: function() {
// TODO: Can I do this dynamically instead of explicitly?
// Exposed globally so that the foreground can access the same instance through chrome.extension.getBackgroundPage()
window.analyticsManager = this.get('analyticsManager');
window.browserSettings = this.get('browserSettings');
window.tabManager = this.get('tabManager');
window.signInManager = this.get('signInManager');
window.settings = this.get('settings');
window.stream = this.get('stream');
window.nextButton = this.get('nextButton');
window.playPauseButton = this.get('playPauseButton');
window.previousButton = this.get('previousButton');
window.radioButton = this.get('radioButton');
window.repeatButton = this.get('repeatButton');
window.shuffleButton = this.get('shuffleButton');
window.search = this.get('search');
window.player = this.get('player');
window.dataSourceManager = this.get('dataSourceManager');
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/js/background/model/signInManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
break;
}

// sendResponse becomes invalid when the event listener returns, unless you return true from the event listener to indicate you wish to send a response asynchronously (this will keep the message channel open to the other end until sendResponse is called).
// sendResponse becomes invalid after returning you return true to indicate a response will be sent asynchronously.
return sendAsynchronousResponse;
},

Expand Down
5 changes: 5 additions & 0 deletions src/js/background/model/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
// TODO: Function is way too big.
// If a streamItem which was active is removed, activateNext will have a removedActiveItemIndex provided
activateNext: function(removedActiveItemIndex) {
/* jshint ignore:start */
var nextItem = null;

var shuffleEnabled = this.get('shuffleButton').get('enabled');
Expand Down Expand Up @@ -140,6 +141,7 @@
}

return nextItem;
/* jshint ignore:end */
},

activatePrevious: function() {
Expand All @@ -160,6 +162,8 @@

// Return the previous item or null without affecting the history.
getPrevious: function() {
// TODO: Reduce cyclomatic complexity.
/* jshint ignore:start */
var previousStreamItem = null;
var history = this.get('history');
var items = this.get('items');
Expand Down Expand Up @@ -194,6 +198,7 @@
}

return previousStreamItem;
/* jshint ignore:end */
},

// A StreamItem's related song information is used when radio mode is enabled to allow users to discover new music.
Expand Down
43 changes: 25 additions & 18 deletions src/js/contentScript/beatport.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@
});
}

// Take a given track element and parse its children for information needed to query YouTube for corresponding song.
this.getQueryFromTrack = function(track) {
// Figure out the information needed to find a song on YouTube.
// Query will look like "primaryTitle remix artist1 artist2"
var primaryTitle = track.querySelector('[class*=track-primary-title]').textContent;
var remix = track.querySelector('[class*=track-remixed]').textContent;

var artistsNodeList = track.querySelectorAll('[class*=track-artists] a');
var artists = [];
for (var artistNodeIndex = 0; artistNodeIndex < artistsNodeList.length; artistNodeIndex++) {
artists.push(artistsNodeList[artistNodeIndex].textContent);
}

var query = primaryTitle;
// Original Mix can mess up YouTube queries since songs won't always have that value.
if (remix !== 'Original Mix') {
query = ' ' + remix;
}
query += ' ' + artists.join(' ');

return query;
}.bind(this);

// Pass enable: true in to enable Streamus icons. Pass enable: false in to disable Streamus icons and revert back to original Beatport functionality.
this.toggleStreamusIcons = function(enable) {
// Work within a container because bucket-items are scattered throughout Beatport pages.
Expand All @@ -47,27 +70,11 @@
var button = track.querySelector('.icon[class*=track-play]');

if (enable) {
// Figure out the information needed to find a song on YouTube.
// Query will look like "primaryTitle remix artist1 artist2"
var primaryTitle = track.querySelector('[class*=track-primary-title]').textContent;
var remix = track.querySelector('[class*=track-remixed]').textContent;

var artistsNodeList = track.querySelectorAll('[class*=track-artists] a');
var artists = [];
for (var artistNodeIndex = 0; artistNodeIndex < artistsNodeList.length; artistNodeIndex++) {
artists.push(artistsNodeList[artistNodeIndex].textContent);
}

var streamusQuery = primaryTitle;
// Original Mix can mess up YouTube queries since songs won't always have that value.
if (remix !== 'Original Mix') {
streamusQuery = ' ' + remix;
}
streamusQuery += ' ' + artists.join(' ');
var query = this.getQueryFromTrack(track);

// Decorate button to indicate it is Streamus-ified, cache query on the button so playAll can read it.
button.classList.add('streamusButton');
button.dataset.streamusQuery = streamusQuery;
button.dataset.streamusQuery = query;
button.addEventListener('click', onTrackPlayButtonClick);
} else {
button.classList.remove('streamusButton');
Expand Down
3 changes: 3 additions & 0 deletions src/js/contentScript/youTube.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@
}.bind(this);

this.onChromeRuntimeMessage = function(message) {
// TODO: Reduce cyclomatic complexity.
/* jshint ignore:start */
if (message.action) {
this[message.action](message.value);
}
Expand Down Expand Up @@ -212,6 +214,7 @@
break;
}
}
/* jshint ignore:end */
}.bind(this);

this.onGetYouTubeContentScriptDataResponse = function(youTubeContentScriptData) {
Expand Down
3 changes: 3 additions & 0 deletions src/js/foreground/view/behavior/slidingRender.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@
},

_setRenderedElements: function(scrollTop) {
// TODO: Clean this up. It's still such a huge function.
/* jshint ignore:start */
// Figure out the range of items currently rendered:
var currentMinRenderIndex = this.minRenderIndex;
var currentMaxRenderIndex = this.maxRenderIndex;
Expand Down Expand Up @@ -190,6 +192,7 @@
}

this.lastScrollTop = scrollTop;
/* jshint ignore:end */
},

_setHeightTranslateY: function() {
Expand Down

0 comments on commit 2447c81

Please sign in to comment.