2 * @brief The file contains functions for text editing and commenting
5 function commentGetLink(id,prompttext) {
6 reply = prompt(prompttext);
7 if(reply && reply.length) {
8 reply = bin2hex(reply);
9 $.get('parse_url?noAttachment=1&binurl=' + reply, function(data) {
10 addCommentText(data, id);
15 function addCommentText(data, id) {
17 var textfield = document.getElementById("comment-edit-text-" + id);
18 // check if the textfield does have the default-value
19 commentOpenUI(textfield, id);
20 // save already existent content
21 var currentText = $("#comment-edit-text-" + id).val();
22 //insert the data as new value
23 textfield.value = currentText + data;
24 autosize.update($("#comment-edit-text-" + id));
27 function commentLinkDrop(event, id) {
28 var reply = event.dataTransfer.getData("text/uri-list");
29 event.target.textContent = reply;
30 event.preventDefault();
31 if (reply && reply.length) {
32 reply = bin2hex(reply);
33 $.get('parse_url?noAttachment=1&binurl=' + reply, function(data) {
34 addCommentText(data, id);
39 function commentLinkDropper(event) {
40 var linkFound = event.dataTransfer.types.contains("text/uri-list");
42 event.preventDefault();
47 function insertFormatting(BBcode, id) {
48 var tmpStr = $("#comment-edit-text-" + id).val();
50 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
51 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
52 openMenu("comment-edit-submit-wrapper-" + id);
55 textarea = document.getElementById("comment-edit-text-" + id);
56 if (document.selection) {
58 selected = document.selection.createRange();
59 selected.text = "[" + BBcode + "]" + selected.text + "[/" + BBcode + "]";
60 } else if (textarea.selectionStart || textarea.selectionStart == "0") {
61 var start = textarea.selectionStart;
62 var end = textarea.selectionEnd;
63 textarea.value = textarea.value.substring(0, start) + "[" + BBcode + "]" + textarea.value.substring(start, end) + "[/" + BBcode + "]" + textarea.value.substring(end, textarea.value.length);
66 $(textarea).trigger('change');
71 function insertFormattingToPost(BBcode) {
72 textarea = document.getElementById("profile-jot-text");
73 if (document.selection) {
75 selected = document.selection.createRange();
76 selected.text = "[" + BBcode + "]" + selected.text + "[/" + BBcode + "]";
77 } else if (textarea.selectionStart || textarea.selectionStart == "0") {
78 var start = textarea.selectionStart;
79 var end = textarea.selectionEnd;
80 textarea.value = textarea.value.substring(0, start) + "[" + BBcode + "]" + textarea.value.substring(start, end) + "[/" + BBcode + "]" + textarea.value.substring(end, textarea.value.length);
83 $(textarea).trigger('change');
88 function showThread(id) {
89 $("#collapsed-comments-" + id).show()
90 $("#collapsed-comments-" + id + " .collapsed-comments").show()
92 function hideThread(id) {
93 $("#collapsed-comments-" + id).hide()
94 $("#collapsed-comments-" + id + " .collapsed-comments").hide()
97 function cmtBbOpen(id) {
98 $("#comment-edit-bb-" + id).show();
100 function cmtBbClose(id) {
101 $("#comment-edit-bb-" + id).hide();
104 function commentExpand(id) {
105 $("#comment-edit-text-" + id).value = '';
106 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
107 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
108 $("#comment-edit-text-" + id).focus();
109 $("#mod-cmnt-wrap-" + id).show();
110 openMenu("comment-edit-submit-wrapper-" + id);
114 function commentClose(obj, id) {
115 if (obj.value == '') {
116 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full");
117 $("#comment-edit-text-" + id).addClass("comment-edit-text-empty");
118 $("#mod-cmnt-wrap-" + id).hide();
119 closeMenu("comment-edit-submit-wrapper-" + id);
125 function showHideCommentBox(id) {
126 if ($('#comment-edit-form-' + id).is(':visible')) {
127 $('#comment-edit-form-' + id).hide();
129 $('#comment-edit-form-' + id).show();
133 function commentOpenUI(obj, id) {
134 $("#comment-edit-text-" + id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
135 // Choose an arbitrary tab index that's greater than what we're using in jot (3 of them)
136 // The submit button gets tabindex + 1
137 $("#comment-edit-text-" + id).attr('tabindex', '9');
138 $("#comment-edit-submit-" + id).attr('tabindex', '10');
139 $("#comment-edit-submit-wrapper-" + id).show();
140 // initialize autosize for this comment
141 autosize($("#comment-edit-text-" + id + ".text-autosize"));
144 function commentCloseUI(obj, id) {
145 if (obj.value === '') {
146 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full").addClass("comment-edit-text-empty");
147 $("#comment-edit-text-" + id).removeAttr('tabindex');
148 $("#comment-edit-submit-" + id).removeAttr('tabindex');
149 $("#comment-edit-submit-wrapper-" + id).hide();
150 // destroy the automatic textarea resizing
151 autosize.destroy($("#comment-edit-text-" + id + ".text-autosize"));
155 function jotTextOpenUI(obj) {
156 if (obj.value == '') {
157 $(".modal-body #profile-jot-text").addClass("profile-jot-text-full").removeClass("profile-jot-text-empty");
158 // initiale autosize for the jot
159 autosize($(".modal-body #profile-jot-text"));
163 function jotTextCloseUI(obj) {
164 if (obj.value === '') {
165 $(".modal-body #profile-jot-text").removeClass("profile-jot-text-full").addClass("profile-jot-text-empty");
166 // destroy the automatic textarea resizing
167 autosize.destroy($(".modal-body #profile-jot-text"));
171 function commentOpen(obj, id) {
172 if (obj.value == '') {
173 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
174 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
175 $("#mod-cmnt-wrap-" + id).show();
176 openMenu("comment-edit-submit-wrapper-" + id);
182 function commentInsert(obj, id) {
183 var tmpStr = $("#comment-edit-text-" + id).val();
185 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
186 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
187 openMenu("comment-edit-submit-wrapper-" + id);
189 var ins = $(obj).html();
190 ins = ins.replace('<', '<');
191 ins = ins.replace('>', '>');
192 ins = ins.replace('&', '&');
193 ins = ins.replace('"', '"');
194 $("#comment-edit-text-" + id).val(tmpStr + ins);
197 function qCommentInsert(obj, id) {
198 var tmpStr = $("#comment-edit-text-" + id).val();
200 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
201 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
202 openMenu("comment-edit-submit-wrapper-" + id);
204 var ins = $(obj).val();
205 ins = ins.replace('<', '<');
206 ins = ins.replace('>', '>');
207 ins = ins.replace('&', '&');
208 ins = ins.replace('"', '"');
209 $("#comment-edit-text-" + id).val(tmpStr + ins);
213 function confirmDelete() {
214 return confirm(aStr.delitem);
218 * Hide and removes an item element from the DOM after the deletion url is
219 * successful, restore it else.
221 * @param {string} url The item removal URL
222 * @param {string} elementId The DOM id of the item element
223 * @returns {undefined}
225 function dropItem(url, elementId) {
226 var confirm = confirmDelete();
229 $('body').css('cursor', 'wait');
231 var $el = $(document.getElementById(elementId));
233 $el.fadeTo('fast', 0.33, function () {
234 $.get(url).then(function() {
237 // @todo Show related error message
239 }).always(function() {
240 $('body').css('cursor', 'auto');