main.js 65 KB

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