]> git.mxchange.org Git - friendica.git/blob - view/theme/frio/js/textedit.js
d3b090d537af6faa97762cb79f98f91c58bf97a1
[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                 $("#comment-edit-text-" + id).val(tmpStr);
13         }
14
15         textarea = document.getElementById("comment-edit-text-" +id);
16         if (document.selection) {
17                 textarea.focus();
18                 selected = document.selection.createRange();
19                 if (BBcode == "url") {
20                         selected.text = "["+BBcode+"]" + "http://" +  selected.text + "[/"+BBcode+"]";
21                 } else {
22                         selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
23                 }
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);
29                 } else {
30                         textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
31                 }
32         }
33
34         return true;
35 }
36
37
38 function showThread(id) {
39         $("#collapsed-comments-" + id).show()
40         $("#collapsed-comments-" + id + " .collapsed-comments").show()
41 }
42 function hideThread(id) {
43         $("#collapsed-comments-" + id).hide()
44         $("#collapsed-comments-" + id + " .collapsed-comments").hide()
45 }
46
47 function cmtBbOpen(id) {
48         $("#comment-edit-bb-" + id).show();
49 }
50 function cmtBbClose(id) {
51         $("#comment-edit-bb-" + id).hide();
52 }
53
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);
61         return true;
62 }
63
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);
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 == '') {
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"));
97                 }
98         };
99
100         $(document).bind( "click.commentOpen", handler );
101 }
102
103 function commentCloseUI(obj, id) {
104         $(document).unbind( "click.commentClose", handler );
105
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"));
114                 }
115         };
116
117         $(document).bind( "click.commentClose", handler );
118 }
119
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"));
125         }
126 }
127
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"));
133         }
134 }
135
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);
142                 return true;
143         }
144         return false;
145 }
146
147 function commentInsert(obj,id) {
148         var tmpStr = $("#comment-edit-text-" + id).val();
149         if (tmpStr == '') {
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);
153         }
154         var ins = $(obj).html();
155         ins = ins.replace('&lt;','<');
156         ins = ins.replace('&gt;','>');
157         ins = ins.replace('&amp;','&');
158         ins = ins.replace('&quot;','"');
159         $("#comment-edit-text-" + id).val(tmpStr + ins);
160 }
161
162 function qCommentInsert(obj,id) {
163         var tmpStr = $("#comment-edit-text-" + id).val();
164         if (tmpStr == '') {
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);
168         }
169         var ins = $(obj).val();
170         ins = ins.replace('&lt;','<');
171         ins = ins.replace('&gt;','>');
172         ins = ins.replace('&amp;','&');
173         ins = ins.replace('&quot;','"');
174         $("#comment-edit-text-" + id).val(tmpStr + ins);
175         $(obj).val('');
176 }
177
178 function confirmDelete() { return confirm(aStr.delitem); }
179
180 function dropItem(url, object) {
181         var confirm = confirmDelete();
182
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;
189
190         if(confirm) {
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');
196                         });
197                 });
198         }
199 }