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