2 * @brief The file contains functions for text editing and commenting
5 function initComment(callback) {
6 if (typeof callback != "undefined") {
11 function commentGetLink(id) {
12 reply = prompt("Please enter a link URL:");
13 if(reply && reply.length) {
14 reply = bin2hex(reply);
15 $.get('parse_url?isComment=1&binurl=' + reply, function(data) {
16 addcommenttext(data, id);
21 function addcommenttext(data, id) {
23 var textfield = document.getElementById("comment-edit-text-" + id);
24 // check if the textfield does have the default-value
25 commentOpenUI(textfield, id);
26 // save already existent content
27 var currentText = $("#comment-edit-text-" + id).val();
28 //insert the data as new value
29 textfield.value = currentText + data;
30 autosize.update($("#comment-edit-text-" + id));
33 function commentlinkdrop(event, id) {
34 var reply = event.dataTransfer.getData("text/uri-list");
35 event.target.textContent = reply;
36 event.preventDefault();
37 if(reply && reply.length) {
38 reply = bin2hex(reply);
39 $.get('parse_url?isComment=1&binurl=' + reply, function(data) {
40 if (!editor) $("comment-edit-text-" + id).val("");
41 initComment(function(){
42 addcommenttext(data, id);
48 function commentlinkdropper(event) {
49 var linkFound = event.dataTransfer.types.contains("text/uri-list");
51 event.preventDefault();
55 function insertFormatting(BBcode, id) {
56 var tmpStr = $("#comment-edit-text-" + id).val();
58 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
59 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
60 openMenu("comment-edit-submit-wrapper-" + id);
63 textarea = document.getElementById("comment-edit-text-" + id);
64 if (document.selection) {
66 selected = document.selection.createRange();
67 selected.text = "[" + BBcode + "]" + selected.text + "[/" + BBcode + "]";
68 } else if (textarea.selectionStart || textarea.selectionStart == "0") {
69 var start = textarea.selectionStart;
70 var end = textarea.selectionEnd;
71 textarea.value = textarea.value.substring(0, start) + "[" + BBcode + "]" + textarea.value.substring(start, end) + "[/" + BBcode + "]" + textarea.value.substring(end, textarea.value.length);
74 $(textarea).trigger('change');
79 function insertFormattingToPost(BBcode) {
80 textarea = document.getElementById("profile-jot-text");
81 if (document.selection) {
83 selected = document.selection.createRange();
84 selected.text = "[" + BBcode + "]" + selected.text + "[/" + BBcode + "]";
85 } else if (textarea.selectionStart || textarea.selectionStart == "0") {
86 var start = textarea.selectionStart;
87 var end = textarea.selectionEnd;
88 textarea.value = textarea.value.substring(0, start) + "[" + BBcode + "]" + textarea.value.substring(start, end) + "[/" + BBcode + "]" + textarea.value.substring(end, textarea.value.length);
91 $(textarea).trigger('change');
96 function showThread(id) {
97 $("#collapsed-comments-" + id).show()
98 $("#collapsed-comments-" + id + " .collapsed-comments").show()
100 function hideThread(id) {
101 $("#collapsed-comments-" + id).hide()
102 $("#collapsed-comments-" + id + " .collapsed-comments").hide()
105 function cmtBbOpen(id) {
106 $("#comment-edit-bb-" + id).show();
108 function cmtBbClose(id) {
109 $("#comment-edit-bb-" + id).hide();
112 function commentExpand(id) {
113 $("#comment-edit-text-" + id).value = '';
114 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
115 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
116 $("#comment-edit-text-" + id).focus();
117 $("#mod-cmnt-wrap-" + id).show();
118 openMenu("comment-edit-submit-wrapper-" + id);
122 function commentClose(obj, id) {
123 if (obj.value == '') {
124 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full");
125 $("#comment-edit-text-" + id).addClass("comment-edit-text-empty");
126 $("#mod-cmnt-wrap-" + id).hide();
127 closeMenu("comment-edit-submit-wrapper-" + id);
133 function showHideCommentBox(id) {
134 if ($('#comment-edit-form-' + id).is(':visible')) {
135 $('#comment-edit-form-' + id).hide();
137 $('#comment-edit-form-' + id).show();
141 function commentOpenUI(obj, id) {
142 $("#comment-edit-text-" + id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
143 // Choose an arbitrary tab index that's greater than what we're using in jot (3 of them)
144 // The submit button gets tabindex + 1
145 $("#comment-edit-text-" + id).attr('tabindex', '9');
146 $("#comment-edit-submit-" + id).attr('tabindex', '10');
147 $("#comment-edit-submit-wrapper-" + id).show();
148 // initialize autosize for this comment
149 autosize($("#comment-edit-text-" + id + ".text-autosize"));
152 function commentCloseUI(obj, id) {
153 if (obj.value === '') {
154 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full").addClass("comment-edit-text-empty");
155 $("#comment-edit-text-" + id).removeAttr('tabindex');
156 $("#comment-edit-submit-" + id).removeAttr('tabindex');
157 $("#comment-edit-submit-wrapper-" + id).hide();
158 // destroy the automatic textarea resizing
159 autosize.destroy($("#comment-edit-text-" + id + ".text-autosize"));
163 function jotTextOpenUI(obj) {
164 if (obj.value == '') {
165 $(".modal-body #profile-jot-text").addClass("profile-jot-text-full").removeClass("profile-jot-text-empty");
166 // initiale autosize for the jot
167 autosize($(".modal-body #profile-jot-text"));
171 function jotTextCloseUI(obj) {
172 if (obj.value === '') {
173 $(".modal-body #profile-jot-text").removeClass("profile-jot-text-full").addClass("profile-jot-text-empty");
174 // destroy the automatic textarea resizing
175 autosize.destroy($(".modal-body #profile-jot-text"));
179 function commentOpen(obj, id) {
180 if (obj.value == '') {
181 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
182 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
183 $("#mod-cmnt-wrap-" + id).show();
184 openMenu("comment-edit-submit-wrapper-" + id);
190 function commentInsert(obj, id) {
191 var tmpStr = $("#comment-edit-text-" + id).val();
193 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
194 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
195 openMenu("comment-edit-submit-wrapper-" + id);
197 var ins = $(obj).html();
198 ins = ins.replace('<', '<');
199 ins = ins.replace('>', '>');
200 ins = ins.replace('&', '&');
201 ins = ins.replace('"', '"');
202 $("#comment-edit-text-" + id).val(tmpStr + ins);
205 function qCommentInsert(obj, id) {
206 var tmpStr = $("#comment-edit-text-" + id).val();
208 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
209 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
210 openMenu("comment-edit-submit-wrapper-" + id);
212 var ins = $(obj).val();
213 ins = ins.replace('<', '<');
214 ins = ins.replace('>', '>');
215 ins = ins.replace('&', '&');
216 ins = ins.replace('"', '"');
217 $("#comment-edit-text-" + id).val(tmpStr + ins);
221 function confirmDelete() {
222 return confirm(aStr.delitem);
226 * Hide and removes an item element from the DOM after the deletion url is
227 * successful, restore it else.
229 * @param {string} url The item removal URL
230 * @param {string} elementId The DOM id of the item element
231 * @returns {undefined}
233 function dropItem(url, elementId) {
234 var confirm = confirmDelete();
237 $('body').css('cursor', 'wait');
239 var $el = $(document.getElementById(elementId));
241 $el.fadeTo('fast', 0.33, function () {
242 $.get(url).then(function() {
245 // @todo Show related error message
247 }).always(function() {
248 $('body').css('cursor', 'auto');