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