From bd34d875d36f248e4a594f9f8c4752d0ff377879 Mon Sep 17 00:00:00 2001 From: Ben Croker Date: Wed, 17 Feb 2021 14:57:37 +0100 Subject: [PATCH] Added asset bundle --- src/assets/ErrorAsset.php | 30 ++++++++++++++++++++++++++++++ src/resources/css/error.css | 4 ++++ src/resources/js/error.js | 8 ++++++++ src/templates/_error.html | 14 ++++---------- 4 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 src/assets/ErrorAsset.php create mode 100644 src/resources/css/error.css create mode 100644 src/resources/js/error.js diff --git a/src/assets/ErrorAsset.php b/src/assets/ErrorAsset.php new file mode 100644 index 0000000..38f984a --- /dev/null +++ b/src/assets/ErrorAsset.php @@ -0,0 +1,30 @@ +sourcePath = '@putyourlightson/snaptcha/resources'; + + // define the relative path to CSS/JS files that should be registered with the page when this asset bundle is registered + $this->css = [ + 'css/error.css', + ]; + + $this->js = [ + 'js/error.js', + ]; + + parent::init(); + } +} diff --git a/src/resources/css/error.css b/src/resources/css/error.css new file mode 100644 index 0000000..cbc4bcb --- /dev/null +++ b/src/resources/css/error.css @@ -0,0 +1,4 @@ +.btn.submit { + font-weight: bold !important; + text-transform: uppercase; +} diff --git a/src/resources/js/error.js b/src/resources/js/error.js new file mode 100644 index 0000000..11142e7 --- /dev/null +++ b/src/resources/js/error.js @@ -0,0 +1,8 @@ +document.getElementById('warning').remove(); +document.getElementById('error').classList.remove('hidden'); +document.getElementById('graphic').classList.remove('hidden'); + +setTimeout(function() { + document.getElementById('graphic').remove(); + document.getElementById('resubmit').classList.remove('disabled'); +}, document.getElementById('resubmit').dataset.timeout); diff --git a/src/templates/_error.html b/src/templates/_error.html index e520f75..5677851 100644 --- a/src/templates/_error.html +++ b/src/templates/_error.html @@ -1,15 +1,9 @@ {% extends '_layouts/message' %} +{% do view.registerAssetBundle('putyourlightson\\snaptcha\\assets\\ErrorAsset') %} + {% set title = settings.errorTitle %} -{% js %} - document.getElementById('warning').remove(); - document.getElementById('error').classList.remove('hidden'); - setTimeout(function() { - document.getElementById('graphic').remove(); - document.getElementById('resubmit').classList.remove('disabled'); - }, {{ (settings.minimumSubmitTime * 1000) + random(1, 100) }}); -{% endjs %} {% block message %} @@ -30,10 +24,10 @@

{{ settings.errorTitle }}

{{ craft.snaptcha.field }} - -
+ {% endblock %}