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