+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/js/index.js b/js/index.js
new file mode 100644
index 0000000..5195057
--- /dev/null
+++ b/js/index.js
@@ -0,0 +1,347 @@
+// do this when you have multiple files!
+var RFMP = RFMP || {};
+
+RFMP.songs = [
+ {
+ title: "Requiem for a Fish",
+ artist: "The Freak Fandango Orchestra",
+ url: "music/The_Freak_Fandango_Orchestra_-_01_-_Requiem_for_a_Fish.mp3"
+ },
+ {
+ title: "Russian Beach (Heycaluca)",
+ artist: "Party People in a Can",
+ url: "music/Party_People_in_a_Can_-_05_-_Russian_Beach_Heycaluca.mp3"
+ },
+ {
+ title: "Pueblo Duerme",
+ artist: "La Barca de Sua",
+ url: "music/La_Barca_de_Sua_-_05_-_Pueblo_Duerme.mp3"
+ },
+ {
+ title: "Ragtime Dance",
+ artist: "Scott Joplin",
+ url: "music/Scott_Joplin_-_Ragtime_Dance.mp3"
+ },
+ {
+ title: "Ghost Dance",
+ artist: "Kevin MacLeod",
+ url: "music/Kevin_MacLeod_-_Ghost_Dance.mp3"
+ }
+];
+// do this when you have multiple files!
+var RFMP = RFMP || {};
+
+// the view is for talking to the HTML and the user
+RFMP.view = {
+
+ init: function(listeners) {
+ // adds song HTML to playlist
+ RFMP.view.addSongs();
+
+ // pass handler methods from our player
+ // to add to the DOM
+ RFMP.view.addListeners(listeners);
+
+ // update the info text for the currently
+ // playing track
+ RFMP.view.updateSongInfo();
+ },
+
+ // changes the controls center button to play or pause
+ updateControls: function() {
+ if (RFMP.currentState.playing) {
+ $('#ctrl-play').addClass('glyphicon-pause')
+ .removeClass('glyphicon-play');
+ } else {
+ $('#ctrl-play').removeClass('glyphicon-pause')
+ .addClass('glyphicon-play');
+ }
+ },
+
+ // Changes the text in the control panel
+ // to reflect the song name and artist
+ // of the current song
+ updateSongInfo: function() {
+ // get the info of the current song
+ var currentSong = RFMP.songs[RFMP.currentState.song];
+
+ $('#song-info .song-title').text(currentSong.title);
+ $('#song-info .song-artist').text(currentSong.artist);
+ },
+
+ // this takes in a `$song` jQuery
+ // element that references the play/pause
+ // button and returns the index ID
+ getId: function($song) {
+ // `+` is a quick way to convert a string
+ // to a number
+ return +$song.data('index');
+ },
+
+ // this takes in a `$song` jQuery
+ // element that references the play/pause
+ // button and returns the audio element associated
+ // with it
+ getAudio: function($song) {
+ return $song.next();
+ },
+
+ // this return finds the play/pause button
+ // of the song associated with the `id`
+ // we passed into the argument
+ getSongFromId: function(id) {
+ // the selector looks for a span element
+ // with a particular `data-index`.
+ // This data-index corresponds
+ // to our `songs` array.
+ // Make sure there's no space between
+ // span and []
+ return $('span[data-index=' + id + ']');
+ },
+
+ // calls the above method with the id
+ // of the current song
+ getCurrentSong: function() {
+ var id = RFMP.currentState.song;
+
+ return RFMP.view.getSongFromId(id);
+ },
+
+ // changes the song's button to a "play" icon
+ changeToPlay: function($song) {
+ $song.removeClass('glyphicon-pause')
+ .addClass('glyphicon-play');
+ },
+
+ // changes the song's button to a "pause" icon
+ changeToPause: function($song) {
+ $song.addClass('glyphicon-pause')
+ .removeClass('glyphicon-play');
+ },
+
+ // adds listeners to the elements we need
+ addListeners: function(listeners) {
+ // Note: we are simply passing our methods as
+ // handlers rather than writing anonymouse functions
+ var $playlist = $('#playlist'),
+ $ctrlPlay = $('#ctrl-play'),
+ $ctrlNext = $('#ctrl-next'),
+ $ctrlPrev = $('#ctrl-prev');
+
+ // this is event delegation. It adds a `click`
+ // listener to all the elements with a
+ // `play-pause` class inside our playlist,
+ // i.e. all our play/pause buttons.
+ $playlist.on("click", ".play-pause", listeners.playPause);
+
+ $ctrlPlay.on("click", listeners.playPause);
+ $ctrlNext.on("click", listeners.nextTrack);
+ $ctrlPrev.on("click", listeners.prevTrack);
+ },
+
+ // creates a song HTML element for each song
+ // in our `songs` array. Now it's easy to modify
+ // our song list without touching the HTML.
+ addSongs: function() {
+ RFMP.songs.forEach(function(song, index) {
+ // this creates the element
+ var $playlistItem = RFMP.view.createSongItem(song, index);
+
+ // and now we add it to the bottom of our playlist
+ $('#playlist').append($playlistItem);
+ });
+ },
+
+ // this dynamically creates a list item
+ // of all the necessary elements
+ // for a single song and returns it
+ createSongItem: function(song, index) {
+ var $li = $('
')
+ .addClass("col-xs-1")
+ .appendTo($li);
+
+ var $button = $('')
+ .addClass("glyphicon glyphicon-play play-pause")
+ .attr("aria-hidden", "true")
+ // this adds a `data` property that
+ // refers to the index in the
+ // `songs` array
+ .attr("data-index", index)
+ .appendTo($textCol);
+
+ var $audio = $('