Skip to content

Commit

Permalink
clean up, multi run functions moved
Browse files Browse the repository at this point in the history
  • Loading branch information
ChapelR committed Jul 17, 2019
1 parent 836db3d commit a5cb4bf
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 24 deletions.
2 changes: 1 addition & 1 deletion dist/harlowe-audio.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function processStyles (dir, out, name) {

// linting
function lint () {
return gulp.src('./src/js')
return gulp.src('./src/js/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default', { beep : true }));
}
Expand All @@ -44,6 +44,7 @@ function rimraf () {
// build functions
function buildScripts () {
var jsFiles = [
'vendor/detect.js',
'options.js',
'get.js',
'audio.js',
Expand All @@ -52,7 +53,6 @@ function buildScripts () {
'list.js',
'extensions.js',
'controlpanel.js',
'detect.js',
'preload.js',
'state.js',
'setup.js',
Expand Down
10 changes: 9 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"gulp-jshint": "^2.1.0",
"gulp-rename": "^1.4.0",
"gulp-replace": "^1.0.0",
"gulp-tap": "^1.0.1",
"gulp-uglify": "^3.0.2",
"jshint": "^2.10.2",
"node-zip": "^1.1.1"
Expand Down
1 change: 0 additions & 1 deletion src/js/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,4 @@
window.Chapel = window.Chapel || {};

window.Chapel.Audio = Audio;

}());
2 changes: 1 addition & 1 deletion src/js/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
var configsFromPassage = null;

if ($configPassage.length) {
var cfgLines = parseBlock($configPassage.text())
var cfgLines = parseBlock($configPassage.text());

var userOptions = {};

Expand Down
35 changes: 18 additions & 17 deletions src/js/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,47 +44,48 @@
return (this instanceof A.group);
},

runOnAll : function (group, method, args) {
group.members.forEach( function (track) {
track[method].apply(track, (args && Array.isArray(args)) ? args : []);
});
_runOnAll : function (group, method, args, test) {
if (test != null) {
args = [].slice.call(arguments).slice(2);
} else {
if (!(args instanceof Array)) {
args = [args];
}
}
var pass = [group.members, method, args];
Track._runOnMultiple.apply(null, pass);
}
});

// A.group('playing').pause(); or A.group('playing').mute(true);

Object.assign(A.group.prototype, {
constructor : A.group,
run : function (method, args, test) {
if (test != null) {
args = [].slice.call(arguments).slice(1);
}
if (Track.prototype.hasOwnProperty(method)) {
A.group.runOnAll(this, method, args);
}
_run : function () {
A.group._runOnAll.apply(null, [this].concat([].slice.call(arguments)));
},
play : function () {
this.run('play');
this._run('play');
return this;
},
pause : function () {
this.run('pause');
this._run('pause');
return this;
},
stop : function () {
this.run('stop');
this._run('stop');
return this;
},
mute : function (bool) {
this.run('mute', [bool]);
this._run('mute', bool);
return this;
},
volume : function (val) {
this.run('volume', [val]);
this._run('volume', val);
return this;
},
loop : function (bool) {
this.run('loop', [bool]);
this._run('loop', bool);
return this;
}
});
Expand Down
26 changes: 26 additions & 0 deletions src/js/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
}
Playlist.list[id] = new Playlist(id, trackList);
return Playlist.list[id];
},

_runOnAll : function (list, method, args, test) {
if (test != null) {
args = [].slice.call(arguments).slice(2);
} else {
if (!(args instanceof Array)) {
args = [args];
}
}
var pass = [list.tracks, method, args];
Track._runOnMultiple.apply(null, pass);
}
});

Expand All @@ -39,6 +51,17 @@
clone : function () {
return new Playlist(this.id, this.tracks.map( function (tr) { return tr.id; }));
},
_run : function () { // undocumented; prefer groups
Playlist._runOnAll.apply(null, [this].concat([].slice.call(arguments)));
},
volume : function (level) {
this._run('volume', level);
return this;
},
mute : function (bool) {
this._run('mute', bool);
return this;
},
shuffle : function () {
var a = this.tracks;
var j, x, i;
Expand All @@ -57,6 +80,9 @@
isPlaying : function () {
return this.playing;
},
nowPlaying : function () {
return Track.get(this.current);
},
play : function (i) {
var self = this;
i = i || (function () {
Expand Down
1 change: 0 additions & 1 deletion src/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@
}
console.log.apply(null, arguments);
};

}());
17 changes: 17 additions & 0 deletions src/js/track.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,23 @@
} else {
$container.remove();
}
},
_runOnMultiple : function (list, method, args) {
if (!(list instanceof Array)) {
return;
}
if (!Track.prototype.hasOwnProperty(method)) {
return;
}
list.forEach( function (track) {
if (!Track.is(track)) {
track = Track.get(track) || null;
}
if (!track) {
return;
}
track[method].apply(track, (args && args instanceof Array) ? args : []);
});
}
});

Expand Down
File renamed without changes.

0 comments on commit a5cb4bf

Please sign in to comment.