From d4852862898edaab462f56bcd2cf3ca6be4851ea Mon Sep 17 00:00:00 2001 From: Bachir Soussi Chiadmi Date: Thu, 12 Apr 2018 23:54:45 +0200 Subject: [PATCH] fixed cloing entree history nav --- .../assets/dist/scripts/corpus.min.js | 21 +++++++------------ .../edlp_corpus/assets/scripts/corpus.js | 21 +++++++------------ .../edlptheme/assets/dist/scripts/main.min.js | 10 ++++++--- .../custom/edlptheme/assets/scripts/main.js | 10 ++++++--- .../block--system-branding-block.html.twig | 4 ++-- 5 files changed, 30 insertions(+), 36 deletions(-) diff --git a/sites/all/modules/figli/edlp_corpus/assets/dist/scripts/corpus.min.js b/sites/all/modules/figli/edlp_corpus/assets/dist/scripts/corpus.min.js index f8f60bf09..0534046ee 100644 --- a/sites/all/modules/figli/edlp_corpus/assets/dist/scripts/corpus.min.js +++ b/sites/all/modules/figli/edlp_corpus/assets/dist/scripts/corpus.min.js @@ -616,9 +616,7 @@ // | __|_ _| |_ _ _ ___ ___ ___ // | _|| ' \ _| '_/ -_) -_|_-< // |___|_||_\__|_| \___\___/__/ - // TODO : this functionn is not clear as it should be called toggleEntry - function openEntree(tid, bubbling){ - //var $link = $('a.term-link[tid="'+tid+'"]'); + function toggleEntree(tid, bubbling){ var $link = _$entrees_block_termlinks.filter('[tid="'+tid+'"]'); var $li = $link.parents('li'); var sys_path = $link.attr('data-drupal-link-system-path'); @@ -630,6 +628,7 @@ if(bubbling){ _$body.trigger({'type':'open_entree', 'tid':tid, 'url':url, 'sys_path':sys_path}); } + // bubbling is true only when event is a real click on entree link }else if(bubbling){ $li.removeClass('opened'); scrambleCollection(); @@ -696,20 +695,14 @@ // |___/\__|_| \__,_|_|_|_|_.__/_|_|_||_\__, | // |___/ function scrambleCollection(){ - console.log('scrambleCollection'); + // console.log('scrambleCollection'); for (var i = 0; i < _nodes.length; i++) { _nodes[i].scramble(); } // setTimeout(stopScrambling, 2000); // stopScrambling(); }; - // function stopScrambling(){ - // for (var i = 0; i < _nodes.length; i++) { - // setTimeout(function(n){ - // n.stopScrambling(); - // }.bind(this, _nodes[i]), 1000 + Math.random()*4000); - // } - // }; + function closeAllEntries(){ _$entrees_block_termlinks.each(function(index, el) { if($(this).parents('li').is('.opened')){ @@ -821,7 +814,7 @@ closeNode(); }) .on('open-entree', function(e){ - openEntree(e.tid); + toggleEntree(e.tid); }) .on('close-all-entree', function(e){ closeAllEntries(); @@ -830,7 +823,7 @@ _$entrees_block_termlinks.on('click', function(event) { // console.log('_$entrees_block_termlinks click', this); event.preventDefault(); - openEntree($(this).attr('tid'), true); + toggleEntree($(this).attr('tid'), true); // var $link = $(this); // var tid = $link.attr('tid'); // var $li = $link.parents('li'); @@ -839,7 +832,7 @@ // if(!$li.is('.opened')){ // _$entrees_block_termlinks.parents('li').removeClass('opened'); // $li.addClass('opened'); - // openEntree(tid); + // toggleEntree(tid); // _$body.trigger({'type':'open_entree', 'tid':tid, 'url':url, 'sys_path':sys_path}); // }else{ // $li.removeClass('opened'); diff --git a/sites/all/modules/figli/edlp_corpus/assets/scripts/corpus.js b/sites/all/modules/figli/edlp_corpus/assets/scripts/corpus.js index f8f60bf09..0534046ee 100644 --- a/sites/all/modules/figli/edlp_corpus/assets/scripts/corpus.js +++ b/sites/all/modules/figli/edlp_corpus/assets/scripts/corpus.js @@ -616,9 +616,7 @@ // | __|_ _| |_ _ _ ___ ___ ___ // | _|| ' \ _| '_/ -_) -_|_-< // |___|_||_\__|_| \___\___/__/ - // TODO : this functionn is not clear as it should be called toggleEntry - function openEntree(tid, bubbling){ - //var $link = $('a.term-link[tid="'+tid+'"]'); + function toggleEntree(tid, bubbling){ var $link = _$entrees_block_termlinks.filter('[tid="'+tid+'"]'); var $li = $link.parents('li'); var sys_path = $link.attr('data-drupal-link-system-path'); @@ -630,6 +628,7 @@ if(bubbling){ _$body.trigger({'type':'open_entree', 'tid':tid, 'url':url, 'sys_path':sys_path}); } + // bubbling is true only when event is a real click on entree link }else if(bubbling){ $li.removeClass('opened'); scrambleCollection(); @@ -696,20 +695,14 @@ // |___/\__|_| \__,_|_|_|_|_.__/_|_|_||_\__, | // |___/ function scrambleCollection(){ - console.log('scrambleCollection'); + // console.log('scrambleCollection'); for (var i = 0; i < _nodes.length; i++) { _nodes[i].scramble(); } // setTimeout(stopScrambling, 2000); // stopScrambling(); }; - // function stopScrambling(){ - // for (var i = 0; i < _nodes.length; i++) { - // setTimeout(function(n){ - // n.stopScrambling(); - // }.bind(this, _nodes[i]), 1000 + Math.random()*4000); - // } - // }; + function closeAllEntries(){ _$entrees_block_termlinks.each(function(index, el) { if($(this).parents('li').is('.opened')){ @@ -821,7 +814,7 @@ closeNode(); }) .on('open-entree', function(e){ - openEntree(e.tid); + toggleEntree(e.tid); }) .on('close-all-entree', function(e){ closeAllEntries(); @@ -830,7 +823,7 @@ _$entrees_block_termlinks.on('click', function(event) { // console.log('_$entrees_block_termlinks click', this); event.preventDefault(); - openEntree($(this).attr('tid'), true); + toggleEntree($(this).attr('tid'), true); // var $link = $(this); // var tid = $link.attr('tid'); // var $li = $link.parents('li'); @@ -839,7 +832,7 @@ // if(!$li.is('.opened')){ // _$entrees_block_termlinks.parents('li').removeClass('opened'); // $li.addClass('opened'); - // openEntree(tid); + // toggleEntree(tid); // _$body.trigger({'type':'open_entree', 'tid':tid, 'url':url, 'sys_path':sys_path}); // }else{ // $li.removeClass('opened'); diff --git a/sites/all/themes/custom/edlptheme/assets/dist/scripts/main.min.js b/sites/all/themes/custom/edlptheme/assets/dist/scripts/main.min.js index 6427c8d2a..00e6c5095 100644 --- a/sites/all/themes/custom/edlptheme/assets/dist/scripts/main.min.js +++ b/sites/all/themes/custom/edlptheme/assets/dist/scripts/main.min.js @@ -348,7 +348,7 @@ function onHistoryPopState(e){ console.log('onPopState',e.state); if(e.state.home){ - backToFrontPage(); + backToFrontPage(true); }else{ if(e.state.entree_tid){ openEntree(e.state.entree_tid); @@ -369,7 +369,8 @@ function initAjaxLinks(){ // console.log('initAjaxLinks'); - $('a', '#block-mainnavigation') + $('a.site-name', '#block-edlptheme-branding') + .add('a', '#block-mainnavigation') .add('a', '#block-footer.menu--footer') .add('a', '#block-productions') .add('a', 'article.node:not(.node--type-enregistrement) h2.node-title') @@ -1070,13 +1071,16 @@ // | _| '_/ _ \ ' \ _| _/ _` / _` / -_) // |_||_| \___/_||_\__|_| \__,_\__, \___| // |___/ - function backToFrontPage(){ + function backToFrontPage(pop_state){ closeAllModals(); // assume we are going back to front page $('body').removeClass().addClass('path-frontpage'); $('a[data-drupal-link-system-path=""]').addClass('is-active'); // close entrees _$corpus_canvas.trigger({'type':'close-all-entree'}); + if(!pop_state){ + history.pushState({home:true}, null, window.location.origin); + } } function initHome(){ diff --git a/sites/all/themes/custom/edlptheme/assets/scripts/main.js b/sites/all/themes/custom/edlptheme/assets/scripts/main.js index 6427c8d2a..00e6c5095 100644 --- a/sites/all/themes/custom/edlptheme/assets/scripts/main.js +++ b/sites/all/themes/custom/edlptheme/assets/scripts/main.js @@ -348,7 +348,7 @@ function onHistoryPopState(e){ console.log('onPopState',e.state); if(e.state.home){ - backToFrontPage(); + backToFrontPage(true); }else{ if(e.state.entree_tid){ openEntree(e.state.entree_tid); @@ -369,7 +369,8 @@ function initAjaxLinks(){ // console.log('initAjaxLinks'); - $('a', '#block-mainnavigation') + $('a.site-name', '#block-edlptheme-branding') + .add('a', '#block-mainnavigation') .add('a', '#block-footer.menu--footer') .add('a', '#block-productions') .add('a', 'article.node:not(.node--type-enregistrement) h2.node-title') @@ -1070,13 +1071,16 @@ // | _| '_/ _ \ ' \ _| _/ _` / _` / -_) // |_||_| \___/_||_\__|_| \__,_\__, \___| // |___/ - function backToFrontPage(){ + function backToFrontPage(pop_state){ closeAllModals(); // assume we are going back to front page $('body').removeClass().addClass('path-frontpage'); $('a[data-drupal-link-system-path=""]').addClass('is-active'); // close entrees _$corpus_canvas.trigger({'type':'close-all-entree'}); + if(!pop_state){ + history.pushState({home:true}, null, window.location.origin); + } } function initHome(){ diff --git a/sites/all/themes/custom/edlptheme/templates/block/block--system-branding-block.html.twig b/sites/all/themes/custom/edlptheme/templates/block/block--system-branding-block.html.twig index 4cf23dee8..ab8560234 100644 --- a/sites/all/themes/custom/edlptheme/templates/block/block--system-branding-block.html.twig +++ b/sites/all/themes/custom/edlptheme/templates/block/block--system-branding-block.html.twig @@ -17,12 +17,12 @@ {% if site_logo or site_name %}

{% if site_logo %} - {% endif %} {% if site_name %} - {{ site_name }} + {{ site_name }} {% endif %}

{% endif %}