]> git.mxchange.org Git - friendica.git/blob - js/textedit.js
be4cd770a8a2f0c580679bb167d38c1caa67cac1
[friendica.git] / 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
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                 obj.value = aStr.comment;
67                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full");
68                 $("#comment-edit-text-" + id).addClass("comment-edit-text-empty");
69                 $("#mod-cmnt-wrap-" + id).hide();
70                 closeMenu("comment-edit-submit-wrapper-" + id);
71                 return true;
72         }
73         return false;
74 }
75
76 function showHideCommentBox(id) {
77         if( $('#comment-edit-form-' + id).is(':visible')) {
78                 $('#comment-edit-form-' + id).hide();
79         }
80         else {
81                 $('#comment-edit-form-' + id).show();
82         }
83 }
84
85 function commentOpenUI(obj, id) {
86         $(document).unbind( "click.commentOpen", handler );
87
88         var handler = function() {
89                 if(obj.value == aStr.comment) {
90                         obj.value = '';
91                         $("#comment-edit-text-" + id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
92                         // Choose an arbitrary tab index that's greater than what we're using in jot (3 of them)
93                         // The submit button gets tabindex + 1
94                         $("#comment-edit-text-" + id).attr('tabindex','9');
95                         $("#comment-edit-submit-" + id).attr('tabindex','10');
96                         $("#comment-edit-submit-wrapper-" + id).show();
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                 obj.value = aStr.comment;
109                         $("#comment-edit-text-" + id).removeClass("comment-edit-text-full").addClass("comment-edit-text-empty");
110                         $("#comment-edit-text-" + id).removeAttr('tabindex');
111                         $("#comment-edit-submit-" + id).removeAttr('tabindex');
112                         $("#comment-edit-submit-wrapper-" + id).hide();
113                 }
114         };
115
116         $(document).bind( "click.commentClose", handler );
117 }
118 function commentOpen(obj,id) {
119         if(obj.value == aStr.comment) {
120                 obj.value = '';
121                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
122                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
123                 $("#mod-cmnt-wrap-" + id).show();
124                 openMenu("comment-edit-submit-wrapper-" + id);
125                 return true;
126         }
127         return false;
128 }
129
130 function commentInsert(obj,id) {
131         var tmpStr = $("#comment-edit-text-" + id).val();
132         if(tmpStr == aStr.comment) {
133                 tmpStr = '';
134                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
135                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
136                 openMenu("comment-edit-submit-wrapper-" + id);
137         }
138         var ins = $(obj).html();
139         ins = ins.replace('&lt;','<');
140         ins = ins.replace('&gt;','>');
141         ins = ins.replace('&amp;','&');
142         ins = ins.replace('&quot;','"');
143         $("#comment-edit-text-" + id).val(tmpStr + ins);
144 }
145
146 function qCommentInsert(obj,id) {
147         var tmpStr = $("#comment-edit-text-" + id).val();
148         if(tmpStr == aStr.comment) {
149                 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).val();
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         $(obj).val('');
161 }
162
163 function confirmDelete() { return confirm(aStr.delitem); }