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