]> git.mxchange.org Git - friendica.git/blobdiff - js/main.js
Frio Bugfix: clear float at the end of comment-edit
[friendica.git] / js / main.js
index d1fd3765fbc94bcfedd049aa4e99047d99eee913..008d84b0bf1349a9b297226f8de98c818c2bef88 100644 (file)
@@ -5,36 +5,38 @@
 
        function _resizeIframe(obj, desth) {
                var h = obj.style.height;
-               var ch = obj.contentWindow.document.body.scrollHeight + 'px';
-               if (h==ch) {
+               var ch = obj.contentWindow.document.body.scrollHeight;
+               if (h == (ch + 'px')) {
                        return;
                }
-               console.log("_resizeIframe", obj, desth, ch);
-               if (desth!=ch) {
-                       setTimeout(_resizeIframe, 500, obj, ch);
-               } else {
-                       if (ch>0) obj.style.height  = ch;
-                       setTimeout(_resizeIframe, 1000, obj, ch);
+               if (desth == ch && ch>0) {
+                       obj.style.height  = ch + 'px';
                }
+               setTimeout(_resizeIframe, 100, obj, ch);
        }
 
-  function openClose(theID) {
-    if(document.getElementById(theID).style.display == "block") {
-      document.getElementById(theID).style.display = "none"
-    }
-    else {
-      document.getElementById(theID).style.display = "block"
-    }
-  }
+       function openClose(theID) {
+               if(document.getElementById(theID).style.display == "block") {
+                       document.getElementById(theID).style.display = "none"
+               }
+               else {
+                       document.getElementById(theID).style.display = "block"
+               }
+       }
 
-  function openMenu(theID) {
-      document.getElementById(theID).style.display = "block"
-  }
+       function openMenu(theID) {
+               document.getElementById(theID).style.display = "block"
+       }
 
-  function closeMenu(theID) {
-      document.getElementById(theID).style.display = "none"
-  }
+       function closeMenu(theID) {
+               document.getElementById(theID).style.display = "none"
+       }
 
+       function decodeHtml(html) {
+               var txt = document.createElement("textarea");
+               txt.innerHTML = html;
+               return txt.value;
+       }
 
 
        var src = null;
@@ -51,6 +53,7 @@
        var commentBusy = false;
        var last_popup_menu = null;
        var last_popup_button = null;
+       var lockLoadContent = false;
 
        $(function() {
                $.ajaxSetup({cache: false});
                function close_last_popup_menu() {
                        if(last_popup_menu) {
                                last_popup_menu.hide();
+                               last_popup_menu.off('click', function(e) {e.stopPropagation()});
                                last_popup_button.removeClass("selected");
                                last_popup_menu = null;
                                last_popup_button = null;
                                last_popup_button = null;
                        } else {
                                last_popup_menu = menu;
+                               last_popup_menu.on('click', function(e) {e.stopPropagation()});
                                last_popup_button = parent;
                                $('#nav-notifications-menu').perfectScrollbar('update');
                        }
                var notifications_mark = unescape($('<div>').append( $("#nav-notifications-mark-all").clone() ).html()); //outerHtml hack
                var notifications_empty = unescape($("#nav-notifications-menu").html());
 
-               /* enable perfect-scrollbars for nav-notivications-menu */
-               $('#nav-notifications-menu').perfectScrollbar();
-               $('aside').perfectScrollbar();
+               /* enable perfect-scrollbars for different elements */
+               $('#nav-notifications-menu, aside').perfectScrollbar();
 
                /* nav update event  */
                $('nav').bind('nav-update', function(e,data){
                                        var html = notifications_tpl.format(
                                                e.attr('href'),                     // {0}  // link to the source
                                                e.attr('photo'),                    // {1}  // photo of the contact
-                                               text,                               // {2}  // preformatet text (autor + text)
+                                               text,                               // {2}  // preformatted text (autor + text)
                                                e.attr('date'),                     // {3}  // date of notification (time ago)
-                                               seenclass,                          // {4}  // vistiting status of the notification
-                                               new Date(e.attr('timestamp')*1000), // {5}  //date of notification
+                                               seenclass,                          // {4}  // visited status of the notification
+                                               new Date(e.attr('timestamp')*1000), // {5}  // date of notification
                                                e.attr('url'),                      // {6}  // profile url of the contact
-                                               e.text().format(""),                // {7}  // clean status text
-                                               contact                             // {8}  //preformatat author (name + profile url)
+                                               e.text().format(contact),           // {7}  // preformatted html (text including author profile url)
+                                               ''                                  // {8}  // Deprecated
                                        );
                                        nnm.append(html);
                                });
                                        if (notification_lastitem!== null && notification_id > notification_lastitem) {
                                                if (getNotificationPermission()==="granted") {
                                                        var notification = new Notification(document.title, {
-                                                                                         body: e.text().replace('&rarr; ','').format(e.attr('name')),
+                                                                                         body: decodeHtml(e.text().replace('&rarr; ','').format(e.attr('name'))),
                                                                                          icon: e.attr('photo'),
                                                                                         });
                                                        notification['url'] = e.attr('href');
                        }
                });
 
+               // Set an event listener for infinite scroll
+               if(typeof infinite_scroll !== 'undefined') {
+                       $(window).scroll(function(e){
+                               if ($(document).height() != $(window).height()) {
+                                       // First method that is expected to work - but has problems with Chrome
+                                       if ($(window).scrollTop() > ($(document).height() - $(window).height() * 1.5))
+                                               loadScrollContent();
+                               } else {
+                                       // This method works with Chrome - but seems to be much slower in Firefox
+                                       if ($(window).scrollTop() > (($("section").height() + $("header").height() + $("footer").height()) - $(window).height() * 1.5))
+                                               loadScrollContent();
+                               }
+                       });
+               }
+
 
        });
 
                                $('body').css('cursor', 'auto');
                        }
                        /* autocomplete @nicknames */
-                       $(".comment-edit-form  textarea").contact_autocomplete(baseurl+"/acl");
+                       $(".comment-edit-form  textarea").editor_autocomplete(baseurl+"/acl");
+                       /* autocomplete bbcode */
+                       $(".comment-edit-form  textarea").bbco_autocomplete('bbcode');
 
                        // setup videos, since VideoJS won't take care of any loaded via AJAX
                        if(typeof videojs != 'undefined') videojs.autoSetup();
                $('#pause').html('');
        }
 
+       // load more network content (used for infinite scroll)
+       function loadScrollContent() {
+               if (lockLoadContent) return;
+               lockLoadContent = true;
+
+               $("#scroll-loader").fadeIn('normal');
+
+               // the page number to load is one higher than the actual
+               // page number
+               infinite_scroll.pageno+=1;
+
+               console.log('Loading page ' + infinite_scroll.pageno);
+
+               // get the raw content from the next page and insert this content
+               // right before "#conversation-end"
+               $.get('network?mode=raw' + infinite_scroll.reload_uri + '&page=' + infinite_scroll.pageno, function(data) {
+                       $("#scroll-loader").hide();
+                       if ($(data).length > 0) {
+                               $(data).insertBefore('#conversation-end');
+                               lockLoadContent = false;
+                       } else {
+                               $("#scroll-end").fadeIn('normal');
+                       }
+               });
+       }
 
     function bin2hex(s){
         // Converts the binary representation of data to hex