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