]> git.mxchange.org Git - friendica.git/blob - js/main.js
Merge pull request #1 from friendica/develop
[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                                 eNotif.children("note").each(function(){
185                                         e = $(this);
186                                         text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
187                                         html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
188                                         nnm.append(html);
189                                         
190                                         if(e.text().search('&rarr;') == 0) {
191                                          var notification = new Notification(document.title, {
192                                           body: e.text().replace('&rarr; ',''),
193                                           icon: e.attr('photo')
194                                          });
195    
196                                          // TODO (yet unsupported by most browsers): 
197                                          // Implement notification.onclick()
198                                          
199                                          // notifyMarkAll();
200                                        }
201                                 });
202
203                                 $("img[data-src]", nnm).each(function(i, el){
204                                         // Add src attribute for images with a data-src attribute
205                                         // However, don't bother if the data-src attribute is empty, because
206                                         // an empty "src" tag for an image will cause some browsers
207                                         // to prefetch the root page of the Friendica hub, which will
208                                         // unnecessarily load an entire profile/ or network/ page
209                                         if($(el).data("src") != '') $(el).attr('src', $(el).data("src"));
210                                 });
211                         }
212
213                         notif = eNotif.attr('count');
214                         if (notif>0){
215                                 $("#nav-notifications-linkmenu").addClass("on");
216                         } else {
217                                 $("#nav-notifications-linkmenu").removeClass("on");
218                         }
219                         if(notif == 0) { notif = ''; $('#notify-update').removeClass('show') } else { $('#notify-update').addClass('show') }
220                         $('#notify-update').html(notif);
221                         
222                         var eSysmsg = $(data).find('sysmsgs');
223                         eSysmsg.children("notice").each(function(){
224                                 text = $(this).text();
225                                 $.jGrowl(text, { sticky: true, theme: 'notice' });
226                         });
227                         eSysmsg.children("info").each(function(){
228                                 text = $(this).text();
229                                 $.jGrowl(text, { sticky: false, theme: 'info', life: 5000 });
230                         });
231                         
232                 });
233
234                 NavUpdate(); 
235                 // Allow folks to stop the ajax page updates with the pause/break key
236                 $(document).keydown(function(event) {
237                         if(event.keyCode == '8') {
238                                 var target = event.target || event.srcElement;
239                                 if (!/input|textarea/i.test(target.nodeName)) {
240                                         return false;
241                                 }
242                         }
243                         if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
244                                 event.preventDefault();
245                                 if(stopped == false) {
246                                         stopped = true;
247                                         if (event.ctrlKey) {
248                                                 totStopped = true;
249                                         }
250                                         $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
251                                 } else {
252                                         unpause();
253                                 }
254                         } else {
255                                 if (!totStopped) {
256                                         unpause();
257                                 }
258                         }
259                 });
260                 
261                 
262         });
263
264         function NavUpdate() {
265
266                 if(! stopped) {
267                         var pingCmd = 'ping' + ((localUser != 0) ? '?f=&uid=' + localUser : '');
268                         $.get(pingCmd,function(data) {
269                                 $(data).find('result').each(function() {
270                                         // send nav-update event
271                                         $('nav').trigger('nav-update', this);
272                                         
273                                         
274                                         // start live update
275
276                                         if($('#live-network').length)   { src = 'network'; liveUpdate(); }
277                                         if($('#live-profile').length)   { src = 'profile'; liveUpdate(); }
278                                         if($('#live-community').length) { src = 'community'; liveUpdate(); }
279                                         if($('#live-notes').length)     { src = 'notes'; liveUpdate(); }
280                                         if($('#live-display').length)     { src = 'display'; liveUpdate(); }
281 /*                                      if($('#live-display').length) {
282                                                 if(liking) {
283                                                         liking = 0;
284                                                         window.location.href=window.location.href 
285                                                 }
286                                         }*/
287                                         if($('#live-photos').length) { 
288                                                 if(liking) {
289                                                         liking = 0;
290                                                         window.location.href=window.location.href 
291                                                 }
292                                         }
293
294                                         
295                                         
296                                         
297                                 });
298                         }) ;
299                 }
300                 timer = setTimeout(NavUpdate,updateInterval);
301         }
302
303         function liveUpdate() {
304                 if((src == null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; }
305                 if(($('.comment-edit-text-full').length) || (in_progress)) {
306                         if(livetime) {
307                                 clearTimeout(livetime);
308                         }
309                         livetime = setTimeout(liveUpdate, 5000);
310                         return;
311                 }
312                 if(livetime != null)
313                         livetime = null;
314
315                 prev = 'live-' + src;
316
317                 in_progress = true;
318
319                 if ($(document).scrollTop() == 0)
320                         force_update = true;
321
322                 var udargs = ((netargs.length) ? '/' + netargs : '');
323                 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&force=' + ((force_update) ? 1 : 0);
324
325                 $.get(update_url,function(data) {
326                         in_progress = false;
327                         force_update = false;
328                         //                      $('.collapsed-comments',data).each(function() {
329                         //      var ident = $(this).attr('id');
330                         //      var is_hidden = $('#' + ident).is(':hidden');
331                         //      if($('#' + ident).length) {
332                         //              $('#' + ident).replaceWith($(this));
333                         //              if(is_hidden)
334                         //                      $('#' + ident).hide();
335                         //      }
336                         //});
337
338                         // add a new thread
339                         $('.toplevel_item',data).each(function() {
340                                 var ident = $(this).attr('id');
341
342                                 if($('#' + ident).length == 0 && profile_page == 1) {
343                                         $('img',this).each(function() {
344                                                 $(this).attr('src',$(this).attr('dst'));
345                                         });
346                                         $('#' + prev).after($(this));
347                                 }
348                                 else {
349                                         // Find out if the hidden comments are open, so we can keep it that way
350                                         // if a new comment has been posted
351                                         var id = $('.hide-comments-total', this).attr('id');
352                                         if(typeof id != 'undefined') {
353                                                 id = id.split('-')[3];
354                                                 var commentsOpen = $("#collapsed-comments-" + id).is(":visible");
355                                         }
356
357                                         $('img',this).each(function() {
358                                                 $(this).attr('src',$(this).attr('dst'));
359                                         });
360                                         //vScroll = $(document).scrollTop();
361                                         $('html').height($('html').height());
362                                         $('#' + ident).replaceWith($(this));
363
364                                         if(typeof id != 'undefined') {
365                                                 if(commentsOpen) showHideComments(id);
366                                         }
367                                         $('html').height('auto');
368                                         //$(document).scrollTop(vScroll);
369                                 }
370                                 prev = ident;
371                         });
372
373                         // reset vars for inserting individual items
374
375                         /*                      prev = 'live-' + src;
376
377                         $('.wall-item-outside-wrapper',data).each(function() {
378                                 var ident = $(this).attr('id');
379
380                                 if($('#' + ident).length == 0 && prev != 'live-' + src) {
381                                                 $('img',this).each(function() {
382                                                         $(this).attr('src',$(this).attr('dst'));
383                                                 });
384                                                 $('#' + prev).after($(this));
385                                 }
386                                 else { 
387                                         $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago')); 
388                                         if($('#' + ident + ' ' + '.comment-edit-text-empty').length)
389                                                 $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
390                                         $('#' + ident + ' ' + '.hide-comments-total').replaceWith($(this).find('.hide-comments-total'));
391                                         $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
392                                         $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
393                                         $('#' + ident + ' ' + '.my-comment-photo').each(function() {
394                                                 $(this).attr('src',$(this).attr('dst'));
395                                         });
396                                 }
397                                 prev = ident; 
398                         });
399                         */
400                         $('.like-rotator').hide();
401                         if(commentBusy) {
402                                 commentBusy = false;
403                                 $('body').css('cursor', 'auto');
404                         }
405                         /* autocomplete @nicknames */
406                         $(".comment-edit-form  textarea").contact_autocomplete(baseurl+"/acl");
407
408                         // setup videos, since VideoJS won't take care of any loaded via AJAX
409                         if(typeof videojs != 'undefined') videojs.autoSetup();
410                 });
411         }
412
413         function imgbright(node) {
414                 $(node).removeClass("drophide").addClass("drop");
415         }
416
417         function imgdull(node) {
418                 $(node).removeClass("drop").addClass("drophide");
419         }
420
421         // Since our ajax calls are asynchronous, we will give a few 
422         // seconds for the first ajax call (setting like/dislike), then 
423         // run the updater to pick up any changes and display on the page.
424         // The updater will turn any rotators off when it's done. 
425         // This function will have returned long before any of these
426         // events have completed and therefore there won't be any
427         // visible feedback that anything changed without all this
428         // trickery. This still could cause confusion if the "like" ajax call
429         // is delayed and NavUpdate runs before it completes.
430
431         function dolike(ident,verb) {
432                 unpause();
433                 $('#like-rotator-' + ident.toString()).show();
434                 $.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
435                 liking = 1;
436                 force_update = true;
437         }
438
439         function dosubthread(ident) {
440                 unpause();
441                 $('#like-rotator-' + ident.toString()).show();
442                 $.get('subthread/' + ident.toString(), NavUpdate );
443                 liking = 1;
444         }
445
446
447         function dostar(ident) {
448                 ident = ident.toString();
449                 $('#like-rotator-' + ident).show();
450                 $.get('starred/' + ident, function(data) {
451                         if(data.match(/1/)) {
452                                 $('#starred-' + ident).addClass('starred');
453                                 $('#starred-' + ident).removeClass('unstarred');
454                                 $('#star-' + ident).addClass('hidden');
455                                 $('#unstar-' + ident).removeClass('hidden');
456                         }
457                         else {
458                                 $('#starred-' + ident).addClass('unstarred');
459                                 $('#starred-' + ident).removeClass('starred');
460                                 $('#star-' + ident).removeClass('hidden');
461                                 $('#unstar-' + ident).addClass('hidden');
462                         }
463                         $('#like-rotator-' + ident).hide();
464                 });
465         }
466
467         function doignore(ident) {
468                 ident = ident.toString();
469                 $('#like-rotator-' + ident).show();
470                 $.get('ignored/' + ident, function(data) {
471                         if(data.match(/1/)) {
472                                 $('#ignored-' + ident).addClass('ignored');
473                                 $('#ignored-' + ident).removeClass('unignored');
474                                 $('#ignore-' + ident).addClass('hidden');
475                                 $('#unignore-' + ident).removeClass('hidden');
476                         }
477                         else {
478                                 $('#ignored-' + ident).addClass('unignored');
479                                 $('#ignored-' + ident).removeClass('ignored');
480                                 $('#ignore-' + ident).removeClass('hidden');
481                                 $('#unignore-' + ident).addClass('hidden');
482                         }
483                         $('#like-rotator-' + ident).hide();
484                 });
485         }
486
487         function getPosition(e) {
488                 var cursor = {x:0, y:0};
489                 if ( e.pageX || e.pageY  ) {
490                         cursor.x = e.pageX;
491                         cursor.y = e.pageY;
492                 }
493                 else {
494                         if( e.clientX || e.clientY ) {
495                                 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
496                                 cursor.y = e.clientY + (document.documentElement.scrollTop  || document.body.scrollTop)  - document.documentElement.clientTop;
497                         }
498                         else {
499                                 if( e.x || e.y ) {
500                                         cursor.x = e.x;
501                                         cursor.y = e.y;
502                                 }
503                         }
504                 }
505                 return cursor;
506         }
507
508         var lockvisible = false;
509
510         function lockview(event,id) {
511                 event = event || window.event;
512                 cursor = getPosition(event);
513                 if(lockvisible) {
514                         lockviewhide();
515                 }
516                 else {
517                         lockvisible = true;
518                         $.get('lockview/' + id, function(data) {
519                                 $('#panel').html(data);
520                                 $('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
521                                 $('#panel').show();
522                         });
523                 }
524         }
525
526         function lockviewhide() {
527                 lockvisible = false;
528                 $('#panel').hide();
529         }
530
531         function post_comment(id) {
532                 unpause();
533                 commentBusy = true;
534                 $('body').css('cursor', 'wait');
535                 $("#comment-preview-inp-" + id).val("0");
536                 $.post(  
537              "item",  
538              $("#comment-edit-form-" + id).serialize(),
539                         function(data) {
540                                 if(data.success) {
541                                         $("#comment-edit-wrapper-" + id).hide();
542                                         $("#comment-edit-text-" + id).val('');
543                                 var tarea = document.getElementById("comment-edit-text-" + id);
544                                         if(tarea)
545                                                 commentClose(tarea,id);
546                                         if(timer) clearTimeout(timer);
547                                         timer = setTimeout(NavUpdate,10);
548                                         force_update = true;
549                                 }
550                                 if(data.reload) {
551                                         window.location.href=data.reload;
552                                 }
553                         },
554                         "json"  
555          );  
556          return false;  
557         }
558
559
560         function preview_comment(id) {
561                 $("#comment-preview-inp-" + id).val("1");
562                 $("#comment-edit-preview-" + id).show();
563                 $.post(  
564              "item",  
565              $("#comment-edit-form-" + id).serialize(),
566                         function(data) {
567                                 if(data.preview) {
568                                                 
569                                         $("#comment-edit-preview-" + id).html(data.preview);
570                                         $("#comment-edit-preview-" + id + " a").click(function() { return false; });
571                                 }
572                         },
573                         "json"  
574          );  
575          return true;  
576         }
577
578
579
580         function showHideComments(id) {
581                 if( $("#collapsed-comments-" + id).is(":visible")) {
582                         $("#collapsed-comments-" + id).hide();
583                         $("#hide-comments-" + id).html(window.showMore);
584                 }
585                 else {
586                         $("#collapsed-comments-" + id).show();
587                         $("#hide-comments-" + id).html(window.showFewer);
588                 }
589         }
590
591
592
593         function preview_post() {
594                 $("#jot-preview").val("1");
595                 $("#jot-preview-content").show();
596                 tinyMCE.triggerSave();
597                 $.post(  
598                         "item",  
599                         $("#profile-jot-form").serialize(),
600                         function(data) {
601                                 if(data.preview) {                      
602                                         $("#jot-preview-content").html(data.preview);
603                                         $("#jot-preview-content" + " a").click(function() { return false; });
604                                 }
605                         },
606                         "json"  
607                 );  
608                 $("#jot-preview").val("0");
609                 return true;  
610         }
611
612
613         function unpause() {
614                 // unpause auto reloads if they are currently stopped
615                 totStopped = false;
616                 stopped = false;
617             $('#pause').html('');
618         }
619                 
620
621     function bin2hex(s){  
622         // Converts the binary representation of data to hex    
623         //   
624         // version: 812.316  
625         // discuss at: http://phpjs.org/functions/bin2hex  
626         // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)  
627         // +   bugfixed by: Onno Marsman  
628         // +   bugfixed by: Linuxworld  
629         // *     example 1: bin2hex('Kev');  
630         // *     returns 1: '4b6576'  
631         // *     example 2: bin2hex(String.fromCharCode(0x00));  
632         // *     returns 2: '00'  
633         var v,i, f = 0, a = [];  
634         s += '';  
635         f = s.length;  
636           
637         for (i = 0; i<f; i++) {  
638             a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");  
639         }  
640           
641         return a.join('');  
642     }  
643
644         function groupChangeMember(gid, cid, sec_token) {
645                 $('body .fakelink').css('cursor', 'wait');
646                 $.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
647                                 $('#group-update-wrapper').html(data);
648                                 $('body .fakelink').css('cursor', 'auto');                              
649                 });
650         }
651
652         function profChangeMember(gid,cid) {
653                 $('body .fakelink').css('cursor', 'wait');
654                 $.get('profperm/' + gid + '/' + cid, function(data) {
655                                 $('#prof-update-wrapper').html(data);
656                                 $('body .fakelink').css('cursor', 'auto');                              
657                 });
658         }
659
660         function contactgroupChangeMember(gid,cid) {
661                 $('body').css('cursor', 'wait');
662                 $.get('contactgroup/' + gid + '/' + cid, function(data) {
663                                 $('body').css('cursor', 'auto');
664                 });
665         }
666
667
668 function checkboxhighlight(box) {
669   if($(box).is(':checked')) {
670         $(box).addClass('checkeditem');
671   }
672   else {
673         $(box).removeClass('checkeditem');
674   }
675 }
676
677 function notifyMarkAll() {
678         $.get('notify/mark/all', function(data) {
679                 if(timer) clearTimeout(timer);
680                 timer = setTimeout(NavUpdate,1000);
681                 force_update = true;
682         });
683 }
684
685
686 // code from http://www.tinymce.com/wiki.php/How-to_implement_a_custom_file_browser
687 function fcFileBrowser (field_name, url, type, win) {
688     /* TODO: If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
689        the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
690        These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
691
692
693     var cmsURL = baseurl+"/fbrowser/"+type+"/";
694
695     tinyMCE.activeEditor.windowManager.open({
696         file : cmsURL,
697         title : 'File Browser',
698         width : 420,  // Your dimensions may differ - toy around with them!
699         height : 400,
700         resizable : "yes",
701         inline : "yes",  // This parameter only has an effect if you use the inlinepopups plugin!
702         close_previous : "no"
703     }, {
704         window : win,
705         input : field_name
706     });
707     return false;
708   }
709
710 function setupFieldRichtext(){
711         tinyMCE.init({
712                 theme : "advanced",
713                 mode : "specific_textareas",
714                 editor_selector: "fieldRichtext",
715                 plugins : "bbcode,paste, inlinepopups",
716                 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
717                 theme_advanced_buttons2 : "",
718                 theme_advanced_buttons3 : "",
719                 theme_advanced_toolbar_location : "top",
720                 theme_advanced_toolbar_align : "center",
721                 theme_advanced_blockformats : "blockquote,code",
722                 theme_advanced_resizing : true,
723                 paste_text_sticky : true,
724                 entity_encoding : "raw",
725                 add_unload_trigger : false,
726                 remove_linebreaks : false,
727                 //force_p_newlines : false,
728                 //force_br_newlines : true,
729                 forced_root_block : 'div',
730                 convert_urls: false,
731                 content_css: baseurl+"/view/custom_tinymce.css",
732                 theme_advanced_path : false,
733                 file_browser_callback : "fcFileBrowser",
734         });
735 }
736
737
738 /** 
739  * sprintf in javascript 
740  *      "{0} and {1}".format('zero','uno'); 
741  **/
742 String.prototype.format = function() {
743     var formatted = this;
744     for (var i = 0; i < arguments.length; i++) {
745         var regexp = new RegExp('\\{'+i+'\\}', 'gi');
746         formatted = formatted.replace(regexp, arguments[i]);
747     }
748     return formatted;
749 };
750 // Array Remove
751 Array.prototype.remove = function(item) {
752   to=undefined; from=this.indexOf(item);
753   var rest = this.slice((to || from) + 1 || this.length);
754   this.length = from < 0 ? this.length + from : from;
755   return this.push.apply(this, rest);
756 };
757
758 function previewTheme(elm) {
759         theme = $(elm).val();
760         $.getJSON('pretheme?f=&theme=' + theme,function(data) {
761                         $('#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>');
762         });
763
764 }