]> git.mxchange.org Git - friendica.git/blob - view/theme/frio/js/textedit.js
bbbd8fde860a12832b9518d625a647fae580de0a
[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         } else {
80                 $('#comment-edit-form-' + id).show();
81         }
82 }
83
84 function commentOpenUI(obj, id) {
85         $("#comment-edit-text-" + id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
86         // Choose an arbitrary tab index that's greater than what we're using in jot (3 of them)
87         // The submit button gets tabindex + 1
88         $("#comment-edit-text-" + id).attr('tabindex', '9');
89         $("#comment-edit-submit-" + id).attr('tabindex', '10');
90         $("#comment-edit-submit-wrapper-" + id).show();
91         // initialize autosize for this comment
92         autosize($("#comment-edit-text-" + id + ".text-autosize"));
93 }
94
95 function commentCloseUI(obj, id) {
96         if (obj.value === '') {
97                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full").addClass("comment-edit-text-empty");
98                 $("#comment-edit-text-" + id).removeAttr('tabindex');
99                 $("#comment-edit-submit-" + id).removeAttr('tabindex');
100                 $("#comment-edit-submit-wrapper-" + id).hide();
101                 // destroy the automatic textarea resizing
102                 autosize.destroy($("#comment-edit-text-" + id + ".text-autosize"));
103         }
104 }
105
106 function jotTextOpenUI(obj) {
107         if (obj.value == '') {
108                 $(".modal-body #profile-jot-text").addClass("profile-jot-text-full").removeClass("profile-jot-text-empty");
109                 // initiale autosize for the jot
110                 autosize($(".modal-body #profile-jot-text"));
111         }
112 }
113
114 function jotTextCloseUI(obj) {
115         if (obj.value === '') {
116                 $(".modal-body #profile-jot-text").removeClass("profile-jot-text-full").addClass("profile-jot-text-empty");
117                 // destroy the automatic textarea resizing
118                 autosize.destroy($(".modal-body #profile-jot-text"));
119         }
120 }
121
122 function commentOpen(obj, id) {
123         if (obj.value == '') {
124                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
125                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
126                 $("#mod-cmnt-wrap-" + id).show();
127                 openMenu("comment-edit-submit-wrapper-" + id);
128                 return true;
129         }
130         return false;
131 }
132
133 function commentInsert(obj, id) {
134         var tmpStr = $("#comment-edit-text-" + id).val();
135         if (tmpStr == '') {
136                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
137                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
138                 openMenu("comment-edit-submit-wrapper-" + id);
139         }
140         var ins = $(obj).html();
141         ins = ins.replace('&lt;', '<');
142         ins = ins.replace('&gt;', '>');
143         ins = ins.replace('&amp;', '&');
144         ins = ins.replace('&quot;', '"');
145         $("#comment-edit-text-" + id).val(tmpStr + ins);
146 }
147
148 function qCommentInsert(obj, id) {
149         var tmpStr = $("#comment-edit-text-" + id).val();
150         if (tmpStr == '') {
151                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
152                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
153                 openMenu("comment-edit-submit-wrapper-" + id);
154         }
155         var ins = $(obj).val();
156         ins = ins.replace('&lt;', '<');
157         ins = ins.replace('&gt;', '>');
158         ins = ins.replace('&amp;', '&');
159         ins = ins.replace('&quot;', '"');
160         $("#comment-edit-text-" + id).val(tmpStr + ins);
161         $(obj).val('');
162 }
163
164 function confirmDelete() {
165         return confirm(aStr.delitem);
166 }
167
168 /**
169  * Hide and removes an item element from the DOM after the deletion url is
170  * successful, restore it else.
171  *
172  * @param {string} url The item removal URL
173  * @param {string} elementId The DOM id of the item element
174  * @returns {undefined}
175  */
176 function dropItem(url, elementId) {
177         var confirm = confirmDelete();
178
179         if (confirm) {
180                 $('body').css('cursor', 'wait');
181
182                 var $el = $(document.getElementById(elementId));
183
184                 $el.fadeTo('fast', 0.33, function () {
185                         $.get(url).then(function() {
186                                 $el.remove();
187                         }).fail(function() {
188                                 // @todo Show related error message
189                                 $el.show();
190                         }).always(function() {
191                                 $('body').css('cursor', 'auto');
192                         });
193                 });
194         }
195 }