2 * @brief The file contains functions for text editing and commenting
6 function insertFormatting(BBcode, id) {
7 var tmpStr = $("#comment-edit-text-" + id).val();
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);
14 textarea = document.getElementById("comment-edit-text-" + id);
15 if (document.selection) {
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);
25 $(textarea).trigger('change');
30 function insertFormattingToPost(BBcode) {
31 textarea = document.getElementById("profile-jot-text");
32 if (document.selection) {
34 selected = document.selection.createRange();
35 selected.text = "[" + BBcode + "]" + selected.text + "[/" + BBcode + "]";
36 } else if (textarea.selectionStart || textarea.selectionStart == "0") {
37 var start = textarea.selectionStart;
38 var end = textarea.selectionEnd;
39 textarea.value = textarea.value.substring(0, start) + "[" + BBcode + "]" + textarea.value.substring(start, end) + "[/" + BBcode + "]" + textarea.value.substring(end, textarea.value.length);
42 $(textarea).trigger('change');
47 function showThread(id) {
48 $("#collapsed-comments-" + id).show()
49 $("#collapsed-comments-" + id + " .collapsed-comments").show()
51 function hideThread(id) {
52 $("#collapsed-comments-" + id).hide()
53 $("#collapsed-comments-" + id + " .collapsed-comments").hide()
56 function cmtBbOpen(id) {
57 $("#comment-edit-bb-" + id).show();
59 function cmtBbClose(id) {
60 $("#comment-edit-bb-" + id).hide();
63 function commentExpand(id) {
64 $("#comment-edit-text-" + id).value = '';
65 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
66 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
67 $("#comment-edit-text-" + id).focus();
68 $("#mod-cmnt-wrap-" + id).show();
69 openMenu("comment-edit-submit-wrapper-" + id);
73 function commentClose(obj, id) {
74 if (obj.value == '') {
75 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full");
76 $("#comment-edit-text-" + id).addClass("comment-edit-text-empty");
77 $("#mod-cmnt-wrap-" + id).hide();
78 closeMenu("comment-edit-submit-wrapper-" + id);
84 function showHideCommentBox(id) {
85 if ($('#comment-edit-form-' + id).is(':visible')) {
86 $('#comment-edit-form-' + id).hide();
88 $('#comment-edit-form-' + id).show();
92 function commentOpenUI(obj, id) {
93 $("#comment-edit-text-" + id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
94 // Choose an arbitrary tab index that's greater than what we're using in jot (3 of them)
95 // The submit button gets tabindex + 1
96 $("#comment-edit-text-" + id).attr('tabindex', '9');
97 $("#comment-edit-submit-" + id).attr('tabindex', '10');
98 $("#comment-edit-submit-wrapper-" + id).show();
99 // initialize autosize for this comment
100 autosize($("#comment-edit-text-" + id + ".text-autosize"));
103 function commentCloseUI(obj, id) {
104 if (obj.value === '') {
105 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full").addClass("comment-edit-text-empty");
106 $("#comment-edit-text-" + id).removeAttr('tabindex');
107 $("#comment-edit-submit-" + id).removeAttr('tabindex');
108 $("#comment-edit-submit-wrapper-" + id).hide();
109 // destroy the automatic textarea resizing
110 autosize.destroy($("#comment-edit-text-" + id + ".text-autosize"));
114 function jotTextOpenUI(obj) {
115 if (obj.value == '') {
116 $(".modal-body #profile-jot-text").addClass("profile-jot-text-full").removeClass("profile-jot-text-empty");
117 // initiale autosize for the jot
118 autosize($(".modal-body #profile-jot-text"));
122 function jotTextCloseUI(obj) {
123 if (obj.value === '') {
124 $(".modal-body #profile-jot-text").removeClass("profile-jot-text-full").addClass("profile-jot-text-empty");
125 // destroy the automatic textarea resizing
126 autosize.destroy($(".modal-body #profile-jot-text"));
130 function commentOpen(obj, id) {
131 if (obj.value == '') {
132 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
133 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
134 $("#mod-cmnt-wrap-" + id).show();
135 openMenu("comment-edit-submit-wrapper-" + id);
141 function commentInsert(obj, id) {
142 var tmpStr = $("#comment-edit-text-" + id).val();
144 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
145 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
146 openMenu("comment-edit-submit-wrapper-" + id);
148 var ins = $(obj).html();
149 ins = ins.replace('<', '<');
150 ins = ins.replace('>', '>');
151 ins = ins.replace('&', '&');
152 ins = ins.replace('"', '"');
153 $("#comment-edit-text-" + id).val(tmpStr + ins);
156 function qCommentInsert(obj, id) {
157 var tmpStr = $("#comment-edit-text-" + id).val();
159 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
160 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
161 openMenu("comment-edit-submit-wrapper-" + id);
163 var ins = $(obj).val();
164 ins = ins.replace('<', '<');
165 ins = ins.replace('>', '>');
166 ins = ins.replace('&', '&');
167 ins = ins.replace('"', '"');
168 $("#comment-edit-text-" + id).val(tmpStr + ins);
172 function confirmDelete() {
173 return confirm(aStr.delitem);
177 * Hide and removes an item element from the DOM after the deletion url is
178 * successful, restore it else.
180 * @param {string} url The item removal URL
181 * @param {string} elementId The DOM id of the item element
182 * @returns {undefined}
184 function dropItem(url, elementId) {
185 var confirm = confirmDelete();
188 $('body').css('cursor', 'wait');
190 var $el = $(document.getElementById(elementId));
192 $el.fadeTo('fast', 0.33, function () {
193 $.get(url).then(function() {
196 // @todo Show related error message
198 }).always(function() {
199 $('body').css('cursor', 'auto');