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 $(document).unbind( "click.commentOpen", handler );
86 var handler = function() {
87 if (obj.value == '') {
88 $("#comment-edit-text-" + id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
89 // Choose an arbitrary tab index that's greater than what we're using in jot (3 of them)
90 // The submit button gets tabindex + 1
91 $("#comment-edit-text-" + id).attr('tabindex','9');
92 $("#comment-edit-submit-" + id).attr('tabindex','10');
93 $("#comment-edit-submit-wrapper-" + id).show();
94 // initialize autosize for this comment
95 autosize($("#comment-edit-text-" + id + ".text-autosize"));
99 $(document).bind( "click.commentOpen", handler );
102 function commentCloseUI(obj, id) {
103 $(document).unbind( "click.commentClose", handler );
105 var handler = function() {
106 if (obj.value === '') {
107 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full").addClass("comment-edit-text-empty");
108 $("#comment-edit-text-" + id).removeAttr('tabindex');
109 $("#comment-edit-submit-" + id).removeAttr('tabindex');
110 $("#comment-edit-submit-wrapper-" + id).hide();
111 // destroy the automatic textarea resizing
112 autosize.destroy($("#comment-edit-text-" + id + ".text-autosize"));
116 $(document).bind( "click.commentClose", handler );
119 function jotTextOpenUI(obj) {
120 if (obj.value == '') {
121 $(".modal-body #profile-jot-text").addClass("profile-jot-text-full").removeClass("profile-jot-text-empty");
122 // initiale autosize for the jot
123 autosize($(".modal-body #profile-jot-text"));
127 function jotTextCloseUI(obj) {
128 if (obj.value === '') {
129 $(".modal-body #profile-jot-text").removeClass("profile-jot-text-full").addClass("profile-jot-text-empty");
130 // destroy the automatic textarea resizing
131 autosize.destroy($(".modal-body #profile-jot-text"));
135 function commentOpen(obj,id) {
136 if (obj.value == '') {
137 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
138 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
139 $("#mod-cmnt-wrap-" + id).show();
140 openMenu("comment-edit-submit-wrapper-" + id);
146 function commentInsert(obj,id) {
147 var tmpStr = $("#comment-edit-text-" + id).val();
149 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
150 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
151 openMenu("comment-edit-submit-wrapper-" + id);
153 var ins = $(obj).html();
154 ins = ins.replace('<','<');
155 ins = ins.replace('>','>');
156 ins = ins.replace('&','&');
157 ins = ins.replace('"','"');
158 $("#comment-edit-text-" + id).val(tmpStr + ins);
161 function qCommentInsert(obj,id) {
162 var tmpStr = $("#comment-edit-text-" + id).val();
164 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
165 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
166 openMenu("comment-edit-submit-wrapper-" + id);
168 var ins = $(obj).val();
169 ins = ins.replace('<','<');
170 ins = ins.replace('>','>');
171 ins = ins.replace('&','&');
172 ins = ins.replace('"','"');
173 $("#comment-edit-text-" + id).val(tmpStr + ins);
177 function confirmDelete() { return confirm(aStr.delitem); }
179 function dropItem(url, object) {
180 var confirm = confirmDelete();
182 //if the first character of the object is #, remove it because
183 // we use getElementById which don't need the #
184 // getElementByID selects elements even if there are special characters
185 // in the ID (like %) which won't work with jQuery
186 /// @todo ceck if we can solve this in the template
187 object = object.indexOf('#') == 0 ? object.substring(1) : object;
190 $('body').css('cursor', 'wait');
191 $(document.getElementById(object)).fadeTo('fast', 0.33, function () {
192 $.get(url).done(function() {
193 $(document.getElementById(object)).remove();
194 $('body').css('cursor', 'auto');