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>
6 <script type="text/javascript">
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({
22 'transition' : 'elastic'
24 $(".jothidden").show();
25 $("#profile-jot-text").keyup(function(){
26 var textlen = $(this).val().length;
27 $('#character-counter').text(textlen);
32 if (typeof callback != "undefined") {
37 function enableOnUser(){
42 <script type="text/javascript">
43 var ispublic = '{{$ispublic nofilter}}';
44 aStr.linkurl = '{{$linkurl}}';
47 $(document).ready(function() {
49 /* enable editor on focus and click */
50 $("#profile-jot-text").focus(enableOnUser);
51 $("#profile-jot-text").click(enableOnUser);
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"));
60 /* show images / file browser window
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"));
69 addeditortext(embedcode);
71 .on('fbrowser.file.main', function(e, filename, embedcode, id) {
72 jotTextOpenUI(document.getElementById("profile-jot-text"));
74 addeditortext(embedcode);
76 // Asynchronous jot submission
77 .on('submit', '#profile-jot-form', function (e) {
80 // Disable jot submit buttons during processing
81 let $share = $('#profile-jot-submit').button('loading');
82 let $sharePreview = $('#profile-jot-preview-submit').button('loading');
84 let formData = new FormData(e.target);
85 // This cancels the automatic redirection after item submission
86 formData.delete('return');
96 // Reset to form for jot reuse in the same page
98 $('#jot-modal').modal('hide');
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);
105 // Reset jot submit button state
106 $share.button('reset');
107 $sharePreview.button('reset');
109 // Force the display update of the edited post/comment
110 if (formData.get('post_id')) {
112 update_item = formData.get('post_id');
119 $('#wall-image-upload').on('click', function(){
120 Dialog.doImageBrowser("main");
124 $('#wall-file-upload').on('click', function(){
125 Dialog.doFileBrowser("main");
130 function deleteCheckedItems() {
131 if(confirm('{{$delitems}}')) {
133 var ItemsToDelete = {};
135 $("#item-delete-selected").hide();
136 $('#item-delete-selected-rotator').show();
137 $('body').css('cursor', 'wait');
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;
147 checkedstr = $(this).val();
150 // Get the corresponding item container
151 var deleteItem = this.closest(".wall-item-container");
152 ItemsToDelete[deleteItem.id] = deleteItem;
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);
161 $.post('item', { dropitems: checkedstr }, function(data) {
163 // Loop through the ItemsToDelete Object and remove
164 // corresponding item div
165 for(var key in ItemsToDelete) {
166 $(ItemsToDelete[key]).remove();
168 $('body').css('cursor', 'auto');
169 $('#item-delete-selected-rotator').hide();
174 function jotVideoURL() {
175 reply = prompt("{{$vidurl}}");
176 if(reply && reply.length) {
177 addeditortext('[video]' + reply + '[/video]');
181 function jotAudioURL() {
182 reply = prompt("{{$audurl}}");
183 if(reply && reply.length) {
184 addeditortext('[audio]' + reply + '[/audio]');
188 function jotGetLocation() {
189 reply = prompt("{{$whereareu}}", $('#jot-location').val());
190 if(reply && reply.length) {
191 $('#jot-location').val(reply);
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(){
206 $("#jot-popup").show();
209 function linkDropper(event) {
210 var linkFound = event.dataTransfer.types.contains("text/uri-list");
212 event.preventDefault();
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';
226 $.get('parseurl?binurl=' + reply + noAttachment, function(data) {
227 if (!editor) $("#profile-jot-text").val("");
228 initEditor(function(){
230 $('#profile-rotator').hide();
233 autosize.update($("#profile-jot-text"));
237 function itemTag(id) {
238 reply = prompt("{{$term}}");
239 if(reply && reply.length) {
240 reply = reply.replace('#','');
244 $('body').css('cursor', 'wait');
246 $.get('tagger/' + id + '?term=' + reply);
247 if(timer) clearTimeout(timer);
248 timer = setTimeout(NavUpdate,3000);
254 function itemFiler(id) {
255 var bordercolor = $("input").css("border-color");
257 $.get('filer/', function(data){
258 $.colorbox({html:data});
259 $("#id_term").keypress(function(){
260 $(this).css("border-color",bordercolor);
262 $("#select_term").change(function(){
263 $("#id_term").css("border-color",bordercolor);
266 $("#filer_save").click(function(e){
268 reply = $("#id_term").val();
269 if(reply && reply.length) {
271 $('body').css('cursor', 'wait');
272 $.get('filer/' + id + '?term=' + reply, NavUpdate);
273 // if(timer) clearTimeout(timer);
274 // timer = setTimeout(NavUpdate,3000);
279 $("#id_term").css("border-color","#FF0000");
287 function jotClearLocation() {
288 $('#jot-coord').val('');
289 $('#profile-nolocation-wrapper').hide();
292 function addeditortext(data) {
294 var textfield = document.getElementById("profile-jot-text");
295 // check if the textfield does have the default-value
296 jotTextOpenUI(textfield);
297 // save already existent content
298 var currentText = $("#profile-jot-text").val();
299 //insert the data as new value
300 textfield.value = currentText + data;
301 autosize.update($("#profile-jot-text"));
307 var modal = $('#jot-modal').modal();
308 jotcache = $("#jot-sections");
310 // Auto focus on the first enabled field in the modal
311 modal.on('shown.bs.modal', function (e) {
312 $('#jot-modal-content').find('select:not([disabled]), input:not([type=hidden]):not([disabled]), textarea:not([disabled])').first().focus();
316 .find('#jot-modal-content')
320 // Jot attachment live preview.
321 linkPreview = $('#profile-jot-text').linkPreview();
324 // Activate the jot text section in the jot modal
325 function jotActive() {
326 // Make sure jot text does have really the active class (we do this because there are some
327 // other events which trigger jot text (we need to do this for the desktop and mobile
329 var elem = $("#jot-modal .jot-nav #jot-text-lnk");
330 var elemMobile = $("#jot-modal .jot-nav #jot-text-lnk-mobile")
331 toggleJotNav(elem[0]);
332 toggleJotNav(elemMobile[0]);