]> _ Git - physioassist-wordpress.git/commitdiff
Wait #3921 @6
authorstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 15 Oct 2020 17:10:43 +0000 (17:10 +0000)
committerstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 15 Oct 2020 17:10:43 +0000 (17:10 +0000)
wp-config.php
wp-content/mu-plugins/physioassist/src/CookieNotice/Setup.php [new file with mode: 0644]
wp-content/mu-plugins/physioassist/src/Init.php
wp-content/themes/physioassist/package.json
wp-content/themes/physioassist/resources/assets/config.json
wp-content/themes/physioassist/resources/assets/images/icons/close.svg
wp-content/themes/physioassist/resources/assets/scripts/cookie-notice.js [new file with mode: 0644]
wp-content/themes/physioassist/resources/assets/styles/components/navigation-mobile.styl
wp-content/themes/physioassist/resources/assets/styles/widgets/cookie-notice.styl [new file with mode: 0644]
wp-content/themes/physioassist/resources/views/widgets/cookie-notice.blade.php [new file with mode: 0644]
wp-content/themes/physioassist/yarn.lock

index 7aac956356916896a878636815841d7b46e4031e..9f01a5d4bba1057172821fc3438977d73e7dba9e 100644 (file)
@@ -65,7 +65,9 @@ $table_prefix  = 'wp_';
  *\r
  * @link https://codex.wordpress.org/Debugging_in_WordPress\r
  */\r
-define('WP_DEBUG', false);\r
+if ( !defined('WP_DEBUG') ) {\r
+    define('WP_DEBUG', false);\r
+}\r
 \r
 /* That's all, stop editing! Happy blogging. */\r
 \r
diff --git a/wp-content/mu-plugins/physioassist/src/CookieNotice/Setup.php b/wp-content/mu-plugins/physioassist/src/CookieNotice/Setup.php
new file mode 100644 (file)
index 0000000..59b678d
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+
+namespace PhysioAssist\CookieNotice;
+
+use function App\template;
+use function App\asset_path;
+
+class Setup {
+
+    private $cookie_name = 'cube-cookies-accepted';
+
+    /**
+     * Common setup, will be automatically triggered by Init class if included
+     */
+    public function register() {
+
+        if (isset($_COOKIE[$this->cookie_name]) && $_COOKIE[$this->cookie_name] == 1) {
+            return false; // Already accepted, nothing else to be done
+        }
+
+        // Output HTML for cookie notice at the bottom of the page
+        add_action('get_footer', function() {
+            // Include JS resources for cookie notice
+            wp_register_script('lity', asset_path('scripts/lity.js'), ['jquery'], null, true);
+            wp_register_script('cube-cookie-notice', asset_path('scripts/cookie-notice.js'), ['lity'], null, true);
+            wp_localize_script('cube-cookie-notice', 'cube_cookie_notice', ['cookie_name' => $this->cookie_name]); // For JS usage
+            wp_enqueue_script('cube-cookie-notice');
+
+            // Get content from cookie notice page
+            $cookie_notice = get_page_by_path('cookie-notice');
+
+            if ($cookie_notice) {
+                $learn_more = __('Learn more', 'physioassist');
+
+                // Note: We could support this content coming from Elementor but it's simpler for now
+                // to use the basic WordPress content. In the future, we could check the post_meta and
+                // if _elementor_edit_mode = 'builder', then we know it's an Elementor page...
+                //$content = \Elementor\Plugin::instance()->frontend->get_builder_content_for_display(wpml_object_id_filter($cookie_notice->ID, 'page', true));
+
+                $page_ID = wpml_object_id_filter($cookie_notice->ID, 'page', true);
+
+                $message = get_post_meta($page_ID, 'cube_cookie_message', true); // Custom post meta holds the cookie message
+                $content = wpautop(get_post_field('post_content', $page_ID)); // Page body holds popup info
+
+                echo template('widgets/cookie-notice', compact('message', 'learn_more', 'content'));
+            } else {
+                echo '<script>console.warn("Cookie Notice Error: unable to get message. Check page exists.")</script>';
+            }
+        });
+
+    }
+
+}
index dc076509a5ba039c4a42583c101c46800fcd33b6..7eec85bd591a2fadfcf7767bb58c9666a07866f8 100644 (file)
@@ -16,6 +16,7 @@ final class Init { // Marked as final because this class should never be extende
             Common\Setup::class,
             Elementor\Setup::class,
             WooCommerce\Setup::class,
+            CookieNotice\Setup::class,
         ];
     }
 
