]> git.mxchange.org Git - friendica.git/blobdiff - include/main.js
Merge pull request #116 from fabrixxm/admin
[friendica.git] / include / main.js
index c7a3aea4821da620a67886c0346ae094cf3c552b..3cc6079778812cc69564a6dc9f9e29b00390ebfe 100644 (file)
        var langSelect = false;
        var commentBusy = false;
 
-       $(document).ready(function() {
+       $(function() {
                $.ajaxSetup({cache: false});
 
                msie = $.browser.msie ;
+               
+               
+               /* nav update event  */
+               $('nav').bind('nav-update', function(e,data){;
+                       var net = $(data).find('net').text();
+                       if(net == 0) { net = ''; $('#net-update').hide() } else { $('#net-update').show() }
+                       $('#net-update').html(net);
+                       var home = $(data).find('home').text();
+                       if(home == 0) { home = '';  $('#home-update').hide() } else { $('#home-update').show() }
+                       $('#home-update').html(home);
+                       var mail = $(data).find('mail').text();
+                       if(mail == 0) { mail = '';  $('#mail-update').hide() } else { $('#mail-update').show() }
+                       $('#mail-update').html(mail);
+                       var intro = $(data).find('intro').text();
+                       var register = $(data).find('register').text();
+                       if(intro == 0) { intro = ''; }
+                       if(register != 0 && intro != '') { intro = intro+'/'+register; }
+                       if(register != 0 && intro == '') { intro = '0/'+register; }
+                       if (intro == '') { $('#notify-update').hide() } else { $('#notify-update').show() }
+                       $('#notify-update').html(intro);
+               });
+               
+               
                NavUpdate(); 
                // Allow folks to stop the ajax page updates with the pause/break key
                $(document).keypress(function(event) {
                                        $('#pause').html('');
                                }
                        }
-                       // F8 - show/hide language selector
-                       if(event.keyCode == '119') {
-                               if(langSelect) {
-                                       langSelect = false;
-                                       $('#language-selector').hide();
-                               }
-                               else {
-                                       langSelect = true;
-                                       $('#language-selector').show();
-                               }
-                       }               
-
-// this is shift-home on FF, but $ on IE, disabling until I figure out why the diff.
-// update: incompatible usage of onKeyDown vs onKeyPress
-//                     if(event.keyCode == '36' && event.shiftKey == true) {
-//                             if(homebase !== undefined) {
-//                                     event.preventDefault();
-//                                     document.location = homebase;
-//                             }
-//                     }
                });                                     
        });
 
                if(! stopped) {
                        $.get("ping",function(data) {
                                $(data).find('result').each(function() {
-                                       var net = $(this).find('net').text();
-                                       if(net == 0) { net = ''; $('#net-update').hide() } else { $('#net-update').show() }
-                                       $('#net-update').html(net);
-                                       var home = $(this).find('home').text();
-                                       if(home == 0) { home = '';  $('#home-update').hide() } else { $('#home-update').show() }
-                                       $('#home-update').html(home);
-                                       var mail = $(this).find('mail').text();
-                                       if(mail == 0) { mail = '';  $('#mail-update').hide() } else { $('#mail-update').show() }
-                                       $('#mail-update').html(mail);
-                                       var intro = $(this).find('intro').text();
-                                       var register = $(this).find('register').text();
-                                       if(intro == 0) { intro = ''; }
-                                       if(register != 0 && intro != '') { intro = intro+'/'+register; }
-                                       if(register != 0 && intro == '') { intro = '0/'+register; }
-                                       if (intro == '') { $('#notify-update').hide() } else { $('#notify-update').show() }
-                                       $('#notify-update').html(intro);
-
+                                       // send nav-update event
+                                       $('nav').trigger('nav-update', this);
                                });
                        }) ;
                }
                        in_progress = false;
                        $('.ccollapse-wrapper',data).each(function() {
                                var ident = $(this).attr('id');
+                               var is_hidden = $('#' + ident).is(':hidden');
                                if($('#' + ident).length) {
                                        $('#' + ident).replaceWith($(this));
+                                       if(is_hidden)
+                                               $('#' + ident).hide();
                                }
                        });
                        $('.wall-item-outside-wrapper',data).each(function() {
                                var ident = $(this).attr('id');
-                               if($('#' + ident).length == 0) { 
+                               if($('#' + ident).length == 0) {
                                        $('img',this).each(function() {
                                                $(this).attr('src',$(this).attr('dst'));
                                        });
                });
        }
 
+/** 
+ * sprintf in javascript 
+ *     "{0} and {1}".format('zero','uno'); 
+ **/
+String.prototype.format = function() {
+    var formatted = this;
+    for (var i = 0; i < arguments.length; i++) {
+        var regexp = new RegExp('\\{'+i+'\\}', 'gi');
+        formatted = formatted.replace(regexp, arguments[i]);
+    }
+    return formatted;
+};