main.js 64 KB

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