btcpayserver/BTCPayServer/wwwroot/main/site.js

82 lines
2.5 KiB
JavaScript
Raw Normal View History

$(function () {
$(".localizeDate").each(function (index) {
var serverDate = $(this).text();
var localDate = new Date(serverDate);
var dateString = localDate.toLocaleDateString() + " " + localDate.toLocaleTimeString();
$(this).text(dateString);
});
2019-01-14 22:43:29 +01:00
2019-05-12 00:13:16 +02:00
// intializing date time pickers throughts website
$(".flatdtpicker").each(function () {
var element = $(this);
2019-05-12 01:31:52 +02:00
var fdtp = element.attr("data-fdtp");
// support for initializing with special options per instance
if (fdtp) {
var parsed = JSON.parse(fdtp);
element.flatpickr(parsed);
} else {
var min = element.attr("min");
var max = element.attr("max");
var defaultDate = element.attr("value");
element.flatpickr({
enableTime: true,
enableSeconds: true,
dateFormat: 'Z',
altInput: true,
altFormat: 'Y-m-d H:i:S',
minDate: min,
maxDate: max,
defaultDate: defaultDate,
time_24hr: true,
defaultHour: 0,
parseDate: function (date) {
// check with Kukks if this is still needed with new date format
return moment(date).toDate();
}
});
}
});
2019-01-14 22:43:29 +01:00
$(".input-group-clear").on("click", function () {
2019-01-14 22:43:29 +01:00
$(this).parents(".input-group").find("input").val(null);
handleInputGroupClearButtonDisplay(this);
2019-01-14 22:43:29 +01:00
});
$(".input-group-clear").each(function () {
var inputGroupClearBtn = this;
handleInputGroupClearButtonDisplay(inputGroupClearBtn);
$(this).parents(".input-group").find("input").on("change input", function () {
handleInputGroupClearButtonDisplay(inputGroupClearBtn);
});
});
2019-01-14 22:43:29 +01:00
$(".only-for-js").show();
function handleInputGroupClearButtonDisplay(element) {
var inputs = $(element).parents(".input-group").find("input");
$(element).hide();
for (var i = 0; i < inputs.length; i++) {
var el = inputs.get(i);
if ($(el).val() || el.attributes.value) {
$(element).show();
break;
}
}
}
});
function switchTimeFormat() {
$(".switchTimeFormat").each(function (index) {
var htmlVal = $(this).html();
var switchVal = $(this).attr("data-switch");
$(this).html(switchVal);
$(this).attr("data-switch", htmlVal);
});
}