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