main.js 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383
  1. (function($, Drupal, drupalSettings) {
  2. EdlpTheme = function(){
  3. var _ajax_settings = drupalSettings.edlp_ajax;
  4. var _$body = $('body');
  5. // var _is_front = drupalSettings.path.isFront;
  6. var _corpus_ready = false;
  7. var _$corpus_canvas;
  8. var _$row = $('main[role="main"]>.layout-content>.row');
  9. var _$ajaxLinks;
  10. var _audioPlayer;
  11. var _randomPlayer;
  12. var _compoPlayer;
  13. // ___ _ _
  14. // |_ _|_ _ (_) |_
  15. // | || ' \| | _|
  16. // |___|_||_|_|\__|
  17. function init(){
  18. console.log("EdlpTheme init()");
  19. _audioPlayer = new AudioPlayer();
  20. _compoPlayer = new CompoPlayer();
  21. initAjaxLinks();
  22. initHistory();
  23. if(!drupalSettings.path.isFront)
  24. return;
  25. initEvents();
  26. };
  27. // ___ _
  28. // | __|_ _____ _ _| |_ ___
  29. // | _|\ V / -_) ' \ _(_-<
  30. // |___|\_/\___|_||_\__/__/
  31. function initEvents(){
  32. _$body
  33. .on('corpus-map-ready', onCorpusMapReady)
  34. .on('on-studio-chutier-updated', initAjaxLinks)
  35. .on('studio-initialized', function(e){
  36. _compoPlayer.newCompo();
  37. })
  38. .on('studio-not-active', function(e){
  39. _compoPlayer.deactivate();
  40. })
  41. .on('on-studio-compo-updated', function(e){
  42. initAjaxLinks();
  43. _compoPlayer.refresh();
  44. })
  45. .on('on-studio-compo-opened', function(e){
  46. initAjaxLinks();
  47. _compoPlayer.newCompo();
  48. })
  49. .on('search-results-loaded', initAjaxLinks)
  50. // do not close index or notice modale on entree click
  51. .on('open_entree', function(e){
  52. console.log('on_open_entree : e', e);
  53. closeAllModals();
  54. // add body class for currently loaded content
  55. // var body_classes = [
  56. // 'path-'+sys_path.replace(/\//g, '-'),
  57. // 'entity-type-'+data.entity_type,
  58. // 'bundle-'+data.bundle,
  59. // 'view-mode-'+data.view_mode
  60. // ];
  61. _$body.removeClass();//.addClass(body_classes.join(' '));
  62. // record new history state
  63. if(typeof e.url != 'undefined'){
  64. // var state = {
  65. // ajax_path:null,
  66. // sys_path:null,
  67. // entree_tid:e.tid
  68. // };
  69. var state = getSysPathState(e.sys_path);
  70. history.pushState(state, null, e.url);
  71. }
  72. })
  73. .on('close_entree', function(e){
  74. backToFrontPage();
  75. });
  76. }
  77. // ___ _ _ ___
  78. // / __| __ _ _ ___| | | _ ) __ _ _ _ ___
  79. // \__ \/ _| '_/ _ \ | | _ \/ _` | '_(_-<
  80. // |___/\__|_| \___/_|_|___/\__,_|_| /__/
  81. function initScrollbars(){
  82. // console.log("initScrollbars");
  83. // TODO: find a better js scroll than overlayScrollbars which does not handle well max-height + overflow-y:auto;
  84. // $('.os-scroll').overlayScrollbars({
  85. // overflowBehavior:{
  86. // x:'h',
  87. // y:'scroll',
  88. // clipAlways:false
  89. // }
  90. // });
  91. };
  92. // _ _
  93. // /_\ (_)__ ___ __
  94. // / _ \ | / _` \ \ /
  95. // /_/ \_\/ \__,_/_\_\
  96. // |__/
  97. function getSysPathState(sys_path, view_mode){
  98. // console.log('Theme : getSysPathState', sys_path);
  99. var state = {
  100. 'sys_path':sys_path,
  101. 'ajax_path': sys_path
  102. };
  103. // convert node link to edlp_ajax_node module links
  104. var node_match = state.ajax_path.match(/^\/?(node\/(\d+))$/i);
  105. console.log('node_match', node_match);
  106. var term_match = state.ajax_path.match(/^\/?(taxonomy\/term\/(\d+))$/i);
  107. console.log('term_match', term_match);
  108. if(node_match){
  109. // TODO: detect audio links which will open audioplayer and wont load any ajax content unless view_mode "article" or "transcript"
  110. state.ajax_path = _ajax_settings.entityjson_path+'/'+node_match[1];
  111. state.node_nid = node_match[2];
  112. // check for viewmode attribute
  113. if(view_mode){
  114. state.ajax_path += '/'+view_mode;
  115. }
  116. }else if(term_match){
  117. // terms are always entrees, there's no other vocabulary links in front
  118. state.ajax_path = _ajax_settings.entityjson_path+'/'+term_match[1];
  119. state.ajax_path = state.ajax_path.replace(/taxonomy\/term/, 'taxonomy_term');
  120. state.entree_tid = term_match[2];
  121. // check for viewmode attribute
  122. if(view_mode){
  123. state.ajax_path += '/'+view_mode;
  124. state.view_mode = view_mode;
  125. }else{
  126. state.ajax_path = null;
  127. }
  128. }else{
  129. // convert other link to ajax
  130. // TODO: we assume that other links (no node, no term) are all from own modules (e.g. productions) !! may not be true !!
  131. state.ajax_path += '/ajax'
  132. }
  133. return state;
  134. };
  135. function ajaxLoadContent(state){
  136. console.log('ajaxLoadContent : url', state.url);
  137. _$body.addClass('ajax-loading');
  138. var path = window.location.origin + Drupal.url(state.ajax_path);
  139. $.getJSON(path, {})
  140. .done(function(data){
  141. onAjaxLoaded(data, state);
  142. })
  143. .fail(function(jqxhr, textStatus, error){
  144. onAjaxLoadError(jqxhr, textStatus, error, state.sys_path);
  145. });
  146. };
  147. function onAjaxLoadError(jqxhr, textStatus, error, sys_path){
  148. console.warn('ajaxlink load failed for '+sys_path+' : '+error, jqxhr.responseText);
  149. $('.ajax-loading').removeClass('ajax-loading');
  150. _$body.removeClass('ajax-loading');
  151. };
  152. function onAjaxLoaded(data, state){
  153. console.log('ajax loaded url:'+state.url+' ajax_path:'+state.ajax_path+' sys_path:'+state.sys_path);
  154. // console.log(data);
  155. // reset all style may been added by other pages (like masonry for productions)
  156. // and replace all content with newly loaded
  157. // TODO: build a system to replace or append contents (like studio + search)
  158. if(data.entity_type == "node" && data.bundle == "evenement"){
  159. if(_$row.find('.col.event').length){
  160. _$row.find('.col.event').replaceWith(data.rendered);
  161. }else if(_$row.find('.col.aside').length){
  162. _$row.find('.col.aside').replaceWith(data.rendered);
  163. }else{
  164. _$row.append(data.rendered);
  165. }
  166. }else{
  167. _$row.removeAttr('style').html(data.rendered);
  168. }
  169. // add body class for currently loaded content
  170. var body_classes = [
  171. 'path-'+state.sys_path.replace(/\//g, '-'),
  172. 'entity-type-'+data.entity_type,
  173. 'bundle-'+data.bundle,
  174. 'view-mode-'+data.view_mode
  175. ];
  176. _$body.removeClass().addClass(body_classes.join(' '));
  177. // id node add a generic path-node class to body
  178. // m = state.sys_path.match(/^\/?(node\/\d+)$/g);
  179. // if(m)
  180. if(state.node_nid)
  181. _$body.addClass('path-edlp-node');
  182. // handle clicked link classes
  183. $('.ajax-loading').removeClass('ajax-loading');
  184. $('.is-active').removeClass('is-active');
  185. $('.is-active-trail').removeClass('is-active-trail');
  186. if(typeof state.selector != 'undefined'){
  187. // in case of entree link (actualy, selector is used only for entries links)
  188. // TODO: unfortunatly on initFirstLoad there is no selector property
  189. console.log('selector', state.selector);
  190. $('a[selector="'+state.selector+'"]').addClass('is-active');
  191. initAudioLinksInContent();
  192. }else{
  193. if(typeof state.view_mode != 'undefined'){
  194. $('a[viewmode="'+state.view_mode+'"][data-drupal-link-system-path="'+state.sys_path+'"]').addClass('is-active');
  195. }else{
  196. $('a[data-drupal-link-system-path="'+state.sys_path+'"]').addClass('is-active');
  197. }
  198. // as new content is not related to entree, we trigger close entree
  199. _$body.trigger({'type':'new-content-not-entree-ajax-loaded'});
  200. }
  201. // if bundle page (productions) activate production links
  202. if (typeof data.bundle != 'undefined' && data.bundle == "page") {
  203. $('a[data-drupal-link-system-path="productions"]').addClass('is-active-trail');
  204. }
  205. // if node is in production menu tree, set first level of tree active, e.g. pieces sonores
  206. if (typeof data.menu_parents != 'undefined') {
  207. for (var i = 0; i < data.menu_parents.length; i++) {
  208. var menu_sys_path = data.menu_parents[i];
  209. $('a[data-drupal-link-system-path="'+menu_sys_path+'"]').addClass('is-active-trail');
  210. }
  211. }
  212. // if block attached (eg : from edlp_productions module)
  213. // not used anymore as production block is always present (but not visible)
  214. if(typeof data.block != 'undefined'){
  215. // if block not already added
  216. if(!$('#'+data.block.id, '.region-'+data.block.region).length){
  217. $('.region-'+data.block.region).append(data.block.rendered);
  218. }
  219. }
  220. // initScrollbars();
  221. if(state.sys_path == "productions"){
  222. initProductions();
  223. }else{
  224. addCloseModalBtnToCols();
  225. }
  226. // enregistrement transcription
  227. if(data.entity_type == "node" && data.bundle == "enregistrement" && data.view_mode == "transcript"){
  228. // window.requestAnimationFrame(initEnregistrementTranscript);
  229. initEnregistrementTranscript();
  230. }
  231. // update the language switcher block if it comes in the response
  232. if(typeof data.translations_links != 'undefined'){
  233. console.log('state',state);
  234. var lang_code = drupalSettings.path.currentLanguage;
  235. var $links = $(data.translations_links);
  236. // set active link
  237. $links.find('li[hreflang="'+lang_code+'"]').addClass('is-active').find('a').addClass('is-active');
  238. if(state.view_mode){
  239. $links.find('a').each(function(i,e){
  240. var $a = $(this);
  241. $a.attr('href', $a.attr('href')+'#'+state.view_mode);
  242. });
  243. }
  244. // if(state.selector){
  245. // $links.find('a').attr('selector', state.selector);
  246. // }
  247. $('ul','.block.language-switcher-language-url').replaceWith($links);
  248. }
  249. initAjaxLinks();
  250. // trigger other modules behaviours
  251. _$body.trigger({'type':'new-content-ajax-loaded'});
  252. // and call druapl behaviours
  253. Drupal.attachBehaviors(_$row[0]);
  254. _$body.attr('booted', 'booted');
  255. _$body.removeClass('ajax-loading');
  256. // url is null means that we are loading content on popState event
  257. // so we don't record the state again
  258. if(state.url){
  259. // var state = {
  260. // ajax_path:ajax_path,
  261. // sys_path:sys_path,
  262. // };
  263. // console.log('url:'+url+' ; state',state);
  264. // console.log(window.location);
  265. // /!\ we can not pushestate with absolute url /!\
  266. history.pushState(state, null, state.url);
  267. }
  268. };
  269. function initAudioLinksInContent(){
  270. // console.log('initAudioLinksInContent');
  271. _$row.find('a.audio-link')
  272. .on('mouseover', function(event) {
  273. event.preventDefault();
  274. // console.log('onmouseover audio-link');
  275. if(_corpus_ready){
  276. _$corpus_canvas.trigger({
  277. type:'mouseover-audio-link',
  278. nid:$(this).attr('nid')
  279. });
  280. }
  281. })
  282. .on('mouseout', function(event) {
  283. event.preventDefault();
  284. // console.log('onmouseout audio-link');
  285. if(_corpus_ready){
  286. _$corpus_canvas.trigger({
  287. type:'mouseout-audio-link',
  288. nid:$(this).attr('nid')
  289. });
  290. }
  291. });
  292. };
  293. function addCloseModalBtnToCols(){
  294. $('.col', _$row).each(function(index, el) {
  295. if($('span.close-col-btn', this).length)
  296. return true;
  297. $(this).children('.wrapper').prepend($('<span>')
  298. .addClass('close-col-btn')
  299. .on('click', onCloseModal)
  300. );
  301. });
  302. };
  303. function onCloseModal(e){
  304. // check for theme attribute and emmit event
  305. var $col = $(this).parents('.col');
  306. var theme = $col.attr('theme');
  307. if(theme != ''){
  308. _$body.trigger({'type':theme+'-col-closed'});
  309. }
  310. // remove the col
  311. $col.remove();
  312. // if row is empty and we are not in productions or entree notice|index call closeAllModals()
  313. if(!$('.col', _$row).length
  314. && !_$body.is('.entity-type-node.bundle-page')
  315. && !_$body.is('.entity-type-taxonomy_term.bundle-entrees')){
  316. backToFrontPage();
  317. }
  318. };
  319. // _ _ ___ _ _
  320. // /_\ (_)__ ___ __ | _ ) |___ __| |__ ___
  321. // / _ \ | / _` \ \ / | _ \ / _ \/ _| / /(_-<
  322. // /_/ \_\/ \__,_/_\_\ |___/_\___/\__|_\_\/__/
  323. // |__/
  324. // NOT USED (YET)
  325. function refreshAllBlocks(){
  326. var path = window.location.origin + Drupal.url(_ajax_settings.blocksjson_path);
  327. $.getJSON(path, {})
  328. .done(function(data){
  329. onAjaxBlockLoaded(data);
  330. })
  331. .fail(function(jqxhr, textStatus, error){
  332. onAjaxBlockLoadError(jqxhr, textStatus, error);
  333. });
  334. };
  335. function onAjaxBlockLoadError(jqxhr, textStatus, error){
  336. console.warn('ajax block load failed: '+error, jqxhr.responseText);
  337. };
  338. function onAjaxBlockLoaded(data){
  339. console.log('onAjaxBlockLoaded', data);
  340. // TODO: update each blocks (exepted language switcher)
  341. for (var blockname in data.blocks) {
  342. var block = data.blocks[blockname];
  343. console.log(blockname, block);
  344. $(block.id).replaceWith(block.rendered);
  345. }
  346. };
  347. // _ _ _ _
  348. // | || (_)__| |_ ___ _ _ _ _
  349. // | __ | (_-< _/ _ \ '_| || |
  350. // |_||_|_/__/\__\___/_| \_, |
  351. // |__/
  352. function initHistory(){
  353. initFirstLoad();
  354. window.addEventListener('popstate', onHistoryPopState);
  355. };
  356. function initFirstLoad(){
  357. console.log('theme : initFirstLoad()');
  358. // var origin_sys_path = window.localStorage.getItem('edlp_origin_path');
  359. var edlp_origin = JSON.parse(window.localStorage.getItem('edlp_origin'));
  360. console.log('edlp_origin', edlp_origin);
  361. if(edlp_origin != null && edlp_origin.sys_path){
  362. // hash is used as viewmode for taxonomy term entrees load (index or notice)
  363. // and for audio contents (article|transcript)
  364. var view_mode = edlp_origin.hash.replace('#', '');
  365. // create history state
  366. var state = getSysPathState(edlp_origin.sys_path, view_mode);
  367. // open entree tray in case of entree index|notice
  368. // (index or notice will be opened with ajaxLoadContent)
  369. // refactorized with new infos from edlp_origin
  370. // if(view_mode){
  371. if(edlp_origin.entity_type == "taxonomy_term"
  372. && edlp_origin.entity_bundle == "entrees"
  373. && view_mode){
  374. // var $link = $('[href="'+edlp_origin.url+'"][viewmode="'+view_mode+'"]');
  375. // var selector = $link.attr('selector') || null;
  376. // record the selector in the state for actions after ajaxContentLoaded
  377. state.selector = 'entree-'+view_mode+'-link-'+edlp_origin.entity_id; // entree-index-link-125
  378. // if(selector){
  379. // in case of entree link (actualy, selector is used only for entries links)
  380. // TODO: use a promise
  381. // TODO: but what if corpus ready before onAjaxLoaded >> use a promise !!
  382. if(_corpus_ready){
  383. _$corpus_canvas.trigger({
  384. type:'open-entree',
  385. // tid:$link.attr('tid')
  386. tid:edlp_origin.entity_id
  387. });
  388. }else{
  389. // else : EdlpCorpus will check when ready if entry item (notice or index) is already .is-active
  390. // .is-active class is added by onAjaxLoaded() (when content is loaded)
  391. // $('li.entree[tid="'+$link.attr('tid')+'"] a.term-link').addClass('is-active');
  392. $('li.entree[tid="'+edlp_origin.entity_id+'"] a.term-link').addClass('is-active');
  393. }
  394. // }
  395. }
  396. // check if audio link
  397. if(edlp_origin.audio_url){
  398. var node = {
  399. nid:edlp_origin.entity_id,
  400. audio_url:edlp_origin.audio_url
  401. };
  402. _audioPlayer.openDocument(node, 'history_first_load');
  403. if(view_mode == ""){
  404. // if audio only record in state
  405. state.audio = true;
  406. state.node = node;
  407. // we don't laod ajax content so we boot the home
  408. _$body.attr('booted', 'booted');
  409. }else{
  410. // ajax load content for audio only if article or transcript
  411. ajaxLoadContent(state);
  412. }
  413. }
  414. // only if not entree path
  415. // only if not audio (without article or transcript) path
  416. else if(state.ajax_path){
  417. // load content through ajax
  418. // ajaxLoadContent(null, state.sys_path, state.ajax_path, selector);
  419. ajaxLoadContent(state);
  420. }
  421. if(state.entree_tid){
  422. openEntree(state.entree_tid);
  423. }
  424. // record history state
  425. history.replaceState(state, null, edlp_origin.url+edlp_origin.hash);
  426. // reset the storage
  427. window.localStorage.removeItem("edlp_origin");
  428. // window.localStorage.removeItem("edlp_origin_url");
  429. }else{
  430. history.replaceState({home:true}, null, window.location.pathname);
  431. _$body.attr('booted', 'booted');
  432. }
  433. };
  434. function onHistoryPopState(e){
  435. console.log('onPopState',e.state);
  436. if(e.state.home){
  437. backToFrontPage(true);
  438. }
  439. else if (e.state.audio) {
  440. _audioPlayer.openDocument(e.state.node, 'popstate', e.state.historic_index);
  441. }
  442. else{
  443. if(e.state.entree_tid){
  444. openEntree(e.state.entree_tid);
  445. }
  446. if(e.state.ajax_path){
  447. e.state.url = null;
  448. // ajaxLoadContent(null, e.state.sys_path, e.state.ajax_path)
  449. ajaxLoadContent(e.state);
  450. }
  451. }
  452. };
  453. // _ _ _ _ _
  454. // /_\ (_)__ ___ _| | (_)_ _ | |__ ___
  455. // / _ \ | / _` \ \ / |__| | ' \| / /(_-<
  456. // /_/ \_\/ \__,_/_\_\____|_|_||_|_\_\/__/
  457. // |__/
  458. function initAjaxLinks(){
  459. // console.log('initAjaxLinks');
  460. $('a.site-name', '#block-edlptheme-branding')
  461. .add('a', '#block-mainnavigation')
  462. // .add('a', '.block.language-switcher-language-url')
  463. .add('a', '#block-footer.menu--footer')
  464. .add('a', '#block-productions')
  465. .add('a', 'article.node:not(.node--type-enregistrement) h2.node-title')
  466. .add('a', '.productions-subtree')
  467. .add('a', '.productions-parent')
  468. // .add('a.index-link, a.notice-link', '#block-edlpentreesblock')
  469. .addClass('ajax-link');
  470. _$ajaxLinks = $('.ajax-link:not(.ajax-enabled)')
  471. .each(function(i,e){
  472. var $this = $(this);
  473. // avoid already ajaxified links
  474. if($this.is('.ajax-enable')) return;
  475. if($this.attr('data-drupal-link-system-path')){
  476. $this.on('click', onClickAjaxLink).addClass('ajax-enable');
  477. }
  478. });
  479. };
  480. function onClickAjaxLink(e){
  481. e.preventDefault();
  482. var $link = $(this);
  483. if($link.is('.is-active'))
  484. return false;
  485. // Audio links
  486. // launch audio player and stop here
  487. if($link.is('.audio-link')){
  488. _audioPlayer
  489. .emmit('stop-shuffle')
  490. .openDocument({
  491. nid:$link.attr('nid'),
  492. audio_url:$link.attr('audio_url')
  493. });
  494. return false;
  495. }
  496. // NOT USED (YET)
  497. // if($link.is('.language-link')){
  498. // TODO: change global site current language
  499. // load all blocks translated (exepted language switcher) ... :/
  500. // refreshAllBlocks();
  501. // TODO: use a promise to initAjaxLinks again after blocks updated
  502. // then let load the content
  503. // }
  504. // other links
  505. var sys_path = $(this).attr('data-drupal-link-system-path');
  506. // front page
  507. // just remove contents and stop here
  508. if(sys_path == '<front>'){
  509. backToFrontPage();
  510. return false;
  511. }
  512. var view_mode = $link.attr('viewmode');
  513. var state = getSysPathState(sys_path, view_mode);
  514. state.url = $(this).attr('href');
  515. if(view_mode){
  516. state.url += "#"+view_mode;
  517. }
  518. if($link.is('[selector]')){
  519. state.selector = $link.attr('selector');
  520. }
  521. $link.addClass('ajax-loading');
  522. // ajaxLoadContent(url, sys_path, state.ajax_path, selector);
  523. ajaxLoadContent(state);
  524. return false;
  525. };
  526. // ___
  527. // / __|___ _ _ _ __ _ _ ___
  528. // | (__/ _ \ '_| '_ \ || (_-<
  529. // \___\___/_| | .__/\_,_/__/
  530. // |_|
  531. function onCorpusMapReady(e){
  532. //console.log('theme : onCorpusReady', e);
  533. _corpus_ready = true;
  534. _$corpus_canvas = $('canvas#corpus-map');
  535. _$corpus_canvas
  536. .on('corpus-cliked-on-map', function(e) {
  537. //console.log('theme : corpus-cliked-on-map');
  538. backToFrontPage();
  539. })
  540. .on('corpus-cliked-on-node', function(e) {
  541. //console.log('theme : corpus-cliked-on-node', e);
  542. _audioPlayer
  543. .emmit('stop-shuffle')
  544. .openDocument(e.target_node);
  545. });
  546. _randomPlayer = new RandomPlayer(e.playlist);
  547. _$body.attr('corpus-map', 'ready');
  548. }
  549. function openEntree(tid){
  550. if(tid){
  551. closeAllModals();
  552. _$body.removeClass();//.addClass(body_classes.join(' '));
  553. // open entree
  554. if(_corpus_ready){
  555. _$corpus_canvas.trigger({
  556. type:'open-entree',
  557. tid:tid
  558. });
  559. }else{
  560. // else : EdlpCorpus will check when ready if entry item (notice or index) is already .is-active
  561. $('li.entree[tid="'+tid+'"] a.term-link').addClass('is-active');
  562. }
  563. }
  564. };
  565. // _ _ _
  566. // /_\ _ _ __| (_)___
  567. // / _ \ || / _` | / _ \
  568. // /_/ \_\_,_\__,_|_\___/
  569. //
  570. // https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement
  571. // https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/samples/gg589528%28v%3dvs.85%29
  572. // https://www.binarytides.com/using-html5-audio-element-javascript/
  573. function AudioPlayer(){
  574. var that = this;
  575. this.fid;
  576. this.audio = new Audio();
  577. // audio events
  578. this.audio_events = ["loadedmetadata","canplay","playing","pause","timeupdate","ended"];
  579. // UI dom objects
  580. this.$container = $('<div id="audio-player">');
  581. // btns
  582. this.$btns = $('<div>').addClass('btns').appendTo(this.$container);
  583. this.$previous = $('<div>').addClass('previous').appendTo(this.$btns);
  584. this.$playpause = $('<div>').addClass('play-pause').appendTo(this.$btns);
  585. this.$next = $('<div>').addClass('next').appendTo(this.$btns);
  586. // timeline
  587. this.$timelinecont= $('<div>').addClass('time-line-container').appendTo(this.$container);
  588. this.$timeline = $('<div>').addClass('time-line').appendTo(this.$timelinecont);
  589. this.$loader = $('<div>').addClass('loader').appendTo(this.$timeline);
  590. this.$cursor = $('<div>').addClass('cursor').appendTo(this.$timeline);
  591. // time
  592. this.$time = $('<div>').addClass('time').appendTo(this.$container);
  593. this.$currentTime = $('<div>').addClass('current-time').html('00:00').appendTo(this.$time);
  594. this.$duration = $('<div>').addClass('duration').html('00:00').appendTo(this.$time);
  595. // favoris
  596. this.$fav = $('<div>').addClass('favoris').appendTo(this.$container);
  597. // cartel
  598. this.$cartel = $('<div>').addClass('cartel').appendTo(this.$container);
  599. // hiding
  600. this.hideTimer = false;
  601. this.hideTimeMS = 10000;
  602. // history
  603. this.currentHistoricIndex = null;
  604. this.historic = [];
  605. this.shuffle_is_active = false;
  606. // object events
  607. this.event_handlers = {
  608. 'audio-open-document':[],
  609. 'audio-play':[],
  610. 'audio-pause':[],
  611. 'audio-play-next':[],
  612. 'audio-ended':[],
  613. 'stop-shuffle':[]
  614. };
  615. this.init();
  616. };
  617. AudioPlayer.prototype = {
  618. init(){
  619. // append ui to document
  620. this.$container.appendTo('header[role="banner"] .region-header');
  621. // record timeline width
  622. this.timeline_w = parseInt(this.$timeline.width());
  623. // init audio events
  624. var fn = '';
  625. for (var i = 0; i < this.audio_events.length; i++) {
  626. fn = this.audio_events[i];
  627. // capitalize first letter of event (only cosmetic :p )
  628. fn = 'on'+fn.charAt(0).toUpperCase()+fn.slice(1);
  629. this.audio.addEventListener(
  630. this.audio_events[i],
  631. this[fn].bind(this),
  632. true);
  633. }
  634. // init btns events
  635. this.$previous.on('click', this.playPrevious.bind(this));
  636. this.$playpause.on('click', this.togglePlayPause.bind(this));
  637. this.$next.on('click', this.playNext.bind(this));
  638. },
  639. openDocument(node, caller, historic_index){
  640. // console.log('AudioPlayer openDocument', node);
  641. if(typeof node == 'undefined'
  642. || typeof node.nid == 'undefined'
  643. || typeof node.audio_url == 'undfined'){
  644. console.warn('AudioPlayer openDocument() node is malformed', node);
  645. return false;
  646. }
  647. // if we don't come from history popstate
  648. if(typeof caller == 'undefined' || caller != 'popstate'){
  649. this.historic.push(node);
  650. this.currentHistoricIndex = this.historic.length-1;
  651. // this.shuffle_mode = shuffle_mode || false;
  652. // add the document opening to history to be able to share and play audio from any where
  653. if(caller != "history_first_load"){
  654. state = {
  655. audio:true,
  656. node:node,
  657. historic_index : this.currentHistoricIndex,
  658. };
  659. history.pushState(state, null, node.document_url);
  660. }
  661. }else{
  662. // if the call commes from popstate, we update the current position of index
  663. this.currentHistoricIndex = historic_index;
  664. }
  665. this.emmit('audio-open-document', {caller:caller});
  666. this.launch();
  667. },
  668. launch(){
  669. this.clearTimeOutToHide();
  670. this.setSRC(this.historic[this.currentHistoricIndex].audio_url);
  671. this.loadNode(this.historic[this.currentHistoricIndex].nid);
  672. // emmit new playing doc (e.g.: corpus map nowing that audio played from RandomPlayer)
  673. try {
  674. _$corpus_canvas.trigger({
  675. 'type':'audio-node-opened',
  676. 'nid':this.historic[this.currentHistoricIndex].nid
  677. });
  678. } catch (e) {
  679. console.info('AudioPlayer : _$corpus_canvas does not exists');
  680. }
  681. this.showHidePreviousBtn();
  682. this.showHideNextBtn();
  683. this.show();
  684. },
  685. // audio functions
  686. setSRC(url){
  687. // console.log('AudioPlayer setSRC : url', url);
  688. this.audio.src = url;
  689. },
  690. onLoadedmetadata(){
  691. var rem = parseInt(this.audio.duration, 10),
  692. mins = Math.floor(rem/60,10),
  693. secs = rem - mins*60;
  694. this.$duration.html('<span>'+(mins<10 ? '0':'')+mins+':'+(secs<10 ? '0':'')+secs+'</span>');
  695. this.updateLoadingBar();
  696. },
  697. updateLoadingBar(){
  698. this.$loader.css({
  699. 'width':parseInt((100 * this.audio.buffered.end(0) / this.audio.duration), 10)+'%'
  700. });
  701. if( this.audio.buffered.end(0) < this.audio.duration ){
  702. // loop through this function until file is fully loaded
  703. var that = this;
  704. window.requestAnimationFrame(that.updateLoadingBar.bind(that));
  705. }else{
  706. //console.log('Audio fully loaded');
  707. }
  708. },
  709. onCanplay(){
  710. this.play();
  711. },
  712. play(){
  713. this.clearTimeOutToHide();
  714. this.audio.play();
  715. },
  716. playPrevious(){
  717. if(this.currentHistoricIndex > 0){
  718. this.currentHistoricIndex -= 1;
  719. this.launch();
  720. }
  721. },
  722. playNext(){
  723. if(this.currentHistoricIndex < this.historic.length-1){
  724. this.currentHistoricIndex += 1;
  725. this.launch();
  726. }else{
  727. this.emmit('audio-play-next');
  728. }
  729. },
  730. togglePlayPause(e){
  731. if(this.audio.paused){
  732. this.audio.play();
  733. }else{
  734. this.audio.pause();
  735. }
  736. },
  737. stop(){
  738. // console.log('AudioPlayer stop()');
  739. // debugger;
  740. this.audio.pause();
  741. // don't close player if article or transcript is open
  742. if(!_$body.is('.path-node-'+this.historic[this.currentHistoricIndex].nid)){
  743. this.timeOutToHide();
  744. }
  745. },
  746. // audio events
  747. onPlaying(){
  748. this.$btns.addClass('is-playing');
  749. this.emmit('audio-play');
  750. },
  751. onPause(){
  752. this.$btns.removeClass('is-playing');
  753. this.emmit('audio-pause');
  754. },
  755. onTimeupdate(){
  756. // move cursor
  757. this.$cursor.css({
  758. 'left':(this.audio.currentTime/this.audio.duration * this.timeline_w)+"px"
  759. });
  760. // update time text display
  761. var rem = parseInt(this.audio.currentTime, 10),
  762. mins = Math.floor(rem/60,10),
  763. secs = rem - mins*60;
  764. this.$currentTime.html('<span>'+(mins<10 ? '0':'')+mins+':'+(secs<10 ? '0':'')+secs+'</span>');
  765. },
  766. onEnded(){
  767. console.log('AudioPlayer onEnded()');
  768. this.emmit('audio-ended');
  769. this.stop();
  770. },
  771. // cartel functions
  772. loadNode(nid){
  773. this.$cartel.addClass('loading');
  774. var vm = 'player_cartel';
  775. var ajax_path = _ajax_settings.entityjson_path+'/node/'+nid+'/'+vm;
  776. var path = window.location.origin + Drupal.url(ajax_path);
  777. $.getJSON(path, {})
  778. .done(this.onNodeLoaded.bind(this))
  779. .fail(this.onNodeLoadFail.bind(this));
  780. },
  781. onNodeLoaded(data){
  782. // console.log('AudioPlayer node loaded');
  783. this.$cartel.html(data.rendered).removeClass('loading');
  784. _$body.trigger({'type':'new-audio-cartel-loaded'});
  785. initAjaxLinks();
  786. },
  787. onNodeLoadFail(jqxhr, textStatus, error){
  788. console.warn('AudioPlayer node load failed', jqxhr.responseText);
  789. this.$cartel.removeClass('loading').html('');
  790. },
  791. // global
  792. show(){
  793. this.$container.addClass('visible');
  794. },
  795. showHidePreviousBtn(){
  796. if(this.historic.length > 1 && this.currentHistoricIndex > 0){
  797. this.$previous.addClass('is-active');
  798. }else{
  799. this.$previous.removeClass('is-active');
  800. }
  801. },
  802. showHideNextBtn(){
  803. if(this.currentHistoricIndex < this.historic.length-1 || this.shuffle_is_active){
  804. this.$next.addClass('is-active');
  805. }else{
  806. this.$next.removeClass('is-active');
  807. }
  808. },
  809. timeOutToHide(){
  810. // console.log('AudioPlayer timeOutToHide()');
  811. this.clearTimeOutToHide();
  812. this.hideTimer = setTimeout(this.hide.bind(this), this.hideTimeMS);
  813. },
  814. clearTimeOutToHide(){
  815. // console.log('AudioPlayer clearTimeOutToHide()',this.hideTimer);
  816. if(this.hideTimer){
  817. clearTimeout(this.hideTimer);
  818. this.hideTimer = false;
  819. }
  820. },
  821. hide(){
  822. // console.log('AudioPlayer hide()');
  823. this.$container.removeClass('visible');
  824. // trigger highlighted node remove on corpus map
  825. try {
  826. _$corpus_canvas.trigger('audio-node-closed');
  827. } catch (e) {
  828. console.info('AudioPlayer hide() : _$corpus_canvas does not exists');
  829. }
  830. },
  831. // object events
  832. on(event_name, handler){
  833. if(typeof this.event_handlers[event_name] == 'undefined'){
  834. console.warn('AudioPlayer : event '+event_name+' does not exists');
  835. }
  836. this.event_handlers[event_name].push(handler);
  837. return this;
  838. },
  839. emmit(event_name, args){
  840. // console.log('AudioPlayer emmit() event_name', event_name);
  841. // console.log('AudioPlayer emmit() handlers', this.event_handlers[event_name]);
  842. var handler;
  843. var args = args || {};
  844. for (var i = this.event_handlers[event_name].length-1; i >= 0 ; i--) {
  845. handler = this.event_handlers[event_name][i];
  846. // console.log('AudioPlayer emmit() loop handler', handler);
  847. setTimeout(function(){
  848. // console.log('AudioPlayer emmit() timeout handler', handler);
  849. handler(args);
  850. }, 0);
  851. }
  852. return this;
  853. },
  854. }
  855. // ___ _ ___ _
  856. // | _ \__ _ _ _ __| |___ _ __ | _ \ |__ _ _ _ ___ _ _
  857. // | / _` | ' \/ _` / _ \ ' \| _/ / _` | || / -_) '_|
  858. // |_|_\__,_|_||_\__,_\___/_|_|_|_| |_\__,_|\_, \___|_|
  859. // |__/
  860. function RandomPlayer(playlist){
  861. this.active = false;
  862. this.playlist = playlist;
  863. this.$btn = $('<a>').html('Shuffle').addClass('random-player-btn');
  864. this.init();
  865. };
  866. RandomPlayer.prototype = {
  867. init(){
  868. // this.shuffle();
  869. $('<div>')
  870. .addClass('block random-player')
  871. .append(this.$btn)
  872. // .insertAfter('#block-userlogin, #block-studiolinkblock');
  873. .prependTo('.region-footer-right');
  874. // events
  875. this.$btn.on('click', this.toggleActive.bind(this));
  876. // attach an event on AudioPlayer
  877. _audioPlayer
  878. .on('audio-ended', this.onAudioPlayerEnded.bind(this))
  879. .on('audio-play-next', this.onAudioPlayNext.bind(this))
  880. .on('stop-shuffle', this.stop.bind(this));
  881. },
  882. shuffle(){
  883. var tempPLaylist = [];
  884. for (var i = this.playlist.length-1; i >= 0 ; i--) {
  885. tempPLaylist.push(this.playlist[i]);
  886. }
  887. this.shuffledPlaylist = [];
  888. while(tempPLaylist.length > 0){
  889. var r = Math.floor(Math.random() * tempPLaylist.length);
  890. this.shuffledPlaylist.push(tempPLaylist.splice(r,1)[0]);
  891. }
  892. //console.log('RandomPlayer, this.shuffledPlaylist', this.shuffledPlaylist);
  893. },
  894. toggleActive(e){
  895. if (this.active) {
  896. this.stop();
  897. }else{
  898. this.start();
  899. }
  900. },
  901. start(){
  902. this.active = _audioPlayer.shuffle_is_active = true;
  903. this.$btn.addClass('is-active');
  904. this.shuffle();
  905. this.next();
  906. },
  907. stop(){
  908. this.active = _audioPlayer.shuffle_is_active = false;
  909. this.$btn.removeClass('is-active');
  910. // stop audio player
  911. // _audioPlayer.stop();
  912. },
  913. next(){
  914. if(this.active && this.shuffledPlaylist.length > 0)
  915. _audioPlayer.openDocument(this.shuffledPlaylist.splice(0,1)[0]);
  916. },
  917. onAudioPlayNext(){
  918. //console.log('RandomPlayer : onAudioPlayNext()');
  919. this.next();
  920. },
  921. onAudioPlayerEnded(){
  922. //console.log('RandomPlayer : onAudioPlayerEnded()');
  923. this.next();
  924. }
  925. };
  926. // ___ ___ _
  927. // / __|___ _ __ _ __ ___| _ \ |__ _ _ _ ___ _ _
  928. // | (__/ _ \ ' \| '_ \/ _ \ _/ / _` | || / -_) '_|
  929. // \___\___/_|_|_| .__/\___/_| |_\__,_|\_, \___|_|
  930. // |_| |__/
  931. function CompoPlayer(){
  932. this.active = false;
  933. this.playing = false;
  934. this.paused = false;
  935. this.playlist = [];
  936. this.current_index = 0;
  937. this.$composer = null;
  938. this.$compo = null;
  939. this.$controls = null;
  940. this.init();
  941. };
  942. CompoPlayer.prototype = {
  943. init(){
  944. // console.log('CompoPlayer init()');
  945. // attach an event on AudioPlayer
  946. _audioPlayer
  947. .on('audio-open-document', this.onAudioOpenDocument.bind(this))
  948. .on('audio-play', this.onAudioPlayerPlay.bind(this))
  949. .on('audio-pause', this.onAudioPlayerPause.bind(this))
  950. .on('audio-ended', this.onAudioPlayerEnded.bind(this));
  951. // .on('audio-play-next', this.onAudioPlayNext.bind(this));
  952. // this.newCompo();
  953. },
  954. newCompo(){
  955. //console.log('CompoPlayer newCompo()');
  956. // this.$compo = $('.composition_ui .composer .composition');
  957. this.initControls();
  958. },
  959. initControls(){
  960. //console.log('CompoPlayer initControls()');
  961. this.$composer = $('.composition_ui .composer');
  962. this.$compo = $('.composition_ui .composer .composition');
  963. this.$controls = $('.composition_ui .composer .compo-player-controls');
  964. if(!this.$controls.is('.ready') && this.$compo){
  965. this.$previous = $('<div>').addClass('previous')
  966. .on('click', this.prev.bind(this))
  967. .appendTo(this.$controls);
  968. this.$playpause = $('<div>').addClass('play-pause')
  969. .on('click', this.togglePlayPause.bind(this))
  970. .appendTo(this.$controls);
  971. this.$next = $('<div>').addClass('next')
  972. .on('click', this.next.bind(this))
  973. .appendTo(this.$controls);
  974. this.$controls.addClass('ready');
  975. this.refresh();
  976. this.active = true;
  977. // this.newCompo();
  978. }
  979. },
  980. refresh(){
  981. // console.log('CompoPlayer refresh(), this', this);
  982. this.stop();
  983. // load new playlist
  984. this.playlist = [];
  985. var that = this;
  986. $('.field--name-documents .field__item',this.$compo).each(function(i,el){
  987. var $link = $('a.audio-link',this);
  988. that.playlist.push({
  989. item:$(this),
  990. audio_url:$link.attr("audio_url"),
  991. nid:$link.attr("nid"),
  992. });
  993. });
  994. this.showHideControls();
  995. },
  996. togglePlayPause(){
  997. // console.log('CompoPlayer togglePlayPause');
  998. if (this.playing && !this.paused) {
  999. this.pause();
  1000. }else{
  1001. if(this.playing && this.paused){
  1002. this.play();
  1003. }else{
  1004. this.start();
  1005. }
  1006. }
  1007. },
  1008. start(){
  1009. //console.log('start');
  1010. // console.log('CompoPlayer start()');
  1011. this.playing = true;
  1012. this.play();
  1013. },
  1014. play(){
  1015. // console.log('play');
  1016. if(this.paused){
  1017. this.paused = false;
  1018. _audioPlayer.play();
  1019. }else{
  1020. _audioPlayer.openDocument(this.playlist[this.current_index], this);
  1021. }
  1022. this.setActiveItem().showHideControls();
  1023. },
  1024. pause(){
  1025. //console.log('pause');
  1026. this.paused = true;
  1027. this.showHideControls();
  1028. _audioPlayer.stop();
  1029. },
  1030. next(){
  1031. // console.log('CompoPlayer next()');
  1032. if(this.playing){
  1033. this.current_index += 1;
  1034. if(this.current_index < this.playlist.length){
  1035. this.play();
  1036. }else{
  1037. this.stop();
  1038. }
  1039. }
  1040. },
  1041. prev(){
  1042. // console.log('CompoPlayer prev()');
  1043. if(this.playing){
  1044. this.current_index -= 1;
  1045. if(this.current_index >= 0){
  1046. this.play();
  1047. }else{
  1048. this.stop();
  1049. }
  1050. }
  1051. },
  1052. stop(){
  1053. if(this.playing){
  1054. _audioPlayer.stop();
  1055. }
  1056. this.reset();
  1057. },
  1058. reset(){
  1059. this.playing = false;
  1060. this.paused = false;
  1061. this.resetIndex();
  1062. },
  1063. resetIndex(){
  1064. this.current_index = 0;
  1065. this.showHideControls().resetActiveItems();
  1066. },
  1067. setActiveItem(){
  1068. this.resetActiveItems();
  1069. if(this.playing && this.current_index >= 0){
  1070. this.playlist[this.current_index].item.addClass('is-active');
  1071. }
  1072. // this call shoud not be here
  1073. this.showHideControls();
  1074. return this;
  1075. },
  1076. resetActiveItems(){
  1077. for (var n = 0; n < this.playlist.length; n++) {
  1078. // console.log('node',node);
  1079. this.playlist[n].item.removeClass('is-active');
  1080. }
  1081. return this;
  1082. },
  1083. showHideControls(){
  1084. // console.log('CompoPlayer showHideNextBtn(), playing:'+this.playing+', paused:'+this.paused);
  1085. // global playing
  1086. if(this.$controls){
  1087. if(this.playing && !this.paused){
  1088. this.$controls.addClass('is-playing');
  1089. }else{
  1090. this.$controls.removeClass('is-playing');
  1091. }
  1092. }
  1093. // playpause
  1094. if(this.$playpause){
  1095. if(this.playlist.length > 0){
  1096. this.$playpause.addClass('is-active');
  1097. }else{
  1098. this.$playpause.removeClass('is-active');
  1099. }
  1100. }
  1101. // next
  1102. if(this.$next){
  1103. if(this.playing && this.playlist.length > 1 && this.current_index < this.playlist.length -1){
  1104. this.$next.addClass('is-active');
  1105. }else{
  1106. this.$next.removeClass('is-active');
  1107. }
  1108. }
  1109. // previous
  1110. if(this.$previous){
  1111. if(this.playing && this.playlist.length > 1 && this.current_index > 0){
  1112. this.$previous.addClass('is-active');
  1113. }else{
  1114. this.$previous.removeClass('is-active');
  1115. }
  1116. }
  1117. return this;
  1118. },
  1119. deactivate(){
  1120. this.stop();
  1121. this.active = false;
  1122. },
  1123. // _audioPlayer events
  1124. onAudioOpenDocument(args){
  1125. if(args.caller !== this){
  1126. // console.log('CompoPlayer onAudioOpenDocument() called by other');
  1127. this.reset();
  1128. }
  1129. // else{
  1130. // // console.log('CompoPlayer onAudioOpenDocument() self calling');
  1131. // }
  1132. },
  1133. onAudioPlayerPlay(){
  1134. if(this.playing && this.paused){
  1135. this.paused = false;
  1136. this.showHideControls();
  1137. }
  1138. },
  1139. onAudioPlayerPause(){
  1140. if(this.playing && !this.paused){
  1141. this.paused = true;
  1142. this.showHideControls();
  1143. }
  1144. },
  1145. onAudioPlayerEnded(){
  1146. this.next();
  1147. },
  1148. // onAudioPlayNext(){
  1149. // this.next();
  1150. // }
  1151. };
  1152. // ___ _ ___
  1153. // | __| _ ___ _ _| |_| _ \__ _ __ _ ___
  1154. // | _| '_/ _ \ ' \ _| _/ _` / _` / -_)
  1155. // |_||_| \___/_||_\__|_| \__,_\__, \___|
  1156. // |___/
  1157. function backToFrontPage(pop_state){
  1158. console.log('backToFrontPage', pop_state);
  1159. closeAllModals();
  1160. // assume we are going back to front page
  1161. $('body').removeClass().addClass('path-frontpage');
  1162. $('a[data-drupal-link-system-path="<front>"]').addClass('is-active');
  1163. // close entrees
  1164. _$corpus_canvas.trigger({'type':'close-all-entree'});
  1165. if(typeof pop_state == "undefined" || !pop_state){
  1166. console.log('backToFrontPage push state');
  1167. history.pushState({home:true}, null, drupalSettings.path.baseUrl+drupalSettings.path.currentLanguage);
  1168. }
  1169. }
  1170. function initHome(){
  1171. addCloseModalBtnToCols();
  1172. // console.log('theme : initHome');
  1173. // console.log('theme : initProductions');
  1174. var $grid = $('.grid',_$row).masonry({
  1175. itemSelector:'.col',
  1176. columnWidth:'.col-2',
  1177. horizontalOrder: true,
  1178. containerStyle: null,
  1179. // disable initial layout
  1180. // initLayout: false,
  1181. });
  1182. // bind event
  1183. // $grid.masonry( 'on', 'layoutComplete', function() {
  1184. // console.log('layout is complete');
  1185. // });
  1186. // layout Masonry after each image loads
  1187. $grid.imagesLoaded().progress( function() {
  1188. $grid.masonry('layout');
  1189. });
  1190. $grid.imagesLoaded(function(){
  1191. $grid.masonry('layout');
  1192. });
  1193. }
  1194. // ___ _ _ _
  1195. // | _ \_ _ ___ __| |_ _ __| |_(_)___ _ _ ___
  1196. // | _/ '_/ _ \/ _` | || / _| _| / _ \ ' \(_-<
  1197. // |_| |_| \___/\__,_|\_,_\__|\__|_\___/_||_/__/
  1198. function initProductions(){
  1199. // console.log('theme : initProductions');
  1200. var $grid = $('.grid',_$row).masonry({
  1201. itemSelector:'.col',
  1202. columnWidth:'.col-2',
  1203. horizontalOrder: true,
  1204. containerStyle: null,
  1205. // disable initial layout
  1206. // initLayout: false,
  1207. });
  1208. // bind event
  1209. // $grid.masonry( 'on', 'layoutComplete', function() {
  1210. // console.log('layout is complete');
  1211. // });
  1212. // layout Masonry after each image loads
  1213. $grid.imagesLoaded().progress( function() {
  1214. $grid.masonry('layout');
  1215. });
  1216. $grid.imagesLoaded(function(){
  1217. $grid.masonry('layout');
  1218. });
  1219. };
  1220. // ___ _ _ _
  1221. // | __|_ _ _ _ ___ __ _(_)__| |_ _ _ ___ _ __ ___ _ _| |_
  1222. // | _|| ' \| '_/ -_) _` | (_-< _| '_/ -_) ' \/ -_) ' \ _|
  1223. // |___|_||_|_| \___\__, |_/__/\__|_| \___|_|_|_\___|_||_\__|
  1224. // |___/
  1225. function initEnregistrementTranscript(){
  1226. console.log('initEnregistrementTranscript');
  1227. var $node = _$row.find('article.node--type-enregistrement.node--view-mode-transcript');
  1228. var $nav = $('<nav>').prependTo($node);
  1229. $node.find('.field--name-field-transcript-vo').addClass('visible').find('.field__label')
  1230. .clone().appendTo($nav).addClass('is-active')
  1231. .attr('field_target', '.field--name-field-transcript-vo');
  1232. $node.find('.field--name-field-transcript-trad').find('.field__label')
  1233. .clone().appendTo($nav)
  1234. .attr('field_target', '.field--name-field-transcript-trad');
  1235. $nav.find('.field__label').on('click', function(){
  1236. var $this = $(this).addClass('is-active');
  1237. $this.siblings('.is-active').removeClass('is-active');
  1238. $this.parents('article.node').find('.field.visible').removeClass('visible');
  1239. $this.parents('article.node').find($this.attr('field_target')).addClass('visible');
  1240. });
  1241. };
  1242. // __ __ _ _
  1243. // | \/ |___ __| |__ _| |___
  1244. // | |\/| / _ \/ _` / _` | (_-<
  1245. // |_| |_\___/\__,_\__,_|_/__/
  1246. function closeAllModals(){
  1247. //console.log('theme : closeAllModals');
  1248. // TODO: animate the remove
  1249. _$row.html('');
  1250. _$ajaxLinks.removeClass('is-active');
  1251. _$body.trigger({'type':'all-modal-closed'});
  1252. };
  1253. // _ _ _
  1254. // | || |___| |_ __ ___ _ _ ___
  1255. // | __ / -_) | '_ \/ -_) '_(_-<
  1256. // |_||_\___|_| .__/\___|_| /__/
  1257. // |_|
  1258. // https://plainjs.com/javascript/utilities/set-cookie-get-cookie-and-delete-cookie-5/
  1259. // function getCookie(name) {
  1260. // var v = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');
  1261. // return v ? v[2] : null;
  1262. // }
  1263. // function setCookie(name, value, days) {
  1264. // var d = new Date;
  1265. // d.setTime(d.getTime() + 24*60*60*1000*days);
  1266. // document.cookie = name + "=" + value + ";path=/;expires=" + d.toGMTString();
  1267. // }
  1268. // function deleteCookie(name) { setCookie(name, '', -1); }
  1269. init();
  1270. } // end EdlpTheme()
  1271. $(document).ready(function($) {
  1272. if(drupalSettings.path.isFront){
  1273. var edlptheme = new EdlpTheme();
  1274. }
  1275. });
  1276. })(jQuery, Drupal, drupalSettings);