mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-20 10:40:29 +01:00
104 lines
3.2 KiB
JavaScript
104 lines
3.2 KiB
JavaScript
$(function () {
|
|
// initialize timezone offset value if field is present in page
|
|
var timezoneOffset = new Date().getTimezoneOffset();
|
|
$("#TimezoneOffset").val(timezoneOffset);
|
|
|
|
// localize all elements that have localizeDate class
|
|
$(".localizeDate").each(function (index) {
|
|
var serverDate = $(this).text();
|
|
var localDate = new Date(serverDate);
|
|
|
|
var dateString = localDate.toLocaleDateString() + " " + localDate.toLocaleTimeString();
|
|
$(this).text(dateString);
|
|
});
|
|
|
|
|
|
function updateTimeAgo(){
|
|
var timeagoElements = $("[data-timeago-unixms]");
|
|
timeagoElements.each(function () {
|
|
var elem = $(this);
|
|
elem.text(moment(elem.data("timeago-unixms")).fromNow());
|
|
});
|
|
setTimeout(updateTimeAgo, 1000);
|
|
}
|
|
updateTimeAgo();
|
|
|
|
// intializing date time pickers throughts website
|
|
$(".flatdtpicker").each(function () {
|
|
var element = $(this);
|
|
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
|
|
});
|
|
}
|
|
});
|
|
|
|
|
|
$(".input-group-clear").on("click", function () {
|
|
$(this).parents(".input-group").find("input").val(null);
|
|
handleInputGroupClearButtonDisplay(this);
|
|
});
|
|
|
|
$(".input-group-clear").each(function () {
|
|
var inputGroupClearBtn = this;
|
|
handleInputGroupClearButtonDisplay(inputGroupClearBtn);
|
|
$(this).parents(".input-group").find("input").on("change input", function () {
|
|
handleInputGroupClearButtonDisplay(inputGroupClearBtn);
|
|
});
|
|
});
|
|
|
|
$('[data-toggle="tooltip"]').tooltip();
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
$('[data-clipboard]').on('click', function (e) {
|
|
if (navigator.clipboard) {
|
|
e.preventDefault();
|
|
var item = e.currentTarget;
|
|
var text = item.getAttribute('data-clipboard');
|
|
navigator.clipboard.writeText(text);
|
|
item.blur();
|
|
}
|
|
});
|
|
|
|
});
|
|
|
|
function switchTimeFormat() {
|
|
$(".switchTimeFormat").each(function (index) {
|
|
var htmlVal = $(this).html();
|
|
var switchVal = $(this).attr("data-switch");
|
|
|
|
$(this).html(switchVal);
|
|
$(this).attr("data-switch", htmlVal);
|
|
});
|
|
}
|