Browse Source

mobile dev alpha, redirecting is working, started mobile display

Bachir Soussi Chiadmi 6 years ago
parent
commit
7601ad0b4c

+ 7 - 0
sites/all/modules/figli/edlp_mobile/edlp_mobile.info.yml

@@ -0,0 +1,7 @@
+name: 'edlp_mobile'
+type: module
+description: 'Handle some mobile behaviours'
+core: 8.x
+package: 'Edlp'
+dependencies:
+  - domain

+ 150 - 0
sites/all/modules/figli/edlp_mobile/edlp_mobile.module

@@ -0,0 +1,150 @@
+<?php
+
+/**
+ * @file
+ * Contains edlp_mobile.module.
+ */
+
+use Drupal\Core\Routing\RouteMatchInterface;
+// use Drupal\domain\DomainStorage;
+// use Drupal\domain\DomainElementManager;
+
+/**
+ * Implements hook_help().
+ */
+function edlp_mobile_help($route_name, RouteMatchInterface $route_match) {
+  switch ($route_name) {
+    // Main module help for the edlp_mobile module.
+    case 'help.page.edlp_mobile':
+      $output = '';
+      $output .= '<h3>' . t('About') . '</h3>';
+      $output .= '<p>' . t('Handle some mobile behaviours') . '</p>';
+      return $output;
+
+    default:
+  }
+}
+
+
+/**
+* hook_entity_extra_field_info()
+*/
+// function edlp_mobile_entity_extra_field_info(){
+//   $extra = [];
+//   $extra['domain']['relations'] = [
+//     'label' => t('Relations'),
+//     'description' => 'Display enregistrement relations with other content types',
+//     'weight' => 99,
+//   ];
+//   return $extra;
+// }
+
+// should be the right way
+// function edlp_mobile_entity_field_storage_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type) {
+//   if ($entity_type->id() == 'domain') {
+//     $definitions['device'] = \Drupal\Core\Field\BaseFieldDefinition::create('string')
+//       ->setName('Device')
+//       ->setLabel(t('Define a target device for this domain (mobile|desktop)'))
+//       ->setTargetEntityTypeId($entity_type->id());
+//     return $definitions;
+//   }
+// }
+
+/**
+ * Implements hook_page_attachments().
+ * @param array $attachments
+ */
+function edlp_mobile_page_attachments(array &$attachments) {
+  $is_mobile_domain = false;
+
+  global $base_root;
+  //dpm($base_root, '$base_root');
+
+  $current_domain = preg_replace('/http:\/\/|https:\/\//i', '', $base_root);
+  //dpm($current_domain, '$current_domain');
+
+  $domain_storage = \Drupal::entityTypeManager()->getStorage('domain');
+  $domains = $domain_storage->loadMultiple();
+  //dpm($domains);
+  $domain_alias_storage = \Drupal::entityTypeManager()->getStorage('domain_alias');
+  //dpm($domain_alias_storage);
+
+  foreach ($domains as $domain_id => $domain) {
+    if($domain->isActive()){
+      //dpm($domain);
+
+      $alias_ids = $domain_alias_storage->getQuery()->condition('domain_id', $domain_id)->execute();
+      //dpm($alias_ids, 'alias_ids');
+
+      $aliases = $domain_alias_storage->loadMultiple($alias_ids);
+      // dpm($aliases, 'aliases');
+
+      foreach ($aliases as $alias_id => $alias) {
+        if($alias->getPattern() == $current_domain){
+          // we found the current domain and current alias
+          dpm($domain, 'domain');
+          dpm($alias, 'alias');
+          $env = $alias->getEnvironment();
+          $env_aliases = $domain_alias_storage->loadByEnvironment($env);
+          dpm($env_aliases, '$env_aliases');
+          // find out mibile alias and desktop alias
+          // this is dirty
+          // TODO: set target device as domain setting
+          if ($domain->id() == 'm_encyclopediedelaparole_org'){
+            // current domain/alias is mobile
+            $is_mobile_domain = true;
+            $mobile_url = $alias->getPattern();
+            // find desktop pattern
+            foreach ($env_aliases as $env_alias_id => $env_alias) {
+              if($env_alias_id != $alias_id){
+                // we found the desktop pattern
+                $desktop_url = $env_alias->getPattern();
+              }
+            }
+          }else{
+            // current domain/alias is mobile
+            $is_mobile_domain = false;
+            $desktop_url = $alias->getPattern();
+            // find desktop pattern
+            foreach ($env_aliases as $env_alias_id => $env_alias) {
+              if($env_alias_id != $alias_id){
+                // we found the desktop pattern
+                $mobile_url = $env_alias->getPattern();
+              }
+            }
+          }
+          break;
+        }
+      }
+      break;
+    }
+  }
+
+  // $mobile =
+  $current_path = \Drupal::service('path.current')->getPath();
+  $is_front = \Drupal::service('path.matcher')->isFrontPage();
+  $current_language = \Drupal::languageManager()->getCurrentLanguage()->getId();
+
+  // $redirect = false;
+  $js_str = "var edlp_mobile = {\n
+    current_url:'".$base_root."',\n
+    current_path:'".$current_path."',\n
+    is_front:".($is_front ? 'true':'false').",\n
+    lang_code:'".$current_language."',\n
+    is_mobile_domain:".($is_mobile_domain ? 'true':'false').",\n
+    mobile_url:'".$mobile_url."',\n
+    desktop_url:'".$desktop_url."',\n
+  };";
+
+  $attachments['#attached']['html_head'][] = [
+    [
+      '#type' => 'html_tag',
+      '#tag' => 'script',
+      '#value' => $js_str,
+      '#weight' => -1000,
+      '#group' => 'edlp'
+    ],
+    // A key, to make it possible to recognize this HTML  element when altering.
+    'edlp_mobile',
+  ];
+}

