2 * @brief The file contains functions for text editing and commenting
6 function insertFormatting(comment,BBcode,id) {
8 var tmpStr = $("#comment-edit-text-" + id).val();
9 if(tmpStr == comment) {
11 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
12 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
13 openMenu("comment-edit-submit-wrapper-" + id);
14 $("#comment-edit-text-" + id).val(tmpStr);
17 textarea = document.getElementById("comment-edit-text-" +id);
18 if (document.selection) {
20 selected = document.selection.createRange();
22 selected.text = "["+BBcode+"]" + "http://" + selected.text + "[/"+BBcode+"]";
24 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
25 } else if (textarea.selectionStart || textarea.selectionStart == "0") {
26 var start = textarea.selectionStart;
27 var end = textarea.selectionEnd;
29 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + "http://" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
31 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) {
65 obj.value = aStr.comment;
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 == aStr.comment) {
90 $("#comment-edit-text-" + id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
91 // Choose an arbitrary tab index that's greater than what we're using in jot (3 of them)
92 // The submit button gets tabindex + 1
93 $("#comment-edit-text-" + id).attr('tabindex','9');
94 $("#comment-edit-submit-" + id).attr('tabindex','10');
95 $("#comment-edit-submit-wrapper-" + id).show();
96 // initiale autosize for this comment
97 autosize($("#comment-edit-text-" + id + ".text-autosize"));
101 $(document).bind( "click.commentOpen", handler );
104 function commentCloseUI(obj, id) {
105 $(document).unbind( "click.commentClose", handler );
107 var handler = function() {
108 if(obj.value === '') {
109 obj.value = aStr.comment;
110 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full").addClass("comment-edit-text-empty");
111 $("#comment-edit-text-" + id).removeAttr('tabindex');
112 $("#comment-edit-submit-" + id).removeAttr('tabindex');
113 $("#comment-edit-submit-wrapper-" + id).hide();
114 // destroy the automatic textarea resizing
115 autosize.destroy($("#comment-edit-text-" + id + ".text-autosize"));
119 $(document).bind( "click.commentClose", handler );
122 // test if there is default content in the jot text box and remove it
123 function jotTextOpenUI(obj) {
124 if(obj.value == aStr.share) {
126 $(".modal-body #profile-jot-text").addClass("profile-jot-text-full").removeClass("profile-jot-text-empty");
127 // initiale autosize for the jot
128 autosize($(".modal-body #profile-jot-text"));
132 // insert default content into the jot text box
134 function jotTextCloseUI(obj) {
135 if(obj.value === '') {
136 obj.value = aStr.share;
137 $(".modal-body #profile-jot-text").removeClass("profile-jot-text-full").addClass("profile-jot-text-empty");
138 // destroy the automatic textarea resizing
139 autosize.destroy($(".modal-body #profile-jot-text"));
143 function commentOpen(obj,id) {
144 if(obj.value == aStr.comment) {
146 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
147 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
148 $("#mod-cmnt-wrap-" + id).show();
149 openMenu("comment-edit-submit-wrapper-" + id);
155 function commentInsert(obj,id) {
156 var tmpStr = $("#comment-edit-text-" + id).val();
157 if(tmpStr == aStr.comment) {
159 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
160 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
161 openMenu("comment-edit-submit-wrapper-" + id);
163 var ins = $(obj).html();
164 ins = ins.replace('<','<');
165 ins = ins.replace('>','>');
166 ins = ins.replace('&','&');
167 ins = ins.replace('"','"');
168 $("#comment-edit-text-" + id).val(tmpStr + ins);
171 function qCommentInsert(obj,id) {
172 var tmpStr = $("#comment-edit-text-" + id).val();
173 if(tmpStr == aStr.comment) {
175 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
176 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
177 openMenu("comment-edit-submit-wrapper-" + id);
179 var ins = $(obj).val();
180 ins = ins.replace('<','<');
181 ins = ins.replace('>','>');
182 ins = ins.replace('&','&');
183 ins = ins.replace('"','"');
184 $("#comment-edit-text-" + id).val(tmpStr + ins);
188 function confirmDelete() { return confirm(aStr.delitem); }
190 function dropItem(url, object) {
191 var confirm = confirmDelete();
193 //if the first character of the object is #, remove it because
194 // we use getElementById which don't need the #
195 // getElementByID selects elements even if there are special characters
196 // in the ID (like %) which won't work with jQuery
197 /// @todo ceck if we can solve this in the template
198 object = object.indexOf('#') == 0 ? object.substring(1) : object;
201 $('body').css('cursor', 'wait');
202 $(document.getElementById(object)).fadeTo('fast', 0.33, function () {
203 $.get(url).done(function() {
204 $(document.getElementById(object)).remove();
205 $('body').css('cursor', 'auto');