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);
37 function showThread(id) {
38 $("#collapsed-comments-" + id).show()
39 $("#collapsed-comments-" + id + " .collapsed-comments").show()
41 function hideThread(id) {
42 $("#collapsed-comments-" + id).hide()
43 $("#collapsed-comments-" + id + " .collapsed-comments").hide()
46 function cmtBbOpen(id) {
47 $("#comment-edit-bb-" + id).show();
49 function cmtBbClose(id) {
50 $("#comment-edit-bb-" + id).hide();
53 function commentExpand(id) {
54 $("#comment-edit-text-" + id).value = '';
55 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
56 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
57 $("#comment-edit-text-" + id).focus();
58 $("#mod-cmnt-wrap-" + id).show();
59 openMenu("comment-edit-submit-wrapper-" + id);
63 function commentClose(obj,id) {
64 if (obj.value == '') {
65 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full");
66 $("#comment-edit-text-" + id).addClass("comment-edit-text-empty");
67 $("#mod-cmnt-wrap-" + id).hide();
68 closeMenu("comment-edit-submit-wrapper-" + id);
74 function showHideCommentBox(id) {
75 if( $('#comment-edit-form-' + id).is(':visible')) {
76 $('#comment-edit-form-' + id).hide();
79 $('#comment-edit-form-' + id).show();
83 function commentOpenUI(obj, id) {
84 $("#comment-edit-text-" + id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
85 // Choose an arbitrary tab index that's greater than what we're using in jot (3 of them)
86 // The submit button gets tabindex + 1
87 $("#comment-edit-text-" + id).attr('tabindex','9');
88 $("#comment-edit-submit-" + id).attr('tabindex','10');
89 $("#comment-edit-submit-wrapper-" + id).show();
90 // initialize autosize for this comment
91 autosize($("#comment-edit-text-" + id + ".text-autosize"));
94 function commentCloseUI(obj, id) {
95 if (obj.value === '') {
96 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full").addClass("comment-edit-text-empty");
97 $("#comment-edit-text-" + id).removeAttr('tabindex');
98 $("#comment-edit-submit-" + id).removeAttr('tabindex');
99 $("#comment-edit-submit-wrapper-" + id).hide();
100 // destroy the automatic textarea resizing
101 autosize.destroy($("#comment-edit-text-" + id + ".text-autosize"));
105 function jotTextOpenUI(obj) {
106 if (obj.value == '') {
107 $(".modal-body #profile-jot-text").addClass("profile-jot-text-full").removeClass("profile-jot-text-empty");
108 // initiale autosize for the jot
109 autosize($(".modal-body #profile-jot-text"));
113 function jotTextCloseUI(obj) {
114 if (obj.value === '') {
115 $(".modal-body #profile-jot-text").removeClass("profile-jot-text-full").addClass("profile-jot-text-empty");
116 // destroy the automatic textarea resizing
117 autosize.destroy($(".modal-body #profile-jot-text"));
121 function commentOpen(obj,id) {
122 if (obj.value == '') {
123 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
124 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
125 $("#mod-cmnt-wrap-" + id).show();
126 openMenu("comment-edit-submit-wrapper-" + id);
132 function commentInsert(obj,id) {
133 var tmpStr = $("#comment-edit-text-" + id).val();
135 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
136 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
137 openMenu("comment-edit-submit-wrapper-" + id);
139 var ins = $(obj).html();
140 ins = ins.replace('<','<');
141 ins = ins.replace('>','>');
142 ins = ins.replace('&','&');
143 ins = ins.replace('"','"');
144 $("#comment-edit-text-" + id).val(tmpStr + ins);
147 function qCommentInsert(obj,id) {
148 var tmpStr = $("#comment-edit-text-" + id).val();
150 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
151 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
152 openMenu("comment-edit-submit-wrapper-" + id);
154 var ins = $(obj).val();
155 ins = ins.replace('<','<');
156 ins = ins.replace('>','>');
157 ins = ins.replace('&','&');
158 ins = ins.replace('"','"');
159 $("#comment-edit-text-" + id).val(tmpStr + ins);
163 function confirmDelete() { return confirm(aStr.delitem); }
166 * Hide and removes an item element from the DOM after the deletion url is
167 * successful, restore it else.
169 * @param {string} url The item removal URL
170 * @param {string} elementId The DOM id of the item element
171 * @returns {undefined}
173 function dropItem(url, elementId) {
174 var confirm = confirmDelete();
177 $('body').css('cursor', 'wait');
179 var $el = $(document.getElementById(elementId));
181 $el.fadeTo('fast', 0.33, function () {
182 $.get(url).then(function() {
185 // @todo Show related error message
187 }).always(function() {
188 $('body').css('cursor', 'auto');