]> git.mxchange.org Git - friendica.git/blob - view/theme/frio/js/compose.js
Merge pull request #10093 from urbalazs/copyright-2021
[friendica.git] / view / theme / frio / js / compose.js
1 // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPLv3-or-later
2 $(function () {
3         // Jot attachment live preview.
4         let $textarea = $("textarea[name=body]");
5         $textarea.linkPreview();
6         $textarea.keyup(function () {
7                 var textlen = $(this).val().length;
8                 $("#character-counter").text(textlen);
9         });
10         $textarea.editor_autocomplete(baseurl + "/search/acl");
11         $textarea.bbco_autocomplete("bbcode");
12
13         let location_button = document.getElementById("profile-location");
14         let location_input = document.getElementById("jot-location");
15
16         if (location_button && location_input) {
17                 updateLocationButtonDisplay(location_button, location_input);
18
19                 location_input.addEventListener("change", function () {
20                         updateLocationButtonDisplay(location_button, location_input);
21                 });
22                 location_input.addEventListener("keyup", function () {
23                         updateLocationButtonDisplay(location_button, location_input);
24                 });
25
26                 location_button.addEventListener("click", function () {
27                         if (location_input.value) {
28                                 location_input.value = "";
29                                 updateLocationButtonDisplay(location_button, location_input);
30                         } else if ("geolocation" in navigator) {
31                                 navigator.geolocation.getCurrentPosition(
32                                         function (position) {
33                                                 location_input.value = position.coords.latitude + ", " + position.coords.longitude;
34                                                 updateLocationButtonDisplay(location_button, location_input);
35                                         },
36                                         function (error) {
37                                                 location_button.disabled = true;
38                                                 updateLocationButtonDisplay(location_button, location_input);
39                                         },
40                                 );
41                         }
42                 });
43         }
44 });
45
46 function updateLocationButtonDisplay(location_button, location_input) {
47         location_button.classList.remove("btn-primary");
48         if (location_input.value) {
49                 location_button.disabled = false;
50                 location_button.classList.add("btn-primary");
51                 location_button.title = location_button.dataset.titleClear;
52         } else if (!"geolocation" in navigator) {
53                 location_button.disabled = true;
54                 location_button.title = location_button.dataset.titleUnavailable;
55         } else if (location_button.disabled) {
56                 location_button.title = location_button.dataset.titleDisabled;
57         } else {
58                 location_button.title = location_button.dataset.titleSet;
59         }
60 }
61 // @license-end