Skip to content

Commit

Permalink
Merge pull request #7 from mauricerenck/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mauricerenck authored Dec 4, 2020
2 parents aa92453 + 21e2841 commit b9a3427
Show file tree
Hide file tree
Showing 19 changed files with 420 additions and 221 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v12.16.3
180 changes: 89 additions & 91 deletions assets/komments.js
Original file line number Diff line number Diff line change
@@ -1,112 +1,110 @@
window.onload = function () {
const komment = document.querySelector('#kommentform #komment')
const kommentForm = document.querySelector('#kommentform')
const kommentEmail = document.querySelector('#kommentform #email')
const kommentAuthor = document.querySelector('#kommentform #author')
const kommentUrl = document.querySelector('#kommentform #author_url')
const timeField = document.querySelector('#kommentform .cts')
const submitField = document.querySelector('#kommentform input[type=submit]')
const spamIndicatorProgress = document.querySelector('#kommentform .spam-indicator .progress')
const sendingIndicator = document.querySelector('#kommentform .loader')
const formFeedback = document.querySelector('#kommentform .form-feedback')

let duration = {
indicator: 0,
timer: null,
current: 0
const komment = document.querySelector('#kommentform #komment')
const kommentForm = document.querySelector('#kommentform')
const kommentEmail = document.querySelector('#kommentform #email')
const kommentAuthor = document.querySelector('#kommentform #author')
const kommentUrl = document.querySelector('#kommentform #author_url')
const timeField = document.querySelector('#kommentform .cts')
const submitField = document.querySelector('#kommentform input[type=submit]')
const spamIndicatorProgress = document.querySelector('#kommentform .spam-indicator .progress')
const sendingIndicator = document.querySelector('#kommentform .loader')
const formFeedback = document.querySelector('#kommentform .form-feedback')

let duration = {
indicator: 0,
timer: null,
current: 0
}

const setIndicator = () => {

if (duration.current > 0) {
return
}

const setIndicator = () => {
timeField.value = 0;
submitField.disabled = true;

if (duration.current > 0) {
return
}
duration.timer = window.setInterval(() => {
duration.indicator += 10;
spamIndicatorProgress.style.width = `${duration.indicator}%`

timeField.value = 0;
submitField.disabled = true;
if (duration.indicator > 25) {
spamIndicatorProgress.classList.add('orange')
}

duration.timer = window.setInterval(() => {
duration.indicator += 10;
spamIndicatorProgress.style.width = `${duration.indicator}%`
if (duration.indicator > 50) {
spamIndicatorProgress.classList.add('yellow')
}

if (duration.indicator > 25) {
spamIndicatorProgress.classList.add('orange')
}
if (duration.indicator > 75) {
spamIndicatorProgress.classList.add('green')
}

if (duration.indicator > 50) {
spamIndicatorProgress.classList.add('yellow')
}
if (duration.indicator >= 100) {
spamIndicatorProgress.classList.add('done')
submitField.disabled = false;

if (duration.indicator > 75) {
spamIndicatorProgress.classList.add('green')
}
window.clearInterval(duration.timer)
}

if (duration.indicator >= 100) {
spamIndicatorProgress.classList.add('done')
submitField.disabled = false;
duration.current++;
timeField.value = duration.current
}, 1000)
}

window.clearInterval(duration.timer)
}

duration.current++;
timeField.value = duration.current
}, 1000)
const sendKomment = (event) => {
if (!kommentForm) {
return true
}
event.preventDefault();

const kommentFormAction = kommentForm.action;
sendingIndicator.classList.remove('loading-invisible');

window.fetch(kommentFormAction, {
method: 'post',
headers: { 'Content-Type': 'application/json', 'X-Return-Type': 'json' },
body: JSON.stringify(Object.fromEntries(new FormData(event.target))),
})
.then(function (response) {
sendingIndicator.classList.add('loading-invisible');
if (!response.ok) {
throw response;
}


const sendKomment = (event) => {
if (!kommentForm) {
return true
}
event.preventDefault();

const kommentFormAction = kommentForm.action;
sendingIndicator.classList.remove('loading-invisible');

window.fetch(kommentFormAction, {
method: 'post',
headers: { 'Content-Type': 'application/json', 'X-Return-Type': 'json' },
body: JSON.stringify(Object.fromEntries(new FormData(event.target))),
return response;
})
.then(function (response) {
sendingIndicator.classList.add('loading-invisible');
if (!response.ok) {
throw response;
}

return response;
.then((response) => {
response.json().then(message => {
formFeedback.classList.remove('error')
formFeedback.classList.add('moderation-note')
formFeedback.innerHTML = message.message
kommentForm.reset();
})
.then((response) => {
response.json().then(message => {
formFeedback.classList.remove('error')
formFeedback.classList.add('moderation-note')
formFeedback.innerHTML = message.message
kommentForm.reset();
})
})
.catch((error) => {
error.json().then(error => {
formFeedback.classList.add('error')
formFeedback.classList.remove('moderation-note')
formFeedback.innerHTML = error.message
})
.catch((error) => {
error.json().then(error => {
formFeedback.classList.add('error')
formFeedback.classList.remove('moderation-note')
formFeedback.innerHTML = error.message

})
})
}
})
}

kommentEmail.style.display = 'none';
kommentAuthor.style.display = 'none';
kommentUrl.style.display = 'none';
kommentEmail.style.display = 'none';
kommentAuthor.style.display = 'none';
kommentUrl.style.display = 'none';

komment.addEventListener('focus', () => {
setIndicator();
kommentEmail.style.display = 'block';
kommentAuthor.style.display = 'block';
kommentUrl.style.display = 'block';
});
komment.addEventListener('focus', () => {
setIndicator();
kommentEmail.style.display = 'block';
kommentAuthor.style.display = 'block';
kommentUrl.style.display = 'block';
});

kommentForm.addEventListener('submit', (event) => {
sendKomment(event);
});
kommentForm.addEventListener('submit', (event) => {
sendKomment(event);
});

};
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mauricerenck/komments",
"version": "0.9.14",
"version": "0.9.15",
"description": "A comment and webmention plugin for Kirby 3",
"type": "kirby-plugin",
"license": "MIT",
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions config/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@

use Xml;
use File;
use f;
use Structure;

return [
'routes' => [
[
'pattern' => 'komments/version',
'action' => function () {
$string = f::read(kirby()->roots()->index() . '/composer.json');
return $string;
}
],
[
'pattern' => 'komments/queued',
'action' => function () {
Expand Down
2 changes: 1 addition & 1 deletion config/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'mastodon-instance-url' => 'https://mastodon.social/api/v1/statuses',
'mastodon-text-field' => 'mastodonTeaser',
'ping-archiveorg' => false,
'auto-delete-spam' => true,
'auto-delete-spam' => false,
'auto-disable-komments' => 0,
'auto-disable-komments-datefield' => 'date',
'komment-icon-like' => '❤️',
Expand Down
2 changes: 1 addition & 1 deletion index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b9a3427

Please sign in to comment.