12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369 |
- (function($, Drupal, drupalSettings) {
- EdlpTheme = function(){
- var _origin = window.location.origin;
- var _base_url = drupalSettings.path.baseUrl;
- var _ajax_settings = drupalSettings.edlp_ajax;
- var _$body = $('body');
-
- var _corpus_ready = false;
- var _$corpus_canvas;
- var _$row = $('main[role="main"]>.layout-content>.row');
- var _$ajaxLinks;
- var _audioPlayer;
- var _randomPlayer;
- var _compoPlayer;
- var _ajax_timing = {
- start:0,
- end:0
- };
- var _corpus_promise;
- var _is_mobile = edlp_mobile.device_is_mobile;
- var _is_loggedin = drupalSettings.user.uid === 0 ? false : true;
- var _$log_form;
- var _user_tokens;
- var _states_history = [];
- var _is_expo = $('body').hasClass('domain-expo-encyclopediedelaparole-org');
-
-
-
-
- function init(){
- console.log("EdlpTheme init()");
- if (!_is_loggedin) {
- initLogForm();
- }
- if(_is_mobile){
- initMobile();
- }else if(drupalSettings.path.isFront){
- initDesktopHome();
- }
- initEvents();
- _audioPlayer = new AudioPlayer();
- _compoPlayer = new CompoPlayer();
- initAjaxLinks();
- initHistory();
- if(!_is_mobile){
- checkLayout();
- initAudioLinksHover();
- }
- if(_is_mobile){
- if(drupalSettings.path.isFront){
- initHomeMobile();
- }
- _$body.attr('booted', 'booted');
- }
- };
-
-
-
-
-
- function initLogForm(){
- console.log('initLogForm');
- _$log_form = $('#user-login-form:not(ajax-enebled)')
- .on('submit', onSubmitLogForm)
- .addClass('ajax-enabled');
- };
- function onSubmitLogForm(e){
- e.preventDefault();
-
- var args = {
- name : $('input#edit-name[type="text"]', this).val(),
- pass : $('input#edit-pass[type="password"]', this).val()
- };
-
- logIn(args).then(logedin);
- return false;
- };
- function logIn(args){
- console.log('logIn', args);
- _$log_form.addClass('ajax-loading');
- _$body.addClass('ajax-loading');
- return $.ajax({
- type: 'POST',
- headers: {'Content-Type': 'application/json'},
- xhrFields: {
- withCredentials: true
- },
-
- url: _origin+_base_url+"user/login?_format=json",
- data: JSON.stringify(args),
-
-
- success: function(response){
-
- _user_tokens = response;
- },
- error: function (xhr, ajaxOptions, thrownError){
- console.log(xhr.status);
- console.log(thrownError);
- }
- });
- };
- function logedin(){
- $('body').addClass('user-logged-in');
- getStudioLinkBlock();
- };
- function getStudioLinkBlock(){
- var path = _origin+_base_url+'edlp/ajax/blocks/json/';
- $.getJSON(path+"studiolinkblock", {})
- .done(onStudioLinkBlockLoaded)
- .fail(function(jqxhr, textStatus, error){
- console.warn('Studio ink block load failed', jqxhr.responseText);
- });
- };
- function onStudioLinkBlockLoaded(data){
- console.log('onStudioLinkBlockLoaded', data);
- $('#block-studiouserlogin').replaceWith(data.blocks.studiolinkblock.rendered);
- initAjaxLinks();
- refreshFavoritesLinks();
- _$log_form.removeClass('ajax-loading');
- _$body.removeClass('ajax-loading');
- }
-
-
-
-
- function initMobile(){
- console.log('initMobile');
-
-
-
-
-
-
- $('h2, a', '#block-mainnavigation')
- .add('h2, a', '#block-mainnavigation-2')
- .on('click', onclickHomeMobileMenu);
- }
- function onclickHomeMobileMenu(e){
-
- $('#block-mainnavigation-2').toggleClass('opened');
- };
- function initHomeMobile(){
-
-
-
-
-
-
-
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- function initDesktopHome(){
- console.log('initDesktopHome');
-
- var $prods = $('.grid .col .node--type-page');
- $r = Math.floor(Math.random() * $prods.length)
- $prods.each(function(index) {
- if(index != $r){
- $(this).parents('.col').remove();
- }
- });
- console.log('$prods', $prods);
- }
-
-
-
-
- function initEvents(){
-
- var $corpus_df = $.Deferred();
- _corpus_promise = $corpus_df.promise();
- _$body
- .on('corpus-map-ready', function(e){
- onCorpusMapReady(e);
- $corpus_df.resolve();
- })
- .on('on-studio-chutier-updated', initAjaxLinks)
- .on('studio-initialized', function(e){
- _compoPlayer.newCompo();
- })
- .on('studio-not-active', function(e){
- _compoPlayer.deactivate();
- })
- .on('on-studio-compo-updated', function(e){
- initAjaxLinks();
- _compoPlayer.refresh();
- })
- .on('on-studio-compo-opened', function(e){
- initAjaxLinks();
- _compoPlayer.newCompo();
- })
- .on('search-results-loaded', function(e){
- initAjaxLinks();
- initAudioLinksHover();
- checkVisibleCorpusMapSpace();
- })
-
- .on('open_entree', function(e){
- console.log('on_open_entree : e', e);
- closeAllModals();
- checkLayout();
-
-
-
-
-
-
-
- _$body.removeClass();
-
- if(typeof e.url != 'undefined'){
- var state = getSysPathState(e.sys_path);
- history.pushState(state, null, e.url);
-
- if(typeof _paq !== 'undefined'){
-
-
- _paq.push(['setCustomUrl', e.url]);
- _paq.push(['setDocumentTitle', e.title]);
- _paq.push(['trackPageView']);
- }
- }
- })
- .on('close_entree', function(e){
- backToFrontPage();
- checkLayout();
- });
- window.addEventListener('resize', checkLayout, false);
- }
-
-
-
-
- function checkLayout(){
- var $audioplayer = $("#audio-player");
- if($audioplayer.length){
- var navpos = $('#block-mainnavigation').position();
-
- if(typeof navpos != 'undefined'){
- $audioplayer.css({
- 'width':navpos.left+'px'
- });
- }
- }
- checkGridBlockHeight();
- checkGridBlockVisible();
-
-
- };
-
-
-
-
- function initScrollbars(){
-
-
-
-
-
-
-
-
-
- };
-
-
-
-
-
- function getSysPathState(sys_path, view_mode){
-
- var state = {
- 'sys_path':sys_path,
- 'ajax_path': sys_path
- };
-
- var node_match = state.ajax_path.match(/^\/?(node\/(\d+))$/i);
- console.log('node_match', node_match);
- var term_match = state.ajax_path.match(/^\/?(taxonomy\/term\/(\d+))$/i);
- console.log('term_match', term_match);
- if(node_match){
-
- state.ajax_path = _ajax_settings.entityjson_path+'/'+node_match[1];
- state.node_nid = node_match[2];
-
- if(view_mode){
- state.ajax_path += '/'+view_mode;
- state.view_mode = view_mode;
- }
- }else if(term_match){
-
- state.ajax_path = _ajax_settings.entityjson_path+'/'+term_match[1];
- state.ajax_path = state.ajax_path.replace(/taxonomy\/term/, 'taxonomy_term');
- state.entree_tid = term_match[2];
-
- if(view_mode){
- state.ajax_path += '/'+view_mode;
- state.view_mode = view_mode;
- }else{
- state.ajax_path = null;
- }
- }else{
-
-
- state.ajax_path += '/ajax'
- }
- return state;
- };
- function ajaxLoadContent(state){
- console.log('ajaxLoadContent : state', state);
- _$body.addClass('ajax-loading');
- _ajax_timing.start = performance.now();
- var path = _origin + Drupal.url(state.ajax_path);
- $.getJSON(path, {})
- .done(function(data){
- onAjaxLoaded(data, state);
- })
- .fail(function(jqxhr, textStatus, error){
- onAjaxLoadError(jqxhr, textStatus, error, state.sys_path);
- });
- };
- function onAjaxLoadError(jqxhr, textStatus, error, sys_path){
- console.warn('ajaxlink load failed for '+sys_path+' : '+error, jqxhr.responseText);
- $('.ajax-loading').removeClass('ajax-loading');
- _$body.removeClass('ajax-loading');
- };
- function onAjaxLoaded(data, state){
- console.log('ajax loaded', state, data);
- var $rendered = $(data.rendered);
- $rendered.attr({
- 'sys_path':state.sys_path,
- 'view_mode': state.view_mode
- });
-
-
-
-
- if(data.entity_type == "node" && data.bundle == "evenement"){
- if(_$row.find('.col.event').length){
- _$row.find('.col.event').replaceWith($rendered);
- }else if(_$row.find('.col.aside').length){
- _$row.find('.col.aside').replaceWith($rendered);
- }else{
- _$row.append($rendered);
- }
- }
- else if(
- (state.context == 'document-transcript' || state.context == 'document-artcile')
- && state.caller == "search"
- ){
- _$row.append($rendered);
- }
- else{
- _$row.removeAttr('style').html($rendered);
- }
-
- if ((data.entity_type == "node" && data.bundle == "static")
- || state.sys_path == "docsindex") {
- $('.ajax-link.is-active.articles-link').removeClass('is-active');
- }
-
- var body_classes = [
- 'path-'+state.sys_path.replace(/\//g, '-'),
- 'entity-type-'+data.entity_type,
- 'bundle-'+data.bundle,
- 'view-mode-'+data.view_mode
- ];
- _$body.removeClass().addClass(body_classes.join(' '));
-
-
-
- if(state.node_nid)
- _$body.addClass('path-edlp-node');
-
- $('.ajax-loading').removeClass('ajax-loading');
- $('.ajax-link.is-active:not(.articles-link)').removeClass('is-active');
- $('.is-active-trail').removeClass('is-active-trail');
- if(typeof state.selector != 'undefined'){
-
-
- console.log('selector', state.selector);
- $('a[selector="'+state.selector+'"]').addClass('is-active');
- initAudioLinksHover();
- }else{
- if(typeof state.view_mode != 'undefined'){
- $('a[viewmode="'+state.view_mode+'"][data-drupal-link-system-path="'+state.sys_path+'"]').addClass('is-active');
- }else{
-
- _corpus_promise.done(function(){
- $('a[data-drupal-link-system-path="'+state.sys_path+'"]').addClass('is-active');
- });
- }
-
- _$body.trigger({'type':'new-content-not-entree-ajax-loaded'});
- }
-
- if (typeof data.bundle != 'undefined' && data.bundle == "page") {
- $('a[data-drupal-link-system-path="productions"]').addClass('is-active-trail');
- }
-
- if (typeof data.menu_parents != 'undefined') {
- for (var i = 0; i < data.menu_parents.length; i++) {
- var menu_sys_path = data.menu_parents[i];
- $('a[data-drupal-link-system-path="'+menu_sys_path+'"]').addClass('is-active-trail');
- }
- }
-
- if(typeof data.documents_lies != 'undefined'){
- if(_corpus_ready){
- _$body.trigger({
- type:'ajax-node-loaded-linked-documents',
- nids:data.documents_lies
- });
- }else{
- _corpus_promise.done(function(){
- _$body.trigger({
- type:'ajax-node-loaded-linked-documents',
- nids:data.documents_lies
- });
- });
- }
- }
-
-
- if(typeof data.block != 'undefined'){
-
- if(!$('#'+data.block.id, '.region-'+data.block.region).length){
- $('.region-'+data.block.region).append(data.block.rendered);
- }
- }
-
- if(state.sys_path == "productions"){
-
- initGrid();
- }else{
- addCloseModalBtnToCols();
- }
- if(state.sys_path == "collection"){
-
- initCollectionNav();
- }
-
- if(data.entity_type == "node" && data.bundle == "enregistrement" && data.view_mode == "transcript"){
-
- initEnregistrementTranscript();
- }
- if(state.sys_path == "search"){
- initSearch();
- }
-
- if(typeof data.translations_links != 'undefined'){
- console.log('state',state);
- var lang_code = drupalSettings.path.currentLanguage;
- var $links = $(data.translations_links);
-
- $links.find('li[hreflang="'+lang_code+'"]').addClass('is-active').find('a').addClass('is-active');
- if(state.view_mode){
- $links.find('a').each(function(i,e){
- var $a = $(this);
- $a.attr('href', $a.attr('href')+'#'+state.view_mode);
- });
- }
-
-
-
- $('ul','.block.language-switcher-language-url').replaceWith($links);
- }
- initAjaxLinks();
- initAudioLinksHover();
- checkVisibleCorpusMapSpace();
-
- _$body.trigger({'type':'new-content-ajax-loaded'});
-
- Drupal.attachBehaviors(_$row[0]);
- _$body.attr('booted', 'booted');
- _$body.removeClass('ajax-loading');
-
- _states_history.unshift(state);
-
-
- 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 initAudioLinksHover(){
- console.log("initAudioLinksHover()");
- _$row.find('a.audio-link')
- .not('article.node--view-mode-docsindex 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(){
- if(_is_mobile) return;
- $('.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){
- console.log("onCloseModal");
-
- console.log("onCloseModal _states_history",_states_history);
- if(['document-transcript', 'document-article'].indexOf(_states_history[0].context) != -1)
- {
- if (_states_history[0].caller == "production") {
- for (var i = 0; i < _states_history.length; i++) {
- if (_states_history[i].context == "production") {
-
- console.log("onCloseModal return to production", _states_history[i]);
- ajaxLoadContent(_states_history[i]);
- return;
- }
- }
- }
- if (_states_history[0].caller == "entree-index") {
- for (var i = 0; i < _states_history.length; i++) {
- if (_states_history[i].context == "entree-index") {
- console.log("onCloseModal return to entree-index", _states_history[i]);
- ajaxLoadContent(_states_history[i]);
- return;
- }
- }
- }
- if (_states_history[0].caller == "entree-notice") {
- for (var i = 0; i < _states_history.length; i++) {
- if (_states_history[i].context == "entree-notice") {
- console.log("onCloseModal return to entree-notice", _states_history[i]);
- ajaxLoadContent(_states_history[i]);
- return;
- }
- }
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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') && $(this).next().is('.node--type-page')){
-
-
- $col.add($col.siblings('.col')).remove();
- }else{
-
- $col.remove();
- }
- checkRowEmpty();
- checkVisibleCorpusMapSpace();
-
- if( $col.attr('view_mode') && $col.attr('sys_path')){
- $('a[data-drupal-link-system-path="'+$col.attr('sys_path')+'"][viewmode="'+$col.attr('view_mode')+'"]').removeClass('is-active');
- }
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- function initHistory(){
- initFirstLoad();
- window.addEventListener('popstate', onHistoryPopState);
- };
- function initFirstLoad(){
- console.log('theme : initFirstLoad()');
- console.log('window.location', window.location);
-
- var edlp_origin = JSON.parse(window.localStorage.getItem('edlp_origin'));
- console.log('edlp_origin', edlp_origin);
- if(edlp_origin != null && edlp_origin.sys_path){
-
-
- var hash = edlp_origin.hash.replace('#', '');
-
- var state = getSysPathState(edlp_origin.sys_path, hash);
-
- state.historic_index = 0;
-
-
-
-
- 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'){
- console.log('first load hash', hash);
-
-
- state.audio = true;
- state.node = node;
- if(!_is_mobile){
-
- _$body.attr('booted', 'booted');
- }else{
- ajaxLoadContent(state);
- }
- }else{
- console.log('first load load content');
-
- 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){
- console.log('onHistoryPopState',e.state);
- if(e.state.home){
- backToFrontPage(true);
- }
- else if (e.state.audio) {
- console.log('popstate audio : e.state', e.state);
- _audioPlayer.openDocument(e.state.node, 'popstate', e.state.historic_index);
- if(_is_mobile){
- ajaxLoadContent(e.state)
- }
- }
- 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', '#block-mainnavigation')
- .add('a', '#block-mainnavigation-2')
-
- .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');
- if(!_is_mobile){
- $('a.site-name', '#block-edlptheme-branding').addClass('ajax-link');
- }
- _$ajaxLinks = $('.ajax-link');
- activateAjaxLinks();
- };
- function activateAjaxLinks(){
-
- _$ajaxLinks.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') && !$link.is('.site-name'))
- return false;
-
-
- if($link.is('.audio-link')){
-
- caller = $link.parents('.lastdocs, .lastdocs-home').length ? 'lastdocs' : null;
-
- if(!caller){
- caller = $link.parents('.composition_ui').length ? 'studio-compo' : null;
- }
-
- if(caller == 'studio-compo'){
- var index = $link.parents('.field__item').index();
- console.log('audio link caller', caller, index);
-
- _compoPlayer.start(index);
- }else{
- _audioPlayer
- .emmit('stop-shuffle')
- .openDocument({
- nid:$link.attr('nid'),
- audio_url:$link.attr('audio_url'),
- title:$link.find('.field--name-title').html()
- },
- caller);
- }
- return false;
- }
-
- if($link.is('[type^="audio"]')){
- _audioPlayer
- .emmit('stop-shuffle')
- .openSound($link.attr('href'), $link.html());
- return false;
- }
-
-
-
-
-
-
-
-
-
- var sys_path = $(this).attr('data-drupal-link-system-path');
-
-
- if(sys_path == '<front>'){
- if(!_is_mobile){
- if($link.is('.is-active') && _corpus_ready){
- _$corpus_canvas.trigger({'type':'shuffle-collection'});
- }else{
- backToFrontPage();
- }
- return false;
- }
-
-
-
- }
- var view_mode = $link.attr('viewmode');
- var state = getSysPathState(sys_path, view_mode);
- state.url = $(this).attr('href');
- if(view_mode){
- state.url += "#"+view_mode;
- }
-
-
- var contexts = /^.*\/(productions|documents|entrees|search)(\/.*)?/g.exec(state.url);
- console.log("onClickAjaxLink contexts", contexts);
- if(contexts){
- switch (contexts[1]) {
- case 'productions':
-
-
- state.context = "production"
-
-
-
- break;
- case 'entrees':
- switch(view_mode) {
- case 'index':
- state.context = "entree-index";
- break;
- case 'notice':
- state.context = "entree-notice";
- break;
- }
- break;
- case 'search':
- state.context = "search";
- break;
- case 'documents':
-
- switch (view_mode) {
- case 'transcript':
- state.context = "document-transcript";
- break;
- case 'article':
- state.context = "document-article";
- break;
- default:
- state.context = "document";
- }
-
- if(typeof _states_history[0] != "undefined"){
- if(_states_history[0].caller){
- state.caller = _states_history[0].caller
- }else{
- state.caller = _states_history[0].context
- }
- }else{
- state.caller = null;
- }
- break;
- }
- }else{
- state.context = null;
-
- }
- if($link.is('[selector]')){
- state.selector = $link.attr('selector');
- }
- $link.addClass('ajax-loading');
-
- ajaxLoadContent(state);
- return false;
- };
- function refreshFavoritesLinks(){
- console.log("refreshFavoritesLinks", _states_history);
-
- _audioPlayer.reloadNode();
-
- if(_states_history[0].view_mode == 'index' || _states_history[0].sys_path == "docsindex"){
- ajaxLoadContent(_states_history[0]);
- }
- }
-
-
-
-
-
- function onCorpusMapReady(e){
-
- _corpus_ready = true;
- _$corpus_canvas = $('canvas#corpus-map');
- _$corpus_canvas
- .on('corpus-cliked-on-map', function(e) {
-
- backToFrontPage();
- })
- .on('corpus-cliked-on-node', function(e) {
-
- _audioPlayer
- .emmit('stop-shuffle')
-
- .openDocument(e.target_node);
- });
- _randomPlayer = new RandomPlayer(e.playlist);
- if (_is_expo) {
- initExpo();
- }
-
- initAjaxLinks();
- _$body.attr('corpus-map', 'ready');
- }
- function openEntree(tid){
- if(tid){
- closeAllModals();
- _$body.removeClass();
-
- if(_corpus_ready){
- _$corpus_canvas.trigger({
- type:'open-entree',
- tid:tid
- });
- }else{
-
- $('li.entree[tid="'+tid+'"] a.term-link').addClass('is-active');
- }
- }
- };
- function checkVisibleCorpusMapSpace(){
- var left_limit = 0, right_limit = 0;
- _$row.find('.col').each(function(i,e){
- var $col = $(this);
- var offset = $col.offset();
- console.log('$col', $col);
- switch(true){
- case $col.is('.float-right'):
- right_limit = Math.max(right_limit, Math.abs(offset.left-15-window.innerWidth));
- break;
- default:
- left_limit = Math.max(left_limit, offset.left+$col.width()+15);
- break;
- }
- });
- console.log('checkVisibleCorpusMapSpace left_limit:'+left_limit+" right_limit:"+right_limit);
- if(_corpus_ready){
- _$body.trigger({
- type:'visible-space-changed',
- left_limit:left_limit,
- right_limit:right_limit
- });
- }else{
- _corpus_promise.done(function(){
- _$body.trigger({
- type:'visible-space-changed',
- left_limit:left_limit,
- right_limit:right_limit
- });
- });
- }
- };
-
-
-
-
-
-
-
-
- function AudioPlayer(){
- var that = this;
- this.fid;
- this.audio = new Audio();
-
- this.audio_events = ["loadedmetadata","playing","pause","timeupdate","ended","error"];
-
- this.$container = $('<div id="audio-player">');
-
- this.$btns = $('<div>').addClass('btns').appendTo(this.$container);
- this.$previous = $('<div>').addClass('previous').appendTo(this.$btns);
- this.$playpause = $('<div>').addClass('play-pause').appendTo(this.$btns);
- this.$next = $('<div>').addClass('next').appendTo(this.$btns);
-
- this.$timelinecont= $('<div>').addClass('time-line-container').appendTo(this.$container);
- this.$timeline = $('<div>').addClass('time-line').appendTo(this.$timelinecont);
- this.$loader = $('<div>').addClass('loader').appendTo(this.$timeline);
- this.$cursor = $('<div>').addClass('cursor').appendTo(this.$timeline);
-
- this.$time = $('<div>').addClass('time').appendTo(this.$container);
- this.$currentTime = $('<div>').addClass('current-time').html('00:00').appendTo(this.$time);
- this.$duration = $('<div>').addClass('duration').html('00:00').appendTo(this.$time);
-
- this.$fav = $('<div>').addClass('favoris').appendTo(this.$container);
-
- this.$cartel = $('<div>').addClass('cartel').appendTo(this.$container);
- this.scndCartel_visible = 0;
- this.cartelSwitchIntervalMS = 7000;
- this.cartelSwitchInterval = false;
-
- this.visible = false;
- this.hideTimer = false;
- this.hideTimeMS = 15000;
-
- this.currentHistoricIndex = null;
- this.historic = [];
- this.shuffle_is_active = false;
-
- this.auto_open_article = false;
-
- this.event_handlers = {
- 'audio-open-document':[],
- 'audio-play':[],
- 'audio-pause':[],
- 'audio-play-next':[],
- 'audio-ended':[],
- 'stop-shuffle':[]
- };
- this.init();
- };
- AudioPlayer.prototype = {
- init(){
- if(!_is_expo){
- this.$container_parent = $('header[role="banner"] .region-header');
- }else{
- this.$container_parent = $('main[role="main"]');
- }
-
- this.$container.appendTo(this.$container_parent);
-
- this.timeline_w = parseInt(this.$timeline.width());
-
- this.$loader.on('click', this.seek.bind(this));
-
- var fn = '';
- for (var i = 0; i < this.audio_events.length; i++) {
- fn = this.audio_events[i];
-
- fn = 'on'+fn.charAt(0).toUpperCase()+fn.slice(1);
- this.audio.addEventListener(
- this.audio_events[i],
- this[fn].bind(this),
- true);
- }
-
- 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){
- console.log('AudioPlayer openDocument', node, caller, historic_index);
- if(typeof node == 'undefined'
- || typeof node.nid == 'undefined'
- || typeof node.audio_url == 'undefined'){
- console.warn('AudioPlayer openDocument() node is malformed', node);
- return false;
- }
-
- if(typeof caller == 'undefined' || caller != 'popstate'){
- console.log('');
- this.historic.push(node);
- this.currentHistoricIndex = this.historic.length-1;
-
-
- if(caller != "history_first_load"){
- if(typeof node.document_url == 'undefined'){
- console.warn("AudioPlayer openDocument missing document_url, can't push state to history", caller, node);
- }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;
- }
- if(_$body.is('.path-frontpage') && caller !== 'lastdocs' && !_is_mobile){
- closeAllModals();
- }
-
-
- 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.clearIntervalAutoCartelSwitch();
- console.log('this.historic', this.historic);
- console.log('this.currentHistoricIndex', this.currentHistoricIndex);
- this.setSRC(this.historic[this.currentHistoricIndex].audio_url);
- if(!_is_mobile){
- this.loadNode(this.historic[this.currentHistoricIndex].nid);
- }
-
- try {
- _$corpus_canvas.trigger({
- 'type':'audio-node-opened',
- 'nid':this.historic[this.currentHistoricIndex].nid
- });
- } catch (e) {
- 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();
- 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){
- console.log('AudioPlayer setSRC : url', url);
- 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(){
- console.log("updateLoadingBar");
-
-
- 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{
- console.log('Audio fully loaded');
- }
- }else{
-
- window.requestAnimationFrame(this.updateLoadingBar.bind(this));
- }
- },
-
-
-
- onError(){
- console.warn("Audio Error " + this.audio.error.code + "; details: " + this.audio.error.message);
- },
- play(){
- this.clearTimeOutToHide();
-
-
-
-
-
-
- var promise = this.audio.play();
-
- if (promise !== undefined) {
- promise.catch(function(error){
-
-
- console.warn('autoplay failed, ask for playing', error);
- }).then(function(){
-
- console.log('autoplay succeed');
- });
- }
- },
- 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();
- }
- },
- seek(e){
- var seek = e.originalEvent.layerX / this.timeline_w * this.audio.duration
- console.log("Audio seeking : seek", seek);
- this.audio.currentTime = seek;
- },
- seekToEnd(){
- if (this.audio.duration > 40) {
- console.log("seekToEnd", this.audio.duration);
- this.audio.currentTime = this.audio.duration - 20;
- }
- },
-
- 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(){
- console.log('AudioPlayer onEnded()');
- this.stop();
- this.emmit('audio-ended');
- },
-
- reloadNode(){
- if(this.visible){
- if(!_is_mobile){
- console.log('reloadNode (cartel)');
- this.loadNode(this.historic[this.currentHistoricIndex].nid);
- }
- }
- },
- loadNode(nid){
- this.$cartel.addClass('loading');
- var vm = 'player_cartel';
- var ajax_path = _ajax_settings.entityjson_path+'/node/'+nid+'/'+vm;
- var path = _origin + Drupal.url(ajax_path);
- $.getJSON(path, {})
- .done(this.onNodeLoaded.bind(this))
- .fail(this.onNodeLoadFail.bind(this));
- },
- onNodeLoaded(data){
- console.log('AudioPlayer node loaded');
- this.$cartel.html(data.rendered).removeClass('loading');
- _$body.trigger({'type':'new-audio-cartel-loaded'});
- initAjaxLinks();
-
- this.scndCartel_visible = 0;
- this.$cartel.removeClass('second-visible');
- if(!_is_expo){
-
- if (this.$cartel.find('.second-cartel .col-left').children().length > 1
- || this.$cartel.find('.second-cartel').children('.col-right').length){
-
- this.cartelSwitchInterval = setInterval(this.switchCartel.bind(this), this.cartelSwitchIntervalMS);
- }
-
- Drupal.attachBehaviors(this.$cartel);
- }
-
- this.setAutoOpenArticle();
- if(this.auto_open_article){
- this.$cartel.find('a.link-article').trigger('click');
- this.auto_open_article = false;
- }
- },
- onNodeLoadFail(jqxhr, textStatus, error){
- console.warn('AudioPlayer node load failed', jqxhr.responseText);
- this.$cartel.removeClass('loading').html('');
- },
- setAutoOpenArticle(art){
- this.auto_open_article = $('a.articles-link').is('.is-active');
- return this;
- },
-
- show(){
- this.visible = true;
- 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;
- }
- },
-
- switchCartel(){
-
- if (this.scndCartel_visible) {
-
- this.$cartel.removeClass('second-visible');
- this.scndCartel_visible = 0;
-
- this.clearIntervalAutoCartelSwitch();
- }else{
-
- this.$cartel.addClass('second-visible');
- this.scndCartel_visible = 1;
- }
- },
- clearIntervalAutoCartelSwitch(){
- if(this.cartelSwitchInterval){
- clearInterval(this.cartelSwitchInterval);
- this.cartelSwitchInterval = false;
- }
- },
- hide(){
-
- this.visible = false;
- this.$container_parent.removeClass('audio-player-visible');
- this.$container.removeClass('visible');
-
- try {
- _$corpus_canvas.trigger('audio-node-closed');
- } catch (e) {
- console.info('AudioPlayer hide() : _$corpus_canvas does not exists');
- }
- },
- deActivateRandom(){
- this.shuffle_is_active = false;
- this.showHideNextBtn();
- },
-
- on(event_name, handler){
- if(typeof this.event_handlers[event_name] == 'undefined'){
- console.warn('AudioPlayer : event '+event_name+' does not exists');
- }
- this.event_handlers[event_name].push(handler);
- return this;
- },
- emmit(event_name, args){
- console.log('AudioPlayer emmit()', event_name, args, this.event_handlers[event_name]);
-
- 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;
- },
- }
-
-
-
-
-
- function RandomPlayer(playlist){
- this.active = false;
- this.playlist = playlist;
- this.path = _base_url+drupalSettings.path.pathPrefix+'#random'
- this.$btn = $('<a>')
- .html('Shuffle')
- .attr('href',this.path)
- .attr('alt', drupalSettings.edlp_corpus.random_link_title)
- .addClass('random-player-btn');
- this.init();
- };
- RandomPlayer.prototype = {
- init(){
-
- $('<div>')
- .addClass('block random-player')
- .append(this.$btn)
-
- .prependTo('.region-footer-right');
-
- this.$btn.on('click', this.toggleActive.bind(this));
-
- _audioPlayer
- .on('audio-play-next', this.onAudioPlayNext.bind(this))
- .on('audio-ended', this.onAudioPlayerEnded.bind(this))
- .on('stop-shuffle', this.stop.bind(this));
- _$corpus_canvas
- .on('update-random-playlist', this.updatePlaylist.bind(this));
-
- if(window.location.hash == '#random'){
- this.start();
- }
- },
- updatePlaylist(e){
- if (!_is_expo) {
- this.playlist = e.playlist;
- this.shuffle();
- }
- },
- shuffle(){
- var tempPLaylist = [];
- for (var i = this.playlist.length-1; i >= 0 ; i--) {
- tempPLaylist.push(this.playlist[i]);
- }
- this.shuffledPlaylist = [];
- while(tempPLaylist.length > 0){
- var r = Math.floor(Math.random() * tempPLaylist.length);
- this.shuffledPlaylist.push(tempPLaylist.splice(r,1)[0]);
- }
-
- },
- toggleActive(e){
- e.preventDefault();
- if (this.active) {
- this.stop();
- }else{
- this.start();
- }
- return false;
- },
- start(){
- this.active = _audioPlayer.shuffle_is_active = true;
- this.$btn.addClass('is-active');
- this.shuffle();
- this.next();
-
- if(typeof _paq !== 'undefined'){
-
- _paq.push(['trackEvent', 'RandomPlayer', 'start']);
- }
- },
- stop(){
- this.active = false;
- this.$btn.removeClass('is-active');
-
-
-
- history.replaceState(history.state, null, window.location.pathname);
-
- _audioPlayer.deActivateRandom();
- if(typeof _paq !== 'undefined'){
-
- _paq.push(['trackEvent', 'RandomPlayer', 'stop']);
- }
- },
- next(){
- console.log('RandomPlayer next', this.active, this.shuffledPlaylist.length);
- if(this.active){
- if (this.shuffledPlaylist.length == 0) {
- this.shuffle();
- }
- _audioPlayer.openDocument(this.shuffledPlaylist.splice(0,1)[0], 'random');
- }
- },
- onAudioPlayNext(){
- console.log('RandomPlayer : onAudioPlayNext()');
- if(this.active){
- this.next();
- }
- },
- onAudioPlayerEnded(){
- console.log('RandomPlayer : onAudioPlayerEnded()');
- if(this.active){
- this.next();
- if(_is_expo){
- _$corpus_canvas.trigger({'type':'scramble-collection'});
- }
- }
- }
- };
-
-
-
-
-
- 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 = {
- init(){
-
-
- _audioPlayer
- .on('audio-open-document', this.onAudioOpenDocument.bind(this))
- .on('audio-play', this.onAudioPlayerPlay.bind(this))
- .on('audio-pause', this.onAudioPlayerPause.bind(this))
- .on('audio-ended', this.onAudioPlayerEnded.bind(this));
-
-
- },
- newCompo(){
- console.log('CompoPlayer newCompo()');
-
- this.initControls();
- },
- initControls(){
-
- 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.$compo){
- 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.active = true;
-
- }
- this.refresh();
- },
- refresh(){
-
- this.stop();
-
- this.playlist = [];
- var that = this;
- $('.field--name-documents .field__item',this.$compo).each(function(i,el){
- var $link = $('a.audio-link',this);
- that.playlist.push({
- item:$(this),
- audio_url:$link.attr("audio_url"),
- nid:$link.attr("nid"),
- });
- });
- this.showHideControls();
- },
- togglePlayPause(){
-
- if (this.playing && !this.paused) {
- this.pause();
- }else{
- if(this.playing && this.paused){
- this.play();
- }else{
- this.start();
- }
- }
- },
- start(i){
-
-
- this.current_index = i || 0;
- this.playing = true;
- this.play();
- },
- play(){
- console.log('CompoPlayer play()', this.playlist[this.current_index]);
- if(this.paused){
- this.paused = false;
- _audioPlayer.play();
- }else{
- console.log('CompoPlayer opendoc with audio player');
-
- _audioPlayer.emmit('stop-shuffle').openDocument(this.playlist[this.current_index], this);
- }
- this.setActiveItem().showHideControls();
- },
- pause(){
-
- this.paused = true;
- this.showHideControls();
- _audioPlayer.stop();
- },
- next(){
- console.log('CompoPlayer next()',this.playing);
- if(this.playing){
- this.current_index += 1;
- if(this.current_index < this.playlist.length){
- this.play();
- }else{
- this.stop();
- }
- }
- },
- prev(){
-
- if(this.playing){
- this.current_index -= 1;
- if(this.current_index >= 0){
- this.play();
- }else{
- this.stop();
- }
- }
- },
- stop(){
- if(this.playing){
- _audioPlayer.stop();
- }
- this.reset();
- },
- reset(){
- this.playing = false;
- this.paused = false;
- this.resetIndex();
- },
- resetIndex(){
- this.current_index = 0;
- this.showHideControls().resetActiveItems();
- },
- setActiveItem(){
- this.resetActiveItems();
- if(this.playing && this.current_index >= 0){
- this.playlist[this.current_index].item.addClass('is-active');
- }
-
- this.showHideControls();
- return this;
- },
- resetActiveItems(){
- for (var n = 0; n < this.playlist.length; n++) {
-
- this.playlist[n].item.removeClass('is-active');
- }
- return this;
- },
- showHideControls(){
-
-
- if(this.$controls){
- if(this.playing && !this.paused){
- this.$controls.addClass('is-playing');
- }else{
- this.$controls.removeClass('is-playing');
- }
- }
-
- if(this.$playpause){
- if(this.playlist.length > 0){
- this.$playpause.addClass('is-active');
- }else{
- this.$playpause.removeClass('is-active');
- }
- }
-
- if(this.$next){
- if(this.playing && this.playlist.length > 1 && this.current_index < this.playlist.length -1){
- this.$next.addClass('is-active');
- }else{
- this.$next.removeClass('is-active');
- }
- }
-
- if(this.$previous){
- if(this.playing && this.playlist.length > 1 && this.current_index > 0){
- this.$previous.addClass('is-active');
- }else{
- this.$previous.removeClass('is-active');
- }
- }
- return this;
- },
- deactivate(){
- this.stop();
- this.active = false;
- },
-
- onAudioOpenDocument(args){
- console.log('Compo player onAudioOpenDocument', args);
- if(args.caller !== this){
-
- this.reset();
- }
-
-
-
- },
- onAudioPlayerPlay(){
- if(this.playing && this.paused){
- this.paused = false;
- this.showHideControls();
- }
- },
- onAudioPlayerPause(){
- if(this.playing && !this.paused){
- this.paused = true;
- this.showHideControls();
- }
- },
- onAudioPlayerEnded(){
- console.log('onAudioPlayerEnded');
- if(this.playing){
-
- this.paused = false;
- this.next();
- }
- },
-
-
-
- };
-
-
-
-
-
- function initExpo(){
- console.log('initExpo', window.location.hash);
- document.title = edlp.site_name;
- if(window.location.hash == '#black'){
- $('body').addClass('expo-black');
- }
- _$body.on('map-node-opened', checkExpoPlayerPositionning);
- _randomPlayer.start();
- initKeyboard();
- }
- function checkExpoPlayerPositionning(e){
- console.log('checkExpoPlayerPositionning', e.node);
-
- switch(true){
- case e.node.x > window.innerWidth-610 && e.node.y < 200:
- _audioPlayer.$container.attr('pos', 'bottom-left');
- break;
- case e.node.x > window.innerWidth-610:
- _audioPlayer.$container.attr('pos', 'top-left');
- break;
- case e.node.y < 200:
- _audioPlayer.$container.attr('pos', 'bottom-right');
- break;
- default:
- _audioPlayer.$container.attr('pos', 'top-right');
- }
- _audioPlayer.$container.css({
- 'display':"block",
- 'left':e.node.x+"px",
- 'top':e.node.y+"px",
- });
- }
- function initKeyboard(){
- $(document).bind('keyup', 'alt+n', function(){
- _randomPlayer.next();
- });
- }
-
-
-
-
- function initGrid(){
- console.log('theme : initGrid');
- if(!_is_mobile){
- checkGridBlockHeight();
- _$row.find('.col').addClass('offfield');
- }
- if(false){
- var $grid = $('.grid',_$row).masonry({
- itemSelector:'.col',
- columnWidth:'.col-2',
- containerStyle: null,
- resizeContainer:false,
-
- transitionDuration:0,
-
-
-
- });
-
- $grid.imagesLoaded().progress( function() {
- $grid.masonry('layout');
- });
- $grid.imagesLoaded(function(){
- $grid.masonry('layout');
-
- });
-
-
-
-
- $grid.on('layoutComplete', checkGridBlockVisible);
- }else{
-
- if(!_is_mobile){
- checkGridBlockVisible();
- }
- }
- };
- function checkGridBlockHeight(){
-
-
- var $r_h = _$row.height();
- var $this;
-
- $('.grid .col', _$row).each(function(i,e){
- $this = $(this);
- if(!$this.is('[init-height]')){
- $this.attr('init-height', $this.outerHeight())
- }
-
-
-
-
-
-
- $this.height(Math.min($this.attr('init-height'), _$row.height()));
- });
- };
- function checkGridBlockVisible(){
-
-
- var $r_h = _$row.height();
- var $this,pos;
- $('.grid .col', _$row).each(function(i,e){
-
- $this = $(this);
- pos = $this.position();
-
- if(pos.top+$this.height() <= $r_h){
- $this.removeClass('offfield');
- }else{
- $this.addClass('offfield');
- }
-
- });
-
-
-
-
-
-
-
-
-
-
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- function initCollectionNav(){
- console.log('initCollectionNav');
-
- $('.field--name-field-notice, .index', '.taxonomy-term.vocabulary-entrees.home_mobile')
- .addClass('closed');
- $('.field--name-field-notice>.field__label', '.taxonomy-term.vocabulary-entrees.home_mobile')
- .on('click', onClickCollectionNotice);
- $('.index>.field__label', '.taxonomy-term.vocabulary-entrees.home_mobile')
- .on('click', onClickCollectionIndex);
- };
- function onClickCollectionNotice(e){
-
-
- toggleEntreeOpening($(this).parent(), 'notice');
- };
- function onClickCollectionIndex(e){
-
-
- toggleEntreeOpening($(this).parent(), 'index');
- };
- function toggleEntreeOpening($e, part){
- $e.toggleClass('closed')
- .parents('.taxonomy-term.vocabulary-entrees.home_mobile').toggleClass(part+'-opened');
- }
-
-
-
-
- function initSearch(){
-
-
-
- $('#edit-entries--wrapper legend', '#edlp-search-form').on('click', function(){
- $(this).parent().toggleClass('opened');
- });
- };
-
-
-
-
-
- function initEnregistrementTranscript(){
- console.log('initEnregistrementTranscript');
- var $node = _$row.find('article.node--type-enregistrement.node--view-mode-transcript');
- var $nav = $('<nav>').prependTo($node);
- $node.find('.field--name-field-transcript-vo').addClass('visible').find('.field__label')
- .clone().appendTo($nav).addClass('is-active')
- .attr('field_target', '.field--name-field-transcript-vo');
- $node.find('.field--name-field-transcript-trad').find('.field__label')
- .clone().appendTo($nav)
- .attr('field_target', '.field--name-field-transcript-trad');
- $nav.find('.field__label').on('click', function(){
- var $this = $(this).addClass('is-active');
- $this.siblings('.is-active').removeClass('is-active');
- $this.parents('article.node').find('.field.visible').removeClass('visible');
- $this.parents('article.node').find($this.attr('field_target')).addClass('visible');
- });
- };
-
-
-
-
-
- function backToFrontPage(pop_state){
- console.log('backToFrontPage', pop_state);
- if(!_is_mobile){
- closeAllModals();
-
- $('body').removeClass().addClass('path-frontpage');
- $('a[data-drupal-link-system-path="<front>"]').addClass('is-active');
-
- if(_corpus_ready){
- _$corpus_canvas.trigger({'type':'close-all-entree'});
- _$corpus_canvas.trigger({'type':'scramble-collection'});
- }
- if(typeof pop_state == "undefined" || !pop_state){
- console.log('backToFrontPage push state');
- state = {
- home:true,
- context:"home",
- caller:null
- }
- _states_history.unshift(state);
- history.pushState(state, null, _base_url+drupalSettings.path.currentLanguage);
- }
- }else{
-
- ajaxLoadContent({home: true, ajax_path: 'home_m/ajax', sys_path: 'frontpage'});
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- function closeAllModals(){
-
-
- _$row.html('');
- _$ajaxLinks.removeClass('is-active');
- _$body.trigger({'type':'all-modal-closed'});
-
- checkVisibleCorpusMapSpace();
- };
- function checkRowEmpty(){
- console.log('checkRowEmpty');
-
- if(!$('.col', _$row).length){
- if(!_$body.is('.entity-type-taxonomy_term.bundle-entrees')){
- if(!_$body.is('.entity-type-node.bundle-page')){
-
-
- if(_$body.is('.bundle-enregistrement.view-mode-article')
- && $('a.articles-link').is('.is-active')){
- console.log('Closing article while article index is active');
-
- $('a.articles-link').removeClass('is-active').trigger('click');
- }else{
- backToFrontPage();
- }
-
-
-
-
-
- }else{
-
- if(_corpus_ready){
- _$corpus_canvas.trigger({'type':'scramble-collection'});
- }
-
- $('a[data-drupal-link-system-path="productions"]', '#block-mainnavigation')
- .removeClass('is-active').trigger('click');
- }
- }else{
-
- $('.entree-content a.is-active').removeClass('is-active');
-
- }
- }
- };
- init();
- }
- $(document).ready(function($) {
- if(drupalSettings.path.isFront){
- var edlptheme = new EdlpTheme();
- }else{
- $('body').attr('booted', 'booted');
- }
- });
- })(jQuery, Drupal, drupalSettings);
|