]> _ Git - physioassist-wordpress.git/commitdiff
Bug fixes + Done #2098 @5.5
authorstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 28 Jun 2018 17:27:29 +0000 (17:27 +0000)
committerstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 28 Jun 2018 17:27:29 +0000 (17:27 +0000)
wp-content/mu-plugins/physioassist/src/Elementor/Widgets/ProfileGrid.php
wp-content/themes/physioassist/package.json
wp-content/themes/physioassist/resources/assets/config.json
wp-content/themes/physioassist/resources/assets/scripts/profile-grid.js [new file with mode: 0644]
wp-content/themes/physioassist/resources/assets/styles/layouts/header.styl
wp-content/themes/physioassist/resources/assets/styles/widgets/profile-grid.styl
wp-content/themes/physioassist/resources/views/widgets/profile-grid.blade.php
wp-content/themes/physioassist/yarn.lock

index fa8fdc162f75b4c3549cac44e3839b9cc95dc898..66669a784b0fafe091d3170438e9c7a6f5f3514f 100644 (file)
@@ -40,7 +40,16 @@ class ProfileGrid extends Widget_Base {
      * @return array Widget scripts dependencies.
      */
     public function get_script_depends() {
-        return [];
+
+        wp_register_script(
+            'cube-profile-grid',
+            \App\asset_path('scripts/profile-grid.js'),
+            ['jquery'], // Dependencies
+            null, // Version
+            true // In footer?
+        );
+
+        return ['cube-profile-grid'];
     }
     /**
      * Register the widget controls.
@@ -111,6 +120,32 @@ class ProfileGrid extends Widget_Base {
                 'title_field' => '{{{ title }}}',
             ]
         );
+
+        $this->add_control(
+            'truncate_text',
+            [
+                'label' => __( 'Truncate long text?', 'cube' ),
+                'type' => Controls_Manager::SWITCHER,
+                'default' => '',
+                'return_value' => 'truncate-text',
+                'prefix_class' => '',
+                'render_type' => 'template', // Make editor re-render when this changes
+            ]
+        );
+
+        $this->add_control(
+            'truncate_lines',
+            [
+                'label' => __( 'Max lines of text', 'cube' ),
+                'type' => Controls_Manager::NUMBER,
+                'default' => '5',
+                'condition' => [
+                    'truncate_text!' => ''
+                ],
+                'separator' => 'none',
+            ]
+        );
+
         $this->end_controls_section();
     }
     /**
@@ -123,8 +158,9 @@ class ProfileGrid extends Widget_Base {
     protected function render() {
 
         $items = $this->get_settings('items');
+        $truncate_lines = $this->get_settings('truncate_lines');
 
-        $html = \App\template('widgets/profile-grid', compact('items'));
+        $html = \App\template('widgets/profile-grid', compact('items', 'truncate_lines'));
 
         echo '<div class="profile-grid">'. $html .'</div>';
     }
@@ -157,7 +193,11 @@ class ProfileGrid extends Widget_Base {
                             <h4 class="profile-grid-subtitle">{{{ item.subtitle }}}</h4>
                         <# } #>
 
-                        <div class="profile-grid-body">
+                        <div class="profile-grid-body"
+                             data-truncate-lines="{{ settings.truncate_lines }}"
+                             data-read-more="<?php _ex('Read more', 'Profile grid read more link text', 'cube') ?>"
+                             data-read-less="<?php _ex('Read less', 'Profile grid read less link text', 'cube') ?>"
+                        >
                             {{{ item.body }}}
                         </div>
 
index 90edbf4a17761e252a91f6536ab9d11a179bcd1f..160ecbe32c2a6541eb6c18ea3c64cc9cf85464ad 100644 (file)
     "stylelint-webpack-plugin": "^0.10.1",
     "stylus": "^0.54.5",
     "stylus-loader": "^3.0.1",
+    "trunk8": "^0.0.1",
     "url-loader": "^0.6.2",
     "webpack": "~3.10.0",
     "webpack-assets-manifest": "^1.0.0",
index 83a0f07c2e7fc3a18c8a02b8c493c59bab69e04c..9fe0d87904cc91912530de11c207653e56d579ac 100644 (file)
@@ -7,6 +7,9 @@
     "hero-block": [
       "./scripts/hero-block.js"
     ],
+    "profile-grid": [
+      "./scripts/profile-grid.js"
+    ],
     "text-block": [
       "./scripts/text-block.js"
     ],
diff --git a/wp-content/themes/physioassist/resources/assets/scripts/profile-grid.js b/wp-content/themes/physioassist/resources/assets/scripts/profile-grid.js
new file mode 100644 (file)
index 0000000..ba58d7c
--- /dev/null
@@ -0,0 +1,62 @@
+import trunk8 from 'trunk8'; // eslint-disable-line
+import debounce from 'lodash.debounce';
+
+(function($) {
+
+  // ELEMENTOR Trigger
+  $(window).on( 'elementor/frontend/init', function() {
+    // eslint-disable-next-line
+    elementorFrontend.hooks.addAction('frontend/element_ready/cube-profile-grid.default', function ($scope) {
+
+      // Only run on blocks that have this setting activated
+      if (!$scope.hasClass('truncate-text')) {
+        return;
+      }
+
+      var text_selector = '.profile-grid-body',
+          $text = $scope.find(text_selector),
+          num_lines = $text.data('truncate-lines') || 5,
+          read_more = $text.data('read-more'),
+          read_less = $text.data('read-less'),
+          svg_arrow = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 74.247 119.388">
+                          <path d="M11.506,119.388c-3.253,0-6.485-1.372-8.76-4.043c-4.119-4.835-3.538-12.093,1.297-16.211l46.299-39.44
+                          L4.043,20.254C-0.792,16.136-1.373,8.878,2.746,4.043c4.119-4.835,11.377-5.416,16.212-1.297l47.791,40.71
+                          c4.765,4.058,7.499,9.977,7.499,16.237c0,6.262-2.734,12.181-7.5,16.239l-47.79,40.709
+                          C16.793,118.486,14.142,119.388,11.506,119.388z M51.834,60.965h0.01H51.834z"/>
+                       </svg>`;
+
+      setTimeout(function() {
+        $text.trunk8({
+          lines: num_lines,
+          fill: `... <a class="profile-grid-read-more arrow-link" href="#">${svg_arrow} ${read_more}</a>`,
+        });
+      }, 100); // Small timeout needed or Trunk8 doesn't always fire on frontend
+
+
+      $(document).on('click', '.profile-grid-read-more', function (event) {
+        $(this).parents(text_selector).trunk8('revert').append(`<a class="profile-grid-read-less arrow-link" href="#">${svg_arrow} ${read_less}</a>`);
+        event.preventDefault();
+      });
+
+      $(document).on('click', '.profile-grid-read-less', function (event) {
+        $(this).parent().trunk8();
+        event.preventDefault();
+      });
+
+
+    });
+  });
+
+  $(document).ready(function() {
+    setTimeout(truncateText, 500); // Just in case it doesn't fire the first time for some reason...
+  });
+
+  // Handle re-trimming text when window resizes
+  $(window).on('resize', debounce(truncateText, 250));
+
+
+})(jQuery);
+
+function truncateText() {
+  $('.truncate-text .profile-grid-body').trunk8();
+}
index b553f957e13edffcc10a944a416e13543263e3ee..f65214f509d3ae1f7de6e8f9b920a00ebdd849c3 100644 (file)
@@ -28,6 +28,12 @@ header.site
   .elementor-editor-active &
     pointer-events: none
 
+  // When in Elementor editor and we scroll down, there will be
+  // a gap at the top that is left by the editor controls. This
+  // isn't needed once we scroll down so reset position to top: 0
+  .elementor-editor-active.transparent-header-disabled &
+    top: 0
+
   // Main logo
   // Logo is split into symbol + text so we can hide the symbol when reducing the header height
   .logo
index 605e6f334a7295b71850494f0316c3e479816fe1..64fd8b66e974a3cfeb2c896a604e54b174b5ca49 100644 (file)
@@ -27,6 +27,7 @@
 
   &-text
     constrain(padding-left, 3.5vw) // Gutter between image and text
+    flex: 1 // Needed so Firefox behaves (sets flex-basis: 0%)
 
     +below(400px)
       padding-left: 0
     color: $colors.text
     font-size: 16px
 
-  &-cta
+  &-cta, &-read-more, &-read-less
     display: block
     margin-top: 1.4em
+
+  &-read-less
+    svg
+      transform: rotate(180deg)
index b1279cba61c661d8bba5f7b57a0e9808db4e9d25..4a5a4a51b3a5bc9ab77dd167509dc66d154a19da 100644 (file)
         <h4 class="profile-grid-subtitle">{{ $item['subtitle'] }}</h4>
       @endif
 
-      <div class="profile-grid-body">
+      <div class="profile-grid-body"
+           data-truncate-lines="{{ $truncate_lines }}"
+           data-read-more="<?php _ex('Read more', 'Profile grid read more link text', 'cube') ?>"
+           data-read-less="<?php _ex('Read less', 'Profile grid read less link text', 'cube') ?>"
+      >
         {!! $item['body'] !!}
       </div>
 
index 3551ee1f8841873157c082d9e5309a4fc16e4362..9f39888356ad1d49f5fddd09853933b6c1d5057f 100644 (file)
@@ -7097,6 +7097,10 @@ trough@^1.0.0:
   dependencies:
     glob "^6.0.4"
 
+trunk8@^0.0.1:
+  version "0.0.1"
+  resolved "https://registry.yarnpkg.com/trunk8/-/trunk8-0.0.1.tgz#710b5614ed3b35a24ee8349769c3cc2a158e9ad5"
+
 tty-browserify@0.0.0:
   version "0.0.0"
   resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6"