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);
56 $('.profile-jot-net input[type=checkbox]').each(function() {
57 // Restores checkbox state if it had been saved
58 if ($(this).attr('data-checked') !== undefined) {
59 $(this).prop('checked', $(this).attr('data-checked') === 'true');
62 $('.profile-jot-net input').attr('disabled', false);
65 $('#visibility-custom-panel').on('show.bs.collapse', function() {
66 $('#visibility-custom').prop('checked', true);
67 $group_allow_input.prop('disabled', false);
68 $contact_allow_input.prop('disabled', false);
69 $group_deny_input.prop('disabled', false);
70 $contact_deny_input.prop('disabled', false);
72 $('.profile-jot-net input[type=checkbox]').each(function() {
73 // Saves current checkbox state
75 .attr('data-checked', $(this).prop('checked'))
76 .prop('checked', false);
78 $('.profile-jot-net input').attr('disabled', 'disabled');
81 if (document.querySelector('input[name="visibility"]:checked').value === 'custom') {
82 $('#visibility-custom-panel').collapse({parent: '#visibility-accordion'});
85 // Custom visibility tags inputs
87 let acl_groups = new Bloodhound({
88 local: {{$acl_groups|@json_encode nofilter}},
89 identify: function(obj) { return obj.id; },
90 datumTokenizer: Bloodhound.tokenizers.obj.whitespace(['name']),
91 queryTokenizer: Bloodhound.tokenizers.whitespace,
93 let acl_contacts = new Bloodhound({
94 local: {{$acl_contacts|@json_encode nofilter}},
95 identify: function(obj) { return obj.id; },
96 datumTokenizer: Bloodhound.tokenizers.obj.whitespace(['name', 'addr']),
97 queryTokenizer: Bloodhound.tokenizers.whitespace,
99 let acl = new Bloodhound({
100 local: {{$acl|@json_encode nofilter}},
101 identify: function(obj) { return obj.id; },
102 datumTokenizer: Bloodhound.tokenizers.obj.whitespace(['name', 'addr']),
103 queryTokenizer: Bloodhound.tokenizers.whitespace,
107 let suggestionTemplate = function (item) {
108 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>';
111 $acl_allow_input.tagsinput({
112 confirmKeys: [13, 44],
113 cancelConfirmKeysOnEmpty: true,
115 tagClass: function(item) {
117 case 'group' : return 'label label-primary';
120 return 'label label-info';
126 itemTitle: function(item) {
133 suggestion: suggestionTemplate
135 source: acl.ttAdapter()
141 confirmKeys: [13, 44],
143 tagClass: function(item) {
145 case 'group' : return 'label label-primary';
148 return 'label label-info';
154 itemTitle: function(item) {
161 suggestion: suggestionTemplate
163 source: acl.ttAdapter()
167 // Import existing ACL into the tags input fields.
169 $group_allow_input.val().split(',').forEach(function (val) {
170 $acl_allow_input.tagsinput('add', acl_groups.get(val)[0]);
172 $contact_allow_input.val().split(',').forEach(function (val) {
173 $acl_allow_input.tagsinput('add', acl_contacts.get(val)[0]);
175 $group_deny_input.val().split(',').forEach(function (val) {
176 $acl_deny_input.tagsinput('add', acl_groups.get(val)[0]);
178 $contact_deny_input.val().split(',').forEach(function (val) {
179 $acl_deny_input.tagsinput('add', acl_contacts.get(val)[0]);
182 // Anti-duplicate callback + acl fields value generation
184 $acl_allow_input.on('itemAdded', function (event) {
185 // Removes duplicate in the opposite acl box
186 $acl_deny_input.tagsinput('remove', event.item);
188 // Update the real acl field
189 $group_allow_input.val('');
190 $contact_allow_input.val('');
191 [].forEach.call($acl_allow_input.tagsinput('items'), function (item) {
192 if (item.type === 'group') {
193 $group_allow_input.val($group_allow_input.val() + '<' + item.id + '>');
195 $contact_allow_input.val($contact_allow_input.val() + '<' + item.id + '>');
200 $acl_deny_input.on('itemAdded', function (event) {
201 // Removes duplicate in the opposite acl box
202 $acl_allow_input.tagsinput('remove', event.item);
204 // Update the real acl field
205 $group_deny_input.val('');
206 $contact_deny_input.val('');
207 [].forEach.call($acl_deny_input.tagsinput('items'), function (item) {
208 if (item.type === 'group') {
209 $group_deny_input.val($group_allow_input.val() + '<' + item.id + '>');
211 $contact_deny_input.val($contact_allow_input.val() + '<' + item.id + '>');
216 let location_button = document.getElementById('profile-location');
217 let location_input = document.getElementById('jot-location');
219 updateLocationButtonDisplay(location_button, location_input);
221 location_input.addEventListener('change', function () {
222 updateLocationButtonDisplay(location_button, location_input);
224 location_input.addEventListener('keyup', function () {
225 updateLocationButtonDisplay(location_button, location_input);
228 location_button.addEventListener('click', function() {
229 if (location_input.value) {
230 location_input.value = '';
231 updateLocationButtonDisplay(location_button, location_input);
232 } else if ("geolocation" in navigator) {
233 navigator.geolocation.getCurrentPosition(function(position) {
234 location_input.value = position.coords.latitude + ', ' + position.coords.longitude;
235 updateLocationButtonDisplay(location_button, location_input);
236 }, function (error) {
237 location_button.disabled = true;
238 updateLocationButtonDisplay(location_button, location_input);