javascript improvements
use `const` instead of `var`/`let` use `$(function () { ... })` instead of `$(document).ready(function () { ... })` unify codestyle
This commit is contained in:
parent
887add83f6
commit
23d7e8632b
|
@ -39,11 +39,11 @@ function form_spinner($name, $label, $value)
|
||||||
</div>
|
</div>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(\'#spinner-' . $name . '-down\').click(function () {
|
$(\'#spinner-' . $name . '-down\').click(function () {
|
||||||
let spinner = $(\'#spinner-' . $name . '\');
|
const spinner = $(\'#spinner-' . $name . '\');
|
||||||
spinner.val(parseInt(spinner.val()) - 1);
|
spinner.val(parseInt(spinner.val()) - 1);
|
||||||
});
|
});
|
||||||
$(\'#spinner-' . $name . '-up\').click(function () {
|
$(\'#spinner-' . $name . '-up\').click(function () {
|
||||||
let spinner = $(\'#spinner-' . $name . '\');
|
const spinner = $(\'#spinner-' . $name . '\');
|
||||||
spinner.val(parseInt(spinner.val()) + 1);
|
spinner.val(parseInt(spinner.val()) + 1);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -54,7 +54,7 @@ function UserDriverLicense_edit_view($user_source, $user_driver_license)
|
||||||
'
|
'
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function () {
|
$(function () {
|
||||||
let checkbox = $(\'#wants_to_drive\');
|
const checkbox = $(\'#wants_to_drive\');
|
||||||
if (checkbox.is(\':checked\'))
|
if (checkbox.is(\':checked\'))
|
||||||
$(\'#driving_license\').show();
|
$(\'#driving_license\').show();
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,35 +1,35 @@
|
||||||
const lang = document.documentElement.getAttribute('lang');
|
const lang = document.documentElement.getAttribute('lang');
|
||||||
|
|
||||||
const templateFuture = 'in %value %unit';
|
const templateFuture = 'in %value %unit';
|
||||||
const templatePast = lang === "en"
|
const templatePast = lang === 'en'
|
||||||
? '%value %unit ago'
|
? '%value %unit ago'
|
||||||
: 'vor %value %unit';
|
: 'vor %value %unit';
|
||||||
|
|
||||||
const yearUnits = lang === "en"
|
const yearUnits = lang === 'en'
|
||||||
? ["year", "years"]
|
? ['year', 'years']
|
||||||
: ["Jahr", "Jahren"];
|
: ['Jahr', 'Jahren'];
|
||||||
|
|
||||||
const monthUnits = lang === "en"
|
const monthUnits = lang === 'en'
|
||||||
? ["month", "months"]
|
? ['month', 'months']
|
||||||
: ["Monat", "Monaten"];
|
: ['Monat', 'Monaten'];
|
||||||
|
|
||||||
const dayUnits = lang === "en"
|
const dayUnits = lang === 'en'
|
||||||
? ["day", "days"]
|
? ['day', 'days']
|
||||||
: ["Tag", "Tagen"];
|
: ['Tag', 'Tagen'];
|
||||||
|
|
||||||
const hourUnits = lang === "en"
|
const hourUnits = lang === 'en'
|
||||||
? ["hour", "hours"]
|
? ['hour', 'hours']
|
||||||
: ["Stunde", "Stunden"];
|
: ['Stunde', 'Stunden'];
|
||||||
|
|
||||||
const minuteUnits = lang === "en"
|
const minuteUnits = lang === 'en'
|
||||||
? ["minute", "minutes"]
|
? ['minute', 'minutes']
|
||||||
: ["Minute", "Minuten"];
|
: ['Minute', 'Minuten'];
|
||||||
|
|
||||||
const secondUnits = lang === "en"
|
const secondUnits = lang === 'en'
|
||||||
? ["second", "seconds"]
|
? ['second', 'seconds']
|
||||||
: ["Sekunde", "Sekunden"];
|
: ['Sekunde', 'Sekunden'];
|
||||||
|
|
||||||
const nowString = lang === "en" ? "now" : "jetzt";
|
const nowString = lang === 'en' ? 'now' : 'jetzt';
|
||||||
|
|
||||||
const secondsHour = 60 * 60;
|
const secondsHour = 60 * 60;
|
||||||
|
|
||||||
|
@ -56,8 +56,8 @@ function formatFromNow(timestamp) {
|
||||||
const template = ago ? templatePast : templateFuture;
|
const template = ago ? templatePast : templateFuture;
|
||||||
const unit = value === 1 ? singular : plural;
|
const unit = value === 1 ? singular : plural;
|
||||||
return template
|
return template
|
||||||
.replace("%value", value)
|
.replace('%value', value)
|
||||||
.replace("%unit", unit);
|
.replace('%unit', unit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,11 +67,11 @@ function formatFromNow(timestamp) {
|
||||||
/**
|
/**
|
||||||
* Initialises all countdown fields on the page.
|
* Initialises all countdown fields on the page.
|
||||||
*/
|
*/
|
||||||
$(document).ready(function () {
|
$(function () {
|
||||||
$.each($('[data-countdown-ts]'), function (i, e) {
|
$.each($('[data-countdown-ts]'), function (i, e) {
|
||||||
var span = $(e);
|
const span = $(e);
|
||||||
const timestamp = span.data("countdown-ts");
|
const timestamp = span.data('countdown-ts');
|
||||||
var text = span.html();
|
const text = span.html();
|
||||||
span.html(text.replace('%c', formatFromNow(timestamp)));
|
span.html(text.replace('%c', formatFromNow(timestamp)));
|
||||||
setInterval(function () {
|
setInterval(function () {
|
||||||
span.html(text.replace('%c', formatFromNow(timestamp)));
|
span.html(text.replace('%c', formatFromNow(timestamp)));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
require('select2')
|
require('select2');
|
||||||
import { formatDay, formatTime } from "./date";
|
import { formatDay, formatTime } from './date';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets all checkboxes to the wanted state
|
* Sets all checkboxes to the wanted state
|
||||||
|
@ -42,7 +42,7 @@ global.setInput = (from, to) => {
|
||||||
const toTime = $('#end_time');
|
const toTime = $('#end_time');
|
||||||
|
|
||||||
if (!fromDay || !fromTime || !toDay || !toTime) {
|
if (!fromDay || !fromTime || !toDay || !toTime) {
|
||||||
console.warn("cannot set input date because of missing field");
|
console.warn('cannot set input date because of missing field');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,13 +56,13 @@ global.setInput = (from, to) => {
|
||||||
global.setDay = (days) => {
|
global.setDay = (days) => {
|
||||||
days = days || 0;
|
days = days || 0;
|
||||||
|
|
||||||
var from = new Date();
|
const from = new Date();
|
||||||
from.setHours(0, 0, 0, 0);
|
from.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
// add days, Date handles the overflow
|
// add days, Date handles the overflow
|
||||||
from.setDate(from.getDate() + days);
|
from.setDate(from.getDate() + days);
|
||||||
|
|
||||||
var to = new Date(from);
|
const to = new Date(from);
|
||||||
to.setHours(23, 59);
|
to.setHours(23, 59);
|
||||||
|
|
||||||
setInput(from, to);
|
setInput(from, to);
|
||||||
|
@ -71,8 +71,8 @@ global.setDay = (days) => {
|
||||||
global.setHours = (hours) => {
|
global.setHours = (hours) => {
|
||||||
hours = hours || 1;
|
hours = hours || 1;
|
||||||
|
|
||||||
var from = new Date();
|
const from = new Date();
|
||||||
var to = new Date(from);
|
const to = new Date(from);
|
||||||
|
|
||||||
// convert hours to add to milliseconds (60 minutes * 60 seconds * 1000 for milliseconds)
|
// convert hours to add to milliseconds (60 minutes * 60 seconds * 1000 for milliseconds)
|
||||||
const msToAdd = hours * 60 * 60 * 1000;
|
const msToAdd = hours * 60 * 60 * 1000;
|
||||||
|
@ -101,13 +101,13 @@ $(function () {
|
||||||
*/
|
*/
|
||||||
$(function () {
|
$(function () {
|
||||||
$('.input-group.time').each(function () {
|
$('.input-group.time').each(function () {
|
||||||
var elem = $(this);
|
const elem = $(this);
|
||||||
elem.find('button').on('click', function () {
|
elem.find('button').on('click', function () {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
var input = elem.children('input').first();
|
const input = elem.children('input').first();
|
||||||
input.val(formatTime(now));
|
input.val(formatTime(now));
|
||||||
var daySelector = $('#' + input.attr('id').replace('time', 'day'));
|
const daySelector = $('#' + input.attr('id').replace('time', 'day'));
|
||||||
var days = daySelector.children('option');
|
const days = daySelector.children('option');
|
||||||
const yyyyMMDD = formatDay(now);
|
const yyyyMMDD = formatDay(now);
|
||||||
days.each(function (i) {
|
days.each(function (i) {
|
||||||
if ($(days[i]).val() === yyyyMMDD) {
|
if ($(days[i]).val() === yyyyMMDD) {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
/**
|
/**
|
||||||
* Enables the fixed headers and time lane for the shift-calendar and datatables
|
* Enables the fixed headers and time lane for the shift-calendar and datatables
|
||||||
*/
|
*/
|
||||||
$(document).ready(function () {
|
$(function () {
|
||||||
if ($('.shift-calendar').length) {
|
if ($('.shift-calendar').length) {
|
||||||
var timeLanes = $('.shift-calendar .time');
|
const timeLanes = $('.shift-calendar .time');
|
||||||
var headers = $('.shift-calendar .header');
|
const headers = $('.shift-calendar .header');
|
||||||
var topReference = $('.container-fluid .row');
|
const topReference = $('.container-fluid .row');
|
||||||
timeLanes.css({
|
timeLanes.css({
|
||||||
'position': 'relative',
|
'position': 'relative',
|
||||||
'z-index': 999
|
'z-index': 999
|
||||||
|
@ -16,8 +16,8 @@ $(document).ready(function () {
|
||||||
});
|
});
|
||||||
$(window).scroll(
|
$(window).scroll(
|
||||||
function () {
|
function () {
|
||||||
var top = headers.parent().offset().top;
|
const top = headers.parent().offset().top;
|
||||||
var left = 15;
|
const left = 15;
|
||||||
timeLanes.css({
|
timeLanes.css({
|
||||||
'left': Math.max(0, $(window).scrollLeft() - left) + 'px'
|
'left': Math.max(0, $(window).scrollLeft() - left) + 'px'
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue