main.js 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951
  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. var _ajax_timing = {
  14. start:0,
  15. end:0
  16. };
  17. var _corpus_promise;
  18. var _is_mobile = edlp_mobile.device_is_mobile;
  19. // ___ _ _
  20. // |_ _|_ _ (_) |_
  21. // | || ' \| | _|
  22. // |___|_||_|_|\__|
  23. function init(){
  24. console.log("EdlpTheme init()");
  25. // if(!drupalSettings.path.isFront)
  26. // return;
  27. if(!_is_mobile){
  28. initEvents();
  29. _audioPlayer = new AudioPlayer();
  30. _compoPlayer = new CompoPlayer();
  31. checkLayout();
  32. initAjaxLinks();
  33. initHistory();
  34. initAudioLinksHover();
  35. }else{
  36. if(drupalSettings.path.isFront){
  37. initHomeMobile();
  38. }
  39. _$body.attr('booted', 'booted');
  40. }
  41. // if(!drupalSettings.path.isFront)
  42. // return;
  43. //
  44. // initEvents();
  45. };
  46. // __ __ _ _ _
  47. // | \/ |___| |__(_) |___
  48. // | |\/| / _ \ '_ \ | / -_)
  49. // |_| |_\___/_.__/_|_\___|
  50. function initHomeMobile(){
  51. $('.field--name-field-notice, .index', '.entrees .taxonomy-term.vocabulary-entrees')
  52. .addClass('closed');
  53. $('[data-drupal-link-system-path="<front>"]','#block-mainnavigation')
  54. .removeClass('is-active')
  55. .attr('href', '#collection');
  56. $('h2#block-mainnavigation-menu, a', '#block-mainnavigation')
  57. .on('click', onclickHomeMobileMenu);
  58. // $('a', '#block-mainnavigation')
  59. // .on('click', onclickHomeMobileMenu);
  60. $('.field--name-field-notice>.field__label', '.entrees .taxonomy-term.vocabulary-entrees')
  61. .on('click', onClickHomeMobileNotice);
  62. $('.index>.field__label', '.entrees .taxonomy-term.vocabulary-entrees')
  63. .on('click', onClickHomeMobileIndex);
  64. };
  65. function onclickHomeMobileMenu(e){
  66. $('#block-mainnavigation').toggleClass('visible');
  67. };
  68. function onClickHomeMobileNotice(e){
  69. // console.log('onClickHomeMobileNotice');
  70. // var $part = $(this).parent();//parents('.taxonomy-term');
  71. toggleEntreeOpening($(this).parent(), 'notice');
  72. };
  73. function onClickHomeMobileIndex(e){
  74. // console.log('onClickHomeMobileIndex');
  75. // var $part = $(this).parent();//parents('.taxonomy-term');
  76. toggleEntreeOpening($(this).parent(), 'index');
  77. };
  78. function toggleEntreeOpening($e, part){
  79. $e.toggleClass('closed')
  80. .parents('.taxonomy-term.vocabulary-entrees.home_mobile').toggleClass(part+'-opened');
  81. }
  82. // ___ _
  83. // | __|_ _____ _ _| |_ ___
  84. // | _|\ V / -_) ' \ _(_-<
  85. // |___|\_/\___|_||_\__/__/
  86. function initEvents(){
  87. // https://www.html5rocks.com/en/tutorials/async/deferred/
  88. var $corpus_df = $.Deferred();
  89. _corpus_promise = $corpus_df.promise();
  90. _$body
  91. .on('corpus-map-ready', function(e){
  92. onCorpusMapReady(e);
  93. $corpus_df.resolve();
  94. })
  95. .on('on-studio-chutier-updated', initAjaxLinks)
  96. .on('studio-initialized', function(e){
  97. _compoPlayer.newCompo();
  98. })
  99. .on('studio-not-active', function(e){
  100. _compoPlayer.deactivate();
  101. })
  102. .on('on-studio-compo-updated', function(e){
  103. initAjaxLinks();
  104. _compoPlayer.refresh();
  105. })
  106. .on('on-studio-compo-opened', function(e){
  107. initAjaxLinks();
  108. _compoPlayer.newCompo();
  109. })
  110. .on('search-results-loaded', function(e){
  111. initAjaxLinks();
  112. initAudioLinksHover();
  113. checkVisibleCorpusMapSpace();
  114. })
  115. // do not close index or notice modale on entree click
  116. .on('open_entree', function(e){
  117. console.log('on_open_entree : e', e);
  118. closeAllModals();
  119. checkLayout();
  120. // add body class for currently loaded content
  121. // var body_classes = [
  122. // 'path-'+sys_path.replace(/\//g, '-'),
  123. // 'entity-type-'+data.entity_type,
  124. // 'bundle-'+data.bundle,
  125. // 'view-mode-'+data.view_mode
  126. // ];
  127. _$body.removeClass();//.addClass(body_classes.join(' '));
  128. // record new history state
  129. if(typeof e.url != 'undefined'){
  130. var state = getSysPathState(e.sys_path);
  131. history.pushState(state, null, e.url);
  132. // piwik
  133. if(typeof _paq !== 'undefined'){
  134. // page tracking
  135. // https://matomo.org/blog/2017/02/how-to-track-single-page-websites-using-piwik-analytics/
  136. _paq.push(['setCustomUrl', e.url]);
  137. _paq.push(['setDocumentTitle', e.title]);
  138. _paq.push(['trackPageView']);
  139. }
  140. }
  141. })
  142. .on('close_entree', function(e){
  143. backToFrontPage();
  144. checkLayout();
  145. });
  146. window.addEventListener('resize', checkLayout, false);
  147. }
  148. // __ ___ _ ___ _
  149. // \ \ / (_)_ _ __| |_____ __ __ | _ \___ __(_)______
  150. // \ \/\/ /| | ' \/ _` / _ \ V V / | / -_|_-< |_ / -_)
  151. // \_/\_/ |_|_||_\__,_\___/\_/\_/ |_|_\___/__/_/__\___|
  152. function checkLayout(){
  153. var $audioplayer = $("#audio-player");
  154. if($audioplayer.length){
  155. var navpos = $('#block-mainnavigation').position();
  156. // console.log('navpos', navpos);
  157. if(typeof navpos != 'undefined'){
  158. $audioplayer.css({
  159. 'width':navpos.left+'px'
  160. });
  161. }
  162. }
  163. checkGridBlockHeight();
  164. checkGridBlockVisible();
  165. // entrees
  166. // TODO: center the entrees menu
  167. };
  168. // ___ _ _ ___
  169. // / __| __ _ _ ___| | | _ ) __ _ _ _ ___
  170. // \__ \/ _| '_/ _ \ | | _ \/ _` | '_(_-<
  171. // |___/\__|_| \___/_|_|___/\__,_|_| /__/
  172. function initScrollbars(){
  173. // console.log("initScrollbars");
  174. // TODO: find a better js scroll than overlayScrollbars which does not handle well max-height + overflow-y:auto;
  175. // $('.os-scroll').overlayScrollbars({
  176. // overflowBehavior:{
  177. // x:'h',
  178. // y:'scroll',
  179. // clipAlways:false
  180. // }
  181. // });
  182. };
  183. // _ _
  184. // /_\ (_)__ ___ __
  185. // / _ \ | / _` \ \ /
  186. // /_/ \_\/ \__,_/_\_\
  187. // |__/
  188. function getSysPathState(sys_path, view_mode){
  189. // console.log('Theme : getSysPathState', sys_path);
  190. var state = {
  191. 'sys_path':sys_path,
  192. 'ajax_path': sys_path
  193. };
  194. // convert node link to edlp_ajax_node module links
  195. var node_match = state.ajax_path.match(/^\/?(node\/(\d+))$/i);
  196. console.log('node_match', node_match);
  197. var term_match = state.ajax_path.match(/^\/?(taxonomy\/term\/(\d+))$/i);
  198. console.log('term_match', term_match);
  199. if(node_match){
  200. // TODO: detect audio links which will open audioplayer and wont load any ajax content unless view_mode "article" or "transcript"
  201. state.ajax_path = _ajax_settings.entityjson_path+'/'+node_match[1];
  202. state.node_nid = node_match[2];
  203. // check for viewmode attribute
  204. if(view_mode){
  205. state.ajax_path += '/'+view_mode;
  206. state.view_mode = view_mode;
  207. }
  208. }else if(term_match){
  209. // terms are always entrees, there's no other vocabulary links in front
  210. state.ajax_path = _ajax_settings.entityjson_path+'/'+term_match[1];
  211. state.ajax_path = state.ajax_path.replace(/taxonomy\/term/, 'taxonomy_term');
  212. state.entree_tid = term_match[2];
  213. // check for viewmode attribute
  214. if(view_mode){
  215. state.ajax_path += '/'+view_mode;
  216. state.view_mode = view_mode;
  217. }else{
  218. state.ajax_path = null;
  219. }
  220. }else{
  221. // convert other link to ajax
  222. // TODO: we assume that other links (no node, no term) are all from own modules (e.g. productions) !! may not be true !!
  223. state.ajax_path += '/ajax'
  224. }
  225. return state;
  226. };
  227. function ajaxLoadContent(state){
  228. console.log('ajaxLoadContent : state', state);
  229. _$body.addClass('ajax-loading');
  230. _ajax_timing.start = performance.now();
  231. var path = window.location.origin + Drupal.url(state.ajax_path);
  232. $.getJSON(path, {})
  233. .done(function(data){
  234. onAjaxLoaded(data, state);
  235. })
  236. .fail(function(jqxhr, textStatus, error){
  237. onAjaxLoadError(jqxhr, textStatus, error, state.sys_path);
  238. });
  239. };
  240. function onAjaxLoadError(jqxhr, textStatus, error, sys_path){
  241. console.warn('ajaxlink load failed for '+sys_path+' : '+error, jqxhr.responseText);
  242. $('.ajax-loading').removeClass('ajax-loading');
  243. _$body.removeClass('ajax-loading');
  244. };
  245. function onAjaxLoaded(data, state){
  246. console.log('ajax loaded', state, data);
  247. var $rendered = $(data.rendered);
  248. $rendered.attr({
  249. 'sys_path':state.sys_path,
  250. 'view_mode': state.view_mode
  251. });
  252. // console.log(data);
  253. // reset all style may been added by other pages (like masonry for productions)
  254. // and replace all content with newly loaded
  255. // TODO: build a system to replace or append contents (like studio + search)
  256. if(data.entity_type == "node" && data.bundle == "evenement"){
  257. if(_$row.find('.col.event').length){
  258. _$row.find('.col.event').replaceWith($rendered);
  259. }else if(_$row.find('.col.aside').length){
  260. _$row.find('.col.aside').replaceWith($rendered);
  261. }else{
  262. _$row.append($rendered);
  263. }
  264. }else{
  265. _$row.removeAttr('style').html($rendered);
  266. }
  267. // add body class for currently loaded content
  268. var body_classes = [
  269. 'path-'+state.sys_path.replace(/\//g, '-'),
  270. 'entity-type-'+data.entity_type,
  271. 'bundle-'+data.bundle,
  272. 'view-mode-'+data.view_mode
  273. ];
  274. _$body.removeClass().addClass(body_classes.join(' '));
  275. // id node add a generic path-node class to body
  276. // m = state.sys_path.match(/^\/?(node\/\d+)$/g);
  277. // if(m)
  278. if(state.node_nid)
  279. _$body.addClass('path-edlp-node');
  280. // handle clicked link classes
  281. $('.ajax-loading').removeClass('ajax-loading');
  282. $('.ajax-link.is-active:not(.articles-link)').removeClass('is-active');
  283. $('.is-active-trail').removeClass('is-active-trail');
  284. if(typeof state.selector != 'undefined'){
  285. // in case of entree link (actualy, selector is used only for entries links)
  286. // TODO: unfortunatly on initFirstLoad there is no selector property
  287. console.log('selector', state.selector);
  288. $('a[selector="'+state.selector+'"]').addClass('is-active');
  289. initAudioLinksHover();
  290. }else{
  291. if(typeof state.view_mode != 'undefined'){
  292. $('a[viewmode="'+state.view_mode+'"][data-drupal-link-system-path="'+state.sys_path+'"]').addClass('is-active');
  293. }else{
  294. // wait for corpus map beeing ready (e.g. for articles link)
  295. _corpus_promise.done(function(){
  296. $('a[data-drupal-link-system-path="'+state.sys_path+'"]').addClass('is-active');
  297. });
  298. }
  299. // as new content is not related to entree, we trigger close entree
  300. _$body.trigger({'type':'new-content-not-entree-ajax-loaded'});
  301. }
  302. // if bundle page (productions) activate production links
  303. if (typeof data.bundle != 'undefined' && data.bundle == "page") {
  304. $('a[data-drupal-link-system-path="productions"]').addClass('is-active-trail');
  305. }
  306. // if node is in production menu tree, set first level of tree active, e.g. pieces sonores
  307. if (typeof data.menu_parents != 'undefined') {
  308. for (var i = 0; i < data.menu_parents.length; i++) {
  309. var menu_sys_path = data.menu_parents[i];
  310. $('a[data-drupal-link-system-path="'+menu_sys_path+'"]').addClass('is-active-trail');
  311. }
  312. }
  313. // if entity has corpus-map's linked document call a filter to corpus map
  314. if(typeof data.documents_lies != 'undefined'){
  315. if(_corpus_ready){
  316. _$body.trigger({
  317. type:'ajax-node-loaded-linked-documents',
  318. nids:data.documents_lies
  319. });
  320. }else{
  321. _corpus_promise.done(function(){
  322. _$body.trigger({
  323. type:'ajax-node-loaded-linked-documents',
  324. nids:data.documents_lies
  325. });
  326. });
  327. }
  328. }
  329. // if block attached (eg : from edlp_productions module)
  330. // not used anymore as production block is always present (but not visible)
  331. if(typeof data.block != 'undefined'){
  332. // if block not already added
  333. if(!$('#'+data.block.id, '.region-'+data.block.region).length){
  334. $('.region-'+data.block.region).append(data.block.rendered);
  335. }
  336. }
  337. // initScrollbars();
  338. if(state.sys_path == "productions"){
  339. // initProductions();
  340. initGrid();
  341. }else{
  342. addCloseModalBtnToCols();
  343. }
  344. // enregistrement transcription
  345. if(data.entity_type == "node" && data.bundle == "enregistrement" && data.view_mode == "transcript"){
  346. // window.requestAnimationFrame(initEnregistrementTranscript);
  347. initEnregistrementTranscript();
  348. }
  349. if(state.sys_path == "search"){
  350. initSearch();
  351. }
  352. // update the language switcher block if it comes in the response
  353. if(typeof data.translations_links != 'undefined'){
  354. console.log('state',state);
  355. var lang_code = drupalSettings.path.currentLanguage;
  356. var $links = $(data.translations_links);
  357. // set active link
  358. $links.find('li[hreflang="'+lang_code+'"]').addClass('is-active').find('a').addClass('is-active');
  359. if(state.view_mode){
  360. $links.find('a').each(function(i,e){
  361. var $a = $(this);
  362. $a.attr('href', $a.attr('href')+'#'+state.view_mode);
  363. });
  364. }
  365. // if(state.selector){
  366. // $links.find('a').attr('selector', state.selector);
  367. // }
  368. $('ul','.block.language-switcher-language-url').replaceWith($links);
  369. }
  370. initAjaxLinks();
  371. initAudioLinksHover();
  372. checkVisibleCorpusMapSpace();
  373. // trigger other modules behaviours
  374. _$body.trigger({'type':'new-content-ajax-loaded'});
  375. // and call drupal behaviours
  376. Drupal.attachBehaviors(_$row[0]);
  377. _$body.attr('booted', 'booted');
  378. _$body.removeClass('ajax-loading');
  379. // url is null means that we are loading content on popState event
  380. // so we don't record the state again
  381. if(state.url){
  382. // var state = {
  383. // ajax_path:ajax_path,
  384. // sys_path:sys_path,
  385. // };
  386. // console.log('url:'+url+' ; state',state);
  387. // console.log(window.location);
  388. // /!\ we can not pushestate with absolute url /!\
  389. history.pushState(state, null, state.url);
  390. // piwik
  391. if(typeof _paq !== 'undefined'){
  392. // page tracking
  393. // https://matomo.org/blog/2017/02/how-to-track-single-page-websites-using-piwik-analytics/
  394. _paq.push(['setCustomUrl', state.url]);
  395. _paq.push(['setDocumentTitle', data.title]);
  396. // TODO: piwik track load time
  397. _ajax_timing.end = performance.now();
  398. _paq.push(['setGenerationTimeMs', _ajax_timing.end-_ajax_timing.start]);
  399. _paq.push(['trackPageView']);
  400. // js event
  401. // trackEvent(category, action, [name], [value])
  402. // _paq.push(['trackEvent', 'AjaxNav', 'loaded', state.url]);
  403. }
  404. }
  405. };
  406. function initAudioLinksHover(){
  407. console.log("initAudioLinksHover()");
  408. _$row.find('a.audio-link')
  409. .on('mouseover', function(event) {
  410. event.preventDefault();
  411. if(_corpus_ready){
  412. _$corpus_canvas.trigger({
  413. type:'mouseover-audio-link',
  414. nid:$(this).attr('nid')
  415. });
  416. }
  417. })
  418. .on('mouseout', function(event) {
  419. event.preventDefault();
  420. if(_corpus_ready){
  421. _$corpus_canvas.trigger({
  422. type:'mouseout-audio-link',
  423. nid:$(this).attr('nid')
  424. });
  425. }
  426. });
  427. };
  428. function addCloseModalBtnToCols(){
  429. $('.col', _$row).each(function(index, el) {
  430. if($('span.close-col-btn', this).length)
  431. return true;
  432. $(this).children('.wrapper').prepend($('<span>')
  433. .addClass('close-col-btn')
  434. .on('click', onCloseModal)
  435. );
  436. });
  437. };
  438. function onCloseModal(e){
  439. // check for theme attribute and emmit event
  440. var $col = $(this).parents('.col');
  441. var theme = $col.attr('theme');
  442. if(theme != ''){
  443. _$body.trigger({'type':theme+'-col-closed'});
  444. }
  445. if(_$body.is('.entity-type-node.bundle-page') && $(this).next().is('.node--type-page')){
  446. // remove all the col (prod page and agenda in case) only if closing the main page col
  447. // if closing the aside col (agenda) leave the main col in place
  448. $col.add($col.siblings('.col')).remove();
  449. }else{
  450. // remove the col
  451. $col.remove();
  452. }
  453. checkRowEmpty();
  454. checkVisibleCorpusMapSpace();
  455. // set links to this modal to not active (tested on articles from audio cartel)
  456. if( $col.attr('view_mode') && $col.attr('sys_path')){
  457. $('a[data-drupal-link-system-path="'+$col.attr('sys_path')+'"][viewmode="'+$col.attr('view_mode')+'"]').removeClass('is-active');
  458. }
  459. };
  460. // _ _ ___ _ _
  461. // /_\ (_)__ ___ __ | _ ) |___ __| |__ ___
  462. // / _ \ | / _` \ \ / | _ \ / _ \/ _| / /(_-<
  463. // /_/ \_\/ \__,_/_\_\ |___/_\___/\__|_\_\/__/
  464. // |__/
  465. // NOT USED (YET)
  466. // function refreshAllBlocks(){
  467. // var path = window.location.origin + Drupal.url(_ajax_settings.blocksjson_path);
  468. // $.getJSON(path, {})
  469. // .done(function(data){
  470. // onAjaxBlockLoaded(data);
  471. // })
  472. // .fail(function(jqxhr, textStatus, error){
  473. // onAjaxBlockLoadError(jqxhr, textStatus, error);
  474. // });
  475. // };
  476. // function onAjaxBlockLoadError(jqxhr, textStatus, error){
  477. // console.warn('ajax block load failed: '+error, jqxhr.responseText);
  478. // };
  479. // function onAjaxBlockLoaded(data){
  480. // console.log('onAjaxBlockLoaded', data);
  481. // // TODO: update each blocks (exepted language switcher)
  482. // for (var blockname in data.blocks) {
  483. // var block = data.blocks[blockname];
  484. // console.log(blockname, block);
  485. // $(block.id).replaceWith(block.rendered);
  486. // }
  487. // };
  488. // _ _ _ _
  489. // | || (_)__| |_ ___ _ _ _ _
  490. // | __ | (_-< _/ _ \ '_| || |
  491. // |_||_|_/__/\__\___/_| \_, |
  492. // |__/
  493. function initHistory(){
  494. initFirstLoad();
  495. window.addEventListener('popstate', onHistoryPopState);
  496. };
  497. function initFirstLoad(){
  498. console.log('theme : initFirstLoad()');
  499. console.log('window.location', window.location);
  500. // var origin_sys_path = window.localStorage.getItem('edlp_origin_path');
  501. var edlp_origin = JSON.parse(window.localStorage.getItem('edlp_origin'));
  502. console.log('edlp_origin', edlp_origin);
  503. if(edlp_origin != null && edlp_origin.sys_path){
  504. // hash is used as viewmode for taxonomy term entrees load (index or notice)
  505. // and for audio contents (article|transcript)
  506. var hash = edlp_origin.hash.replace('#', '');
  507. // create history state
  508. var state = getSysPathState(edlp_origin.sys_path, hash);
  509. // open entree tray in case of entree index|notice
  510. // (index or notice will be opened with ajaxLoadContent)
  511. // refactorized with new infos from edlp_origin
  512. // if(hash){
  513. if(edlp_origin.entity_type == "taxonomy_term"
  514. && edlp_origin.entity_bundle == "entrees"
  515. && hash){
  516. // var $link = $('[href="'+edlp_origin.url+'"][viewmode="'+hash+'"]');
  517. // var selector = $link.attr('selector') || null;
  518. // record the selector in the state for actions after ajaxContentLoaded
  519. state.selector = 'entree-'+hash+'-link-'+edlp_origin.entity_id; // entree-index-link-125
  520. // if(selector){
  521. // in case of entree link (actualy, selector is used only for entries links)
  522. // TODO: use a promise
  523. // TODO: but what if corpus ready before onAjaxLoaded >> use a promise !!
  524. if(_corpus_ready){
  525. _$corpus_canvas.trigger({
  526. type:'open-entree',
  527. // tid:$link.attr('tid')
  528. tid:edlp_origin.entity_id
  529. });
  530. }else{
  531. // else : EdlpCorpus will check when ready if entry item (notice or index) is already .is-active
  532. // .is-active class is added by onAjaxLoaded() (when content is loaded)
  533. // $('li.entree[tid="'+$link.attr('tid')+'"] a.term-link').addClass('is-active');
  534. $('li.entree[tid="'+edlp_origin.entity_id+'"] a.term-link').addClass('is-active');
  535. }
  536. // }
  537. }
  538. // check if audio link
  539. // only if not random link
  540. if(edlp_origin.audio_url){
  541. var node = {
  542. nid:edlp_origin.entity_id,
  543. audio_url:edlp_origin.audio_url
  544. };
  545. _audioPlayer.openDocument(node, 'history_first_load');
  546. // close home
  547. closeAllModals();
  548. if(hash == "" || hash == 'random'){
  549. // if hash is random, RandomPlayer will be started when playlist sent by corpus.js
  550. // if audio only record in state
  551. state.audio = true;
  552. state.node = node;
  553. // we don't laod ajax content so we boot the home
  554. _$body.attr('booted', 'booted');
  555. }else{
  556. // ajax load content for audio only if article or transcript
  557. ajaxLoadContent(state);
  558. }
  559. }
  560. // only if not entree path
  561. // only if not audio (without article or transcript) path
  562. else if(state.ajax_path){
  563. // load content through ajax
  564. // ajaxLoadContent(null, state.sys_path, state.ajax_path, selector);
  565. ajaxLoadContent(state);
  566. }
  567. if(state.entree_tid){
  568. openEntree(state.entree_tid);
  569. }
  570. // record history state
  571. history.replaceState(state, null, edlp_origin.url+edlp_origin.hash);
  572. // reset the storage
  573. window.localStorage.removeItem("edlp_origin");
  574. // window.localStorage.removeItem("edlp_origin_url");
  575. }else{
  576. // if(window.location.hash == "#random"){
  577. //
  578. // }
  579. history.replaceState({home:true}, null, window.location.pathname+window.location.hash);
  580. // initHome();
  581. initGrid();
  582. _$body.attr('booted', 'booted');
  583. }
  584. };
  585. function onHistoryPopState(e){
  586. console.log('onPopState',e.state);
  587. if(e.state.home){
  588. backToFrontPage(true);
  589. }
  590. else if (e.state.audio) {
  591. _audioPlayer.openDocument(e.state.node, 'popstate', e.state.historic_index);
  592. }
  593. else{
  594. if(e.state.entree_tid){
  595. openEntree(e.state.entree_tid);
  596. }
  597. if(e.state.ajax_path){
  598. e.state.url = null;
  599. // ajaxLoadContent(null, e.state.sys_path, e.state.ajax_path)
  600. ajaxLoadContent(e.state);
  601. }
  602. }
  603. };
  604. // _ _ _ _ _
  605. // /_\ (_)__ ___ _| | (_)_ _ | |__ ___
  606. // / _ \ | / _` \ \ / |__| | ' \| / /(_-<
  607. // /_/ \_\/ \__,_/_\_\____|_|_||_|_\_\/__/
  608. // |__/
  609. function initAjaxLinks(){
  610. // console.log('initAjaxLinks');
  611. $('a.site-name', '#block-edlptheme-branding')
  612. .add('a', '#block-mainnavigation')
  613. // .add('a', '.block.language-switcher-language-url')
  614. .add('a', '#block-footer.menu--footer')
  615. .add('a', '#block-productions')
  616. .add('a', 'article.node:not(.node--type-enregistrement) h2.node-title')
  617. // .add('a', 'article.node--type-evenement.node--view-mode-teaser .field--name-field-page-liee')
  618. .add('a', '.productions-subtree')
  619. .add('a', '.productions-parent')
  620. // .add('a.index-link, a.notice-link', '#block-edlpentreesblock')
  621. .add('a', '.field--name-field-son')
  622. .addClass('ajax-link');
  623. $('a[data-drupal-link-system-path="<front>"]', '#block-mainnavigation').removeClass('is-active');
  624. _$ajaxLinks = $('.ajax-link:not(.ajax-enabled)')
  625. .each(function(i,e){
  626. var $this = $(this);
  627. // avoid already ajaxified links
  628. if($this.is('.ajax-enable')) return;
  629. if($this.attr('data-drupal-link-system-path') || $this.is('[type^="audio"]')){
  630. $this.on('click', onClickAjaxLink).addClass('ajax-enable');
  631. }
  632. });
  633. };
  634. function onClickAjaxLink(e){
  635. e.preventDefault();
  636. var $link = $(this);
  637. // let the site-name link going through as it will shuffle the map if already active
  638. if($link.is('.is-active') && !$link.is('.site-name'))
  639. return false;
  640. // Audio links
  641. // launch audio player and stop here
  642. if($link.is('.audio-link')){
  643. // check if caller is lastdocs block
  644. caller = $link.parents('.lastdocs').length ? 'lastdocs' : null;
  645. // open audio player
  646. _audioPlayer
  647. .emmit('stop-shuffle')
  648. .openDocument({
  649. nid:$link.attr('nid'),
  650. audio_url:$link.attr('audio_url'),
  651. title:$link.find('.field--name-title').html()
  652. },
  653. caller);
  654. return false;
  655. }
  656. // other sounds playing
  657. if($link.is('[type^="audio"]')){
  658. _audioPlayer
  659. .emmit('stop-shuffle')
  660. .openSound($link.attr('href'), $link.html());
  661. return false;
  662. }
  663. // NOT USED ( YET ? )
  664. // if($link.is('.language-link')){
  665. // TODO: change global site current language
  666. // load all blocks translated (exepted language switcher) ... :/
  667. // refreshAllBlocks();
  668. // TODO: use a promise to initAjaxLinks again after blocks updated
  669. // then let load the content
  670. // }
  671. // other links
  672. var sys_path = $(this).attr('data-drupal-link-system-path');
  673. // front page
  674. // just remove contents and stop here
  675. if(sys_path == '<front>'){
  676. if($link.is('.is-active') && _corpus_ready){
  677. _$corpus_canvas.trigger({'type':'shuffle-collection'});
  678. }else{
  679. backToFrontPage();
  680. }
  681. return false;
  682. }
  683. var view_mode = $link.attr('viewmode');
  684. var state = getSysPathState(sys_path, view_mode);
  685. state.url = $(this).attr('href');
  686. if(view_mode){
  687. state.url += "#"+view_mode;
  688. }
  689. if($link.is('[selector]')){
  690. state.selector = $link.attr('selector');
  691. }
  692. $link.addClass('ajax-loading');
  693. // ajaxLoadContent(url, sys_path, state.ajax_path, selector);
  694. ajaxLoadContent(state);
  695. return false;
  696. };
  697. // ___
  698. // / __|___ _ _ _ __ _ _ ___
  699. // | (__/ _ \ '_| '_ \ || (_-<
  700. // \___\___/_| | .__/\_,_/__/
  701. // |_|
  702. function onCorpusMapReady(e){
  703. //console.log('theme : onCorpusReady', e);
  704. _corpus_ready = true;
  705. _$corpus_canvas = $('canvas#corpus-map');
  706. _$corpus_canvas
  707. .on('corpus-cliked-on-map', function(e) {
  708. //console.log('theme : corpus-cliked-on-map');
  709. backToFrontPage();
  710. })
  711. .on('corpus-cliked-on-node', function(e) {
  712. //console.log('theme : corpus-cliked-on-node', e);
  713. _audioPlayer
  714. .emmit('stop-shuffle')
  715. // .setAutoOpenArticle(e.article)
  716. .openDocument(e.target_node);
  717. });
  718. _randomPlayer = new RandomPlayer(e.playlist);
  719. // mainly for articles link
  720. initAjaxLinks();
  721. _$body.attr('corpus-map', 'ready');
  722. }
  723. function openEntree(tid){
  724. if(tid){
  725. closeAllModals();
  726. _$body.removeClass();//.addClass(body_classes.join(' '));
  727. // open entree
  728. if(_corpus_ready){
  729. _$corpus_canvas.trigger({
  730. type:'open-entree',
  731. tid:tid
  732. });
  733. }else{
  734. // else : EdlpCorpus will check when ready if entry item (notice or index) is already .is-active
  735. $('li.entree[tid="'+tid+'"] a.term-link').addClass('is-active');
  736. }
  737. }
  738. };
  739. function checkVisibleCorpusMapSpace(){
  740. var left_limit = 0, right_limit = 0;
  741. _$row.find('.col').each(function(i,e){
  742. var $col = $(this);
  743. var offset = $col.offset();
  744. console.log('$col', $col);
  745. switch(true){
  746. case $col.is('.float-right'):
  747. right_limit = Math.max(right_limit, Math.abs(offset.left-15-window.innerWidth));
  748. break;
  749. default:
  750. left_limit = Math.max(left_limit, offset.left+$col.width()+15);
  751. break;
  752. }
  753. });
  754. console.log('checkVisibleCorpusMapSpace left_limit:'+left_limit+" right_limit:"+right_limit);
  755. if(_corpus_ready){
  756. _$body.trigger({
  757. type:'visible-space-changed',
  758. left_limit:left_limit,
  759. right_limit:right_limit
  760. });
  761. }else{
  762. _corpus_promise.done(function(){
  763. _$body.trigger({
  764. type:'visible-space-changed',
  765. left_limit:left_limit,
  766. right_limit:right_limit
  767. });
  768. });
  769. }
  770. };
  771. // _ _ _
  772. // /_\ _ _ __| (_)___
  773. // / _ \ || / _` | / _ \
  774. // /_/ \_\_,_\__,_|_\___/
  775. //
  776. // https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement
  777. // https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/samples/gg589528%28v%3dvs.85%29
  778. // https://www.binarytides.com/using-html5-audio-element-javascript/
  779. function AudioPlayer(){
  780. var that = this;
  781. this.fid;
  782. this.audio = new Audio();
  783. // audio events
  784. this.audio_events = ["loadedmetadata","playing","pause","timeupdate","ended","error"]; // ,"canplay"
  785. // UI dom objects
  786. this.$container = $('<div id="audio-player">');
  787. // btns
  788. this.$btns = $('<div>').addClass('btns').appendTo(this.$container);
  789. this.$previous = $('<div>').addClass('previous').appendTo(this.$btns);
  790. this.$playpause = $('<div>').addClass('play-pause').appendTo(this.$btns);
  791. this.$next = $('<div>').addClass('next').appendTo(this.$btns);
  792. // timeline
  793. this.$timelinecont= $('<div>').addClass('time-line-container').appendTo(this.$container);
  794. this.$timeline = $('<div>').addClass('time-line').appendTo(this.$timelinecont);
  795. this.$loader = $('<div>').addClass('loader').appendTo(this.$timeline);
  796. this.$cursor = $('<div>').addClass('cursor').appendTo(this.$timeline);
  797. // time
  798. this.$time = $('<div>').addClass('time').appendTo(this.$container);
  799. this.$currentTime = $('<div>').addClass('current-time').html('00:00').appendTo(this.$time);
  800. this.$duration = $('<div>').addClass('duration').html('00:00').appendTo(this.$time);
  801. // favoris
  802. this.$fav = $('<div>').addClass('favoris').appendTo(this.$container);
  803. // cartel
  804. this.$cartel = $('<div>').addClass('cartel').appendTo(this.$container);
  805. this.scndCartel_visible = 0;
  806. this.cartelSwitchIntervalMS = 7000;
  807. this.cartelSwitchInterval = false;
  808. // hiding
  809. this.hideTimer = false;
  810. this.hideTimeMS = 15000;
  811. // history
  812. this.currentHistoricIndex = null;
  813. this.historic = [];
  814. this.shuffle_is_active = false;
  815. // artciles
  816. this.auto_open_article = false;
  817. // object events
  818. this.event_handlers = {
  819. 'audio-open-document':[],
  820. 'audio-play':[],
  821. 'audio-pause':[],
  822. 'audio-play-next':[],
  823. 'audio-ended':[],
  824. 'stop-shuffle':[]
  825. };
  826. this.init();
  827. };
  828. AudioPlayer.prototype = {
  829. init(){
  830. this.$container_parent = $('header[role="banner"] .region-header');
  831. // append ui to document
  832. this.$container.appendTo(this.$container_parent);
  833. // record timeline width
  834. this.timeline_w = parseInt(this.$timeline.width());
  835. // init seeking
  836. this.$loader.on('click', this.seek.bind(this));
  837. // init audio events
  838. var fn = '';
  839. for (var i = 0; i < this.audio_events.length; i++) {
  840. fn = this.audio_events[i];
  841. // capitalize first letter of event (only cosmetic :p )
  842. fn = 'on'+fn.charAt(0).toUpperCase()+fn.slice(1);
  843. this.audio.addEventListener(
  844. this.audio_events[i],
  845. this[fn].bind(this),
  846. true);
  847. }
  848. // init btns events
  849. this.$previous.on('click', this.playPrevious.bind(this));
  850. this.$playpause.on('click', this.togglePlayPause.bind(this));
  851. this.$next.on('click', this.playNext.bind(this));
  852. },
  853. openDocument(node, caller, historic_index){
  854. console.log('AudioPlayer openDocument', node, caller);
  855. if(typeof node == 'undefined'
  856. || typeof node.nid == 'undefined'
  857. || typeof node.audio_url == 'undefined'){
  858. console.warn('AudioPlayer openDocument() node is malformed', node);
  859. return false;
  860. }
  861. // if we don't come from history popstate
  862. if(typeof caller == 'undefined' || caller != 'popstate'){
  863. this.historic.push(node);
  864. this.currentHistoricIndex = this.historic.length-1;
  865. // this.shuffle_mode = shuffle_mode || false;
  866. // add the document opening to history to be able to share and play audio from any where
  867. if(caller != "history_first_load"){
  868. if(typeof node.document_url == 'undefined'){
  869. console.warn("AudioPlayer openDocument missing document_url, can't push state to history", caller, node);
  870. }else{
  871. var state = {
  872. audio:true,
  873. node:{
  874. nid:node.nid,
  875. audio_url:node.audio_url,
  876. document_url:node.document_url,
  877. title:node.title || null,
  878. },
  879. historic_index : this.currentHistoricIndex,
  880. };
  881. // console.log('AudioPlayer pushstate', state);
  882. var url = node.document_url + (caller == 'random' ? '#random' : '');
  883. history.pushState(state, null, url);
  884. }
  885. }
  886. }else{
  887. // if the call commes from popstate, we update the current position of index
  888. this.currentHistoricIndex = historic_index;
  889. }
  890. if(_$body.is('.path-frontpage') && caller !== 'lastdocs'){
  891. closeAllModals();
  892. }
  893. // TODO: update language switcher for document url
  894. // TODO: stop random player if playing from studio
  895. this.emmit('audio-open-document', {caller:caller});
  896. // piwik
  897. // debugger;
  898. if(typeof _paq !== 'undefined'){
  899. // page tracking
  900. // https://matomo.org/blog/2017/02/how-to-track-single-page-websites-using-piwik-analytics/
  901. // _paq.push(['setCustomUrl', state.url]);
  902. // _paq.push(['setDocumentTitle', data.title]);
  903. // _paq.push(['trackPageView']);
  904. // js event
  905. // trackEvent(category, action, [name], [value])
  906. if(typeof node.title != 'undefined'){
  907. _paq.push(['trackEvent', 'Audio', 'play', node.title]);
  908. }
  909. }
  910. this.launch();
  911. },
  912. launch(){
  913. this.clearTimeOutToHide();
  914. this.clearIntervalAutoCartelSwitch();
  915. this.setSRC(this.historic[this.currentHistoricIndex].audio_url);
  916. this.loadNode(this.historic[this.currentHistoricIndex].nid);
  917. // emmit new playing doc (e.g.: corpus map nowing that audio played from RandomPlayer)
  918. try {
  919. _$corpus_canvas.trigger({
  920. 'type':'audio-node-opened',
  921. 'nid':this.historic[this.currentHistoricIndex].nid
  922. });
  923. } catch (e) {
  924. console.info('AudioPlayer : _$corpus_canvas does not exists, testing promise');
  925. var that = this;
  926. _corpus_promise.done(function(){
  927. _$corpus_canvas.trigger({
  928. 'type':'audio-node-opened',
  929. 'nid':that.historic[that.currentHistoricIndex].nid
  930. });
  931. });
  932. }
  933. this.showHidePreviousBtn();
  934. this.showHideNextBtn();
  935. this.show();
  936. },
  937. openSound(url, title){
  938. this.hide();
  939. this.clearTimeOutToHide();
  940. this.$cartel.html("");
  941. this.setSRC(url);
  942. this.show();
  943. if(typeof _paq !== 'undefined'){
  944. _paq.push(['trackEvent', 'Audio', 'play', url]);
  945. }
  946. },
  947. // audio functions
  948. setSRC(url){
  949. console.log('AudioPlayer setSRC : url', url);
  950. this.audio.src = url;
  951. // need to trigger play right now to prevent safari blocking auto-play
  952. this.play();
  953. },
  954. // audio is ready to play
  955. onLoadedmetadata(){
  956. var rem = parseInt(this.audio.duration, 10),
  957. mins = Math.floor(rem/60,10),
  958. secs = rem - mins*60;
  959. this.$duration.html('<span>'+(mins<10 ? '0':'')+mins+':'+(secs<10 ? '0':'')+secs+'</span>');
  960. this.updateLoadingBar();
  961. },
  962. updateLoadingBar(){
  963. console.log("updateLoadingBar");
  964. // var that = this;
  965. // if (this.audio.readyState === 4){
  966. if(this.audio.buffered.length>0){
  967. // debugger;
  968. this.$loader.css({
  969. 'width':parseInt((100 * this.audio.buffered.end(0) / this.audio.duration), 10)+'%'
  970. });
  971. if( this.audio.buffered.end(0) < this.audio.duration ){
  972. // loop through this function until file is fully loaded
  973. window.requestAnimationFrame(this.updateLoadingBar.bind(this));
  974. }else{
  975. console.log('Audio fully loaded');
  976. }
  977. }else{
  978. // as audio buffer is not ready, recall updateLoadingBar in next frame
  979. window.requestAnimationFrame(this.updateLoadingBar.bind(this));
  980. }
  981. },
  982. // onCanplay(){
  983. // // this.play();
  984. // },
  985. onError(){
  986. console.warn("Audio Error " + this.audio.error.code + "; details: " + this.audio.error.message);
  987. },
  988. play(){
  989. this.clearTimeOutToHide();
  990. // this.audio.play();
  991. // Not really needed has we trigger play right after setting the source https://stackoverflow.com/questions/47431439/mp4-video-safari-showing-unhandled-promise-rejection-object-domerror-in-c
  992. var promise = this.audio.play();
  993. // console.log('promise', promise);
  994. if (promise !== undefined) {
  995. promise.catch(function(error){
  996. // Auto-play was prevented
  997. // Show a UI element to let the user manually start playback
  998. console.warn('autoplay failed, ask for playing', error);
  999. }).then(function(){
  1000. // Auto-play started
  1001. console.log('autoplay succeed');
  1002. });
  1003. }
  1004. },
  1005. playPrevious(){
  1006. if(this.currentHistoricIndex > 0){
  1007. this.currentHistoricIndex -= 1;
  1008. this.launch();
  1009. // TODO: update history state
  1010. }
  1011. },
  1012. playNext(){
  1013. if(this.currentHistoricIndex < this.historic.length-1){
  1014. this.currentHistoricIndex += 1;
  1015. this.launch();
  1016. // TODO: update history state
  1017. }else{
  1018. this.emmit('audio-play-next');
  1019. }
  1020. },
  1021. togglePlayPause(e){
  1022. if(this.audio.paused){
  1023. // this.audio.play();
  1024. this.play();
  1025. }else{
  1026. // this.audio.pause();
  1027. this.stop();
  1028. }
  1029. },
  1030. stop(){
  1031. // console.log('AudioPlayer stop()');
  1032. // debugger;
  1033. this.audio.pause();
  1034. // don't close player if article or transcript is open
  1035. if(!(_$body.is('.path-node-'+this.historic[this.currentHistoricIndex].nid)
  1036. && (_$body.is('.view-mode-article') || _$body.is('.view-mode-transcript')))){
  1037. this.timeOutToHide();
  1038. }
  1039. },
  1040. seek(e){
  1041. var seek = e.originalEvent.layerX / this.timeline_w * this.audio.duration
  1042. console.log("Audio seeking : seek", seek);
  1043. this.audio.currentTime = seek;
  1044. },
  1045. // audio events
  1046. onPlaying(){
  1047. this.$btns.addClass('is-playing');
  1048. this.emmit('audio-play');
  1049. },
  1050. onPause(){
  1051. this.$btns.removeClass('is-playing');
  1052. this.emmit('audio-pause');
  1053. },
  1054. onTimeupdate(){
  1055. // move cursor
  1056. this.$cursor.css({
  1057. 'left':(this.audio.currentTime/this.audio.duration * this.timeline_w)+"px"
  1058. });
  1059. // update time text display
  1060. var rem = parseInt(this.audio.currentTime, 10),
  1061. mins = Math.floor(rem/60,10),
  1062. secs = rem - mins*60;
  1063. this.$currentTime.html('<span>'+(mins<10 ? '0':'')+mins+':'+(secs<10 ? '0':'')+secs+'</span>');
  1064. },
  1065. onEnded(){
  1066. console.log('AudioPlayer onEnded()');
  1067. this.stop();
  1068. this.emmit('audio-ended');
  1069. },
  1070. // cartel functions
  1071. loadNode(nid){
  1072. this.$cartel.addClass('loading');
  1073. var vm = 'player_cartel';
  1074. var ajax_path = _ajax_settings.entityjson_path+'/node/'+nid+'/'+vm;
  1075. var path = window.location.origin + Drupal.url(ajax_path);
  1076. $.getJSON(path, {})
  1077. .done(this.onNodeLoaded.bind(this))
  1078. .fail(this.onNodeLoadFail.bind(this));
  1079. },
  1080. onNodeLoaded(data){
  1081. console.log('AudioPlayer node loaded', data);
  1082. this.$cartel.html(data.rendered).removeClass('loading');
  1083. _$body.trigger({'type':'new-audio-cartel-loaded'});
  1084. initAjaxLinks();
  1085. // cartel autoswitch
  1086. this.scndCartel_visible = 0;
  1087. this.$cartel.removeClass('second-visible');
  1088. // if second cartel has special info ?
  1089. if (this.$cartel.find('.second-cartel .col-left').children().length > 1
  1090. || this.$cartel.find('.second-cartel').children('.col-right').length){
  1091. // init cartel auto switch
  1092. this.cartelSwitchInterval = setInterval(this.switchCartel.bind(this), this.cartelSwitchIntervalMS);
  1093. }
  1094. // call drupal behaviours (for addtoany)
  1095. Drupal.attachBehaviors(this.$cartel);
  1096. // open automaticly tha article if needed
  1097. this.setAutoOpenArticle();
  1098. if(this.auto_open_article){
  1099. this.$cartel.find('a.link-article').trigger('click');
  1100. this.auto_open_article = false;
  1101. }
  1102. },
  1103. onNodeLoadFail(jqxhr, textStatus, error){
  1104. console.warn('AudioPlayer node load failed', jqxhr.responseText);
  1105. this.$cartel.removeClass('loading').html('');
  1106. },
  1107. setAutoOpenArticle(art){
  1108. this.auto_open_article = $('a.articles-link').is('.is-active');
  1109. return this;
  1110. },
  1111. // global
  1112. show(){
  1113. this.$container_parent.addClass('audio-player-visible');
  1114. this.$container.addClass('visible');
  1115. },
  1116. showHidePreviousBtn(){
  1117. if(this.historic.length > 1 && this.currentHistoricIndex > 0){
  1118. this.$previous.addClass('is-active');
  1119. }else{
  1120. this.$previous.removeClass('is-active');
  1121. }
  1122. },
  1123. showHideNextBtn(){
  1124. if(this.currentHistoricIndex < this.historic.length-1 || this.shuffle_is_active){
  1125. this.$next.addClass('is-active');
  1126. }else{
  1127. this.$next.removeClass('is-active');
  1128. }
  1129. },
  1130. timeOutToHide(){
  1131. // console.log('AudioPlayer timeOutToHide()');
  1132. this.clearTimeOutToHide();
  1133. this.hideTimer = setTimeout(this.hide.bind(this), this.hideTimeMS);
  1134. },
  1135. clearTimeOutToHide(){
  1136. // console.log('AudioPlayer clearTimeOutToHide()',this.hideTimer);
  1137. if(this.hideTimer){
  1138. clearTimeout(this.hideTimer);
  1139. this.hideTimer = false;
  1140. }
  1141. },
  1142. // cartel
  1143. switchCartel(){
  1144. // console.log("switchCartel", this.scndCartel_visible);
  1145. if (this.scndCartel_visible) {
  1146. // return to first cartel
  1147. this.$cartel.removeClass('second-visible');
  1148. this.scndCartel_visible = 0;
  1149. // kill the auto switch after one rotation
  1150. this.clearIntervalAutoCartelSwitch();
  1151. }else{
  1152. // switch to 2nd cartel
  1153. this.$cartel.addClass('second-visible');
  1154. this.scndCartel_visible = 1;
  1155. }
  1156. },
  1157. clearIntervalAutoCartelSwitch(){
  1158. if(this.cartelSwitchInterval){
  1159. clearInterval(this.cartelSwitchInterval);
  1160. this.cartelSwitchInterval = false;
  1161. }
  1162. },
  1163. hide(){
  1164. // console.log('AudioPlayer hide()');
  1165. this.$container_parent.removeClass('audio-player-visible');
  1166. this.$container.removeClass('visible');
  1167. // trigger highlighted node remove on corpus map
  1168. try {
  1169. _$corpus_canvas.trigger('audio-node-closed');
  1170. } catch (e) {
  1171. console.info('AudioPlayer hide() : _$corpus_canvas does not exists');
  1172. }
  1173. },
  1174. deActivateRandom(){
  1175. this.shuffle_is_active = false;
  1176. this.showHideNextBtn();
  1177. },
  1178. // object events
  1179. on(event_name, handler){
  1180. if(typeof this.event_handlers[event_name] == 'undefined'){
  1181. console.warn('AudioPlayer : event '+event_name+' does not exists');
  1182. }
  1183. this.event_handlers[event_name].push(handler);
  1184. return this;
  1185. },
  1186. emmit(event_name, args){
  1187. console.log('AudioPlayer emmit()', event_name, args, this.event_handlers[event_name]);
  1188. // console.log('AudioPlayer emmit() handlers', this.event_handlers[event_name]);
  1189. var handler;
  1190. var args = args || {};
  1191. for (var i = this.event_handlers[event_name].length-1; i >= 0 ; i--) {
  1192. handler = this.event_handlers[event_name][i];
  1193. // console.log('AudioPlayer emmit() loop handler', handler);
  1194. (function(handler, args){
  1195. setTimeout(function(){
  1196. // console.log('AudioPlayer emmit() timeout handler', handler);
  1197. handler(args);
  1198. }, 0);
  1199. }(handler, args));
  1200. }
  1201. return this;
  1202. },
  1203. }
  1204. // ___ _ ___ _
  1205. // | _ \__ _ _ _ __| |___ _ __ | _ \ |__ _ _ _ ___ _ _
  1206. // | / _` | ' \/ _` / _ \ ' \| _/ / _` | || / -_) '_|
  1207. // |_|_\__,_|_||_\__,_\___/_|_|_|_| |_\__,_|\_, \___|_|
  1208. // |__/
  1209. function RandomPlayer(playlist){
  1210. this.active = false;
  1211. this.playlist = playlist;
  1212. this.path = drupalSettings.path.baseUrl+drupalSettings.path.pathPrefix+'#random'
  1213. this.$btn = $('<a>')
  1214. .html('Shuffle')
  1215. .attr('href',this.path)
  1216. .attr('alt', drupalSettings.edlp_corpus.random_link_title)
  1217. .addClass('random-player-btn');
  1218. this.init();
  1219. };
  1220. RandomPlayer.prototype = {
  1221. init(){
  1222. // this.shuffle();
  1223. $('<div>')
  1224. .addClass('block random-player')
  1225. .append(this.$btn)
  1226. // .insertAfter('#block-userlogin, #block-studiolinkblock');
  1227. .prependTo('.region-footer-right');
  1228. // events
  1229. this.$btn.on('click', this.toggleActive.bind(this));
  1230. // attach an event on AudioPlayer
  1231. _audioPlayer
  1232. .on('audio-play-next', this.onAudioPlayNext.bind(this))
  1233. .on('audio-ended', this.onAudioPlayerEnded.bind(this))
  1234. // .on('audio-ended', function(e){
  1235. // console.log('RandomPlayer, audio-ended', e);
  1236. // })
  1237. .on('stop-shuffle', this.stop.bind(this));
  1238. _$corpus_canvas
  1239. .on('update-random-playlist', this.updatePlaylist.bind(this));
  1240. // provide a link to auto start random player
  1241. if(window.location.hash == '#random'){
  1242. this.start();
  1243. // window.location.hash = '';
  1244. }
  1245. },
  1246. updatePlaylist(e){
  1247. // debugger;
  1248. this.playlist = e.playlist;
  1249. this.shuffle();
  1250. },
  1251. shuffle(){
  1252. var tempPLaylist = [];
  1253. for (var i = this.playlist.length-1; i >= 0 ; i--) {
  1254. tempPLaylist.push(this.playlist[i]);
  1255. }
  1256. this.shuffledPlaylist = [];
  1257. while(tempPLaylist.length > 0){
  1258. var r = Math.floor(Math.random() * tempPLaylist.length);
  1259. this.shuffledPlaylist.push(tempPLaylist.splice(r,1)[0]);
  1260. }
  1261. //console.log('RandomPlayer, this.shuffledPlaylist', this.shuffledPlaylist);
  1262. },
  1263. toggleActive(e){
  1264. e.preventDefault();
  1265. if (this.active) {
  1266. this.stop();
  1267. }else{
  1268. this.start();
  1269. }
  1270. return false;
  1271. },
  1272. start(){
  1273. this.active = _audioPlayer.shuffle_is_active = true;
  1274. this.$btn.addClass('is-active');
  1275. this.shuffle();
  1276. this.next();
  1277. // piwik
  1278. if(typeof _paq !== 'undefined'){
  1279. // trackEvent(category, action, [name], [value])
  1280. _paq.push(['trackEvent', 'RandomPlayer', 'start']);
  1281. }
  1282. },
  1283. stop(){
  1284. this.active = false;
  1285. this.$btn.removeClass('is-active');
  1286. // stop audio player
  1287. // _audioPlayer.stop();
  1288. // remove hash
  1289. history.replaceState(history.state, null, window.location.pathname);
  1290. // tell to AudioPlayer to deactivate netx btn
  1291. _audioPlayer.deActivateRandom();
  1292. if(typeof _paq !== 'undefined'){
  1293. // trackEvent(category, action, [name], [value])
  1294. _paq.push(['trackEvent', 'RandomPlayer', 'stop']);
  1295. }
  1296. },
  1297. next(){
  1298. console.log('RandomPlayer next', this.active, this.shuffledPlaylist.length);
  1299. if(this.active && this.shuffledPlaylist.length > 0)
  1300. _audioPlayer.openDocument(this.shuffledPlaylist.splice(0,1)[0], 'random');
  1301. },
  1302. onAudioPlayNext(){
  1303. console.log('RandomPlayer : onAudioPlayNext()');
  1304. if(this.active){
  1305. this.next();
  1306. }
  1307. },
  1308. onAudioPlayerEnded(){
  1309. console.log('RandomPlayer : onAudioPlayerEnded()');
  1310. if(this.active){
  1311. this.next();
  1312. }
  1313. }
  1314. };
  1315. // ___ ___ _
  1316. // / __|___ _ __ _ __ ___| _ \ |__ _ _ _ ___ _ _
  1317. // | (__/ _ \ ' \| '_ \/ _ \ _/ / _` | || / -_) '_|
  1318. // \___\___/_|_|_| .__/\___/_| |_\__,_|\_, \___|_|
  1319. // |_| |__/
  1320. function CompoPlayer(){
  1321. this.active = false;
  1322. this.playing = false;
  1323. this.paused = false;
  1324. this.playlist = [];
  1325. this.current_index = 0;
  1326. this.$composer = null;
  1327. this.$compo = null;
  1328. this.$controls = null;
  1329. this.init();
  1330. };
  1331. CompoPlayer.prototype = {
  1332. init(){
  1333. // console.log('CompoPlayer init()');
  1334. // attach an event on AudioPlayer
  1335. _audioPlayer
  1336. .on('audio-open-document', this.onAudioOpenDocument.bind(this))
  1337. .on('audio-play', this.onAudioPlayerPlay.bind(this))
  1338. .on('audio-pause', this.onAudioPlayerPause.bind(this))
  1339. .on('audio-ended', this.onAudioPlayerEnded.bind(this));
  1340. // .on('audio-play-next', this.onAudioPlayNext.bind(this));
  1341. // this.newCompo();
  1342. },
  1343. newCompo(){
  1344. //console.log('CompoPlayer newCompo()');
  1345. // this.$compo = $('.composition_ui .composer .composition');
  1346. this.initControls();
  1347. },
  1348. initControls(){
  1349. //console.log('CompoPlayer initControls()');
  1350. this.$composer = $('.composition_ui .composer');
  1351. this.$compo = $('.composition_ui .composer .composition');
  1352. this.$controls = $('.composition_ui .composer .compo-player-controls');
  1353. if(!this.$controls.is('.ready') && this.$compo){
  1354. this.$previous = $('<div>').addClass('previous')
  1355. .on('click', this.prev.bind(this))
  1356. .appendTo(this.$controls);
  1357. this.$playpause = $('<div>').addClass('play-pause')
  1358. .on('click', this.togglePlayPause.bind(this))
  1359. .appendTo(this.$controls);
  1360. this.$next = $('<div>').addClass('next')
  1361. .on('click', this.next.bind(this))
  1362. .appendTo(this.$controls);
  1363. this.$controls.addClass('ready');
  1364. this.refresh();
  1365. this.active = true;
  1366. // this.newCompo();
  1367. }
  1368. },
  1369. refresh(){
  1370. // console.log('CompoPlayer refresh(), this', this);
  1371. this.stop();
  1372. // load new playlist
  1373. this.playlist = [];
  1374. var that = this;
  1375. $('.field--name-documents .field__item',this.$compo).each(function(i,el){
  1376. var $link = $('a.audio-link',this);
  1377. that.playlist.push({
  1378. item:$(this),
  1379. audio_url:$link.attr("audio_url"),
  1380. nid:$link.attr("nid"),
  1381. });
  1382. });
  1383. this.showHideControls();
  1384. },
  1385. togglePlayPause(){
  1386. // console.log('CompoPlayer togglePlayPause');
  1387. if (this.playing && !this.paused) {
  1388. this.pause();
  1389. }else{
  1390. if(this.playing && this.paused){
  1391. this.play();
  1392. }else{
  1393. this.start();
  1394. }
  1395. }
  1396. },
  1397. start(){
  1398. //console.log('start');
  1399. // console.log('CompoPlayer start()');
  1400. this.playing = true;
  1401. this.play();
  1402. },
  1403. play(){
  1404. // console.log('play');
  1405. if(this.paused){
  1406. this.paused = false;
  1407. _audioPlayer.play();
  1408. }else{
  1409. // _audioPlayer;
  1410. _audioPlayer.emmit('stop-shuffle').openDocument(this.playlist[this.current_index], this);
  1411. // TODO: stop random player
  1412. }
  1413. this.setActiveItem().showHideControls();
  1414. },
  1415. pause(){
  1416. //console.log('pause');
  1417. this.paused = true;
  1418. this.showHideControls();
  1419. _audioPlayer.stop();
  1420. },
  1421. next(){
  1422. // console.log('CompoPlayer next()');
  1423. if(this.playing){
  1424. this.current_index += 1;
  1425. if(this.current_index < this.playlist.length){
  1426. this.play();
  1427. }else{
  1428. this.stop();
  1429. }
  1430. }
  1431. },
  1432. prev(){
  1433. // console.log('CompoPlayer prev()');
  1434. if(this.playing){
  1435. this.current_index -= 1;
  1436. if(this.current_index >= 0){
  1437. this.play();
  1438. }else{
  1439. this.stop();
  1440. }
  1441. }
  1442. },
  1443. stop(){
  1444. if(this.playing){
  1445. _audioPlayer.stop();
  1446. }
  1447. this.reset();
  1448. },
  1449. reset(){
  1450. this.playing = false;
  1451. this.paused = false;
  1452. this.resetIndex();
  1453. },
  1454. resetIndex(){
  1455. this.current_index = 0;
  1456. this.showHideControls().resetActiveItems();
  1457. },
  1458. setActiveItem(){
  1459. this.resetActiveItems();
  1460. if(this.playing && this.current_index >= 0){
  1461. this.playlist[this.current_index].item.addClass('is-active');
  1462. }
  1463. // this call shoud not be here
  1464. this.showHideControls();
  1465. return this;
  1466. },
  1467. resetActiveItems(){
  1468. for (var n = 0; n < this.playlist.length; n++) {
  1469. // console.log('node',node);
  1470. this.playlist[n].item.removeClass('is-active');
  1471. }
  1472. return this;
  1473. },
  1474. showHideControls(){
  1475. // console.log('CompoPlayer showHideNextBtn(), playing:'+this.playing+', paused:'+this.paused);
  1476. // global playing
  1477. if(this.$controls){
  1478. if(this.playing && !this.paused){
  1479. this.$controls.addClass('is-playing');
  1480. }else{
  1481. this.$controls.removeClass('is-playing');
  1482. }
  1483. }
  1484. // playpause
  1485. if(this.$playpause){
  1486. if(this.playlist.length > 0){
  1487. this.$playpause.addClass('is-active');
  1488. }else{
  1489. this.$playpause.removeClass('is-active');
  1490. }
  1491. }
  1492. // next
  1493. if(this.$next){
  1494. if(this.playing && this.playlist.length > 1 && this.current_index < this.playlist.length -1){
  1495. this.$next.addClass('is-active');
  1496. }else{
  1497. this.$next.removeClass('is-active');
  1498. }
  1499. }
  1500. // previous
  1501. if(this.$previous){
  1502. if(this.playing && this.playlist.length > 1 && this.current_index > 0){
  1503. this.$previous.addClass('is-active');
  1504. }else{
  1505. this.$previous.removeClass('is-active');
  1506. }
  1507. }
  1508. return this;
  1509. },
  1510. deactivate(){
  1511. this.stop();
  1512. this.active = false;
  1513. },
  1514. // _audioPlayer events
  1515. onAudioOpenDocument(args){
  1516. if(args.caller !== this){
  1517. // console.log('CompoPlayer onAudioOpenDocument() called by other');
  1518. this.reset();
  1519. }
  1520. // else{
  1521. // // console.log('CompoPlayer onAudioOpenDocument() self calling');
  1522. // }
  1523. },
  1524. onAudioPlayerPlay(){
  1525. if(this.playing && this.paused){
  1526. this.paused = false;
  1527. this.showHideControls();
  1528. }
  1529. },
  1530. onAudioPlayerPause(){
  1531. if(this.playing && !this.paused){
  1532. this.paused = true;
  1533. this.showHideControls();
  1534. }
  1535. },
  1536. onAudioPlayerEnded(){
  1537. if(this.playing){
  1538. this.next();
  1539. }
  1540. },
  1541. // onAudioPlayNext(){
  1542. // this.next();
  1543. // }
  1544. };
  1545. // ___ _ _
  1546. // / __|_ _(_)__| |
  1547. // | (_ | '_| / _` |
  1548. // \___|_| |_\__,_|
  1549. function initGrid(){
  1550. console.log('theme : initGrid');
  1551. checkGridBlockHeight();
  1552. _$row.find('.col').addClass('offfield');
  1553. if(false){
  1554. var $grid = $('.grid',_$row).masonry({
  1555. itemSelector:'.col',
  1556. columnWidth:'.col-2',
  1557. containerStyle: null,
  1558. resizeContainer:false,
  1559. // horizontalOrder: true,
  1560. transitionDuration:0,//'0.2s',
  1561. // stagger:30,
  1562. // disable initial layout
  1563. // initLayout: false,
  1564. });
  1565. // layout Masonry after each image loads
  1566. $grid.imagesLoaded().progress( function() {
  1567. $grid.masonry('layout');
  1568. });
  1569. $grid.imagesLoaded(function(){
  1570. $grid.masonry('layout');
  1571. // checkProductionBlockVisible();
  1572. });
  1573. // bind event
  1574. // $grid.masonry( 'on', 'layoutComplete', function() {
  1575. // console.log('layout is complete');
  1576. // });
  1577. $grid.on('layoutComplete', checkGridBlockVisible);
  1578. }else{
  1579. // setTimeout(checkGridBlockVisible, 100);
  1580. checkGridBlockVisible();
  1581. }
  1582. };
  1583. function checkGridBlockHeight(){
  1584. // console.log('checkGridBlockHeight');
  1585. var $r_h = _$row.height();
  1586. var $this;
  1587. // console.log($r_h);
  1588. $('.grid .col', _$row).each(function(i,e){
  1589. $this = $(this);
  1590. if(!$this.is('[init-height]')){
  1591. $this.attr('init-height', $this.outerHeight())
  1592. }
  1593. // console.log($(this).height(), $(this).innerHeight(), $(this).outerHeight());
  1594. // if($this.height() > $r_h){
  1595. // $this.height($r_h);
  1596. // }else{
  1597. // $this.height('auto');
  1598. // }
  1599. $this.height(Math.min($this.attr('init-height'), _$row.height()));
  1600. });
  1601. };
  1602. function checkGridBlockVisible(){
  1603. // console.log('checkGridBlockVisible');
  1604. var $r_h = _$row.height();
  1605. var $this,pos;
  1606. $('.grid .col', _$row).each(function(i,e){
  1607. // $(this).on('load',function(event){
  1608. $this = $(this);
  1609. pos = $this.position();
  1610. // console.log(pos.top, $this.height(), pos.top+$this.height(), $r_h, $this);
  1611. if(pos.top+$this.height() <= $r_h){
  1612. $this.removeClass('offfield');
  1613. }else{
  1614. $this.addClass('offfield');
  1615. }
  1616. // });
  1617. });
  1618. // for (var i in items) {
  1619. // if(!items[i].isTransitioning){
  1620. // console.log('y+outerHeight', items[i].position.y+items[i].size.outerHeight);
  1621. // console.log('_$row.height()', _$row.height());
  1622. // if(items[i].position.y+items[i].size.outerHeight < _$row.height()){
  1623. // $(items[i].element).removeClass('offfield');
  1624. // }else{
  1625. // // $(items[i].element).addClass('offfield');
  1626. // }
  1627. // }
  1628. // }
  1629. }
  1630. // ___ _ _ _
  1631. // | _ \_ _ ___ __| |_ _ __| |_(_)___ _ _ ___
  1632. // | _/ '_/ _ \/ _` | || / _| _| / _ \ ' \(_-<
  1633. // |_| |_| \___/\__,_|\_,_\__|\__|_\___/_||_/__/
  1634. // function initProductions(){
  1635. // console.log('theme : initProductions');
  1636. //
  1637. // // _$row.find('.col').addClass('offfield');
  1638. // var $grid = $('.grid',_$row).masonry({
  1639. // itemSelector:'.col',
  1640. // columnWidth:'.col-2',
  1641. // containerStyle: null,
  1642. // resizeContainer:false,
  1643. // // horizontalOrder: true,
  1644. // transitionDuration:0,//'0.2s',
  1645. // // stagger:30,
  1646. // // disable initial layout
  1647. // // initLayout: false,
  1648. // });
  1649. //
  1650. // // layout Masonry after each image loads
  1651. // $grid.imagesLoaded().progress( function() {
  1652. // $grid.masonry('layout');
  1653. // });
  1654. //
  1655. // $grid.imagesLoaded(function(){
  1656. // $grid.masonry('layout');
  1657. // // checkProductionBlockVisible();
  1658. // });
  1659. //
  1660. // // bind event
  1661. // // $grid.masonry( 'on', 'layoutComplete', function() {
  1662. // // console.log('layout is complete');
  1663. // // });
  1664. // // $grid.on('layoutComplete', checkProductionBlockVisible);
  1665. // };
  1666. // ___ _
  1667. // / __| ___ __ _ _ _ __| |_
  1668. // \__ \/ -_) _` | '_/ _| ' \
  1669. // |___/\___\__,_|_| \__|_||_|
  1670. function initSearch(){
  1671. // if($('#edit-entries input:checked', '#edlp-search-form').length){
  1672. // $('#edit-entries--wrapper', '#edlp-search-form').toggleClass('opened');
  1673. // }
  1674. $('#edit-entries--wrapper legend', '#edlp-search-form').on('click', function(){
  1675. $(this).parent().toggleClass('opened');
  1676. });
  1677. };
  1678. // ___ _ _ _
  1679. // | __|_ _ _ _ ___ __ _(_)__| |_ _ _ ___ _ __ ___ _ _| |_
  1680. // | _|| ' \| '_/ -_) _` | (_-< _| '_/ -_) ' \/ -_) ' \ _|
  1681. // |___|_||_|_| \___\__, |_/__/\__|_| \___|_|_|_\___|_||_\__|
  1682. // |___/
  1683. function initEnregistrementTranscript(){
  1684. console.log('initEnregistrementTranscript');
  1685. var $node = _$row.find('article.node--type-enregistrement.node--view-mode-transcript');
  1686. var $nav = $('<nav>').prependTo($node);
  1687. $node.find('.field--name-field-transcript-vo').addClass('visible').find('.field__label')
  1688. .clone().appendTo($nav).addClass('is-active')
  1689. .attr('field_target', '.field--name-field-transcript-vo');
  1690. $node.find('.field--name-field-transcript-trad').find('.field__label')
  1691. .clone().appendTo($nav)
  1692. .attr('field_target', '.field--name-field-transcript-trad');
  1693. $nav.find('.field__label').on('click', function(){
  1694. var $this = $(this).addClass('is-active');
  1695. $this.siblings('.is-active').removeClass('is-active');
  1696. $this.parents('article.node').find('.field.visible').removeClass('visible');
  1697. $this.parents('article.node').find($this.attr('field_target')).addClass('visible');
  1698. });
  1699. };
  1700. // ___ _ ___
  1701. // | __| _ ___ _ _| |_| _ \__ _ __ _ ___
  1702. // | _| '_/ _ \ ' \ _| _/ _` / _` / -_)
  1703. // |_||_| \___/_||_\__|_| \__,_\__, \___|
  1704. // |___/
  1705. function backToFrontPage(pop_state){
  1706. console.log('backToFrontPage', pop_state);
  1707. closeAllModals();
  1708. // assume we are going back to front page
  1709. $('body').removeClass().addClass('path-frontpage');
  1710. $('a[data-drupal-link-system-path="<front>"]').addClass('is-active');
  1711. // close entrees
  1712. _$corpus_canvas.trigger({'type':'close-all-entree'});
  1713. _$corpus_canvas.trigger({'type':'scramble-collection'});
  1714. if(typeof pop_state == "undefined" || !pop_state){
  1715. console.log('backToFrontPage push state');
  1716. history.pushState({home:true}, null, drupalSettings.path.baseUrl+drupalSettings.path.currentLanguage);
  1717. }
  1718. }
  1719. function initHome(){
  1720. addCloseModalBtnToCols();
  1721. return;
  1722. console.log('theme : initHome');
  1723. var $grid = $('.grid',_$row).masonry({
  1724. itemSelector:'.col',
  1725. columnWidth:'.col-2',
  1726. horizontalOrder: true,
  1727. containerStyle: null,
  1728. // disable initial layout
  1729. // initLayout: false,
  1730. });
  1731. // bind event
  1732. // $grid.masonry( 'on', 'layoutComplete', function() {
  1733. // console.log('layout is complete');
  1734. // });
  1735. // layout Masonry after each image loads
  1736. $grid.imagesLoaded().progress( function() {
  1737. $grid.masonry('layout');
  1738. });
  1739. $grid.imagesLoaded(function(){
  1740. $grid.masonry('layout');
  1741. });
  1742. }
  1743. // __ __ _ _
  1744. // | \/ |___ __| |__ _| |___
  1745. // | |\/| / _ \/ _` / _` | (_-<
  1746. // |_| |_\___/\__,_\__,_|_/__/
  1747. function closeAllModals(){
  1748. //console.log('theme : closeAllModals');
  1749. // TODO: animate the remove
  1750. _$row.html('');
  1751. _$ajaxLinks.removeClass('is-active');
  1752. _$body.trigger({'type':'all-modal-closed'});
  1753. // checkRowEmpty();
  1754. };
  1755. function checkRowEmpty(){
  1756. console.log('checkRowEmpty');
  1757. // if row is empty and we are not in productions or entree notice|index call closeAllModals()
  1758. if(!$('.col', _$row).length){
  1759. if(!_$body.is('.entity-type-taxonomy_term.bundle-entrees')){
  1760. if(!_$body.is('.entity-type-node.bundle-page')){
  1761. // we weren't on production or entree, so go back to front page
  1762. // debugger;
  1763. if(_$body.is('.bundle-enregistrement.view-mode-article')
  1764. && $('a.articles-link').is('.is-active')){
  1765. console.log('Closing article while article index is active');
  1766. // if node article and articles is active, reload index
  1767. $('a.articles-link').removeClass('is-active').trigger('click');
  1768. }else{
  1769. backToFrontPage();
  1770. }
  1771. // if(!$('a.articles-link').is('.is-active')){
  1772. // // don't go back to front page if articles filter is on
  1773. // backToFrontPage();
  1774. // }else{
  1775. // }
  1776. }else{
  1777. // if we were on production page just scramble collection in case of map was filtered
  1778. _$corpus_canvas.trigger({'type':'scramble-collection'});
  1779. // reload production home
  1780. $('a[data-drupal-link-system-path="productions"]', '#block-mainnavigation')
  1781. .removeClass('is-active').trigger('click');
  1782. }
  1783. }else{
  1784. // remove is-active class from index or notice entree links
  1785. $('.entree-content a.is-active').removeClass('is-active');
  1786. // TODO: remove the hash index or notice
  1787. }
  1788. }
  1789. };
  1790. init();
  1791. } // end EdlpTheme()
  1792. $(document).ready(function($) {
  1793. if(drupalSettings.path.isFront){
  1794. var edlptheme = new EdlpTheme();
  1795. }else{
  1796. $('body').attr('booted', 'booted');
  1797. }
  1798. });
  1799. })(jQuery, Drupal, drupalSettings);