Browse Source

auto load article on audio open if map's articl filter is on

Bachir Soussi Chiadmi 7 years ago
parent
commit
29ad08648f

+ 21 - 16
sites/all/modules/figli/edlp_corpus/assets/dist/scripts/corpus.min.js

@@ -35,6 +35,7 @@
     var _nodes = [];
     var _articles_nodes = [];
     var _no_articles_nodes = [];
+    var _articles_filter_on = false;
     var _nodes_by_entries = {};
     var _nodes_by_nid = {};
     var _nodes_Nid_Id = {};
@@ -56,16 +57,16 @@
     var _settings = drupalSettings.edlp_corpus;
     var _ecolors = _settings.colors;
     // Physics
-    var _attracter,
-        _repulser_top,
-        _repulser_center,
-        _repulser_bottom,
-        _scrambler_TL,
-        _scrambler_TR,
-        _scrambler_BR,
-        _scrambler_BL,
-        _scrambler_CL,
-        _scrambler_CR;
+    var _attracter;
+        // _repulser_top,
+        // _repulser_center,
+        // _repulser_bottom,
+        // _scrambler_TL,
+        // _scrambler_TR,
+        // _scrambler_BR,
+        // _scrambler_BL,
+        // _scrambler_CL,
+        // _scrambler_CR;
 
     //     ____      _ __
     //    /  _/___  (_) /______
@@ -772,24 +773,26 @@
       e.preventDefault();
       $(this).toggleClass('is-active');
       if($(this).is('.is-active')){
-        filterArticles();
+        activateArticlesFilter();
         closeAllEntries();
       }else{
-        resetArticlesFilter();
+        deactivateArticlesFilter();
       }
       // _$canvas.trigger({
       //   'type':'corpus-cliqued-on-articles'
       // });
       return false;
     };
-    function filterArticles(){
-      //console.log('filterArticles');
+    function activateArticlesFilter(){
+      //console.log('activateArticlesFilter');
+      _articles_filter_on = true;
       for (var i = 0; i < _no_articles_nodes.length; i++) {
         _no_articles_nodes[i].fade();
       }
     };
-    function resetArticlesFilter(){
-      //console.log('resetArticlesFilter');
+    function deactivateArticlesFilter(){
+      //console.log('deactivateArticlesFilter');
+      _articles_filter_on = false;
       for (var i = 0; i < _no_articles_nodes.length; i++) {
         _no_articles_nodes[i].unFade();
       }
@@ -830,6 +833,7 @@
               var event = {
                 'type':'corpus-cliked-on-node',
                 'target_node':_nodes[_node_hover_id],
+                'article':_articles_filter_on
               };
               _$canvas.trigger(event);
               // instead of directly opening the doc, create an event listener (e.g. : audio played from random)
@@ -837,6 +841,7 @@
             }else{
               // console.log('corpus : click on map');
               _$canvas.trigger('corpus-cliked-on-map');
+              shutDownArticles();
             }
           }
         })

+ 21 - 16
sites/all/modules/figli/edlp_corpus/assets/scripts/corpus.js

@@ -35,6 +35,7 @@
     var _nodes = [];
     var _articles_nodes = [];
     var _no_articles_nodes = [];
+    var _articles_filter_on = false;
     var _nodes_by_entries = {};
     var _nodes_by_nid = {};
     var _nodes_Nid_Id = {};
@@ -56,16 +57,16 @@
     var _settings = drupalSettings.edlp_corpus;
     var _ecolors = _settings.colors;
     // Physics
-    var _attracter,
-        _repulser_top,
-        _repulser_center,
-        _repulser_bottom,
-        _scrambler_TL,
-        _scrambler_TR,
-        _scrambler_BR,
-        _scrambler_BL,
-        _scrambler_CL,
-        _scrambler_CR;
+    var _attracter;
+        // _repulser_top,
+        // _repulser_center,
+        // _repulser_bottom,
+        // _scrambler_TL,
+        // _scrambler_TR,
+        // _scrambler_BR,
+        // _scrambler_BL,
+        // _scrambler_CL,
+        // _scrambler_CR;
 
     //     ____      _ __
     //    /  _/___  (_) /______
@@ -772,24 +773,26 @@
       e.preventDefault();
       $(this).toggleClass('is-active');
       if($(this).is('.is-active')){
-        filterArticles();
+        activateArticlesFilter();
         closeAllEntries();
       }else{
-        resetArticlesFilter();
+        deactivateArticlesFilter();
       }
       // _$canvas.trigger({
       //   'type':'corpus-cliqued-on-articles'
       // });
       return false;
     };
