Skip to content

Commit

Permalink
apply lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Oct 8, 2020
1 parent 3ea3972 commit f7dfd8b
Show file tree
Hide file tree
Showing 90 changed files with 3,361 additions and 3,311 deletions.
254 changes: 127 additions & 127 deletions assets/js/app/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,135 +2,135 @@ import $ from 'jquery';
import { DateTime } from 'luxon';

$(document).ready(function() {
// add a js class to indicate we have JS enabled. Might need a change to either modernizr or somethng comparable
$('html').addClass('js');

/*
** Sidebar collapse functionality
** Collapsible Sidebar on load
** The 'admin__sidebar--is-collapsed' class has effect up to screen sizes where the sidebar menu cannot be totally
** offscreen anymore
*/
$('.admin__sidebar').addClass('admin__sidebar--is-collapsed');

$('.admin-sidebar-toggler').on('click', function() {
if ($('.admin__sidebar').hasClass('admin__sidebar--is-collapsed')) {
$('.admin__sidebar')
.addClass('admin__sidebar--is-expanded')
.removeClass('admin__sidebar--is-collapsed');
$(this).toggleClass('is-active');
} else {
$('.admin__sidebar')
.addClass('admin__sidebar--is-collapsed')
.removeClass('admin__sidebar--is-expanded');
$(this).toggleClass('is-active');
// add a js class to indicate we have JS enabled. Might need a change to either modernizr or somethng comparable
$('html').addClass('js');

/*
** Sidebar collapse functionality
** Collapsible Sidebar on load
** The 'admin__sidebar--is-collapsed' class has effect up to screen sizes where the sidebar menu cannot be totally
** offscreen anymore
*/
$('.admin__sidebar').addClass('admin__sidebar--is-collapsed');

$('.admin-sidebar-toggler').on('click', function() {
if ($('.admin__sidebar').hasClass('admin__sidebar--is-collapsed')) {
$('.admin__sidebar')
.addClass('admin__sidebar--is-expanded')
.removeClass('admin__sidebar--is-collapsed');
$(this).toggleClass('is-active');
} else {
$('.admin__sidebar')
.addClass('admin__sidebar--is-collapsed')
.removeClass('admin__sidebar--is-expanded');
$(this).toggleClass('is-active');
}
});

/*
** Hash on tabs functionality
** When there is a Bootstrap data-toggle="pill" element, append the hash to the link
*/
let url = location.href.replace(/\/$/, '');
if (location.hash) {
const hash = url.split('#');
$('a[href="#' + hash[1] + '"]').tab('show');
url = location.href.replace(/\/#/, '#');
history.replaceState(null, null, url);
setTimeout(() => {
$(window).scrollTop(0);
}, 50);
}
});

/*
** Hash on tabs functionality
** When there is a Bootstrap data-toggle="pill" element, append the hash to the link
*/
let url = location.href.replace(/\/$/, '');
if (location.hash) {
const hash = url.split('#');
$('a[href="#' + hash[1] + '"]').tab('show');
url = location.href.replace(/\/#/, '#');
history.replaceState(null, null, url);
setTimeout(() => {
$(window).scrollTop(0);
}, 50);
}

$('a[data-toggle="pill"]').on('click', function() {
let newUrl;
const hash = $(this).attr('href');
newUrl = url.split('#')[0] + hash;
history.replaceState(null, null, newUrl);
});

/*
** Convert all ISO dates with class .datetime-relative to relative time
*/
$('.datetime-relative').each(function() {
$(this).text(DateTime.fromISO($(this).text()).toRelative());
});

/*
** Initialise all popover elements
*/
$('[data-toggle="popover"]').popover();

/*
** When a field from another group is invalid, show it.
*/
$('#editor button[type="submit"]').click(function() {
$('input:invalid').each(function() {
// Find the tab-pane that this element is inside, and get the id
var $closest = $(this).closest('.tab-pane');
var id = $closest.attr('id');

// Find the link that corresponds to the pane and have it show
$('.nav a[href="#' + id + '"]').tab('show');

// Only want to do it once
return false;

$('a[data-toggle="pill"]').on('click', function() {
let newUrl;
const hash = $(this).attr('href');
newUrl = url.split('#')[0] + hash;
history.replaceState(null, null, newUrl);
});

/*
** Convert all ISO dates with class .datetime-relative to relative time
*/
$('.datetime-relative').each(function() {
$(this).text(DateTime.fromISO($(this).text()).toRelative());
});

/*
** Initialise all popover elements
*/
$('[data-toggle="popover"]').popover();

/*
** When a field from another group is invalid, show it.
*/
$('#editor button[type="submit"]').click(function() {
$('input:invalid').each(function() {
// Find the tab-pane that this element is inside, and get the id
var $closest = $(this).closest('.tab-pane');
var id = $closest.attr('id');

// Find the link that corresponds to the pane and have it show
$('.nav a[href="#' + id + '"]').tab('show');

// Only want to do it once
return false;
});
});

/*
** Simulates disabled behavior for elements with data-readonly attribute.
* This is needed, because a disabled input cannot be required.
*/
$('[data-readonly]').on('keydown paste', function(e) {
e.preventDefault();
});
});

/*
** Simulates disabled behavior for elements with data-readonly attribute.
* This is needed, because a disabled input cannot be required.
*/
$('[data-readonly]').on('keydown paste', function(e) {
e.preventDefault();
});
/* Part of the code above, however make sure flatpickr is not readonly
* and that its validation works.
*/
$('.editor--date')
.siblings()
.prop('readonly', false)
.attr('data-readonly', 'readonly');
$('.editor--date').on('change', e => {
const target = $(e.target)
.parent()
.find('input[data-readonly="readonly"]');
if (target.val()) {
target[0].setCustomValidity('');
} else {
target[0].setCustomValidity('Please fill out this field.');
/* Part of the code above, however make sure flatpickr is not readonly
* and that its validation works.
*/
$('.editor--date')
.siblings()
.prop('readonly', false)
.attr('data-readonly', 'readonly');
$('.editor--date').on('change', e => {
const target = $(e.target)
.parent()
.find('input[data-readonly="readonly"]');
if (target.val()) {
target[0].setCustomValidity('');
} else {
target[0].setCustomValidity('Please fill out this field.');
}
});

/*
** Display the custom error message, if set.
*/
function handleInvalid(event) {
const errormessage = $(event.target).attr('data-errormessage');
event.target.setCustomValidity(errormessage);
}

function handleInput(event) {
event.target.setCustomValidity('');
}
});

/*
** Display the custom error message, if set.
*/
function handleInvalid(event) {
const errormessage = $(event.target).attr('data-errormessage');
event.target.setCustomValidity(errormessage);
}

function handleInput(event) {
event.target.setCustomValidity('');
}

$('[data-errormessage]').on('invalid', handleInvalid);

/* Remove custom validity every time input is changed. This is done because setCustomValidity does not reset */
$('[data-errormessage]').on('input', handleInput);

/* Set the errormessage on the correct editor--date field */
$('.editor--date').each(function() {
let siblings = $(this).siblings();
const errormessage = $(this).attr('data-errormessage');

siblings.each(function() {
$(this)
.attr('data-errormessage', errormessage)
.on('invalid', handleInvalid)
.on('input', handleInput);

$('[data-errormessage]').on('invalid', handleInvalid);

/* Remove custom validity every time input is changed. This is done because setCustomValidity does not reset */
$('[data-errormessage]').on('input', handleInput);

/* Set the errormessage on the correct editor--date field */
$('.editor--date').each(function() {
let siblings = $(this).siblings();
const errormessage = $(this).attr('data-errormessage');

siblings.each(function() {
$(this)
.attr('data-errormessage', errormessage)
.on('invalid', handleInvalid)
.on('input', handleInput);
});
});
});
/* End of custom error message */
/* End of custom error message */
});
40 changes: 20 additions & 20 deletions assets/js/app/confirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@ import bootbox from 'bootbox';
import $ from 'jquery';

let bootboxDefaults = {
locale: 'en',
locale: 'en',
};

bootbox.setDefaults(bootboxDefaults);

let locale = $('html').attr('lang');

if (locale) {
bootbox.setLocale(locale);
bootbox.setLocale(locale);
}

$('*[data-confirmation]').on('click', function() {
const thisElem = $(this);
const thisHref = $(this).attr('href');
const confirmation = $(this).data('confirmation');

if (!thisElem.data('confirmed')) {
bootbox.confirm(confirmation, function(result) {
if (result && thisHref) {
window.location = thisHref;
}

if (result) {
thisElem.attr('data-confirmed', true);
thisElem.click();
}
});

return false;
}
const thisElem = $(this);
const thisHref = $(this).attr('href');
const confirmation = $(this).data('confirmation');

if (!thisElem.data('confirmed')) {
bootbox.confirm(confirmation, function(result) {
if (result && thisHref) {
window.location = thisHref;
}

if (result) {
thisElem.attr('data-confirmed', true);
thisElem.click();
}
});

return false;
}
});
Loading

0 comments on commit f7dfd8b

Please sign in to comment.