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