open document on loading close the home

This commit is contained in:
2018-05-03 00:15:35 +02:00
parent 382d1c4ddd
commit 7fe3f9a747
2 changed files with 75 additions and 68 deletions
@@ -20,12 +20,11 @@ $('ul','.block.language-switcher-language-url').replaceWith($links);}
initAjaxLinks();checkVisibleCorpusMapSpace();_$body.trigger({'type':'new-content-ajax-loaded'});Drupal.attachBehaviors(_$row[0]);_$body.attr('booted','booted');_$body.removeClass('ajax-loading');if(state.url){history.pushState(state,null,state.url);if(typeof _paq!=='undefined'){_paq.push(['setCustomUrl',state.url]);_paq.push(['setDocumentTitle',data.title]);_ajax_timing.end=performance.now();_paq.push(['setGenerationTimeMs',_ajax_timing.end-_ajax_timing.start]);_paq.push(['trackPageView']);}}};function initAudioLinksInContent(){_$row.find('a.audio-link').on('mouseover',function(event){event.preventDefault();if(_corpus_ready){_$corpus_canvas.trigger({type:'mouseover-audio-link',nid:$(this).attr('nid')});}}).on('mouseout',function(event){event.preventDefault();if(_corpus_ready){_$corpus_canvas.trigger({type:'mouseout-audio-link',nid:$(this).attr('nid')});}});};function addCloseModalBtnToCols(){$('.col',_$row).each(function(index,el){if($('span.close-col-btn',this).length)
return true;$(this).children('.wrapper').prepend($('<span>').addClass('close-col-btn').on('click',onCloseModal));});};function onCloseModal(e){var $col=$(this).parents('.col');var theme=$col.attr('theme');if(theme!=''){_$body.trigger({'type':theme+'-col-closed'});}
if(_$body.is('.entity-type-node.bundle-page')){$col.add($col.siblings('.col')).remove();}else{$col.remove();}
checkRowEmpty();checkVisibleCorpusMapSpace();};function initHistory(){initFirstLoad();window.addEventListener('popstate',onHistoryPopState);};function initFirstLoad(){void 0;void 0;var edlp_origin=JSON.parse(window.localStorage.getItem('edlp_origin'));void 0;if(edlp_origin!=null&&edlp_origin.sys_path){var hash=edlp_origin.hash.replace('#','');if(hash!="random"){var state=getSysPathState(edlp_origin.sys_path,hash);if(edlp_origin.entity_type=="taxonomy_term"&&edlp_origin.entity_bundle=="entrees"&&hash){state.selector='entree-'+hash+'-link-'+edlp_origin.entity_id;if(_corpus_ready){_$corpus_canvas.trigger({type:'open-entree',tid:edlp_origin.entity_id});}else{$('li.entree[tid="'+edlp_origin.entity_id+'"] a.term-link').addClass('is-active');}}
if(edlp_origin.audio_url){var node={nid:edlp_origin.entity_id,audio_url:edlp_origin.audio_url};_audioPlayer.openDocument(node,'history_first_load');if(hash==""){state.audio=true;state.node=node;_$body.attr('booted','booted');}else{ajaxLoadContent(state);}}
checkRowEmpty();checkVisibleCorpusMapSpace();};function initHistory(){initFirstLoad();window.addEventListener('popstate',onHistoryPopState);};function initFirstLoad(){void 0;void 0;var edlp_origin=JSON.parse(window.localStorage.getItem('edlp_origin'));void 0;if(edlp_origin!=null&&edlp_origin.sys_path){var hash=edlp_origin.hash.replace('#','');var state=getSysPathState(edlp_origin.sys_path,hash);if(edlp_origin.entity_type=="taxonomy_term"&&edlp_origin.entity_bundle=="entrees"&&hash){state.selector='entree-'+hash+'-link-'+edlp_origin.entity_id;if(_corpus_ready){_$corpus_canvas.trigger({type:'open-entree',tid:edlp_origin.entity_id});}else{$('li.entree[tid="'+edlp_origin.entity_id+'"] a.term-link').addClass('is-active');}}
if(edlp_origin.audio_url){var node={nid:edlp_origin.entity_id,audio_url:edlp_origin.audio_url};_audioPlayer.openDocument(node,'history_first_load');closeAllModals();if(hash==""||hash=='random'){state.audio=true;state.node=node;_$body.attr('booted','booted');}else{ajaxLoadContent(state);}}
else if(state.ajax_path){ajaxLoadContent(state);}
if(state.entree_tid){openEntree(state.entree_tid);}
history.replaceState(state,null,edlp_origin.url+edlp_origin.hash);}
window.localStorage.removeItem("edlp_origin");}else{history.replaceState({home:true},null,window.location.pathname+window.location.hash);initGrid();_$body.attr('booted','booted');}};function onHistoryPopState(e){void 0;if(e.state.home){backToFrontPage(true);}
history.replaceState(state,null,edlp_origin.url+edlp_origin.hash);window.localStorage.removeItem("edlp_origin");}else{history.replaceState({home:true},null,window.location.pathname+window.location.hash);initGrid();_$body.attr('booted','booted');}};function onHistoryPopState(e){void 0;if(e.state.home){backToFrontPage(true);}
else if(e.state.audio){_audioPlayer.openDocument(e.state.node,'popstate',e.state.historic_index);}
else{if(e.state.entree_tid){openEntree(e.state.entree_tid);}
if(e.state.ajax_path){e.state.url=null;ajaxLoadContent(e.state);}}};function initAjaxLinks(){$('a.site-name','#block-edlptheme-branding').add('a','#block-mainnavigation').add('a','#block-footer.menu--footer').add('a','#block-productions').add('a','article.node:not(.node--type-enregistrement) h2.node-title').add('a','.productions-subtree').add('a','.productions-parent').add('a','.field--name-field-son').addClass('ajax-link');$('a[data-drupal-link-system-path="<front>"]','#block-mainnavigation').removeClass('is-active');_$ajaxLinks=$('.ajax-link:not(.ajax-enabled)').each(function(i,e){var $this=$(this);if($this.is('.ajax-enable'))return;if($this.attr('data-drupal-link-system-path')||$this.is('[type^="audio"]')){$this.on('click',onClickAjaxLink).addClass('ajax-enable');}});};function onClickAjaxLink(e){e.preventDefault();var $link=$(this);if($link.is('.is-active'))
@@ -39,7 +38,7 @@ function openEntree(tid){if(tid){closeAllModals();_$body.removeClass();if(_corpu
this.$previous.on('click',this.playPrevious.bind(this));this.$playpause.on('click',this.togglePlayPause.bind(this));this.$next.on('click',this.playNext.bind(this));},openDocument(node,caller,historic_index){void 0;if(typeof node=='undefined'||typeof node.nid=='undefined'||typeof node.audio_url=='undefined'){void 0;return false;}
if(typeof caller=='undefined'||caller!='popstate'){this.historic.push(node);this.currentHistoricIndex=this.historic.length-1;if(caller!="history_first_load"){if(typeof node.document_url=='undefined'){void 0;}else{var state={audio:true,node:{nid:node.nid,audio_url:node.audio_url,document_url:node.document_url,title:node.title||null,},historic_index:this.currentHistoricIndex,};var url=node.document_url+(caller=='random'?'#random':'');history.pushState(state,null,url);}}}else{this.currentHistoricIndex=historic_index;}
this.emmit('audio-open-document',{caller:caller});if(typeof _paq!=='undefined'){if(typeof node.title!='undefined'){_paq.push(['trackEvent','Audio','play',node.title]);}}
this.launch();},launch(){this.clearTimeOutToHide();this.setSRC(this.historic[this.currentHistoricIndex].audio_url);this.loadNode(this.historic[this.currentHistoricIndex].nid);try{_$corpus_canvas.trigger({'type':'audio-node-opened','nid':this.historic[this.currentHistoricIndex].nid});}catch(e){void 0;}
this.launch();},launch(){this.clearTimeOutToHide();this.setSRC(this.historic[this.currentHistoricIndex].audio_url);this.loadNode(this.historic[this.currentHistoricIndex].nid);try{_$corpus_canvas.trigger({'type':'audio-node-opened','nid':this.historic[this.currentHistoricIndex].nid});}catch(e){void 0;var that=this;_corpus_promise.done(function(){_$corpus_canvas.trigger({'type':'audio-node-opened','nid':that.historic[that.currentHistoricIndex].nid});});}
this.showHidePreviousBtn();this.showHideNextBtn();this.show();},openSound(url,title){this.hide();this.clearTimeOutToHide();this.$cartel.html("");this.setSRC(url);this.show();if(typeof _paq!=='undefined'){_paq.push(['trackEvent','Audio','play',url]);}},setSRC(url){void 0;this.audio.src=url;this.play();},onLoadedmetadata(){var rem=parseInt(this.audio.duration,10),mins=Math.floor(rem/60,10),secs=rem-mins*60;this.$duration.html('<span>'+(mins<10?'0':'')+mins+':'+(secs<10?'0':'')+secs+'</span>');this.updateLoadingBar();},updateLoadingBar(){void 0;if(this.audio.buffered.length>0){this.$loader.css({'width':parseInt((100*this.audio.buffered.end(0)/this.audio.duration),10)+'%'});if(this.audio.buffered.end(0)<this.audio.duration){window.requestAnimationFrame(this.updateLoadingBar.bind(this));}else{void 0;}}else{window.requestAnimationFrame(this.updateLoadingBar.bind(this));}},onError(){void 0;},play(){this.clearTimeOutToHide();var promise=this.audio.play();if(promise!==undefined){promise.catch(function(error){void 0;}).then(function(){void 0;});}},playPrevious(){if(this.currentHistoricIndex>0){this.currentHistoricIndex-=1;this.launch();}},playNext(){if(this.currentHistoricIndex<this.historic.length-1){this.currentHistoricIndex+=1;this.launch();}else{this.emmit('audio-play-next');}},togglePlayPause(e){if(this.audio.paused){this.play();}else{this.stop();}},stop(){this.audio.pause();if(!(_$body.is('.path-node-'+this.historic[this.currentHistoricIndex].nid)&&(_$body.is('.view-mode-article')||_$body.is('.view-mode-transcript')))){this.timeOutToHide();}},onPlaying(){this.$btns.addClass('is-playing');this.emmit('audio-play');},onPause(){this.$btns.removeClass('is-playing');this.emmit('audio-pause');},onTimeupdate(){this.$cursor.css({'left':(this.audio.currentTime/this.audio.duration*this.timeline_w)+"px"});var rem=parseInt(this.audio.currentTime,10),mins=Math.floor(rem/60,10),secs=rem-mins*60;this.$currentTime.html('<span>'+(mins<10?'0':'')+mins+':'+(secs<10?'0':'')+secs+'</span>');},onEnded(){void 0;this.stop();this.emmit('audio-ended');},loadNode(nid){this.$cartel.addClass('loading');var vm='player_cartel';var ajax_path=_ajax_settings.entityjson_path+'/node/'+nid+'/'+vm;var path=window.location.origin+Drupal.url(ajax_path);$.getJSON(path,{}).done(this.onNodeLoaded.bind(this)).fail(this.onNodeLoadFail.bind(this));},onNodeLoaded(data){this.$cartel.html(data.rendered).removeClass('loading');_$body.trigger({'type':'new-audio-cartel-loaded'});initAjaxLinks();if(this.auto_open_article){this.$cartel.find('a.link-article').trigger('click');this.auto_open_article=false;}},onNodeLoadFail(jqxhr,textStatus,error){void 0;this.$cartel.removeClass('loading').html('');},setAutoOpenArticle(art){this.auto_open_article=art;return this;},show(){this.$container_parent.addClass('audio-player-visible');this.$container.addClass('visible');},showHidePreviousBtn(){if(this.historic.length>1&&this.currentHistoricIndex>0){this.$previous.addClass('is-active');}else{this.$previous.removeClass('is-active');}},showHideNextBtn(){if(this.currentHistoricIndex<this.historic.length-1||this.shuffle_is_active){this.$next.addClass('is-active');}else{this.$next.removeClass('is-active');}},timeOutToHide(){this.clearTimeOutToHide();this.hideTimer=setTimeout(this.hide.bind(this),this.hideTimeMS);},clearTimeOutToHide(){if(this.hideTimer){clearTimeout(this.hideTimer);this.hideTimer=false;}},hide(){this.$container_parent.removeClass('audio-player-visible');this.$container.removeClass('visible');try{_$corpus_canvas.trigger('audio-node-closed');}catch(e){void 0;}},deActivateRandom(){this.shuffle_is_active=false;this.showHideNextBtn();},on(event_name,handler){if(typeof this.event_handlers[event_name]=='undefined'){void 0;}
this.event_handlers[event_name].push(handler);return this;},emmit(event_name,args){void 0;var handler;var args=args||{};for(var i=this.event_handlers[event_name].length-1;i>=0;i--){handler=this.event_handlers[event_name][i];(function(handler,args){setTimeout(function(){handler(args);},0);}(handler,args));}
return this;},}
@@ -534,75 +534,75 @@
// and for audio contents (article|transcript)
var hash = edlp_origin.hash.replace('#', '');
// if hash is random, RandomPlayer will be started when playlist sent by corpus.js
if(hash != "random"){
// create history state
var state = getSysPathState(edlp_origin.sys_path, hash);
// create history state
var state = getSysPathState(edlp_origin.sys_path, hash);
// open entree tray in case of entree index|notice
// (index or notice will be opened with ajaxLoadContent)
// refactorized with new infos from edlp_origin
// if(hash){
if(edlp_origin.entity_type == "taxonomy_term"
&& edlp_origin.entity_bundle == "entrees"
&& hash){
// var $link = $('[href="'+edlp_origin.url+'"][viewmode="'+hash+'"]');
// var selector = $link.attr('selector') || null;
// open entree tray in case of entree index|notice
// (index or notice will be opened with ajaxLoadContent)
// refactorized with new infos from edlp_origin
// if(hash){
if(edlp_origin.entity_type == "taxonomy_term"
&& edlp_origin.entity_bundle == "entrees"
&& hash){
// var $link = $('[href="'+edlp_origin.url+'"][viewmode="'+hash+'"]');
// var selector = $link.attr('selector') || null;
// record the selector in the state for actions after ajaxContentLoaded
state.selector = 'entree-'+hash+'-link-'+edlp_origin.entity_id; // entree-index-link-125
// if(selector){
// in case of entree link (actualy, selector is used only for entries links)
// TODO: use a promise
// TODO: but what if corpus ready before onAjaxLoaded >> use a promise !!
if(_corpus_ready){
_$corpus_canvas.trigger({
type:'open-entree',
// tid:$link.attr('tid')
tid:edlp_origin.entity_id
});
}else{
// else : EdlpCorpus will check when ready if entry item (notice or index) is already .is-active
// .is-active class is added by onAjaxLoaded() (when content is loaded)
// $('li.entree[tid="'+$link.attr('tid')+'"] a.term-link').addClass('is-active');
$('li.entree[tid="'+edlp_origin.entity_id+'"] a.term-link').addClass('is-active');
}
// }
}
// check if audio link
// only if not random link
if(edlp_origin.audio_url){
var node = {
nid:edlp_origin.entity_id,
audio_url:edlp_origin.audio_url
};
_audioPlayer.openDocument(node, 'history_first_load');
if(hash == ""){
// if audio only record in state
state.audio = true;
state.node = node;
// we don't laod ajax content so we boot the home
_$body.attr('booted', 'booted');
// record the selector in the state for actions after ajaxContentLoaded
state.selector = 'entree-'+hash+'-link-'+edlp_origin.entity_id; // entree-index-link-125
// if(selector){
// in case of entree link (actualy, selector is used only for entries links)
// TODO: use a promise
// TODO: but what if corpus ready before onAjaxLoaded >> use a promise !!
if(_corpus_ready){
_$corpus_canvas.trigger({
type:'open-entree',
// tid:$link.attr('tid')
tid:edlp_origin.entity_id
});
}else{
// ajax load content for audio only if article or transcript
ajaxLoadContent(state);
// else : EdlpCorpus will check when ready if entry item (notice or index) is already .is-active
// .is-active class is added by onAjaxLoaded() (when content is loaded)
// $('li.entree[tid="'+$link.attr('tid')+'"] a.term-link').addClass('is-active');
$('li.entree[tid="'+edlp_origin.entity_id+'"] a.term-link').addClass('is-active');
}
}
// only if not entree path
// only if not audio (without article or transcript) path
else if(state.ajax_path){
// load content through ajax
// ajaxLoadContent(null, state.sys_path, state.ajax_path, selector);
// }
}
// check if audio link
// only if not random link
if(edlp_origin.audio_url){
var node = {
nid:edlp_origin.entity_id,
audio_url:edlp_origin.audio_url
};
_audioPlayer.openDocument(node, 'history_first_load');
// close home
closeAllModals();
if(hash == "" || hash == 'random'){
// if hash is random, RandomPlayer will be started when playlist sent by corpus.js
// if audio only record in state
state.audio = true;
state.node = node;
// we don't laod ajax content so we boot the home
_$body.attr('booted', 'booted');
}else{
// ajax load content for audio only if article or transcript
ajaxLoadContent(state);
}
if(state.entree_tid){
openEntree(state.entree_tid);
}
// record history state
history.replaceState(state, null, edlp_origin.url+edlp_origin.hash);
}
// only if not entree path
// only if not audio (without article or transcript) path
else if(state.ajax_path){
// load content through ajax
// ajaxLoadContent(null, state.sys_path, state.ajax_path, selector);
ajaxLoadContent(state);
}
if(state.entree_tid){
openEntree(state.entree_tid);
}
// record history state
history.replaceState(state, null, edlp_origin.url+edlp_origin.hash);
// reset the storage
window.localStorage.removeItem("edlp_origin");
@@ -976,7 +976,15 @@
'nid':this.historic[this.currentHistoricIndex].nid
});
} catch (e) {
console.info('AudioPlayer : _$corpus_canvas does not exists');
console.info('AudioPlayer : _$corpus_canvas does not exists, testing promise');
var that = this;
_corpus_promise.done(function(){
_$corpus_canvas.trigger({
'type':'audio-node-opened',
'nid':that.historic[that.currentHistoricIndex].nid
});
});
}
this.showHidePreviousBtn();