index 74b8b5e0407f1d76ec93f5b760e4a88b03c49bba..bc758e135b5acc0e36e3c1da899862fb33eb7a0e 100644 (file)
@@ -84,6 +84,7 @@
     "imagemin-mozjpeg": "~7.0.0",
     "imagemin-webpack-plugin": "~2.0.0",
     "import-glob": "~1.5",
+    "js-cookie": "^2.2.1",
     "lity": "^2.4.0",
     "lodash.debounce": "^4.0.8",
     "lodash.throttle": "^4.1.1",
index be29e77c4ea6514e76fcff7050b0d7c12b805503..1a096a71c3a13d386ad5ffded0478c8630a14a80 100644 (file)
@@ -31,6 +31,9 @@
     "lity": [
       "./scripts/lity.js"
     ],
+    "cookie-notice": [
+      "./scripts/cookie-notice.js"
+    ],
     "customizer": [
       "./scripts/customizer.js"
     ]
index 52c722155f13837f2f85721f04ae1b0da9cf557e..3838fe8e083cfbb9a8e9df8f162a48c0f6c7a3ef 100644 (file)
@@ -1,14 +1 @@
-<?xml version="1.0" encoding="utf-8"?>\r
-<!-- Generator: Adobe Illustrator 15.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->\r
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\r
-<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"\r
-        width="17.847px" height="17.847px" viewBox="0 0 17.847 17.847" enable-background="new 0 0 17.847 17.847" xml:space="preserve">\r
-<g>\r
-       <g>\r
-               <path fill-rule="evenodd" clip-rule="evenodd" fill="#ffffff" d="M11.044,8.923l6.363-6.363c0.586-0.585,0.586-1.535,0-2.121\r
-                       c-0.586-0.585-1.535-0.585-2.121,0L8.923,6.802L2.56,0.439c-0.586-0.585-1.535-0.585-2.121,0c-0.585,0.586-0.585,1.536,0,2.121\r
-                       l6.363,6.363l-6.363,6.363c-0.585,0.586-0.585,1.535,0,2.121c0.586,0.586,1.535,0.586,2.121,0l6.363-6.363l6.363,6.363\r
-                       c0.586,0.586,1.535,0.586,2.121,0s0.586-1.535,0-2.121L11.044,8.923z"/>\r
-       </g>\r
-</g>\r
-</svg>\r
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 17.847 17.847"><path fill-rule="evenodd" clip-rule="evenodd" fill="#fff" d="M11.044 8.923l6.363-6.363A1.5 1.5 0 1015.286.439L8.923 6.802 2.56.439a1.501 1.501 0 00-2.121 0 1.501 1.501 0 000 2.121l6.363 6.363-6.363 6.363a1.5 1.5 0 102.121 2.121l6.363-6.363 6.363 6.363a1.5 1.5 0 102.121-2.121l-6.363-6.363z"/></svg>
diff --git a/wp-content/themes/physioassist/resources/assets/scripts/cookie-notice.js b/wp-content/themes/physioassist/resources/assets/scripts/cookie-notice.js
new file mode 100644 (file)
index 0000000..6f81e7d
--- /dev/null
@@ -0,0 +1,9 @@
+import Cookies from 'js-cookie';
+
+// Get name of cookie from localised script variable set in PHP
+let cookie_name = window.cube_cookie_notice.cookie_name;
+
+$(document).on('click', '.cube-cookie-notice-close', function() {
+  Cookies.set(cookie_name, 1, { expires: 365 });
+  $(this).parent().fadeOut();
+});
index 518334b5d4266472c3d53799bf1b2ba3c2db02d1..11136cdf1af146220b2340ea4358bfd386851bb5 100644 (file)
@@ -7,10 +7,12 @@
   width: 32px
   height: 28px
   background: url(../images/icons/mobile-menu.svg) center no-repeat
