Works with the Form plugin
This commit is contained in:
parent
6ce186584e
commit
5f50c08970
8 changed files with 221 additions and 404 deletions
|
@ -1,194 +0,0 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<title>Comments Email Template</title>
|
||||
<style>
|
||||
/* -------------------------------------
|
||||
GLOBAL
|
||||
------------------------------------- */
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;
|
||||
font-size: 100%;
|
||||
line-height: 1.6;
|
||||
}
|
||||
img {
|
||||
max-width: 100%;
|
||||
}
|
||||
body {
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-webkit-text-size-adjust: none;
|
||||
width: 100%!important;
|
||||
height: 100%;
|
||||
}
|
||||
/* -------------------------------------
|
||||
ELEMENTS
|
||||
------------------------------------- */
|
||||
a {
|
||||
color: #348eda;
|
||||
}
|
||||
.btn-primary {
|
||||
text-decoration: none;
|
||||
color: #FFF;
|
||||
background-color: #348eda;
|
||||
border: solid #348eda;
|
||||
border-width: 10px 20px;
|
||||
line-height: 2;
|
||||
font-weight: bold;
|
||||
margin-right: 10px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
border-radius: 25px;
|
||||
}
|
||||
.btn-secondary {
|
||||
text-decoration: none;
|
||||
color: #FFF;
|
||||
background-color: #aaa;
|
||||
border: solid #aaa;
|
||||
border-width: 10px 20px;
|
||||
line-height: 2;
|
||||
font-weight: bold;
|
||||
margin-right: 10px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
border-radius: 25px;
|
||||
}
|
||||
.last {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.first {
|
||||
margin-top: 0;
|
||||
}
|
||||
.padding {
|
||||
padding: 10px 0;
|
||||
}
|
||||
/* -------------------------------------
|
||||
BODY
|
||||
------------------------------------- */
|
||||
table.body-wrap {
|
||||
width: 100%;
|
||||
padding: 20px;
|
||||
}
|
||||
table.body-wrap .container {
|
||||
border: 1px solid #f0f0f0;
|
||||
}
|
||||
/* -------------------------------------
|
||||
FOOTER
|
||||
------------------------------------- */
|
||||
table.footer-wrap {
|
||||
width: 100%;
|
||||
clear: both!important;
|
||||
}
|
||||
.footer-wrap .container p {
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
|
||||
}
|
||||
table.footer-wrap a {
|
||||
color: #999;
|
||||
}
|
||||
/* -------------------------------------
|
||||
TYPOGRAPHY
|
||||
------------------------------------- */
|
||||
h1, h2, h3 {
|
||||
font-family: "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
|
||||
color: #000;
|
||||
margin: 40px 0 10px;
|
||||
line-height: 1.2;
|
||||
font-weight: 200;
|
||||
}
|
||||
h1 {
|
||||
font-size: 36px;
|
||||
}
|
||||
h2 {
|
||||
font-size: 28px;
|
||||
}
|
||||
h3 {
|
||||
font-size: 22px;
|
||||
}
|
||||
p, ul, ol {
|
||||
margin-bottom: 10px;
|
||||
font-weight: normal;
|
||||
font-size: 14px;
|
||||
}
|
||||
ul li, ol li {
|
||||
margin-left: 5px;
|
||||
list-style-position: inside;
|
||||
}
|
||||
/* ---------------------------------------------------
|
||||
RESPONSIVENESS
|
||||
Nuke it from orbit. It's the only way to be sure.
|
||||
------------------------------------------------------ */
|
||||
/* Set a max-width, and make it display as block so it will automatically stretch to that width, but will also shrink down on a phone or something */
|
||||
.container {
|
||||
display: block!important;
|
||||
max-width: 600px!important;
|
||||
margin: 0 auto!important; /* makes it centered */
|
||||
clear: both!important;
|
||||
}
|
||||
/* Set the padding on the td rather than the div for Outlook compatibility */
|
||||
.body-wrap .container {
|
||||
padding: 20px;
|
||||
}
|
||||
/* This should also be a block element, so that it will fill 100% of the .container */
|
||||
.content {
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
display: block;
|
||||
}
|
||||
/* Let's make sure tables in the content area are 100% wide */
|
||||
.content table {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#f6f6f6">
|
||||
|
||||
<!-- body -->
|
||||
<table class="body-wrap" bgcolor="#f6f6f6">
|
||||
<tr>
|
||||
<td></td>
|
||||
<td class="container" bgcolor="#FFFFFF">
|
||||
<div class="content">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
{{ content }}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
<!-- /body -->
|
||||
|
||||
<!-- footer -->
|
||||
<table class="footer-wrap">
|
||||
<tr>
|
||||
<td></td>
|
||||
<td class="container">
|
||||
<div class="content">
|
||||
<table>
|
||||
<tr>
|
||||
<td align="center">
|
||||
{{ 'PLUGIN_COMMENTS.EMAIL_FOOTER'|tu }}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
<!-- /footer -->
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -1,113 +1,28 @@
|
|||
{% set use_captcha = grav.config.plugins.comments.use_captcha %}
|
||||
<h3>{{'PLUGIN_COMMENTS.ADD_COMMENT'|t}}</h3>
|
||||
|
||||
<h3>Add a Comment</h3>
|
||||
<form name="{{ grav.config.plugins.comments.form.name }}"
|
||||
action="{{ uri.rootUrl ~ (grav.config.plugins.comments.form.action|default(page.route)) }}/processform:true"
|
||||
method="{{ grav.config.plugins.comments.form.method|upper|default('POST') }}">
|
||||
{% for field in grav.config.plugins.comments.form.fields %}
|
||||
|
||||
<script>
|
||||
$(function() {
|
||||
function validateEmail(email) {
|
||||
var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
|
||||
return re.test(email);
|
||||
}
|
||||
|
||||
$(document).on('click tap', '.js__add-new-comment', function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
var text = $('.js__new-comment-text').val();
|
||||
var name = $('.js__new-comment-name').val();
|
||||
var email = $('.js__new-comment-email').val();
|
||||
var captcha = $('#g-recaptcha-response').val();
|
||||
|
||||
if (text.length == 0 || email.length == 0 || name.length == 0) {
|
||||
$('.alert').html('Please fill all the fields');
|
||||
$('.alert-container').show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!validateEmail(email)) {
|
||||
$('.alert').html('Please enter a valid email');
|
||||
$('.alert-container').show();
|
||||
return;
|
||||
}
|
||||
|
||||
{% if use_captcha %}
|
||||
if (!captcha) {
|
||||
$('.alert').html("Error validating the security code");
|
||||
$('.alert-container').show();
|
||||
return;
|
||||
}
|
||||
{% endif %}
|
||||
|
||||
$.ajax({
|
||||
url: "{{ grav.uri.rootUrl }}/add-comment",
|
||||
data: {
|
||||
text: $('.js__new-comment-text').val(),
|
||||
name: $('.js__new-comment-name').val(),
|
||||
email: $('.js__new-comment-email').val(),
|
||||
title: "{{ grav.page.header.title }}",
|
||||
lang: "{{ grav.language.getActive }}",
|
||||
path: "{{ grav.uri.path }}",
|
||||
{% if use_captcha %}recaptchaResponse: captcha{% endif %}
|
||||
},
|
||||
type: 'POST'
|
||||
})
|
||||
.success(function() {
|
||||
$('.alert-container').hide();
|
||||
window.location.reload();
|
||||
})
|
||||
.error(function() {
|
||||
$('.alert').html("Error while posting the comment");
|
||||
$('.alert-container').show();
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
{% if use_captcha %}
|
||||
<script src="https://www.google.com/recaptcha/api.js?onload=captchaOnloadCallback&render=explicit" async defer></script>
|
||||
|
||||
<script>
|
||||
$(function() {
|
||||
var captchaOnloadCallback = function captchaOnloadCallback() {
|
||||
grecaptcha.render('g-recaptcha', {
|
||||
'sitekey': "{{grav.config.plugins.comments.recatpcha_site_key}}",
|
||||
'callback': captchaValidatedCallback,
|
||||
'expired-callback': captchaExpiredCallback
|
||||
});
|
||||
}
|
||||
|
||||
var captchaValidatedCallback = function captchaValidatedCallback() {
|
||||
};
|
||||
|
||||
var captchaExpiredCallback = function captchaExpiredCallback() {
|
||||
grecaptcha.reset();
|
||||
};
|
||||
});
|
||||
</script>
|
||||
{% endif %}
|
||||
|
||||
<div class="alert-container" style="display: none">
|
||||
<blockquote>
|
||||
<blockquote>
|
||||
<blockquote>
|
||||
<blockquote>
|
||||
<p class="alert"></p>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
</div>
|
||||
|
||||
<form>
|
||||
<textarea class="js__new-comment-text"></textarea>
|
||||
{{'PLUGIN_COMMENTS.NAME'|t}} <input type="text" class="js__new-comment-name" />
|
||||
{{'PLUGIN_COMMENTS.EMAIL'|t}} <input type="email" class="js__new-comment-email" />
|
||||
{% if use_captcha %}
|
||||
<div class="g-recaptcha" id="g-recaptcha"></div>
|
||||
{% set value = form.value(field.name) %}
|
||||
{% if field.evaluateDefault %}
|
||||
{% set value = evaluate(field.evaluateDefault) %}
|
||||
{% endif %}
|
||||
<div>
|
||||
{% include "forms/fields/#{field.type}/#{field.type}.html.twig" %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<input type="submit" class="js__add-new-comment" />
|
||||
<div class="buttons">
|
||||
{% for button in grav.config.plugins.comments.form.buttons %}
|
||||
<button class="button" type="{{ button.type|default('submit') }}">{{ button.value|default('Submit') }}</button>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="alert">{{ form.message }}</div>
|
||||
|
||||
{% if grav.twig.comments|length %}
|
||||
|
||||
<h3>{{'PLUGIN_COMMENTS.COMMENTS'|t}}</h3>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue