friendica_2021.01_tupambae_.../view/theme/frio/js/compose.js

62 lines
2.2 KiB
JavaScript
Raw Normal View History

// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPLv3-or-later
2021-01-22 14:38:44 +01:00
$(function () {
// Jot attachment live preview.
2021-01-22 14:38:44 +01:00
let $textarea = $("textarea[name=body]");
$textarea.linkPreview();
2021-01-22 14:38:44 +01:00
$textarea.keyup(function () {
var textlen = $(this).val().length;
2021-01-22 14:38:44 +01:00
$("#character-counter").text(textlen);
});
2021-01-22 14:38:44 +01:00
$textarea.editor_autocomplete(baseurl + "/search/acl");
$textarea.bbco_autocomplete("bbcode");
2021-01-22 14:38:44 +01:00
let location_button = document.getElementById("profile-location");
let location_input = document.getElementById("jot-location");
if (location_button && location_input) {
updateLocationButtonDisplay(location_button, location_input);
2021-01-22 14:38:44 +01:00
location_input.addEventListener("change", function () {
updateLocationButtonDisplay(location_button, location_input);
});
2021-01-22 14:38:44 +01:00
location_input.addEventListener("keyup", function () {
updateLocationButtonDisplay(location_button, location_input);
});
2021-01-22 14:38:44 +01:00
location_button.addEventListener("click", function () {
if (location_input.value) {
2021-01-22 14:38:44 +01:00
location_input.value = "";
updateLocationButtonDisplay(location_button, location_input);
} else if ("geolocation" in navigator) {
2021-01-22 14:38:44 +01: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);
},
);
}
});
}
});
2021-01-22 14:38:44 +01:00
function updateLocationButtonDisplay(location_button, location_input) {
location_button.classList.remove("btn-primary");
if (location_input.value) {
location_button.disabled = false;
2021-01-22 14:38:44 +01:00
location_button.classList.add("btn-primary");
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;
}
}
// @license-end