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