usage of JavaScript 1.7 only keywords.
1 | /** |
||
2 | * Audio Player |
||
3 | * |
||
4 | * This file is licensed under the Affero General Public License version 3 or |
||
5 | * later. See the LICENSE.md file. |
||
6 | * |
||
7 | * @author Marcel Scherello <[email protected]> |
||
8 | * @author Sebastian Doell <[email protected]> |
||
9 | * @copyright 2016-2019 Marcel Scherello |
||
10 | * @copyright 2015 Sebastian Doell |
||
11 | */ |
||
12 | |||
13 | /* global SM2BarPlayer soundManager */ |
||
14 | // OK because ./js/soundmanager2.js is sourced before in html |
||
15 | |||
16 | 'use strict'; |
||
17 | |||
18 | var Audios = function () { |
||
19 | this.AudioPlayer = null; |
||
20 | this.PlaylistContainer = $('#playlist-container'); |
||
21 | this.EmptyContainer = $('#empty-container'); |
||
22 | this.ActivePlaylist = $('#activePlaylist'); |
||
23 | this.albums = []; |
||
24 | this.CategorySelectors = []; |
||
25 | this.AjaxCallStatus = null; |
||
26 | this.AlbumPlay = null; |
||
27 | this.initialDocumentTitle = null; |
||
28 | }; |
||
29 | |||
30 | Audios.prototype.init = function () { |
||
31 | this.initialDocumentTitle = $('title').html().trim(); |
||
32 | |||
33 | var locHash = decodeURI(location.hash).substr(1); |
||
34 | if (locHash !== '') { |
||
35 | var locHashTemp = locHash.split('-'); |
||
36 | |||
37 | $('#searchresults').addClass('hidden'); |
||
38 | window.location.href = '#'; |
||
39 | if (locHashTemp[0] !== 'volume' && locHashTemp[0] !== 'repeat' && locHashTemp[0] !== 'shuffle' && locHashTemp[0] !== 'prev' && locHashTemp[0] !== 'play' && locHashTemp[0] !== 'next') { |
||
40 | this.CategorySelectors = locHashTemp; |
||
41 | this.presetDisplay(); |
||
42 | } |
||
43 | } else { |
||
44 | // read saved values from user values |
||
45 | this.getUserValue('category', this.displayCategory.bind(this)); |
||
46 | } |
||
47 | |||
48 | this.initKeyListener(); |
||
49 | $('.toolTip').tooltip(); |
||
50 | |||
51 | // temporary solution until code gets more self-contained |
||
52 | soundManager.audiosInstance = this; |
||
53 | if (!OCA.Audioplayer) { |
||
54 | OCA.Audioplayer = {}; |
||
55 | } |
||
56 | OCA.Audioplayer.audiosInstance = this; |
||
57 | }; |
||
58 | |||
59 | Audios.prototype.displayCategory = function () { |
||
60 | if (this.CategorySelectors === 'false') { |
||
61 | this.showInitScreen(); |
||
62 | } else if (this.CategorySelectors[0] && this.CategorySelectors[0] !== 'Albums') { |
||
63 | this.presetDisplay(); |
||
64 | } else { |
||
65 | this.loadCategoryAlbums(); |
||
66 | } |
||
67 | }; |
||
68 | |||
69 | Audios.prototype.presetDisplay = function () { |
||
70 | $('#category_selector').val(this.CategorySelectors[0]); |
||
71 | this.loadCategory(this.loadLatestCategory.bind(this)); |
||
72 | }; |
||
73 | |||
74 | Audios.prototype.loadLatestCategory = function () { |
||
75 | if (this.CategorySelectors[1] && this.CategorySelectors[1] !== 'undefined') { |
||
76 | $('#myCategory li[data-id="' + this.CategorySelectors[1] + '"]').addClass('active'); |
||
77 | var appNavigation = $('#app-navigation'); |
||
78 | appNavigation.scrollTop(appNavigation.scrollTop() + $('#myCategory li.active').first().position().top - 25); |
||
79 | this.loadIndividualCategory(null, function () { // select the last played title |
||
80 | if (this.CategorySelectors[2] && this.CategorySelectors[2] !== 'undefined') { |
||
81 | var item = $('#individual-playlist li[data-trackid="' + this.CategorySelectors[2] + '"]'); |
||
82 | item.find('.icon').hide(); |
||
83 | item.find('.ioc').removeClass('ioc-volume-up').addClass('ioc-volume-off').show(); |
||
84 | } |
||
85 | }.bind(this)); |
||
86 | } |
||
87 | }; |
||
88 | |||
89 | Audios.prototype.initKeyListener = function () { |
||
90 | $(document).keyup(function (evt) { |
||
91 | if (this.AudioPlayer !== null && $('#activePlaylist li').length > 0) { |
||
92 | |||
93 | if (evt.target) { |
||
94 | var nodeName = evt.target.nodeName.toUpperCase(); |
||
95 | //don't activate shortcuts when the user is in an input, textarea or select element |
||
96 | if (nodeName === 'INPUT' || nodeName === 'TEXTAREA' || nodeName === 'SELECT') { |
||
97 | return; |
||
98 | } |
||
99 | } |
||
100 | |||
101 | var currentVolume; |
||
102 | var newVolume; |
||
103 | if (evt.key === ' ') {//Space pause/play |
||
104 | if ($('.sm2-bar-ui').hasClass('playing')) { |
||
105 | this.AudioPlayer.actions.stop(); |
||
106 | } else { |
||
107 | this.AudioPlayer.actions.play(); |
||
108 | } |
||
109 | } else if (evt.key === 'ArrowRight') {// right |
||
110 | this.AudioPlayer.actions.next(); |
||
111 | } else if (evt.key === 'ArrowLeft') {//left |
||
112 | this.AudioPlayer.actions.prev(); |
||
113 | } else if (evt.key === 'ArrowUp') {//up sound up |
||
114 | currentVolume = this.AudioPlayer.actions.getVolume(); |
||
115 | if (currentVolume > 0 && currentVolume <= 100) { |
||
116 | newVolume = currentVolume + 10; |
||
117 | if (newVolume >= 100) { |
||
118 | newVolume = 100; |
||
119 | } |
||
120 | this.AudioPlayer.actions.setVolume(newVolume); |
||
121 | } |
||
122 | } else if (evt.key === 'ArrowDown') {//down sound down |
||
123 | //this.AudioPlayer.actions.setVolume(0); |
||
124 | currentVolume = this.AudioPlayer.actions.getVolume(); |
||
125 | |||
126 | if (currentVolume > 0 && currentVolume <= 100) { |
||
127 | newVolume = currentVolume - 10; |
||
128 | if (newVolume <= 0) { |
||
129 | newVolume = 10; |
||
130 | } |
||
131 | this.AudioPlayer.actions.setVolume(newVolume); |
||
132 | } |
||
133 | } |
||
134 | } |
||
135 | }.bind(this)); |
||
136 | }; |
||
137 | |||
138 | Audios.prototype.loadCategoryAlbums = function () { |
||
139 | this.PlaylistContainer.show(); |
||
140 | this.EmptyContainer.hide(); |
||
141 | $('#loading').show(); |
||
142 | $('.toolTip').tooltip('hide'); |
||
143 | $('#alben').addClass('active'); |
||
144 | $('#individual-playlist').remove(); |
||
145 | $('#individual-playlist-info').hide(); |
||
146 | $('#individual-playlist-header').hide(); |
||
147 | $('.coverrow').remove(); |
||
148 | $('.songcontainer').remove(); |
||
149 | |||
150 | $('#myCategory li').removeClass('active'); |
||
151 | $('#newPlaylist').addClass('ap_hidden'); |
||
152 | |||
153 | $.ajax({ |
||
154 | type: 'GET', |
||
155 | url: OC.generateUrl('apps/audioplayer/getcategory'), |
||
156 | data: {category: 'Album'}, |
||
157 | success: this.loadCategoryAlbumsResponse.bind(this) |
||
158 | }); |
||
159 | }; |
||
160 | |||
161 | Audios.prototype.loadCategoryAlbumsResponse = function (jsondata) { |
||
162 | $('#loading').hide(); |
||
163 | if (jsondata.status === 'success') { |
||
164 | $('.sm2-bar-ui').show(); |
||
165 | this.buildCoverRow(jsondata.data); |
||
166 | } else { |
||
167 | this.showInitScreen(); |
||
168 | } |
||
169 | }; |
||
170 | |||
171 | Audios.prototype.buildCoverRow = function (aAlbums) { |
||
172 | var divAlbum = []; |
||
173 | var getcoverUrl = OC.generateUrl('apps/audioplayer/getcover/'); |
||
174 | var divRow = $('<div />').addClass('coverrow'); |
||
175 | |||
176 | var boundLoadIndividualAlbums = this.loadIndividualAlbums.bind(this); |
||
177 | for (var album of aAlbums) { |
||
0 ignored issues
–
show
Backwards Compatibility
introduced
by
Loading history...
|
|||
178 | var addCss; |
||
179 | var addDescr; |
||
180 | if (album.cid === '') { |
||
181 | addCss = 'background-color: #D3D3D3;color: #333333;'; |
||
182 | addDescr = album.name.substring(0, 1); |
||
183 | } else { |
||
184 | addDescr = ''; |
||
185 | addCss = 'background-image:url(' + getcoverUrl + album.cid + ');-webkit-background-size:cover;-moz-background-size:cover;background-size:cover;'; |
||
186 | } |
||
187 | |||
188 | divAlbum = $('<div/>').addClass('album').css('margin-left', '15px').attr({ |
||
189 | 'data-album': album.id, |
||
190 | 'data-name': album.name //required for songcontainer title |
||
191 | }).on('click', boundLoadIndividualAlbums); |
||
192 | |||
193 | var divPlayHref = $('<a/>'); |
||
194 | var divPlayImage = $('<div/>').attr({ |
||
195 | 'id': 'AlbumPlay' |
||
196 | }).on('click', boundLoadIndividualAlbums); |
||
197 | |||
198 | divPlayHref.append(divPlayImage); |
||
199 | |||
200 | var divAlbumCover = $('<div/>').addClass('albumcover').attr({'style': addCss}).text(addDescr); |
||
201 | var divAlbumDescr = $('<div/>').addClass('albumdescr').html('<span class="albumname">' + album.name + '</span><span class="artist">' + album.art + '</span>'); |
||
202 | |||
203 | divAlbum.append(divAlbumCover); |
||
204 | divAlbum.append(divAlbumDescr); |
||
205 | divAlbum.append(divPlayImage); |
||
206 | divRow.append(divAlbum); |
||
207 | } |
||
208 | this.PlaylistContainer.append(divRow); |
||
209 | }; |
||
210 | |||
211 | Audios.prototype.loadIndividualAlbums = function (evt) { |
||
212 | evt.stopPropagation(); |
||
213 | evt.preventDefault(); |
||
214 | |||
215 | var directPlay = typeof $(evt.target).attr('id') !== 'undefined'; |
||
216 | var eventTarget = $(evt.target).parent(); |
||
217 | var AlbumId = eventTarget.attr('data-album'); |
||
218 | var activeAlbum = $('.album[data-album="' + AlbumId + '"]'); |
||
219 | |||
220 | if (activeAlbum.hasClass('is-active')) { |
||
221 | $('.songcontainer').slideUp(200, function () { |
||
222 | $('.album').removeClass('is-active').find('.artist').css('visibility', 'visible'); |
||
223 | }); |
||
224 | } else { |
||
225 | $('.album').removeClass('is-active').find('.artist').css('visibility', 'visible'); |
||
226 | this.PlaylistContainer.data('playlist', 'Albums-' + AlbumId); |
||
227 | |||
228 | activeAlbum.addClass('is-active'); |
||
229 | activeAlbum.find('.artist').css('visibility', 'hidden'); |
||
230 | this.buildSongContainer(eventTarget, directPlay); |
||
231 | } |
||
232 | }; |
||
233 | |||
234 | Audios.prototype.buildSongContainer = function (eventTarget, directPlay) { |
||
235 | var AlbumId = eventTarget.attr('data-album'); |
||
236 | var AlbumName = eventTarget.attr('data-name'); |
||
237 | var activeAlbum = $('.album[data-album="' + AlbumId + '"]'); |
||
238 | var iArrowLeft = 72; |
||
239 | |||
240 | $('.songcontainer').remove(); |
||
241 | var divSongContainer = $('<div/>').addClass('songcontainer'); |
||
242 | var divArrow = $('<i/>').addClass('open-arrow').css('left', activeAlbum.position().left + iArrowLeft); |
||
243 | var divSongContainerInner = $('<div/>').addClass('songcontainer-inner'); |
||
244 | var listAlbumWrapper = $('<ul/>').addClass('albumwrapper').attr('data-album', AlbumId); |
||
245 | var divSongList; |
||
246 | var h2SongHeader = $('<h2/>').text(AlbumName); |
||
247 | var addCss; |
||
248 | var addDescr; |
||
249 | var myCover = $('.album.is-active .albumcover').css('background-image'); |
||
250 | |||
251 | if (myCover === 'none') { |
||
252 | addCss = 'background-color: #D3D3D3;color: #333333;'; |
||
253 | addDescr = AlbumName.substring(0, 1); |
||
254 | } else { |
||
255 | addDescr = ''; |
||
256 | addCss = 'background-image:' + myCover + ';-webkit-background-size:cover;-moz-background-size:cover;background-size:cover;'; |
||
257 | } |
||
258 | var divSongContainerCover = $('<div/>').addClass('songcontainer-cover').attr({'style': addCss}).text(addDescr); |
||
259 | var sidebarThumbnail = $('#sidebarThumbnail'); |
||
260 | |||
261 | if (this.PlaylistContainer.width() < 850) { |
||
262 | divSongContainerCover.addClass('cover-small'); |
||
263 | divSongList = $('<div/>').addClass('songlist one-column'); |
||
264 | if (sidebarThumbnail.hasClass('full')) { |
||
265 | sidebarThumbnail.addClass('larger').removeClass('full'); |
||
266 | } |
||
267 | } else { |
||
268 | divSongList = $('<div/>').addClass('songlist two-column'); |
||
269 | if (sidebarThumbnail.hasClass('larger')) { |
||
270 | sidebarThumbnail.addClass('full').removeClass('larger'); |
||
271 | } |
||
272 | } |
||
273 | |||
274 | var br = $('<br />').css('clear', 'both'); |
||
275 | |||
276 | divSongList.append(listAlbumWrapper); |
||
277 | divSongContainerInner.append(divSongContainerCover); |
||
278 | divSongContainerInner.append(h2SongHeader); |
||
279 | divSongContainerInner.append('<br/>'); |
||
280 | divSongContainerInner.append(divSongList); |
||
281 | divSongContainerInner.append(br); |
||
282 | divSongContainer.append(divArrow); |
||
283 | divSongContainer.append(divSongContainerInner); |
||
284 | this.PlaylistContainer.append(divSongContainer); |
||
285 | |||
286 | if (this.AjaxCallStatus !== null) { |
||
287 | this.AjaxCallStatus.abort(); |
||
288 | } |
||
289 | |||
290 | this.AjaxCallStatus = $.ajax({ |
||
291 | type: 'GET', |
||
292 | url: OC.generateUrl('apps/audioplayer/getcategoryitems'), |
||
293 | data: {category: 'Album', categoryId: AlbumId}, |
||
294 | success: function (jsondata) { |
||
295 | if (jsondata.status === 'success') { |
||
296 | var songcounter = 0; |
||
297 | $(jsondata.data).each(function (i, el) { |
||
298 | listAlbumWrapper.append(this.buildTrackRow(el)); |
||
299 | songcounter++; |
||
300 | }.bind(this)); |
||
301 | if (songcounter % 2 !== 0) { |
||
302 | var li = $('<li/>'); |
||
303 | var spanNr = $('<span/>').addClass('number').text('\u00A0'); |
||
304 | li.append(spanNr); |
||
305 | li.addClass('noPlaylist'); |
||
306 | listAlbumWrapper.append(li); //add a blank row in case of uneven records=>avoid a Chrome bug to strangely split the records across columns |
||
307 | } |
||
308 | this.trackClickHandler(); |
||
309 | this.indicateCurrentPlayingTrack(); |
||
310 | if (directPlay === true) { |
||
311 | $('.albumwrapper').find('.title').first().trigger('click'); |
||
312 | |||
313 | } |
||
314 | } |
||
315 | }.bind(this) |
||
316 | }); |
||
317 | |||
318 | var searchresult = decodeURI(location.hash).substr(1); |
||
319 | if (searchresult !== '') { |
||
320 | var locHashTemp = searchresult.split('-'); |
||
321 | var evt = {}; |
||
322 | evt.albumId = locHashTemp[1]; |
||
323 | window.location.href = '#'; |
||
324 | } |
||
325 | |||
326 | if (directPlay !== true) { |
||
327 | |||
328 | var iScroll = 120; |
||
329 | var iSlideDown = 200; |
||
330 | var iTop = 80; |
||
331 | var appContent; |
||
332 | var containerTop; |
||
333 | var appContentScroll; |
||
334 | if ($('#content-wrapper').length === 1) { //check old structure of NC13 and oC |
||
335 | appContent = $('#app-content'); |
||
336 | var scrollTopValue = appContent.scrollTop(); |
||
337 | containerTop = scrollTopValue + activeAlbum.offset().top + iTop; |
||
338 | appContentScroll = scrollTopValue + activeAlbum.offset().top - iScroll; |
||
339 | } else { //structure was changed with NC14 |
||
340 | appContent = $(document); |
||
341 | containerTop = activeAlbum.offset().top + iTop; |
||
342 | appContentScroll = activeAlbum.offset().top - iScroll; |
||
343 | } |
||
344 | |||
345 | divSongContainer.css({'top': containerTop}).slideDown(iSlideDown); |
||
346 | appContent.scrollTop(appContentScroll); |
||
347 | } |
||
348 | return true; |
||
349 | }; |
||
350 | |||
351 | Audios.prototype.buildTrackRow = function (elem) { |
||
352 | var getAudiostreamUrl = OC.generateUrl('apps/audioplayer/getaudiostream') + '?file='; |
||
353 | var can_play = soundManager.html5; |
||
354 | |||
355 | var li = $('<li/>').attr({ |
||
356 | 'data-trackid': elem.id, |
||
357 | 'data-title': elem.cl1, |
||
358 | 'data-artist': elem.cl2, |
||
359 | 'data-cover': elem.cid, |
||
360 | 'data-mimetype': elem.mim, |
||
361 | 'data-path': elem.lin, |
||
362 | 'class': 'dragable' |
||
363 | }); |
||
364 | |||
365 | var spanAction = $('<span/>').addClass('actionsSong').html('<i class="ioc ioc-volume-off"></i> '); |
||
366 | var spanNr = $('<span/>').addClass('number').text(elem.cl3); |
||
367 | var streamUrl = $('<a/>').attr({'href': getAudiostreamUrl + elem.lin, 'type': elem.mim}); |
||
368 | var spanEdit = $('<span/>').addClass('edit-song icon-more').attr({'title': t('audioplayer', 'Options')}).on('click', OCA.Audioplayer.Sidebar.showSidebar.bind(this)); |
||
369 | var spanTitle; |
||
370 | |||
371 | if (can_play[elem.mim] === true) { |
||
372 | spanTitle = $('<span/>').addClass('title').text(elem.cl1); |
||
373 | } else { |
||
374 | spanTitle = $('<span/>').addClass('title').html('<i>' + elem.cl1 + '</i>'); |
||
375 | } |
||
376 | |||
377 | li.append(streamUrl); |
||
378 | li.append(spanAction); |
||
379 | li.append(spanNr); |
||
380 | li.append(spanTitle); |
||
381 | li.append(spanEdit); |
||
382 | |||
383 | return li; |
||
384 | }; |
||
385 | |||
386 | Audios.prototype.trackClickHandler = function (callback) { |
||
387 | var albumWrapper = $('.albumwrapper'); |
||
388 | var getcoverUrl = OC.generateUrl('apps/audioplayer/getcover/'); |
||
389 | var category = this.PlaylistContainer.data('playlist').split('-'); |
||
390 | |||
391 | var can_play = soundManager.html5; |
||
392 | var stream_array = ['audio/mpegurl', 'audio/x-scpls', 'application/xspf+xml']; |
||
393 | for (var s = 0; s < stream_array.length; s++) { |
||
394 | can_play[stream_array[s]] = true; |
||
395 | } |
||
396 | |||
397 | var playlist = albumWrapper.find('li'); |
||
398 | var boundProcessAlbum = this.processAlbum.bind(this, category, getcoverUrl, can_play, playlist); |
||
399 | playlist.each( |
||
400 | boundProcessAlbum |
||
401 | ); |
||
402 | // the callback is used for the the init function to get feedback when all title rows are ready |
||
403 | if (typeof callback === 'function') { |
||
404 | callback(); |
||
405 | } |
||
406 | }; |
||
407 | |||
408 | Audios.prototype.processAlbum = function (category, coverUrl, can_play, playlist, i, el) { |
||
409 | var element = $(el); |
||
410 | |||
411 | if (!(category[0] === 'Playlist' && category[1].toString()[0] !== 'X' && category[1] !== '')) { |
||
412 | element.draggable({ |
||
413 | appendTo: 'body', |
||
414 | helper: this.dragElement, |
||
415 | cursor: 'move', |
||
416 | delay: 500, |
||
417 | start: function (event, ui) { |
||
418 | ui.helper.addClass('draggingSong'); |
||
419 | } |
||
420 | }); |
||
421 | } |
||
422 | |||
423 | element.find('.title').on('click', |
||
424 | this.onTitleClick.bind(this, coverUrl, can_play, playlist, element) |
||
425 | ); |
||
426 | }; |
||
427 | |||
428 | |||
429 | Audios.prototype.onTitleClick = function (coverUrl, can_play, playlist, element) { |
||
430 | var activeLi = element.closest('li'); |
||
431 | // if enabled, play sonos and skip the rest of the processing |
||
432 | if ($('#audioplayer_sonos').val() === 'checked') { |
||
433 | var liIndex = element.parents('li').index(); |
||
434 | this.PlaySonos(liIndex); |
||
435 | this.setStatistics(); |
||
436 | return; |
||
437 | } |
||
438 | if (can_play[activeLi.data('mimetype')] !== true) { |
||
439 | console.warn(`can't play ${activeLi.data('mimetype')}`); |
||
440 | return false; |
||
441 | } |
||
442 | if (activeLi.hasClass('isActive')) { |
||
443 | if ($('.sm2-bar-ui').hasClass('playing')) { |
||
444 | this.AudioPlayer.actions.stop(); |
||
445 | } else { |
||
446 | this.AudioPlayer.actions.play(); |
||
447 | } |
||
448 | } else { |
||
449 | // the visible playlist has to be copied to the player queue |
||
450 | // this disconnects the free navigation in AP while continuing to play a playlist |
||
451 | if (this.PlaylistContainer.data('playlist') !== this.ActivePlaylist.data('playlist')) { |
||
452 | var ClonePlaylist = playlist.clone(); |
||
453 | this.ActivePlaylist.html(''); |
||
454 | this.ActivePlaylist.append(ClonePlaylist); |
||
455 | this.ActivePlaylist.find('span').remove(); |
||
456 | this.ActivePlaylist.find('.noPlaylist').remove(); |
||
457 | this.ActivePlaylist.data('playlist', this.PlaylistContainer.data('playlist')); |
||
458 | } |
||
459 | this.currentTrackUiChange(coverUrl, activeLi); |
||
460 | if (this.AudioPlayer.playlistController.data.selectedIndex === null) { |
||
461 | this.AudioPlayer.playlistController.data.selectedIndex = 0; |
||
462 | } |
||
463 | this.AudioPlayer.actions.play(activeLi.index()); |
||
464 | this.setStatistics(); |
||
465 | } |
||
466 | }; |
||
467 | |||
468 | Audios.prototype.indicateCurrentPlayingTrack = function () { |
||
469 | if (this.PlaylistContainer.data('playlist') === this.ActivePlaylist.data('playlist')) { |
||
470 | var playingTrackId = $('#activePlaylist li.selected').data('trackid'); |
||
471 | var playingListItem = $('.albumwrapper li[data-trackid="' + playingTrackId + '"]'); |
||
472 | playingListItem.addClass('isActive'); |
||
473 | playingListItem.find('i.ioc').removeClass('ioc-volume-off').addClass('ioc-volume-up').show(); |
||
474 | playingListItem.find('i.icon').hide(); |
||
475 | } |
||
476 | }; |
||
477 | |||
478 | Audios.prototype.loadCategory = function (callback) { |
||
479 | var category = $('#category_selector').val(); |
||
480 | var addPlaylist = $('#addPlaylist'); |
||
481 | addPlaylist.addClass('hidden'); |
||
482 | $('#myCategory').html(''); |
||
483 | $('.toolTip').tooltip('hide'); |
||
484 | $.ajax({ |
||
485 | type: 'GET', |
||
486 | url: OC.generateUrl('apps/audioplayer/getcategory'), |
||
487 | data: {category: category}, |
||
488 | success: function (jsondata) { |
||
489 | if (jsondata.status === 'success') { |
||
490 | $(jsondata.data).each(function (i, el) { |
||
491 | var li = $('<li/>').attr({'data-id': el.id, 'data-name': el.name}); |
||
492 | var spanCounter = $('<span/>').attr('class', 'counter').text(el.counter); |
||
493 | var spanName; |
||
494 | |||
495 | if (category === 'Playlist' && el.id.toString()[0] !== 'X' && el.id !== '' && el.id.toString()[0] !== 'S') { |
||
496 | spanName = $('<span/>').attr({'class': 'pl-name-play'}).text(el.name).on('click', this.loadIndividualCategory.bind(this)); |
||
497 | var spanSort = $('<i/>').attr({ |
||
498 | 'class': 'ioc ioc-sort toolTip', |
||
499 | 'data-sortid': el.id, |
||
500 | 'title': t('audioplayer', 'Sort playlist') |
||
501 | }).on('click', this.sortPlaylist.bind(this)); |
||
502 | var spanEdit = $('<i/>').attr({ |
||
503 | 'class': 'icon icon-rename toolTip', |
||
504 | 'data-name': el.name, |
||
505 | 'data-editid': el.id, |
||
506 | 'title': t('audioplayer', 'Rename playlist') |
||
507 | }).on('click', this.renamePlaylist.bind(this)); |
||
508 | var spanDelete = $('<i/>').attr({ |
||
509 | 'class': 'ioc ioc-delete toolTip', |
||
510 | 'data-deleteid': el.id, |
||
511 | 'title': t('audioplayer', 'Delete playlist') |
||
512 | }).on('click', this.deletePlaylist.bind(this)); |
||
513 | li.droppable({ |
||
514 | activeClass: 'activeHover', |
||
515 | hoverClass: 'dropHover', |
||
516 | accept: 'li.dragable', |
||
517 | over: function () { |
||
518 | }, |
||
519 | drop: function (event, ui) { |
||
520 | this.addSongToPlaylist($(this).attr('data-id'), ui.draggable.attr('data-trackid')); |
||
521 | } |
||
522 | }); |
||
523 | li.append(spanName); |
||
524 | li.append(spanEdit); |
||
525 | li.append(spanSort); |
||
526 | li.append(spanDelete); |
||
527 | li.append(spanCounter); |
||
528 | } else if (el.id === '') { |
||
529 | spanName = $('<span/>').text(el.name).css({'float': 'left', 'min-height': '10px'}); |
||
530 | li.append(spanName); |
||
531 | li.append(spanCounter); |
||
532 | } else { |
||
533 | spanName = $('<span/>').attr({ |
||
534 | 'class': 'pl-name', |
||
535 | 'title': el.name |
||
536 | }).text(el.name).on('click', this.loadIndividualCategory.bind(this)); |
||
537 | li.append(spanName); |
||
538 | li.append(spanCounter); |
||
539 | } |
||
540 | $('#myCategory').append(li); |
||
541 | }.bind(this)); |
||
542 | if (typeof callback === 'function') { |
||
543 | callback(); |
||
544 | } |
||
545 | $('.toolTip').tooltip(); |
||
546 | } else { |
||
547 | this.showInitScreen(); |
||
548 | } |
||
549 | }.bind(this) |
||
550 | }); |
||
551 | if (category === 'Playlist') { |
||
552 | addPlaylist.removeClass('hidden'); |
||
553 | } |
||
554 | return true; |
||
555 | }; |
||
556 | |||
557 | |||
558 | Audios.prototype.loadIndividualCategory = function (evt, callback) { |
||
559 | this.PlaylistContainer.show(); |
||
560 | this.EmptyContainer.hide(); |
||
561 | $('#loading').show(); |
||
562 | $('.toolTip').tooltip('hide'); |
||
563 | $('#alben').removeClass('active'); |
||
564 | var individual_playlist = $('#individual-playlist'); |
||
565 | individual_playlist.remove(); |
||
566 | $('#individual-playlist-info').show(); |
||
567 | $('#individual-playlist-header').show(); |
||
568 | $('.coverrow').remove(); |
||
569 | $('.songcontainer').remove(); |
||
570 | |||
571 | this.PlaylistContainer.append('<ul id="individual-playlist" class="albumwrapper"></ul>'); |
||
572 | |||
573 | var category = $('#category_selector').val(); |
||
574 | |||
575 | if (typeof evt !== 'undefined' && evt !== null) { |
||
576 | $('#myCategory li').removeClass('active').removeClass('active'); |
||
577 | var eventTarget = $(evt.target); |
||
578 | eventTarget.parent('li').addClass('active').addClass('active'); |
||
579 | } |
||
580 | |||
581 | var categoryActive = $('#myCategory li.active'); |
||
582 | var PlaylistId = categoryActive.data('id'); |
||
583 | this.CategorySelectors[1] = PlaylistId; |
||
584 | this.PlaylistContainer.data('playlist', category + '-' + PlaylistId); |
||
585 | |||
586 | |||
587 | if (individual_playlist.data('ui-sortable')) { $('#individual-playlist').sortable('destroy'); } |
||
588 | $('.header-title').data('order', ''); |
||
589 | $('.header-artist').data('order', ''); |
||
590 | $('.header-album').data('order', ''); |
||
591 | |||
592 | if (this.AjaxCallStatus !== null) { |
||
593 | this.AjaxCallStatus.abort(); |
||
594 | } |
||
595 | |||
596 | this.AjaxCallStatus = $.ajax({ |
||
597 | type: 'GET', |
||
598 | url: OC.generateUrl('apps/audioplayer/getcategoryitems'), |
||
599 | data: {category: category, categoryId: PlaylistId}, |
||
600 | success: this.onGetCategoryItemsResponse.bind(this, callback, category, categoryActive, PlaylistId) |
||
601 | }); |
||
602 | }; |
||
603 | |||
604 | Audios.prototype.onGetCategoryItemsResponse = function (callback, category, categoryActive, playlistId, jsondata) { |
||
605 | var getAudiostreamUrl = OC.generateUrl('apps/audioplayer/getaudiostream') + '?file='; |
||
606 | var albumcount = ''; |
||
607 | var can_play = soundManager.html5; |
||
608 | var stream_array = ['audio/mpegurl', 'audio/x-scpls', 'application/xspf+xml']; |
||
609 | for (var s = 0; s < stream_array.length; s++) { |
||
610 | can_play[stream_array[s]] = true; |
||
611 | } |
||
612 | var category_title = categoryActive.find('span').first().text(); |
||
613 | $('#loading').hide(); |
||
614 | if (jsondata.status === 'success') { |
||
615 | $('.sm2-bar-ui').show(); |
||
616 | $(jsondata.data).each(function (i, el) { |
||
617 | |||
618 | var li = $('<li/>').attr({ |
||
619 | 'data-trackid': el.id, |
||
620 | 'data-mimetype': el.mim, |
||
621 | 'mimetype': el.mim, |
||
622 | 'data-title': el.cl1, |
||
623 | 'data-artist': el.cl2, |
||
624 | 'data-album': el.cl3, |
||
625 | 'data-cover': el.cid, |
||
626 | 'data-path': el.lin, |
||
627 | 'class': 'dragable' |
||
628 | }); |
||
629 | var fav_action; |
||
630 | |||
631 | if (el.fav === 't') { |
||
632 | fav_action = $('<i/>').addClass('icon icon-starred') |
||
633 | .css({'opacity': 0.3}) |
||
634 | .attr({'data-trackid': el.id}) |
||
635 | .on('click', this.favoriteUpdate.bind(this)); |
||
636 | } else { |
||
637 | fav_action = $('<i/>').addClass('icon icon-star') |
||
638 | .attr({'data-trackid': el.id}) |
||
639 | .on('click', this.favoriteUpdate.bind(this)); |
||
640 | } |
||
641 | |||
642 | var stream_type; |
||
643 | var streamUrl; |
||
644 | var spanAction; |
||
645 | var spanEdit; |
||
646 | var spanTitle; |
||
647 | |||
648 | if (el.mim === 'audio/mpegurl' || el.mim === 'audio/x-scpls' || el.mim === 'application/xspf+xml') { |
||
649 | stream_type = true; |
||
650 | streamUrl = $('<a/>').attr({'href': el.lin, 'type': el.mim}); |
||
651 | spanAction = $('<span/>') |
||
652 | .addClass('actionsSong') |
||
653 | .append(fav_action) |
||
654 | .append($('<i/>').addClass('ioc ioc-volume-off')); |
||
655 | } else { |
||
656 | stream_type = false; |
||
657 | streamUrl = $('<a/>').attr({'href': getAudiostreamUrl + el.lin, 'type': el.mim}); |
||
658 | spanAction = $('<span/>').addClass('actionsSong') |
||
659 | .append(fav_action) |
||
660 | .append($('<i/>').addClass('ioc ioc-volume-off')); |
||
661 | } |
||
662 | var spanInterpret = $('<span>').attr({'class': 'interpret'}); |
||
663 | var spanAlbum = $('<span>').attr({'class': 'album-indi'}); |
||
664 | var spanTime = $('<span/>').addClass('time').text(el.len); |
||
665 | |||
666 | if (can_play[el.mim] === true || stream_type === true) { |
||
667 | spanTitle = $('<span/>').addClass('title').text(el.cl1); |
||
668 | spanInterpret = spanInterpret.text(el.cl2); |
||
669 | spanAlbum = spanAlbum.text(el.cl3); |
||
670 | spanEdit = $('<span/>').addClass('edit-song icon-more').attr({'title': t('audioplayer', 'Options')}).on('click', OCA.Audioplayer.Sidebar.showSidebar.bind(this)); |
||
671 | } else { |
||
672 | spanTitle = $('<span/>').addClass('title').html('<i>' + el.cl1 + '</i>'); |
||
673 | spanInterpret = spanInterpret.html('<i>' + el.cl2 + '</i>'); |
||
674 | spanAlbum = spanAlbum.html('<i>' + el.cl3 + '</i>'); |
||
675 | spanEdit = $('<span/>').addClass('edit-song ioc-close').attr({'title': t('audioplayer', 'MIME type not supported by browser')}).css({ |
||
676 | 'opacity': 1, |
||
677 | 'text-align': 'center' |
||
678 | }).on('click', OCA.Audioplayer.Sidebar.showSidebar.bind(this)); |
||
679 | } |
||
680 | |||
681 | |||
682 | li.append(streamUrl); |
||
683 | li.append(spanAction); |
||
684 | li.append(spanTitle); |
||
685 | li.append(spanInterpret); |
||
686 | li.append(spanAlbum); |
||
687 | li.append(spanTime); |
||
688 | li.append(spanEdit); |
||
689 | |||
690 | $('#individual-playlist').append(li); |
||
691 | }.bind(this)); // end each loop |
||
692 | |||
693 | this.trackClickHandler(callback); |
||
694 | this.indicateCurrentPlayingTrack(); |
||
695 | |||
696 | $('.header-title').text(jsondata.header.col1); |
||
697 | $('.header-artist').text(jsondata.header.col2); |
||
698 | $('.header-album').text(jsondata.header.col3); |
||
699 | $('.header-time').text(jsondata.header.col4); |
||
700 | |||
701 | if (jsondata.albums >> 1) { |
||
702 | albumcount = ' (' + jsondata.albums + ' ' + t('audioplayer', 'Albums') + ')'; |
||
703 | } else { |
||
704 | albumcount = ''; |
||
705 | } |
||
706 | |||
707 | } else if (playlistId.toString()[0] === 'X') { |
||
708 | this.showInitScreen('smart'); |
||
709 | } else { |
||
710 | this.showInitScreen('playlist'); |
||
711 | } |
||
712 | |||
713 | if (category !== 'Title') { |
||
714 | $('#individual-playlist-info').html(t('audioplayer', 'Selected ' + category) + ': ' + category_title + albumcount); |
||
715 | } else { |
||
716 | $('#individual-playlist-info').html(t('audioplayer', 'Selected') + ': ' + category_title + albumcount); |
||
717 | } |
||
718 | }; |
||
719 | |||
720 | Audios.prototype.showInitScreen = function (mode) { |
||
721 | $('.sm2-bar-ui').hide(); |
||
722 | this.PlaylistContainer.hide(); |
||
723 | this.EmptyContainer.show(); |
||
724 | this.EmptyContainer.html(''); |
||
725 | |||
726 | if (mode === 'smart') { |
||
727 | this.EmptyContainer.html('<span class="no-songs-found">' + t('audioplayer', 'Welcome to') + ' ' + t('audioplayer', 'Audio Player') + '</span>'); |
||
728 | } else if (mode === 'playlist') { |
||
729 | this.EmptyContainer.html('<span class="no-songs-found">' + t('audioplayer', 'Add new tracks to playlist by drag and drop') + '</span>'); |
||
730 | } else { |
||
731 | this.EmptyContainer.html('<span class="no-songs-found">' + t('audioplayer', 'Welcome to') + ' ' + t('audioplayer', 'Audio Player') + '</span>'); |
||
732 | this.EmptyContainer.append('<span class="no-songs-found-pl"><i class="ioc ioc-refresh" title="' + t('audioplayer', 'Scan for new audio files') + '" id="scanAudiosFirst"></i> ' + t('audioplayer', 'Add new tracks to library') + '</span>'); |
||
733 | this.EmptyContainer.append('<a class="no-songs-found-pl" href="https://github.com/rello/audioplayer/wiki" target="_blank">' + t('audioplayer', 'Help') + '</a>'); |
||
734 | } |
||
735 | }; |
||
736 | |||
737 | Audios.prototype.dragElement = function () { |
||
738 | return $(this).clone().text($(this).find('.title').attr('data-title')); |
||
739 | }; |
||
740 | |||
741 | Audios.prototype.favoriteUpdate = function (evt) { |
||
742 | var trackid = $(evt.target).attr('data-trackid'); |
||
743 | var isFavorite = false; |
||
744 | |||
745 | if (this.CategorySelectors[1].toString().substring(0, 1) === 'S') { return; } |
||
746 | |||
747 | if ($(evt.target).hasClass('icon icon-starred')) { |
||
748 | isFavorite = true; |
||
749 | $(evt.target).removeClass('icon icon-starred'); |
||
750 | $(evt.target).addClass('icon icon-star').removeAttr('style'); |
||
751 | } else { |
||
752 | isFavorite = false; |
||
753 | $(evt.target).removeClass('icon icon-star'); |
||
754 | $(evt.target).addClass('icon icon-starred').css('opacity', 1); |
||
755 | } |
||
756 | |||
757 | $.ajax({ |
||
758 | type: 'GET', |
||
759 | url: OC.generateUrl('apps/audioplayer/setfavorite'), |
||
760 | data: { |
||
761 | 'trackid': trackid, |
||
762 | 'isFavorite': isFavorite |
||
763 | } |
||
764 | }); |
||
765 | return false; |
||
766 | }; |
||
767 | |||
768 | Audios.prototype.addSongToPlaylist = function (plId, songId) { |
||
769 | var sort = parseInt($('#myPlayList li[data-id="' + plId + '"]').find('.counter').text()); |
||
770 | return $.getJSON(OC.generateUrl('apps/audioplayer/addtracktoplaylist'), { |
||
771 | playlistid: plId, |
||
772 | songid: songId, |
||
773 | sorting: (sort + 1) |
||
774 | }).then(function () { |
||
775 | $('.toolTip').tooltip('hide'); |
||
776 | this.CategorySelectors[0] = 'Playlist'; |
||
777 | this.loadCategory(); |
||
778 | }.bind(this)); |
||
779 | }; |
||
780 | |||
781 | Audios.prototype.newPlaylist = function (plName) { |
||
782 | $.ajax({ |
||
783 | type: 'GET', |
||
784 | url: OC.generateUrl('apps/audioplayer/addplaylist'), |
||
785 | data: {'playlist': plName}, |
||
786 | success: function (jsondata) { |
||
787 | if (jsondata.status === 'success') { |
||
788 | this.loadCategory(); |
||
789 | } |
||
790 | if (jsondata.status === 'error') { |
||
791 | $('#notification').text(t('audioplayer', 'No playlist selected!')).slideDown(); |
||
792 | window.setTimeout(function () { |
||
793 | $('#notification').slideUp(); |
||
794 | }, 3000); |
||
795 | } |
||
796 | }.bind(this) |
||
797 | }); |
||
798 | }; |
||
799 | |||
800 | Audios.prototype.renamePlaylist = function (evt) { |
||
801 | var eventTarget = $(evt.target); |
||
802 | if ($('.plclone').length === 1) { |
||
803 | var plId = eventTarget.data('editid'); |
||
804 | var plistName = eventTarget.data('name'); |
||
805 | var myClone = $('#pl-clone').clone(); |
||
806 | |||
807 | |||
808 | $('#myCategory li[data-id="' + plId + '"]').after(myClone); |
||
809 | myClone.attr('data-pl', plId).show(); |
||
810 | $('#myCategory li[data-id="' + plId + '"]').hide(); |
||
811 | |||
812 | var boundGenerateRenameRequest = this.generateRenameRequest.bind(this); |
||
813 | myClone.find('input[name="playlist"]') |
||
814 | .bind('keydown', function (event) { |
||
815 | if (event.which === 13) { |
||
816 | if (myClone.find('input[name="playlist"]').val() !== '') { |
||
817 | boundGenerateRenameRequest(plId, myClone); |
||
818 | } else { |
||
819 | myClone.remove(); |
||
820 | $('#myCategory li[data-id="' + plId + '"]').show(); |
||
821 | } |
||
822 | } |
||
823 | }) |
||
824 | .val(plistName).trigger('focus'); |
||
825 | |||
826 | |||
827 | myClone.on('keyup', function (evt) { |
||
828 | if (evt.keyCode === 27) { |
||
829 | myClone.remove(); |
||
830 | $('#myCategory li[data-id="' + plId + '"]').show(); |
||
831 | } |
||
832 | }); |
||
833 | myClone.find('button.icon-checkmark').on('click', function () { |
||
834 | if (myClone.find('input[name="playlist"]').val() !== '') { |
||
835 | boundGenerateRenameRequest(plId, myClone); |
||
836 | } |
||
837 | }); |
||
838 | myClone.find('button.icon-close').on('click', function () { |
||
839 | this.loadCategory(); |
||
840 | myClone.remove(); |
||
841 | }.bind(this)); |
||
842 | } |
||
843 | }; |
||
844 | |||
845 | Audios.prototype.generateRenameRequest = function (playlistId, playlistClone) { |
||
846 | var saveForm = $('.plclone[data-pl="' + playlistId + '"]'); |
||
847 | var plname = saveForm.find('input[name="playlist"]').val(); |
||
848 | |||
849 | $.getJSON(OC.generateUrl('apps/audioplayer/updateplaylist'), { |
||
850 | plId: playlistId, |
||
851 | newname: plname |
||
852 | }, function (jsondata) { |
||
853 | if (jsondata.status === 'success') { |
||
854 | this.loadCategory(); |
||
855 | playlistClone.remove(); |
||
856 | } |
||
857 | if (jsondata.status === 'error') { |
||
858 | alert('could not update playlist'); |
||
859 | } |
||
860 | }.bind(this)); |
||
861 | }; |
||
862 | |||
863 | Audios.prototype.sortPlaylist = function (evt) { |
||
864 | var eventTarget = $(evt.target); |
||
865 | var notification = $('#notification'); |
||
866 | if ($('#myCategory li').hasClass('active')) { |
||
867 | var plId = eventTarget.attr('data-sortid'); |
||
868 | if (eventTarget.hasClass('sortActive')) { |
||
869 | |||
870 | var idsInOrder = $('#individual-playlist').sortable('toArray', {attribute: 'data-trackid'}); |
||
871 | $.getJSON(OC.generateUrl('apps/audioplayer/sortplaylist'), { |
||
872 | playlistid: plId, |
||
873 | songids: idsInOrder.join(';') |
||
874 | }, function (jsondata) { |
||
875 | if (jsondata.status === 'success') { |
||
876 | eventTarget.removeClass('sortActive'); |
||
877 | $('#individual-playlist').sortable('destroy'); |
||
878 | notification.text(jsondata.msg); |
||
879 | notification.slideDown(); |
||
880 | window.setTimeout(function () { |
||
881 | $('#notification').slideUp(); |
||
882 | }, 3000); |
||
883 | } |
||
884 | }.bind(this)); |
||
885 | |||
886 | } else { |
||
887 | |||
888 | notification.text(t('audioplayer', 'Sort modus active')); |
||
889 | notification.slideDown(); |
||
890 | window.setTimeout(function () { |
||
891 | $('#notification').slideUp(); |
||
892 | }, 3000); |
||
893 | |||
894 | $('#individual-playlist').sortable({ |
||
895 | items: 'li', |
||
896 | axis: 'y', |
||
897 | placeholder: 'ui-state-highlight', |
||
898 | helper: 'clone', |
||
899 | stop: function () { |
||
900 | } |
||
901 | }); |
||
902 | |||
903 | eventTarget.addClass('sortActive'); |
||
904 | if ($('.sm2-bar-ui').hasClass('playing')) { |
||
905 | this.AudioPlayer.actions.pause(); |
||
906 | $('#individual-playlist li').removeClass('isActive'); |
||
907 | $('#individual-playlist li i.ioc').hide(); |
||
908 | } else { |
||
909 | $('#individual-playlist li').removeClass('isActive'); |
||
910 | $('#individual-playlist li i.ioc').hide(); |
||
911 | } |
||
912 | |||
913 | } |
||
914 | } |
||
915 | }; |
||
916 | |||
917 | Audios.prototype.deletePlaylist = function (evt) { |
||
918 | var plId = $(evt.target).attr('data-deleteid'); |
||
919 | |||
920 | OC.dialogs.message( |
||
921 | t('audioplayer', 'Are you sure?'), |
||
922 | t('audioplayer', 'Delete playlist'), |
||
923 | null, |
||
924 | OCdialogs.YES_NO_BUTTONS, |
||
925 | function (e) { |
||
926 | if (e === true) { |
||
927 | $.ajax({ |
||
928 | type: 'GET', |
||
929 | url: OC.generateUrl('apps/audioplayer/removeplaylist'), |
||
930 | data: {'playlistid': plId}, |
||
931 | success: function (jsondata) { |
||
932 | if (jsondata.status === 'success') { |
||
933 | this.loadCategory(); |
||
934 | $('#notification').text(t('audioplayer', 'Playlist successfully deleted!')).slideDown(); |
||
935 | window.setTimeout(function () { |
||
936 | $('#notification').slideUp(); |
||
937 | }, 3000); |
||
938 | } |
||
939 | }.bind(this) |
||
940 | }); |
||
941 | } |
||
942 | }.bind(this), |
||
943 | true |
||
944 | ); |
||
945 | return false; |
||
946 | |||
947 | }; |
||
948 | |||
949 | Audios.prototype.getUserValue = function (user_type, callback) { |
||
950 | $.ajax({ |
||
951 | type: 'GET', |
||
952 | url: OC.generateUrl('apps/audioplayer/getvalue'), |
||
953 | data: {'type': user_type}, |
||
954 | success: function (jsondata) { |
||
955 | if (jsondata.status === 'success' && user_type === 'category') { |
||
956 | this.CategorySelectors = jsondata.value.split('-'); |
||
957 | callback(this.CategorySelectors); |
||
958 | } else if (jsondata.status === 'false' && user_type === 'category'){ |
||
959 | this.CategorySelectors = 'false'; |
||
960 | callback(this.CategorySelectors); |
||
961 | } |
||
962 | }.bind(this) |
||
963 | }); |
||
964 | }; |
||
965 | |||
966 | Audios.prototype.setUserValue = function (user_type, user_value) { |
||
967 | if (user_type) { |
||
968 | if (user_type === 'category') { this.CategorySelectors = user_value.split('-'); } |
||
969 | $.ajax({ |
||
970 | type: 'GET', |
||
971 | url: OC.generateUrl('apps/audioplayer/setvalue'), |
||
972 | data: { |
||
973 | 'type': user_type, |
||
974 | 'value': user_value |
||
975 | }, |
||
976 | success: function () { |
||
977 | } |
||
978 | }); |
||
979 | } |
||
980 | }; |
||
981 | |||
982 | Audios.prototype.setStatistics = function () { |
||
983 | var track_id = $('#activePlaylist li.selected').data('trackid'); |
||
984 | if (track_id) { |
||
985 | $.ajax({ |
||
986 | type: 'GET', |
||
987 | url: OC.generateUrl('apps/audioplayer/setstatistics'), |
||
988 | data: {'track_id': track_id}, |
||
989 | success: function () { |
||
990 | } |
||
991 | }); |
||
992 | this.setUserValue('category', this.CategorySelectors[0] + '-' + this.CategorySelectors[1] + '-' + track_id); |
||
993 | } |
||
994 | |||
995 | }; |
||
996 | |||
997 | Audios.prototype.sortPlaylist = function (evt) { |
||
998 | var column = $(evt.target).attr('class').split('-')[1]; |
||
999 | var order = $(evt.target).data('order'); |
||
1000 | var factor = 1; |
||
1001 | |||
1002 | if (order === 'descending') { |
||
1003 | factor = -1; |
||
1004 | $(evt.target).data('order', 'ascending'); |
||
1005 | } else { |
||
1006 | $(evt.target).data('order', 'descending'); |
||
1007 | } |
||
1008 | |||
1009 | var elems = $('#individual-playlist').children('li').get(); |
||
1010 | if (elems.length === 0) { return; } |
||
1011 | |||
1012 | var reg_check = $(elems).first().data(column).toString().match(/^\d{1,2}-\d{1,2}$/); |
||
1013 | elems.sort(function (a, b) { |
||
1014 | a = $(a).data(column).toString(); |
||
1015 | b = $(b).data(column).toString(); |
||
1016 | if (reg_check) { |
||
1017 | a = parseInt(a.split('-')[0]) * 100 + parseInt(a.split('-')[1]); |
||
1018 | b = parseInt(b.split('-')[0]) * 100 + parseInt(b.split('-')[1]); |
||
1019 | } else { |
||
1020 | a = a.toLowerCase(); |
||
1021 | b = b.toLowerCase(); |
||
1022 | } |
||
1023 | return ((a < b) ? -1 * factor : ((a > b) ? factor : 0)); |
||
1024 | }); |
||
1025 | $('#individual-playlist').append(elems); |
||
1026 | |||
1027 | if (this.PlaylistContainer.data('playlist') === this.ActivePlaylist.data('playlist')) { |
||
1028 | elems = this.ActivePlaylist.children('li').get(); |
||
1029 | elems.sort(function (a, b) { |
||
1030 | a = $(a).data(column).toString(); |
||
1031 | b = $(b).data(column).toString(); |
||
1032 | if (reg_check) { |
||
1033 | a = parseInt(a.split('-')[0]) * 100 + parseInt(a.split('-')[1]); |
||
1034 | b = parseInt(b.split('-')[0]) * 100 + parseInt(b.split('-')[1]); |
||
1035 | } else { |
||
1036 | a = a.toLowerCase(); |
||
1037 | b = b.toLowerCase(); |
||
1038 | } |
||
1039 | return ((a < b) ? -1 * factor : ((a > b) ? factor : 0)); |
||
1040 | }); |
||
1041 | this.ActivePlaylist.append(elems); |
||
1042 | } |
||
1043 | |||
1044 | if (this.AudioPlayer) { |
||
1045 | this.AudioPlayer.playlistController.data.selectedIndex = $('#activePlaylist li.selected').index(); |
||
1046 | } |
||
1047 | }; |
||
1048 | |||
1049 | Audios.prototype.currentTrackUiChange = function (coverUrl, activeLi) { |
||
1050 | var addCss; |
||
1051 | var addDescr; |
||
1052 | var coverID = activeLi.data('cover'); |
||
1053 | if (coverID === '') { |
||
1054 | addCss = 'background-color: #D3D3D3;color: #333333;'; |
||
1055 | addDescr = activeLi.data('title').substring(0, 1); |
||
1056 | } else { |
||
1057 | addCss = 'background-image:url(' + coverUrl + coverID + ');-webkit-background-size:cover;-moz-background-size:cover;background-size:cover;'; |
||
1058 | addDescr = ''; |
||
1059 | } |
||
1060 | $('.sm2-playlist-cover').attr({'style': addCss}).text(addDescr); |
||
1061 | document.title = activeLi.data('title') + ' (' + activeLi.data('artist') + ' ) @ ' + this.initialDocumentTitle; |
||
1062 | }; |
||
1063 | |||
1064 | Audios.prototype.soundmanagerCallback = function (SMaction) { |
||
1065 | if (SMaction === 'setVolume') { |
||
1066 | this.setUserValue('volume', Math.round(this.AudioPlayer.actions.getVolume())); |
||
1067 | } else { |
||
1068 | this.currentTrackUiChange( |
||
1069 | OC.generateUrl('apps/audioplayer/getcover/'), |
||
1070 | $('#activePlaylist li.selected') |
||
1071 | ); |
||
1072 | this.setStatistics(); |
||
1073 | } |
||
1074 | }; |
||
1075 | |||
1076 | Audios.prototype.checkNewTracks = function () { |
||
1077 | $.ajax({ |
||
1078 | type: 'POST', |
||
1079 | url: OC.generateUrl('apps/audioplayer/checknewtracks'), |
||
1080 | success: function (data) { |
||
1081 | if (data === 'true') { |
||
1082 | OC.Notification.showTemporary(t('audioplayer', 'New or updated audio files available')); |
||
1083 | } |
||
1084 | } |
||
1085 | }); |
||
1086 | }; |
||
1087 | |||
1088 | Audios.prototype.resizePlaylist = function () { |
||
1089 | var songlist = $('.songcontainer .songlist'); |
||
1090 | $('.sm2-bar-ui').width(this.PlaylistContainer.width()); |
||
1091 | if ($('.album.is-active').length !== 0) { |
||
1092 | this.buildSongContainer($('.album.is-active')); |
||
1093 | } |
||
1094 | |||
1095 | if (this.PlaylistContainer.width() < 850) { |
||
1096 | songlist.addClass('one-column'); |
||
1097 | songlist.removeClass('two-column'); |
||
1098 | $('.songcontainer .songcontainer-cover').addClass('cover-small'); |
||
1099 | } else { |
||
1100 | songlist.removeClass('one-column'); |
||
1101 | songlist.addClass('two-column'); |
||
1102 | $('.songcontainer .songcontainer-cover').removeClass('cover-small'); |
||
1103 | } |
||
1104 | }; |
||
1105 | |||
1106 | var resizeTimeout = null; |
||
1107 | $(document).ready(function () { |
||
1108 | |||
1109 | var myAudios = new Audios(); |
||
1110 | myAudios.init(); |
||
1111 | myAudios.checkNewTracks(); |
||
1112 | if ($('#audioplayer_sonos').val() !== 'checked') { |
||
1113 | myAudios.AudioPlayer = new SM2BarPlayer($('.sm2-bar-ui')[0]); |
||
1114 | myAudios.AudioPlayer.actions.setVolume($('#audioplayer_volume').val()); |
||
1115 | } |
||
1116 | |||
1117 | var notify = $('#audioplayer_notification').val(); |
||
1118 | if (notify !== '') { |
||
1119 | OC.Notification.showHtml( |
||
1120 | notify, |
||
1121 | { |
||
1122 | type: 'error', |
||
1123 | isHTML: true |
||
1124 | } |
||
1125 | ); |
||
1126 | } |
||
1127 | |||
1128 | $('.sm2-bar-ui').width(myAudios.PlaylistContainer.width()); |
||
1129 | |||
1130 | myAudios.resizePlaylist = _.debounce(myAudios.resizePlaylist.bind(myAudios), 250); |
||
1131 | $('#app-content').on('appresized', myAudios.resizePlaylist); |
||
1132 | |||
1133 | $('#addPlaylist').on('click', function () { |
||
1134 | $('#newPlaylistTxt').val(''); |
||
1135 | $('#newPlaylist').removeClass('ap_hidden'); |
||
1136 | }); |
||
1137 | |||
1138 | $('#newPlaylistBtn_cancel').on('click', function () { |
||
1139 | $('#newPlaylistTxt').val(''); |
||
1140 | $('#newPlaylist').addClass('ap_hidden'); |
||
1141 | }); |
||
1142 | |||
1143 | $('#newPlaylistBtn_ok').on('click', function () { |
||
1144 | var newPlaylistTxt = $('#newPlaylistTxt'); |
||
1145 | if (newPlaylistTxt.val() !== '') { |
||
1146 | myAudios.newPlaylist(newPlaylistTxt.val()); |
||
1147 | newPlaylistTxt.val(''); |
||
1148 | newPlaylistTxt.trigger('focus'); |
||
1149 | $('#newPlaylist').addClass('ap_hidden'); |
||
1150 | } |
||
1151 | }); |
||
1152 | |||
1153 | $('#newPlaylistTxt').bind('keydown', function (event) { |
||
1154 | var newPlaylistTxt = $('#newPlaylistTxt'); |
||
1155 | if (event.which === 13 && newPlaylistTxt.val() !== '') { |
||
1156 | myAudios.newPlaylist(newPlaylistTxt.val()); |
||
1157 | newPlaylistTxt.val(''); |
||
1158 | newPlaylistTxt.trigger('focus'); |
||
1159 | $('#newPlaylist').addClass('ap_hidden'); |
||
1160 | } |
||
1161 | }); |
||
1162 | |||
1163 | |||
1164 | $('#alben').addClass('active').on('click', function () { |
||
1165 | myAudios.loadCategoryAlbums(); |
||
1166 | myAudios.setUserValue('category', 'Albums'); |
||
1167 | }); |
||
1168 | |||
1169 | |||
1170 | $('#toggle_alternative').prepend('<div id="app-navigation-toggle_alternative" class="icon-menu" style="float: left; box-sizing: border-box;"></div>'); |
||
1171 | |||
1172 | $('#app-navigation-toggle_alternative').on('click', function () { |
||
1173 | $('#newPlaylist').addClass('ap_hidden'); |
||
1174 | if ($('#app-navigation').hasClass('hidden')) { |
||
1175 | $('#app-navigation').removeClass('hidden'); |
||
1176 | myAudios.setUserValue('navigation', 'true'); |
||
1177 | } else { |
||
1178 | $('#app-navigation').addClass('hidden'); |
||
1179 | myAudios.setUserValue('navigation', 'false'); |
||
1180 | } |
||
1181 | myAudios.resizePlaylist.call(myAudios); |
||
1182 | }); |
||
1183 | |||
1184 | $('#category_selector').change(function () { |
||
1185 | $('#newPlaylist').addClass('ap_hidden'); |
||
1186 | myAudios.CategorySelectors[0] = $('#category_selector').val(); |
||
1187 | myAudios.CategorySelectors[1] = ''; |
||
1188 | $('#myCategory').html(''); |
||
1189 | if (myAudios.CategorySelectors[0] !== '') { |
||
1190 | myAudios.loadCategory(); |
||
1191 | } |
||
1192 | }); |
||
1193 | |||
1194 | var boundSortPlaylist = myAudios.sortPlaylist.bind(myAudios); |
||
1195 | $('.header-title').on('click', boundSortPlaylist).css('cursor', 'pointer'); |
||
1196 | $('.header-artist').on('click', boundSortPlaylist).css('cursor', 'pointer'); |
||
1197 | $('.header-album').on('click', boundSortPlaylist).css('cursor', 'pointer'); |
||
1198 | |||
1199 | window.setTimeout(function () { |
||
1200 | $('.sm2-bar-ui').width(myAudios.PlaylistContainer.width()); |
||
1201 | }, 1000); |
||
1202 | |||
1203 | $(window).on('resize', _.debounce(function () { |
||
1204 | if (resizeTimeout) { |
||
1205 | clearTimeout(resizeTimeout); |
||
1206 | } |
||
1207 | resizeTimeout = setTimeout(function () { |
||
1208 | myAudios.resizePlaylist(); |
||
1209 | }, 500); |
||
1210 | })); |
||
1211 | |||
1212 | window.onhashchange = function () { |
||
1213 | var locHash = decodeURI(location.hash).substr(1); |
||
1214 | if (locHash !== '') { |
||
1215 | var locHashTemp = locHash.split('-'); |
||
1216 | |||
1217 | $('#searchresults').addClass('hidden'); |
||
1218 | window.location.href = '#'; |
||
1219 | if (locHashTemp[0] !== 'volume' && locHashTemp[0] !== 'repeat' && locHashTemp[0] !== 'shuffle' && locHashTemp[0] !== 'prev' && locHashTemp[0] !== 'play' && locHashTemp[0] !== 'next') { |
||
1220 | myAudios.CategorySelectors = locHashTemp; |
||
1221 | myAudios.presetDisplay(); |
||
1222 | } |
||
1223 | } |
||
1224 | }; |
||
1225 | }); |
||
1226 |