main.js 69 KB

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