]> git.mxchange.org Git - friendica.git/blob - view/theme/frost-mobile/js/main.js
Merge branch 'feature/2014-09-hackathon-ui-improvements' into develop
[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, 10000);
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").contact_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                         if($(this).height() > 350) {
406                                 $('html').height($('html').height());
407                                 $(this).divgrow({ initialHeight: 300, showBrackets: false, speed: 0 });
408                                 $(this).addClass('divmore');
409                                 $('html').height('auto');
410                         }
411                 });
412         }
413
414 /*      function imgbright(node) {
415                 $(node).removeClass("drophide").addClass("drop");
416         }
417
418         function imgdull(node) {
419                 $(node).removeClass("drop").addClass("drophide");
420         }*/
421
422         // Since our ajax calls are asynchronous, we will give a few 
423         // seconds for the first ajax call (setting like/dislike), then 
424         // run the updater to pick up any changes and display on the page.
425         // The updater will turn any rotators off when it's done. 
426         // This function will have returned long before any of these
427         // events have completed and therefore there won't be any
428         // visible feedback that anything changed without all this
429         // trickery. This still could cause confusion if the "like" ajax call
430         // is delayed and NavUpdate runs before it completes.
431
432         function dolike(ident,verb) {
433                 unpause();
434                 $('#like-rotator-' + ident.toString()).show();
435                 $.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
436 //              if(timer) clearTimeout(timer);
437 //              timer = setTimeout(NavUpdate,3000);
438                 liking = 1;
439         }
440
441         function dostar(ident) {
442                 ident = ident.toString();
443                 //$('#like-rotator-' + ident).show();
444                 $.get('starred/' + ident, function(data) {
445                         if(data.match(/1/)) {
446                                 $('#starred-' + ident).addClass('starred');
447                                 $('#starred-' + ident).removeClass('unstarred');
448                                 $('#star-' + ident).addClass('hidden');
449                                 $('#unstar-' + ident).removeClass('hidden');
450                         }
451                         else {                  
452                                 $('#starred-' + ident).addClass('unstarred');
453                                 $('#starred-' + ident).removeClass('starred');
454                                 $('#star-' + ident).removeClass('hidden');
455                                 $('#unstar-' + ident).addClass('hidden');
456                         }
457                         //$('#like-rotator-' + ident).hide();   
458                 });
459         }
460
461         function getPosition(e) {
462                 var cursor = {x:0, y:0};
463                 if ( e.pageX || e.pageY  ) {
464                         cursor.x = e.pageX;
465                         cursor.y = e.pageY;
466                 }
467                 else {
468                         if( e.clientX || e.clientY ) {
469                                 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
470                                 cursor.y = e.clientY + (document.documentElement.scrollTop  || document.body.scrollTop)  - document.documentElement.clientTop;
471                         }
472                         else {
473                                 if( e.x || e.y ) {
474                                         cursor.x = e.x;
475                                         cursor.y = e.y;
476                                 }
477                         }
478                 }
479                 return cursor;
480         }
481
482         var lockvisible = false;
483
484         function lockview(event,id) {
485                 event = event || window.event;
486                 cursor = getPosition(event);
487                 if(lockvisible) {
488                         lockviewhide();
489                 }
490                 else {
491                         lockvisible = true;
492                         $.get('lockview/' + id, function(data) {
493                                 $('#panel').html(data);
494                                 $('#panel').css({ 'left': 10 , 'top': cursor.y + 20});
495                                 $('#panel').show();
496                         });
497                 }
498         }
499
500         function lockviewhide() {
501                 lockvisible = false;
502                 $('#panel').hide();
503         }
504
505         function post_comment(id) {
506                 unpause();
507                 commentBusy = true;
508                 $('body').css('cursor', 'wait');
509                 $("#comment-preview-inp-" + id).val("0");
510                 $.post(  
511              "item",  
512              $("#comment-edit-form-" + id).serialize(),
513                         function(data) {
514                                 if(data.success) {
515                                         $("#comment-edit-wrapper-" + id).hide();
516                                         $("#comment-edit-text-" + id).val('');
517                                 var tarea = document.getElementById("comment-edit-text-" + id);
518                                         if(tarea)
519                                                 commentClose(tarea,id);
520                                         if(timer) clearTimeout(timer);
521                                         timer = setTimeout(NavUpdate,10);
522                                 }
523                                 if(data.reload) {
524                                         window.location.href=data.reload;
525                                 }
526                         },
527                         "json"  
528          );  
529          return false;  
530         }
531
532
533         function preview_comment(id) {
534                 $("#comment-preview-inp-" + id).val("1");
535                 $("#comment-edit-preview-" + id).show();
536                 $.post(  
537              "item",  
538              $("#comment-edit-form-" + id).serialize(),
539                         function(data) {
540                                 if(data.preview) {
541                                                 
542                                         $("#comment-edit-preview-" + id).html(data.preview);
543                                         $("#comment-edit-preview-" + id + " a").click(function() { return false; });
544                                 }
545                         },
546                         "json"  
547          );  
548          return true;  
549         }
550
551
552         function showHideComments(id) {
553                 if( $("#collapsed-comments-" + id).is(":visible")) {
554                         $("#collapsed-comments-" + id).hide();
555                         $("#hide-comments-" + id).html(window.showMore);
556                 }
557                 else {
558                         $("#collapsed-comments-" + id).show();
559                         $("#hide-comments-" + id).html(window.showFewer);
560                         collapseHeight("#collapsed-comments-" + id);
561                 }
562         }
563
564
565         function preview_post() {
566                 $("#jot-preview").val("1");
567                 $("#jot-preview-content").show();
568                 tinyMCE.triggerSave();
569                 $.post(  
570                         "item",  
571                         $("#profile-jot-form").serialize(),
572                         function(data) {
573                                 if(data.preview) {                      
574                                         $("#jot-preview-content").html(data.preview);
575                                         $("#jot-preview-content" + " a").click(function() { return false; });
576                                 }
577                         },
578                         "json"  
579                 );  
580                 $("#jot-preview").val("0");
581                 return true;  
582         }
583
584
585         function unpause() {
586                 // unpause auto reloads if they are currently stopped
587                 totStopped = false;
588                 stopped = false;
589             $('#pause').html('');
590         }
591                 
592
593     function bin2hex(s){  
594         // Converts the binary representation of data to hex    
595         //   
596         // version: 812.316  
597         // discuss at: http://phpjs.org/functions/bin2hex  
598         // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)  
599         // +   bugfixed by: Onno Marsman  
600         // +   bugfixed by: Linuxworld  
601         // *     example 1: bin2hex('Kev');  
602         // *     returns 1: '4b6576'  
603         // *     example 2: bin2hex(String.fromCharCode(0x00));  
604         // *     returns 2: '00'  
605         var v,i, f = 0, a = [];  
606         s += '';  
607         f = s.length;  
608           
609         for (i = 0; i<f; i++) {  
610             a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");  
611         }  
612           
613         return a.join('');  
614     }  
615
616         function groupChangeMember(gid, cid, sec_token) {
617                 $('body .fakelink').css('cursor', 'wait');
618                 $.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
619                                 $('#group-update-wrapper').html(data);
620                                 $('body .fakelink').css('cursor', 'auto');                              
621                 });
622         }
623
624         function profChangeMember(gid,cid) {
625                 $('body .fakelink').css('cursor', 'wait');
626                 $.get('profperm/' + gid + '/' + cid, function(data) {
627                                 $('#prof-update-wrapper').html(data);
628                                 $('body .fakelink').css('cursor', 'auto');                              
629                 });
630         }
631
632         function contactgroupChangeMember(gid,cid) {
633                 $('body').css('cursor', 'wait');
634                 $.get('contactgroup/' + gid + '/' + cid, function(data) {
635                                 $('body').css('cursor', 'auto');
636                 });
637         }
638
639
640 function checkboxhighlight(box) {
641   if($(box).is(':checked')) {
642         $(box).addClass('checkeditem');
643   }
644   else {
645         $(box).removeClass('checkeditem');
646   }
647 }
648
649 function notifyMarkAll() {
650         $.get('notify/mark/all', function(data) {
651                 if(timer) clearTimeout(timer);
652                 timer = setTimeout(NavUpdate,1000);
653         });
654 }
655
656
657 // code from http://www.tinymce.com/wiki.php/How-to_implement_a_custom_file_browser
658 function fcFileBrowser (field_name, url, type, win) {
659     /* TODO: If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
660        the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
661        These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
662
663
664     var cmsURL = baseurl+"/fbrowser/"+type+"/";
665
666     tinyMCE.activeEditor.windowManager.open({
667         file : cmsURL,
668         title : 'File Browser',
669         width : 420,  // Your dimensions may differ - toy around with them!
670         height : 400,
671         resizable : "yes",
672         inline : "yes",  // This parameter only has an effect if you use the inlinepopups plugin!
673         close_previous : "no"
674     }, {
675         window : win,
676         input : field_name
677     });
678     return false;
679   }
680
681 function setupFieldRichtext(){
682         tinyMCE.init({
683                 theme : "advanced",
684                 mode : "specific_textareas",
685                 editor_selector: "fieldRichtext",
686                 plugins : "bbcode,paste, inlinepopups",
687                 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
688                 theme_advanced_buttons2 : "",
689                 theme_advanced_buttons3 : "",
690                 theme_advanced_toolbar_location : "top",
691                 theme_advanced_toolbar_align : "center",
692                 theme_advanced_blockformats : "blockquote,code",
693                 paste_text_sticky : true,
694                 entity_encoding : "raw",
695                 add_unload_trigger : false,
696                 remove_linebreaks : false,
697                 //force_p_newlines : false,
698                 //force_br_newlines : true,
699                 forced_root_block : 'div',
700                 convert_urls: false,
701                 content_css: baseurl+"/view/custom_tinymce.css",
702                 theme_advanced_path : false,
703                 file_browser_callback : "fcFileBrowser",
704         });
705 }
706
707
708 /** 
709  * sprintf in javascript 
710  *      "{0} and {1}".format('zero','uno'); 
711  **/
712 String.prototype.format = function() {
713     var formatted = this;
714     for (var i = 0; i < arguments.length; i++) {
715         var regexp = new RegExp('\\{'+i+'\\}', 'gi');
716         formatted = formatted.replace(regexp, arguments[i]);
717     }
718     return formatted;
719 };
720 // Array Remove
721 Array.prototype.remove = function(item) {
722   to=undefined; from=this.indexOf(item);
723   var rest = this.slice((to || from) + 1 || this.length);
724   this.length = from < 0 ? this.length + from : from;
725   return this.push.apply(this, rest);
726 };
727
728 function previewTheme(elm) {
729         theme = $(elm).val();
730         $.getJSON('pretheme?f=&theme=' + theme,function(data) {
731                         $('#theme-preview').html('<div id="theme-desc">' + data.desc + '</div><div id="theme-version">' + data.version + '</div><div id="theme-credits">' + data.credits + '</div>');
732         });
733
734 }