+  background-size: contain
   cursor: pointer
 
   &.open
     background-image: url(../images/icons/close.svg)
+    background-size: 18px
 
   +below($breakpoint-menu)
     display: block
diff --git a/wp-content/themes/physioassist/resources/assets/styles/widgets/cookie-notice.styl b/wp-content/themes/physioassist/resources/assets/styles/widgets/cookie-notice.styl
new file mode 100644 (file)
index 0000000..1a98d91
--- /dev/null
@@ -0,0 +1,29 @@
+.cube-cookie-notice
+  position: fixed
+  left: 30px
+  bottom: 30px
+  width: calc(100% - 60px)
+  max-width: 350px
+  background-color: rgba(#222, 0.95)
+  color: #fff
+  padding: 1em 2.25em
+  z-index: 99
+  font-size: 13px
+
+  &-close
+    position: absolute
+    top: 0.7em
+    right: @top
+    width: 1.25em
+    height: @width
+    cursor: pointer
+
+  &-lightbox
+    horizontal-spacing(5vw)
+    padding-top: 90px
+    constrain(padding-bottom, 5vw)
+    background-color: #fff
+    width: 90vw
+    max-width: 1200px
+    max-height: 90vh !important // Gives 5% top and bottom gap
+    overflow-y: auto // Scroll internally if content is too tall for screen
diff --git a/wp-content/themes/physioassist/resources/views/widgets/cookie-notice.blade.php b/wp-content/themes/physioassist/resources/views/widgets/cookie-notice.blade.php
new file mode 100644 (file)
index 0000000..3dbe993
--- /dev/null
@@ -0,0 +1,12 @@
+{{-- Cube Cookie Notice --}}
+<div class="cube-cookie-notice">
+  {!! $message !!}
+  <br/>
+  <a href="#cube_cookie_notice_info" data-lity>{{ $learn_more }}</a>
+  @svg('icons/close', 'cube-cookie-notice-close')
+</div>
+
+{{-- Lightbox popup --}}
+<div id="cube_cookie_notice_info" class="cube-cookie-notice-lightbox lity-hide">
+  {!! $content !!}
+</div>
index 763b9a81e0dc1677d1b269586c22a6114e2b9464..308566e74b38f7783c8c4adfc16a664653d9e102 100644 (file)
@@ -4978,6 +4978,11 @@ js-base64@^2.1.8, js-base64@^2.1.9:
   resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.5.1.tgz#1efa39ef2c5f7980bb1784ade4a8af2de3291121"
   integrity sha512-M7kLczedRMYX4L8Mdh4MzyAMM9O5osx+4FcOQuTvr3A9F2D9S5JXheN0ewNbrvK2UatkTRhL5ejGmGSjNMiZuw==
 
+js-cookie@^2.2.1:
+  version "2.2.1"
+  resolved "https://registry.yarnpkg.com/js-cookie/-/js-cookie-2.2.1.tgz#69e106dc5d5806894562902aa5baec3744e9b2b8"
+  integrity sha512-HvdH2LzI/EAZcUwA8+0nKNtWHqS+ZmijLA30RwZA0bo7ToCckjK5MkGhjED9KoRcXO6BaGI3I9UIzSA1FKFPOQ==
+
 js-tokens@^3.0.2:
   version "3.0.2"
   resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"