main.js 44 KB

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