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