main.js 63 KB

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