main.js 69 KB

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