]> git.mxchange.org Git - friendica.git/blob - view/theme/frio/js/textedit.js
Merge remote-tracking branch 'upstream/develop' into 1704-mastodon
[friendica.git] / view / theme / frio / js / textedit.js
1 /*
2  * @brief The file contains functions for text editing and commenting
3  */
4
5
6 function insertFormatting(BBcode,id) {
7         var tmpStr = $("#comment-edit-text-" + id).val();
8         if (tmpStr == '') {
9                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
10                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
11                 openMenu("comment-edit-submit-wrapper-" + id);
12         }
13
14         textarea = document.getElementById("comment-edit-text-" +id);
15         if (document.selection) {
16                 textarea.focus();
17                 selected = document.selection.createRange();
18                 if (BBcode == "url") {
19                         selected.text = "["+BBcode+"]" + "http://" +  selected.text + "[/"+BBcode+"]";
20                 } else {
21                         selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
22                 }
23         } else if (textarea.selectionStart || textarea.selectionStart == "0") {
24                 var start = textarea.selectionStart;
25                 var end = textarea.selectionEnd;
26                 if (BBcode == "url") {
27                         textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + "http://" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
28                 } else {
29                         textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
30                 }
31         }
32
33         $(textarea).trigger('change');
34
35         return true;
36 }
37
38
39 function showThread(id) {
40         $("#collapsed-comments-" + id).show()
41         $("#collapsed-comments-" + id + " .collapsed-comments").show()
42 }
43 function hideThread(id) {
44         $("#collapsed-comments-" + id).hide()
45         $("#collapsed-comments-" + id + " .collapsed-comments").hide()
46 }
47
48 function cmtBbOpen(id) {
49         $("#comment-edit-bb-" + id).show();
50 }
51 function cmtBbClose(id) {
52         $("#comment-edit-bb-" + id).hide();
53 }
54
55 function commentExpand(id) {
56         $("#comment-edit-text-" + id).value = '';
57         $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
58         $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
59         $("#comment-edit-text-" + id).focus();
60         $("#mod-cmnt-wrap-" + id).show();
61         openMenu("comment-edit-submit-wrapper-" + id);
62         return true;
63 }
64
65 function commentClose(obj,id) {
66         if (obj.value == '') {
67                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full");
68                 $("#comment-edit-text-" + id).addClass("comment-edit-text-empty");
69                 $("#mod-cmnt-wrap-" + id).hide();
70                 closeMenu("comment-edit-submit-wrapper-" + id);
71                 return true;
72         }
73         return false;
74 }
75
76 function showHideCommentBox(id) {
77         if( $('#comment-edit-form-' + id).is(':visible')) {
78                 $('#comment-edit-form-' + id).hide();
79         }
80         else {
81                 $('#comment-edit-form-' + id).show();
82         }
83 }
84
85 function commentOpenUI(obj, id) {
86         $("#comment-edit-text-" + id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
87         // Choose an arbitrary tab index that's greater than what we're using in jot (3 of them)
88         // The submit button gets tabindex + 1
89         $("#comment-edit-text-" + id).attr('tabindex','9');
90         $("#comment-edit-submit-" + id).attr('tabindex','10');
91         $("#comment-edit-submit-wrapper-" + id).show();
92         // initialize autosize for this comment
93         autosize($("#comment-edit-text-" + id + ".text-autosize"));
94 }
95
96 function commentCloseUI(obj, id) {
97         if (obj.value === '') {
98                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full").addClass("comment-edit-text-empty");
99                 $("#comment-edit-text-" + id).removeAttr('tabindex');
100                 $("#comment-edit-submit-" + id).removeAttr('tabindex');
101                 $("#comment-edit-submit-wrapper-" + id).hide();
102                 // destroy the automatic textarea resizing
103                 autosize.destroy($("#comment-edit-text-" + id + ".text-autosize"));
104         }
105 }
106
107 function jotTextOpenUI(obj) {
108         if (obj.value == '') {
109                 $(".modal-body #profile-jot-text").addClass("profile-jot-text-full").removeClass("profile-jot-text-empty");
110                 // initiale autosize for the jot
111                 autosize($(".modal-body #profile-jot-text"));
112         }
113 }
114
115 function jotTextCloseUI(obj) {
116         if (obj.value === '') {
117                 $(".modal-body #profile-jot-text").removeClass("profile-jot-text-full").addClass("profile-jot-text-empty");
118                 // destroy the automatic textarea resizing
119                 autosize.destroy($(".modal-body #profile-jot-text"));
120         }
121 }
122
123 function commentOpen(obj,id) {
124         if (obj.value == '') {
125                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
126                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
127                 $("#mod-cmnt-wrap-" + id).show();
128                 openMenu("comment-edit-submit-wrapper-" + id);
129                 return true;
130         }
131         return false;
132 }
133
134 function commentInsert(obj,id) {
135         var tmpStr = $("#comment-edit-text-" + id).val();
136         if (tmpStr == '') {
137                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
138                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
139                 openMenu("comment-edit-submit-wrapper-" + id);
140         }
141         var ins = $(obj).html();
142         ins = ins.replace('&lt;','<');
143         ins = ins.replace('&gt;','>');
144         ins = ins.replace('&amp;','&');
145         ins = ins.replace('&quot;','"');
146         $("#comment-edit-text-" + id).val(tmpStr + ins);
147 }
148
149 function qCommentInsert(obj,id) {
150         var tmpStr = $("#comment-edit-text-" + id).val();
151         if (tmpStr == '') {
152                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
153                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
154                 openMenu("comment-edit-submit-wrapper-" + id);
155         }
156         var ins = $(obj).val();
157         ins = ins.replace('&lt;','<');
158         ins = ins.replace('&gt;','>');
159         ins = ins.replace('&amp;','&');
160         ins = ins.replace('&quot;','"');
161         $("#comment-edit-text-" + id).val(tmpStr + ins);
162         $(obj).val('');
163 }
164
165 function confirmDelete() { return confirm(aStr.delitem); }
166
167 /**
168  * Hide and removes an item element from the DOM after the deletion url is
169  * successful, restore it else.
170  *
171  * @param {string} url The item removal URL
172  * @param {string} elementId The DOM id of the item element
173  * @returns {undefined}
174  */
175 function dropItem(url, elementId) {
176         var confirm = confirmDelete();
177
178         if (confirm) {
179                 $('body').css('cursor', 'wait');
180
181                 var $el = $(document.getElementById(elementId));
182
183                 $el.fadeTo('fast', 0.33, function () {
184                         $.get(url).then(function() {
185                                 $el.remove();
186                         }).fail(function() {
187                                 // @todo Show related error message
188                                 $el.show();
189                         }).always(function() {
190                                 $('body').css('cursor', 'auto');
191                         });
192                 });
193         }
194 }