-    function filterArticles(){
-      //console.log('filterArticles');
+    function activateArticlesFilter(){
+      //console.log('activateArticlesFilter');
+      _articles_filter_on = true;
       for (var i = 0; i < _no_articles_nodes.length; i++) {
         _no_articles_nodes[i].fade();
       }
     };
-    function resetArticlesFilter(){
-      //console.log('resetArticlesFilter');
+    function deactivateArticlesFilter(){
+      //console.log('deactivateArticlesFilter');
+      _articles_filter_on = false;
       for (var i = 0; i < _no_articles_nodes.length; i++) {
         _no_articles_nodes[i].unFade();
       }
@@ -830,6 +833,7 @@
               var event = {
                 'type':'corpus-cliked-on-node',
                 'target_node':_nodes[_node_hover_id],
+                'article':_articles_filter_on
               };
               _$canvas.trigger(event);
               // instead of directly opening the doc, create an event listener (e.g. : audio played from random)
@@ -837,6 +841,7 @@
             }else{
               // console.log('corpus : click on map');
               _$canvas.trigger('corpus-cliked-on-map');
+              shutDownArticles();
             }
           }
         })

+ 19 - 9
sites/all/themes/custom/edlptheme/assets/dist/scripts/main.min.js

@@ -127,6 +127,7 @@
         // check for viewmode attribute
         if(view_mode){
           state.ajax_path += '/'+view_mode;
+          state.view_mode = view_mode;
         }
       }else if(term_match){
         // terms are always entrees, there's no other vocabulary links in front
@@ -148,7 +149,7 @@
       return state;
     };
     function ajaxLoadContent(state){
-      console.log('ajaxLoadContent : url', state.url);
+      console.log('ajaxLoadContent : state', state);
       _$body.addClass('ajax-loading');
 
       var path = window.location.origin + Drupal.url(state.ajax_path);
@@ -166,7 +167,7 @@
       _$body.removeClass('ajax-loading');
     };
     function onAjaxLoaded(data, state){
-      console.log('ajax loaded url:'+state.url+' ajax_path:'+state.ajax_path+' sys_path:'+state.sys_path);
+      console.log('ajax loaded : state', state);
       // console.log(data);
       // reset all style may been added by other pages (like masonry for productions)
       // and replace all content with newly loaded
@@ -200,7 +201,7 @@
 
       // handle clicked link classes
       $('.ajax-loading').removeClass('ajax-loading');
-      $('.is-active').removeClass('is-active');
+      $('.ajax-link.is-active').removeClass('is-active');
       $('.is-active-trail').removeClass('is-active-trail');
 
       if(typeof state.selector != 'undefined'){
@@ -302,11 +303,9 @@
     };
 
     function initAudioLinksInContent(){
-      // console.log('initAudioLinksInContent');
       _$row.find('a.audio-link')
         .on('mouseover', function(event) {
           event.preventDefault();
-          // console.log('onmouseover audio-link');
           if(_corpus_ready){
             _$corpus_canvas.trigger({
               type:'mouseover-audio-link',
@@ -316,7 +315,6 @@
         })
         .on('mouseout', function(event) {
           event.preventDefault();
-          // console.log('onmouseout audio-link');
           if(_corpus_ready){
             _$corpus_canvas.trigger({
               type:'mouseout-audio-link',
@@ -570,6 +568,7 @@
       }
 
       var view_mode = $link.attr('viewmode');
+
       var state = getSysPathState(sys_path, view_mode);
       state.url = $(this).attr('href');
 
@@ -588,7 +587,6 @@
       return false;
     };
 
-
     //   ___
     //  / __|___ _ _ _ __ _  _ ___
     // | (__/ _ \ '_| '_ \ || (_-<
@@ -607,6 +605,7 @@
           //console.log('theme : corpus-cliked-on-node', e);
           _audioPlayer
             .emmit('stop-shuffle')
+            .setAutoOpenArticle(e.article)
             .openDocument(e.target_node);
         });
 
@@ -678,6 +677,9 @@
       this.historic = [];
       this.shuffle_is_active = false;
 
+      // artciles
+      this.auto_open_article = false;
+
       // object events
       this.event_handlers = {
         'audio-open-document':[],
@@ -821,7 +823,8 @@
         // debugger;
         this.audio.pause();
         // don't close player if article or transcript is open
-        if(!_$body.is('.path-node-'+this.historic[this.currentHistoricIndex].nid)){
+        if(!(_$body.is('.path-node-'+this.historic[this.currentHistoricIndex].nid)
+          && (_$body.is('.view-mode-article') || _$body.is('.view-mode-transcript')))){
           this.timeOutToHide();
         }
       },
@@ -865,11 +868,19 @@
         this.$cartel.html(data.rendered).removeClass('loading');
         _$body.trigger({'type':'new-audio-cartel-loaded'});
         initAjaxLinks();
+        if(this.auto_open_article){
+          this.$cartel.find('a.link-article').trigger('click');
+          this.auto_open_article = false;
+        }
       },
       onNodeLoadFail(jqxhr, textStatus, error){
         console.warn('AudioPlayer node load failed', jqxhr.responseText);
         this.$cartel.removeClass('loading').html('');
       },
+      setAutoOpenArticle(art){
+        this.auto_open_article = art;
+        return this;
+      },
       // global
       show(){
         this.$container.addClass('visible');
@@ -1317,7 +1328,6 @@
       });
     };
 
-
     //  ___                   _    _                         _
     // | __|_ _  _ _ ___ __ _(_)__| |_ _ _ ___ _ __  ___ _ _| |_
     // | _|| ' \| '_/ -_) _` | (_-<  _| '_/ -_) '  \/ -_) ' \  _|

+ 19 - 9
sites/all/themes/custom/edlptheme/assets/scripts/main.js

@@ -127,6 +127,7 @@
         // check for viewmode attribute
         if(view_mode){
           state.ajax_path += '/'+view_mode;
+          state.view_mode = view_mode;
         }
       }else if(term_match){
         // terms are always entrees, there's no other vocabulary links in front
@@ -148,7 +149,7 @@
       return state;
     };
     function ajaxLoadContent(state){
-      console.log('ajaxLoadContent : url', state.url);
+      console.log('ajaxLoadContent : state', state);
       _$body.addClass('ajax-loading');
 
       var path = window.location.origin + Drupal.url(state.ajax_path);
@@ -166,7 +167,7 @@
       _$body.removeClass('ajax-loading');
     };
     function onAjaxLoaded(data, state){
-      console.log('ajax loaded url:'+state.url+' ajax_path:'+state.ajax_path+' sys_path:'+state.sys_path);
+      console.log('ajax loaded : state', state);
       // console.log(data);
       // reset all style may been added by other pages (like masonry for productions)
       // and replace all content with newly loaded
@@ -200,7 +201,7 @@
 
       // handle clicked link classes
       $('.ajax-loading').removeClass('ajax-loading');
-      $('.is-active').removeClass('is-active');
+      $('.ajax-link.is-active').removeClass('is-active');
       $('.is-active-trail').removeClass('is-active-trail');
 
       if(typeof state.selector != 'undefined'){
@@ -302,11 +303,9 @@
     };
 
     function initAudioLinksInContent(){
-      // console.log('initAudioLinksInContent');
       _$row.find('a.audio-link')
         .on('mouseover', function(event) {
           event.preventDefault();
-          // console.log('onmouseover audio-link');
           if(_corpus_ready){
             _$corpus_canvas.trigger({
               type:'mouseover-audio-link',
@@ -316,7 +315,6 @@
         })
         .on('mouseout', function(event) {
           event.preventDefault();
-          // console.log('onmouseout audio-link');
           if(_corpus_ready){
             _$corpus_canvas.trigger({
               type:'mouseout-audio-link',
@@ -570,6 +568,7 @@
       }
 
       var view_mode = $link.attr('viewmode');
+
       var state = getSysPathState(sys_path, view_mode);
       state.url = $(this).attr('href');
 
@@ -588,7 +587,6 @@
       return false;
     };
 
-
     //   ___
     //  / __|___ _ _ _ __ _  _ ___
     // | (__/ _ \ '_| '_ \ || (_-<
@@ -607,6 +605,7 @@
           //console.log('theme : corpus-cliked-on-node', e);
           _audioPlayer
             .emmit('stop-shuffle')
+            .setAutoOpenArticle(e.article)
             .openDocument(e.target_node);
         });
 
@@ -678,6 +677,9 @@
       this.historic = [];
       this.shuffle_is_active = false;
 
+      // artciles
+      this.auto_open_article = false;
+
       // object events
       this.event_handlers = {
         'audio-open-document':[],
@@ -821,7 +823,8 @@
         // debugger;
         this.audio.pause();
         // don't close player if article or transcript is open
-        if(!_$body.is('.path-node-'+this.historic[this.currentHistoricIndex].nid)){
+        if(!(_$body.is('.path-node-'+this.historic[this.currentHistoricIndex].nid)
+          && (_$body.is('.view-mode-article') || _$body.is('.view-mode-transcript')))){
           this.timeOutToHide();
         }
       },
@@ -865,11 +868,19 @@
         this.$cartel.html(data.rendered).removeClass('loading');
         _$body.trigger({'type':'new-audio-cartel-loaded'});
         initAjaxLinks();
+        if(this.auto_open_article){
+          this.$cartel.find('a.link-article').trigger('click');
+          this.auto_open_article = false;
+        }
       },
       onNodeLoadFail(jqxhr, textStatus, error){
         console.warn('AudioPlayer node load failed', jqxhr.responseText);
         this.$cartel.removeClass('loading').html('');
       },
+      setAutoOpenArticle(art){
+        this.auto_open_article = art;
+        return this;
+      },
       // global
       show(){
         this.$container.addClass('visible');
@@ -1317,7 +1328,6 @@
       });
     };
 
-
     //  ___                   _    _                         _
     // | __|_ _  _ _ ___ __ _(_)__| |_ _ _ ___ _ __  ___ _ _| |_
     // | _|| ' \| '_/ -_) _` | (_-<  _| '_/ -_) '  \/ -_) ' \  _|