+ 0 - 2
sites/all/themes/custom/edlptheme/assets/dist/scripts/history.min.js

@@ -1,2 +0,0 @@
-
-void 0;if(edlp.redirect){void 0;void 0;edlp.sys_path=edlp.sys_path.replace(/^\//,'');edlp.url=window.location.pathname;edlp.hash=window.location.hash;window.localStorage.setItem('edlp_origin',JSON.stringify(edlp));window.location.replace(window.location.origin+'/'+edlp.lang_code);}else{void 0;}

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


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


+ 0 - 20
sites/all/themes/custom/edlptheme/assets/scripts/history.js

@@ -1,20 +0,0 @@
-console.log('EDLP THEME HISTORY.js');
-// var edlp is provided by edlp_ajax.module file
-if(edlp.redirect){
-  console.log('history redirect', edlp);
-  console.log('window.location', window.location);
-  // window.localStorage.setItem('edlp_origin_path', edlp.sys_path.replace(/^\//, ''));
-  edlp.sys_path = edlp.sys_path.replace(/^\//, '');
-
-  // window.localStorage.setItem('edlp_origin_url', window.location.pathname);
-  edlp.url = window.location.pathname;
-
-  // window.localStorage.setItem('edlp_origin_hash', window.location.hash);
-  edlp.hash = window.location.hash;
-
-  window.localStorage.setItem('edlp_origin', JSON.stringify(edlp));
-  // redirect to home
-  window.location.replace(window.location.origin+'/'+edlp.lang_code);
-}else{
-  console.log('history do not redirect');
-}

+ 5 - 3
sites/all/themes/custom/edlptheme/assets/scripts/main.js

@@ -121,9 +121,11 @@
       if($audioplayer.length){
         var navpos = $('#block-mainnavigation').position();
         console.log('navpos', navpos);
-        $audioplayer.css({
-          'width':navpos.left+'px'
-        });
+        if(typeof navpos != 'undefined'){
+          $audioplayer.css({
+            'width':navpos.left+'px'
+          });
+        }
       }
 
       // entrees

File diff suppressed because it is too large
+ 4 - 0
sites/all/themes/custom/edlptheme/assets/scripts/redirect.js


+ 1 - 1
sites/all/themes/custom/edlptheme/edlptheme.info.yml

@@ -5,7 +5,7 @@ base theme: classy
 core: 8.x
 libraries:
   - core/normalize
-  - edlptheme/history-js
+  - edlptheme/redirect-js
   - edlptheme/global-css
   - edlptheme/global-js
 

+ 2 - 2
sites/all/themes/custom/edlptheme/edlptheme.libraries.yml

@@ -4,11 +4,11 @@ global-css:
     theme:
       assets/dist/styles/app.min.css: {}
 
-history-js:
+redirect-js:
   version: VERSION
   header: true
   js:
-    assets/dist/scripts/history.min.js: { weight:-998, preprocess: false, minified: true }
+    assets/dist/scripts/redirect.min.js: { weight:-998, preprocess: false, minified: true }
 
 global-js:
   version: VERSION

+ 1 - 1
sites/all/themes/custom/edlptheme/gulpfile.js

@@ -29,7 +29,7 @@ function handleError(err) {
 }
 
 gulp.task('scripts', function () {
-  gulp.src(['./assets/scripts/main.js', './assets/scripts/history.js']) // './assets/scripts/shared_variables.js',
+  gulp.src(['./assets/scripts/main.js', './assets/scripts/redirect.js']) // './assets/scripts/shared_variables.js',
     // .pipe(concat('main.js'))
     .pipe(gulpif(prod, stripDebug()))
     .pipe(gulpif(prod, jsmin()))

+ 2 - 2
sites/all/themes/custom/edlptheme/templates/content/edlp-home.html.twig

@@ -18,7 +18,7 @@
 <div class="grid">
 
   {% for node in nodes %}
-    <div class="col col-{{ node.cols }}">
+    <div class="col small-col-12 med-col-4 large-col-{{ node.cols }}">
       <div class="wrapper">
         {{ node.build }}
       </div>
@@ -26,7 +26,7 @@
   {% endfor %}
 
 
-  <div class="agenda col col-3">
+  <div class="agenda col small-col-12 med-col-4 large-col-3">
     <div class="wrapper">
       {{ agenda }}
     </div>

+ 3 - 3
sites/default/config/sync/better_messages.settings.yml

@@ -2,7 +2,7 @@ position: tr
 vertical: 70
 horizontal: 10
 fixed: 1
-width: 400px
+width: 600px
 autoclose: 7
 opendelay: 0.3
 disable_autoclose: 1
@@ -15,8 +15,8 @@ popout:
   effect: fadeIn
   duration: fast
 jquery_ui:
-  draggable: 0
-  resizable: 0
+  draggable: 1
+  resizable: 1
 visibility:
   message_type:
     id: message_type

+ 2 - 1
sites/default/config/sync/block.block.edlpentreesblock.yml

@@ -25,7 +25,8 @@ visibility:
     domains:
       encyclopediedelaparole_org: encyclopediedelaparole_org
     negate: false
-    context_mapping: {  }
+    context_mapping:
+      'entity:domain': '@domain.current_domain_context:entity:domain'
   request_path:
     id: request_path
     pages: '<front>'

+ 1 - 0
sites/default/config/sync/core.entity_view_display.node.enregistrement.default.yml

@@ -45,6 +45,7 @@ content:
       link: false
     third_party_settings: {  }
 hidden:
+  addtoany: true
   body: true
   chutier_actions: true
   field_collectionneurs: true

+ 1 - 0
sites/default/config/sync/core.extension.yml

@@ -39,6 +39,7 @@ module:
   edlp_fils: 0
   edlp_home: 0
   edlp_migrate: 0
+  edlp_mobile: 0
   edlp_productions: 0
   edlp_search: 0
   edlp_studio: 0

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