]> git.mxchange.org Git - friendica.git/blob - view/templates/item/compose-footer.tpl
[frio] Add jotnet fields to compose page
[friendica.git] / view / templates / item / compose-footer.tpl
1 <script type="text/javascript">
2         function updateLocationButtonDisplay(location_button, location_input)
3         {
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;
14                 } else {
15                         location_button.title = location_button.dataset.titleSet;
16                 }
17         }
18
19         $(function() {
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);
26                 });
27                 $textarea.editor_autocomplete(baseurl+"/acl");
28                 $textarea.bbco_autocomplete('bbcode');
29
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]');
36
37                 // Visibility accordion
38
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.
45                                 e.stopPropagation()
46                         }
47                 });
48
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);
55
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');
60                                 }
61                         });
62                         $('.profile-jot-net input').attr('disabled', false);
63                 });
64
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);
71
72                         $('.profile-jot-net input[type=checkbox]').each(function() {
73                                 // Saves current checkbox state
74                                 $(this)
75                                         .attr('data-checked', $(this).prop('checked'))
76                                         .prop('checked', false);
77                         });
78                         $('.profile-jot-net input').attr('disabled', 'disabled');
79                 });
80
81                 if (document.querySelector('input[name="visibility"]:checked').value === 'custom') {
82                         $('#visibility-custom-panel').collapse({parent: '#visibility-accordion'});
83                 }
84
85                 // Custom visibility tags inputs
86
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,
92                 });
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,
98                 });
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,
104                 });
105                 acl.initialize();
106
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>';
109                 };
110
111                 $acl_allow_input.tagsinput({
112                         confirmKeys: [13, 44],
113                         cancelConfirmKeysOnEmpty: true,
114                         freeInput: false,
115                         tagClass: function(item) {
116                                 switch (item.type) {
117                                         case 'group'   : return 'label label-primary';
118                                         case 'contact'  :
119                                         default:
120                                                 return 'label label-info';
121                                 }
122                         },
123                         itemValue: 'id',
124                         itemText: 'name',
125                         itemThumb: 'micro',
126                         itemTitle: function(item) {
127                                 return item.addr;
128                         },
129                         typeaheadjs: {
130                                 name: 'contacts',
131                                 displayKey: 'name',
132                                 templates: {
133                                         suggestion: suggestionTemplate
134                                 },
135                                 source: acl.ttAdapter()
136                         }
137                 });
138
139                 $acl_deny_input
140                 .tagsinput({
141                         confirmKeys: [13, 44],
142                         freeInput: false,
143                         tagClass: function(item) {
144                                 switch (item.type) {
145                                         case 'group'   : return 'label label-primary';
146                                         case 'contact'  :
147                                         default:
148                                                 return 'label label-info';
149                                 }
150                         },
151                         itemValue: 'id',
152                         itemText: 'name',
153                         itemThumb: 'micro',
154                         itemTitle: function(item) {
155                                 return item.addr;
156                         },
157                         typeaheadjs: {
158                                 name: 'contacts',
159                                 displayKey: 'name',
160                                 templates: {
161                                         suggestion: suggestionTemplate
162                                 },
163                                 source: acl.ttAdapter()
164                         }
165                 });
166
167                 // Import existing ACL into the tags input fields.
168
169                 $group_allow_input.val().split(',').forEach(function (val) {
170                         $acl_allow_input.tagsinput('add', acl_groups.get(val)[0]);
171                 });
172                 $contact_allow_input.val().split(',').forEach(function (val) {
173                         $acl_allow_input.tagsinput('add', acl_contacts.get(val)[0]);
174                 });
175                 $group_deny_input.val().split(',').forEach(function (val) {
176                         $acl_deny_input.tagsinput('add', acl_groups.get(val)[0]);
177                 });
178                 $contact_deny_input.val().split(',').forEach(function (val) {
179                         $acl_deny_input.tagsinput('add', acl_contacts.get(val)[0]);
180                 });
181
182                 // Anti-duplicate callback + acl fields value generation
183
184                 $acl_allow_input.on('itemAdded', function (event) {
185                         // Removes duplicate in the opposite acl box
186                         $acl_deny_input.tagsinput('remove', event.item);
187
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 + '>');
194                                 } else {
195                                         $contact_allow_input.val($contact_allow_input.val() + '<' + item.id + '>');
196                                 }
197                         });
198                 });
199
200                 $acl_deny_input.on('itemAdded', function (event) {
201                         // Removes duplicate in the opposite acl box
202                         $acl_allow_input.tagsinput('remove', event.item);
203
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 + '>');
210                                 } else {
211                                         $contact_deny_input.val($contact_allow_input.val() + '<' + item.id + '>');
212                                 }
213                         });
214                 });
215
216                 let location_button = document.getElementById('profile-location');
217                 let location_input = document.getElementById('jot-location');
218
219                 updateLocationButtonDisplay(location_button, location_input);
220
221                 location_input.addEventListener('change', function () {
222                         updateLocationButtonDisplay(location_button, location_input);
223                 });
224                 location_input.addEventListener('keyup', function () {
225                         updateLocationButtonDisplay(location_button, location_input);
226                 });
227
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);
239                                 });
240                         }
241                 });
242         })
243 </script>