]> git.mxchange.org Git - friendica.git/blob - templates/jot-header.tpl
first files - move to Version 0.1
[friendica.git] / 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").addClass("profile-jot-text-full").removeClass("profile-jot-text-empty");
15                         $("#jot-category").show();
16                         $("#jot-category").addClass("jot-category-ex");
17                         $("#jot-profile-jot-wrapper").show();
18                         $("#profile-jot-text").contact_autocomplete(baseurl+"/acl");
19                         editor = true;
20                         $("a#jot-perms-icon").colorbox({
21                                 'inline' : true,
22                                 'transition' : 'elastic'
23                         });
24                         $(".jothidden").show();
25                         if (typeof cb!="undefined") cb();
26                         return;
27                 }       
28                 tinyMCE.init({
29                         theme : "advanced",
30                         mode : "specific_textareas",
31                         editor_selector: {{$editselect}},
32                         auto_focus: "profile-jot-text",
33                         plugins : "bbcode,paste,autoresize, inlinepopups",
34                         theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
35                         theme_advanced_buttons2 : "",
36                         theme_advanced_buttons3 : "",
37                         theme_advanced_toolbar_location : "top",
38                         theme_advanced_toolbar_align : "center",
39                         theme_advanced_blockformats : "blockquote,code",
40                         theme_advanced_resizing : true,
41                         gecko_spellcheck : true,
42                         paste_text_sticky : true,
43                         entity_encoding : "raw",
44                         add_unload_trigger : false,
45                         remove_linebreaks : false,
46                         //force_p_newlines : false,
47                         //force_br_newlines : true,
48                         forced_root_block : 'div',
49                         convert_urls: false,
50                         content_css: "{{$baseurl}}/view/custom_tinymce.css",
51                         theme_advanced_path : false,
52                         file_browser_callback : "fcFileBrowser",
53                         setup : function(ed) {
54                                 cPopup = null;
55                                 ed.onKeyDown.add(function(ed,e) {
56                                         if(cPopup !== null)
57                                                 cPopup.onkey(e);
58                                 });
59
60                                 ed.onKeyUp.add(function(ed, e) {
61                                         var txt = tinyMCE.activeEditor.getContent();
62                                         match = txt.match(/@([^ \n]+)$/);
63                                         if(match!==null) {
64                                                 if(cPopup === null) {
65                                                         cPopup = new ACPopup(this,baseurl+"/acl");
66                                                 }
67                                                 if(cPopup.ready && match[1]!==cPopup.searchText) cPopup.search(match[1]);
68                                                 if(! cPopup.ready) cPopup = null;
69                                         }
70                                         else {
71                                                 if(cPopup !== null) { cPopup.close(); cPopup = null; }
72                                         }
73
74                                         textlen = txt.length;
75                                         if(textlen != 0 && $('#jot-perms-icon').is('.unlock')) {
76                                                 $('#profile-jot-desc').html(ispublic);
77                                         }
78                                         else {
79                                                 $('#profile-jot-desc').html('&nbsp;');
80                                         }        
81
82                                  //Character count
83
84                                         if(textlen <= 140) {
85                                                 $('#character-counter').removeClass('red');
86                                                 $('#character-counter').removeClass('orange');
87                                                 $('#character-counter').addClass('grey');
88                                         }
89                                         if((textlen > 140) && (textlen <= 420)) {
90                                                 $('#character-counter').removeClass('grey');
91                                                 $('#character-counter').removeClass('red');
92                                                 $('#character-counter').addClass('orange');
93                                         }
94                                         if(textlen > 420) {
95                                                 $('#character-counter').removeClass('grey');
96                                                 $('#character-counter').removeClass('orange');
97                                                 $('#character-counter').addClass('red');
98                                         }
99                                         $('#character-counter').text(textlen);
100                                 });
101
102                                 ed.onInit.add(function(ed) {
103                                         ed.pasteAsPlainText = true;
104                                         $("#profile-jot-text-loading").hide();
105                                         $(".jothidden").show();
106                                         if (typeof cb!="undefined") cb();
107                                 });
108
109                         }
110                 });
111                 editor = true;
112                 // setup acl popup
113                 $("a#jot-perms-icon").colorbox({
114                         'inline' : true,
115                         'transition' : 'elastic'
116                 }); 
117         } else {
118                 if (typeof cb!="undefined") cb();
119         }
120 }
121
122 function enableOnUser(){
123         if (editor) return;
124         $(this).val("");
125         initEditor();
126 }
127
128
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                 $.get('share/' + id, function(data) {
269                         if (!editor) $("#profile-jot-text").val("");
270                         initEditor(function(){
271                         addeditortext(data);
272                         });
273                 });
274
275                 jotShow();
276
277                 $("#jot-popup").show();
278         }
279
280         function linkdropper(event) {
281                 var linkFound = event.dataTransfer.types.contains("text/uri-list");
282                 if(linkFound)
283                         event.preventDefault();
284         }
285
286         function linkdrop(event) {
287                 var reply = event.dataTransfer.getData("text/uri-list");
288                 event.target.textContent = reply;
289                 event.preventDefault();
290                 if(reply && reply.length) {
291                         reply = bin2hex(reply);
292                         $('#profile-rotator').show();
293                         $.get('parse_url?binurl=' + reply, function(data) {
294                                 if (!editor) $("#profile-jot-text").val("");
295                                 initEditor(function(){
296                                         addeditortext(data);
297                                         $('#profile-rotator').hide();
298                                 });
299                         });
300                 }
301         }
302
303         function itemTag(id) {
304                 reply = prompt("{{$term}}");
305                 if(reply && reply.length) {
306                         reply = reply.replace('#','');
307                         if(reply.length) {
308
309                                 commentBusy = true;
310                                 $('body').css('cursor', 'wait');
311
312                                 $.get('tagger/' + id + '?term=' + reply);
313                                 if(timer) clearTimeout(timer);
314                                 timer = setTimeout(NavUpdate,3000);
315                                 liking = 1;
316                         }
317                 }
318         }
319
320         function itemFiler(id) {
321
322                 var bordercolor = $("input").css("border-color");
323
324                 $.get('filer/', function(data){
325                         $.colorbox({html:data});
326                         $("#id_term").keypress(function(){
327                                 $(this).css("border-color",bordercolor);
328                         })
329                         $("#select_term").change(function(){
330                                 $("#id_term").css("border-color",bordercolor);
331                         })
332
333                         $("#filer_save").click(function(e){
334                                 e.preventDefault();
335                                 reply = $("#id_term").val();
336                                 if(reply && reply.length) {
337                                         commentBusy = true;
338                                         $('body').css('cursor', 'wait');
339                                         $.get('filer/' + id + '?term=' + reply, NavUpdate);
340 //                                      if(timer) clearTimeout(timer);
341 //                                      timer = setTimeout(NavUpdate,3000);
342                                         liking = 1;
343                                         $.colorbox.close();
344                                 } else {
345                                         $("#id_term").css("border-color","#FF0000");
346                                 }
347                                 return false;
348                         });
349                 });
350
351         }
352
353         function jotClearLocation() {
354                 $('#jot-coord').val('');
355                 $('#profile-nolocation-wrapper').hide();
356         }
357
358         function addeditortext(data) {
359                 if(plaintext == 'none') {
360                         var currentText = $("#profile-jot-text").val();
361                         $("#profile-jot-text").val(currentText + data);
362                 }
363                 else
364                         tinyMCE.execCommand('mceInsertRawHTML',false,data);
365         }
366
367         {{$geotag}}
368
369         function jotShow() {
370                 var modal = $('#jot-modal').modal();
371                 var jot = $("#profile-jot-form");
372
373                 // Clear bs modal on close
374                 // We need this to prevent that the modal displays old content
375                 $('body').on('hidden.bs.modal', '#jot-modal', function () {
376                         $(this).removeData('bs.modal');
377                         $("#jot-content").append(jot);
378                 });
379
380                 modal
381                         .find('#jot-modal-body')
382                         .append(jot)
383                         .modal.show
384                         ;
385         }
386
387         // the following functions show/hide the specific jot content 
388         // in dependence of the selected nav
389         function aclActive() {
390                 $(".modal-body #profile-jot-wrapper, .modal-body #jot-preview-content").hide();
391                 $(".modal-body #profile-jot-acl-wrapper").show();
392                 $("#jot-text-lnk, #jot-preview-lnk").parent("li").removeClass("active");
393                 $("#jot-perms-lnk").parent("li").addClass("active");
394         }
395
396         function jotActive() {
397                 $(".modal-body #profile-jot-acl-wrapper, .modal-body #jot-preview-content").hide();
398                 $(".modal-body #profile-jot-wrapper").show();
399                 $("#jot-perms-lnk, #jot-preview-lnk").parent("li").removeClass("active");
400                 $("#jot-text-lnk").parent("li").addClass("active");
401         }
402
403         function previewActive() {
404                 $(".modal-body #profile-jot-wrapper, .modal-body #profile-jot-acl-wrapper").hide();
405                 $("#jot-text-lnk, #jot-perms-lnk").parent("li").removeClass("active");
406                 $("#jot-preview-lnk").parent("li").addClass("active");
407                 preview_post();
408         }
409 </script>
410