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