]> git.mxchange.org Git - friendica.git/blob - view/theme/frost-mobile/js/main.js
197d496646cfcdfab30acc123b7d23d8756ed482
[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                                 $("img[data-src]", nnm).each(function(i, el){
192                                         // Replace data-src attribute with src attribute for every image
193                                         $(el).attr('src', $(el).data("src"));
194                                         $(el).removeAttr("data-src");
195                                 });
196                         }
197                         notif = eNotif.attr('count');
198                         if (notif>0){
199                                 $j("#nav-notifications-linkmenu").addClass("on");
200                         } else {
201                                 $j("#nav-notifications-linkmenu").removeClass("on");
202                         }
203                         if(notif == 0) { notif = ''; $j('#notify-update').removeClass('show') } else { $j('#notify-update').addClass('show') }
204                         $j('#notify-update').html(notif);
205                         
206                         var eSysmsg = $j(data).find('sysmsgs');
207                         eSysmsg.children("notice").each(function(){
208                                 text = $j(this).text();
209                                 $j.jGrowl(text, { sticky: false, theme: 'notice', life: 1000 });
210                         });
211                         eSysmsg.children("info").each(function(){
212                                 text = $j(this).text();
213                                 $j.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 /*              $j(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                                         $j('#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                         $j.get(pingCmd,function(data) {
254                                 $j(data).find('result').each(function() {
255                                         // send nav-update event
256                                         $j('nav').trigger('nav-update', this);
257                                         
258                                         
259                                         // start live update
260
261                                         
262
263                                         if($j('#live-network').length)   { src = 'network'; liveUpdate(); }
264                                         if($j('#live-profile').length)   { src = 'profile'; liveUpdate(); }
265                                         if($j('#live-community').length) { src = 'community'; liveUpdate(); }
266                                         if($j('#live-notes').length)     { src = 'notes'; liveUpdate(); }
267                                         if($j('#live-display').length) { src = 'display'; liveUpdate(); }
268                                         /*if($j('#live-display').length) {
269                                                 if(liking) {
270                                                         liking = 0;
271                                                         window.location.href=window.location.href 
272                                                 }
273                                         }*/
274                                         if($j('#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) || (! profile_uid)) { $j('.like-rotator').hide(); return; }
292                 if(($j('.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 + '&msie=' + ((msie) ? 1 : 0);
307
308                 $j.get(update_url,function(data) {
309                         in_progress = false;
310                         //                      $j('.collapsed-comments',data).each(function() {
311                         //      var ident = $j(this).attr('id');
312                         //      var is_hidden = $j('#' + ident).is(':hidden');
313                         //      if($j('#' + ident).length) {
314                         //              $j('#' + ident).replaceWith($j(this));
315                         //              if(is_hidden)
316                         //                      $j('#' + ident).hide();
317                         //      }
318                         //});
319
320                         // add a new thread
321
322                         $j('.toplevel_item',data).each(function() {
323                                 var ident = $j(this).attr('id');
324
325                                 if($j('#' + ident).length == 0 && profile_page == 1) {
326                                         $j('img',this).each(function() {
327                                                 $j(this).attr('src',$j(this).attr('dst'));
328                                         });
329                                         $j('#' + prev).after($j(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 = $j('.hide-comments-total', this).attr('id');
335                                         if(typeof id != 'undefined') {
336                                                 id = id.split('-')[3];
337                                                 var commentsOpen = $j("#collapsed-comments-" + id).is(":visible");
338                                         }
339
340                                         $j('img',this).each(function() {
341                                                 $j(this).attr('src',$j(this).attr('dst'));
342                                         });
343                                         //vScroll = $j(document).scrollTop();
344                                         $j('html').height($j('html').height());
345                                         $j('#' + ident).replaceWith($j(this));
346
347                                         if(typeof id != 'undefined') {
348                                                 if(commentsOpen) showHideComments(id);
349                                         }
350                                         $j('html').height('auto');
351                                         //$j(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                         $j('.wall-item-outside-wrapper',data).each(function() {
364                                 var ident = $j(this).attr('id');
365
366                                 if($j('#' + ident).length == 0 && prev != 'live-' + src) {
367                                                 $j('img',this).each(function() {
368                                                         $j(this).attr('src',$j(this).attr('dst'));
369                                                 });
370                                                 $j('#' + prev).after($j(this));
371                                 }
372                                 else { 
373                                         $j('#' + ident + ' ' + '.wall-item-ago').replaceWith($j(this).find('.wall-item-ago')); 
374                                         if($j('#' + ident + ' ' + '.comment-edit-text-empty').length)
375                                                 $j('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($j(this).find('.wall-item-comment-wrapper'));
376                                         $j('#' + ident + ' ' + '.hide-comments-total').replaceWith($j(this).find('.hide-comments-total'));
377                                         $j('#' + ident + ' ' + '.wall-item-like').replaceWith($j(this).find('.wall-item-like'));
378                                         $j('#' + ident + ' ' + '.wall-item-dislike').replaceWith($j(this).find('.wall-item-dislike'));
379                                         $j('#' + ident + ' ' + '.my-comment-photo').each(function() {
380                                                 $j(this).attr('src',$j(this).attr('dst'));
381                                         });
382                                 }
383                                 prev = ident; 
384                         });*/
385                         
386                         $j('.like-rotator').hide();
387                         if(commentBusy) {
388                                 commentBusy = false;
389                                 $j('body').css('cursor', 'auto');
390                         }
391                         /* autocomplete @nicknames */
392                         $j(".comment-edit-form  textarea").contact_autocomplete(baseurl+"/acl");
393                 });
394         }
395
396         function collapseHeight(elems) {
397                 var elemName = '.wall-item-body:not(.divmore)';
398                 if(typeof elems != 'undefined') {
399                         elemName = elems + ' ' + elemName;
400                 }
401                 $j(elemName).each(function() {
402                         if($j(this).height() > 350) {
403                                 $j('html').height($j('html').height());
404                                 $j(this).divgrow({ initialHeight: 300, showBrackets: false, speed: 0 });
405                                 $j(this).addClass('divmore');
406                                 $j('html').height('auto');
407                         }
408                 });
409         }
410
411         function imgbright(node) {
412                 $j(node).removeClass("drophide").addClass("drop");
413         }
414
415         function imgdull(node) {
416                 $j(node).removeClass("drop").addClass("drophide");
417         }
418
419         // Since our ajax calls are asynchronous, we will give a few 
420         // seconds for the first ajax call (setting like/dislike), then 
421         // run the updater to pick up any changes and display on the page.
422         // The updater will turn any rotators off when it's done. 
423         // This function will have returned long before any of these
424         // events have completed and therefore there won't be any
425         // visible feedback that anything changed without all this
426         // trickery. This still could cause confusion if the "like" ajax call
427         // is delayed and NavUpdate runs before it completes.
428
429         function dolike(ident,verb) {
430                 unpause();
431                 $j('#like-rotator-' + ident.toString()).show();
432                 $j.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
433 //              if(timer) clearTimeout(timer);
434 //              timer = setTimeout(NavUpdate,3000);
435                 liking = 1;
436         }
437
438         function dostar(ident) {
439                 ident = ident.toString();
440                 //$j('#like-rotator-' + ident).show();
441                 $j.get('starred/' + ident, function(data) {
442                         if(data.match(/1/)) {
443                                 $j('#starred-' + ident).addClass('starred');
444                                 $j('#starred-' + ident).removeClass('unstarred');
445                                 $j('#star-' + ident).addClass('hidden');
446                                 $j('#unstar-' + ident).removeClass('hidden');
447                         }
448                         else {                  
449                                 $j('#starred-' + ident).addClass('unstarred');
450                                 $j('#starred-' + ident).removeClass('starred');
451                                 $j('#star-' + ident).removeClass('hidden');
452                                 $j('#unstar-' + ident).addClass('hidden');
453                         }
454                         //$j('#like-rotator-' + ident).hide();  
455                 });
456         }
457
458         function getPosition(e) {
459                 var cursor = {x:0, y:0};
460                 if ( e.touches[0].pageX || e.touches[0].pageY  ) {
461                         cursor.x = e.touches[0].pageX;
462                         cursor.y = e.touches[0].pageY;
463                 }
464                 else {
465                         if( e.touches[0].clientX || e.touches[0].clientY ) {
466                                 cursor.x = e.touches[0].clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
467                                 cursor.y = e.touches[0].clientY + (document.documentElement.scrollTop  || document.body.scrollTop)  - document.documentElement.clientTop;
468                         }
469                         else {
470                                 if( e.touches[0].x || e.touches[0].y ) {
471                                         cursor.touches[0].x = e.touches[0].x;
472                                         cursor.touches[0].y = e.touches[0].y;
473                                 }
474                         }
475                 }
476                 return cursor;
477         }
478
479         var lockvisible = false;
480
481         function lockview(event,id) {
482                 event = event || window.event;
483                 cursor = getPosition(event);
484                 if(lockvisible) {
485                         lockviewhide();
486                 }
487                 else {
488                         lockvisible = true;
489                         $j.get('lockview/' + id, function(data) {
490                                 $j('#panel').html(data);
491                                 $j('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
492                                 $j('#panel').show();
493                         });
494                 }
495         }
496
497         function lockviewhide() {
498                 lockvisible = false;
499                 $j('#panel').hide();
500         }
501
502         function post_comment(id) {
503                 unpause();
504                 commentBusy = true;
505                 $j('body').css('cursor', 'wait');
506                 $j("#comment-preview-inp-" + id).val("0");
507                 $j.post(  
508              "item",  
509              $j("#comment-edit-form-" + id).serialize(),
510                         function(data) {
511                                 if(data.success) {
512                                         $j("#comment-edit-wrapper-" + id).hide();
513                                         $j("#comment-edit-text-" + id).val('');
514                                 var tarea = document.getElementById("comment-edit-text-" + id);
515                                         if(tarea)
516                                                 commentClose(tarea,id);
517                                         if(timer) clearTimeout(timer);
518                                         timer = setTimeout(NavUpdate,10);
519                                 }
520                                 if(data.reload) {
521                                         window.location.href=data.reload;
522                                 }
523                         },
524                         "json"  
525          );  
526          return false;  
527         }
528
529
530         function preview_comment(id) {
531                 $j("#comment-preview-inp-" + id).val("1");
532                 $j("#comment-edit-preview-" + id).show();
533                 $j.post(  
534              "item",  
535              $j("#comment-edit-form-" + id).serialize(),
536                         function(data) {
537                                 if(data.preview) {
538                                                 
539                                         $j("#comment-edit-preview-" + id).html(data.preview);
540                                         $j("#comment-edit-preview-" + id + " a").click(function() { return false; });
541                                 }
542                         },
543                         "json"  
544          );  
545          return true;  
546         }
547
548
549         function showHideComments(id) {
550                 if( $j("#collapsed-comments-" + id).is(":visible")) {
551                         $j("#collapsed-comments-" + id).hide();
552                         $j("#hide-comments-" + id).html(window.showMore);
553                 }
554                 else {
555                         $j("#collapsed-comments-" + id).show();
556                         $j("#hide-comments-" + id).html(window.showFewer);
557                         collapseHeight("#collapsed-comments-" + id);
558                 }
559         }
560
561
562         function preview_post() {
563                 $j("#jot-preview").val("1");
564                 $j("#jot-preview-content").show();
565                 tinyMCE.triggerSave();
566                 $j.post(  
567                         "item",  
568                         $j("#profile-jot-form").serialize(),
569                         function(data) {
570                                 if(data.preview) {                      
571                                         $j("#jot-preview-content").html(data.preview);
572                                         $j("#jot-preview-content" + " a").click(function() { return false; });
573                                 }
574                         },
575                         "json"  
576                 );  
577                 $j("#jot-preview").val("0");
578                 return true;  
579         }
580
581
582         function unpause() {
583                 // unpause auto reloads if they are currently stopped
584                 totStopped = false;
585                 stopped = false;
586             $j('#pause').html('');
587         }
588                 
589
590     function bin2hex(s){  
591         // Converts the binary representation of data to hex    
592         //   
593         // version: 812.316  
594         // discuss at: http://phpjs.org/functions/bin2hex  
595         // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)  
596         // +   bugfixed by: Onno Marsman  
597         // +   bugfixed by: Linuxworld  
598         // *     example 1: bin2hex('Kev');  
599         // *     returns 1: '4b6576'  
600         // *     example 2: bin2hex(String.fromCharCode(0x00));  
601         // *     returns 2: '00'  
602         var v,i, f = 0, a = [];  
603         s += '';  
604         f = s.length;  
605           
606         for (i = 0; i<f; i++) {  
607             a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");  
608         }  
609           
610         return a.join('');  
611     }  
612
613         function groupChangeMember(gid, cid, sec_token) {
614                 $j('body .fakelink').css('cursor', 'wait');
615                 $j.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
616                                 $j('#group-update-wrapper').html(data);
617                                 $j('body .fakelink').css('cursor', 'auto');                             
618                 });
619         }
620
621         function profChangeMember(gid,cid) {
622                 $j('body .fakelink').css('cursor', 'wait');
623                 $j.get('profperm/' + gid + '/' + cid, function(data) {
624                                 $j('#prof-update-wrapper').html(data);
625                                 $j('body .fakelink').css('cursor', 'auto');                             
626                 });
627         }
628
629         function contactgroupChangeMember(gid,cid) {
630                 $j('body').css('cursor', 'wait');
631                 $j.get('contactgroup/' + gid + '/' + cid, function(data) {
632                                 $j('body').css('cursor', 'auto');
633                 });
634         }
635
636
637 function checkboxhighlight(box) {
638   if($j(box).is(':checked')) {
639         $j(box).addClass('checkeditem');
640   }
641   else {
642         $j(box).removeClass('checkeditem');
643   }
644 }
645
646 function notifyMarkAll() {
647         $j.get('notify/mark/all', function(data) {
648                 if(timer) clearTimeout(timer);
649                 timer = setTimeout(NavUpdate,1000);
650         });
651 }
652
653
654 // code from http://www.tinymce.com/wiki.php/How-to_implement_a_custom_file_browser
655 function fcFileBrowser (field_name, url, type, win) {
656     /* TODO: If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
657        the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
658        These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
659
660
661     var cmsURL = baseurl+"/fbrowser/"+type+"/";
662
663     tinyMCE.activeEditor.windowManager.open({
664         file : cmsURL,
665         title : 'File Browser',
666         width : 420,  // Your dimensions may differ - toy around with them!
667         height : 400,
668         resizable : "yes",
669         inline : "yes",  // This parameter only has an effect if you use the inlinepopups plugin!
670         close_previous : "no"
671     }, {
672         window : win,
673         input : field_name
674     });
675     return false;
676   }
677
678 function setupFieldRichtext(){
679         tinyMCE.init({
680                 theme : "advanced",
681                 mode : "specific_textareas",
682                 editor_selector: "fieldRichtext",
683                 plugins : "bbcode,paste, inlinepopups",
684                 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
685                 theme_advanced_buttons2 : "",
686                 theme_advanced_buttons3 : "",
687                 theme_advanced_toolbar_location : "top",
688                 theme_advanced_toolbar_align : "center",
689                 theme_advanced_blockformats : "blockquote,code",
690                 paste_text_sticky : true,
691                 entity_encoding : "raw",
692                 add_unload_trigger : false,
693                 remove_linebreaks : false,
694                 force_p_newlines : false,
695                 force_br_newlines : true,
696                 forced_root_block : '',
697                 convert_urls: false,
698                 content_css: baseurl+"/view/custom_tinymce.css",
699                 theme_advanced_path : false,
700                 file_browser_callback : "fcFileBrowser",
701         });
702 }
703
704
705 /** 
706  * sprintf in javascript 
707  *      "{0} and {1}".format('zero','uno'); 
708  **/
709 String.prototype.format = function() {
710     var formatted = this;
711     for (var i = 0; i < arguments.length; i++) {
712         var regexp = new RegExp('\\{'+i+'\\}', 'gi');
713         formatted = formatted.replace(regexp, arguments[i]);
714     }
715     return formatted;
716 };
717 // Array Remove
718 Array.prototype.remove = function(item) {
719   to=undefined; from=this.indexOf(item);
720   var rest = this.slice((to || from) + 1 || this.length);
721   this.length = from < 0 ? this.length + from : from;
722   return this.push.apply(this, rest);
723 };
724
725 function previewTheme(elm) {
726         theme = $j(elm).val();
727         $j.getJSON('pretheme?f=&theme=' + theme,function(data) {
728                         $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>');
729         });
730
731 }