2 * @brief The file contains functions for text editing and commenting
5 function commentGetLink(id) {
6 reply = prompt("Please enter a link URL:");
7 if(reply && reply.length) {
8 reply = bin2hex(reply);
9 $.get('parse_url?isComment=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?isComment=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();
46 function insertFormatting(BBcode, id) {
47 var tmpStr = $("#comment-edit-text-" + id).val();
49 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
50 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
51 openMenu("comment-edit-submit-wrapper-" + id);
54 textarea = document.getElementById("comment-edit-text-" + id);
55 if (document.selection) {
57 selected = document.selection.createRange();
58 selected.text = "[" + BBcode + "]" + selected.text + "[/" + BBcode + "]";
59 } else if (textarea.selectionStart || textarea.selectionStart == "0") {
60 var start = textarea.selectionStart;
61 var end = textarea.selectionEnd;
62 textarea.value = textarea.value.substring(0, start) + "[" + BBcode + "]" + textarea.value.substring(start, end) + "[/" + BBcode + "]" + textarea.value.substring(end, textarea.value.length);
65 $(textarea).trigger('change');
70 function insertFormattingToPost(BBcode) {
71 textarea = document.getElementById("profile-jot-text");
72 if (document.selection) {
74 selected = document.selection.createRange();
75 selected.text = "[" + BBcode + "]" + selected.text + "[/" + BBcode + "]";
76 } else if (textarea.selectionStart || textarea.selectionStart == "0") {
77 var start = textarea.selectionStart;
78 var end = textarea.selectionEnd;
79 textarea.value = textarea.value.substring(0, start) + "[" + BBcode + "]" + textarea.value.substring(start, end) + "[/" + BBcode + "]" + textarea.value.substring(end, textarea.value.length);
82 $(textarea).trigger('change');
87 function showThread(id) {
88 $("#collapsed-comments-" + id).show()
89 $("#collapsed-comments-" + id + " .collapsed-comments").show()
91 function hideThread(id) {
92 $("#collapsed-comments-" + id).hide()
93 $("#collapsed-comments-" + id + " .collapsed-comments").hide()
96 function cmtBbOpen(id) {
97 $("#comment-edit-bb-" + id).show();
99 function cmtBbClose(id) {
100 $("#comment-edit-bb-" + id).hide();
103 function commentExpand(id) {
104 $("#comment-edit-text-" + id).value = '';
105 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
106 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
107 $("#comment-edit-text-" + id).focus();
108 $("#mod-cmnt-wrap-" + id).show();
109 openMenu("comment-edit-submit-wrapper-" + id);
113 function commentClose(obj, id) {
114 if (obj.value == '') {
115 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full");
116 $("#comment-edit-text-" + id).addClass("comment-edit-text-empty");
117 $("#mod-cmnt-wrap-" + id).hide();
118 closeMenu("comment-edit-submit-wrapper-" + id);
124 function showHideCommentBox(id) {
125 if ($('#comment-edit-form-' + id).is(':visible')) {
126 $('#comment-edit-form-' + id).hide();
128 $('#comment-edit-form-' + id).show();
132 function commentOpenUI(obj, id) {
133 $("#comment-edit-text-" + id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
134 // Choose an arbitrary tab index that's greater than what we're using in jot (3 of them)
135 // The submit button gets tabindex + 1
136 $("#comment-edit-text-" + id).attr('tabindex', '9');
137 $("#comment-edit-submit-" + id).attr('tabindex', '10');
138 $("#comment-edit-submit-wrapper-" + id).show();
139 // initialize autosize for this comment
140 autosize($("#comment-edit-text-" + id + ".text-autosize"));
143 function commentCloseUI(obj, id) {
144 if (obj.value === '') {
145 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full").addClass("comment-edit-text-empty");
146 $("#comment-edit-text-" + id).removeAttr('tabindex');
147 $("#comment-edit-submit-" + id).removeAttr('tabindex');
148 $("#comment-edit-submit-wrapper-" + id).hide();
149 // destroy the automatic textarea resizing
150 autosize.destroy($("#comment-edit-text-" + id + ".text-autosize"));
154 function jotTextOpenUI(obj) {
155 if (obj.value == '') {
156 $(".modal-body #profile-jot-text").addClass("profile-jot-text-full").removeClass("profile-jot-text-empty");
157 // initiale autosize for the jot
158 autosize($(".modal-body #profile-jot-text"));
162 function jotTextCloseUI(obj) {
163 if (obj.value === '') {
164 $(".modal-body #profile-jot-text").removeClass("profile-jot-text-full").addClass("profile-jot-text-empty");
165 // destroy the automatic textarea resizing
166 autosize.destroy($(".modal-body #profile-jot-text"));
170 function commentOpen(obj, id) {
171 if (obj.value == '') {
172 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
173 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
174 $("#mod-cmnt-wrap-" + id).show();
175 openMenu("comment-edit-submit-wrapper-" + id);
181 function commentInsert(obj, id) {
182 var tmpStr = $("#comment-edit-text-" + id).val();
184 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
185 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
186 openMenu("comment-edit-submit-wrapper-" + id);
188 var ins = $(obj).html();
189 ins = ins.replace('<', '<');
190 ins = ins.replace('>', '>');
191 ins = ins.replace('&', '&');
192 ins = ins.replace('"', '"');
193 $("#comment-edit-text-" + id).val(tmpStr + ins);
196 function qCommentInsert(obj, id) {
197 var tmpStr = $("#comment-edit-text-" + id).val();
199 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
200 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
201 openMenu("comment-edit-submit-wrapper-" + id);
203 var ins = $(obj).val();
204 ins = ins.replace('<', '<');
205 ins = ins.replace('>', '>');
206 ins = ins.replace('&', '&');
207 ins = ins.replace('"', '"');
208 $("#comment-edit-text-" + id).val(tmpStr + ins);
212 function confirmDelete() {
213 return confirm(aStr.delitem);
217 * Hide and removes an item element from the DOM after the deletion url is
218 * successful, restore it else.
220 * @param {string} url The item removal URL
221 * @param {string} elementId The DOM id of the item element
222 * @returns {undefined}
224 function dropItem(url, elementId) {
225 var confirm = confirmDelete();
228 $('body').css('cursor', 'wait');
230 var $el = $(document.getElementById(elementId));
232 $el.fadeTo('fast', 0.33, function () {
233 $.get(url).then(function() {
236 // @todo Show related error message
238 }).always(function() {
239 $('body').css('cursor', 'auto');