fixed studio and compoplayer init process

This commit is contained in:
Bachir Soussi Chiadmi
2018-03-27 16:15:54 +02:00
parent bb03f9bf7b
commit 09f25ef4ef
3 changed files with 78 additions and 38 deletions
@@ -45,6 +45,12 @@
function initEvents(){
$('body')
.on('on-studio-chutier-updated', initAjaxLinks)
.on('studio-initialized', function(e){
_compoPlayer.initControls();
})
.on('studio-not-active', function(e){
_compoPlayer.deactivate();
})
.on('on-studio-compo-updated', function(e){
initAjaxLinks();
_compoPlayer.refresh();
@@ -280,7 +286,6 @@
_$body.attr('corpus-map', 'ready');
}
// _ _ _
// /_\ _ _ __| (_)___
// / _ \ || / _` | / _ \
@@ -637,11 +642,14 @@
// \___\___/_|_|_| .__/\___/_| |_\__,_|\_, \___|_|
// |_| |__/
function CompoPlayer(){
this.active = false;
this.playing = false;
this.paused = false;
this.playlist = [];
this.current_index = 0;
this.$composer = null;
this.$compo = null;
this.$controls = null;
this.init();
};
CompoPlayer.prototype = {
@@ -655,26 +663,30 @@
.on('audio-ended', this.onAudioPlayerEnded.bind(this));
// .on('audio-play-next', this.onAudioPlayNext.bind(this));
// this.newCompo();
},
initControls(){
console.log('CompoPlayer initControls()');
this.$composer = $('.composition_ui .composer');
this.$controls = $('.composition_ui .composer .compo-player-controls');
this.$previous = $('<div>').addClass('previous')
.on('click', this.prev.bind(this))
.appendTo(this.$controls);
this.$playpause = $('<div>').addClass('play-pause')
.on('click', this.togglePlayPause.bind(this))
.appendTo(this.$controls);
this.$next = $('<div>').addClass('next')
.on('click', this.next.bind(this))
.appendTo(this.$controls);
this.active = true; // TODO: set active false
this.newCompo();
},
newCompo(){
console.log('CompoPlayer newCompo()');
// $('.composition_ui .composer .composition .field--name-documents')
this.$composer = $('.composition_ui .composer');
this.$compo = $('.composition_ui .composer .composition');
this.$controls = $('.composition_ui .composer .compo-player-controls');
if(!this.$controls.is('.ready')){
this.$previous = $('<div>').addClass('previous')
.on('click', this.prev.bind(this))
.appendTo(this.$controls);
this.$playpause = $('<div>').addClass('play-pause')
.on('click', this.togglePlayPause.bind(this))
.appendTo(this.$controls);
this.$next = $('<div>').addClass('next')
.on('click', this.next.bind(this))
.appendTo(this.$controls);
this.$controls.addClass('ready');
}
this.refresh();
},
refresh(){
@@ -810,6 +822,10 @@
}
return this;
},
deactivate(){
this.stop();
this.active = false;
},
// _audioPlayer events
onAudioOpenDocument(args){
if(args.caller !== this){
@@ -887,6 +903,7 @@
// TODO: animate the remove
_$row.html('');
_$ajaxLinks.removeClass('is-active');
_$body.trigger({'type':'all-modal-closed'});
};
init();
@@ -45,6 +45,12 @@
function initEvents(){
$('body')
.on('on-studio-chutier-updated', initAjaxLinks)
.on('studio-initialized', function(e){
_compoPlayer.initControls();
})
.on('studio-not-active', function(e){
_compoPlayer.deactivate();
})
.on('on-studio-compo-updated', function(e){
initAjaxLinks();
_compoPlayer.refresh();
@@ -280,7 +286,6 @@
_$body.attr('corpus-map', 'ready');
}
// _ _ _
// /_\ _ _ __| (_)___
// / _ \ || / _` | / _ \
@@ -637,11 +642,14 @@
// \___\___/_|_|_| .__/\___/_| |_\__,_|\_, \___|_|
// |_| |__/
function CompoPlayer(){
this.active = false;
this.playing = false;
this.paused = false;
this.playlist = [];
this.current_index = 0;
this.$composer = null;
this.$compo = null;
this.$controls = null;
this.init();
};
CompoPlayer.prototype = {
@@ -655,26 +663,30 @@
.on('audio-ended', this.onAudioPlayerEnded.bind(this));
// .on('audio-play-next', this.onAudioPlayNext.bind(this));
// this.newCompo();
},
initControls(){
console.log('CompoPlayer initControls()');
this.$composer = $('.composition_ui .composer');
this.$controls = $('.composition_ui .composer .compo-player-controls');
this.$previous = $('<div>').addClass('previous')
.on('click', this.prev.bind(this))
.appendTo(this.$controls);
this.$playpause = $('<div>').addClass('play-pause')
.on('click', this.togglePlayPause.bind(this))
.appendTo(this.$controls);
this.$next = $('<div>').addClass('next')
.on('click', this.next.bind(this))
.appendTo(this.$controls);
this.active = true; // TODO: set active false
this.newCompo();
},
newCompo(){
console.log('CompoPlayer newCompo()');
// $('.composition_ui .composer .composition .field--name-documents')
this.$composer = $('.composition_ui .composer');
this.$compo = $('.composition_ui .composer .composition');
this.$controls = $('.composition_ui .composer .compo-player-controls');
if(!this.$controls.is('.ready')){
this.$previous = $('<div>').addClass('previous')
.on('click', this.prev.bind(this))
.appendTo(this.$controls);
this.$playpause = $('<div>').addClass('play-pause')
.on('click', this.togglePlayPause.bind(this))
.appendTo(this.$controls);
this.$next = $('<div>').addClass('next')
.on('click', this.next.bind(this))
.appendTo(this.$controls);
this.$controls.addClass('ready');
}
this.refresh();
},
refresh(){
@@ -810,6 +822,10 @@
}
return this;
},
deactivate(){
this.stop();
this.active = false;
},
// _audioPlayer events
onAudioOpenDocument(args){
if(args.caller !== this){
@@ -887,6 +903,7 @@
// TODO: animate the remove
_$row.html('');
_$ajaxLinks.removeClass('is-active');
_$body.trigger({'type':'all-modal-closed'});
};
init();