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();
81 $('#comment-edit-form-' + id).show();
85 function commentOpenUI(obj, id) {
86 $("#comment-edit-text-" + id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
87 // Choose an arbitrary tab index that's greater than what we're using in jot (3 of them)
88 // The submit button gets tabindex + 1
89 $("#comment-edit-text-" + id).attr('tabindex','9');
90 $("#comment-edit-submit-" + id).attr('tabindex','10');
91 $("#comment-edit-submit-wrapper-" + id).show();
92 // initialize autosize for this comment
93 autosize($("#comment-edit-text-" + id + ".text-autosize"));
96 function commentCloseUI(obj, id) {
97 if (obj.value === '') {
98 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full").addClass("comment-edit-text-empty");
99 $("#comment-edit-text-" + id).removeAttr('tabindex');
100 $("#comment-edit-submit-" + id).removeAttr('tabindex');
101 $("#comment-edit-submit-wrapper-" + id).hide();
102 // destroy the automatic textarea resizing
103 autosize.destroy($("#comment-edit-text-" + id + ".text-autosize"));
107 function jotTextOpenUI(obj) {
108 if (obj.value == '') {
109 $(".modal-body #profile-jot-text").addClass("profile-jot-text-full").removeClass("profile-jot-text-empty");
110 // initiale autosize for the jot
111 autosize($(".modal-body #profile-jot-text"));
115 function jotTextCloseUI(obj) {
116 if (obj.value === '') {
117 $(".modal-body #profile-jot-text").removeClass("profile-jot-text-full").addClass("profile-jot-text-empty");
118 // destroy the automatic textarea resizing
119 autosize.destroy($(".modal-body #profile-jot-text"));
123 function commentOpen(obj,id) {
124 if (obj.value == '') {
125 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
126 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
127 $("#mod-cmnt-wrap-" + id).show();
128 openMenu("comment-edit-submit-wrapper-" + id);
134 function commentInsert(obj,id) {
135 var tmpStr = $("#comment-edit-text-" + id).val();
137 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
138 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
139 openMenu("comment-edit-submit-wrapper-" + id);
141 var ins = $(obj).html();
142 ins = ins.replace('<','<');
143 ins = ins.replace('>','>');
144 ins = ins.replace('&','&');
145 ins = ins.replace('"','"');
146 $("#comment-edit-text-" + id).val(tmpStr + ins);
149 function qCommentInsert(obj,id) {
150 var tmpStr = $("#comment-edit-text-" + id).val();
152 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
153 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
154 openMenu("comment-edit-submit-wrapper-" + id);
156 var ins = $(obj).val();
157 ins = ins.replace('<','<');
158 ins = ins.replace('>','>');
159 ins = ins.replace('&','&');
160 ins = ins.replace('"','"');
161 $("#comment-edit-text-" + id).val(tmpStr + ins);
165 function confirmDelete() { return confirm(aStr.delitem); }
168 * Hide and removes an item element from the DOM after the deletion url is
169 * successful, restore it else.
171 * @param {string} url The item removal URL
172 * @param {string} elementId The DOM id of the item element
173 * @returns {undefined}
175 function dropItem(url, elementId) {
176 var confirm = confirmDelete();
179 $('body').css('cursor', 'wait');
181 var $el = $(document.getElementById(elementId));
183 $el.fadeTo('fast', 0.33, function () {
184 $.get(url).then(function() {
187 // @todo Show related error message
189 }).always(function() {
190 $('body').css('cursor', 'auto');