main.js 64 KB

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