main.js 63 KB

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