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');
31 function showThread(id) {
32 $("#collapsed-comments-" + id).show()
33 $("#collapsed-comments-" + id + " .collapsed-comments").show()
35 function hideThread(id) {
36 $("#collapsed-comments-" + id).hide()
37 $("#collapsed-comments-" + id + " .collapsed-comments").hide()
40 function cmtBbOpen(id) {
41 $("#comment-edit-bb-" + id).show();
43 function cmtBbClose(id) {
44 $("#comment-edit-bb-" + id).hide();
47 function commentExpand(id) {
48 $("#comment-edit-text-" + id).value = '';
49 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
50 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
51 $("#comment-edit-text-" + id).focus();
52 $("#mod-cmnt-wrap-" + id).show();
53 openMenu("comment-edit-submit-wrapper-" + id);
57 function commentClose(obj, id) {
58 if (obj.value == '') {
59 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full");
60 $("#comment-edit-text-" + id).addClass("comment-edit-text-empty");
61 $("#mod-cmnt-wrap-" + id).hide();
62 closeMenu("comment-edit-submit-wrapper-" + id);
68 function showHideCommentBox(id) {
69 if ($('#comment-edit-form-' + id).is(':visible')) {
70 $('#comment-edit-form-' + id).hide();
72 $('#comment-edit-form-' + id).show();
76 function commentOpenUI(obj, id) {
77 $("#comment-edit-text-" + id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
78 // Choose an arbitrary tab index that's greater than what we're using in jot (3 of them)
79 // The submit button gets tabindex + 1
80 $("#comment-edit-text-" + id).attr('tabindex', '9');
81 $("#comment-edit-submit-" + id).attr('tabindex', '10');
82 $("#comment-edit-submit-wrapper-" + id).show();
83 // initialize autosize for this comment
84 autosize($("#comment-edit-text-" + id + ".text-autosize"));
87 function commentCloseUI(obj, id) {
88 if (obj.value === '') {
89 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full").addClass("comment-edit-text-empty");
90 $("#comment-edit-text-" + id).removeAttr('tabindex');
91 $("#comment-edit-submit-" + id).removeAttr('tabindex');
92 $("#comment-edit-submit-wrapper-" + id).hide();
93 // destroy the automatic textarea resizing
94 autosize.destroy($("#comment-edit-text-" + id + ".text-autosize"));
98 function jotTextOpenUI(obj) {
99 if (obj.value == '') {
100 $(".modal-body #profile-jot-text").addClass("profile-jot-text-full").removeClass("profile-jot-text-empty");
101 // initiale autosize for the jot
102 autosize($(".modal-body #profile-jot-text"));
106 function jotTextCloseUI(obj) {
107 if (obj.value === '') {
108 $(".modal-body #profile-jot-text").removeClass("profile-jot-text-full").addClass("profile-jot-text-empty");
109 // destroy the automatic textarea resizing
110 autosize.destroy($(".modal-body #profile-jot-text"));
114 function commentOpen(obj, id) {
115 if (obj.value == '') {
116 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
117 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
118 $("#mod-cmnt-wrap-" + id).show();
119 openMenu("comment-edit-submit-wrapper-" + id);
125 function commentInsert(obj, id) {
126 var tmpStr = $("#comment-edit-text-" + id).val();
128 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
129 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
130 openMenu("comment-edit-submit-wrapper-" + id);
132 var ins = $(obj).html();
133 ins = ins.replace('<', '<');
134 ins = ins.replace('>', '>');
135 ins = ins.replace('&', '&');
136 ins = ins.replace('"', '"');
137 $("#comment-edit-text-" + id).val(tmpStr + ins);
140 function qCommentInsert(obj, id) {
141 var tmpStr = $("#comment-edit-text-" + id).val();
143 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
144 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
145 openMenu("comment-edit-submit-wrapper-" + id);
147 var ins = $(obj).val();
148 ins = ins.replace('<', '<');
149 ins = ins.replace('>', '>');
150 ins = ins.replace('&', '&');
151 ins = ins.replace('"', '"');
152 $("#comment-edit-text-" + id).val(tmpStr + ins);
156 function confirmDelete() {
157 return confirm(aStr.delitem);
161 * Hide and removes an item element from the DOM after the deletion url is
162 * successful, restore it else.
164 * @param {string} url The item removal URL
165 * @param {string} elementId The DOM id of the item element
166 * @returns {undefined}
168 function dropItem(url, elementId) {
169 var confirm = confirmDelete();
172 $('body').css('cursor', 'wait');
174 var $el = $(document.getElementById(elementId));
176 $el.fadeTo('fast', 0.33, function () {
177 $.get(url).then(function() {
180 // @todo Show related error message
182 }).always(function() {
183 $('body').css('cursor', 'auto');