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