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 if (BBcode == "url") {
19 selected.text = "["+BBcode+"]" + "http://" + selected.text + "[/"+BBcode+"]";
21 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
23 } else if (textarea.selectionStart || textarea.selectionStart == "0") {
24 var start = textarea.selectionStart;
25 var end = textarea.selectionEnd;
26 if (BBcode == "url") {
27 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + "http://" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
29 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
33 $(textarea).trigger('change');
39 function showThread(id) {
40 $("#collapsed-comments-" + id).show()
41 $("#collapsed-comments-" + id + " .collapsed-comments").show()
43 function hideThread(id) {
44 $("#collapsed-comments-" + id).hide()
45 $("#collapsed-comments-" + id + " .collapsed-comments").hide()
48 function cmtBbOpen(id) {
49 $("#comment-edit-bb-" + id).show();
51 function cmtBbClose(id) {
52 $("#comment-edit-bb-" + id).hide();
55 function commentExpand(id) {
56 $("#comment-edit-text-" + id).value = '';
57 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
58 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
59 $("#comment-edit-text-" + id).focus();
60 $("#mod-cmnt-wrap-" + id).show();
61 openMenu("comment-edit-submit-wrapper-" + id);
65 function commentClose(obj, id) {
66 if (obj.value == '') {
67 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full");
68 $("#comment-edit-text-" + id).addClass("comment-edit-text-empty");
69 $("#mod-cmnt-wrap-" + id).hide();
70 closeMenu("comment-edit-submit-wrapper-" + id);
76 function showHideCommentBox(id) {
77 if ($('#comment-edit-form-' + id).is(':visible')) {
78 $('#comment-edit-form-' + id).hide();
80 $('#comment-edit-form-' + id).show();
84 function commentOpenUI(obj, id) {
85 $("#comment-edit-text-" + id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
86 // Choose an arbitrary tab index that's greater than what we're using in jot (3 of them)
87 // The submit button gets tabindex + 1
88 $("#comment-edit-text-" + id).attr('tabindex', '9');
89 $("#comment-edit-submit-" + id).attr('tabindex', '10');
90 $("#comment-edit-submit-wrapper-" + id).show();
91 // initialize autosize for this comment
92 autosize($("#comment-edit-text-" + id + ".text-autosize"));
95 function commentCloseUI(obj, id) {
96 if (obj.value === '') {
97 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full").addClass("comment-edit-text-empty");
98 $("#comment-edit-text-" + id).removeAttr('tabindex');
99 $("#comment-edit-submit-" + id).removeAttr('tabindex');
100 $("#comment-edit-submit-wrapper-" + id).hide();
101 // destroy the automatic textarea resizing
102 autosize.destroy($("#comment-edit-text-" + id + ".text-autosize"));
106 function jotTextOpenUI(obj) {
107 if (obj.value == '') {
108 $(".modal-body #profile-jot-text").addClass("profile-jot-text-full").removeClass("profile-jot-text-empty");
109 // initiale autosize for the jot
110 autosize($(".modal-body #profile-jot-text"));
114 function jotTextCloseUI(obj) {
115 if (obj.value === '') {
116 $(".modal-body #profile-jot-text").removeClass("profile-jot-text-full").addClass("profile-jot-text-empty");
117 // destroy the automatic textarea resizing
118 autosize.destroy($(".modal-body #profile-jot-text"));
122 function commentOpen(obj, id) {
123 if (obj.value == '') {
124 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
125 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
126 $("#mod-cmnt-wrap-" + id).show();
127 openMenu("comment-edit-submit-wrapper-" + id);
133 function commentInsert(obj, id) {
134 var tmpStr = $("#comment-edit-text-" + id).val();
136 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
137 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
138 openMenu("comment-edit-submit-wrapper-" + id);
140 var ins = $(obj).html();
141 ins = ins.replace('<', '<');
142 ins = ins.replace('>', '>');
143 ins = ins.replace('&', '&');
144 ins = ins.replace('"', '"');
145 $("#comment-edit-text-" + id).val(tmpStr + ins);
148 function qCommentInsert(obj, id) {
149 var tmpStr = $("#comment-edit-text-" + id).val();
151 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
152 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
153 openMenu("comment-edit-submit-wrapper-" + id);
155 var ins = $(obj).val();
156 ins = ins.replace('<', '<');
157 ins = ins.replace('>', '>');
158 ins = ins.replace('&', '&');
159 ins = ins.replace('"', '"');
160 $("#comment-edit-text-" + id).val(tmpStr + ins);
164 function confirmDelete() {
165 return confirm(aStr.delitem);
169 * Hide and removes an item element from the DOM after the deletion url is
170 * successful, restore it else.
172 * @param {string} url The item removal URL
173 * @param {string} elementId The DOM id of the item element
174 * @returns {undefined}
176 function dropItem(url, elementId) {
177 var confirm = confirmDelete();
180 $('body').css('cursor', 'wait');
182 var $el = $(document.getElementById(elementId));
184 $el.fadeTo('fast', 0.33, function () {
185 $.get(url).then(function() {
188 // @todo Show related error message
190 }).always(function() {
191 $('body').css('cursor', 'auto');