2020-09-27 12:36:33 -04:00
|
|
|
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPLv3-or-later
|
2021-01-22 08:38:44 -05:00
|
|
|
$(function () {
|
2019-11-28 12:53:12 -05:00
|
|
|
// Jot attachment live preview.
|
2021-01-22 08:38:44 -05:00
|
|
|
let $textarea = $("textarea[name=body]");
|
2019-11-28 12:53:12 -05:00
|
|
|
$textarea.linkPreview();
|
2021-01-22 08:38:44 -05:00
|
|
|
$textarea.keyup(function () {
|
2019-11-28 12:53:12 -05:00
|
|
|
var textlen = $(this).val().length;
|
2021-01-22 08:38:44 -05:00
|
|
|
$("#character-counter").text(textlen);
|
2019-11-28 12:53:12 -05:00
|
|
|
});
|
2021-01-22 08:38:44 -05:00
|
|
|
$textarea.editor_autocomplete(baseurl + "/search/acl");
|
|
|
|
$textarea.bbco_autocomplete("bbcode");
|
2019-11-28 12:53:12 -05:00
|
|
|
|
2021-01-22 08:38:44 -05:00
|
|
|
let location_button = document.getElementById("profile-location");
|
|
|
|
let location_input = document.getElementById("jot-location");
|
2019-11-28 12:53:12 -05:00
|
|
|
|
|
|
|
if (location_button && location_input) {
|
|
|
|
updateLocationButtonDisplay(location_button, location_input);
|
|
|
|
|
2021-01-22 08:38:44 -05:00
|
|
|
location_input.addEventListener("change", function () {
|
2019-11-28 12:53:12 -05:00
|
|
|
updateLocationButtonDisplay(location_button, location_input);
|
|
|
|
});
|
2021-01-22 08:38:44 -05:00
|
|
|
location_input.addEventListener("keyup", function () {
|
2019-11-28 12:53:12 -05:00
|
|
|
updateLocationButtonDisplay(location_button, location_input);
|
|
|
|
});
|
|
|
|
|
2021-01-22 08:38:44 -05:00
|
|
|
location_button.addEventListener("click", function () {
|
2019-11-28 12:53:12 -05:00
|
|
|
if (location_input.value) {
|
2021-01-22 08:38:44 -05:00
|
|
|
location_input.value = "";
|
2019-11-28 12:53:12 -05:00
|
|
|
updateLocationButtonDisplay(location_button, location_input);
|
|
|
|
} else if ("geolocation" in navigator) {
|
2021-01-22 08:38:44 -05:00
|
|
|
navigator.geolocation.getCurrentPosition(
|
|
|
|
function (position) {
|
|
|
|
location_input.value = position.coords.latitude + ", " + position.coords.longitude;
|
|
|
|
updateLocationButtonDisplay(location_button, location_input);
|
|
|
|
},
|
|
|
|
function (error) {
|
|
|
|
location_button.disabled = true;
|
|
|
|
updateLocationButtonDisplay(location_button, location_input);
|
|
|
|
},
|
|
|
|
);
|
2019-11-28 12:53:12 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-01-22 08:38:44 -05:00
|
|
|
function updateLocationButtonDisplay(location_button, location_input) {
|
|
|
|
location_button.classList.remove("btn-primary");
|
2019-11-28 12:53:12 -05:00
|
|
|
if (location_input.value) {
|
|
|
|
location_button.disabled = false;
|
2021-01-22 08:38:44 -05:00
|
|
|
location_button.classList.add("btn-primary");
|
2019-11-28 12:53:12 -05:00
|
|
|
location_button.title = location_button.dataset.titleClear;
|
|
|
|
} else if (!"geolocation" in navigator) {
|
|
|
|
location_button.disabled = true;
|
|
|
|
location_button.title = location_button.dataset.titleUnavailable;
|
|
|
|
} else if (location_button.disabled) {
|
|
|
|
location_button.title = location_button.dataset.titleDisabled;
|
|
|
|
} else {
|
|
|
|
location_button.title = location_button.dataset.titleSet;
|
|
|
|
}
|
|
|
|
}
|
2020-09-27 12:36:33 -04:00
|
|
|
// @license-end
|