main.js 47 KB

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