Browse Source

fixe sound direct link with mobile from desktop, fix #584

Bachir Soussi Chiadmi 4 years ago
parent
commit
67271fc277

+ 3 - 2
web/modules/custom/edlp_ajax/edlp_ajax.module

@@ -13,13 +13,13 @@ use Drupal\Core\Url;
  * @param array $attachments
  */
 function edlp_ajax_page_attachments(array &$attachments) {
+  // provied info about available urls needed for ajax purpose
   $url = Url::fromRoute('edlp_ajax.entityjson');
   $attachments['#attached']['drupalSettings']['edlp_ajax']['entityjson_path'] = $url->getInternalPath();
   $url = Url::fromRoute('edlp_ajax.blocksjson');
   $attachments['#attached']['drupalSettings']['edlp_ajax']['blocksjson_path'] = $url->getInternalPath();
 
-  $redirect = false;
-
+  // provied infos about current entity (node or taxonomy term) and audio files
   $current_path = \Drupal::service('path.current')->getPath();
   $current_language = \Drupal::languageManager()->getCurrentLanguage()->getId();
   $is_front = \Drupal::service('path.matcher')->isFrontPage();
@@ -49,6 +49,7 @@ function edlp_ajax_page_attachments(array &$attachments) {
 
   // do not redirect if not node, term, or custom routing
   // FIXME: check with routes instead of path as path can change !!!
+  $redirect = false;
   if(preg_match('/^\/?node\/\d+/', $current_path)
     || preg_match('/^\/?taxonomy\/term\/\d+/', $current_path)
     || preg_match('/^\/?productions/', $current_path)

File diff suppressed because it is too large
+ 0 - 0
web/modules/custom/edlp_corpus/assets/dist/styles/corpus.min.css


+ 5 - 4
web/modules/custom/edlp_mobile/edlp_mobile.module

@@ -52,6 +52,8 @@ function edlp_mobile_help($route_name, RouteMatchInterface $route_match) {
 
 /**
  * Implements hook_page_attachments().
+ * the porpuse of this hooks is to collect registered domains informations to set it available to redirect.js file provided by edlptheme
+ * it does nothing by it's own
  * @param array $attachments
  */
 function edlp_mobile_page_attachments(array &$attachments) {
@@ -60,20 +62,19 @@ function edlp_mobile_page_attachments(array &$attachments) {
   global $base_root;
   // dpm($base_root, '$base_root');
 
+  // get the current hostname (domain)
   $current_hostname = preg_replace('/http:\/\/|https:\/\//i', '', $base_root);
   // dpm($current_hostname, '$current_hostname');
 
+  // get domains from domain module
   $domain_storage = \Drupal::entityTypeManager()->getStorage('domain');
-
   $mobile_domain = $domain_storage->load('m_encyclopediedelaparole_org');
   // dpm($mobile_domain, 'mobile_domain');
-
   $desktop_domain = $domain_storage->load('encyclopediedelaparole_org');
   // dpm($desktop_domain, 'desktop_domain');
-
   $expo_domain = $domain_storage->load('expo_encyclopediedelaparole_org');
   // dpm($expo_domain, 'expo_domain');
-
+  // get the current domain
   $current_domain = $domain_storage->loadByHostname($current_hostname);
   // dpm($current_domain, 'current_domain');
 

File diff suppressed because it is too large
+ 333 - 272
web/modules/custom/package-lock.json


File diff suppressed because it is too large
+ 0 - 0
web/themes/custom/edlptheme/assets/dist/scripts/main.min.js


File diff suppressed because it is too large
+ 0 - 0
web/themes/custom/edlptheme/assets/dist/scripts/redirect.min.js


+ 21 - 5
web/themes/custom/edlptheme/assets/scripts/main.js

@@ -136,6 +136,7 @@
     // | |\/| / _ \ '_ \ | / -_)
     // |_|  |_\___/_.__/_|_\___|
     function initMobile(){
+      console.log('initMobile');
       // $('[data-drupal-link-system-path="<front>"]','#block-mainnavigation')
       //   .removeClass('is-active')
       //   .attr('href', '#collection');
@@ -145,10 +146,10 @@
       // TODO: remove collection from mobile home
       // TODO: replace ajax link to only collection for mobile
 
-
       $('h2, a', '#block-mainnavigation')
         .add('h2, a', '#block-mainnavigation-2')
         .on('click', onclickHomeMobileMenu);
+
     }
     function onclickHomeMobileMenu(e){
       // $('#block-mainnavigation').toggleClass('opened');
@@ -722,6 +723,9 @@
         // create history state
         var state = getSysPathState(edlp_origin.sys_path, hash);
 
+        // add historic_index 0 to state
+        state.historic_index = 0;
+
         // open entree tray in case of entree index|notice
         // (index or notice will be opened with ajaxLoadContent)
         // refactorized with new infos from edlp_origin
@@ -764,13 +768,19 @@
           // close home
           closeAllModals();
           if(hash == "" || hash == 'random'){
+            console.log('first load hash', hash);
             // if hash is random, RandomPlayer will be started when playlist sent by corpus.js
             // if audio only record in state
             state.audio = true;
             state.node = node;
-            // we don't laod ajax content so we boot the home
-            _$body.attr('booted', 'booted');
+            if(!_is_mobile){
+              // if not mobile we don't laod ajax content so we boot the home
+              _$body.attr('booted', 'booted');
+            }else{
+              ajaxLoadContent(state);
+            }
           }else{
+            console.log('first load load content');
             // ajax load content for audio only if article or transcript
             ajaxLoadContent(state);
           }
@@ -809,7 +819,11 @@
         backToFrontPage(true);
       }
       else if (e.state.audio) {
-          _audioPlayer.openDocument(e.state.node, 'popstate', e.state.historic_index);
+        console.log('popstate audio : e.state', e.state);
+        _audioPlayer.openDocument(e.state.node, 'popstate', e.state.historic_index);
+        if(_is_mobile){
+          ajaxLoadContent(e.state)
+        }
       }
       else{
         if(e.state.entree_tid){
@@ -1205,7 +1219,7 @@
         this.$next.on('click', this.playNext.bind(this));
       },
       openDocument(node, caller, historic_index){
-        console.log('AudioPlayer openDocument', node, caller);
+        console.log('AudioPlayer openDocument', node, caller, historic_index);
         if(typeof node == 'undefined'
           || typeof node.nid ==  'undefined'
           || typeof node.audio_url == 'undefined'){
@@ -1275,6 +1289,8 @@
       launch(){
         this.clearTimeOutToHide();
         this.clearIntervalAutoCartelSwitch();
+        console.log('this.historic', this.historic);
+        console.log('this.currentHistoricIndex', this.currentHistoricIndex);
         this.setSRC(this.historic[this.currentHistoricIndex].audio_url);
         if(!_is_mobile){
           this.loadNode(this.historic[this.currentHistoricIndex].nid);

+ 6 - 2
web/themes/custom/edlptheme/assets/scripts/redirect.js

@@ -6,6 +6,9 @@ function checkMobile(){
 }
 
 // var edlp_mobile is provided by edlp_mobile.module file
+// TODO: edlp_mobile should be called edlp_domains
+// if device is mobile but domain not, redirect to mobile domain
+// if device is desktop but domain is mobile, redirect to desktop domain
 if(typeof edlp_mobile != "undefined"){
   // console.log(edlp_mobile);
   // console.log('window.location', window.location);
@@ -19,7 +22,8 @@ if(typeof edlp_mobile != "undefined"){
       // console.log('redirect to mobile domain', window.location.protocol +'//'+ edlp_mobile.mobile_url);
       device_redirect = true;
       // redirect to mobile domain
-      window.location.replace(window.location.protocol +'//'+ edlp_mobile.mobile_url);
+      // TODO: preserve params
+      window.location.replace(window.location.protocol +'//'+ edlp_mobile.mobile_url + location.pathname);
       break;
     case (edlp_mobile.is_mobile_domain && !device_is_mobile):
       // console.log('redirect to desktop domain', window.location.protocol +'//'+ edlp_mobile.desktop_url);
@@ -37,7 +41,7 @@ if(typeof edlp_mobile != "undefined"){
 }
 
 // var edlp is provided by edlp_ajax.module file
-if(edlp.redirect && !device_redirect && !device_is_mobile){
+if(edlp.redirect && !device_redirect){ //  && !device_is_mobile
   console.log('redirect', edlp);
   console.log('window.location', window.location);
 

Some files were not shown because too many files changed in this diff