From 8b986ec3cbe9ecb81906f1f4714792e879790863 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Sat, 12 Dec 2015 13:37:59 -0800 Subject: [PATCH] Add eslint --- .eslintrc | 90 +++++ .gitignore | 2 + js/browser.js | 18 +- js/context.js | 62 +-- js/embed.js | 80 ++-- js/font.js | 132 +++---- js/hotkeys.js | 90 ++--- js/main-window.js | 590 +++++++++++++++-------------- js/main.js | 73 ++-- js/media.js | 476 ++++++++++++----------- js/multi-display.js | 112 +++--- js/my-file.js | 54 +-- js/skin-sprites.js | 288 +++++++------- js/skin.js | 158 ++++---- js/{ => vendor}/jszip.2.4.0.min.js | 0 js/visualizer.js | 308 +++++++-------- js/winamp.js | 340 ++++++++--------- js/window-manager.js | 95 ++--- 18 files changed, 1537 insertions(+), 1431 deletions(-) create mode 100644 .eslintrc rename js/{ => vendor}/jszip.2.4.0.min.js (100%) diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 00000000..1c9210ea --- /dev/null +++ b/.eslintrc @@ -0,0 +1,90 @@ +{ + "env": { + "browser": true, + "node": true, + "amd": true + }, + + "rules": { + "block-scoped-var": 1, + "brace-style": [1, "1tbs"], + "camelcase": 2, + "comma-dangle": [2, "never"], + "comma-spacing": 2, + "consistent-return": 1, + "dot-notation": [2, { "allowKeywords": false }], + "eol-last": 2, + "eqeqeq": [2, "smart"], + "indent": [2, 2, {"SwitchCase": 1}], + "key-spacing": 1, + "linebreak-style": 2, + "max-depth": [1, 4], + "max-params": [1, 5], + "new-cap": 2, + "no-alert": 2, + "no-caller": 2, + "no-catch-shadow": 2, + "no-debugger": 2, + "no-delete-var": 2, + "no-div-regex": 1, + "no-dupe-args": 2, + "no-dupe-keys": 2, + "no-duplicate-case": 2, + "no-else-return": 1, + "no-empty-character-class": 2, + "no-empty-label": 2, + "no-eval": 2, + "no-ex-assign": 2, + "no-extend-native": 1, + "no-extra-boolean-cast": 2, + "no-extra-semi": 2, + "no-fallthrough": 2, + "no-floating-decimal": 2, + "no-func-assign": 2, + "no-implied-eval": 2, + "no-inner-declarations": 2, + "no-irregular-whitespace": 2, + "no-label-var": 2, + "no-lone-blocks": 2, + "no-lonely-if": 2, + "no-multi-spaces": 1, + "no-multi-str": 2, + "no-native-reassign": 2, + "no-negated-in-lhs": 1, + "no-nested-ternary": 2, + "no-new-object": 2, + "no-new-wrappers": 2, + "no-obj-calls": 2, + "no-octal": 2, + "no-octal-escape": 2, + "no-proto": 2, + "no-redeclare": 2, + "no-shadow": 2, + "no-spaced-func": 2, + "no-throw-literal": 2, + "no-trailing-spaces": 2, + "no-undef": 2, + "no-undef-init": 2, + "no-undefined": 2, + "no-unneeded-ternary": 2, + "no-unreachable": 2, + "no-unused-expressions": 2, + "no-unused-vars": 2, + "no-use-before-define": [2, "nofunc"], + "no-with": 2, + "quote-props": [1, "consistent-as-needed"], + "quotes": [2, "single", "avoid-escape"], + "radix": 2, + "semi": 2, + "space-after-keywords": [2, "always"], + "space-before-keywords": [2, "always"], + "space-before-function-paren": [2, {"anonymous": "never", "named": "never"}], + "object-curly-spacing": [2, "never"], + "space-infix-ops": 2, + "space-return-throw-case": 2, + "space-unary-ops": [2, { "words": true, "nonwords": false }], + "use-isnan": 2, + "valid-typeof": 2, + "wrap-iife": 2 + } +} diff --git a/.gitignore b/.gitignore index 669819b5..968077a3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ preview.png # Files I use for local dev sometimes llama-2.91.mp3 + +node_modules diff --git a/js/browser.js b/js/browser.js index 84065fe3..89720d18 100644 --- a/js/browser.js +++ b/js/browser.js @@ -1,13 +1,13 @@ define({ - isCompatible: function() { - return this._supportsAudioApi() && this._supportsCanvas(); - }, + isCompatible: function() { + return this._supportsAudioApi() && this._supportsCanvas(); + }, - _supportsAudioApi: function() { - return !!(window.AudioContext || window.webkitAudioContext); - }, - _supportsCanvas: function() { - return !!document.createElement('canvas').getContext; - } + _supportsAudioApi: function() { + return !!(window.AudioContext || window.webkitAudioContext); + }, + _supportsCanvas: function() { + return !!document.createElement('canvas').getContext; + } }); diff --git a/js/context.js b/js/context.js index 1fafa9e2..47f0b311 100644 --- a/js/context.js +++ b/js/context.js @@ -1,45 +1,45 @@ define([ - 'my-file' + 'my-file' ], function( - MyFile + MyFile ) { -return { + return { init: function(winamp) { - this.winamp = winamp; + this.winamp = winamp; - // The Option button - this.option = document.getElementById('option'); - var self = this; + // The Option button + this.option = document.getElementById('option'); + var self = this; - document.onclick = function() { - self.option.classList.remove('selected'); - }; + document.onclick = function() { + self.option.classList.remove('selected'); + }; - this.option.onclick = function(event) { - self.option.classList.toggle('selected'); - event.stopPropagation(); - }; + this.option.onclick = function(event) { + self.option.classList.toggle('selected'); + event.stopPropagation(); + }; - var skinSelectNodes = document.getElementsByClassName('skin-select'); - for(var i = 0; i < skinSelectNodes.length; i++) { - skinSelectNodes[i].onclick = this._loadSkin.bind(this); - } + var skinSelectNodes = document.getElementsByClassName('skin-select'); + for (var i = 0; i < skinSelectNodes.length; i++) { + skinSelectNodes[i].onclick = this._loadSkin.bind(this); + } - document.getElementById('context-play-file').onclick = function() { - self.winamp.openFileDialog(); - }; - document.getElementById('context-load-skin').onclick = function() { - self.winamp.openFileDialog(); - }; - document.getElementById('context-exit').onclick = function() { - self.winamp.close(); - }; + document.getElementById('context-play-file').onclick = function() { + self.winamp.openFileDialog(); + }; + document.getElementById('context-load-skin').onclick = function() { + self.winamp.openFileDialog(); + }; + document.getElementById('context-exit').onclick = function() { + self.winamp.close(); + }; }, _loadSkin: function(event) { - var skinFile = new MyFile(); - skinFile.setUrl(event.target.dataset.skinUrl); - this.winamp.setSkin(skinFile); + var skinFile = new MyFile(); + skinFile.setUrl(event.target.dataset.skinUrl); + this.winamp.setSkin(skinFile); } -}; + }; }); diff --git a/js/embed.js b/js/embed.js index eda23fff..786d5af1 100644 --- a/js/embed.js +++ b/js/embed.js @@ -2,52 +2,52 @@ var scriptTag = document.currentScript; require([ - 'browser', - '../rjs/text!../html/main-window.html', - '../rjs/css!../css/cleanslate.css', - '../rjs/css!../css/winamp.css', - 'winamp', - 'context', - 'hotkeys' + 'browser', + '../rjs/text!../html/main-window.html', + '../rjs/css!../css/cleanslate.css', + '../rjs/css!../css/winamp.css', + 'winamp', + 'context', + 'hotkeys' ], function( - Browser, - mainWindowHtml, - cleanslateCss, - winampCss, - Winamp, - Context, - Hotkeys + Browser, + mainWindowHtml, + cleanslateCss, + winampCss, + Winamp, + Context, + Hotkeys ) { - var node = document.createElement('div'); + var node = document.createElement('div'); - scriptTag.parentNode.insertBefore(node, scriptTag); - var options = scriptTag.dataset; + scriptTag.parentNode.insertBefore(node, scriptTag); + var options = scriptTag.dataset; - var media = options.media ? options.media : 'https://cdn.rawgit.com/captbaritone/llama/master/llama-2.91.mp3'; - var skin = options.skin ? options.skin : 'https://cdn.rawgit.com/captbaritone/winamp-skins/master/v2/base-2.91.wsz'; - var hotKeys = typeof options.hotkeys !== "undefined" ? true : false; + var media = options.media ? options.media : 'https://cdn.rawgit.com/captbaritone/llama/master/llama-2.91.mp3'; + var skin = options.skin ? options.skin : 'https://cdn.rawgit.com/captbaritone/winamp-skins/master/v2/base-2.91.wsz'; + var hotKeys = typeof options.hotkeys !== 'undefined'; - if(Browser.isCompatible()) { - node.innerHTML = mainWindowHtml; - node.setAttribute("id", "winamp2-js"); + if (Browser.isCompatible()) { + node.innerHTML = mainWindowHtml; + node.setAttribute('id', 'winamp2-js'); - var winamp = Winamp.init({ - 'volume': 50, - 'balance': 0, - 'mediaFile': { - 'url': media - }, - 'skinUrl': skin - }); + var winamp = Winamp.init({ + volume: 50, + balance: 0, + mediaFile: { + url: media + }, + skinUrl: skin + }); - if(hotKeys) { - Hotkeys.init(winamp); - } - Context.init(winamp); - } else { - var audio = document.createElement('audio'); - audio.src = media; - audio.setAttribute('controls', true); - node.appendChild(audio); + if (hotKeys) { + Hotkeys.init(winamp); } + Context.init(winamp); + } else { + var audio = document.createElement('audio'); + audio.src = media; + audio.setAttribute('controls', true); + node.appendChild(audio); + } }); diff --git a/js/font.js b/js/font.js index 6de68910..e9744df0 100644 --- a/js/font.js +++ b/js/font.js @@ -1,78 +1,78 @@ // Manage rendering text from this skin's text.bmp file define({ - // Fill a node with a
containing character
s - setNodeToString: function(node, string) { - stringElement = this._stringNode(string); - node.innerHTML = ''; - node.appendChild(stringElement); - }, + // Fill a node with a
containing character
s + setNodeToString: function(node, string) { + var stringElement = this._stringNode(string); + node.innerHTML = ''; + node.appendChild(stringElement); + }, - // Get a
containing char - characterNode: function(char) { - return this.displayCharacterInNode(char, document.createElement('div')); - }, + // Get a
containing char + characterNode: function(char) { + return this.displayCharacterInNode(char, document.createElement('div')); + }, - // Style/populate a
to display a character - displayCharacterInNode: function(character, node) { - position = this._getCharPosition(character); - row = position[0]; - column = position[1]; - verticalOffset = row * 6; - horizontalOffset = column * 5; + // Style/populate a
to display a character + displayCharacterInNode: function(character, node) { + var position = this._getCharPosition(character); + var row = position[0]; + var column = position[1]; + var verticalOffset = row * 6; + var horizontalOffset = column * 5; - x = '-' + horizontalOffset + 'px'; - y = '-' + verticalOffset + 'px'; - node.style.backgroundPosition = x + ' ' + y; - node.classList.add('character'); + var x = '-' + horizontalOffset + 'px'; + var y = '-' + verticalOffset + 'px'; + node.style.backgroundPosition = x + ' ' + y; + node.classList.add('character'); - node.innerHTML = character; - return node; - }, + node.innerHTML = character; + return node; + }, - // Get a
containing a digit - digitNode: function(digit) { - var div = document.createElement('div'); - div.classList.add('digit'); - div.classList.add('digit-' + digit); - return div; - }, + // Get a
containing a digit + digitNode: function(digit) { + var div = document.createElement('div'); + div.classList.add('digit'); + div.classList.add('digit-' + digit); + return div; + }, - // Get a
containing character
s - _stringNode: function(string) { - parentDiv = document.createElement('div'); - for (var i = 0, len = string.length; i < len; i++) { - char = string[i].toLowerCase(); - parentDiv.appendChild(this.characterNode(char)); - } - return parentDiv; - }, - - // Find the background offsets for a given character - _getCharPosition: function(char) { - position = this._fontLookup[char]; - if(!position) { - return this._fontLookup[' ']; - } - return position; - }, - - /* TODO: There are too many " " and "_" characters */ - _fontLookup: { - "a": [0,0], "b": [0,1], "c": [0,2], "d": [0,3], "e": [0,4], "f": [0,5], - "g": [0,6], "h": [0,7], "i": [0,8], "j": [0,9], "k": [0,10], - "l": [0,11], "m": [0,12], "n": [0,13], "o": [0,14], "p": [0,15], - "q": [0,16], "r": [0,17], "s": [0,18], "t": [0,19], "u": [0,20], - "v": [0,21], "w": [0,22], "x": [0,23], "y": [0,24], "z": [0,25], - "\"": [0,26], "@": [0,27], " ": [0,29], "0": [1,0], "1": [1,1], - "2": [1,2], "3": [1,3], "4": [1,4], "5": [1,5], "6": [1,6], "7": [1,7], - "8": [1,8], "9": [1,9], " ": [1,10], "_": [1,11], ":": [1,12], - "(": [1,13], ")": [1,14], "-": [1,15], "'": [1,16], "!": [1,17], - "_": [1,18], "+": [1,19], "\\": [1,20], "/": [1,21], "[": [1,22], - "]": [1,23], "^": [1,24], "&": [1,25], "%": [1,26], ".": [1,27], - "=": [1,28], "$": [1,29], "#": [1,30], "Å": [2,0], "Ö": [2,1], - "Ä": [2,2], "?": [2,3], "*": [2,4], " ": [2,5], "<": [1,22], - ">": [1,23], "{": [1,22], "}": [1,23] + // Get a
containing character
s + _stringNode: function(string) { + var parentDiv = document.createElement('div'); + for (var i = 0, len = string.length; i < len; i++) { + var char = string[i].toLowerCase(); + parentDiv.appendChild(this.characterNode(char)); } + return parentDiv; + }, + + // Find the background offsets for a given character + _getCharPosition: function(char) { + var position = this._fontLookup[char]; + if (!position) { + return this._fontLookup[' ']; + } + return position; + }, + + /* TODO: There are too many " " and "_" characters */ + _fontLookup: { + 'a': [0, 0], 'b': [0, 1], 'c': [0, 2], 'd': [0, 3], 'e': [0, 4], 'f': [0, 5], + 'g': [0, 6], 'h': [0, 7], 'i': [0, 8], 'j': [0, 9], 'k': [0, 10], + 'l': [0, 11], 'm': [0, 12], 'n': [0, 13], 'o': [0, 14], 'p': [0, 15], + 'q': [0, 16], 'r': [0, 17], 's': [0, 18], 't': [0, 19], 'u': [0, 20], + 'v': [0, 21], 'w': [0, 22], 'x': [0, 23], 'y': [0, 24], 'z': [0, 25], + '"': [0, 26], '@': [0, 27], '0': [1, 0], '1': [1, 1], + '2': [1, 2], '3': [1, 3], '4': [1, 4], '5': [1, 5], '6': [1, 6], '7': [1, 7], + '8': [1, 8], '9': [1, 9], '_': [1, 11], ':': [1, 12], + '(': [1, 13], ')': [1, 14], '-': [1, 15], "'": [1, 16], '!': [1, 17], + '+': [1, 19], '\\': [1, 20], '/': [1, 21], '[': [1, 22], + ']': [1, 23], '^': [1, 24], '&': [1, 25], '%': [1, 26], '.': [1, 27], + '=': [1, 28], '$': [1, 29], '#': [1, 30], 'Å': [2, 0], 'Ö': [2, 1], + 'Ä': [2, 2], '?': [2, 3], '*': [2, 4], ' ': [2, 5], '<': [1, 22], + '>': [1, 23], '{': [1, 22], '}': [1, 23] + } }); diff --git a/js/hotkeys.js b/js/hotkeys.js index 8668a5e1..41d4b675 100644 --- a/js/hotkeys.js +++ b/js/hotkeys.js @@ -1,48 +1,48 @@ define({ - init: function(winamp) { - keylog = []; - trigger = [78,85,76,27,76,27,83,79,70,84]; - document.onkeyup = function(e){ - if(e.ctrlKey) { // Is CTRL depressed? - switch(e.keyCode) { - case 68: winamp.toggleDoubledMode(); break; // CTRL+D - // XXX FIXME - case 76: winamp.openOptionMenu(); break; // CTRL+L - case 84: winamp.toggleTimeMode(); break; // CTRL+T - } - } else { - switch(e.keyCode) { - case 37: winamp.seekForwardBy(-5); break; // left arrow - case 38: winamp.incrementVolumeBy(1); break; // up arrow - case 39: winamp.seekForwardBy(5); break; // right arrow - case 40: winamp.incrementVolumeBy(-1); break; // down arrow - case 66: winamp.next(); break; // B - case 67: winamp.pause(); break; // C - case 76: winamp.openFileDialog(); break; // L - case 82: winamp.toggleRepeat(); break; // R - case 83: winamp.toggleShuffle(); break; // S - case 86: winamp.stop(); break; // V - case 88: winamp.play(); break; // X - case 90: winamp.previous(); break; // Z - case 96: winamp.openFileDialog(); break; // numpad 0 - case 97: winamp.previous(10); break; // numpad 1 - case 98: winamp.incrementVolumeBy(-1); break; // numpad 2 - case 99: winamp.next(10); break; // numpad 3 - case 100: winamp.previous(); break; // numpad 4 - case 101: winamp.play(); break; // numpad 5 - case 102: winamp.next(); break; // numpad 6 - case 103: winamp.seekForwardBy(-5); break; // numpad 7 - case 104: winamp.incrementVolumeBy(1); break; // numpad 8 - case 105: winamp.seekForwardBy(5); break; // numpad 9 - } - } + init: function(winamp) { + var keylog = []; + var trigger = [78, 85, 76, 27, 76, 27, 83, 79, 70, 84]; + document.onkeyup = function(e){ + if (e.ctrlKey) { // Is CTRL depressed? + switch (e.keyCode) { + case 68: winamp.toggleDoubledMode(); break; // CTRL+D + // XXX FIXME + case 76: winamp.openOptionMenu(); break; // CTRL+L + case 84: winamp.toggleTimeMode(); break; // CTRL+T + } + } else { + switch (e.keyCode) { + case 37: winamp.seekForwardBy(-5); break; // left arrow + case 38: winamp.incrementVolumeBy(1); break; // up arrow + case 39: winamp.seekForwardBy(5); break; // right arrow + case 40: winamp.incrementVolumeBy(-1); break; // down arrow + case 66: winamp.next(); break; // B + case 67: winamp.pause(); break; // C + case 76: winamp.openFileDialog(); break; // L + case 82: winamp.toggleRepeat(); break; // R + case 83: winamp.toggleShuffle(); break; // S + case 86: winamp.stop(); break; // V + case 88: winamp.play(); break; // X + case 90: winamp.previous(); break; // Z + case 96: winamp.openFileDialog(); break; // numpad 0 + case 97: winamp.previous(10); break; // numpad 1 + case 98: winamp.incrementVolumeBy(-1); break; // numpad 2 + case 99: winamp.next(10); break; // numpad 3 + case 100: winamp.previous(); break; // numpad 4 + case 101: winamp.play(); break; // numpad 5 + case 102: winamp.next(); break; // numpad 6 + case 103: winamp.seekForwardBy(-5); break; // numpad 7 + case 104: winamp.incrementVolumeBy(1); break; // numpad 8 + case 105: winamp.seekForwardBy(5); break; // numpad 9 + } + } - // Easter Egg - keylog.push(e.keyCode); - keylog = keylog.slice(-10); - if(keylog.toString() == trigger.toString()) { - winamp.toggleLlama(); - } - }; - } + // Easter Egg + keylog.push(e.keyCode); + keylog = keylog.slice(-10); + if (keylog.toString() === trigger.toString()) { + winamp.toggleLlama(); + } + }; + } }); diff --git a/js/main-window.js b/js/main-window.js index 38f294ff..a4a5675d 100644 --- a/js/main-window.js +++ b/js/main-window.js @@ -1,398 +1,428 @@ define([ - 'multi-display', - 'font' + 'multi-display', + 'font' ], function( - MultiDisplay, - Font + MultiDisplay, + Font ) { -return { + return { init: function(winamp) { - this.winamp = winamp; - this.nodes = { - 'close': document.getElementById('close'), - 'shade': document.getElementById('shade'), - 'buttonD': document.getElementById('button-d'), - 'position': document.getElementById('position'), - 'volumeMessage': document.getElementById('volume-message'), - 'balanceMessage': document.getElementById('balance-message'), - 'positionMessage': document.getElementById('position-message'), - 'songTitle': document.getElementById('song-title'), - 'time': document.getElementById('time'), - 'shadeTime': document.getElementById('shade-time'), - 'shadeMinusSign': document.getElementById('shade-minus-sign'), - 'visualizer': document.getElementById('visualizer'), - 'previous': document.getElementById('previous'), - 'play': document.getElementById('play'), - 'pause': document.getElementById('pause'), - 'stop': document.getElementById('stop'), - 'next': document.getElementById('next'), - 'eject': document.getElementById('eject'), - 'repeat': document.getElementById('repeat'), - 'shuffle': document.getElementById('shuffle'), - 'volume': document.getElementById('volume'), - 'kbps': document.getElementById('kbps'), - 'khz': document.getElementById('khz'), - 'mono': document.getElementById('mono'), - 'stereo': document.getElementById('stereo'), - 'balance': document.getElementById('balance'), - 'workIndicator': document.getElementById('work-indicator'), - 'titleBar': document.getElementById('title-bar'), - 'window': document.getElementById('main-window'), - }; + this.winamp = winamp; + this.nodes = { + close: document.getElementById('close'), + shade: document.getElementById('shade'), + buttonD: document.getElementById('button-d'), + position: document.getElementById('position'), + volumeMessage: document.getElementById('volume-message'), + balanceMessage: document.getElementById('balance-message'), + positionMessage: document.getElementById('position-message'), + songTitle: document.getElementById('song-title'), + time: document.getElementById('time'), + shadeTime: document.getElementById('shade-time'), + shadeMinusSign: document.getElementById('shade-minus-sign'), + visualizer: document.getElementById('visualizer'), + previous: document.getElementById('previous'), + play: document.getElementById('play'), + pause: document.getElementById('pause'), + stop: document.getElementById('stop'), + next: document.getElementById('next'), + eject: document.getElementById('eject'), + repeat: document.getElementById('repeat'), + shuffle: document.getElementById('shuffle'), + volume: document.getElementById('volume'), + kbps: document.getElementById('kbps'), + khz: document.getElementById('khz'), + mono: document.getElementById('mono'), + stereo: document.getElementById('stereo'), + balance: document.getElementById('balance'), + workIndicator: document.getElementById('work-indicator'), + titleBar: document.getElementById('title-bar'), + window: document.getElementById('main-window') + }; - this.handle = document.getElementById('title-bar'); - this.body = this.nodes.window; + this.handle = document.getElementById('title-bar'); + this.body = this.nodes.window; - this.textDisplay = MultiDisplay.init(Font, this.nodes.songTitle); - this.textDisplay.addRegister('songTitle'); - this.textDisplay.addRegister('position'); - this.textDisplay.addRegister('volume'); - this.textDisplay.addRegister('balance'); - this.textDisplay.addRegister('message'); // General purpose + this.textDisplay = MultiDisplay.init(Font, this.nodes.songTitle); + this.textDisplay.addRegister('songTitle'); + this.textDisplay.addRegister('position'); + this.textDisplay.addRegister('volume'); + this.textDisplay.addRegister('balance'); + this.textDisplay.addRegister('message'); // General purpose - this.textDisplay.showRegister('songTitle'); + this.textDisplay.showRegister('songTitle'); - this.textDisplay.startRegisterMarquee('songTitle'); + this.textDisplay.startRegisterMarquee('songTitle'); - this._registerListeners(); - return this; + this._registerListeners(); + return this; }, _registerListeners: function() { - var self = this; + var self = this; - this.nodes.close.onclick = function() { - self.winamp.close(); - }; + this.nodes.close.onclick = function() { + self.winamp.close(); + }; - this.nodes.shade.onclick = function() { - self.nodes.window.classList.toggle('shade'); - }; + this.nodes.shade.onclick = function() { + self.nodes.window.classList.toggle('shade'); + }; - this.nodes.buttonD.onmousedown = function() { - if(self.nodes.window.classList.contains('doubled')) { - self.textDisplay.setRegisterText('message', 'Disable doublesize mode'); - } else { - self.textDisplay.setRegisterText('message', 'Enable doublesize mode'); - } - self.textDisplay.showRegister('message'); - }; + this.nodes.buttonD.onmousedown = function() { + if (self.nodes.window.classList.contains('doubled')) { + self.textDisplay.setRegisterText('message', 'Disable doublesize mode'); + } else { + self.textDisplay.setRegisterText('message', 'Enable doublesize mode'); + } + self.textDisplay.showRegister('message'); + }; - this.nodes.buttonD.onmouseup = function() { - self.textDisplay.showRegister('songTitle'); - }; + this.nodes.buttonD.onmouseup = function() { + self.textDisplay.showRegister('songTitle'); + }; - this.nodes.buttonD.onclick = function() { - self.winamp.toggleDoubledMode(); - }; + this.nodes.buttonD.onclick = function() { + self.winamp.toggleDoubledMode(); + }; - this.nodes.play.onclick = function() { - self.winamp.play(); - }; + this.nodes.play.onclick = function() { + self.winamp.play(); + }; - this.nodes.songTitle.onmousedown = function() { - self.textDisplay.pauseRegisterMarquee('songTitle'); - }; + this.nodes.songTitle.onmousedown = function() { + self.textDisplay.pauseRegisterMarquee('songTitle'); + }; - this.nodes.songTitle.onmouseup = function() { - setTimeout(function () { - self.textDisplay.startRegisterMarquee('songTitle'); - }, 1000); - }; + this.nodes.songTitle.onmouseup = function() { + setTimeout(function() { + self.textDisplay.startRegisterMarquee('songTitle'); + }, 1000); + }; - this.nodes.position.onmousedown = function() { - if(!self.nodes.window.classList.contains('stop')){ - self.textDisplay.showRegister('position'); - self.nodes.window.classList.add('setting-position'); - } - }; + this.nodes.position.onmousedown = function() { + if (!self.nodes.window.classList.contains('stop')){ + self.textDisplay.showRegister('position'); + self.nodes.window.classList.add('setting-position'); + } + }; - this.nodes.position.onmouseup = function() { - self.textDisplay.showRegister('songTitle'); - self.nodes.window.classList.remove('setting-position'); - }; + this.nodes.position.onmouseup = function() { + self.textDisplay.showRegister('songTitle'); + self.nodes.window.classList.remove('setting-position'); + }; - this.nodes.position.oninput = function() { - var newPercentComplete = self.nodes.position.value; - var newFractionComplete = newPercentComplete/100; - var newElapsed = self._timeString(self.winamp.getDuration() * newFractionComplete); - var duration = self._timeString(self.winamp.getDuration()); - var message = "Seek to: " + newElapsed + "/" + duration + " (" + newPercentComplete + "%)"; - self.textDisplay.setRegisterText('position', message); - }; + this.nodes.position.oninput = function() { + var newPercentComplete = self.nodes.position.value; + var newFractionComplete = newPercentComplete / 100; + var newElapsed = self._timeString(self.winamp.getDuration() * newFractionComplete); + var duration = self._timeString(self.winamp.getDuration()); + var message = 'Seek to: ' + newElapsed + '/' + duration + ' (' + newPercentComplete + '%)'; + self.textDisplay.setRegisterText('position', message); + }; - this.nodes.position.onchange = function() { - if(self.winamp.getState() != 'stop'){ - self.winamp.seekToPercentComplete(this.value); - } - }; + this.nodes.position.onchange = function() { + if (self.winamp.getState() !== 'stop'){ + self.winamp.seekToPercentComplete(this.value); + } + }; - this.nodes.previous.onclick = function() { - self.winamp.previous(); - }; + this.nodes.previous.onclick = function() { + self.winamp.previous(); + }; - this.nodes.next.onclick = function() { - self.winamp.next(); - }; + this.nodes.next.onclick = function() { + self.winamp.next(); + }; - this.nodes.pause.onclick = function() { - self.winamp.pause(); - }; + this.nodes.pause.onclick = function() { + self.winamp.pause(); + }; - this.nodes.stop.onclick = function() { - self.winamp.stop(); - }; + this.nodes.stop.onclick = function() { + self.winamp.stop(); + }; - this.nodes.eject.onclick = function() { - self.winamp.openFileDialog(); - }; + this.nodes.eject.onclick = function() { + self.winamp.openFileDialog(); + }; - this.nodes.repeat.onclick = function() { - self.winamp.toggleRepeat(); - }; + this.nodes.repeat.onclick = function() { + self.winamp.toggleRepeat(); + }; - this.nodes.shuffle.onclick = function() { - self.winamp.toggleShuffle(); - }; + this.nodes.shuffle.onclick = function() { + self.winamp.toggleShuffle(); + }; - this.nodes.shadeTime.onclick = function() { - self.winamp.toggleTimeMode(); - }; + this.nodes.shadeTime.onclick = function() { + self.winamp.toggleTimeMode(); + }; - this.nodes.volume.onmousedown = function() { - self.textDisplay.showRegister('volume'); - }; + this.nodes.volume.onmousedown = function() { + self.textDisplay.showRegister('volume'); + }; - this.nodes.volume.onmouseup = function() { - self.textDisplay.showRegister('songTitle'); - }; + this.nodes.volume.onmouseup = function() { + self.textDisplay.showRegister('songTitle'); + }; - this.nodes.volume.oninput = function() { - self.winamp.setVolume(this.value); - }; + this.nodes.volume.oninput = function() { + self.winamp.setVolume(this.value); + }; - this.nodes.time.onclick = function() { - self.winamp.toggleTimeMode(); - }; + this.nodes.time.onclick = function() { + self.winamp.toggleTimeMode(); + }; - this.nodes.balance.onmousedown = function() { - self.textDisplay.showRegister('balance'); - }; + this.nodes.balance.onmousedown = function() { + self.textDisplay.showRegister('balance'); + }; - this.nodes.balance.onmouseup = function() { - self.textDisplay.showRegister('songTitle'); - }; + this.nodes.balance.onmouseup = function() { + self.textDisplay.showRegister('songTitle'); + }; - this.nodes.balance.oninput = function() { - if(Math.abs(this.value) < 25) { - this.value = 0; - } - self.winamp.setBalance(this.value); - }; + this.nodes.balance.oninput = function() { + if (Math.abs(this.value) < 25) { + this.value = 0; + } + self.winamp.setBalance(this.value); + }; - this.nodes.visualizer.onclick = function() { - self.winamp.toggleVisualizer(); - }; + this.nodes.visualizer.onclick = function() { + self.winamp.toggleVisualizer(); + }; - window.addEventListener('timeUpdated', function() { self.updateTime(); }); - window.addEventListener('startWaiting', function() { self.setWorkingIndicator(); }); - window.addEventListener('stopWaiting', function() { self.unsetWorkingIndicator(); }); - window.addEventListener('startLoading', function() { self.setLoadingState(); }); - window.addEventListener('stopLoading', function() { self.unsetLoadingState(); }); - window.addEventListener('toggleTimeMode', function() { self.toggleTimeMode(); }); - window.addEventListener('changeState', function() { self.changeState(); }); - window.addEventListener('titleUpdated', function() { self.updateTitle(); }); - window.addEventListener('channelCountUpdated', function() { self.updateChannelCount(); }); - window.addEventListener('volumeChanged', function() { self.updateVolume(); }); - window.addEventListener('balanceChanged', function() { self.setBalance(); }); - window.addEventListener('doubledModeToggled', function() { self.toggleDoubledMode(); }); - window.addEventListener('repeatToggled', function() { self.toggleRepeat(); }); - window.addEventListener('llamaToggled', function() { self.toggleLlama(); }); - window.addEventListener('close', function() { self.close(); }); + window.addEventListener('timeUpdated', function() { + self.updateTime(); + }); + window.addEventListener('startWaiting', function() { + self.setWorkingIndicator(); + }); + window.addEventListener('stopWaiting', function() { + self.unsetWorkingIndicator(); + }); + window.addEventListener('startLoading', function() { + self.setLoadingState(); + }); + window.addEventListener('stopLoading', function() { + self.unsetLoadingState(); + }); + window.addEventListener('toggleTimeMode', function() { + self.toggleTimeMode(); + }); + window.addEventListener('changeState', function() { + self.changeState(); + }); + window.addEventListener('titleUpdated', function() { + self.updateTitle(); + }); + window.addEventListener('channelCountUpdated', function() { + self.updateChannelCount(); + }); + window.addEventListener('volumeChanged', function() { + self.updateVolume(); + }); + window.addEventListener('balanceChanged', function() { + self.setBalance(); + }); + window.addEventListener('doubledModeToggled', function() { + self.toggleDoubledMode(); + }); + window.addEventListener('repeatToggled', function() { + self.toggleRepeat(); + }); + window.addEventListener('llamaToggled', function() { + self.toggleLlama(); + }); + window.addEventListener('close', function() { + self.close(); + }); - this.nodes.window.addEventListener('dragenter', this.dragenter.bind(this)); - this.nodes.window.addEventListener('dragover', this.dragover.bind(this)); - this.nodes.window.addEventListener('drop', this.drop.bind(this)); + this.nodes.window.addEventListener('dragenter', this.dragenter.bind(this)); + this.nodes.window.addEventListener('dragover', this.dragover.bind(this)); + this.nodes.window.addEventListener('drop', this.drop.bind(this)); }, toggleDoubledMode: function() { - this.nodes.buttonD.classList.toggle('selected'); - this.nodes.window.classList.toggle('doubled'); + this.nodes.buttonD.classList.toggle('selected'); + this.nodes.window.classList.toggle('doubled'); }, close: function() { - this.nodes.window.classList.add('closed'); + this.nodes.window.classList.add('closed'); }, updatePosition: function() { - if(!this.nodes.window.classList.contains('setting-position')) { - this.nodes.position.value = this.winamp.getPercentComplete(); - } + if (!this.nodes.window.classList.contains('setting-position')) { + this.nodes.position.value = this.winamp.getPercentComplete(); + } }, // In shade mode, the position slider shows up differently depending on if // it's near the start, middle or end of its progress updateShadePositionClass: function() { - var position = this.nodes.position; + var position = this.nodes.position; - position.removeAttribute("class"); - if(position.value <= 33) { - position.classList.add('left'); - } else if(position.value >= 66) { - position.classList.add('right'); - } + position.removeAttribute('class'); + if (position.value <= 33) { + position.classList.add('left'); + } else if (position.value >= 66) { + position.classList.add('right'); + } }, updateTime: function() { - this.updateShadePositionClass(); - this.updatePosition(); + this.updateShadePositionClass(); + this.updatePosition(); - var shadeMinusCharacter = ' '; - var digits = null; - if(this.nodes.time.classList.contains('countdown')) { - digits = this.winamp._timeObject(this.winamp.getTimeRemaining()); - shadeMinusCharacter = '-'; - } else { - digits = this.winamp._timeObject(this.winamp.getTimeElapsed()); - } - this.winamp.skin.font.displayCharacterInNode(shadeMinusCharacter, this.nodes.shadeMinusSign); + var shadeMinusCharacter = ' '; + var digits = null; + if (this.nodes.time.classList.contains('countdown')) { + digits = this.winamp._timeObject(this.winamp.getTimeRemaining()); + shadeMinusCharacter = '-'; + } else { + digits = this.winamp._timeObject(this.winamp.getTimeElapsed()); + } + this.winamp.skin.font.displayCharacterInNode(shadeMinusCharacter, this.nodes.shadeMinusSign); - var digitNodes = [ - document.getElementById('minute-first-digit'), - document.getElementById('minute-second-digit'), - document.getElementById('second-first-digit'), - document.getElementById('second-second-digit') - ]; - var shadeDigitNodes = [ - document.getElementById('shade-minute-first-digit'), - document.getElementById('shade-minute-second-digit'), - document.getElementById('shade-second-first-digit'), - document.getElementById('shade-second-second-digit') - ]; + var digitNodes = [ + document.getElementById('minute-first-digit'), + document.getElementById('minute-second-digit'), + document.getElementById('second-first-digit'), + document.getElementById('second-second-digit') + ]; + var shadeDigitNodes = [ + document.getElementById('shade-minute-first-digit'), + document.getElementById('shade-minute-second-digit'), + document.getElementById('shade-second-first-digit'), + document.getElementById('shade-second-second-digit') + ]; - // For each digit/node - for(var i = 0; i < 4; i++) { - var digit = digits[i]; - var digitNode = digitNodes[i]; - var shadeNode = shadeDigitNodes[i]; - digitNode.innerHTML = ''; - digitNode.appendChild(this.winamp.skin.font.digitNode(digit)); - this.winamp.skin.font.displayCharacterInNode(digit, shadeNode); - } + // For each digit/node + for (var i = 0; i < 4; i++) { + var digit = digits[i]; + var digitNode = digitNodes[i]; + var shadeNode = shadeDigitNodes[i]; + digitNode.innerHTML = ''; + digitNode.appendChild(this.winamp.skin.font.digitNode(digit)); + this.winamp.skin.font.displayCharacterInNode(digit, shadeNode); + } }, setWorkingIndicator: function() { - this.nodes.workIndicator.classList.add('selected'); + this.nodes.workIndicator.classList.add('selected'); }, unsetWorkingIndicator: function() { - this.nodes.workIndicator.classList.remove('selected'); + this.nodes.workIndicator.classList.remove('selected'); }, setLoadingState: function() { - this.nodes.window.classList.add('loading'); + this.nodes.window.classList.add('loading'); }, unsetLoadingState: function() { - this.nodes.window.classList.remove('loading'); + this.nodes.window.classList.remove('loading'); }, toggleTimeMode: function() { - this.nodes.time.classList.toggle('countdown'); - this.updateTime(); + this.nodes.time.classList.toggle('countdown'); + this.updateTime(); }, updateVolume: function() { - var volume = this.winamp.getVolume(); - var percent = volume / 100; - var sprite = Math.round(percent * 28); - var offset = (sprite - 1) * 15; - this.nodes.volume.style.backgroundPosition = '0 -' + offset + 'px'; + var volume = this.winamp.getVolume(); + var percent = volume / 100; + var sprite = Math.round(percent * 28); + var offset = (sprite - 1) * 15; + this.nodes.volume.style.backgroundPosition = '0 -' + offset + 'px'; - var message = 'Volume: ' + volume + '%'; - this.textDisplay.setRegisterText('volume', message); + var message = 'Volume: ' + volume + '%'; + this.textDisplay.setRegisterText('volume', message); - // This shouldn't trigger an infinite loop with volume.onchange(), - // since the value will be the same - this.nodes.volume.value = volume; + // This shouldn't trigger an infinite loop with volume.onchange(), + // since the value will be the same + this.nodes.volume.value = volume; }, setBalance: function() { - var balance = this.winamp.getBalance(); - var string = ''; - if(balance === 0) { - string = 'Balance: Center'; - } else if(balance > 0) { - string = 'Balance: ' + balance + '% Right'; - } else { - string = 'Balance: ' + Math.abs(balance) + '% Left'; - } - this.textDisplay.setRegisterText('balance', string); - balance = Math.abs(balance) / 100; - var sprite = Math.round(balance * 28); - var offset = (sprite - 1) * 15; - this.nodes.balance.style.backgroundPosition = '0px -' + offset + 'px'; + var balance = this.winamp.getBalance(); + var string = ''; + if (balance === 0) { + string = 'Balance: Center'; + } else if (balance > 0) { + string = 'Balance: ' + balance + '% Right'; + } else { + string = 'Balance: ' + Math.abs(balance) + '% Left'; + } + this.textDisplay.setRegisterText('balance', string); + balance = Math.abs(balance) / 100; + var sprite = Math.round(balance * 28); + var offset = (sprite - 1) * 15; + this.nodes.balance.style.backgroundPosition = '0px -' + offset + 'px'; }, changeState: function() { - var state = this.winamp.getState(); - var stateOptions = ['play', 'stop', 'pause']; - for(var i = 0; i < stateOptions.length; i++) { - this.nodes.window.classList.remove(stateOptions[i]); - } - this.nodes.window.classList.add(state); + var state = this.winamp.getState(); + var stateOptions = ['play', 'stop', 'pause']; + for (var i = 0; i < stateOptions.length; i++) { + this.nodes.window.classList.remove(stateOptions[i]); + } + this.nodes.window.classList.add(state); }, toggleLlama: function() { - this.nodes.window.classList.toggle('llama'); + this.nodes.window.classList.toggle('llama'); }, updateTitle: function() { - var duration = this._timeString(this.winamp.getDuration()); - var name = this.winamp.fileName + ' (' + duration + ') *** '; - this.textDisplay.setRegisterText('songTitle', name); + var duration = this._timeString(this.winamp.getDuration()); + var name = this.winamp.fileName + ' (' + duration + ') *** '; + this.textDisplay.setRegisterText('songTitle', name); }, updateChannelCount: function() { - var channels = this.winamp.getChannelCount(); - this.nodes.mono.classList.remove('selected'); - this.nodes.stereo.classList.remove('selected'); - if(channels == 1) { - this.nodes.mono.classList.add('selected'); - } else if(channels == 2) { - this.nodes.stereo.classList.add('selected'); - } + var channels = this.winamp.getChannelCount(); + this.nodes.mono.classList.remove('selected'); + this.nodes.stereo.classList.remove('selected'); + if (channels === 1) { + this.nodes.mono.classList.add('selected'); + } else if (channels === 2) { + this.nodes.stereo.classList.add('selected'); + } }, toggleRepeat: function() { - this.nodes.repeat.classList.toggle('selected'); + this.nodes.repeat.classList.toggle('selected'); }, toggleShuffle: function() { - this.nodes.shuffle.classList.toggle('selected'); + this.nodes.shuffle.classList.toggle('selected'); }, dragenter: function(e) { - e.stopPropagation(); - e.preventDefault(); + e.stopPropagation(); + e.preventDefault(); }, dragover: function(e) { - e.stopPropagation(); - e.preventDefault(); + e.stopPropagation(); + e.preventDefault(); }, drop: function(e) { - e.stopPropagation(); - e.preventDefault(); - var dt = e.dataTransfer; - var file = dt.files[0]; - this.winamp.loadFromFileReference(file); + e.stopPropagation(); + e.preventDefault(); + var dt = e.dataTransfer; + var file = dt.files[0]; + this.winamp.loadFromFileReference(file); }, _timeString: function(time) { - var timeObject = this.winamp._timeObject(time); - return timeObject[0] + timeObject[1] + ':' + timeObject[2] + timeObject[3]; + var timeObject = this.winamp._timeObject(time); + return timeObject[0] + timeObject[1] + ':' + timeObject[2] + timeObject[3]; } -}; + }; }); diff --git a/js/main.js b/js/main.js index a8a95e23..9ebe0b5a 100644 --- a/js/main.js +++ b/js/main.js @@ -1,43 +1,42 @@ require([ - 'browser', - '../rjs/text!../html/main-window.html', - '../rjs/css!../css/winamp.css', - 'winamp', - 'context', - 'hotkeys' + 'browser', + '../rjs/text!../html/main-window.html', + '../rjs/css!../css/winamp.css', + 'winamp', + 'context', + 'hotkeys' ], function( - Browser, - mainWindowHtml, - pageCss, - Winamp, - Context, - Hotkeys + Browser, + mainWindowHtml, + pageCss, + Winamp, + Context, + Hotkeys ) { - document.getElementById('embed-link').onclick = function() { - document.getElementById('embed').classList.toggle('selected'); - document.getElementById('embed-input').select(); - return false; - }; - if(Browser.isCompatible()) { - var mainWindowElement = document.createElement('div'); - mainWindowElement.innerHTML = mainWindowHtml; - document.getElementById('winamp2-js').appendChild(mainWindowElement); + document.getElementById('embed-link').onclick = function() { + document.getElementById('embed').classList.toggle('selected'); + document.getElementById('embed-input').select(); + return false; + }; + if (Browser.isCompatible()) { + var mainWindowElement = document.createElement('div'); + mainWindowElement.innerHTML = mainWindowHtml; + document.getElementById('winamp2-js').appendChild(mainWindowElement); - var winamp = Winamp.init({ - 'volume': 50, - 'balance': 0, - 'mediaFile': { - 'url': "https://cdn.rawgit.com/captbaritone/llama/master/llama-2.91.mp3", - 'name': "1. DJ Mike Llama - Llama Whippin' Intro" - }, - 'skinUrl': - 'https://cdn.rawgit.com/captbaritone/winamp-skins/master/v2/base-2.91.wsz' - }); + var winamp = Winamp.init({ + volume: 50, + balance: 0, + mediaFile: { + url: 'https://cdn.rawgit.com/captbaritone/llama/master/llama-2.91.mp3', + name: "1. DJ Mike Llama - Llama Whippin' Intro" + }, + skinUrl: 'https://cdn.rawgit.com/captbaritone/winamp-skins/master/v2/base-2.91.wsz' + }); - Hotkeys.init(winamp); - Context.init(winamp); - } else { - document.getElementById('winamp').style.display = 'none'; - document.getElementById('browser-compatibility').style.display = 'block'; - } + Hotkeys.init(winamp); + Context.init(winamp); + } else { + document.getElementById('winamp').style.display = 'none'; + document.getElementById('browser-compatibility').style.display = 'block'; + } }); diff --git a/js/media.js b/js/media.js index 9da54db0..04ca0818 100644 --- a/js/media.js +++ b/js/media.js @@ -1,260 +1,256 @@ /* Emulate the native