]> git.mxchange.org Git - friendica.git/blob - view/theme/frio/js/textedit.js
9c5c1823d1b624c1c295e08b963b075e6d53a91c
[friendica.git] / view / theme / frio / js / textedit.js
1 /*
2  * @brief The file contains functions for text editing and commenting
3  */
4
5
6 function insertFormatting(BBcode,id) {
7         var tmpStr = $("#comment-edit-text-" + id).val();
8         if (tmpStr == '') {
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         }
13
14         textarea = document.getElementById("comment-edit-text-" +id);
15         if (document.selection) {
16                 textarea.focus();
17                 selected = document.selection.createRange();
18                 if (BBcode == "url") {
19                         selected.text = "["+BBcode+"]" + "http://" +  selected.text + "[/"+BBcode+"]";
20                 } else {
21                         selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
22                 }
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);
28                 } else {
29                         textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
30                 }
31         }
32
33         return true;
34 }
35
36
37 function showThread(id) {
38         $("#collapsed-comments-" + id).show()
39         $("#collapsed-comments-" + id + " .collapsed-comments").show()
40 }
41 function hideThread(id) {
42         $("#collapsed-comments-" + id).hide()
43         $("#collapsed-comments-" + id + " .collapsed-comments").hide()
44 }
45
46 function cmtBbOpen(id) {
47         $("#comment-edit-bb-" + id).show();
48 }
49 function cmtBbClose(id) {
50         $("#comment-edit-bb-" + id).hide();
51 }
52
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);
60         return true;
61 }
62
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);
69                 return true;
70         }
71         return false;
72 }
73
74 function showHideCommentBox(id) {
75         if( $('#comment-edit-form-' + id).is(':visible')) {
76                 $('#comment-edit-form-' + id).hide();
77         }
78         else {
79                 $('#comment-edit-form-' + id).show();
80         }
81 }
82
83 function commentOpenUI(obj, id) {
84         $(document).unbind( "click.commentOpen", handler );
85
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"));
96                 }
97         };
98
99         $(document).bind( "click.commentOpen", handler );
100 }
101
102 function commentCloseUI(obj, id) {
103         $(document).unbind( "click.commentClose", handler );
104
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"));
113                 }
114         };
115
116         $(document).bind( "click.commentClose", handler );
117 }
118
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"));
124         }
125 }
126
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"));
132         }
133 }
134
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);
141                 return true;
142         }
143         return false;
144 }
145
146 function commentInsert(obj,id) {
147         var tmpStr = $("#comment-edit-text-" + id).val();
148         if (tmpStr == '') {
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);
152         }
153         var ins = $(obj).html();
154         ins = ins.replace('&lt;','<');
155         ins = ins.replace('&gt;','>');
156         ins = ins.replace('&amp;','&');
157         ins = ins.replace('&quot;','"');
158         $("#comment-edit-text-" + id).val(tmpStr + ins);
159 }
160
161 function qCommentInsert(obj,id) {
162         var tmpStr = $("#comment-edit-text-" + id).val();
163         if (tmpStr == '') {
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);
167         }
168         var ins = $(obj).val();
169         ins = ins.replace('&lt;','<');
170         ins = ins.replace('&gt;','>');
171         ins = ins.replace('&amp;','&');
172         ins = ins.replace('&quot;','"');
173         $("#comment-edit-text-" + id).val(tmpStr + ins);
174         $(obj).val('');
175 }
176
177 function confirmDelete() { return confirm(aStr.delitem); }
178
179 function dropItem(url, object) {
180         var confirm = confirmDelete();
181
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;
188
189         if(confirm) {
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');
195                         });
196                 });
197         }
198 }