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