]> git.mxchange.org Git - friendica.git/blob - view/theme/frio/templates/jot-header.tpl
Merge pull request #12102 from MrPetovan/task/11011-frio-contact-template-link
[friendica.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                 /* show images / file browser window
60                  *
61                  **/
62
63                 /* callback */
64                 $('body').on('fbrowser.image.main', function(e, filename, embedcode, id) {
65                         ///@todo this part isn't ideal and need to be done in a better way
66                         jotTextOpenUI(document.getElementById("profile-jot-text"));
67                         jotActive();
68                         addeditortext(embedcode);
69                 })
70                 .on('fbrowser.file.main', function(e, filename, embedcode, id) {
71                         jotTextOpenUI(document.getElementById("profile-jot-text"));
72                         jotActive();
73                         addeditortext(embedcode);
74                 })
75                 // Asynchronous jot submission
76                 .on('submit', '#profile-jot-form', function (e) {
77                         e.preventDefault();
78
79                         // Disable jot submit buttons during processing
80                         let $share = $('#profile-jot-submit').button('loading');
81                         let $sharePreview = $('#profile-jot-preview-submit').button('loading');
82
83                         let formData = new FormData(e.target);
84                         // This cancels the automatic redirection after item submission
85                         formData.delete('return');
86
87                         $.ajax({
88                                 url: 'item',
89                                 data: formData,
90                                 processData: false,
91                                 contentType: false,
92                                 type: 'POST',
93                         })
94                         .then(function () {
95                                 // Reset to form for jot reuse in the same page
96                                 e.target.reset();
97                                 $('#jot-modal').modal('hide');
98                         })
99                         .always(function() {
100                                 // Reset the post_id_random to avoid duplicate post errors
101                                 let new_post_id_random = Math.floor(Math.random() * (Number.MAX_SAFE_INTEGER - (Number.MAX_SAFE_INTEGER / 10))) + Number.MAX_SAFE_INTEGER / 10;
102                                 $('#profile-jot-form [name=post_id_random]').val(new_post_id_random);
103
104                                 // Reset jot submit button state
105                                 $share.button('reset');
106                                 $sharePreview.button('reset');
107
108                                 // Force the display update of the edited post/comment
109                                 if (formData.get('post_id')) {
110                                         force_update = true;
111                                         update_item = formData.get('post_id');
112                                 }
113
114                                 NavUpdate();
115                         })
116                 });
117
118                 $('#wall-image-upload').on('click', function(){
119                         Dialog.doImageBrowser("main");
120                         jotActive();
121                 });
122
123                 $('#wall-file-upload').on('click', function(){
124                         Dialog.doFileBrowser("main");
125                         jotActive();
126                 });
127
128                 $('body').on('click', '.p-category .filerm', function(e){
129                         e.preventDefault();
130
131                         let $href = $(e.target).attr('href');
132                         // Prevents arbitrary Ajax requests
133                         if ($href.substr(0, 7) === 'filerm/') {
134                                 $(e.target).parent().removeClass('btn-success btn-danger');
135                                 $.post($href)
136                                 .done(function() {
137                                         liking = 1;
138                                         force_update = true;
139                                 })
140                                 .always(function () {
141                                         NavUpdate();
142                                 });
143                         }
144                 });
145         });
146
147         function deleteCheckedItems() {
148                 if(confirm('{{$delitems}}')) {
149                         var checkedstr = '';
150                         var ItemsToDelete = {};
151
152                         $("#item-delete-selected").hide();
153                         $('#item-delete-selected-rotator').show();
154                         $('body').css('cursor', 'wait');
155
156                         $('.item-select').each( function() {
157                                 if($(this).is(':checked')) {
158                                         if(checkedstr.length != 0) {
159                                                 checkedstr = checkedstr + ',' + $(this).val();
160                                                 var deleteItem = this.closest(".wall-item-container");
161                                                 ItemsToDelete[deleteItem.id] = deleteItem;
162                                         }
163                                         else {
164                                                 checkedstr = $(this).val();
165                                         }
166
167                                         // Get the corresponding item container
168                                         var deleteItem = this.closest(".wall-item-container");
169                                         ItemsToDelete[deleteItem.id] = deleteItem;
170                                 }
171                         });
172
173                         // Fade the the the container from the items we want to delete
174                         for(var key in  ItemsToDelete) {
175                                 $(ItemsToDelete[key]).fadeTo('fast', 0.33);
176                         };
177
178                         $.post('item', { dropitems: checkedstr }, function(data) {
179                         }).done(function() {
180                                 // Loop through the ItemsToDelete Object and remove
181                                 // corresponding item div
182                                 for(var key in  ItemsToDelete) {
183                                         $(ItemsToDelete[key]).remove();
184                                 }
185                                 $('body').css('cursor', 'auto');
186                                 $('#item-delete-selected-rotator').hide();
187                         });
188                 }
189         }
190
191         function jotVideoURL() {
192                 reply = prompt("{{$vidurl}}");
193                 if(reply && reply.length) {
194                         addeditortext('[video]' + reply + '[/video]');
195                 }
196         }
197
198         function jotAudioURL() {
199                 reply = prompt("{{$audurl}}");
200                 if(reply && reply.length) {
201                         addeditortext('[audio]' + reply + '[/audio]');
202                 }
203         }
204
205         function jotGetLocation() {
206                 reply = prompt("{{$whereareu}}", $('#jot-location').val());
207                 if(reply && reply.length) {
208                         $('#jot-location').val(reply);
209                 }
210         }
211
212         function jotShare(id) {
213                 $.get('post/' + id + '/share', function(data) {
214                         // remove the former content of the text input
215                         $("#profile-jot-text").val("");
216                         initEditor(function(){
217                                 addeditortext(data);
218                         });
219                 });
220
221                 jotShow();
222
223                 $("#jot-popup").show();
224         }
225
226         function linkDropper(event) {
227                 var linkFound = event.dataTransfer.types.contains("text/uri-list");
228                 if(linkFound)
229                         event.preventDefault();
230         }
231
232         function linkDrop(event) {
233                 var reply = event.dataTransfer.getData("text/uri-list");
234                 var noAttachment = '';
235                 event.target.textContent = reply;
236                 event.preventDefault();
237                 if(reply && reply.length) {
238                         reply = bin2hex(reply);
239                         $('#profile-rotator').show();
240                         if (currentText.includes("[attachment") && currentText.includes("[/attachment]")) {
241                                 noAttachment = '&noAttachment=1';
242                         }
243                         $.get('parseurl?binurl=' + reply + noAttachment, function(data) {
244                                 if (!editor) $("#profile-jot-text").val("");
245                                 initEditor(function(){
246                                         addeditortext(data);
247                                         $('#profile-rotator').hide();
248                                 });
249                         });
250                         autosize.update($("#profile-jot-text"));
251                 }
252         }
253
254         function itemTag(id) {
255                 reply = prompt("{{$term}}");
256                 if(reply && reply.length) {
257                         reply = reply.replace('#','');
258                         if(reply.length) {
259
260                                 commentBusy = true;
261                                 $('body').css('cursor', 'wait');
262
263                                 $.post('post/' + id + '/tag/add', {term: reply});
264                                 if(timer) clearTimeout(timer);
265                                 timer = setTimeout(NavUpdate,3000);
266                                 liking = 1;
267                         }
268                 }
269         }
270
271         function itemFiler(id) {
272                 var bordercolor = $("input").css("border-color");
273
274                 $.get('filer/', function(data){
275                         $.colorbox({html:data});
276                         $("#id_term").keypress(function(){
277                                 $(this).css("border-color",bordercolor);
278                         })
279                         $("#select_term").change(function(){
280                                 $("#id_term").css("border-color",bordercolor);
281                         })
282
283                         $("#filer_save").click(function(e){
284                                 e.preventDefault();
285                                 reply = $("#id_term").val();
286                                 if(reply && reply.length) {
287                                         commentBusy = true;
288                                         $('body').css('cursor', 'wait');
289                                         $.get('filer/' + id + '?term=' + reply, NavUpdate);
290 //                                      if(timer) clearTimeout(timer);
291 //                                      timer = setTimeout(NavUpdate,3000);
292                                         liking = 1;
293                                         force_update = true;
294                                         $.colorbox.close();
295                                 } else {
296                                         $("#id_term").css("border-color","#FF0000");
297                                 }
298                                 return false;
299                         });
300                 });
301         }
302
303         function jotClearLocation() {
304                 $('#jot-coord').val('');
305                 $('#profile-nolocation-wrapper').hide();
306         }
307
308         function addeditortext(data) {
309                 // get the textfield
310                 var textfield = document.getElementById("profile-jot-text");
311                 // check if the textfield does have the default-value
312                 jotTextOpenUI(textfield);
313                 // save already existent content
314                 var currentText = $("#profile-jot-text").val();
315                 //insert the data as new value
316                 textfield.value = currentText + data;
317                 autosize.update($("#profile-jot-text"));
318         }
319
320         {{$geotag nofilter}}
321
322         function jotShow() {
323                 var modal = $('#jot-modal').modal();
324                 jotcache = $("#jot-sections");
325
326                 // Auto focus on the first enabled field in the modal
327                 modal.on('shown.bs.modal', function (e) {
328                         $('#jot-modal-content').find('select:not([disabled]), input:not([type=hidden]):not([disabled]), textarea:not([disabled])').first().focus();
329                 })
330
331                 modal
332                         .find('#jot-modal-content')
333                         .append(jotcache)
334                         .modal.show;
335
336                 // Jot attachment live preview.
337                 linkPreview = $('#profile-jot-text').linkPreview();
338         }
339
340         // Activate the jot text section in the jot modal
341         function jotActive() {
342                 // Make sure jot text does have really the active class (we do this because there are some
343                 // other events which trigger jot text (we need to do this for the desktop and mobile
344                 // jot nav
345                 var elem = $("#jot-modal .jot-nav #jot-text-lnk");
346                 var elemMobile = $("#jot-modal .jot-nav #jot-text-lnk-mobile")
347                 toggleJotNav(elem[0]);
348                 toggleJotNav(elemMobile[0]);
349         }
350 </script>