main.js 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883
  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.cartelSwitchInterval = setInterval(this.switchCartel.bind(this), this.cartelSwitchIntervalMS);
  1051. // call drupal behaviours (for addtoany)
  1052. Drupal.attachBehaviors(this.$cartel);
  1053. // open automaticly tha article if needed
  1054. if(this.auto_open_article){
  1055. this.$cartel.find('a.link-article').trigger('click');
  1056. this.auto_open_article = false;
  1057. }
  1058. },
  1059. onNodeLoadFail(jqxhr, textStatus, error){
  1060. console.warn('AudioPlayer node load failed', jqxhr.responseText);
  1061. this.$cartel.removeClass('loading').html('');
  1062. },
  1063. setAutoOpenArticle(art){
  1064. this.auto_open_article = art;
  1065. return this;
  1066. },
  1067. // global
  1068. show(){
  1069. this.$container_parent.addClass('audio-player-visible');
  1070. this.$container.addClass('visible');
  1071. },
  1072. showHidePreviousBtn(){
  1073. if(this.historic.length > 1 && this.currentHistoricIndex > 0){
  1074. this.$previous.addClass('is-active');
  1075. }else{
  1076. this.$previous.removeClass('is-active');
  1077. }
  1078. },
  1079. showHideNextBtn(){
  1080. if(this.currentHistoricIndex < this.historic.length-1 || this.shuffle_is_active){
  1081. this.$next.addClass('is-active');
  1082. }else{
  1083. this.$next.removeClass('is-active');
  1084. }
  1085. },
  1086. timeOutToHide(){
  1087. // console.log('AudioPlayer timeOutToHide()');
  1088. this.clearTimeOutToHide();
  1089. this.hideTimer = setTimeout(this.hide.bind(this), this.hideTimeMS);
  1090. },
  1091. clearTimeOutToHide(){
  1092. // console.log('AudioPlayer clearTimeOutToHide()',this.hideTimer);
  1093. if(this.hideTimer){
  1094. clearTimeout(this.hideTimer);
  1095. this.hideTimer = false;
  1096. }
  1097. },
  1098. // cartel
  1099. switchCartel(){
  1100. // console.log("switchCartel", this.scndCartel_visible);
  1101. if (this.scndCartel_visible) {
  1102. // return to first cartel
  1103. this.$cartel.removeClass('second-visible');
  1104. this.scndCartel_visible = 0;
  1105. }else{
  1106. // switch to 2nd cartel
  1107. this.$cartel.addClass('second-visible');
  1108. this.scndCartel_visible = 1;
  1109. }
  1110. },
  1111. clearIntervalAutoCartelSwitch(){
  1112. if(this.cartelSwitchInterval){
  1113. clearInterval(this.cartelSwitchInterval);
  1114. this.cartelSwitchInterval = false;
  1115. }
  1116. },
  1117. hide(){
  1118. // console.log('AudioPlayer hide()');
  1119. this.$container_parent.removeClass('audio-player-visible');
  1120. this.$container.removeClass('visible');
  1121. // trigger highlighted node remove on corpus map
  1122. try {
  1123. _$corpus_canvas.trigger('audio-node-closed');
  1124. } catch (e) {
  1125. console.info('AudioPlayer hide() : _$corpus_canvas does not exists');
  1126. }
  1127. },
  1128. deActivateRandom(){
  1129. this.shuffle_is_active = false;
  1130. this.showHideNextBtn();
  1131. },
  1132. // object events
  1133. on(event_name, handler){
  1134. if(typeof this.event_handlers[event_name] == 'undefined'){
  1135. console.warn('AudioPlayer : event '+event_name+' does not exists');
  1136. }
  1137. this.event_handlers[event_name].push(handler);
  1138. return this;
  1139. },
  1140. emmit(event_name, args){
  1141. console.log('AudioPlayer emmit()', event_name, args, this.event_handlers[event_name]);
  1142. // console.log('AudioPlayer emmit() handlers', this.event_handlers[event_name]);
  1143. var handler;
  1144. var args = args || {};
  1145. for (var i = this.event_handlers[event_name].length-1; i >= 0 ; i--) {
  1146. handler = this.event_handlers[event_name][i];
  1147. // console.log('AudioPlayer emmit() loop handler', handler);
  1148. (function(handler, args){
  1149. setTimeout(function(){
  1150. // console.log('AudioPlayer emmit() timeout handler', handler);
  1151. handler(args);
  1152. }, 0);
  1153. }(handler, args));
  1154. }
  1155. return this;
  1156. },
  1157. }
  1158. // ___ _ ___ _
  1159. // | _ \__ _ _ _ __| |___ _ __ | _ \ |__ _ _ _ ___ _ _
  1160. // | / _` | ' \/ _` / _ \ ' \| _/ / _` | || / -_) '_|
  1161. // |_|_\__,_|_||_\__,_\___/_|_|_|_| |_\__,_|\_, \___|_|
  1162. // |__/
  1163. function RandomPlayer(playlist){
  1164. this.active = false;
  1165. this.playlist = playlist;
  1166. this.path = drupalSettings.path.baseUrl+drupalSettings.path.pathPrefix+'#random'
  1167. this.$btn = $('<a>').html('Shuffle').attr('href',this.path).addClass('random-player-btn');
  1168. this.init();
  1169. };
  1170. RandomPlayer.prototype = {
  1171. init(){
  1172. // this.shuffle();
  1173. $('<div>')
  1174. .addClass('block random-player')
  1175. .append(this.$btn)
  1176. // .insertAfter('#block-userlogin, #block-studiolinkblock');
  1177. .prependTo('.region-footer-right');
  1178. // events
  1179. this.$btn.on('click', this.toggleActive.bind(this));
  1180. // attach an event on AudioPlayer
  1181. _audioPlayer
  1182. .on('audio-play-next', this.onAudioPlayNext.bind(this))
  1183. .on('audio-ended', this.onAudioPlayerEnded.bind(this))
  1184. // .on('audio-ended', function(e){
  1185. // console.log('RandomPlayer, audio-ended', e);
  1186. // })
  1187. .on('stop-shuffle', this.stop.bind(this));
  1188. _$corpus_canvas
  1189. .on('update-random-playlist', this.updatePlaylist.bind(this));
  1190. // provide a link to auto start random player
  1191. if(window.location.hash == '#random'){
  1192. this.start();
  1193. // window.location.hash = '';
  1194. }
  1195. },
  1196. updatePlaylist(e){
  1197. // debugger;
  1198. this.playlist = e.playlist;
  1199. this.shuffle();
  1200. },
  1201. shuffle(){
  1202. var tempPLaylist = [];
  1203. for (var i = this.playlist.length-1; i >= 0 ; i--) {
  1204. tempPLaylist.push(this.playlist[i]);
  1205. }
  1206. this.shuffledPlaylist = [];
  1207. while(tempPLaylist.length > 0){
  1208. var r = Math.floor(Math.random() * tempPLaylist.length);
  1209. this.shuffledPlaylist.push(tempPLaylist.splice(r,1)[0]);
  1210. }
  1211. //console.log('RandomPlayer, this.shuffledPlaylist', this.shuffledPlaylist);
  1212. },
  1213. toggleActive(e){
  1214. e.preventDefault();
  1215. if (this.active) {
  1216. this.stop();
  1217. }else{
  1218. this.start();
  1219. }
  1220. return false;
  1221. },
  1222. start(){
  1223. this.active = _audioPlayer.shuffle_is_active = true;
  1224. this.$btn.addClass('is-active');
  1225. this.shuffle();
  1226. this.next();
  1227. // piwik
  1228. if(typeof _paq !== 'undefined'){
  1229. // trackEvent(category, action, [name], [value])
  1230. _paq.push(['trackEvent', 'RandomPlayer', 'start']);
  1231. }
  1232. },
  1233. stop(){
  1234. this.active = false;
  1235. this.$btn.removeClass('is-active');
  1236. // stop audio player
  1237. // _audioPlayer.stop();
  1238. // remove hash
  1239. history.replaceState(history.state, null, window.location.pathname);
  1240. // tell to AudioPlayer to deactivate netx btn
  1241. _audioPlayer.deActivateRandom();
  1242. if(typeof _paq !== 'undefined'){
  1243. // trackEvent(category, action, [name], [value])
  1244. _paq.push(['trackEvent', 'RandomPlayer', 'stop']);
  1245. }
  1246. },
  1247. next(){
  1248. console.log('RandomPlayer next', this.active, this.shuffledPlaylist.length);
  1249. if(this.active && this.shuffledPlaylist.length > 0)
  1250. _audioPlayer.openDocument(this.shuffledPlaylist.splice(0,1)[0], 'random');
  1251. },
  1252. onAudioPlayNext(){
  1253. console.log('RandomPlayer : onAudioPlayNext()');
  1254. if(this.active){
  1255. this.next();
  1256. }
  1257. },
  1258. onAudioPlayerEnded(){
  1259. console.log('RandomPlayer : onAudioPlayerEnded()');
  1260. if(this.active){
  1261. this.next();
  1262. }
  1263. }
  1264. };
  1265. // ___ ___ _
  1266. // / __|___ _ __ _ __ ___| _ \ |__ _ _ _ ___ _ _
  1267. // | (__/ _ \ ' \| '_ \/ _ \ _/ / _` | || / -_) '_|
  1268. // \___\___/_|_|_| .__/\___/_| |_\__,_|\_, \___|_|
  1269. // |_| |__/
  1270. function CompoPlayer(){
  1271. this.active = false;
  1272. this.playing = false;
  1273. this.paused = false;
  1274. this.playlist = [];
  1275. this.current_index = 0;
  1276. this.$composer = null;
  1277. this.$compo = null;
  1278. this.$controls = null;
  1279. this.init();
  1280. };
  1281. CompoPlayer.prototype = {
  1282. init(){
  1283. // console.log('CompoPlayer init()');
  1284. // attach an event on AudioPlayer
  1285. _audioPlayer
  1286. .on('audio-open-document', this.onAudioOpenDocument.bind(this))
  1287. .on('audio-play', this.onAudioPlayerPlay.bind(this))
  1288. .on('audio-pause', this.onAudioPlayerPause.bind(this))
  1289. .on('audio-ended', this.onAudioPlayerEnded.bind(this));
  1290. // .on('audio-play-next', this.onAudioPlayNext.bind(this));
  1291. // this.newCompo();
  1292. },
  1293. newCompo(){
  1294. //console.log('CompoPlayer newCompo()');
  1295. // this.$compo = $('.composition_ui .composer .composition');
  1296. this.initControls();
  1297. },
  1298. initControls(){
  1299. //console.log('CompoPlayer initControls()');
  1300. this.$composer = $('.composition_ui .composer');
  1301. this.$compo = $('.composition_ui .composer .composition');
  1302. this.$controls = $('.composition_ui .composer .compo-player-controls');
  1303. if(!this.$controls.is('.ready') && this.$compo){
  1304. this.$previous = $('<div>').addClass('previous')
  1305. .on('click', this.prev.bind(this))
  1306. .appendTo(this.$controls);
  1307. this.$playpause = $('<div>').addClass('play-pause')
  1308. .on('click', this.togglePlayPause.bind(this))
  1309. .appendTo(this.$controls);
  1310. this.$next = $('<div>').addClass('next')
  1311. .on('click', this.next.bind(this))
  1312. .appendTo(this.$controls);
  1313. this.$controls.addClass('ready');
  1314. this.refresh();
  1315. this.active = true;
  1316. // this.newCompo();
  1317. }
  1318. },
  1319. refresh(){
  1320. // console.log('CompoPlayer refresh(), this', this);
  1321. this.stop();
  1322. // load new playlist
  1323. this.playlist = [];
  1324. var that = this;
  1325. $('.field--name-documents .field__item',this.$compo).each(function(i,el){
  1326. var $link = $('a.audio-link',this);
  1327. that.playlist.push({
  1328. item:$(this),
  1329. audio_url:$link.attr("audio_url"),
  1330. nid:$link.attr("nid"),
  1331. });
  1332. });
  1333. this.showHideControls();
  1334. },
  1335. togglePlayPause(){
  1336. // console.log('CompoPlayer togglePlayPause');
  1337. if (this.playing && !this.paused) {
  1338. this.pause();
  1339. }else{
  1340. if(this.playing && this.paused){
  1341. this.play();
  1342. }else{
  1343. this.start();
  1344. }
  1345. }
  1346. },
  1347. start(){
  1348. //console.log('start');
  1349. // console.log('CompoPlayer start()');
  1350. this.playing = true;
  1351. this.play();
  1352. },
  1353. play(){
  1354. // console.log('play');
  1355. if(this.paused){
  1356. this.paused = false;
  1357. _audioPlayer.play();
  1358. }else{
  1359. // _audioPlayer;
  1360. _audioPlayer.emmit('stop-shuffle').openDocument(this.playlist[this.current_index], this);
  1361. // TODO: stop random player
  1362. }
  1363. this.setActiveItem().showHideControls();
  1364. },
  1365. pause(){
  1366. //console.log('pause');
  1367. this.paused = true;
  1368. this.showHideControls();
  1369. _audioPlayer.stop();
  1370. },
  1371. next(){
  1372. // console.log('CompoPlayer next()');
  1373. if(this.playing){
  1374. this.current_index += 1;
  1375. if(this.current_index < this.playlist.length){
  1376. this.play();
  1377. }else{
  1378. this.stop();
  1379. }
  1380. }
  1381. },
  1382. prev(){
  1383. // console.log('CompoPlayer prev()');
  1384. if(this.playing){
  1385. this.current_index -= 1;
  1386. if(this.current_index >= 0){
  1387. this.play();
  1388. }else{
  1389. this.stop();
  1390. }
  1391. }
  1392. },
  1393. stop(){
  1394. if(this.playing){
  1395. _audioPlayer.stop();
  1396. }
  1397. this.reset();
  1398. },
  1399. reset(){
  1400. this.playing = false;
  1401. this.paused = false;
  1402. this.resetIndex();
  1403. },
  1404. resetIndex(){
  1405. this.current_index = 0;
  1406. this.showHideControls().resetActiveItems();
  1407. },
  1408. setActiveItem(){
  1409. this.resetActiveItems();
  1410. if(this.playing && this.current_index >= 0){
  1411. this.playlist[this.current_index].item.addClass('is-active');
  1412. }
  1413. // this call shoud not be here
  1414. this.showHideControls();
  1415. return this;
  1416. },
  1417. resetActiveItems(){
  1418. for (var n = 0; n < this.playlist.length; n++) {
  1419. // console.log('node',node);
  1420. this.playlist[n].item.removeClass('is-active');
  1421. }
  1422. return this;
  1423. },
  1424. showHideControls(){
  1425. // console.log('CompoPlayer showHideNextBtn(), playing:'+this.playing+', paused:'+this.paused);
  1426. // global playing
  1427. if(this.$controls){
  1428. if(this.playing && !this.paused){
  1429. this.$controls.addClass('is-playing');
  1430. }else{
  1431. this.$controls.removeClass('is-playing');
  1432. }
  1433. }
  1434. // playpause
  1435. if(this.$playpause){
  1436. if(this.playlist.length > 0){
  1437. this.$playpause.addClass('is-active');
  1438. }else{
  1439. this.$playpause.removeClass('is-active');
  1440. }
  1441. }
  1442. // next
  1443. if(this.$next){
  1444. if(this.playing && this.playlist.length > 1 && this.current_index < this.playlist.length -1){
  1445. this.$next.addClass('is-active');
  1446. }else{
  1447. this.$next.removeClass('is-active');
  1448. }
  1449. }
  1450. // previous
  1451. if(this.$previous){
  1452. if(this.playing && this.playlist.length > 1 && this.current_index > 0){
  1453. this.$previous.addClass('is-active');
  1454. }else{
  1455. this.$previous.removeClass('is-active');
  1456. }
  1457. }
  1458. return this;
  1459. },
  1460. deactivate(){
  1461. this.stop();
  1462. this.active = false;
  1463. },
  1464. // _audioPlayer events
  1465. onAudioOpenDocument(args){
  1466. if(args.caller !== this){
  1467. // console.log('CompoPlayer onAudioOpenDocument() called by other');
  1468. this.reset();
  1469. }
  1470. // else{
  1471. // // console.log('CompoPlayer onAudioOpenDocument() self calling');
  1472. // }
  1473. },
  1474. onAudioPlayerPlay(){
  1475. if(this.playing && this.paused){
  1476. this.paused = false;
  1477. this.showHideControls();
  1478. }
  1479. },
  1480. onAudioPlayerPause(){
  1481. if(this.playing && !this.paused){
  1482. this.paused = true;
  1483. this.showHideControls();
  1484. }
  1485. },
  1486. onAudioPlayerEnded(){
  1487. if(this.playing){
  1488. this.next();
  1489. }
  1490. },
  1491. // onAudioPlayNext(){
  1492. // this.next();
  1493. // }
  1494. };
  1495. // ___ _ _
  1496. // / __|_ _(_)__| |
  1497. // | (_ | '_| / _` |
  1498. // \___|_| |_\__,_|
  1499. function initGrid(){
  1500. console.log('theme : initGrid');
  1501. checkGridBlockHeight();
  1502. _$row.find('.col').addClass('offfield');
  1503. if(false){
  1504. var $grid = $('.grid',_$row).masonry({
  1505. itemSelector:'.col',
  1506. columnWidth:'.col-2',
  1507. containerStyle: null,
  1508. resizeContainer:false,
  1509. // horizontalOrder: true,
  1510. transitionDuration:0,//'0.2s',
  1511. // stagger:30,
  1512. // disable initial layout
  1513. // initLayout: false,
  1514. });
  1515. // layout Masonry after each image loads
  1516. $grid.imagesLoaded().progress( function() {
  1517. $grid.masonry('layout');
  1518. });
  1519. $grid.imagesLoaded(function(){
  1520. $grid.masonry('layout');
  1521. // checkProductionBlockVisible();
  1522. });
  1523. // bind event
  1524. // $grid.masonry( 'on', 'layoutComplete', function() {
  1525. // console.log('layout is complete');
  1526. // });
  1527. $grid.on('layoutComplete', checkGridBlockVisible);
  1528. }else{
  1529. // setTimeout(checkGridBlockVisible, 100);
  1530. checkGridBlockVisible();
  1531. }
  1532. };
  1533. function checkGridBlockHeight(){
  1534. // console.log('checkGridBlockHeight');
  1535. var $r_h = _$row.height();
  1536. var $this;
  1537. // console.log($r_h);
  1538. $('.grid .col', _$row).each(function(i,e){
  1539. $this = $(this);
  1540. if(!$this.is('[init-height]')){
  1541. $this.attr('init-height', $this.outerHeight())
  1542. }
  1543. // console.log($(this).height(), $(this).innerHeight(), $(this).outerHeight());
  1544. // if($this.height() > $r_h){
  1545. // $this.height($r_h);
  1546. // }else{
  1547. // $this.height('auto');
  1548. // }
  1549. $this.height(Math.min($this.attr('init-height'), _$row.height()));
  1550. });
  1551. };
  1552. function checkGridBlockVisible(){
  1553. // console.log('checkGridBlockVisible');
  1554. var $r_h = _$row.height();
  1555. var $this,pos;
  1556. $('.grid .col', _$row).each(function(i,e){
  1557. // $(this).on('load',function(event){
  1558. $this = $(this);
  1559. pos = $this.position();
  1560. // console.log(pos.top, $this.height(), pos.top+$this.height(), $r_h, $this);
  1561. if(pos.top+$this.height() <= $r_h){
  1562. $this.removeClass('offfield');
  1563. }else{
  1564. $this.addClass('offfield');
  1565. }
  1566. // });
  1567. });
  1568. // for (var i in items) {
  1569. // if(!items[i].isTransitioning){
  1570. // console.log('y+outerHeight', items[i].position.y+items[i].size.outerHeight);
  1571. // console.log('_$row.height()', _$row.height());
  1572. // if(items[i].position.y+items[i].size.outerHeight < _$row.height()){
  1573. // $(items[i].element).removeClass('offfield');
  1574. // }else{
  1575. // // $(items[i].element).addClass('offfield');
  1576. // }
  1577. // }
  1578. // }
  1579. }
  1580. // ___ _ _ _
  1581. // | _ \_ _ ___ __| |_ _ __| |_(_)___ _ _ ___
  1582. // | _/ '_/ _ \/ _` | || / _| _| / _ \ ' \(_-<
  1583. // |_| |_| \___/\__,_|\_,_\__|\__|_\___/_||_/__/
  1584. // function initProductions(){
  1585. // console.log('theme : initProductions');
  1586. //
  1587. // // _$row.find('.col').addClass('offfield');
  1588. // var $grid = $('.grid',_$row).masonry({
  1589. // itemSelector:'.col',
  1590. // columnWidth:'.col-2',
  1591. // containerStyle: null,
  1592. // resizeContainer:false,
  1593. // // horizontalOrder: true,
  1594. // transitionDuration:0,//'0.2s',
  1595. // // stagger:30,
  1596. // // disable initial layout
  1597. // // initLayout: false,
  1598. // });
  1599. //
  1600. // // layout Masonry after each image loads
  1601. // $grid.imagesLoaded().progress( function() {
  1602. // $grid.masonry('layout');
  1603. // });
  1604. //
  1605. // $grid.imagesLoaded(function(){
  1606. // $grid.masonry('layout');
  1607. // // checkProductionBlockVisible();
  1608. // });
  1609. //
  1610. // // bind event
  1611. // // $grid.masonry( 'on', 'layoutComplete', function() {
  1612. // // console.log('layout is complete');
  1613. // // });
  1614. // // $grid.on('layoutComplete', checkProductionBlockVisible);
  1615. // };
  1616. // ___ _
  1617. // / __| ___ __ _ _ _ __| |_
  1618. // \__ \/ -_) _` | '_/ _| ' \
  1619. // |___/\___\__,_|_| \__|_||_|
  1620. function initSearch(){
  1621. // if($('#edit-entries input:checked', '#edlp-search-form').length){
  1622. // $('#edit-entries--wrapper', '#edlp-search-form').toggleClass('opened');
  1623. // }
  1624. $('#edit-entries--wrapper legend', '#edlp-search-form').on('click', function(){
  1625. $(this).parent().toggleClass('opened');
  1626. });
  1627. };
  1628. // ___ _ _ _
  1629. // | __|_ _ _ _ ___ __ _(_)__| |_ _ _ ___ _ __ ___ _ _| |_
  1630. // | _|| ' \| '_/ -_) _` | (_-< _| '_/ -_) ' \/ -_) ' \ _|
  1631. // |___|_||_|_| \___\__, |_/__/\__|_| \___|_|_|_\___|_||_\__|
  1632. // |___/
  1633. function initEnregistrementTranscript(){
  1634. console.log('initEnregistrementTranscript');
  1635. var $node = _$row.find('article.node--type-enregistrement.node--view-mode-transcript');
  1636. var $nav = $('<nav>').prependTo($node);
  1637. $node.find('.field--name-field-transcript-vo').addClass('visible').find('.field__label')
  1638. .clone().appendTo($nav).addClass('is-active')
  1639. .attr('field_target', '.field--name-field-transcript-vo');
  1640. $node.find('.field--name-field-transcript-trad').find('.field__label')
  1641. .clone().appendTo($nav)
  1642. .attr('field_target', '.field--name-field-transcript-trad');
  1643. $nav.find('.field__label').on('click', function(){
  1644. var $this = $(this).addClass('is-active');
  1645. $this.siblings('.is-active').removeClass('is-active');
  1646. $this.parents('article.node').find('.field.visible').removeClass('visible');
  1647. $this.parents('article.node').find($this.attr('field_target')).addClass('visible');
  1648. });
  1649. };
  1650. // ___ _ ___
  1651. // | __| _ ___ _ _| |_| _ \__ _ __ _ ___
  1652. // | _| '_/ _ \ ' \ _| _/ _` / _` / -_)
  1653. // |_||_| \___/_||_\__|_| \__,_\__, \___|
  1654. // |___/
  1655. function backToFrontPage(pop_state){
  1656. console.log('backToFrontPage', pop_state);
  1657. closeAllModals();
  1658. // assume we are going back to front page
  1659. $('body').removeClass().addClass('path-frontpage');
  1660. $('a[data-drupal-link-system-path="<front>"]').addClass('is-active');
  1661. // close entrees
  1662. _$corpus_canvas.trigger({'type':'close-all-entree'});
  1663. _$corpus_canvas.trigger({'type':'scramble-collection'});
  1664. if(typeof pop_state == "undefined" || !pop_state){
  1665. console.log('backToFrontPage push state');
  1666. history.pushState({home:true}, null, drupalSettings.path.baseUrl+drupalSettings.path.currentLanguage);
  1667. }
  1668. }
  1669. function initHome(){
  1670. addCloseModalBtnToCols();
  1671. return;
  1672. console.log('theme : initHome');
  1673. var $grid = $('.grid',_$row).masonry({
  1674. itemSelector:'.col',
  1675. columnWidth:'.col-2',
  1676. horizontalOrder: true,
  1677. containerStyle: null,
  1678. // disable initial layout
  1679. // initLayout: false,
  1680. });
  1681. // bind event
  1682. // $grid.masonry( 'on', 'layoutComplete', function() {
  1683. // console.log('layout is complete');
  1684. // });
  1685. // layout Masonry after each image loads
  1686. $grid.imagesLoaded().progress( function() {
  1687. $grid.masonry('layout');
  1688. });
  1689. $grid.imagesLoaded(function(){
  1690. $grid.masonry('layout');
  1691. });
  1692. }
  1693. // __ __ _ _
  1694. // | \/ |___ __| |__ _| |___
  1695. // | |\/| / _ \/ _` / _` | (_-<
  1696. // |_| |_\___/\__,_\__,_|_/__/
  1697. function closeAllModals(){
  1698. //console.log('theme : closeAllModals');
  1699. // TODO: animate the remove
  1700. _$row.html('');
  1701. _$ajaxLinks.removeClass('is-active');
  1702. _$body.trigger({'type':'all-modal-closed'});
  1703. // checkRowEmpty();
  1704. };
  1705. function checkRowEmpty(){
  1706. // if row is empty and we are not in productions or entree notice|index call closeAllModals()
  1707. if(!$('.col', _$row).length){
  1708. if(!_$body.is('.entity-type-taxonomy_term.bundle-entrees')){
  1709. if(!_$body.is('.entity-type-node.bundle-page')){
  1710. // we weren't on production or entree, so go back to front page
  1711. backToFrontPage();
  1712. }else{
  1713. // if we were on production page just scramble collection in case of map was filtered
  1714. _$corpus_canvas.trigger({'type':'scramble-collection'});
  1715. // reload production home
  1716. $('a[data-drupal-link-system-path="productions"]', '#block-mainnavigation')
  1717. .removeClass('is-active').trigger('click');
  1718. }
  1719. }else{
  1720. // remove is-active class from index or notice entree links
  1721. $('.entree-content a.is-active').removeClass('is-active');
  1722. // TODO: remove the hash index or notice
  1723. }
  1724. }
  1725. };
  1726. init();
  1727. } // end EdlpTheme()
  1728. $(document).ready(function($) {
  1729. if(drupalSettings.path.isFront){
  1730. var edlptheme = new EdlpTheme();
  1731. }else{
  1732. $('body').attr('booted', 'booted');
  1733. }
  1734. });
  1735. })(jQuery, Drupal, drupalSettings);