Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
single_datetime
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
single_datetime
Commits
a7453a2c
Commit
a7453a2c
authored
11 months ago
by
Ide Braakman
Committed by
João Ventura
11 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3459996
by idebr, deepak5423, jcnventura: Fix eslint validation
parent
545f9192
Branches
Branches containing commit
No related tags found
1 merge request
!13
Issue #3459996: Fix eslint validation
Pipeline
#260033
passed with warnings
11 months ago
Stage: build
Stage: validate
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
js/drupal.single_datetime.js
+105
-99
105 additions, 99 deletions
js/drupal.single_datetime.js
with
105 additions
and
99 deletions
js/drupal.single_datetime.js
+
105
−
99
View file @
a7453a2c
...
...
@@ -16,32 +16,32 @@
* Return minutes formatted in array by allowed intervals.
*/
function
SingleDatetimeAllowTimes
(
$hours
,
$type
)
{
var
times
=
[];
const
times
=
[];
// Build array.
$hours
.
forEach
(
function
(
i
)
{
// Formatting hours.
if
(
i
<
10
)
{
i
=
"
0
"
+
i
;
i
=
`0
${
i
}
`
;
}
// Default granularity is one hour.
if
(
$type
===
60
)
{
times
.
push
(
i
+
"
:00
"
);
times
.
push
(
`
${
i
}
:00
`
);
}
// Custom settings, per minutes.
else
{
var
measure
=
60
/
$type
;
for
(
var
j
=
0
;
j
<
measure
;
j
++
)
{
var
minutes
=
$type
*
j
;
const
measure
=
60
/
$type
;
for
(
let
j
=
0
;
j
<
measure
;
j
++
)
{
let
minutes
=
$type
*
j
;
if
(
j
===
0
)
{
minutes
=
"
00
"
;
minutes
=
'
00
'
;
}
else
if
(
minutes
<
10
)
{
minutes
=
"
0
"
+
minutes
;
minutes
=
`0
${
minutes
}
`
;
}
times
.
push
(
i
+
"
:
"
+
minutes
);
times
.
push
(
`
${
i
}
:
${
minutes
}
`
);
}
}
});
...
...
@@ -56,101 +56,106 @@
*/
Drupal
.
behaviors
.
single_datetime
=
{
attach
:
function
attach
(
context
)
{
// Setting the current language for the calendar.
var
lang
=
drupalSettings
.
path
.
currentLanguage
;
let
lang
=
drupalSettings
.
path
.
currentLanguage
;
$
(
once
(
'
datePicker
'
,
'
input[data-single-date-time]
'
,
context
)).
each
(
function
()
{
var
input
=
$
(
this
);
$
(
once
(
'
datePicker
'
,
'
input[data-single-date-time]
'
,
context
)).
each
(
function
()
{
const
input
=
$
(
this
);
// Get widget type.
var
widgetType
=
input
.
data
(
"
singleDateTime
"
);
const
widgetType
=
input
.
data
(
'
singleDateTime
'
);
// Get hour format - 12 or 24.
var
hourFormat
=
input
.
data
(
"
hourFormat
"
);
const
hourFormat
=
input
.
data
(
'
hourFormat
'
);
// Get first day in week from Drupal.
var
dayOfWeekStart
=
input
.
data
(
"
firstDay
"
);
const
dayOfWeekStart
=
input
.
data
(
'
firstDay
'
);
// Default values (used for dates only).
var
format
=
"
Y-m-d
"
;
var
allowTimepicker
=
false
;
let
format
=
'
Y-m-d
'
;
let
allowTimepicker
=
false
;
// Get disabled days.
var
disabledWeekDays
=
input
.
data
(
"
disableDays
"
);
const
disabledWeekDays
=
input
.
data
(
'
disableDays
'
);
// Get excluded dates.
var
disabledDates
=
input
.
data
(
"
excludeDate
"
);
const
disabledDates
=
input
.
data
(
'
excludeDate
'
);
// Get start date.
var
startDate
=
input
.
data
(
"
startDate
"
);
const
startDate
=
input
.
data
(
'
startDate
'
);
// Get minimum date.
var
minDate
=
input
.
data
(
"
minDate
"
);
const
minDate
=
input
.
data
(
'
minDate
'
);
// Get maximum date.
var
maxDate
=
input
.
data
(
"
maxDate
"
);
const
maxDate
=
input
.
data
(
'
maxDate
'
);
// Get start year.
var
yearStart
=
input
.
data
(
"
yearStart
"
);
const
yearStart
=
input
.
data
(
'
yearStart
'
);
// Get end year.
var
yearEnd
=
input
.
data
(
"
yearEnd
"
);
const
yearEnd
=
input
.
data
(
'
yearEnd
'
);
// Set the hour format.
var
formatTime
=
hourFormat
===
"
12h
"
?
"
h:i A
"
:
"
H:i
"
;
const
formatTime
=
hourFormat
===
'
12h
'
?
'
h:i A
'
:
'
H:i
'
;
var
customFormat
=
input
.
data
(
'
customFormat
'
);
const
customFormat
=
input
.
data
(
'
customFormat
'
);
var
inline
=
input
.
data
(
"
inline
"
);
const
inline
=
input
.
data
(
'
inline
'
);
var
allowSeconds
=
Boolean
(
input
.
data
(
"
allowSeconds
"
));
const
allowSeconds
=
Boolean
(
input
.
data
(
'
allowSeconds
'
));
var
mask
=
Boolean
(
input
.
data
(
"
mask
"
));
const
mask
=
Boolean
(
input
.
data
(
'
mask
'
));
var
theme
=
input
.
data
(
"
datetimepickerTheme
"
);
const
theme
=
input
.
data
(
'
datetimepickerTheme
'
);
var
allowBlank
=
Boolean
(
input
.
data
(
"
allowBlank
"
));
const
allowBlank
=
Boolean
(
input
.
data
(
'
allowBlank
'
));
// Default empty array. Only calculate later if field type
// includes times.
var
allowTimes
=
[];
let
allowTimes
=
[];
// If is date & time field.
if
(
widgetType
===
"
datetime
"
)
{
var
hourFormatDefault
=
allowSeconds
===
true
?
"
Y-m-d H:i:00
"
:
"
Y-m-d H:i:s
"
;
var
hourFormatA
=
allowSeconds
===
true
?
"
Y-m-d h:i:00 A
"
:
"
Y-m-d h:i:s A
"
;
format
=
hourFormat
===
"
12h
"
?
hourFormatA
:
hourFormatDefault
;
if
(
widgetType
===
'
datetime
'
)
{
const
hourFormatDefault
=
allowSeconds
===
true
?
'
Y-m-d H:i:00
'
:
'
Y-m-d H:i:s
'
;
const
hourFormatA
=
allowSeconds
===
true
?
'
Y-m-d h:i:00 A
'
:
'
Y-m-d h:i:s A
'
;
format
=
hourFormat
===
'
12h
'
?
hourFormatA
:
hourFormatDefault
;
allowTimepicker
=
true
;
// Get minute granularity, and allowed hours.
allowTimes
=
SingleDatetimeAllowTimes
(
input
.
data
(
"
allowedHours
"
),
input
.
data
(
"
allowTimes
"
));
allowTimes
=
SingleDatetimeAllowTimes
(
input
.
data
(
'
allowedHours
'
),
input
.
data
(
'
allowTimes
'
),
);
}
if
(
typeof
customFormat
!==
'
undefined
'
)
{
format
=
customFormat
;
}
$
(
"
#
"
+
input
.
attr
(
"
id
"
)
).
datetimepicker
({
format
:
format
,
formatTime
:
formatTime
,
$
(
`#
${
input
.
attr
(
'
id
'
)}
`
).
datetimepicker
({
format
,
formatTime
,
lazyInit
:
true
,
timepicker
:
allowTimepicker
,
todayButton
:
true
,
dayOfWeekStart
:
dayOfWeekStart
,
allowTimes
:
allowTimes
,
disabledWeekDays
:
disabledWeekDays
,
disabledDates
:
disabledDates
,
formatDate
:
"
d.m.Y
"
,
inline
:
inline
,
mask
:
mask
,
startDate
:
startDate
,
minDate
:
minDate
,
maxDate
:
maxDate
,
yearStart
:
yearStart
,
yearEnd
:
yearEnd
,
theme
:
theme
,
allowBlank
:
allowBlank
dayOfWeekStart
,
allowTimes
,
disabledWeekDays
,
disabledDates
,
formatDate
:
'
d.m.Y
'
,
inline
,
mask
,
startDate
,
minDate
,
maxDate
,
yearStart
,
yearEnd
,
theme
,
allowBlank
,
});
if
(
lang
===
'
pt-br
'
)
{
...
...
@@ -168,7 +173,8 @@
// Explicitly set locale. Does not work with passed variable
// in settings above.
$
.
datetimepicker
.
setLocale
(
lang
);
});
}
},
);
},
};
})(
jQuery
,
Drupal
,
drupalSettings
,
once
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment