forked from serversideup/amplitudejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
183 lines (145 loc) · 5.76 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
Amplitude.js
Version: 3.0
Author: Dan Pastori
Company: 521 Dimensions
*/
import AmplitudeInitializer from './init/init.js';
import AmplitudeCore from './core/core.js';
import AmplitudeHelpers from './core/helpers.js';
import AmplitudeEvents from './events/events.js';
import config from './config.js';
/*
Amplitude should just be an interface to the public functions.
Everything else should be handled by other objects
*/
var Amplitude = (function () {
/*--------------------------------------------------------------------------
The main init function. The user will call this through
Amplitude.init({}) and pass in their settings.
Public Accessor: Amplitude.init( user_config_json );
@param user_config A JSON object of user defined values that help
configure and initialize AmplitudeJS.
--------------------------------------------------------------------------*/
function init( userConfig ){
AmplitudeInitializer.initialize( userConfig );
}
/*--------------------------------------------------------------------------
Binds new elements that were added to the page.
--------------------------------------------------------------------------*/
function bindNewElements(){
AmplitudeInitializer.rebindDisplay();
}
/*--------------------------------------------------------------------------
Allows the user to turn on debugging.
Public Accessor: Amplitude.setDebug( bool );
@param BOOL state Turns debugging on and off.
--------------------------------------------------------------------------*/
function setDebug( state ){
/*
Sets the global config debug on or off.
*/
config.debug = state;
}
/*--------------------------------------------------------------------------
Returns the active song meta data for the user to do what is
needed.
Public Accessor: Amplitude.getActiveSongMetadata();
@returns JSON Object with the active song information
--------------------------------------------------------------------------*/
function getActiveSongMetadata(){
return config.active_metadata;
}
/*--------------------------------------------------------------------------
Returns a song in the songs array at that index
Public Accessor: Amplitude.getSongByIndex( song_index )
@param int index The integer for the index of the
song in the songs array.
@returns JSON representation for the song at a specific index.
--------------------------------------------------------------------------*/
function getSongByIndex( index ){
return config.songs[index];
}
/*--------------------------------------------------------------------------
Returns a song at a playlist index
Public Accessor: Amplitude.getSongAtPlaylistIndex( playlist, index
@param int index The integer for the index of the
song in the playlist.
@param string playlist The key of the playlist we are getting the song
at the index for
@returns JSON representation for the song at a specific index.
--------------------------------------------------------------------------*/
function getSongAtPlaylistIndex( playlist, index ){
var songIndex = config.playlists[playlist][index];
return config.songs[songIndex];
}
/*--------------------------------------------------------------------------
Adds a song to the end of the config array. This will allow Amplitude
to play the song in a playlist type setting.
Public Accessor: Amplitude.addSong( song_json )
@param song JSON representation of a song.
@returns int New index of the song.
--------------------------------------------------------------------------*/
function addSong( song ){
config.songs.push( song );
return config.songs.length - 1;
}
/*--------------------------------------------------------------------------
When you pass a song object it plays that song right awawy. It sets
the active song in the config to the song you pass in and synchronizes
the visuals.
Public Accessor: Amplitude.playNow( song )
@param song JSON representation of a song.
--------------------------------------------------------------------------*/
function playNow( song ){
AmplitudeCore.playNow( song );
}
/*
TODO: Implement Add Song To Playlist Functionality
*/
function addSongToPlaylist( song, playlist ){
}
/*--------------------------------------------------------------------------
Allows the user to play whatever the active song is directly
through Javascript. Normally ALL of Amplitude functions that access
the core features are called through event handlers.
Public Accessor: Amplitude.play();
--------------------------------------------------------------------------*/
function play(){
AmplitudeCore.play();
}
/*--------------------------------------------------------------------------
Allows the user to pause whatever the active song is directly
through Javascript. Normally ALL of Amplitude functions that access
the core features are called through event handlers.
Public Accessor: Amplitude.pause();
--------------------------------------------------------------------------*/
function pause(){
AmplitudeCore.pause();
}
/*--------------------------------------------------------------------------
Returns the audio object used to play the audio
Public Accessor: Amplitude.getAudio();
--------------------------------------------------------------------------*/
function getAudio(){
return config.active_song;
}
/*
Returns all of the publically accesible methods.
*/
return {
init: init,
bindNewElements: bindNewElements,
setDebug: setDebug,
getActiveSongMetadata: getActiveSongMetadata,
getSongByIndex: getSongByIndex,
getSongAtPlaylistIndex: getSongAtPlaylistIndex,
addSong: addSong,
playNow: playNow,
play: play,
pause: pause,
addSong: addSong,
audio: getAudio
}
})();
export default Amplitude;