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"));
59 /* show images / file browser window
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"));
68 addeditortext(embedcode);
70 .on('fbrowser.file.main', function(e, filename, embedcode, id) {
71 jotTextOpenUI(document.getElementById("profile-jot-text"));
73 addeditortext(embedcode);
75 // Asynchronous jot submission
76 .on('submit', '#profile-jot-form', function (e) {
79 // Disable jot submit buttons during processing
80 let $share = $('#profile-jot-submit').button('loading');
81 let $sharePreview = $('#profile-jot-preview-submit').button('loading');
83 let formData = new FormData(e.target);
84 // This cancels the automatic redirection after item submission
85 formData.delete('return');
95 // Reset to form for jot reuse in the same page
97 $('#jot-modal').modal('hide');
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);
104 // Reset jot submit button state
105 $share.button('reset');
106 $sharePreview.button('reset');
108 // Force the display update of the edited post/comment
109 if (formData.get('post_id')) {
111 update_item = formData.get('post_id');
118 $('#wall-image-upload').on('click', function(){
119 Dialog.doImageBrowser("main");
123 $('#wall-file-upload').on('click', function(){
124 Dialog.doFileBrowser("main");
128 $('body').on('click', '.p-category .filerm', function(e){
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');
140 .always(function () {
147 function deleteCheckedItems() {
148 if(confirm('{{$delitems}}')) {
150 var ItemsToDelete = {};
152 $("#item-delete-selected").hide();
153 $('#item-delete-selected-rotator').show();
154 $('body').css('cursor', 'wait');
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;
164 checkedstr = $(this).val();
167 // Get the corresponding item container
168 var deleteItem = this.closest(".wall-item-container");
169 ItemsToDelete[deleteItem.id] = deleteItem;
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);
178 $.post('item', { dropitems: checkedstr }, function(data) {
180 // Loop through the ItemsToDelete Object and remove
181 // corresponding item div
182 for(var key in ItemsToDelete) {
183 $(ItemsToDelete[key]).remove();
185 $('body').css('cursor', 'auto');
186 $('#item-delete-selected-rotator').hide();
191 function jotVideoURL() {
192 reply = prompt("{{$vidurl}}");
193 if(reply && reply.length) {
194 addeditortext('[video]' + reply + '[/video]');
198 function jotAudioURL() {
199 reply = prompt("{{$audurl}}");
200 if(reply && reply.length) {
201 addeditortext('[audio]' + reply + '[/audio]');
205 function jotGetLocation() {
206 reply = prompt("{{$whereareu}}", $('#jot-location').val());
207 if(reply && reply.length) {
208 $('#jot-location').val(reply);
212 function jotShare(id) {
213 $.get('share/' + id, function(data) {
214 // remove the former content of the text input
215 $("#profile-jot-text").val("");
216 initEditor(function(){
223 $("#jot-popup").show();
226 function linkDropper(event) {
227 var linkFound = event.dataTransfer.types.contains("text/uri-list");
229 event.preventDefault();
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';
243 $.get('parseurl?binurl=' + reply + noAttachment, function(data) {
244 if (!editor) $("#profile-jot-text").val("");
245 initEditor(function(){
247 $('#profile-rotator').hide();
250 autosize.update($("#profile-jot-text"));
254 function itemTag(id) {
255 reply = prompt("{{$term}}");
256 if(reply && reply.length) {
257 reply = reply.replace('#','');
261 $('body').css('cursor', 'wait');
263 $.post('post/' + id + '/tag/add', {term: reply});
264 if(timer) clearTimeout(timer);
265 timer = setTimeout(NavUpdate,3000);
271 function itemFiler(id) {
272 var bordercolor = $("input").css("border-color");
274 $.get('filer/', function(data){
275 $.colorbox({html:data});
276 $("#id_term").keypress(function(){
277 $(this).css("border-color",bordercolor);
279 $("#select_term").change(function(){
280 $("#id_term").css("border-color",bordercolor);
283 $("#filer_save").click(function(e){
285 reply = $("#id_term").val();
286 if(reply && reply.length) {
288 $('body').css('cursor', 'wait');
289 $.get('filer/' + id + '?term=' + reply, NavUpdate);
290 // if(timer) clearTimeout(timer);
291 // timer = setTimeout(NavUpdate,3000);
296 $("#id_term").css("border-color","#FF0000");
303 function jotClearLocation() {
304 $('#jot-coord').val('');
305 $('#profile-nolocation-wrapper').hide();
308 function addeditortext(data) {
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"));
323 var modal = $('#jot-modal').modal();
324 jotcache = $("#jot-sections");
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();
332 .find('#jot-modal-content')
336 // Jot attachment live preview.
337 linkPreview = $('#profile-jot-text').linkPreview();
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
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]);