]> git.mxchange.org Git - friendica.git/blob - view/templates/jot-header.tpl
Merge pull request #1216 from cpfeiffer/TinyMCE-resizable
[friendica.git] / view / templates / jot-header.tpl
1
2
3 <script language="javascript" type="text/javascript">
4
5 var editor=false;
6 var textlen = 0;
7 var plaintext = '{{$editselect}}';
8
9 function initEditor(cb){
10         if (editor==false){
11                 $("#profile-jot-text-loading").show();
12                 if(plaintext == 'none') {
13                         $("#profile-jot-text-loading").hide();
14                         $("#profile-jot-text").css({ 'height': 200, 'color': '#000' });
15                         $("#profile-jot-text").contact_autocomplete(baseurl+"/acl");
16                         editor = true;
17                         $("a#jot-perms-icon").colorbox({
18                                 'inline' : true,
19                                 'transition' : 'elastic'
20                         });
21                         $(".jothidden").show();
22                         if (typeof cb!="undefined") cb();
23                         return;
24                 }       
25                 tinyMCE.init({
26                         theme : "advanced",
27                         mode : "specific_textareas",
28                         editor_selector: {{$editselect}},
29                         auto_focus: "profile-jot-text",
30                         plugins : "bbcode,paste,autoresize, inlinepopups",
31                         theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
32                         theme_advanced_buttons2 : "",
33                         theme_advanced_buttons3 : "",
34                         theme_advanced_toolbar_location : "top",
35                         theme_advanced_toolbar_align : "center",
36                         theme_advanced_blockformats : "blockquote,code",
37                         theme_advanced_resizing : true,
38                         gecko_spellcheck : true,
39                         paste_text_sticky : true,
40                         entity_encoding : "raw",
41                         add_unload_trigger : false,
42                         remove_linebreaks : false,
43                         //force_p_newlines : false,
44                         //force_br_newlines : true,
45                         forced_root_block : 'div',
46                         convert_urls: false,
47                         content_css: "{{$baseurl}}/view/custom_tinymce.css",
48                         theme_advanced_path : false,
49                         file_browser_callback : "fcFileBrowser",
50                         setup : function(ed) {
51                                 cPopup = null;
52                                 ed.onKeyDown.add(function(ed,e) {
53                                         if(cPopup !== null)
54                                                 cPopup.onkey(e);
55                                 });
56
57                                 ed.onKeyUp.add(function(ed, e) {
58                                         var txt = tinyMCE.activeEditor.getContent();
59                                         match = txt.match(/@([^ \n]+)$/);
60                                         if(match!==null) {
61                                                 if(cPopup === null) {
62                                                         cPopup = new ACPopup(this,baseurl+"/acl");
63                                                 }
64                                                 if(cPopup.ready && match[1]!==cPopup.searchText) cPopup.search(match[1]);
65                                                 if(! cPopup.ready) cPopup = null;
66                                         }
67                                         else {
68                                                 if(cPopup !== null) { cPopup.close(); cPopup = null; }
69                                         }
70
71                                         textlen = txt.length;
72                                         if(textlen != 0 && $('#jot-perms-icon').is('.unlock')) {
73                                                 $('#profile-jot-desc').html(ispublic);
74                                         }
75                                         else {
76                                                 $('#profile-jot-desc').html('&nbsp;');
77                                         }        
78
79                                  //Character count
80
81                                         if(textlen <= 140) {
82                                                 $('#character-counter').removeClass('red');
83                                                 $('#character-counter').removeClass('orange');
84                                                 $('#character-counter').addClass('grey');
85                                         }
86                                         if((textlen > 140) && (textlen <= 420)) {
87                                                 $('#character-counter').removeClass('grey');
88                                                 $('#character-counter').removeClass('red');
89                                                 $('#character-counter').addClass('orange');
90                                         }
91                                         if(textlen > 420) {
92                                                 $('#character-counter').removeClass('grey');
93                                                 $('#character-counter').removeClass('orange');
94                                                 $('#character-counter').addClass('red');
95                                         }
96                                         $('#character-counter').text(textlen);
97                                 });
98
99                                 ed.onInit.add(function(ed) {
100                                         ed.pasteAsPlainText = true;
101                                         $("#profile-jot-text-loading").hide();
102                                         $(".jothidden").show();
103                                         if (typeof cb!="undefined") cb();
104                                 });
105
106                         }
107                 });
108                 editor = true;
109                 // setup acl popup
110                 $("a#jot-perms-icon").colorbox({
111                         'inline' : true,
112                         'transition' : 'elastic'
113                 }); 
114         } else {
115                 if (typeof cb!="undefined") cb();
116         }
117 }
118
119 function enableOnUser(){
120         if (editor) return;
121         $(this).val("");
122         initEditor();
123 }
124
125 </script>
126 <script type="text/javascript" src="{{$baseurl}}/js/ajaxupload.js" ></script>
127 <script>
128         var ispublic = '{{$ispublic}}';
129
130         $(document).ready(function() {
131                 
132                 /* enable tinymce on focus and click */
133                 $("#profile-jot-text").focus(enableOnUser);
134                 $("#profile-jot-text").click(enableOnUser);
135
136                 var uploader = new window.AjaxUpload(
137                         'wall-image-upload',
138                         { action: 'wall_upload/{{$nickname}}',
139                                 name: 'userfile',
140                                 onSubmit: function(file,ext) { $('#profile-rotator').show(); },
141                                 onComplete: function(file,response) {
142                                         addeditortext(response);
143                                         $('#profile-rotator').hide();
144                                 }                                
145                         }
146                 );
147                 var file_uploader = new window.AjaxUpload(
148                         'wall-file-upload',
149                         { action: 'wall_attach/{{$nickname}}',
150                                 name: 'userfile',
151                                 onSubmit: function(file,ext) { $('#profile-rotator').show(); },
152                                 onComplete: function(file,response) {
153                                         addeditortext(response);
154                                         $('#profile-rotator').hide();
155                                 }                                
156                         }
157                 );
158
159
160         });
161
162         function deleteCheckedItems() {
163                 if(confirm('{{$delitems}}')) {
164                         var checkedstr = '';
165
166                         $("#item-delete-selected").hide();
167                         $('#item-delete-selected-rotator').show();
168
169                         $('.item-select').each( function() {
170                                 if($(this).is(':checked')) {
171                                         if(checkedstr.length != 0) {
172                                                 checkedstr = checkedstr + ',' + $(this).val();
173                                         }
174                                         else {
175                                                 checkedstr = $(this).val();
176                                         }
177                                 }       
178                         });
179                         $.post('item', { dropitems: checkedstr }, function(data) {
180                                 window.location.reload();
181                         });
182                 }
183         }
184
185         function jotGetLink() {
186                 reply = prompt("{{$linkurl}}");
187                 if(reply && reply.length) {
188                         reply = bin2hex(reply);
189                         $('#profile-rotator').show();
190                         $.get('parse_url?binurl=' + reply, function(data) {
191                                 addeditortext(data);
192                                 $('#profile-rotator').hide();
193                         });
194                 }
195         }
196
197         function jotVideoURL() {
198                 reply = prompt("{{$vidurl}}");
199                 if(reply && reply.length) {
200                         addeditortext('[video]' + reply + '[/video]');
201                 }
202         }
203
204         function jotAudioURL() {
205                 reply = prompt("{{$audurl}}");
206                 if(reply && reply.length) {
207                         addeditortext('[audio]' + reply + '[/audio]');
208                 }
209         }
210
211
212         function jotGetLocation() {
213                 reply = prompt("{{$whereareu}}", $('#jot-location').val());
214                 if(reply && reply.length) {
215                         $('#jot-location').val(reply);
216                 }
217         }
218
219         function jotShare(id) {
220                 if ($('#jot-popup').length != 0) $('#jot-popup').show();
221
222                 $('#like-rotator-' + id).show();
223                 $.get('share/' + id, function(data) {
224                         if (!editor) $("#profile-jot-text").val("");
225                         initEditor(function(){
226                                 addeditortext(data);
227                                 $('#like-rotator-' + id).hide();
228                                 $(window).scrollTop(0);
229                         });
230
231                 });
232         }
233
234         function linkdropper(event) {
235                 var linkFound = event.dataTransfer.types.contains("text/uri-list");
236                 if(linkFound)
237                         event.preventDefault();
238         }
239
240         function linkdrop(event) {
241                 var reply = event.dataTransfer.getData("text/uri-list");
242                 event.target.textContent = reply;
243                 event.preventDefault();
244                 if(reply && reply.length) {
245                         reply = bin2hex(reply);
246                         $('#profile-rotator').show();
247                         $.get('parse_url?binurl=' + reply, function(data) {
248                                 if (!editor) $("#profile-jot-text").val("");
249                                 initEditor(function(){
250                                         addeditortext(data);
251                                         $('#profile-rotator').hide();
252                                 });
253                         });
254                 }
255         }
256
257         function itemTag(id) {
258                 reply = prompt("{{$term}}");
259                 if(reply && reply.length) {
260                         reply = reply.replace('#','');
261                         if(reply.length) {
262
263                                 commentBusy = true;
264                                 $('body').css('cursor', 'wait');
265
266                                 $.get('tagger/' + id + '?term=' + reply);
267                                 if(timer) clearTimeout(timer);
268                                 timer = setTimeout(NavUpdate,3000);
269                                 liking = 1;
270                         }
271                 }
272         }
273
274         function itemFiler(id) {
275                 
276                 var bordercolor = $("input").css("border-color");
277                 
278                 $.get('filer/', function(data){
279                         $.colorbox({html:data});
280                         $("#id_term").keypress(function(){
281                                 $(this).css("border-color",bordercolor);
282                         })
283                         $("#select_term").change(function(){
284                                 $("#id_term").css("border-color",bordercolor);
285                         })
286                         
287                         $("#filer_save").click(function(e){
288                                 e.preventDefault();
289                                 reply = $("#id_term").val();
290                                 if(reply && reply.length) {
291                                         commentBusy = true;
292                                         $('body').css('cursor', 'wait');
293                                         $.get('filer/' + id + '?term=' + reply, NavUpdate);
294 //                                      if(timer) clearTimeout(timer);
295 //                                      timer = setTimeout(NavUpdate,3000);
296                                         liking = 1;
297                                         $.colorbox.close();
298                                 } else {
299                                         $("#id_term").css("border-color","#FF0000");
300                                 }
301                                 return false;
302                         });
303                 });
304                 
305         }
306
307         function jotClearLocation() {
308                 $('#jot-coord').val('');
309                 $('#profile-nolocation-wrapper').hide();
310         }
311
312         function addeditortext(data) {
313                 if(plaintext == 'none') {
314                         var currentText = $("#profile-jot-text").val();
315                         $("#profile-jot-text").val(currentText + data);
316                 }
317                 else
318                         tinyMCE.execCommand('mceInsertRawHTML',false,data);
319         }       
320
321         {{$geotag}}
322
323 </script>
324