Skip to content

Commit

Permalink
Added asset bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Croker committed Feb 17, 2021
1 parent 4bd4828 commit bd34d87
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
30 changes: 30 additions & 0 deletions src/assets/ErrorAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* @copyright Copyright (c) PutYourLightsOn
*/

namespace putyourlightson\snaptcha\assets;

use craft\web\AssetBundle;

class ErrorAsset extends AssetBundle
{
/**
* @inheritdoc
*/
public function init()
{
$this->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();
}
}
4 changes: 4 additions & 0 deletions src/resources/css/error.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.btn.submit {
font-weight: bold !important;
text-transform: uppercase;
}
8 changes: 8 additions & 0 deletions src/resources/js/error.js
Original file line number Diff line number Diff line change
@@ -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);
14 changes: 4 additions & 10 deletions src/templates/_error.html
Original file line number Diff line number Diff line change
@@ -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 %}

Expand All @@ -30,10 +24,10 @@ <h2>{{ settings.errorTitle }}</h2>

{{ craft.snaptcha.field }}

<button id="resubmit" type="submit" class="btn submit disabled" style="font-weight: bold; text-transform: uppercase;">
<button id="resubmit" type="submit" class="btn submit disabled" data-timeout="{{ settings.minimumSubmitTime * 1000 }}">
{{ settings.errorButtonText }}
</button>
<div id="graphic" class="spinner"></div>
<div id="graphic" class="spinner hidden"></div>
</form>

{% endblock %}

0 comments on commit bd34d87

Please sign in to comment.