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);
12 $("#comment-edit-text-" + id).val(tmpStr);
15 textarea = document.getElementById("comment-edit-text-" +id);
16 if (document.selection) {
18 selected = document.selection.createRange();
19 if (BBcode == "url") {
20 selected.text = "["+BBcode+"]" + "http://" + selected.text + "[/"+BBcode+"]";
22 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
24 } else if (textarea.selectionStart || textarea.selectionStart == "0") {
25 var start = textarea.selectionStart;
26 var end = textarea.selectionEnd;
27 if (BBcode == "url") {
28 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + "http://" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
30 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
38 function showThread(id) {
39 $("#collapsed-comments-" + id).show()
40 $("#collapsed-comments-" + id + " .collapsed-comments").show()
42 function hideThread(id) {
43 $("#collapsed-comments-" + id).hide()
44 $("#collapsed-comments-" + id + " .collapsed-comments").hide()
47 function cmtBbOpen(id) {
48 $("#comment-edit-bb-" + id).show();
50 function cmtBbClose(id) {
51 $("#comment-edit-bb-" + id).hide();
54 function commentExpand(id) {
55 $("#comment-edit-text-" + id).value = '';
56 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
57 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
58 $("#comment-edit-text-" + id).focus();
59 $("#mod-cmnt-wrap-" + id).show();
60 openMenu("comment-edit-submit-wrapper-" + id);
64 function commentClose(obj,id) {
65 if (obj.value == '') {
66 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full");
67 $("#comment-edit-text-" + id).addClass("comment-edit-text-empty");
68 $("#mod-cmnt-wrap-" + id).hide();
69 closeMenu("comment-edit-submit-wrapper-" + id);
75 function showHideCommentBox(id) {
76 if( $('#comment-edit-form-' + id).is(':visible')) {
77 $('#comment-edit-form-' + id).hide();
80 $('#comment-edit-form-' + id).show();
84 function commentOpenUI(obj, id) {
85 $(document).unbind( "click.commentOpen", handler );
87 var handler = function() {
88 if (obj.value == '') {
89 $("#comment-edit-text-" + id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
90 // Choose an arbitrary tab index that's greater than what we're using in jot (3 of them)
91 // The submit button gets tabindex + 1
92 $("#comment-edit-text-" + id).attr('tabindex','9');
93 $("#comment-edit-submit-" + id).attr('tabindex','10');
94 $("#comment-edit-submit-wrapper-" + id).show();
95 // initialize autosize for this comment
96 autosize($("#comment-edit-text-" + id + ".text-autosize"));
100 $(document).bind( "click.commentOpen", handler );
103 function commentCloseUI(obj, id) {
104 $(document).unbind( "click.commentClose", handler );
106 var handler = function() {
107 if (obj.value === '') {
108 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full").addClass("comment-edit-text-empty");
109 $("#comment-edit-text-" + id).removeAttr('tabindex');
110 $("#comment-edit-submit-" + id).removeAttr('tabindex');
111 $("#comment-edit-submit-wrapper-" + id).hide();
112 // destroy the automatic textarea resizing
113 autosize.destroy($("#comment-edit-text-" + id + ".text-autosize"));
117 $(document).bind( "click.commentClose", handler );
120 function jotTextOpenUI(obj) {
121 if (obj.value == '') {
122 $(".modal-body #profile-jot-text").addClass("profile-jot-text-full").removeClass("profile-jot-text-empty");
123 // initiale autosize for the jot
124 autosize($(".modal-body #profile-jot-text"));
128 function jotTextCloseUI(obj) {
129 if (obj.value === '') {
130 $(".modal-body #profile-jot-text").removeClass("profile-jot-text-full").addClass("profile-jot-text-empty");
131 // destroy the automatic textarea resizing
132 autosize.destroy($(".modal-body #profile-jot-text"));
136 function commentOpen(obj,id) {
137 if (obj.value == '') {
138 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
139 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
140 $("#mod-cmnt-wrap-" + id).show();
141 openMenu("comment-edit-submit-wrapper-" + id);
147 function commentInsert(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).html();
155 ins = ins.replace('<','<');
156 ins = ins.replace('>','>');
157 ins = ins.replace('&','&');
158 ins = ins.replace('"','"');
159 $("#comment-edit-text-" + id).val(tmpStr + ins);
162 function qCommentInsert(obj,id) {
163 var tmpStr = $("#comment-edit-text-" + id).val();
165 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
166 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
167 openMenu("comment-edit-submit-wrapper-" + id);
169 var ins = $(obj).val();
170 ins = ins.replace('<','<');
171 ins = ins.replace('>','>');
172 ins = ins.replace('&','&');
173 ins = ins.replace('"','"');
174 $("#comment-edit-text-" + id).val(tmpStr + ins);
178 function confirmDelete() { return confirm(aStr.delitem); }
180 function dropItem(url, object) {
181 var confirm = confirmDelete();
183 //if the first character of the object is #, remove it because
184 // we use getElementById which don't need the #
185 // getElementByID selects elements even if there are special characters
186 // in the ID (like %) which won't work with jQuery
187 /// @todo ceck if we can solve this in the template
188 object = object.indexOf('#') == 0 ? object.substring(1) : object;
191 $('body').css('cursor', 'wait');
192 $(document.getElementById(object)).fadeTo('fast', 0.33, function () {
193 $.get(url).done(function() {
194 $(document.getElementById(object)).remove();
195 $('body').css('cursor', 'auto');