main.js 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338
  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 != null && 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. // we don't laod ajax content so we boot the home
  369. _$body.attr('booted', 'booted');
  370. }else{
  371. // ajax load content for audio only if article or transcript
  372. ajaxLoadContent(state);
  373. }
  374. }
  375. // only if not entree path
  376. // only if not audio (without article or transcript) path
  377. else if(state.ajax_path){
  378. // load content through ajax
  379. // ajaxLoadContent(null, state.sys_path, state.ajax_path, selector);
  380. ajaxLoadContent(state);
  381. }
  382. if(state.entree_tid){
  383. openEntree(state.entree_tid);
  384. }
  385. // record history state
  386. history.replaceState(state, null, edlp_origin.url+edlp_origin.hash);
  387. // reset the storage
  388. window.localStorage.removeItem("edlp_origin");
  389. // window.localStorage.removeItem("edlp_origin_url");
  390. }else{
  391. history.replaceState({home:true}, null, window.location.pathname);
  392. _$body.attr('booted', 'booted');
  393. }
  394. };
  395. function onHistoryPopState(e){
  396. console.log('onPopState',e.state);
  397. if(e.state.home){
  398. backToFrontPage(true);
  399. }
  400. else if (e.state.audio) {
  401. _audioPlayer.openDocument(e.state.node, 'popstate', e.state.historic_index);
  402. }
  403. else{
  404. if(e.state.entree_tid){
  405. openEntree(e.state.entree_tid);
  406. }
  407. if(e.state.ajax_path){
  408. e.state.url = null;
  409. // ajaxLoadContent(null, e.state.sys_path, e.state.ajax_path)
  410. ajaxLoadContent(e.state);
  411. }
  412. }
  413. };
  414. // _ _ _ _ _
  415. // /_\ (_)__ ___ _| | (_)_ _ | |__ ___
  416. // / _ \ | / _` \ \ / |__| | ' \| / /(_-<
  417. // /_/ \_\/ \__,_/_\_\____|_|_||_|_\_\/__/
  418. // |__/
  419. function initAjaxLinks(){
  420. // console.log('initAjaxLinks');
  421. $('a.site-name', '#block-edlptheme-branding')
  422. .add('a', '#block-mainnavigation')
  423. // .add('a', '.block.language-switcher-language-url')
  424. .add('a', '#block-footer.menu--footer')
  425. .add('a', '#block-productions')
  426. .add('a', 'article.node:not(.node--type-enregistrement) h2.node-title')
  427. .add('a', '.productions-subtree')
  428. .add('a', '.productions-parent')
  429. // .add('a.index-link, a.notice-link', '#block-edlpentreesblock')
  430. .addClass('ajax-link');
  431. _$ajaxLinks = $('.ajax-link:not(.ajax-enabled)')
  432. .each(function(i,e){
  433. var $this = $(this);
  434. // avoid already ajaxified links
  435. if($this.is('.ajax-enable')) return;
  436. if($this.attr('data-drupal-link-system-path')){
  437. $this.on('click', onClickAjaxLink).addClass('ajax-enable');
  438. }
  439. });
  440. };
  441. function onClickAjaxLink(e){
  442. e.preventDefault();
  443. var $link = $(this);
  444. if($link.is('.is-active'))
  445. return false;
  446. // Audio links
  447. // launch audio player and stop here
  448. if($link.is('.audio-link')){
  449. _audioPlayer
  450. .emmit('stop-shuffle')
  451. .openDocument({
  452. nid:$link.attr('nid'),
  453. audio_url:$link.attr('audio_url')
  454. });
  455. return false;
  456. }
  457. // NOT USED (YET)
  458. // if($link.is('.language-link')){
  459. // TODO: change global site current language
  460. // load all blocks translated (exepted language switcher) ... :/
  461. // refreshAllBlocks();
  462. // TODO: use a promise to initAjaxLinks again after blocks updated
  463. // then let load the content
  464. // }
  465. // other links
  466. var sys_path = $(this).attr('data-drupal-link-system-path');
  467. // front page
  468. // just remove contents and stop here
  469. if(sys_path == '<front>'){
  470. backToFrontPage();
  471. return false;
  472. }
  473. var view_mode = $link.attr('viewmode');
  474. var state = getSysPathState(sys_path, view_mode);
  475. state.url = $(this).attr('href');
  476. if(view_mode){
  477. state.url += "#"+view_mode;
  478. }
  479. if($link.is('[selector]')){
  480. state.selector = $link.attr('selector');
  481. }
  482. $link.addClass('ajax-loading');
  483. // ajaxLoadContent(url, sys_path, state.ajax_path, selector);
  484. ajaxLoadContent(state);
  485. return false;
  486. };
  487. // ___
  488. // / __|___ _ _ _ __ _ _ ___
  489. // | (__/ _ \ '_| '_ \ || (_-<
  490. // \___\___/_| | .__/\_,_/__/
  491. // |_|
  492. function onCorpusMapReady(e){
  493. //console.log('theme : onCorpusReady', e);
  494. _corpus_ready = true;
  495. _$corpus_canvas = $('canvas#corpus-map');
  496. _$corpus_canvas
  497. .on('corpus-cliked-on-map', function(e) {
  498. //console.log('theme : corpus-cliked-on-map');
  499. backToFrontPage();
  500. })
  501. .on('corpus-cliked-on-node', function(e) {
  502. //console.log('theme : corpus-cliked-on-node', e);
  503. _audioPlayer
  504. .emmit('stop-shuffle')
  505. .openDocument(e.target_node);
  506. });
  507. _randomPlayer = new RandomPlayer(e.playlist);
  508. _$body.attr('corpus-map', 'ready');
  509. }
  510. function openEntree(tid){
  511. if(tid){
  512. closeAllModals();
  513. _$body.removeClass();//.addClass(body_classes.join(' '));
  514. // open entree
  515. if(_corpus_ready){
  516. _$corpus_canvas.trigger({
  517. type:'open-entree',
  518. tid:tid
  519. });
  520. }else{
  521. // else : EdlpCorpus will check when ready if entry item (notice or index) is already .is-active
  522. $('li.entree[tid="'+tid+'"] a.term-link').addClass('is-active');
  523. }
  524. }
  525. };
  526. // _ _ _
  527. // /_\ _ _ __| (_)___
  528. // / _ \ || / _` | / _ \
  529. // /_/ \_\_,_\__,_|_\___/
  530. //
  531. // https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement
  532. // https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/samples/gg589528%28v%3dvs.85%29
  533. // https://www.binarytides.com/using-html5-audio-element-javascript/
  534. function AudioPlayer(){
  535. var that = this;
  536. this.fid;
  537. this.audio = new Audio();
  538. // audio events
  539. this.audio_events = ["loadedmetadata","canplay","playing","pause","timeupdate","ended"];
  540. // UI dom objects
  541. this.$container = $('<div id="audio-player">');
  542. // btns
  543. this.$btns = $('<div>').addClass('btns').appendTo(this.$container);
  544. this.$previous = $('<div>').addClass('previous').appendTo(this.$btns);
  545. this.$playpause = $('<div>').addClass('play-pause').appendTo(this.$btns);
  546. this.$next = $('<div>').addClass('next').appendTo(this.$btns);
  547. // timeline
  548. this.$timelinecont= $('<div>').addClass('time-line-container').appendTo(this.$container);
  549. this.$timeline = $('<div>').addClass('time-line').appendTo(this.$timelinecont);
  550. this.$loader = $('<div>').addClass('loader').appendTo(this.$timeline);
  551. this.$cursor = $('<div>').addClass('cursor').appendTo(this.$timeline);
  552. // time
  553. this.$time = $('<div>').addClass('time').appendTo(this.$container);
  554. this.$currentTime = $('<div>').addClass('current-time').html('00:00').appendTo(this.$time);
  555. this.$duration = $('<div>').addClass('duration').html('00:00').appendTo(this.$time);
  556. // favoris
  557. this.$fav = $('<div>').addClass('favoris').appendTo(this.$container);
  558. // cartel
  559. this.$cartel = $('<div>').addClass('cartel').appendTo(this.$container);
  560. // hiding
  561. this.hideTimer = false;
  562. this.hideTimeMS = 10000;
  563. // history
  564. this.currentHistoricIndex = null;
  565. this.historic = [];
  566. this.shuffle_is_active = false;
  567. // object events
  568. this.event_handlers = {
  569. 'audio-open-document':[],
  570. 'audio-play':[],
  571. 'audio-pause':[],
  572. 'audio-play-next':[],
  573. 'audio-ended':[],
  574. 'stop-shuffle':[]
  575. };
  576. this.init();
  577. };
  578. AudioPlayer.prototype = {
  579. init(){
  580. // append ui to document
  581. this.$container.appendTo('header[role="banner"] .region-header');
  582. // record timeline width
  583. this.timeline_w = parseInt(this.$timeline.width());
  584. // init audio events
  585. var fn = '';
  586. for (var i = 0; i < this.audio_events.length; i++) {
  587. fn = this.audio_events[i];
  588. // capitalize first letter of event (only cosmetic :p )
  589. fn = 'on'+fn.charAt(0).toUpperCase()+fn.slice(1);
  590. this.audio.addEventListener(
  591. this.audio_events[i],
  592. this[fn].bind(this),
  593. true);
  594. }
  595. // init btns events
  596. this.$previous.on('click', this.playPrevious.bind(this));
  597. this.$playpause.on('click', this.togglePlayPause.bind(this));
  598. this.$next.on('click', this.playNext.bind(this));
  599. },
  600. openDocument(node, caller, historic_index){
  601. // console.log('AudioPlayer openDocument', node);
  602. if(typeof node == 'undefined'
  603. || typeof node.nid == 'undefined'
  604. || typeof node.audio_url == 'undfined'){
  605. console.warn('AudioPlayer openDocument() node is malformed', node);
  606. return false;
  607. }
  608. // if we don't come from history popstate
  609. if(typeof caller == 'undefined' || caller != 'popstate'){
  610. this.historic.push(node);
  611. this.currentHistoricIndex = this.historic.length-1;
  612. // this.shuffle_mode = shuffle_mode || false;
  613. // add the document opening to history to be able to share and play audio from any where
  614. if(caller != "history_first_load"){
  615. state = {
  616. audio:true,
  617. node:node,
  618. historic_index : this.currentHistoricIndex,
  619. };
  620. history.pushState(state, null, node.document_url);
  621. }
  622. }else{
  623. // if the call commes from popstate, we update the current position of index
  624. this.currentHistoricIndex = historic_index;
  625. }
  626. this.emmit('audio-open-document', {caller:caller});
  627. this.launch();
  628. },
  629. launch(){
  630. this.clearTimeOutToHide();
  631. this.setSRC(this.historic[this.currentHistoricIndex].audio_url);
  632. this.loadNode(this.historic[this.currentHistoricIndex].nid);
  633. // emmit new playing doc (e.g.: corpus map nowing that audio played from RandomPlayer)
  634. try {
  635. _$corpus_canvas.trigger({
  636. 'type':'audio-node-opened',
  637. 'nid':this.historic[this.currentHistoricIndex].nid
  638. });
  639. } catch (e) {
  640. console.info('AudioPlayer : _$corpus_canvas does not exists');
  641. }
  642. this.showHidePreviousBtn();
  643. this.showHideNextBtn();
  644. this.show();
  645. },
  646. // audio functions
  647. setSRC(url){
  648. // console.log('AudioPlayer setSRC : url', url);
  649. this.audio.src = url;
  650. },
  651. onLoadedmetadata(){
  652. var rem = parseInt(this.audio.duration, 10),
  653. mins = Math.floor(rem/60,10),
  654. secs = rem - mins*60;
  655. this.$duration.html('<span>'+(mins<10 ? '0':'')+mins+':'+(secs<10 ? '0':'')+secs+'</span>');
  656. this.updateLoadingBar();
  657. },
  658. updateLoadingBar(){
  659. this.$loader.css({
  660. 'width':parseInt((100 * this.audio.buffered.end(0) / this.audio.duration), 10)+'%'
  661. });
  662. if( this.audio.buffered.end(0) < this.audio.duration ){
  663. // loop through this function until file is fully loaded
  664. var that = this;
  665. window.requestAnimationFrame(that.updateLoadingBar.bind(that));
  666. }else{
  667. //console.log('Audio fully loaded');
  668. }
  669. },
  670. onCanplay(){
  671. this.play();
  672. },
  673. play(){
  674. this.clearTimeOutToHide();
  675. this.audio.play();
  676. },
  677. playPrevious(){
  678. if(this.currentHistoricIndex > 0){
  679. this.currentHistoricIndex -= 1;
  680. this.launch();
  681. }
  682. },
  683. playNext(){
  684. if(this.currentHistoricIndex < this.historic.length-1){
  685. this.currentHistoricIndex += 1;
  686. this.launch();
  687. }else{
  688. this.emmit('audio-play-next');
  689. }
  690. },
  691. togglePlayPause(e){
  692. if(this.audio.paused){
  693. this.audio.play();
  694. }else{
  695. this.audio.pause();
  696. }
  697. },
  698. stop(){
  699. // console.log('AudioPlayer stop()');
  700. // debugger;
  701. this.audio.pause();
  702. // don't close player if article or transcript is open
  703. if(!_$body.is('.path-node-'+this.historic[this.currentHistoricIndex].nid)){
  704. this.timeOutToHide();
  705. }
  706. },
  707. // audio events
  708. onPlaying(){
  709. this.$btns.addClass('is-playing');
  710. this.emmit('audio-play');
  711. },
  712. onPause(){
  713. this.$btns.removeClass('is-playing');
  714. this.emmit('audio-pause');
  715. },
  716. onTimeupdate(){
  717. // move cursor
  718. this.$cursor.css({
  719. 'left':(this.audio.currentTime/this.audio.duration * this.timeline_w)+"px"
  720. });
  721. // update time text display
  722. var rem = parseInt(this.audio.currentTime, 10),
  723. mins = Math.floor(rem/60,10),
  724. secs = rem - mins*60;
  725. this.$currentTime.html('<span>'+(mins<10 ? '0':'')+mins+':'+(secs<10 ? '0':'')+secs+'</span>');
  726. },
  727. onEnded(){
  728. console.log('AudioPlayer onEnded()');
  729. this.emmit('audio-ended');
  730. this.stop();
  731. },
  732. // cartel functions
  733. loadNode(nid){
  734. this.$cartel.addClass('loading');
  735. var vm = 'player_cartel';
  736. var ajax_path = _ajax_settings.entityjson_path+'/node/'+nid+'/'+vm;
  737. var path = window.location.origin + Drupal.url(ajax_path);
  738. $.getJSON(path, {})
  739. .done(this.onNodeLoaded.bind(this))
  740. .fail(this.onNodeLoadFail.bind(this));
  741. },
  742. onNodeLoaded(data){
  743. // console.log('AudioPlayer node loaded');
  744. this.$cartel.html(data.rendered).removeClass('loading');
  745. _$body.trigger({'type':'new-audio-cartel-loaded'});
  746. initAjaxLinks();
  747. },
  748. onNodeLoadFail(jqxhr, textStatus, error){
  749. console.warn('AudioPlayer node load failed', jqxhr.responseText);
  750. this.$cartel.removeClass('loading').html('');
  751. },
  752. // global
  753. show(){
  754. this.$container.addClass('visible');
  755. },
  756. showHidePreviousBtn(){
  757. if(this.historic.length > 1 && this.currentHistoricIndex > 0){
  758. this.$previous.addClass('is-active');
  759. }else{
  760. this.$previous.removeClass('is-active');
  761. }
  762. },
  763. showHideNextBtn(){
  764. if(this.currentHistoricIndex < this.historic.length-1 || this.shuffle_is_active){
  765. this.$next.addClass('is-active');
  766. }else{
  767. this.$next.removeClass('is-active');
  768. }
  769. },
  770. timeOutToHide(){
  771. // console.log('AudioPlayer timeOutToHide()');
  772. this.clearTimeOutToHide();
  773. this.hideTimer = setTimeout(this.hide.bind(this), this.hideTimeMS);
  774. },
  775. clearTimeOutToHide(){
  776. // console.log('AudioPlayer clearTimeOutToHide()',this.hideTimer);
  777. if(this.hideTimer){
  778. clearTimeout(this.hideTimer);
  779. this.hideTimer = false;
  780. }
  781. },
  782. hide(){
  783. // console.log('AudioPlayer hide()');
  784. this.$container.removeClass('visible');
  785. // trigger highlighted node remove on corpus map
  786. try {
  787. _$corpus_canvas.trigger('audio-node-closed');
  788. } catch (e) {
  789. console.info('AudioPlayer hide() : _$corpus_canvas does not exists');
  790. }
  791. },
  792. // object events
  793. on(event_name, handler){
  794. if(typeof this.event_handlers[event_name] == 'undefined'){
  795. console.warn('AudioPlayer : event '+event_name+' does not exists');
  796. }
  797. this.event_handlers[event_name].push(handler);
  798. return this;
  799. },
  800. emmit(event_name, args){
  801. // console.log('AudioPlayer emmit() event_name', event_name);
  802. // console.log('AudioPlayer emmit() handlers', this.event_handlers[event_name]);
  803. var handler;
  804. var args = args || {};
  805. for (var i = this.event_handlers[event_name].length-1; i >= 0 ; i--) {
  806. handler = this.event_handlers[event_name][i];
  807. // console.log('AudioPlayer emmit() loop handler', handler);
  808. setTimeout(function(){
  809. // console.log('AudioPlayer emmit() timeout handler', handler);
  810. handler(args);
  811. }, 0);
  812. }
  813. return this;
  814. },
  815. }
  816. // ___ _ ___ _
  817. // | _ \__ _ _ _ __| |___ _ __ | _ \ |__ _ _ _ ___ _ _
  818. // | / _` | ' \/ _` / _ \ ' \| _/ / _` | || / -_) '_|
  819. // |_|_\__,_|_||_\__,_\___/_|_|_|_| |_\__,_|\_, \___|_|
  820. // |__/
  821. function RandomPlayer(playlist){
  822. this.active = false;
  823. this.playlist = playlist;
  824. this.$btn = $('<a>').html('Shuffle').addClass('random-player-btn');
  825. this.init();
  826. };
  827. RandomPlayer.prototype = {
  828. init(){
  829. // this.shuffle();
  830. $('<div>')
  831. .addClass('block random-player')
  832. .append(this.$btn)
  833. // .insertAfter('#block-userlogin, #block-studiolinkblock');
  834. .prependTo('.region-footer-right');
  835. // events
  836. this.$btn.on('click', this.toggleActive.bind(this));
  837. // attach an event on AudioPlayer
  838. _audioPlayer
  839. .on('audio-ended', this.onAudioPlayerEnded.bind(this))
  840. .on('audio-play-next', this.onAudioPlayNext.bind(this))
  841. .on('stop-shuffle', this.stop.bind(this));
  842. },
  843. shuffle(){
  844. var tempPLaylist = [];
  845. for (var i = this.playlist.length-1; i >= 0 ; i--) {
  846. tempPLaylist.push(this.playlist[i]);
  847. }
  848. this.shuffledPlaylist = [];
  849. while(tempPLaylist.length > 0){
  850. var r = Math.floor(Math.random() * tempPLaylist.length);
  851. this.shuffledPlaylist.push(tempPLaylist.splice(r,1)[0]);
  852. }
  853. //console.log('RandomPlayer, this.shuffledPlaylist', this.shuffledPlaylist);
  854. },
  855. toggleActive(e){
  856. if (this.active) {
  857. this.stop();
  858. }else{
  859. this.start();
  860. }
  861. },
  862. start(){
  863. this.active = _audioPlayer.shuffle_is_active = true;
  864. this.$btn.addClass('is-active');
  865. this.shuffle();
  866. this.next();
  867. },
  868. stop(){
  869. this.active = _audioPlayer.shuffle_is_active = false;
  870. this.$btn.removeClass('is-active');
  871. // stop audio player
  872. // _audioPlayer.stop();
  873. },
  874. next(){
  875. if(this.active && this.shuffledPlaylist.length > 0)
  876. _audioPlayer.openDocument(this.shuffledPlaylist.splice(0,1)[0]);
  877. },
  878. onAudioPlayNext(){
  879. //console.log('RandomPlayer : onAudioPlayNext()');
  880. this.next();
  881. },
  882. onAudioPlayerEnded(){
  883. //console.log('RandomPlayer : onAudioPlayerEnded()');
  884. this.next();
  885. }
  886. };
  887. // ___ ___ _
  888. // / __|___ _ __ _ __ ___| _ \ |__ _ _ _ ___ _ _
  889. // | (__/ _ \ ' \| '_ \/ _ \ _/ / _` | || / -_) '_|
  890. // \___\___/_|_|_| .__/\___/_| |_\__,_|\_, \___|_|
  891. // |_| |__/
  892. function CompoPlayer(){
  893. this.active = false;
  894. this.playing = false;
  895. this.paused = false;
  896. this.playlist = [];
  897. this.current_index = 0;
  898. this.$composer = null;
  899. this.$compo = null;
  900. this.$controls = null;
  901. this.init();
  902. };
  903. CompoPlayer.prototype = {
  904. init(){
  905. // console.log('CompoPlayer init()');
  906. // attach an event on AudioPlayer
  907. _audioPlayer
  908. .on('audio-open-document', this.onAudioOpenDocument.bind(this))
  909. .on('audio-play', this.onAudioPlayerPlay.bind(this))
  910. .on('audio-pause', this.onAudioPlayerPause.bind(this))
  911. .on('audio-ended', this.onAudioPlayerEnded.bind(this));
  912. // .on('audio-play-next', this.onAudioPlayNext.bind(this));
  913. // this.newCompo();
  914. },
  915. newCompo(){
  916. //console.log('CompoPlayer newCompo()');
  917. // this.$compo = $('.composition_ui .composer .composition');
  918. this.initControls();
  919. },
  920. initControls(){
  921. //console.log('CompoPlayer initControls()');
  922. this.$composer = $('.composition_ui .composer');
  923. this.$compo = $('.composition_ui .composer .composition');
  924. this.$controls = $('.composition_ui .composer .compo-player-controls');
  925. if(!this.$controls.is('.ready') && this.$compo){
  926. this.$previous = $('<div>').addClass('previous')
  927. .on('click', this.prev.bind(this))
  928. .appendTo(this.$controls);
  929. this.$playpause = $('<div>').addClass('play-pause')
  930. .on('click', this.togglePlayPause.bind(this))
  931. .appendTo(this.$controls);
  932. this.$next = $('<div>').addClass('next')
  933. .on('click', this.next.bind(this))
  934. .appendTo(this.$controls);
  935. this.$controls.addClass('ready');
  936. this.refresh();
  937. this.active = true;
  938. // this.newCompo();
  939. }
  940. },
  941. refresh(){
  942. // console.log('CompoPlayer refresh(), this', this);
  943. this.stop();
  944. // load new playlist
  945. this.playlist = [];
  946. var that = this;
  947. $('.field--name-documents .field__item',this.$compo).each(function(i,el){
  948. var $link = $('a.audio-link',this);
  949. that.playlist.push({
  950. item:$(this),
  951. audio_url:$link.attr("audio_url"),
  952. nid:$link.attr("nid"),
  953. });
  954. });
  955. this.showHideControls();
  956. },
  957. togglePlayPause(){
  958. // console.log('CompoPlayer togglePlayPause');
  959. if (this.playing && !this.paused) {
  960. this.pause();
  961. }else{
  962. if(this.playing && this.paused){
  963. this.play();
  964. }else{
  965. this.start();
  966. }
  967. }
  968. },
  969. start(){
  970. //console.log('start');
  971. // console.log('CompoPlayer start()');
  972. this.playing = true;
  973. this.play();
  974. },
  975. play(){
  976. // console.log('play');
  977. if(this.paused){
  978. this.paused = false;
  979. _audioPlayer.play();
  980. }else{
  981. _audioPlayer.openDocument(this.playlist[this.current_index], this);
  982. }
  983. this.setActiveItem().showHideControls();
  984. },
  985. pause(){
  986. //console.log('pause');
  987. this.paused = true;
  988. this.showHideControls();
  989. _audioPlayer.stop();
  990. },
  991. next(){
  992. // console.log('CompoPlayer next()');
  993. if(this.playing){
  994. this.current_index += 1;
  995. if(this.current_index < this.playlist.length){
  996. this.play();
  997. }else{
  998. this.stop();
  999. }
  1000. }
  1001. },
  1002. prev(){
  1003. // console.log('CompoPlayer prev()');
  1004. if(this.playing){
  1005. this.current_index -= 1;
  1006. if(this.current_index >= 0){
  1007. this.play();
  1008. }else{
  1009. this.stop();
  1010. }
  1011. }
  1012. },
  1013. stop(){
  1014. if(this.playing){
  1015. _audioPlayer.stop();
  1016. }
  1017. this.reset();
  1018. },
  1019. reset(){
  1020. this.playing = false;
  1021. this.paused = false;
  1022. this.resetIndex();
  1023. },
  1024. resetIndex(){
  1025. this.current_index = 0;
  1026. this.showHideControls().resetActiveItems();
  1027. },
  1028. setActiveItem(){
  1029. this.resetActiveItems();
  1030. if(this.playing && this.current_index >= 0){
  1031. this.playlist[this.current_index].item.addClass('is-active');
  1032. }
  1033. // this call shoud not be here
  1034. this.showHideControls();
  1035. return this;
  1036. },
  1037. resetActiveItems(){
  1038. for (var n = 0; n < this.playlist.length; n++) {
  1039. // console.log('node',node);
  1040. this.playlist[n].item.removeClass('is-active');
  1041. }
  1042. return this;
  1043. },
  1044. showHideControls(){
  1045. // console.log('CompoPlayer showHideNextBtn(), playing:'+this.playing+', paused:'+this.paused);
  1046. // global playing
  1047. if(this.$controls){
  1048. if(this.playing && !this.paused){
  1049. this.$controls.addClass('is-playing');
  1050. }else{
  1051. this.$controls.removeClass('is-playing');
  1052. }
  1053. }
  1054. // playpause
  1055. if(this.$playpause){
  1056. if(this.playlist.length > 0){
  1057. this.$playpause.addClass('is-active');
  1058. }else{
  1059. this.$playpause.removeClass('is-active');
  1060. }
  1061. }
  1062. // next
  1063. if(this.$next){
  1064. if(this.playing && this.playlist.length > 1 && this.current_index < this.playlist.length -1){
  1065. this.$next.addClass('is-active');
  1066. }else{
  1067. this.$next.removeClass('is-active');
  1068. }
  1069. }
  1070. // previous
  1071. if(this.$previous){
  1072. if(this.playing && this.playlist.length > 1 && this.current_index > 0){
  1073. this.$previous.addClass('is-active');
  1074. }else{
  1075. this.$previous.removeClass('is-active');
  1076. }
  1077. }
  1078. return this;
  1079. },
  1080. deactivate(){
  1081. this.stop();
  1082. this.active = false;
  1083. },
  1084. // _audioPlayer events
  1085. onAudioOpenDocument(args){
  1086. if(args.caller !== this){
  1087. // console.log('CompoPlayer onAudioOpenDocument() called by other');
  1088. this.reset();
  1089. }
  1090. // else{
  1091. // // console.log('CompoPlayer onAudioOpenDocument() self calling');
  1092. // }
  1093. },
  1094. onAudioPlayerPlay(){
  1095. if(this.playing && this.paused){
  1096. this.paused = false;
  1097. this.showHideControls();
  1098. }
  1099. },
  1100. onAudioPlayerPause(){
  1101. if(this.playing && !this.paused){
  1102. this.paused = true;
  1103. this.showHideControls();
  1104. }
  1105. },
  1106. onAudioPlayerEnded(){
  1107. this.next();
  1108. },
  1109. // onAudioPlayNext(){
  1110. // this.next();
  1111. // }
  1112. };
  1113. // ___ _ ___
  1114. // | __| _ ___ _ _| |_| _ \__ _ __ _ ___
  1115. // | _| '_/ _ \ ' \ _| _/ _` / _` / -_)
  1116. // |_||_| \___/_||_\__|_| \__,_\__, \___|
  1117. // |___/
  1118. function backToFrontPage(pop_state){
  1119. closeAllModals();
  1120. // assume we are going back to front page
  1121. $('body').removeClass().addClass('path-frontpage');
  1122. $('a[data-drupal-link-system-path="<front>"]').addClass('is-active');
  1123. // close entrees
  1124. _$corpus_canvas.trigger({'type':'close-all-entree'});
  1125. if(!pop_state){
  1126. history.pushState({home:true}, null, drupalSettings.path.baseUrl+drupalSettings.path.currentLanguage);
  1127. }
  1128. }
  1129. function initHome(){
  1130. addCloseModalBtnToCols();
  1131. // console.log('theme : initHome');
  1132. // console.log('theme : initProductions');
  1133. var $grid = $('.grid',_$row).masonry({
  1134. itemSelector:'.col',
  1135. columnWidth:'.col-2',
  1136. horizontalOrder: true,
  1137. containerStyle: null,
  1138. // disable initial layout
  1139. // initLayout: false,
  1140. });
  1141. // bind event
  1142. // $grid.masonry( 'on', 'layoutComplete', function() {
  1143. // console.log('layout is complete');
  1144. // });
  1145. // layout Masonry after each image loads
  1146. $grid.imagesLoaded().progress( function() {
  1147. $grid.masonry('layout');
  1148. });
  1149. $grid.imagesLoaded(function(){
  1150. $grid.masonry('layout');
  1151. });
  1152. }
  1153. // ___ _ _ _
  1154. // | _ \_ _ ___ __| |_ _ __| |_(_)___ _ _ ___
  1155. // | _/ '_/ _ \/ _` | || / _| _| / _ \ ' \(_-<
  1156. // |_| |_| \___/\__,_|\_,_\__|\__|_\___/_||_/__/
  1157. function initProductions(){
  1158. // console.log('theme : initProductions');
  1159. var $grid = $('.grid',_$row).masonry({
  1160. itemSelector:'.col',
  1161. columnWidth:'.col-2',
  1162. horizontalOrder: true,
  1163. containerStyle: null,
  1164. // disable initial layout
  1165. // initLayout: false,
  1166. });
  1167. // bind event
  1168. // $grid.masonry( 'on', 'layoutComplete', function() {
  1169. // console.log('layout is complete');
  1170. // });
  1171. // layout Masonry after each image loads
  1172. $grid.imagesLoaded().progress( function() {
  1173. $grid.masonry('layout');
  1174. });
  1175. $grid.imagesLoaded(function(){
  1176. $grid.masonry('layout');
  1177. });
  1178. };
  1179. // ___ _ _ _
  1180. // | __|_ _ _ _ ___ __ _(_)__| |_ _ _ ___ _ __ ___ _ _| |_
  1181. // | _|| ' \| '_/ -_) _` | (_-< _| '_/ -_) ' \/ -_) ' \ _|
  1182. // |___|_||_|_| \___\__, |_/__/\__|_| \___|_|_|_\___|_||_\__|
  1183. // |___/
  1184. function initEnregistrementTranscript(){
  1185. console.log('initEnregistrementTranscript');
  1186. var $node = _$row.find('article.node--type-enregistrement.node--view-mode-transcript');
  1187. var $nav = $('<nav>').prependTo($node);
  1188. $node.find('.field--name-field-transcript-vo').addClass('visible').find('.field__label')
  1189. .clone().appendTo($nav).addClass('is-active')
  1190. .attr('field_target', '.field--name-field-transcript-vo');
  1191. $node.find('.field--name-field-transcript-trad').find('.field__label')
  1192. .clone().appendTo($nav)
  1193. .attr('field_target', '.field--name-field-transcript-trad');
  1194. $nav.find('.field__label').on('click', function(){
  1195. var $this = $(this).addClass('is-active');
  1196. $this.siblings('.is-active').removeClass('is-active');
  1197. $this.parents('article.node').find('.field.visible').removeClass('visible');
  1198. $this.parents('article.node').find($this.attr('field_target')).addClass('visible');
  1199. });
  1200. };
  1201. // __ __ _ _
  1202. // | \/ |___ __| |__ _| |___
  1203. // | |\/| / _ \/ _` / _` | (_-<
  1204. // |_| |_\___/\__,_\__,_|_/__/
  1205. function closeAllModals(){
  1206. //console.log('theme : closeAllModals');
  1207. // TODO: animate the remove
  1208. _$row.html('');
  1209. _$ajaxLinks.removeClass('is-active');
  1210. _$body.trigger({'type':'all-modal-closed'});
  1211. };
  1212. // _ _ _
  1213. // | || |___| |_ __ ___ _ _ ___
  1214. // | __ / -_) | '_ \/ -_) '_(_-<
  1215. // |_||_\___|_| .__/\___|_| /__/
  1216. // |_|
  1217. // https://plainjs.com/javascript/utilities/set-cookie-get-cookie-and-delete-cookie-5/
  1218. // function getCookie(name) {
  1219. // var v = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');
  1220. // return v ? v[2] : null;
  1221. // }
  1222. // function setCookie(name, value, days) {
  1223. // var d = new Date;
  1224. // d.setTime(d.getTime() + 24*60*60*1000*days);
  1225. // document.cookie = name + "=" + value + ";path=/;expires=" + d.toGMTString();
  1226. // }
  1227. // function deleteCookie(name) { setCookie(name, '', -1); }
  1228. init();
  1229. } // end EdlpTheme()
  1230. $(document).ready(function($) {
  1231. if(drupalSettings.path.isFront){
  1232. var edlptheme = new EdlpTheme();
  1233. }
  1234. });
  1235. })(jQuery, Drupal, drupalSettings);