]> git.mxchange.org Git - friendica.git/blob - view/theme/frost/js/main.js
51df1a47cc8b64b265d154d6c4210212a41f2ff1
[friendica.git] / view / theme / frost / js / main.js
1
2   function openClose(theID) {
3     if(document.getElementById(theID).style.display == "block") { 
4       document.getElementById(theID).style.display = "none" 
5     }
6     else { 
7       document.getElementById(theID).style.display = "block" 
8     } 
9   }
10
11   function openMenu(theID) {
12       document.getElementById(theID).style.display = "block" 
13   }
14
15   function closeMenu(theID) {
16       document.getElementById(theID).style.display = "none" 
17   }
18
19
20
21         var src = null;
22         var prev = null;
23         var livetime = null;
24         var msie = false;
25         var stopped = false;
26         var totStopped = false;
27         var timer = null;
28         var pr = 0;
29         var liking = 0;
30         var in_progress = false;
31         var langSelect = false;
32         var commentBusy = false;
33         var last_popup_menu = null;
34         var last_popup_button = null;
35
36         $j(function() {
37                 $j.ajaxSetup({cache: false});
38
39                 msie = $j.browser.msie ;
40                 
41                 /* setup tooltips *//*
42                 $j("a,.tt").each(function(){
43                         var e = $j(this);
44                         var pos="bottom";
45                         if (e.hasClass("tttop")) pos="top";
46                         if (e.hasClass("ttbottom")) pos="bottom";
47                         if (e.hasClass("ttleft")) pos="left";
48                         if (e.hasClass("ttright")) pos="right";
49                         e.tipTip({defaultPosition: pos, edgeOffset: 8});
50                 });*/
51                 
52                 
53                 
54                 /* setup onoff widgets */
55                 $j(".onoff input").each(function(){
56                         val = $j(this).val();
57                         id = $j(this).attr("id");
58                         $j("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
59                         
60                 });
61                 $j(".onoff > a").click(function(event){
62                         event.preventDefault(); 
63                         var input = $j(this).siblings("input");
64                         var val = 1-input.val();
65                         var id = input.attr("id");
66                         $j("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
67                         $j("#"+id+"_onoff ."+ (val==1?"on":"off")).removeClass("hidden");
68                         input.val(val);
69                         //console.log(id);
70                 });
71                 
72                 /* setup field_richtext */
73                 setupFieldRichtext();
74
75                 /* popup menus */
76                 function close_last_popup_menu(e) {
77
78                         if( last_popup_menu ) {
79                                 if( '#' + last_popup_menu.attr('id') !== $j(e.target).attr('rel')) {
80                                         last_popup_menu.hide();
81                                         last_popup_button.removeClass("selected");
82                                         last_popup_menu = null;
83                                         last_popup_button = null;
84                                 }
85                         }
86                 }
87                 $j('a[rel^=#]').click(function(e){
88
89                         close_last_popup_menu(e);
90                         menu = $j( $j(this).attr('rel') );
91                         e.preventDefault();
92                         e.stopPropagation();
93
94                         if (menu.attr('popup')=="false") return false;
95
96                         $j(this).parent().toggleClass("selected");
97                         menu.slideToggle('fast');
98
99                         if (menu.css("display") == "none") {
100                                 last_popup_menu = null;
101                                 last_popup_button = null;
102                         } else {
103                                 last_popup_menu = menu;
104                                 last_popup_button = $j(this).parent();
105                         }
106                         return false;
107                 });
108                 $j('html').click(function(e) {
109                         close_last_popup_menu(e);
110                 });
111                 
112                 // fancyboxes
113                 $j("a.popupbox").fancybox({
114                         'transitionIn' : 'none',
115                         'transitionOut' : 'none'
116                 });
117                 
118
119                 /* notifications template */
120                 var notifications_tpl= unescape($j("#nav-notifications-template[rel=template]").html());
121                 var notifications_all = unescape($j('<div>').append( $j("#nav-notifications-see-all").clone() ).html()); //outerHtml hack
122                 var notifications_mark = unescape($j('<div>').append( $j("#nav-notifications-mark-all").clone() ).html()); //outerHtml hack
123                 var notifications_empty = unescape($j("#nav-notifications-menu").html());
124                 
125                 /* nav update event  */
126                 $j('nav').bind('nav-update', function(e,data){;
127                         var invalid = $j(data).find('invalid').text();
128                         if(invalid == 1) { window.location.href=window.location.href }
129
130                         var net = $j(data).find('net').text();
131                         if(net == 0) { net = ''; $j('#net-update').removeClass('show') } else { $j('#net-update').addClass('show') }
132                         $j('#net-update').html(net);
133
134                         var home = $j(data).find('home').text();
135                         if(home == 0) { home = '';  $j('#home-update').removeClass('show') } else { $j('#home-update').addClass('show') }
136                         $j('#home-update').html(home);
137                         
138                         var intro = $j(data).find('intro').text();
139                         if(intro == 0) { intro = '';  $j('#intro-update').removeClass('show') } else { $j('#intro-update').addClass('show') }
140                         $j('#intro-update').html(intro);
141
142                         var mail = $j(data).find('mail').text();
143                         if(mail == 0) { mail = '';  $j('#mail-update').removeClass('show') } else { $j('#mail-update').addClass('show') }
144                         $j('#mail-update').html(mail);
145                         
146                         var intro = $j(data).find('intro').text();
147                         if(intro == 0) { intro = '';  $j('#intro-update-li').removeClass('show') } else { $j('#intro-update-li').addClass('show') }
148                         $j('#intro-update-li').html(intro);
149
150                         var mail = $j(data).find('mail').text();
151                         if(mail == 0) { mail = '';  $j('#mail-update-li').removeClass('show') } else { $j('#mail-update-li').addClass('show') }
152                         $j('#mail-update-li').html(mail);
153
154                         var eNotif = $j(data).find('notif')
155                         
156                         if (eNotif.children("note").length==0){
157                                 $j("#nav-notifications-menu").html(notifications_empty);
158                         } else {
159                                 nnm = $j("#nav-notifications-menu");
160                                 nnm.html(notifications_all + notifications_mark);
161                                 //nnm.attr('popup','true');
162                                 eNotif.children("note").each(function(){
163                                         e = $j(this);
164                                         text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
165                                         html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
166                                         nnm.append(html);
167                                 });
168                         }
169                         notif = eNotif.attr('count');
170                         if (notif>0){
171                                 $j("#nav-notifications-linkmenu").addClass("on");
172                         } else {
173                                 $j("#nav-notifications-linkmenu").removeClass("on");
174                         }
175                         if(notif == 0) { notif = ''; $j('#notify-update').removeClass('show') } else { $j('#notify-update').addClass('show') }
176                         $j('#notify-update').html(notif);
177                         
178                         var eSysmsg = $j(data).find('sysmsgs');
179                         eSysmsg.children("notice").each(function(){
180                                 text = $j(this).text();
181                                 $j.jGrowl(text, { sticky: false, theme: 'notice', life: 2000 }); // originally: sticky: true,
182                         });
183                         eSysmsg.children("info").each(function(){
184                                 text = $j(this).text();
185                                 $j.jGrowl(text, { sticky: false, theme: 'info', life: 1500 });
186                         });
187                         
188                 });
189                 
190                 
191                 NavUpdate(); 
192                 // Allow folks to stop the ajax page updates with the pause/break key
193                 $j(document).keydown(function(event) {
194                         if(event.keyCode == '8') {
195                                 var target = event.target || event.srcElement;
196                                 if (!/input|textarea/i.test(target.nodeName)) {
197                                         return false;
198                                 }
199                         }
200                         if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
201                                 event.preventDefault();
202                                 if(stopped == false) {
203                                         stopped = true;
204                                         if (event.ctrlKey) {
205                                                 totStopped = true;
206                                         }
207                                         $j('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
208                                 } else {
209                                         unpause();
210                                 }
211                         } else {
212                                 if (!totStopped) {
213                                         unpause();
214                                 }
215                         }
216                 });
217                 
218                 
219         });
220
221         function NavUpdate() {
222
223                 if(! stopped) {
224                         var pingCmd = 'ping' + ((localUser != 0) ? '?f=&uid=' + localUser : '');
225                         $j.get(pingCmd,function(data) {
226                                 $j(data).find('result').each(function() {
227                                         // send nav-update event
228                                         $j('nav').trigger('nav-update', this);
229                                         
230                                         
231                                         // start live update
232
233                                         
234
235                                         if($j('#live-network').length)   { src = 'network'; liveUpdate(); }
236                                         if($j('#live-profile').length)   { src = 'profile'; liveUpdate(); }
237                                         if($j('#live-community').length) { src = 'community'; liveUpdate(); }
238                                         if($j('#live-notes').length)     { src = 'notes'; liveUpdate(); }
239                                         if($j('#live-display').length) {
240                                                 if(liking) {
241                                                         liking = 0;
242                                                         window.location.href=window.location.href 
243                                                 }
244                                         }
245                                         if($j('#live-photos').length) {
246                                                 if(liking) {
247                                                         liking = 0;
248                                                         window.location.href=window.location.href 
249                                                 }
250                                         }
251
252                                         
253                                         
254                                         
255                                 });
256                         }) ;
257                 }
258                 timer = setTimeout(NavUpdate,updateInterval);
259         }
260
261         function liveUpdate() {
262                 if((src == null) || (stopped) || (! profile_uid)) { $j('.like-rotator').hide(); return; }
263                 if(($j('.comment-edit-text-full').length) || (in_progress)) {
264                         if(livetime) {
265                                 clearTimeout(livetime);
266                         }
267                         livetime = setTimeout(liveUpdate, 10000);
268                         return;
269                 }
270                 if(livetime != null)
271                         livetime = null;
272
273                 prev = 'live-' + src;
274
275                 in_progress = true;
276                 var udargs = ((netargs.length) ? '/' + netargs : '');
277                 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
278
279                 $j.get(update_url,function(data) {
280                         in_progress = false;
281                         //                      $j('.collapsed-comments',data).each(function() {
282                         //      var ident = $j(this).attr('id');
283                         //      var is_hidden = $j('#' + ident).is(':hidden');
284                         //      if($j('#' + ident).length) {
285                         //              $j('#' + ident).replaceWith($j(this));
286                         //              if(is_hidden)
287                         //                      $j('#' + ident).hide();
288                         //      }
289                         //});
290
291                         // add a new thread
292
293                         $j('.toplevel_item',data).each(function() {
294                                 var ident = $j(this).attr('id');
295
296                                 if($j('#' + ident).length == 0 && profile_page == 1) {
297                                         $j('img',this).each(function() {
298                                                 $j(this).attr('src',$j(this).attr('dst'));
299                                         });
300                                         $j('#' + prev).after($j(this));
301                                 }
302                                 else {
303                                         $j('img',this).each(function() {
304                                                 $j(this).attr('src',$j(this).attr('dst'));
305                                         });
306                                         $j('#' + ident).replaceWith($j(this));
307                                 }
308                                 prev = ident;
309                         });
310
311                         // reset vars for inserting individual items
312
313                         /*prev = 'live-' + src;
314
315                         $j('.wall-item-outside-wrapper',data).each(function() {
316                                 var ident = $j(this).attr('id');
317
318                                 if($j('#' + ident).length == 0 && prev != 'live-' + src) {
319                                                 $j('img',this).each(function() {
320                                                         $j(this).attr('src',$j(this).attr('dst'));
321                                                 });
322                                                 $j('#' + prev).after($j(this));
323                                 }
324                                 else { 
325                                         $j('#' + ident + ' ' + '.wall-item-ago').replaceWith($j(this).find('.wall-item-ago')); 
326                                         if($j('#' + ident + ' ' + '.comment-edit-text-empty').length)
327                                                 $j('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($j(this).find('.wall-item-comment-wrapper'));
328                                         $j('#' + ident + ' ' + '.hide-comments-total').replaceWith($j(this).find('.hide-comments-total'));
329                                         $j('#' + ident + ' ' + '.wall-item-like').replaceWith($j(this).find('.wall-item-like'));
330                                         $j('#' + ident + ' ' + '.wall-item-dislike').replaceWith($j(this).find('.wall-item-dislike'));
331                                         $j('#' + ident + ' ' + '.my-comment-photo').each(function() {
332                                                 $j(this).attr('src',$j(this).attr('dst'));
333                                         });
334                                 }
335                                 prev = ident; 
336                         });*/
337                         
338                         $j('.like-rotator').hide();
339                         if(commentBusy) {
340                                 commentBusy = false;
341                                 $j('body').css('cursor', 'auto');
342                         }
343                         /* autocomplete @nicknames */
344                         $j(".comment-edit-form  textarea").contact_autocomplete(baseurl+"/acl");
345                 });
346         }
347
348         function imgbright(node) {
349                 $j(node).removeClass("drophide").addClass("drop");
350         }
351
352         function imgdull(node) {
353                 $j(node).removeClass("drop").addClass("drophide");
354         }
355
356         // Since our ajax calls are asynchronous, we will give a few 
357         // seconds for the first ajax call (setting like/dislike), then 
358         // run the updater to pick up any changes and display on the page.
359         // The updater will turn any rotators off when it's done. 
360         // This function will have returned long before any of these
361         // events have completed and therefore there won't be any
362         // visible feedback that anything changed without all this
363         // trickery. This still could cause confusion if the "like" ajax call
364         // is delayed and NavUpdate runs before it completes.
365
366         function dolike(ident,verb) {
367                 unpause();
368                 $j('#like-rotator-' + ident.toString()).show();
369                 $j.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
370 //              if(timer) clearTimeout(timer);
371 //              timer = setTimeout(NavUpdate,3000);
372                 liking = 1;
373         }
374
375         function dostar(ident) {
376                 ident = ident.toString();
377 //              $j('#like-rotator-' + ident).show();
378                 $j.get('starred/' + ident, function(data) {
379                         if(data.match(/1/)) {
380                                 $j('#starred-' + ident).addClass('starred');
381                                 $j('#starred-' + ident).removeClass('unstarred');
382                                 $j('#star-' + ident).addClass('hidden');
383                                 $j('#unstar-' + ident).removeClass('hidden');
384                         }
385                         else {                  
386                                 $j('#starred-' + ident).addClass('unstarred');
387                                 $j('#starred-' + ident).removeClass('starred');
388                                 $j('#star-' + ident).removeClass('hidden');
389                                 $j('#unstar-' + ident).addClass('hidden');
390                         }
391 //                      $j('#like-rotator-' + ident).hide();    
392                 });
393         }
394
395         function getPosition(e) {
396                 var cursor = {x:0, y:0};
397                 if ( e.pageX || e.pageY  ) {
398                         cursor.x = e.pageX;
399                         cursor.y = e.pageY;
400                 }
401                 else {
402                         if( e.clientX || e.clientY ) {
403                                 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
404                                 cursor.y = e.clientY + (document.documentElement.scrollTop  || document.body.scrollTop)  - document.documentElement.clientTop;
405                         }
406                         else {
407                                 if( e.x || e.y ) {
408                                         cursor.x = e.x;
409                                         cursor.y = e.y;
410                                 }
411                         }
412                 }
413                 return cursor;
414         }
415
416         var lockvisible = false;
417
418         function lockview(event,id) {
419                 event = event || window.event;
420                 cursor = getPosition(event);
421                 if(lockvisible) {
422                         lockviewhide();
423                 }
424                 else {
425                         lockvisible = true;
426                         $j.get('lockview/' + id, function(data) {
427                                 $j('#panel').html(data);
428                                 $j('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
429                                 $j('#panel').show();
430                         });
431                 }
432         }
433
434         function lockviewhide() {
435                 lockvisible = false;
436                 $j('#panel').hide();
437         }
438
439         function post_comment(id) {
440                 unpause();
441                 commentBusy = true;
442                 $j('body').css('cursor', 'wait');
443                 $j("#comment-preview-inp-" + id).val("0");
444                 $j.post(  
445              "item",  
446              $j("#comment-edit-form-" + id).serialize(),
447                         function(data) {
448                                 if(data.success) {
449                                         $j("#comment-edit-wrapper-" + id).hide();
450                                         $j("#comment-edit-text-" + id).val('');
451                                 var tarea = document.getElementById("comment-edit-text-" + id);
452                                         if(tarea)
453                                                 commentClose(tarea,id);
454                                         if(timer) clearTimeout(timer);
455                                         timer = setTimeout(NavUpdate,10);
456                                 }
457                                 if(data.reload) {
458                                         window.location.href=data.reload;
459                                 }
460                         },
461                         "json"  
462          );  
463          return false;  
464         }
465
466
467         function preview_comment(id) {
468                 $j("#comment-preview-inp-" + id).val("1");
469                 $j("#comment-edit-preview-" + id).show();
470                 $j.post(  
471              "item",  
472              $j("#comment-edit-form-" + id).serialize(),
473                         function(data) {
474                                 if(data.preview) {
475                                                 
476                                         $j("#comment-edit-preview-" + id).html(data.preview);
477                                         $j("#comment-edit-preview-" + id + " a").click(function() { return false; });
478                                 }
479                         },
480                         "json"  
481          );  
482          return true;  
483         }
484
485
486
487         function preview_post() {
488                 $j("#jot-preview").val("1");
489                 $j("#jot-preview-content").show();
490                 tinyMCE.triggerSave();
491                 $j.post(  
492                         "item",  
493                         $j("#profile-jot-form").serialize(),
494                         function(data) {
495                                 if(data.preview) {                      
496                                         $j("#jot-preview-content").html(data.preview);
497                                         $j("#jot-preview-content" + " a").click(function() { return false; });
498                                 }
499                         },
500                         "json"  
501                 );  
502                 $j("#jot-preview").val("0");
503                 return true;  
504         }
505
506
507         function unpause() {
508                 // unpause auto reloads if they are currently stopped
509                 totStopped = false;
510                 stopped = false;
511             $j('#pause').html('');
512         }
513                 
514
515     function bin2hex(s){  
516         // Converts the binary representation of data to hex    
517         //   
518         // version: 812.316  
519         // discuss at: http://phpjs.org/functions/bin2hex  
520         // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)  
521         // +   bugfixed by: Onno Marsman  
522         // +   bugfixed by: Linuxworld  
523         // *     example 1: bin2hex('Kev');  
524         // *     returns 1: '4b6576'  
525         // *     example 2: bin2hex(String.fromCharCode(0x00));  
526         // *     returns 2: '00'  
527         var v,i, f = 0, a = [];  
528         s += '';  
529         f = s.length;  
530           
531         for (i = 0; i<f; i++) {  
532             a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");  
533         }  
534           
535         return a.join('');  
536     }  
537
538         function groupChangeMember(gid, cid, sec_token) {
539                 $j('body .fakelink').css('cursor', 'wait');
540                 $j.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
541                                 $j('#group-update-wrapper').html(data);
542                                 $j('body .fakelink').css('cursor', 'auto');                             
543                 });
544         }
545
546         function profChangeMember(gid,cid) {
547                 $j('body .fakelink').css('cursor', 'wait');
548                 $j.get('profperm/' + gid + '/' + cid, function(data) {
549                                 $j('#prof-update-wrapper').html(data);
550                                 $j('body .fakelink').css('cursor', 'auto');                             
551                 });
552         }
553
554         function contactgroupChangeMember(gid,cid) {
555                 $j('body').css('cursor', 'wait');
556                 $j.get('contactgroup/' + gid + '/' + cid, function(data) {
557                                 $j('body').css('cursor', 'auto');
558                 });
559         }
560
561
562 function checkboxhighlight(box) {
563   if($j(box).is(':checked')) {
564         $j(box).addClass('checkeditem');
565   }
566   else {
567         $j(box).removeClass('checkeditem');
568   }
569 }
570
571 function notifyMarkAll() {
572         $j.get('notify/mark/all', function(data) {
573                 if(timer) clearTimeout(timer);
574                 timer = setTimeout(NavUpdate,1000);
575         });
576 }
577
578
579 // code from http://www.tinymce.com/wiki.php/How-to_implement_a_custom_file_browser
580 function fcFileBrowser (field_name, url, type, win) {
581     /* TODO: If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
582        the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
583        These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
584
585
586     var cmsURL = baseurl+"/fbrowser/"+type+"/";
587
588     tinyMCE.activeEditor.windowManager.open({
589         file : cmsURL,
590         title : 'File Browser',
591         width : 420,  // Your dimensions may differ - toy around with them!
592         height : 400,
593         resizable : "yes",
594         inline : "yes",  // This parameter only has an effect if you use the inlinepopups plugin!
595         close_previous : "no"
596     }, {
597         window : win,
598         input : field_name
599     });
600     return false;
601   }
602
603 function setupFieldRichtext(){
604         tinyMCE.init({
605                 theme : "advanced",
606                 mode : "specific_textareas",
607                 editor_selector: "fieldRichtext",
608                 plugins : "bbcode,paste, inlinepopups",
609                 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
610                 theme_advanced_buttons2 : "",
611                 theme_advanced_buttons3 : "",
612                 theme_advanced_toolbar_location : "top",
613                 theme_advanced_toolbar_align : "center",
614                 theme_advanced_blockformats : "blockquote,code",
615                 paste_text_sticky : true,
616                 entity_encoding : "raw",
617                 add_unload_trigger : false,
618                 remove_linebreaks : false,
619                 force_p_newlines : false,
620                 force_br_newlines : true,
621                 forced_root_block : '',
622                 convert_urls: false,
623                 content_css: baseurl+"/view/custom_tinymce.css",
624                 theme_advanced_path : false,
625                 file_browser_callback : "fcFileBrowser",
626         });
627 }
628
629
630 /** 
631  * sprintf in javascript 
632  *      "{0} and {1}".format('zero','uno'); 
633  **/
634 String.prototype.format = function() {
635     var formatted = this;
636     for (var i = 0; i < arguments.length; i++) {
637         var regexp = new RegExp('\\{'+i+'\\}', 'gi');
638         formatted = formatted.replace(regexp, arguments[i]);
639     }
640     return formatted;
641 };
642 // Array Remove
643 Array.prototype.remove = function(item) {
644   to=undefined; from=this.indexOf(item);
645   var rest = this.slice((to || from) + 1 || this.length);
646   this.length = from < 0 ? this.length + from : from;
647   return this.push.apply(this, rest);
648 };
649
650 function previewTheme(elm) {
651         theme = $j(elm).val();
652         $j.getJSON('pretheme?f=&theme=' + theme,function(data) {
653                         $j('#theme-preview').html('<div id="theme-desc">' + data.desc + '</div><div id="theme-version">' + data.version + '</div><div id="theme-credits">' + data.credits + '</div><a href="' + data.img + '"><img src="' + data.img + '" width="320" height="240" alt="' + theme + '" /></a>');
654         });
655
656 }