main.js 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892
  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. // let the site-name link going through as it will shuffle the map if already active
  613. if($link.is('.is-active') && !$link.is('.site-name'))
  614. return false;
  615. // Audio links
  616. // launch audio player and stop here
  617. if($link.is('.audio-link')){
  618. _audioPlayer
  619. .emmit('stop-shuffle')
  620. .openDocument({
  621. nid:$link.attr('nid'),
  622. audio_url:$link.attr('audio_url'),
  623. title:$link.find('.field--name-title').html()
  624. });
  625. return false;
  626. }
  627. // other sounds playing
  628. if($link.is('[type^="audio"]')){
  629. _audioPlayer
  630. .emmit('stop-shuffle')
  631. .openSound($link.attr('href'), $link.html());
  632. return false;
  633. }
  634. // NOT USED ( YET ? )
  635. // if($link.is('.language-link')){
  636. // TODO: change global site current language
  637. // load all blocks translated (exepted language switcher) ... :/
  638. // refreshAllBlocks();
  639. // TODO: use a promise to initAjaxLinks again after blocks updated
  640. // then let load the content
  641. // }
  642. // other links
  643. var sys_path = $(this).attr('data-drupal-link-system-path');
  644. // front page
  645. // just remove contents and stop here
  646. if(sys_path == '<front>'){
  647. if($link.is('.is-active') && _corpus_ready){
  648. _$corpus_canvas.trigger({'type':'shuffle-collection'});
  649. }else{
  650. backToFrontPage();
  651. }
  652. return false;
  653. }
  654. var view_mode = $link.attr('viewmode');
  655. var state = getSysPathState(sys_path, view_mode);
  656. state.url = $(this).attr('href');
  657. if(view_mode){
  658. state.url += "#"+view_mode;
  659. }
  660. if($link.is('[selector]')){
  661. state.selector = $link.attr('selector');
  662. }
  663. $link.addClass('ajax-loading');
  664. // ajaxLoadContent(url, sys_path, state.ajax_path, selector);
  665. ajaxLoadContent(state);
  666. return false;
  667. };
  668. // ___
  669. // / __|___ _ _ _ __ _ _ ___
  670. // | (__/ _ \ '_| '_ \ || (_-<
  671. // \___\___/_| | .__/\_,_/__/
  672. // |_|
  673. function onCorpusMapReady(e){
  674. //console.log('theme : onCorpusReady', e);
  675. _corpus_ready = true;
  676. _$corpus_canvas = $('canvas#corpus-map');
  677. _$corpus_canvas
  678. .on('corpus-cliked-on-map', function(e) {
  679. //console.log('theme : corpus-cliked-on-map');
  680. backToFrontPage();
  681. })
  682. .on('corpus-cliked-on-node', function(e) {
  683. //console.log('theme : corpus-cliked-on-node', e);
  684. _audioPlayer
  685. .emmit('stop-shuffle')
  686. .setAutoOpenArticle(e.article)
  687. .openDocument(e.target_node);
  688. });
  689. _randomPlayer = new RandomPlayer(e.playlist);
  690. _$body.attr('corpus-map', 'ready');
  691. }
  692. function openEntree(tid){
  693. if(tid){
  694. closeAllModals();
  695. _$body.removeClass();//.addClass(body_classes.join(' '));
  696. // open entree
  697. if(_corpus_ready){
  698. _$corpus_canvas.trigger({
  699. type:'open-entree',
  700. tid:tid
  701. });
  702. }else{
  703. // else : EdlpCorpus will check when ready if entry item (notice or index) is already .is-active
  704. $('li.entree[tid="'+tid+'"] a.term-link').addClass('is-active');
  705. }
  706. }
  707. };
  708. function checkVisibleCorpusMapSpace(){
  709. var left_limit = 0, right_limit = 0;
  710. _$row.find('.col').each(function(i,e){
  711. var $col = $(this);
  712. var offset = $col.offset();
  713. console.log('$col', $col);
  714. switch(true){
  715. case $col.is('.float-right'):
  716. right_limit = Math.max(right_limit, Math.abs(offset.left-15-window.innerWidth));
  717. break;
  718. default:
  719. left_limit = Math.max(left_limit, offset.left+$col.width()+15);
  720. break;
  721. }
  722. });
  723. console.log('checkVisibleCorpusMapSpace left_limit:'+left_limit+" right_limit:"+right_limit);
  724. if(_corpus_ready){
  725. _$body.trigger({
  726. type:'visible-space-changed',
  727. left_limit:left_limit,
  728. right_limit:right_limit
  729. });
  730. }else{
  731. _corpus_promise.done(function(){
  732. _$body.trigger({
  733. type:'visible-space-changed',
  734. left_limit:left_limit,
  735. right_limit:right_limit
  736. });
  737. });
  738. }
  739. };
  740. // _ _ _
  741. // /_\ _ _ __| (_)___
  742. // / _ \ || / _` | / _ \
  743. // /_/ \_\_,_\__,_|_\___/
  744. //
  745. // https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement
  746. // https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/samples/gg589528%28v%3dvs.85%29
  747. // https://www.binarytides.com/using-html5-audio-element-javascript/
  748. function AudioPlayer(){
  749. var that = this;
  750. this.fid;
  751. this.audio = new Audio();
  752. // audio events
  753. this.audio_events = ["loadedmetadata","playing","pause","timeupdate","ended","error"]; // ,"canplay"
  754. // UI dom objects
  755. this.$container = $('<div id="audio-player">');
  756. // btns
  757. this.$btns = $('<div>').addClass('btns').appendTo(this.$container);
  758. this.$previous = $('<div>').addClass('previous').appendTo(this.$btns);
  759. this.$playpause = $('<div>').addClass('play-pause').appendTo(this.$btns);
  760. this.$next = $('<div>').addClass('next').appendTo(this.$btns);
  761. // timeline
  762. this.$timelinecont= $('<div>').addClass('time-line-container').appendTo(this.$container);
  763. this.$timeline = $('<div>').addClass('time-line').appendTo(this.$timelinecont);
  764. this.$loader = $('<div>').addClass('loader').appendTo(this.$timeline);
  765. this.$cursor = $('<div>').addClass('cursor').appendTo(this.$timeline);
  766. // time
  767. this.$time = $('<div>').addClass('time').appendTo(this.$container);
  768. this.$currentTime = $('<div>').addClass('current-time').html('00:00').appendTo(this.$time);
  769. this.$duration = $('<div>').addClass('duration').html('00:00').appendTo(this.$time);
  770. // favoris
  771. this.$fav = $('<div>').addClass('favoris').appendTo(this.$container);
  772. // cartel
  773. this.$cartel = $('<div>').addClass('cartel').appendTo(this.$container);
  774. this.scndCartel_visible = 0;
  775. this.cartelSwitchIntervalMS = 7000;
  776. this.cartelSwitchInterval = false;
  777. // hiding
  778. this.hideTimer = false;
  779. this.hideTimeMS = 15000;
  780. // history
  781. this.currentHistoricIndex = null;
  782. this.historic = [];
  783. this.shuffle_is_active = false;
  784. // artciles
  785. this.auto_open_article = false;
  786. // object events
  787. this.event_handlers = {
  788. 'audio-open-document':[],
  789. 'audio-play':[],
  790. 'audio-pause':[],
  791. 'audio-play-next':[],
  792. 'audio-ended':[],
  793. 'stop-shuffle':[]
  794. };
  795. this.init();
  796. };
  797. AudioPlayer.prototype = {
  798. init(){
  799. this.$container_parent = $('header[role="banner"] .region-header');
  800. // append ui to document
  801. this.$container.appendTo(this.$container_parent);
  802. // record timeline width
  803. this.timeline_w = parseInt(this.$timeline.width());
  804. // init seeking
  805. this.$loader.on('click', this.seek.bind(this));
  806. // init audio events
  807. var fn = '';
  808. for (var i = 0; i < this.audio_events.length; i++) {
  809. fn = this.audio_events[i];
  810. // capitalize first letter of event (only cosmetic :p )
  811. fn = 'on'+fn.charAt(0).toUpperCase()+fn.slice(1);
  812. this.audio.addEventListener(
  813. this.audio_events[i],
  814. this[fn].bind(this),
  815. true);
  816. }
  817. // init btns events
  818. this.$previous.on('click', this.playPrevious.bind(this));
  819. this.$playpause.on('click', this.togglePlayPause.bind(this));
  820. this.$next.on('click', this.playNext.bind(this));
  821. },
  822. openDocument(node, caller, historic_index){
  823. console.log('AudioPlayer openDocument', node, caller);
  824. if(typeof node == 'undefined'
  825. || typeof node.nid == 'undefined'
  826. || typeof node.audio_url == 'undefined'){
  827. console.warn('AudioPlayer openDocument() node is malformed', node);
  828. return false;
  829. }
  830. // if we don't come from history popstate
  831. if(typeof caller == 'undefined' || caller != 'popstate'){
  832. this.historic.push(node);
  833. this.currentHistoricIndex = this.historic.length-1;
  834. // this.shuffle_mode = shuffle_mode || false;
  835. // add the document opening to history to be able to share and play audio from any where
  836. if(caller != "history_first_load"){
  837. if(typeof node.document_url == 'undefined'){
  838. console.warn("AudioPlayer openDocument missing document_url, can't push state to history", caller, node);
  839. }else{
  840. var state = {
  841. audio:true,
  842. node:{
  843. nid:node.nid,
  844. audio_url:node.audio_url,
  845. document_url:node.document_url,
  846. title:node.title || null,
  847. },
  848. historic_index : this.currentHistoricIndex,
  849. };
  850. // console.log('AudioPlayer pushstate', state);
  851. var url = node.document_url + (caller == 'random' ? '#random' : '');
  852. history.pushState(state, null, url);
  853. }
  854. }
  855. }else{
  856. // if the call commes from popstate, we update the current position of index
  857. this.currentHistoricIndex = historic_index;
  858. }
  859. if(_$body.is('.path-frontpage')){
  860. closeAllModals();
  861. }
  862. // TODO: update language switcher for document url
  863. // TODO: stop random player if playing from studio
  864. this.emmit('audio-open-document', {caller:caller});
  865. // piwik
  866. // debugger;
  867. if(typeof _paq !== 'undefined'){
  868. // page tracking
  869. // https://matomo.org/blog/2017/02/how-to-track-single-page-websites-using-piwik-analytics/
  870. // _paq.push(['setCustomUrl', state.url]);
  871. // _paq.push(['setDocumentTitle', data.title]);
  872. // _paq.push(['trackPageView']);
  873. // js event
  874. // trackEvent(category, action, [name], [value])
  875. if(typeof node.title != 'undefined'){
  876. _paq.push(['trackEvent', 'Audio', 'play', node.title]);
  877. }
  878. }
  879. this.launch();
  880. },
  881. launch(){
  882. this.clearTimeOutToHide();
  883. this.clearIntervalAutoCartelSwitch();
  884. this.setSRC(this.historic[this.currentHistoricIndex].audio_url);
  885. this.loadNode(this.historic[this.currentHistoricIndex].nid);
  886. // emmit new playing doc (e.g.: corpus map nowing that audio played from RandomPlayer)
  887. try {
  888. _$corpus_canvas.trigger({
  889. 'type':'audio-node-opened',
  890. 'nid':this.historic[this.currentHistoricIndex].nid
  891. });
  892. } catch (e) {
  893. console.info('AudioPlayer : _$corpus_canvas does not exists, testing promise');
  894. var that = this;
  895. _corpus_promise.done(function(){
  896. _$corpus_canvas.trigger({
  897. 'type':'audio-node-opened',
  898. 'nid':that.historic[that.currentHistoricIndex].nid
  899. });
  900. });
  901. }
  902. this.showHidePreviousBtn();
  903. this.showHideNextBtn();
  904. this.show();
  905. },
  906. openSound(url, title){
  907. this.hide();
  908. this.clearTimeOutToHide();
  909. this.$cartel.html("");
  910. this.setSRC(url);
  911. this.show();
  912. if(typeof _paq !== 'undefined'){
  913. _paq.push(['trackEvent', 'Audio', 'play', url]);
  914. }
  915. },
  916. // audio functions
  917. setSRC(url){
  918. console.log('AudioPlayer setSRC : url', url);
  919. this.audio.src = url;
  920. // need to trigger play right now to prevent safari blocking auto-play
  921. this.play();
  922. },
  923. // audio is ready to play
  924. onLoadedmetadata(){
  925. var rem = parseInt(this.audio.duration, 10),
  926. mins = Math.floor(rem/60,10),
  927. secs = rem - mins*60;
  928. this.$duration.html('<span>'+(mins<10 ? '0':'')+mins+':'+(secs<10 ? '0':'')+secs+'</span>');
  929. this.updateLoadingBar();
  930. },
  931. updateLoadingBar(){
  932. console.log("updateLoadingBar");
  933. // var that = this;
  934. // if (this.audio.readyState === 4){
  935. if(this.audio.buffered.length>0){
  936. // debugger;
  937. this.$loader.css({
  938. 'width':parseInt((100 * this.audio.buffered.end(0) / this.audio.duration), 10)+'%'
  939. });
  940. if( this.audio.buffered.end(0) < this.audio.duration ){
  941. // loop through this function until file is fully loaded
  942. window.requestAnimationFrame(this.updateLoadingBar.bind(this));
  943. }else{
  944. console.log('Audio fully loaded');
  945. }
  946. }else{
  947. // as audio buffer is not ready, recall updateLoadingBar in next frame
  948. window.requestAnimationFrame(this.updateLoadingBar.bind(this));
  949. }
  950. },
  951. // onCanplay(){
  952. // // this.play();
  953. // },
  954. onError(){
  955. console.warn("Audio Error " + this.audio.error.code + "; details: " + this.audio.error.message);
  956. },
  957. play(){
  958. this.clearTimeOutToHide();
  959. // this.audio.play();
  960. // 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
  961. var promise = this.audio.play();
  962. // console.log('promise', promise);
  963. if (promise !== undefined) {
  964. promise.catch(function(error){
  965. // Auto-play was prevented
  966. // Show a UI element to let the user manually start playback
  967. console.warn('autoplay failed, ask for playing', error);
  968. }).then(function(){
  969. // Auto-play started
  970. console.log('autoplay succeed');
  971. });
  972. }
  973. },
  974. playPrevious(){
  975. if(this.currentHistoricIndex > 0){
  976. this.currentHistoricIndex -= 1;
  977. this.launch();
  978. // TODO: update history state
  979. }
  980. },
  981. playNext(){
  982. if(this.currentHistoricIndex < this.historic.length-1){
  983. this.currentHistoricIndex += 1;
  984. this.launch();
  985. // TODO: update history state
  986. }else{
  987. this.emmit('audio-play-next');
  988. }
  989. },
  990. togglePlayPause(e){
  991. if(this.audio.paused){
  992. // this.audio.play();
  993. this.play();
  994. }else{
  995. // this.audio.pause();
  996. this.stop();
  997. }
  998. },
  999. stop(){
  1000. // console.log('AudioPlayer stop()');
  1001. // debugger;
  1002. this.audio.pause();
  1003. // don't close player if article or transcript is open
  1004. if(!(_$body.is('.path-node-'+this.historic[this.currentHistoricIndex].nid)
  1005. && (_$body.is('.view-mode-article') || _$body.is('.view-mode-transcript')))){
  1006. this.timeOutToHide();
  1007. }
  1008. },
  1009. seek(e){
  1010. var seek = e.originalEvent.layerX / this.timeline_w * this.audio.duration
  1011. console.log("Audio seeking : seek", seek);
  1012. this.audio.currentTime = seek;
  1013. },
  1014. // audio events
  1015. onPlaying(){
  1016. this.$btns.addClass('is-playing');
  1017. this.emmit('audio-play');
  1018. },
  1019. onPause(){
  1020. this.$btns.removeClass('is-playing');
  1021. this.emmit('audio-pause');
  1022. },
  1023. onTimeupdate(){
  1024. // move cursor
  1025. this.$cursor.css({
  1026. 'left':(this.audio.currentTime/this.audio.duration * this.timeline_w)+"px"
  1027. });
  1028. // update time text display
  1029. var rem = parseInt(this.audio.currentTime, 10),
  1030. mins = Math.floor(rem/60,10),
  1031. secs = rem - mins*60;
  1032. this.$currentTime.html('<span>'+(mins<10 ? '0':'')+mins+':'+(secs<10 ? '0':'')+secs+'</span>');
  1033. },
  1034. onEnded(){
  1035. console.log('AudioPlayer onEnded()');
  1036. this.stop();
  1037. this.emmit('audio-ended');
  1038. },
  1039. // cartel functions
  1040. loadNode(nid){
  1041. this.$cartel.addClass('loading');
  1042. var vm = 'player_cartel';
  1043. var ajax_path = _ajax_settings.entityjson_path+'/node/'+nid+'/'+vm;
  1044. var path = window.location.origin + Drupal.url(ajax_path);
  1045. $.getJSON(path, {})
  1046. .done(this.onNodeLoaded.bind(this))
  1047. .fail(this.onNodeLoadFail.bind(this));
  1048. },
  1049. onNodeLoaded(data){
  1050. // console.log('AudioPlayer node loaded');
  1051. this.$cartel.html(data.rendered).removeClass('loading');
  1052. _$body.trigger({'type':'new-audio-cartel-loaded'});
  1053. initAjaxLinks();
  1054. // init cartel auto switch
  1055. this.scndCartel_visible = 0;
  1056. this.$cartel.removeClass('second-visible');
  1057. this.cartelSwitchInterval = setInterval(this.switchCartel.bind(this), this.cartelSwitchIntervalMS);
  1058. // call drupal behaviours (for addtoany)
  1059. Drupal.attachBehaviors(this.$cartel);
  1060. // open automaticly tha article if needed
  1061. if(this.auto_open_article){
  1062. this.$cartel.find('a.link-article').trigger('click');
  1063. this.auto_open_article = false;
  1064. }
  1065. },
  1066. onNodeLoadFail(jqxhr, textStatus, error){
  1067. console.warn('AudioPlayer node load failed', jqxhr.responseText);
  1068. this.$cartel.removeClass('loading').html('');
  1069. },
  1070. setAutoOpenArticle(art){
  1071. this.auto_open_article = art;
  1072. return this;
  1073. },
  1074. // global
  1075. show(){
  1076. this.$container_parent.addClass('audio-player-visible');
  1077. this.$container.addClass('visible');
  1078. },
  1079. showHidePreviousBtn(){
  1080. if(this.historic.length > 1 && this.currentHistoricIndex > 0){
  1081. this.$previous.addClass('is-active');
  1082. }else{
  1083. this.$previous.removeClass('is-active');
  1084. }
  1085. },
  1086. showHideNextBtn(){
  1087. if(this.currentHistoricIndex < this.historic.length-1 || this.shuffle_is_active){
  1088. this.$next.addClass('is-active');
  1089. }else{
  1090. this.$next.removeClass('is-active');
  1091. }
  1092. },
  1093. timeOutToHide(){
  1094. // console.log('AudioPlayer timeOutToHide()');
  1095. this.clearTimeOutToHide();
  1096. this.hideTimer = setTimeout(this.hide.bind(this), this.hideTimeMS);
  1097. },
  1098. clearTimeOutToHide(){
  1099. // console.log('AudioPlayer clearTimeOutToHide()',this.hideTimer);
  1100. if(this.hideTimer){
  1101. clearTimeout(this.hideTimer);
  1102. this.hideTimer = false;
  1103. }
  1104. },
  1105. // cartel
  1106. switchCartel(){
  1107. // console.log("switchCartel", this.scndCartel_visible);
  1108. if (this.scndCartel_visible) {
  1109. // return to first cartel
  1110. this.$cartel.removeClass('second-visible');
  1111. this.scndCartel_visible = 0;
  1112. }else{
  1113. // switch to 2nd cartel
  1114. this.$cartel.addClass('second-visible');
  1115. this.scndCartel_visible = 1;
  1116. }
  1117. },
  1118. clearIntervalAutoCartelSwitch(){
  1119. if(this.cartelSwitchInterval){
  1120. clearInterval(this.cartelSwitchInterval);
  1121. this.cartelSwitchInterval = false;
  1122. }
  1123. },
  1124. hide(){
  1125. // console.log('AudioPlayer hide()');
  1126. this.$container_parent.removeClass('audio-player-visible');
  1127. this.$container.removeClass('visible');
  1128. // trigger highlighted node remove on corpus map
  1129. try {
  1130. _$corpus_canvas.trigger('audio-node-closed');
  1131. } catch (e) {
  1132. console.info('AudioPlayer hide() : _$corpus_canvas does not exists');
  1133. }
  1134. },
  1135. deActivateRandom(){
  1136. this.shuffle_is_active = false;
  1137. this.showHideNextBtn();
  1138. },
  1139. // object events
  1140. on(event_name, handler){
  1141. if(typeof this.event_handlers[event_name] == 'undefined'){
  1142. console.warn('AudioPlayer : event '+event_name+' does not exists');
  1143. }
  1144. this.event_handlers[event_name].push(handler);
  1145. return this;
  1146. },
  1147. emmit(event_name, args){
  1148. console.log('AudioPlayer emmit()', event_name, args, this.event_handlers[event_name]);
  1149. // console.log('AudioPlayer emmit() handlers', this.event_handlers[event_name]);
  1150. var handler;
  1151. var args = args || {};
  1152. for (var i = this.event_handlers[event_name].length-1; i >= 0 ; i--) {
  1153. handler = this.event_handlers[event_name][i];
  1154. // console.log('AudioPlayer emmit() loop handler', handler);
  1155. (function(handler, args){
  1156. setTimeout(function(){
  1157. // console.log('AudioPlayer emmit() timeout handler', handler);
  1158. handler(args);
  1159. }, 0);
  1160. }(handler, args));
  1161. }
  1162. return this;
  1163. },
  1164. }
  1165. // ___ _ ___ _
  1166. // | _ \__ _ _ _ __| |___ _ __ | _ \ |__ _ _ _ ___ _ _
  1167. // | / _` | ' \/ _` / _ \ ' \| _/ / _` | || / -_) '_|
  1168. // |_|_\__,_|_||_\__,_\___/_|_|_|_| |_\__,_|\_, \___|_|
  1169. // |__/
  1170. function RandomPlayer(playlist){
  1171. this.active = false;
  1172. this.playlist = playlist;
  1173. this.path = drupalSettings.path.baseUrl+drupalSettings.path.pathPrefix+'#random'
  1174. this.$btn = $('<a>').html('Shuffle').attr('href',this.path).addClass('random-player-btn');
  1175. this.init();
  1176. };
  1177. RandomPlayer.prototype = {
  1178. init(){
  1179. // this.shuffle();
  1180. $('<div>')
  1181. .addClass('block random-player')
  1182. .append(this.$btn)
  1183. // .insertAfter('#block-userlogin, #block-studiolinkblock');
  1184. .prependTo('.region-footer-right');
  1185. // events
  1186. this.$btn.on('click', this.toggleActive.bind(this));
  1187. // attach an event on AudioPlayer
  1188. _audioPlayer
  1189. .on('audio-play-next', this.onAudioPlayNext.bind(this))
  1190. .on('audio-ended', this.onAudioPlayerEnded.bind(this))
  1191. // .on('audio-ended', function(e){
  1192. // console.log('RandomPlayer, audio-ended', e);
  1193. // })
  1194. .on('stop-shuffle', this.stop.bind(this));
  1195. _$corpus_canvas
  1196. .on('update-random-playlist', this.updatePlaylist.bind(this));
  1197. // provide a link to auto start random player
  1198. if(window.location.hash == '#random'){
  1199. this.start();
  1200. // window.location.hash = '';
  1201. }
  1202. },
  1203. updatePlaylist(e){
  1204. // debugger;
  1205. this.playlist = e.playlist;
  1206. this.shuffle();
  1207. },
  1208. shuffle(){
  1209. var tempPLaylist = [];
  1210. for (var i = this.playlist.length-1; i >= 0 ; i--) {
  1211. tempPLaylist.push(this.playlist[i]);
  1212. }
  1213. this.shuffledPlaylist = [];
  1214. while(tempPLaylist.length > 0){
  1215. var r = Math.floor(Math.random() * tempPLaylist.length);
  1216. this.shuffledPlaylist.push(tempPLaylist.splice(r,1)[0]);
  1217. }
  1218. //console.log('RandomPlayer, this.shuffledPlaylist', this.shuffledPlaylist);
  1219. },
  1220. toggleActive(e){
  1221. e.preventDefault();
  1222. if (this.active) {
  1223. this.stop();
  1224. }else{
  1225. this.start();
  1226. }
  1227. return false;
  1228. },
  1229. start(){
  1230. this.active = _audioPlayer.shuffle_is_active = true;
  1231. this.$btn.addClass('is-active');
  1232. this.shuffle();
  1233. this.next();
  1234. // piwik
  1235. if(typeof _paq !== 'undefined'){
  1236. // trackEvent(category, action, [name], [value])
  1237. _paq.push(['trackEvent', 'RandomPlayer', 'start']);
  1238. }
  1239. },
  1240. stop(){
  1241. this.active = false;
  1242. this.$btn.removeClass('is-active');
  1243. // stop audio player
  1244. // _audioPlayer.stop();
  1245. // remove hash
  1246. history.replaceState(history.state, null, window.location.pathname);
  1247. // tell to AudioPlayer to deactivate netx btn
  1248. _audioPlayer.deActivateRandom();
  1249. if(typeof _paq !== 'undefined'){
  1250. // trackEvent(category, action, [name], [value])
  1251. _paq.push(['trackEvent', 'RandomPlayer', 'stop']);
  1252. }
  1253. },
  1254. next(){
  1255. console.log('RandomPlayer next', this.active, this.shuffledPlaylist.length);
  1256. if(this.active && this.shuffledPlaylist.length > 0)
  1257. _audioPlayer.openDocument(this.shuffledPlaylist.splice(0,1)[0], 'random');
  1258. },
  1259. onAudioPlayNext(){
  1260. console.log('RandomPlayer : onAudioPlayNext()');
  1261. if(this.active){
  1262. this.next();
  1263. }
  1264. },
  1265. onAudioPlayerEnded(){
  1266. console.log('RandomPlayer : onAudioPlayerEnded()');
  1267. if(this.active){
  1268. this.next();
  1269. }
  1270. }
  1271. };
  1272. // ___ ___ _
  1273. // / __|___ _ __ _ __ ___| _ \ |__ _ _ _ ___ _ _
  1274. // | (__/ _ \ ' \| '_ \/ _ \ _/ / _` | || / -_) '_|
  1275. // \___\___/_|_|_| .__/\___/_| |_\__,_|\_, \___|_|
  1276. // |_| |__/
  1277. function CompoPlayer(){
  1278. this.active = false;
  1279. this.playing = false;
  1280. this.paused = false;
  1281. this.playlist = [];
  1282. this.current_index = 0;
  1283. this.$composer = null;
  1284. this.$compo = null;
  1285. this.$controls = null;
  1286. this.init();
  1287. };
  1288. CompoPlayer.prototype = {
  1289. init(){
  1290. // console.log('CompoPlayer init()');
  1291. // attach an event on AudioPlayer
  1292. _audioPlayer
  1293. .on('audio-open-document', this.onAudioOpenDocument.bind(this))
  1294. .on('audio-play', this.onAudioPlayerPlay.bind(this))
  1295. .on('audio-pause', this.onAudioPlayerPause.bind(this))
  1296. .on('audio-ended', this.onAudioPlayerEnded.bind(this));
  1297. // .on('audio-play-next', this.onAudioPlayNext.bind(this));
  1298. // this.newCompo();
  1299. },
  1300. newCompo(){
  1301. //console.log('CompoPlayer newCompo()');
  1302. // this.$compo = $('.composition_ui .composer .composition');
  1303. this.initControls();
  1304. },
  1305. initControls(){
  1306. //console.log('CompoPlayer initControls()');
  1307. this.$composer = $('.composition_ui .composer');
  1308. this.$compo = $('.composition_ui .composer .composition');
  1309. this.$controls = $('.composition_ui .composer .compo-player-controls');
  1310. if(!this.$controls.is('.ready') && this.$compo){
  1311. this.$previous = $('<div>').addClass('previous')
  1312. .on('click', this.prev.bind(this))
  1313. .appendTo(this.$controls);
  1314. this.$playpause = $('<div>').addClass('play-pause')
  1315. .on('click', this.togglePlayPause.bind(this))
  1316. .appendTo(this.$controls);
  1317. this.$next = $('<div>').addClass('next')
  1318. .on('click', this.next.bind(this))
  1319. .appendTo(this.$controls);
  1320. this.$controls.addClass('ready');
  1321. this.refresh();
  1322. this.active = true;
  1323. // this.newCompo();
  1324. }
  1325. },
  1326. refresh(){
  1327. // console.log('CompoPlayer refresh(), this', this);
  1328. this.stop();
  1329. // load new playlist
  1330. this.playlist = [];
  1331. var that = this;
  1332. $('.field--name-documents .field__item',this.$compo).each(function(i,el){
  1333. var $link = $('a.audio-link',this);
  1334. that.playlist.push({
  1335. item:$(this),
  1336. audio_url:$link.attr("audio_url"),
  1337. nid:$link.attr("nid"),
  1338. });
  1339. });
  1340. this.showHideControls();
  1341. },
  1342. togglePlayPause(){
  1343. // console.log('CompoPlayer togglePlayPause');
  1344. if (this.playing && !this.paused) {
  1345. this.pause();
  1346. }else{
  1347. if(this.playing && this.paused){
  1348. this.play();
  1349. }else{
  1350. this.start();
  1351. }
  1352. }
  1353. },
  1354. start(){
  1355. //console.log('start');
  1356. // console.log('CompoPlayer start()');
  1357. this.playing = true;
  1358. this.play();
  1359. },
  1360. play(){
  1361. // console.log('play');
  1362. if(this.paused){
  1363. this.paused = false;
  1364. _audioPlayer.play();
  1365. }else{
  1366. // _audioPlayer;
  1367. _audioPlayer.emmit('stop-shuffle').openDocument(this.playlist[this.current_index], this);
  1368. // TODO: stop random player
  1369. }
  1370. this.setActiveItem().showHideControls();
  1371. },
  1372. pause(){
  1373. //console.log('pause');
  1374. this.paused = true;
  1375. this.showHideControls();
  1376. _audioPlayer.stop();
  1377. },
  1378. next(){
  1379. // console.log('CompoPlayer next()');
  1380. if(this.playing){
  1381. this.current_index += 1;
  1382. if(this.current_index < this.playlist.length){
  1383. this.play();
  1384. }else{
  1385. this.stop();
  1386. }
  1387. }
  1388. },
  1389. prev(){
  1390. // console.log('CompoPlayer prev()');
  1391. if(this.playing){
  1392. this.current_index -= 1;
  1393. if(this.current_index >= 0){
  1394. this.play();
  1395. }else{
  1396. this.stop();
  1397. }
  1398. }
  1399. },
  1400. stop(){
  1401. if(this.playing){
  1402. _audioPlayer.stop();
  1403. }
  1404. this.reset();
  1405. },
  1406. reset(){
  1407. this.playing = false;
  1408. this.paused = false;
  1409. this.resetIndex();
  1410. },
  1411. resetIndex(){
  1412. this.current_index = 0;
  1413. this.showHideControls().resetActiveItems();
  1414. },
  1415. setActiveItem(){
  1416. this.resetActiveItems();
  1417. if(this.playing && this.current_index >= 0){
  1418. this.playlist[this.current_index].item.addClass('is-active');
  1419. }
  1420. // this call shoud not be here
  1421. this.showHideControls();
  1422. return this;
  1423. },
  1424. resetActiveItems(){
  1425. for (var n = 0; n < this.playlist.length; n++) {
  1426. // console.log('node',node);
  1427. this.playlist[n].item.removeClass('is-active');
  1428. }
  1429. return this;
  1430. },
  1431. showHideControls(){
  1432. // console.log('CompoPlayer showHideNextBtn(), playing:'+this.playing+', paused:'+this.paused);
  1433. // global playing
  1434. if(this.$controls){
  1435. if(this.playing && !this.paused){
  1436. this.$controls.addClass('is-playing');
  1437. }else{
  1438. this.$controls.removeClass('is-playing');
  1439. }
  1440. }
  1441. // playpause
  1442. if(this.$playpause){
  1443. if(this.playlist.length > 0){
  1444. this.$playpause.addClass('is-active');
  1445. }else{
  1446. this.$playpause.removeClass('is-active');
  1447. }
  1448. }
  1449. // next
  1450. if(this.$next){
  1451. if(this.playing && this.playlist.length > 1 && this.current_index < this.playlist.length -1){
  1452. this.$next.addClass('is-active');
  1453. }else{
  1454. this.$next.removeClass('is-active');
  1455. }
  1456. }
  1457. // previous
  1458. if(this.$previous){
  1459. if(this.playing && this.playlist.length > 1 && this.current_index > 0){
  1460. this.$previous.addClass('is-active');
  1461. }else{
  1462. this.$previous.removeClass('is-active');
  1463. }
  1464. }
  1465. return this;
  1466. },
  1467. deactivate(){
  1468. this.stop();
  1469. this.active = false;
  1470. },
  1471. // _audioPlayer events
  1472. onAudioOpenDocument(args){
  1473. if(args.caller !== this){
  1474. // console.log('CompoPlayer onAudioOpenDocument() called by other');
  1475. this.reset();
  1476. }
  1477. // else{
  1478. // // console.log('CompoPlayer onAudioOpenDocument() self calling');
  1479. // }
  1480. },
  1481. onAudioPlayerPlay(){
  1482. if(this.playing && this.paused){
  1483. this.paused = false;
  1484. this.showHideControls();
  1485. }
  1486. },
  1487. onAudioPlayerPause(){
  1488. if(this.playing && !this.paused){
  1489. this.paused = true;
  1490. this.showHideControls();
  1491. }
  1492. },
  1493. onAudioPlayerEnded(){
  1494. if(this.playing){
  1495. this.next();
  1496. }
  1497. },
  1498. // onAudioPlayNext(){
  1499. // this.next();
  1500. // }
  1501. };
  1502. // ___ _ _
  1503. // / __|_ _(_)__| |
  1504. // | (_ | '_| / _` |
  1505. // \___|_| |_\__,_|
  1506. function initGrid(){
  1507. console.log('theme : initGrid');
  1508. checkGridBlockHeight();
  1509. _$row.find('.col').addClass('offfield');
  1510. if(false){
  1511. var $grid = $('.grid',_$row).masonry({
  1512. itemSelector:'.col',
  1513. columnWidth:'.col-2',
  1514. containerStyle: null,
  1515. resizeContainer:false,
  1516. // horizontalOrder: true,
  1517. transitionDuration:0,//'0.2s',
  1518. // stagger:30,
  1519. // disable initial layout
  1520. // initLayout: false,
  1521. });
  1522. // layout Masonry after each image loads
  1523. $grid.imagesLoaded().progress( function() {
  1524. $grid.masonry('layout');
  1525. });
  1526. $grid.imagesLoaded(function(){
  1527. $grid.masonry('layout');
  1528. // checkProductionBlockVisible();
  1529. });
  1530. // bind event
  1531. // $grid.masonry( 'on', 'layoutComplete', function() {
  1532. // console.log('layout is complete');
  1533. // });
  1534. $grid.on('layoutComplete', checkGridBlockVisible);
  1535. }else{
  1536. // setTimeout(checkGridBlockVisible, 100);
  1537. checkGridBlockVisible();
  1538. }
  1539. };
  1540. function checkGridBlockHeight(){
  1541. // console.log('checkGridBlockHeight');
  1542. var $r_h = _$row.height();
  1543. var $this;
  1544. // console.log($r_h);
  1545. $('.grid .col', _$row).each(function(i,e){
  1546. $this = $(this);
  1547. if(!$this.is('[init-height]')){
  1548. $this.attr('init-height', $this.outerHeight())
  1549. }
  1550. // console.log($(this).height(), $(this).innerHeight(), $(this).outerHeight());
  1551. // if($this.height() > $r_h){
  1552. // $this.height($r_h);
  1553. // }else{
  1554. // $this.height('auto');
  1555. // }
  1556. $this.height(Math.min($this.attr('init-height'), _$row.height()));
  1557. });
  1558. };
  1559. function checkGridBlockVisible(){
  1560. // console.log('checkGridBlockVisible');
  1561. var $r_h = _$row.height();
  1562. var $this,pos;
  1563. $('.grid .col', _$row).each(function(i,e){
  1564. // $(this).on('load',function(event){
  1565. $this = $(this);
  1566. pos = $this.position();
  1567. // console.log(pos.top, $this.height(), pos.top+$this.height(), $r_h, $this);
  1568. if(pos.top+$this.height() <= $r_h){
  1569. $this.removeClass('offfield');
  1570. }else{
  1571. $this.addClass('offfield');
  1572. }
  1573. // });
  1574. });
  1575. // for (var i in items) {
  1576. // if(!items[i].isTransitioning){
  1577. // console.log('y+outerHeight', items[i].position.y+items[i].size.outerHeight);
  1578. // console.log('_$row.height()', _$row.height());
  1579. // if(items[i].position.y+items[i].size.outerHeight < _$row.height()){
  1580. // $(items[i].element).removeClass('offfield');
  1581. // }else{
  1582. // // $(items[i].element).addClass('offfield');
  1583. // }
  1584. // }
  1585. // }
  1586. }
  1587. // ___ _ _ _
  1588. // | _ \_ _ ___ __| |_ _ __| |_(_)___ _ _ ___
  1589. // | _/ '_/ _ \/ _` | || / _| _| / _ \ ' \(_-<
  1590. // |_| |_| \___/\__,_|\_,_\__|\__|_\___/_||_/__/
  1591. // function initProductions(){
  1592. // console.log('theme : initProductions');
  1593. //
  1594. // // _$row.find('.col').addClass('offfield');
  1595. // var $grid = $('.grid',_$row).masonry({
  1596. // itemSelector:'.col',
  1597. // columnWidth:'.col-2',
  1598. // containerStyle: null,
  1599. // resizeContainer:false,
  1600. // // horizontalOrder: true,
  1601. // transitionDuration:0,//'0.2s',
  1602. // // stagger:30,
  1603. // // disable initial layout
  1604. // // initLayout: false,
  1605. // });
  1606. //
  1607. // // layout Masonry after each image loads
  1608. // $grid.imagesLoaded().progress( function() {
  1609. // $grid.masonry('layout');
  1610. // });
  1611. //
  1612. // $grid.imagesLoaded(function(){
  1613. // $grid.masonry('layout');
  1614. // // checkProductionBlockVisible();
  1615. // });
  1616. //
  1617. // // bind event
  1618. // // $grid.masonry( 'on', 'layoutComplete', function() {
  1619. // // console.log('layout is complete');
  1620. // // });
  1621. // // $grid.on('layoutComplete', checkProductionBlockVisible);
  1622. // };
  1623. // ___ _
  1624. // / __| ___ __ _ _ _ __| |_
  1625. // \__ \/ -_) _` | '_/ _| ' \
  1626. // |___/\___\__,_|_| \__|_||_|
  1627. function initSearch(){
  1628. // if($('#edit-entries input:checked', '#edlp-search-form').length){
  1629. // $('#edit-entries--wrapper', '#edlp-search-form').toggleClass('opened');
  1630. // }
  1631. $('#edit-entries--wrapper legend', '#edlp-search-form').on('click', function(){
  1632. $(this).parent().toggleClass('opened');
  1633. });
  1634. };
  1635. // ___ _ _ _
  1636. // | __|_ _ _ _ ___ __ _(_)__| |_ _ _ ___ _ __ ___ _ _| |_
  1637. // | _|| ' \| '_/ -_) _` | (_-< _| '_/ -_) ' \/ -_) ' \ _|
  1638. // |___|_||_|_| \___\__, |_/__/\__|_| \___|_|_|_\___|_||_\__|
  1639. // |___/
  1640. function initEnregistrementTranscript(){
  1641. console.log('initEnregistrementTranscript');
  1642. var $node = _$row.find('article.node--type-enregistrement.node--view-mode-transcript');
  1643. var $nav = $('<nav>').prependTo($node);
  1644. $node.find('.field--name-field-transcript-vo').addClass('visible').find('.field__label')
  1645. .clone().appendTo($nav).addClass('is-active')
  1646. .attr('field_target', '.field--name-field-transcript-vo');
  1647. $node.find('.field--name-field-transcript-trad').find('.field__label')
  1648. .clone().appendTo($nav)
  1649. .attr('field_target', '.field--name-field-transcript-trad');
  1650. $nav.find('.field__label').on('click', function(){
  1651. var $this = $(this).addClass('is-active');
  1652. $this.siblings('.is-active').removeClass('is-active');
  1653. $this.parents('article.node').find('.field.visible').removeClass('visible');
  1654. $this.parents('article.node').find($this.attr('field_target')).addClass('visible');
  1655. });
  1656. };
  1657. // ___ _ ___
  1658. // | __| _ ___ _ _| |_| _ \__ _ __ _ ___
  1659. // | _| '_/ _ \ ' \ _| _/ _` / _` / -_)
  1660. // |_||_| \___/_||_\__|_| \__,_\__, \___|
  1661. // |___/
  1662. function backToFrontPage(pop_state){
  1663. console.log('backToFrontPage', pop_state);
  1664. closeAllModals();
  1665. // assume we are going back to front page
  1666. $('body').removeClass().addClass('path-frontpage');
  1667. $('a[data-drupal-link-system-path="<front>"]').addClass('is-active');
  1668. // close entrees
  1669. _$corpus_canvas.trigger({'type':'close-all-entree'});
  1670. _$corpus_canvas.trigger({'type':'scramble-collection'});
  1671. if(typeof pop_state == "undefined" || !pop_state){
  1672. console.log('backToFrontPage push state');
  1673. history.pushState({home:true}, null, drupalSettings.path.baseUrl+drupalSettings.path.currentLanguage);
  1674. }
  1675. }
  1676. function initHome(){
  1677. addCloseModalBtnToCols();
  1678. return;
  1679. console.log('theme : initHome');
  1680. var $grid = $('.grid',_$row).masonry({
  1681. itemSelector:'.col',
  1682. columnWidth:'.col-2',
  1683. horizontalOrder: true,
  1684. containerStyle: null,
  1685. // disable initial layout
  1686. // initLayout: false,
  1687. });
  1688. // bind event
  1689. // $grid.masonry( 'on', 'layoutComplete', function() {
  1690. // console.log('layout is complete');
  1691. // });
  1692. // layout Masonry after each image loads
  1693. $grid.imagesLoaded().progress( function() {
  1694. $grid.masonry('layout');
  1695. });
  1696. $grid.imagesLoaded(function(){
  1697. $grid.masonry('layout');
  1698. });
  1699. }
  1700. // __ __ _ _
  1701. // | \/ |___ __| |__ _| |___
  1702. // | |\/| / _ \/ _` / _` | (_-<
  1703. // |_| |_\___/\__,_\__,_|_/__/
  1704. function closeAllModals(){
  1705. //console.log('theme : closeAllModals');
  1706. // TODO: animate the remove
  1707. _$row.html('');
  1708. _$ajaxLinks.removeClass('is-active');
  1709. _$body.trigger({'type':'all-modal-closed'});
  1710. // checkRowEmpty();
  1711. };
  1712. function checkRowEmpty(){
  1713. // if row is empty and we are not in productions or entree notice|index call closeAllModals()
  1714. if(!$('.col', _$row).length){
  1715. if(!_$body.is('.entity-type-taxonomy_term.bundle-entrees')){
  1716. if(!_$body.is('.entity-type-node.bundle-page')){
  1717. // we weren't on production or entree, so go back to front page
  1718. if(!$('a.articles-link').is('.is-active')){
  1719. // don't go back to front page if articles filter is on
  1720. backToFrontPage();
  1721. }
  1722. }else{
  1723. // if we were on production page just scramble collection in case of map was filtered
  1724. _$corpus_canvas.trigger({'type':'scramble-collection'});
  1725. // reload production home
  1726. $('a[data-drupal-link-system-path="productions"]', '#block-mainnavigation')
  1727. .removeClass('is-active').trigger('click');
  1728. }
  1729. }else{
  1730. // remove is-active class from index or notice entree links
  1731. $('.entree-content a.is-active').removeClass('is-active');
  1732. // TODO: remove the hash index or notice
  1733. }
  1734. }
  1735. };
  1736. init();
  1737. } // end EdlpTheme()
  1738. $(document).ready(function($) {
  1739. if(drupalSettings.path.isFront){
  1740. var edlptheme = new EdlpTheme();
  1741. }else{
  1742. $('body').attr('booted', 'booted');
  1743. }
  1744. });
  1745. })(jQuery, Drupal, drupalSettings);