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