main.js 66 KB

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