Fix some HTML structure and JS formatting

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-12-17 14:09:14 +01:00
parent 5a5c233a5e
commit 2c3148fe9e
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
3 changed files with 40 additions and 42 deletions

View File

@ -17,13 +17,13 @@
*/
$(document).ready(function () {
/**
* Error check when submitting form
*/
$("#formulaire").submit(function (event) {
var isHidden = $("#hidden").prop('checked');
var isOptionAllUserCanModifyEverything = $("#editableByAll").is(":checked");
var isHidden = $("#hidden").prop("checked");
var isOptionAllUserCanModifyEverything =
$("#editableByAll").is(":checked");
if (isHidden && isOptionAllUserCanModifyEverything) {
event.preventDefault();
@ -44,22 +44,23 @@ $(document).ready(function () {
}
});
/**
/**
* Enable/Disable ValueMax options
*/
$("#use_ValueMax").change(function () {
if ($(this).prop("checked")) {
$("#ValueMax").removeClass("hidden");
const useValueMax = document.querySelector("#use_ValueMax");
useValueMax.addEventListener("change", function () {
const valueMaxOptions = document.querySelector("#value_max_options");
if (useValueMax.checked) {
valueMaxOptions.classList.remove("hidden");
} else {
$("#ValueMax").addClass("hidden");
valueMaxOptions.classList.add("hidden");
}
});
/**
* Hide/Show password options
*/
$("#use_password").change(function(){
$("#use_password").change(function () {
if ($(this).prop("checked")) {
$("#password_options").removeClass("hidden");
} else {
@ -88,9 +89,12 @@ $(document).ready(function () {
document.getElementById("cookie-warning").setAttribute("style", "");
}
var wrapper = new MDEWrapper($('#poll_comments')[0], $('#rich-editor-button'), $('#simple-editor-button'));
if ($('#rich-editor-button').hasClass('active')) {
var wrapper = new MDEWrapper(
$("#poll_comments")[0],
$("#rich-editor-button"),
$("#simple-editor-button")
);
if ($("#rich-editor-button").hasClass("active")) {
wrapper.enable();
}
});

View File

@ -1,12 +1,12 @@
function myPreviewRender (text) {
text = text.replace(/[\u00A0-\u9999<>\&]/gim, function(i) {
return '&#'+i.charCodeAt(0)+';';
function myPreviewRender(text) {
text = text.replace(/[\u00A0-\u9999<>\&]/gim, function (i) {
return "&#" + i.charCodeAt(0) + ";";
});
text = SimpleMDE.prototype.markdown(text);
text = DOMPurify.sanitize(text);
return text;
};
}
function MDEWrapper(textarea, enableButton, disableButton) {
this.element = textarea;

View File

@ -129,36 +129,30 @@
{* Value MAX *}
<div class="form-group {$errors['ValueMax']['class']}">
<label for="use_valueMax" class="col-sm-4 control-label">
{__('Step 1', 'Value Max')}<br/>
</label>
<div class="col-sm-8">
<div class="checkbox">
<label>
<input id="use_ValueMax" name="use_ValueMax" type="checkbox" {if $use_ValueMax}checked{/if}>
{__('Step 1', "Limit the amount of voters per option")}
</label>
</div>
</div>
</div>
<div class="form-group {$errors['ValueMax']['class']}">
<div id="ValueMax" {if !$use_ValueMax}class="hidden"{/if}>
<div class="col-sm-offset-4 col-sm-8">
<label for="use_valueMax" class="col-sm-4 control-label">
{__('Step 1', 'Value Max')}<br/>
</label>
<div class="col-sm-8">
<div class="checkbox">
<label>
<input id="ValueMax" type="number" min="0" name="ValueMax" value="{$ValueMax|html}" {$errors['ValueMax']['aria']}>
{__('Step 1', "ValueMax instructions")}
<input id="use_ValueMax" name="use_ValueMax" type="checkbox" {if $use_ValueMax}checked{/if} />
{__('Step 1', "Limit the amount of voters per option")}
</label>
</div>
</div>
</div>
<div id="value_max_options" {if !$use_ValueMax}class="hidden"{/if}>
<div class="col-sm-offset-4 col-sm-8">
<label for="ValueMax">
<input id="ValueMax" type="number" min="0" name="ValueMax" value="{$ValueMax|html}" {$errors['ValueMax']['aria']} />
{__('Step 1', "ValueMax instructions")}
</label>
</div>
</div>
</div>
{if !empty($errors['ValueMax']['msg'])}
<div class="alert alert-danger">
<p id="poll_customized_url_error">
<p id="poll_value_max_error">
{$errors['ValueMax']['msg']}
</p>
</div>
@ -209,7 +203,7 @@
{* Password *}
<div class="form-group">
<label for="poll_id" class="col-sm-4 control-label">
<label for="use_password" class="col-sm-4 control-label">
{__('Step 1', 'Poll password')}
</label>
@ -263,7 +257,7 @@
</div>
<div class="form-group">
<label for="poll_id" class="col-sm-4 control-label">
<label class="col-sm-4 control-label">
{__('Step 1', 'Permissions')}
</label>
<div class="col-sm-8">