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