]> git.mxchange.org Git - friendica.git/blob - view/theme/frio/templates/jot-header.tpl
Auto-focus first input field of modal when shown
[friendica.git] / view / theme / frio / templates / jot-header.tpl
1
2 <script type="text/javascript" src="{{$baseurl}}/js/ajaxupload.js" ></script>
3
4 <script type="text/javascript">
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").editor_autocomplete(baseurl+"/acl");
19                                 $("#profile-jot-text").bbco_autocomplete('bbcode');
20                                 editor = true;
21                                 $("a#jot-perms-icon").colorbox({
22                                         'inline' : true,
23                                         'transition' : 'elastic'
24                                 });
25                                 $(".jothidden").show();
26                                 if (typeof cb!="undefined") cb();
27                                 $("#profile-jot-text").keyup(function(){
28                                         var textlen = $(this).val().length;
29                                         $('#character-counter').text(textlen);
30                                 });
31                                 return;
32                         }
33                         tinyMCE.init({
34                                 theme : "advanced",
35                                 mode : "specific_textareas",
36                                 editor_selector: {{$editselect}},
37                                 auto_focus: "profile-jot-text",
38                                 plugins : "bbcode,paste,autoresize, inlinepopups",
39                                 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
40                                 theme_advanced_buttons2 : "",
41                                 theme_advanced_buttons3 : "",
42                                 theme_advanced_toolbar_location : "top",
43                                 theme_advanced_toolbar_align : "center",
44                                 theme_advanced_blockformats : "blockquote,code",
45                                 theme_advanced_resizing : true,
46                                 gecko_spellcheck : true,
47                                 paste_text_sticky : true,
48                                 entity_encoding : "raw",
49                                 add_unload_trigger : false,
50                                 remove_linebreaks : false,
51                                 //force_p_newlines : false,
52                                 //force_br_newlines : true,
53                                 forced_root_block : 'div',
54                                 convert_urls: false,
55                                 content_css: "{{$baseurl}}/view/custom_tinymce.css",
56                                 theme_advanced_path : false,
57                                 file_browser_callback : "fcFileBrowser",
58                                 setup : function(ed) {
59                                         cPopup = null;
60                                         ed.onKeyDown.add(function(ed,e) {
61                                                 if(cPopup !== null)
62                                                         cPopup.onkey(e);
63                                         });
64
65                                         ed.onKeyUp.add(function(ed, e) {
66                                                 var txt = tinyMCE.activeEditor.getContent();
67                                                 match = txt.match(/@([^ \n]+)$/);
68                                                 if(match!==null) {
69                                                         if(cPopup === null) {
70                                                                 cPopup = new ACPopup(this,baseurl+"/acl");
71                                                         }
72                                                         if(cPopup.ready && match[1]!==cPopup.searchText) cPopup.search(match[1]);
73                                                         if(! cPopup.ready) cPopup = null;
74                                                 }
75                                                 else {
76                                                         if(cPopup !== null) { cPopup.close(); cPopup = null; }
77                                                 }
78
79                                                 textlen = txt.length;
80                                                 if(textlen != 0 && $('#jot-perms-icon').is('.unlock')) {
81                                                         $('#profile-jot-desc').html(ispublic);
82                                                 }
83                                                 else {
84                                                         $('#profile-jot-desc').html('&nbsp;');
85                                                 }
86
87                                          //Character count
88
89                                                 if(textlen <= 140) {
90                                                         $('#character-counter').removeClass('red');
91                                                         $('#character-counter').removeClass('orange');
92                                                         $('#character-counter').addClass('grey');
93                                                 }
94                                                 if((textlen > 140) && (textlen <= 420)) {
95                                                         $('#character-counter').removeClass('grey');
96                                                         $('#character-counter').removeClass('red');
97                                                         $('#character-counter').addClass('orange');
98                                                 }
99                                                 if(textlen > 420) {
100                                                         $('#character-counter').removeClass('grey');
101                                                         $('#character-counter').removeClass('orange');
102                                                         $('#character-counter').addClass('red');
103                                                 }
104                                                 $('#character-counter').text(textlen);
105                                         });
106
107                                         ed.onInit.add(function(ed) {
108                                                 ed.pasteAsPlainText = true;
109                                                 $("#profile-jot-text-loading").hide();
110                                                 $(".jothidden").show();
111                                                 if (typeof cb!="undefined") cb();
112                                         });
113
114                                 }
115
116                         });
117                         editor = true;
118
119                         // setup acl popup
120                         $("a#jot-perms-icon").colorbox({
121                                 'inline' : true,
122                                 'transition' : 'elastic'
123                         });
124
125                 } else {
126                         if (typeof cb!="undefined") cb();
127                 }
128         }
129
130         function enableOnUser(){
131                 if (editor) return;
132                 //$(this).val("");
133                 initEditor();
134         }
135 </script>
136
137 <script type="text/javascript">
138         var ispublic = '{{$ispublic}}';
139
140
141         $(document).ready(function() {
142
143                 /* enable tinymce on focus and click */
144                 $("#profile-jot-text").focus(enableOnUser);
145                 $("#profile-jot-text").click(enableOnUser);
146
147                 // When clicking on a forum in acl we should remove the profile jot textarea
148                 // default value before inserting the forum mention
149                 $("body").on('click', '#jot-modal .acl-list-item.forum', function(){
150                         jotTextOpenUI(document.getElementById("profile-jot-text"));
151                 });
152
153
154                 /* show images / file browser window
155                  *
156                  **/
157
158                 /* callback */
159                 $('body').on('fbrowser.image.main', function(e, filename, embedcode, id) {
160                         ///@todo this part isn't ideal and need to be done in a better way
161                         jotTextOpenUI(document.getElementById("profile-jot-text"));
162                         jotActive();
163                         addeditortext(embedcode);
164                 });
165                 $('body').on('fbrowser.file.main', function(e, filename, embedcode, id) {
166                         jotTextOpenUI(document.getElementById("profile-jot-text"));
167                         jotActive();
168                         addeditortext(embedcode);
169                 });
170
171                 $('#wall-image-upload').on('click', function(){
172                         Dialog.doImageBrowser("main");
173                         jotActive();
174                 });
175
176                 $('#wall-file-upload').on('click', function(){
177                         Dialog.doFileBrowser("main");
178                         jotActive();
179                 });
180
181                 /**
182                         var uploader = new window.AjaxUpload(
183                                 'wall-image-upload',
184                                 { action: 'wall_upload/{{$nickname}}',
185                                         name: 'userfile',
186                                         onSubmit: function(file,ext) { $('#profile-rotator').show(); },
187                                         onComplete: function(file,response) {
188                                                 addeditortext(response);
189                                                 $('#profile-rotator').hide();
190                                         }
191                                 }
192                         );
193                         var file_uploader = new window.AjaxUpload(
194                                 'wall-file-upload',
195                                 { action: 'wall_attach/{{$nickname}}',
196                                         name: 'userfile',
197                                         onSubmit: function(file,ext) { $('#profile-rotator').show(); },
198                                         onComplete: function(file,response) {
199                                                 addeditortext(response);
200                                                 $('#profile-rotator').hide();
201                                         }
202                                 }
203                         );
204
205                 }
206                 **/
207         });
208
209         function deleteCheckedItems() {
210                 if(confirm('{{$delitems}}')) {
211                         var checkedstr = '';
212                         var ItemsToDelete = {};
213
214                         $("#item-delete-selected").hide();
215                         $('#item-delete-selected-rotator').show();
216                         $('body').css('cursor', 'wait');
217
218                         $('.item-select').each( function() {
219                                 if($(this).is(':checked')) {
220                                         if(checkedstr.length != 0) {
221                                                 checkedstr = checkedstr + ',' + $(this).val();
222                                                 var deleteItem = this.closest(".wall-item-container");
223                                                 ItemsToDelete[deleteItem.id] = deleteItem;
224                                         }
225                                         else {
226                                                 checkedstr = $(this).val();
227                                         }
228
229                                         // Get the corresponding item container
230                                         var deleteItem = this.closest(".wall-item-container");
231                                         ItemsToDelete[deleteItem.id] = deleteItem;
232                                 }
233                         });
234
235                         // Fade the the the container from the items we want to delete
236                         for(var key in  ItemsToDelete) {
237                                 $(ItemsToDelete[key]).fadeTo('fast', 0.33);
238                         };
239
240                         $.post('item', { dropitems: checkedstr }, function(data) {
241                         }).done(function() {
242                                 // Loop through the ItemsToDelete Object and remove
243                                 // corresponding item div
244                                 for(var key in  ItemsToDelete) {
245                                         $(ItemsToDelete[key]).remove();
246                                 }
247                                 $('body').css('cursor', 'auto');
248                                 $('#item-delete-selected-rotator').hide();
249                         });
250                 }
251         }
252
253         function jotGetLink() {
254                 reply = prompt("{{$linkurl}}");
255                 if(reply && reply.length) {
256                         reply = bin2hex(reply);
257                         $('#profile-rotator').show();
258                         $.get('parse_url?binurl=' + reply, function(data) {
259                                 addeditortext(data);
260                                 $('#profile-rotator').hide();
261                         });
262                 }
263         }
264
265         function jotVideoURL() {
266                 reply = prompt("{{$vidurl}}");
267                 if(reply && reply.length) {
268                         addeditortext('[video]' + reply + '[/video]');
269                 }
270         }
271
272         function jotAudioURL() {
273                 reply = prompt("{{$audurl}}");
274                 if(reply && reply.length) {
275                         addeditortext('[audio]' + reply + '[/audio]');
276                 }
277         }
278
279
280         function jotGetLocation() {
281                 reply = prompt("{{$whereareu}}", $('#jot-location').val());
282                 if(reply && reply.length) {
283                         $('#jot-location').val(reply);
284                 }
285         }
286
287         function jotShare(id) {
288                 $.get('share/' + id, function(data) {
289                         // remove the former content of the text input
290                         $("#profile-jot-text").val("");
291                         initEditor(function(){
292                                 addeditortext(data);
293                         });
294                 });
295
296                 jotShow();
297
298                 $("#jot-popup").show();
299         }
300
301         function linkdropper(event) {
302                 var linkFound = event.dataTransfer.types.contains("text/uri-list");
303                 if(linkFound)
304                         event.preventDefault();
305         }
306
307         function linkdrop(event) {
308                 var reply = event.dataTransfer.getData("text/uri-list");
309                 event.target.textContent = reply;
310                 event.preventDefault();
311                 if(reply && reply.length) {
312                         reply = bin2hex(reply);
313                         $('#profile-rotator').show();
314                         $.get('parse_url?binurl=' + reply, function(data) {
315                                 if (!editor) $("#profile-jot-text").val("");
316                                 initEditor(function(){
317                                         addeditortext(data);
318                                         $('#profile-rotator').hide();
319                                 });
320                         });
321                 }
322         }
323
324         function itemTag(id) {
325                 reply = prompt("{{$term}}");
326                 if(reply && reply.length) {
327                         reply = reply.replace('#','');
328                         if(reply.length) {
329
330                                 commentBusy = true;
331                                 $('body').css('cursor', 'wait');
332
333                                 $.get('tagger/' + id + '?term=' + reply);
334                                 if(timer) clearTimeout(timer);
335                                 timer = setTimeout(NavUpdate,3000);
336                                 liking = 1;
337                         }
338                 }
339         }
340
341         function itemFiler(id) {
342
343                 var bordercolor = $("input").css("border-color");
344
345                 $.get('filer/', function(data){
346                         $.colorbox({html:data});
347                         $("#id_term").keypress(function(){
348                                 $(this).css("border-color",bordercolor);
349                         })
350                         $("#select_term").change(function(){
351                                 $("#id_term").css("border-color",bordercolor);
352                         })
353
354                         $("#filer_save").click(function(e){
355                                 e.preventDefault();
356                                 reply = $("#id_term").val();
357                                 if(reply && reply.length) {
358                                         commentBusy = true;
359                                         $('body').css('cursor', 'wait');
360                                         $.get('filer/' + id + '?term=' + reply, NavUpdate);
361 //                                      if(timer) clearTimeout(timer);
362 //                                      timer = setTimeout(NavUpdate,3000);
363                                         liking = 1;
364                                         $.colorbox.close();
365                                 } else {
366                                         $("#id_term").css("border-color","#FF0000");
367                                 }
368                                 return false;
369                         });
370                 });
371
372         }
373
374         function jotClearLocation() {
375                 $('#jot-coord').val('');
376                 $('#profile-nolocation-wrapper').hide();
377         }
378
379         function addeditortext(data) {
380                 if(plaintext == 'none') {
381                         // get the textfield
382                         var textfield = document.getElementById("profile-jot-text");
383                         // check if the textfield does have the default-value
384                         jotTextOpenUI(textfield);
385                         // save already existent content
386                         var currentText = $("#profile-jot-text").val();
387                         //insert the data as new value
388                         textfield.value = currentText + data;
389                 }
390                 else
391                         tinyMCE.execCommand('mceInsertRawHTML',false,data);
392         }
393
394         {{$geotag}}
395
396         function jotShow() {
397                 var modal = $('#jot-modal').modal();
398                 jotcache = $("#jot-sections");
399
400                 // Auto focus on the first enabled field in the modal
401                 modal.on('shown.bs.modal', function (e) {
402                         $('#jot-modal-content').find('select:not([disabled]), input:not([type=hidden]):not([disabled]), textarea:not([disabled])').first().focus();
403                 })
404
405                 modal
406                         .find('#jot-modal-content')
407                         .append(jotcache)
408                         .modal.show;
409         }
410
411         // the following functions show/hide the specific jot content
412         // in dependence of the selected nav
413         function aclActive() {
414                 $(".modal-body #profile-jot-wrapper, .modal-body #jot-preview-content, .modal-body #jot-fbrowser-wrapper").hide();
415                 $(".modal-body #profile-jot-acl-wrapper").show();
416         }
417
418
419         function previewActive() {
420                 $(".modal-body #profile-jot-wrapper, .modal-body #profile-jot-acl-wrapper,.modal-body #jot-fbrowser-wrapper").hide();
421                 preview_post();
422         }
423
424         function jotActive() {
425                 $(".modal-body #profile-jot-acl-wrapper, .modal-body #jot-preview-content, .modal-body #jot-fbrowser-wrapper").hide();
426                 $(".modal-body #profile-jot-wrapper").show();
427
428                 //make sure jot text does have really the active class (we do this because there are some
429                 // other events which trigger jot text
430                 toggleJotNav($("#jot-modal .jot-nav #jot-text-lnk"));
431         }
432
433         function fbrowserActive() {
434                 $(".modal-body #profile-jot-wrapper, .modal-body #jot-preview-content, .modal-body #profile-jot-acl-wrapper").hide();
435
436                 $(".modal-body #jot-fbrowser-wrapper").show();
437
438                 $(function() {Dialog.showJot();});
439         }
440
441
442 </script>
443