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