]> git.mxchange.org Git - friendica.git/blob - view/theme/frio/js/textedit.js
73f7c9ec91b644978915b5ac7db4a01bc0f9bdbf
[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(comment,BBcode,id) {
7
8                 var tmpStr = $("#comment-edit-text-" + id).val();
9                 if(tmpStr == comment) {
10                         tmpStr = "";
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);
15                 }
16
17         textarea = document.getElementById("comment-edit-text-" +id);
18         if (document.selection) {
19                 textarea.focus();
20                 selected = document.selection.createRange();
21                 if (BBcode == "url"){
22                         selected.text = "["+BBcode+"]" + "http://" +  selected.text + "[/"+BBcode+"]";
23                         } else
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;
28                 if (BBcode == "url"){
29                         textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + "http://" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
30                         } else
31                 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
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                 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);
70                 return true;
71         }
72         return false;
73 }
74
75 function showHideCommentBox(id) {
76         if( $('#comment-edit-form-' + id).is(':visible')) {
77                 $('#comment-edit-form-' + id).hide();
78         }
79         else {
80                 $('#comment-edit-form-' + id).show();
81         }
82 }
83
84 function commentOpenUI(obj, id) {
85         $(document).unbind( "click.commentOpen", handler );
86
87         var handler = function() {
88                 if(obj.value == aStr.comment) {
89                         obj.value = '';
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                         // initialize autosize for this comment
97                         autosize($("#comment-edit-text-" + id + ".text-autosize"));
98                 }
99         };
100
101         $(document).bind( "click.commentOpen", handler );
102 }
103
104 function commentCloseUI(obj, id) {
105         $(document).unbind( "click.commentClose", handler );
106
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"));
116                 }
117         };
118
119         $(document).bind( "click.commentClose", handler );
120 }
121
122 function jotTextOpenUI(obj) {
123         if (obj.value == '') {
124                 $(".modal-body #profile-jot-text").addClass("profile-jot-text-full").removeClass("profile-jot-text-empty");
125                 // initiale autosize for the jot
126                 autosize($(".modal-body #profile-jot-text"));
127         }
128 }
129
130 function jotTextCloseUI(obj) {
131         if (obj.value === '') {
132                 $(".modal-body #profile-jot-text").removeClass("profile-jot-text-full").addClass("profile-jot-text-empty");
133                 // destroy the automatic textarea resizing
134                 autosize.destroy($(".modal-body #profile-jot-text"));
135         }
136 }
137
138 function commentOpen(obj,id) {
139         if(obj.value == aStr.comment) {
140                 obj.value = '';
141                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
142                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
143                 $("#mod-cmnt-wrap-" + id).show();
144                 openMenu("comment-edit-submit-wrapper-" + id);
145                 return true;
146         }
147         return false;
148 }
149
150 function commentInsert(obj,id) {
151         var tmpStr = $("#comment-edit-text-" + id).val();
152         if(tmpStr == aStr.comment) {
153                 tmpStr = '';
154                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
155                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
156                 openMenu("comment-edit-submit-wrapper-" + id);
157         }
158         var ins = $(obj).html();
159         ins = ins.replace('&lt;','<');
160         ins = ins.replace('&gt;','>');
161         ins = ins.replace('&amp;','&');
162         ins = ins.replace('&quot;','"');
163         $("#comment-edit-text-" + id).val(tmpStr + ins);
164 }
165
166 function qCommentInsert(obj,id) {
167         var tmpStr = $("#comment-edit-text-" + id).val();
168         if(tmpStr == aStr.comment) {
169                 tmpStr = '';
170                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
171                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
172                 openMenu("comment-edit-submit-wrapper-" + id);
173         }
174         var ins = $(obj).val();
175         ins = ins.replace('&lt;','<');
176         ins = ins.replace('&gt;','>');
177         ins = ins.replace('&amp;','&');
178         ins = ins.replace('&quot;','"');
179         $("#comment-edit-text-" + id).val(tmpStr + ins);
180         $(obj).val('');
181 }
182
183 function confirmDelete() { return confirm(aStr.delitem); }
184
185 function dropItem(url, object) {
186         var confirm = confirmDelete();
187
188         //if the first character of the object is #, remove it because
189         // we use getElementById which don't need the #
190         // getElementByID selects elements even if there are special characters
191         // in the ID (like %) which won't work with jQuery
192         /// @todo ceck if we can solve this in the template
193         object = object.indexOf('#') == 0 ? object.substring(1) : object;
194
195         if(confirm) {
196                 $('body').css('cursor', 'wait');
197                 $(document.getElementById(object)).fadeTo('fast', 0.33, function () {
198                         $.get(url).done(function() {
199                                 $(document.getElementById(object)).remove();
200                                 $('body').css('cursor', 'auto');
201                         });
202                 });
203         }
204 }