main.js 45 KB

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