1 <script type="text/javascript">
2 function updateLocationButtonDisplay(location_button, location_input)
4 location_button.classList.remove('btn-primary');
5 if (location_input.value) {
6 location_button.disabled = false;
7 location_button.classList.add('btn-primary');
8 location_button.title = location_button.dataset.titleClear;
9 } else if (!"geolocation" in navigator) {
10 location_button.disabled = true;
11 location_button.title = location_button.dataset.titleUnavailable;
12 } else if (location_button.disabled) {
13 location_button.title = location_button.dataset.titleDisabled;
15 location_button.title = location_button.dataset.titleSet;
20 // Jot attachment live preview.
21 let $textarea = $('#comment-edit-text-0');
22 $textarea.linkPreview();
23 $textarea.keyup(function(){
24 var textlen = $(this).val().length;
25 $('#character-counter').text(textlen);
27 $textarea.editor_autocomplete(baseurl+"/acl");
28 $textarea.bbco_autocomplete('bbcode');
30 let $acl_allow_input = $('#acl_allow');
31 let $group_allow_input = $('[name=group_allow]');
32 let $contact_allow_input = $('[name=contact_allow]');
33 let $acl_deny_input = $('#acl_deny');
34 let $group_deny_input = $('[name=group_deny]');
35 let $contact_deny_input = $('[name=contact_deny]');
37 // Visibility accordion
39 // Prevents open panel to collapse
40 // @see https://stackoverflow.com/a/43593116
41 $('[data-toggle="collapse"]').click(function(e) {
42 target = $(this).attr('href');
43 if ($(target).hasClass('in')) {
44 e.preventDefault(); // to stop the page jump to the anchor target.
49 $('#visibility-public-panel').on('show.bs.collapse', function() {
50 $('#visibility-public').prop('checked', true);
51 $group_allow_input.prop('disabled', true);
52 $contact_allow_input.prop('disabled', true);
53 $group_deny_input.prop('disabled', true);
54 $contact_deny_input.prop('disabled', true);
57 $('#visibility-custom-panel').on('show.bs.collapse', function() {
58 $('#visibility-custom').prop('checked', true);
59 $group_allow_input.prop('disabled', false);
60 $contact_allow_input.prop('disabled', false);
61 $group_deny_input.prop('disabled', false);
62 $contact_deny_input.prop('disabled', false);
65 if (document.querySelector('input[name="visibility"]:checked').value === 'custom') {
66 $('#visibility-custom-panel').collapse({parent: '#visibility-accordion'});
69 // Custom visibility tags inputs
71 let acl_groups = new Bloodhound({
72 local: {{$acl_groups|@json_encode nofilter}},
73 identify: function(obj) { return obj.id; },
74 datumTokenizer: Bloodhound.tokenizers.obj.whitespace(['name']),
75 queryTokenizer: Bloodhound.tokenizers.whitespace,
77 let acl_contacts = new Bloodhound({
78 local: {{$acl_contacts|@json_encode nofilter}},
79 identify: function(obj) { return obj.id; },
80 datumTokenizer: Bloodhound.tokenizers.obj.whitespace(['name', 'addr']),
81 queryTokenizer: Bloodhound.tokenizers.whitespace,
83 let acl = new Bloodhound({
84 local: {{$acl|@json_encode nofilter}},
85 identify: function(obj) { return obj.id; },
86 datumTokenizer: Bloodhound.tokenizers.obj.whitespace(['name', 'addr']),
87 queryTokenizer: Bloodhound.tokenizers.whitespace,
91 let suggestionTemplate = function (item) {
92 return '<div><img src="' + item.micro + '" alt="" style="float: left; width: auto; height: 2.8em; margin-right: 0.5em;"> <strong>' + item.name + '</strong><br /><em>' + item.addr + '</em></div>';
95 $acl_allow_input.tagsinput({
96 confirmKeys: [13, 44],
97 cancelConfirmKeysOnEmpty: true,
99 tagClass: function(item) {
101 case 'group' : return 'label label-primary';
104 return 'label label-info';
110 itemTitle: function(item) {
117 suggestion: suggestionTemplate
119 source: acl.ttAdapter()
125 confirmKeys: [13, 44],
127 tagClass: function(item) {
129 case 'group' : return 'label label-primary';
132 return 'label label-info';
138 itemTitle: function(item) {
145 suggestion: suggestionTemplate
147 source: acl.ttAdapter()
151 // Import existing ACL into the tags input fields.
153 $group_allow_input.val().split(',').forEach(function (val) {
154 $acl_allow_input.tagsinput('add', acl_groups.get(val)[0]);
156 $contact_allow_input.val().split(',').forEach(function (val) {
157 $acl_allow_input.tagsinput('add', acl_contacts.get(val)[0]);
159 $group_deny_input.val().split(',').forEach(function (val) {
160 $acl_deny_input.tagsinput('add', acl_groups.get(val)[0]);
162 $contact_deny_input.val().split(',').forEach(function (val) {
163 $acl_deny_input.tagsinput('add', acl_contacts.get(val)[0]);
166 // Anti-duplicate callback + acl fields value generation
168 $acl_allow_input.on('itemAdded', function (event) {
169 // Removes duplicate in the opposite acl box
170 $acl_deny_input.tagsinput('remove', event.item);
172 // Update the real acl field
173 $group_allow_input.val('');
174 $contact_allow_input.val('');
175 [].forEach.call($acl_allow_input.tagsinput('items'), function (item) {
176 if (item.type === 'group') {
177 $group_allow_input.val($group_allow_input.val() + '<' + item.id + '>');
179 $contact_allow_input.val($contact_allow_input.val() + '<' + item.id + '>');
184 $acl_deny_input.on('itemAdded', function (event) {
185 // Removes duplicate in the opposite acl box
186 $acl_allow_input.tagsinput('remove', event.item);
188 // Update the real acl field
189 $group_deny_input.val('');
190 $contact_deny_input.val('');
191 [].forEach.call($acl_deny_input.tagsinput('items'), function (item) {
192 if (item.type === 'group') {
193 $group_deny_input.val($group_allow_input.val() + '<' + item.id + '>');
195 $contact_deny_input.val($contact_allow_input.val() + '<' + item.id + '>');
200 let location_button = document.getElementById('profile-location');
201 let location_input = document.getElementById('jot-location');
203 updateLocationButtonDisplay(location_button, location_input);
205 location_input.addEventListener('change', function () {
206 updateLocationButtonDisplay(location_button, location_input);
208 location_input.addEventListener('keyup', function () {
209 updateLocationButtonDisplay(location_button, location_input);
212 location_button.addEventListener('click', function() {
213 if (location_input.value) {
214 location_input.value = '';
215 updateLocationButtonDisplay(location_button, location_input);
216 } else if ("geolocation" in navigator) {
217 navigator.geolocation.getCurrentPosition(function(position) {
218 location_input.value = position.coords.latitude + ', ' + position.coords.longitude;
219 updateLocationButtonDisplay(location_button, location_input);
220 }, function (error) {
221 location_button.disabled = true;
222 updateLocationButtonDisplay(location_button, location_input);