main.js 66 KB

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