f9e10ca8cd1454c9d144887655a1e924720556c7
[friendica.git/.git] / view / theme / frio / templates / jot-header.tpl
1
2 <script type="text/javascript" src="{{$baseurl}}/view/js/ajaxupload.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script>
3 <script type="text/javascript" src="{{$baseurl}}/view/js/linkPreview.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script>
4 <script type="text/javascript" src="{{$baseurl}}/view/theme/frio/js/jot.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script>
5
6 <script type="text/javascript">
7         var editor = false;
8         var textlen = 0;
9
10         function initEditor(callback) {
11                 if (editor == false) {
12                         $("#profile-jot-text-loading").show();
13                         $("#profile-jot-text-loading").hide();
14                         //$("#profile-jot-text").addClass("profile-jot-text-full").removeClass("profile-jot-text-empty");
15                         $("#jot-category").show();
16                         $("#jot-category").addClass("jot-category-ex");
17                         $("#jot-profile-jot-wrapper").show();
18                         $("#profile-jot-text").editor_autocomplete(baseurl + '/search/acl');
19                         $("#profile-jot-text").bbco_autocomplete('bbcode');
20                         $("a#jot-perms-icon").colorbox({
21                                 'inline' : true,
22                                 'transition' : 'elastic'
23                         });
24                         $(".jothidden").show();
25                         $("#profile-jot-text").keyup(function(){
26                                 var textlen = $(this).val().length;
27                                 $('#character-counter').text(textlen);
28                         });
29
30                         editor = true;
31                 }
32                 if (typeof callback != "undefined") {
33                         callback();
34                 }
35         }
36
37         function enableOnUser(){
38                 initEditor();
39         }
40 </script>
41
42 <script type="text/javascript">
43         var ispublic = '{{$ispublic nofilter}}';
44         aStr.linkurl = '{{$linkurl}}';
45
46
47         $(document).ready(function() {
48
49                 /* enable editor on focus and click */
50                 $("#profile-jot-text").focus(enableOnUser);
51                 $("#profile-jot-text").click(enableOnUser);
52
53                 // When clicking on a forum in acl we should remove the profile jot textarea
54                 // default value before inserting the forum mention
55                 $("body").on('click', '#jot-modal .acl-list-item.forum', function(){
56                         jotTextOpenUI(document.getElementById("profile-jot-text"));
57                 });
58
59
60                 /* show images / file browser window
61                  *
62                  **/
63
64                 /* callback */
65                 $('body').on('fbrowser.image.main', function(e, filename, embedcode, id) {
66                         ///@todo this part isn't ideal and need to be done in a better way
67                         jotTextOpenUI(document.getElementById("profile-jot-text"));
68                         jotActive();
69                         addeditortext(embedcode);
70                 })
71                 .on('fbrowser.file.main', function(e, filename, embedcode, id) {
72                         jotTextOpenUI(document.getElementById("profile-jot-text"));
73                         jotActive();
74                         addeditortext(embedcode);
75                 })
76                 // Asynchronous jot submission
77                 .on('submit', '#profile-jot-form', function (e) {
78                         e.preventDefault();
79
80                         // Disable jot submit buttons during processing
81                         let $share = $('#profile-jot-submit').button('loading');
82                         let $sharePreview = $('#profile-jot-preview-submit').button('loading');
83
84                         let formData = new FormData(e.target);
85                         // This cancels the automatic redirection after item submission
86                         formData.delete('return');
87
88                         $.ajax({
89                                 url: 'item',
90                                 data: formData,
91                                 processData: false,
92                                 contentType: false,
93                                 type: 'POST',
94                         })
95                         .then(function () {
96                                 // Reset to form for jot reuse in the same page
97                                 e.target.reset();
98                                 $('#jot-modal').modal('hide');
99                         })
100                         .always(function() {
101                                 // Reset the post_id_random to avoid duplicate post errors
102                                 let new_post_id_random = Math.floor(Math.random() * (Number.MAX_SAFE_INTEGER - (Number.MAX_SAFE_INTEGER / 10))) + Number.MAX_SAFE_INTEGER / 10;
103                                 $('#profile-jot-form [name=post_id_random]').val(new_post_id_random);
104
105                                 // Reset jot submit button state
106                                 $share.button('reset');
107                                 $sharePreview.button('reset');
108
109                                 // Force the display update of the edited post/comment
110                                 if (formData.get('post_id')) {
111                                         force_update = true;
112                                         update_item = formData.get('post_id');
113                                 }
114
115                                 NavUpdate();
116                         })
117                 });
118
119                 $('#wall-image-upload').on('click', function(){
120                         Dialog.doImageBrowser("main");
121                         jotActive();
122                 });
123
124                 $('#wall-file-upload').on('click', function(){
125                         Dialog.doFileBrowser("main");
126                         jotActive();
127                 });
128         });
129
130         function deleteCheckedItems() {
131                 if(confirm('{{$delitems}}')) {
132                         var checkedstr = '';
133                         var ItemsToDelete = {};
134
135                         $("#item-delete-selected").hide();
136                         $('#item-delete-selected-rotator').show();
137                         $('body').css('cursor', 'wait');
138
139                         $('.item-select').each( function() {
140                                 if($(this).is(':checked')) {
141                                         if(checkedstr.length != 0) {
142                                                 checkedstr = checkedstr + ',' + $(this).val();
143                                                 var deleteItem = this.closest(".wall-item-container");
144                                                 ItemsToDelete[deleteItem.id] = deleteItem;
145                                         }
146                                         else {
147                                                 checkedstr = $(this).val();
148                                         }
149
150                                         // Get the corresponding item container
151                                         var deleteItem = this.closest(".wall-item-container");
152                                         ItemsToDelete[deleteItem.id] = deleteItem;
153                                 }
154                         });
155
156                         // Fade the the the container from the items we want to delete
157                         for(var key in  ItemsToDelete) {
158                                 $(ItemsToDelete[key]).fadeTo('fast', 0.33);
159                         };
160
161                         $.post('item', { dropitems: checkedstr }, function(data) {
162                         }).done(function() {
163                                 // Loop through the ItemsToDelete Object and remove
164                                 // corresponding item div
165                                 for(var key in  ItemsToDelete) {
166                                         $(ItemsToDelete[key]).remove();
167                                 }
168                                 $('body').css('cursor', 'auto');
169                                 $('#item-delete-selected-rotator').hide();
170                         });
171                 }
172         }
173
174         function jotVideoURL() {
175                 reply = prompt("{{$vidurl}}");
176                 if(reply && reply.length) {
177                         addeditortext('[video]' + reply + '[/video]');
178                 }
179         }
180
181         function jotAudioURL() {
182                 reply = prompt("{{$audurl}}");
183                 if(reply && reply.length) {
184                         addeditortext('[audio]' + reply + '[/audio]');
185                 }
186         }
187
188         function jotGetLocation() {
189                 reply = prompt("{{$whereareu}}", $('#jot-location').val());
190                 if(reply && reply.length) {
191                         $('#jot-location').val(reply);
192                 }
193         }
194
195         function jotShare(id) {
196                 $.get('share/' + id, function(data) {
197                         // remove the former content of the text input
198                         $("#profile-jot-text").val("");
199                         initEditor(function(){
200                                 addeditortext(data);
201                         });
202                 });
203
204                 jotShow();
205
206                 $("#jot-popup").show();
207         }
208
209         function linkDropper(event) {
210                 var linkFound = event.dataTransfer.types.contains("text/uri-list");
211                 if(linkFound)
212                         event.preventDefault();
213         }
214
215         function linkDrop(event) {
216                 var reply = event.dataTransfer.getData("text/uri-list");
217                 var noAttachment = '';
218                 event.target.textContent = reply;
219                 event.preventDefault();
220                 if(reply && reply.length) {
221                         reply = bin2hex(reply);
222                         $('#profile-rotator').show();
223                         if (currentText.includes("[attachment") && currentText.includes("[/attachment]")) {
224                                 noAttachment = '&noAttachment=1';
225                         }
226                         $.get('parse_url?binurl=' + reply + noAttachment, function(data) {
227                                 if (!editor) $("#profile-jot-text").val("");
228                                 initEditor(function(){
229                                         addeditortext(data);
230                                         $('#profile-rotator').hide();
231                                 });
232                         });
233                         autosize.update($("#profile-jot-text"));
234                 }
235         }
236
237         function itemTag(id) {
238                 reply = prompt("{{$term}}");
239                 if(reply && reply.length) {
240                         reply = reply.replace('#','');
241                         if(reply.length) {
242
243                                 commentBusy = true;
244                                 $('body').css('cursor', 'wait');
245
246                                 $.get('tagger/' + id + '?term=' + reply);
247                                 if(timer) clearTimeout(timer);
248                                 timer = setTimeout(NavUpdate,3000);
249                                 liking = 1;
250                         }
251                 }
252         }
253
254         function itemFiler(id) {
255                 var bordercolor = $("input").css("border-color");
256
257                 $.get('filer/', function(data){
258                         $.colorbox({html:data});
259                         $("#id_term").keypress(function(){
260                                 $(this).css("border-color",bordercolor);
261                         })
262                         $("#select_term").change(function(){
263                                 $("#id_term").css("border-color",bordercolor);
264                         })
265
266                         $("#filer_save").click(function(e){
267                                 e.preventDefault();
268                                 reply = $("#id_term").val();
269                                 if(reply && reply.length) {
270                                         commentBusy = true;
271                                         $('body').css('cursor', 'wait');
272                                         $.get('filer/' + id + '?term=' + reply, NavUpdate);
273 //                                      if(timer) clearTimeout(timer);
274 //                                      timer = setTimeout(NavUpdate,3000);
275                                         liking = 1;
276                                         $.colorbox.close();
277                                 } else {
278                                         $("#id_term").css("border-color","#FF0000");
279                                 }
280                                 return false;
281                         });
282                 });
283
284         }
285
286         function jotClearLocation() {
287                 $('#jot-coord').val('');
288                 $('#profile-nolocation-wrapper').hide();
289         }
290
291         function addeditortext(data) {
292                 // get the textfield
293                 var textfield = document.getElementById("profile-jot-text");
294                 // check if the textfield does have the default-value
295                 jotTextOpenUI(textfield);
296                 // save already existent content
297                 var currentText = $("#profile-jot-text").val();
298                 //insert the data as new value
299                 textfield.value = currentText + data;
300                 autosize.update($("#profile-jot-text"));
301         }
302
303         {{$geotag nofilter}}
304
305         function jotShow() {
306                 var modal = $('#jot-modal').modal();
307                 jotcache = $("#jot-sections");
308
309                 // Auto focus on the first enabled field in the modal
310                 modal.on('shown.bs.modal', function (e) {
311                         $('#jot-modal-content').find('select:not([disabled]), input:not([type=hidden]):not([disabled]), textarea:not([disabled])').first().focus();
312                 })
313
314                 modal
315                         .find('#jot-modal-content')
316                         .append(jotcache)
317                         .modal.show;
318
319                 // Jot attachment live preview.
320                 linkPreview = $('#profile-jot-text').linkPreview();
321         }
322
323         // Activate the jot text section in the jot modal
324         function jotActive() {
325                 // Make sure jot text does have really the active class (we do this because there are some
326                 // other events which trigger jot text (we need to do this for the desktop and mobile
327                 // jot nav
328                 var elem = $("#jot-modal .jot-nav #jot-text-lnk");
329                 var elemMobile = $("#jot-modal .jot-nav #jot-text-lnk-mobile")
330                 toggleJotNav(elem[0]);
331                 toggleJotNav(elemMobile[0]);
332         }
333 </script>