]> git.mxchange.org Git - friendica.git/blobdiff - js/main.js
remove debug logs
[friendica.git] / js / main.js
index 87b95d62ff81e60c9fd0168b2242dde3597fb05c..455df9bb09161dc3103ffdb2c817ac23eaf0ce5a 100644 (file)
@@ -1,3 +1,7 @@
+  function resizeIframe(obj) {
+    obj.style.height = 0;
+    obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
+  }
 
   function openClose(theID) {
     if(document.getElementById(theID).style.display == "block") { 
                setupFieldRichtext();
 
                /* popup menus */
-       function close_last_popup_menu() {
-               if(last_popup_menu) {
-               last_popup_menu.hide();
-               last_popup_button.removeClass("selected");
-               last_popup_menu = null;
-               last_popup_button = null;
-               }
-               }
+               function close_last_popup_menu() {
+                       if(last_popup_menu) {
+                               last_popup_menu.hide();
+                               last_popup_button.removeClass("selected");
+                               last_popup_menu = null;
+                               last_popup_button = null;
+                       }
+               }
                $('a[rel^=#]').click(function(e){
                        e.preventDefault();
-                       var $parent = $(this).parent();
-                       var isSelected = (last_popup_button && $parent.attr('id') == last_popup_button.attr('id'));
+                       var parent = $(this).parent();
+                       var isSelected = (last_popup_button && parent.attr('id') == last_popup_button.attr('id'));
                        close_last_popup_menu();
                        if(isSelected) return false;
                        menu = $( $(this).attr('rel') );
                        e.preventDefault();
                        e.stopPropagation();
                        if (menu.attr('popup')=="false") return false;
-                       $parent.toggleClass("selected");
+                       parent.toggleClass("selected");
                        menu.toggle();
                        if (menu.css("display") == "none") {
                                last_popup_menu = null;
                                last_popup_button = null;
                        } else {
                                last_popup_menu = menu;
-                               last_popup_button = $parent;
+                               last_popup_button = parent;
                        }
                        return false;
                });
                $('html').click(function() {
-                                               close_last_popup_menu();
+                       close_last_popup_menu();
                });
                
                // fancyboxes
                                nnm = $("#nav-notifications-menu");
                                nnm.html(notifications_all + notifications_mark);
                                //nnm.attr('popup','true');
+
+                               var notification_lastitem = localStorage.getItem("notification-lastitem");
+                               var notification_first_id = 0;
+                               
                                eNotif.children("note").each(function(){
                                        e = $(this);
                                        text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
                                        html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
                                        nnm.append(html);
+                                       
+                                       var notification_id = e.attr('href').match(/\d+$/)[0];
+                                       if (notification_lastitem!== null && notification_id!=notification_lastitem) {
+                                               if (notification_first_id===0) notification_first_id = notification_id;
+                                               if (getNotificationPermission()==="granted") {
+                                                       var notification = new Notification(document.title, {
+                                                                                         body: e.text().replace('&rarr; ','').format(e.attr('name')),
+                                                                                         icon: e.attr('photo'),
+                                                                                        });
+                                                       // close notification after 5 secs.
+                                                       // see https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API#Closing_notifications
+                                                       setTimeout(notification.close.bind(notification), 5000);
+                                                       
+                                                       notification.addEventListener("click", function(ev){
+                                                               window.location = ev.target.data;
+                                                       });
+                                               }
+                                       }
+                                       if (notification_id == notification_lastitem) {
+                                               if (notification_first_id===0) notification_first_id = notification_id;
+                                               notification_lastitem = null;
+                                       }
+                               
+                                       
                                });
+                               if (notification_first_id!==0) notification_lastitem = notification_first_id;
+                               localStorage.setItem("notification-lastitem", notification_lastitem)
 
                                $("img[data-src]", nnm).each(function(i, el){
                                        // Add src attribute for images with a data-src attribute
                        });
                        eSysmsg.children("info").each(function(){
                                text = $(this).text();
-                               $.jGrowl(text, { sticky: false, theme: 'info', life: 10000 });
+                               $.jGrowl(text, { sticky: false, theme: 'info', life: 5000 });
                        });
                        
                });
                        if(livetime) {
                                clearTimeout(livetime);
                        }
-                       livetime = setTimeout(liveUpdate, 10000);
+                       livetime = setTimeout(liveUpdate, 5000);
                        return;
                }
                if(livetime != null)
@@ -703,6 +737,7 @@ function setupFieldRichtext(){
                theme_advanced_toolbar_location : "top",
                theme_advanced_toolbar_align : "center",
                theme_advanced_blockformats : "blockquote,code",
+               theme_advanced_resizing : true,
                paste_text_sticky : true,
                entity_encoding : "raw",
                add_unload_trigger : false,
@@ -745,3 +780,16 @@ function previewTheme(elm) {
        });
 
 }
+
+// notification permission settings in localstorage
+// set by settings page
+function getNotificationPermission() {
+       if (window["Notification"] === undefined) {
+               return null;
+       }
+    if (Notification.permission === 'granted') {
+        return localStorage.getItem('notification-permissions');
+    } else {
+        return Notification.permission;
+    }
+}