]> git.mxchange.org Git - friendica.git/blobdiff - view/theme/frost-mobile/js/main.js
Merge branch 'feature/2014-09-hackathon-ui-improvements' into develop
[friendica.git] / view / theme / frost-mobile / js / main.js
index a32d38ede70c84eb68bf1d65817336b6c14e9a45..1b63a489d69243ef445af8e3296cdb0aa5e7df7a 100644 (file)
@@ -1,27 +1,39 @@
 
-  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(listID) {
+/*             if(document.getElementById(theID).style.display == "block") { 
+                       document.getElementById(theID).style.display = "none" 
+               }
+               else { 
+                       document.getElementById(theID).style.display = "block" 
+               }*/
+               listID = "#" + listID.replace(/:/g, "\\:");
+               listID = listID.replace(/\./g, "\\.");
+               listID = listID.replace(/@/g, "\\@");
+
+               if($(listID).is(":visible")) {
+                       $(listID).hide();
+                       $(listID+"-wrapper").show();
+                       alert($(listID+"-wrapper").attr("id"));
+               }
+               else {
+                       $(listID).show();
+                       $(listID+"-wrapper").hide();
+               }
+       }
 
-  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" 
+       }
 
 
 
        var src = null;
        var prev = null;
        var livetime = null;
-       var msie = false;
        var stopped = false;
        var totStopped = false;
        var timer = null;
@@ -36,8 +48,8 @@
        $(function() {
                $.ajaxSetup({cache: false});
 
-               msie = $.browser.msie ;
-               
+               collapseHeight();
+
                /* setup tooltips *//*
                $("a,.tt").each(function(){
                        var e = $(this);
@@ -78,7 +90,7 @@
                        if( last_popup_menu ) {
                                if( '#' + last_popup_menu.attr('id') !== $(e.target).attr('rel')) {
                                        last_popup_menu.hide();
-                                       if (last_popup_menu.attr('id') == "nav-notifications-menu" ) $('section').show();
+                                       if (last_popup_menu.attr('id') == "nav-notifications-menu" ) $('.main-container').show();
                                        last_popup_button.removeClass("selected");
                                        last_popup_menu = null;
                                        last_popup_button = null;
                        if (menu.css("display") == "none") {
                                $(this).parent().addClass("selected");
                                menu.show();
-                               if (menu.attr('id') == "nav-notifications-menu" ) $('section').hide();
+                               if (menu.attr('id') == "nav-notifications-menu" ) $('.main-container').hide();
                                last_popup_menu = menu;
                                last_popup_button = $(this).parent();
                        } else {
                                $(this).parent().removeClass("selected");
                                menu.hide();
-                               if (menu.attr('id') == "nav-notifications-menu" ) $('section').show();
+                               if (menu.attr('id') == "nav-notifications-menu" ) $('.main-container').show();
                                last_popup_menu = null;
                                last_popup_button = null;
                        }
                });
                
                // fancyboxes
-               /*$("a.popupbox").fancybox({
-                       'transitionIn' : 'elastic',
-                       'transitionOut' : 'elastic'
+               /*$("a.popupbox").colorbox({
+                       'inline' : true,
+                       'transition' : 'none'
                });*/
                
 
                                        html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
                                        nnm.append(html);
                                });
+
+                               $("img[data-src]", nnm).each(function(i, el){
+                                       // Add src attribute for images with a data-src attribute
+                                       // However, don't bother if the data-src attribute is empty, because
+                                       // an empty "src" tag for an image will cause some browsers
+                                       // to prefetch the root page of the Friendica hub, which will
+                                       // unnecessarily load an entire profile/ or network/ page
+                                       if($(el).data("src") != '') $(el).attr('src', $(el).data("src"));
+                               });
                        }
                        notif = eNotif.attr('count');
                        if (notif>0){
                        var eSysmsg = $(data).find('sysmsgs');
                        eSysmsg.children("notice").each(function(){
                                text = $(this).text();
-                               $.jGrowl(text, { sticky: true, theme: 'notice', life: 1000 });
+                               $.jGrowl(text, { sticky: false, theme: 'notice', life: 1000 });
                        });
                        eSysmsg.children("info").each(function(){
                                text = $(this).text();
                                        if($('#live-profile').length)   { src = 'profile'; liveUpdate(); }
                                        if($('#live-community').length) { src = 'community'; liveUpdate(); }
                                        if($('#live-notes').length)     { src = 'notes'; liveUpdate(); }
-                                       if($('#live-display').length) {
+                                       if($('#live-display').length) { src = 'display'; liveUpdate(); }
+                                       /*if($('#live-display').length) {
                                                if(liking) {
                                                        liking = 0;
                                                        window.location.href=window.location.href 
                                                }
-                                       }
+                                       }*/
                                        if($('#live-photos').length) {
                                                if(liking) {
                                                        liking = 0;
        }
 
        function liveUpdate() {
-               if((src == null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; }
+               if((src == null) || (stopped) || (typeof profile_uid == 'undefined') || (! profile_uid)) { $('.like-rotator').hide(); return; }
                if(($('.comment-edit-text-full').length) || (in_progress)) {
                        if(livetime) {
                                clearTimeout(livetime);
 
                in_progress = true;
                var udargs = ((netargs.length) ? '/' + netargs : '');
-               var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
+               var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page;
 
                $.get(update_url,function(data) {
                        in_progress = false;
 
                        // add a new thread
 
-                       $('.tread-wrapper',data).each(function() {
+                       $('.toplevel_item',data).each(function() {
                                var ident = $(this).attr('id');
 
                                if($('#' + ident).length == 0 && profile_page == 1) {
                                        $('#' + prev).after($(this));
                                }
                                else {
+                                       // Find out if the hidden comments are open, so we can keep it that way
+                                       // if a new comment has been posted
+                                       var id = $('.hide-comments-total', this).attr('id');
+                                       if(typeof id != 'undefined') {
+                                               id = id.split('-')[3];
+                                               var commentsOpen = $("#collapsed-comments-" + id).is(":visible");
+                                       }
+
                                        $('img',this).each(function() {
                                                $(this).attr('src',$(this).attr('dst'));
                                        });
+                                       //vScroll = $(document).scrollTop();
+                                       $('html').height($('html').height());
                                        $('#' + ident).replaceWith($(this));
+
+                                       if(typeof id != 'undefined') {
+                                               if(commentsOpen) showHideComments(id);
+                                       }
+                                       $('html').height('auto');
+                                       //$(document).scrollTop(vScroll);
                                }
                                prev = ident;
                        });
 
+
+                       collapseHeight();
+
                        // reset vars for inserting individual items
 
                        /*prev = 'live-' + src;
                        }
                        /* autocomplete @nicknames */
                        $(".comment-edit-form  textarea").contact_autocomplete(baseurl+"/acl");
+
+                       // setup videos, since VideoJS won't take care of any loaded via AJAX
+                       if(typeof videojs != 'undefined') videojs.autoSetup();
                });
        }
 
-       function imgbright(node) {
+       function collapseHeight(elems) {
+               var elemName = '.wall-item-body:not(.divmore)';
+               if(typeof elems != 'undefined') {
+                       elemName = elems + ' ' + elemName;
+               }
+               $(elemName).each(function() {
+                       if($(this).height() > 350) {
+                               $('html').height($('html').height());
+                               $(this).divgrow({ initialHeight: 300, showBrackets: false, speed: 0 });
+                               $(this).addClass('divmore');
+                               $('html').height('auto');
+                       }
+               });
+       }
+
+/*     function imgbright(node) {
                $(node).removeClass("drophide").addClass("drop");
        }
 
        function imgdull(node) {
                $(node).removeClass("drop").addClass("drophide");
-       }
+       }*/
 
        // Since our ajax calls are asynchronous, we will give a few 
        // seconds for the first ajax call (setting like/dislike), then 
                        lockvisible = true;
                        $.get('lockview/' + id, function(data) {
                                $('#panel').html(data);
-                               $('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
+                               $('#panel').css({ 'left': 10 , 'top': cursor.y + 20});
                                $('#panel').show();
                        });
                }
        }
 
 
+       function showHideComments(id) {
+               if( $("#collapsed-comments-" + id).is(":visible")) {
+                       $("#collapsed-comments-" + id).hide();
+                       $("#hide-comments-" + id).html(window.showMore);
+               }
+               else {
+                       $("#collapsed-comments-" + id).show();
+                       $("#hide-comments-" + id).html(window.showFewer);
+                       collapseHeight("#collapsed-comments-" + id);
+               }
+       }
+
 
        function preview_post() {
                $("#jot-preview").val("1");
@@ -623,9 +694,9 @@ function setupFieldRichtext(){
                entity_encoding : "raw",
                add_unload_trigger : false,
                remove_linebreaks : false,
-               force_p_newlines : false,
-               force_br_newlines : true,
-               forced_root_block : '',
+               //force_p_newlines : false,
+               //force_br_newlines : true,
+               forced_root_block : 'div',
                convert_urls: false,
                content_css: baseurl+"/view/custom_tinymce.css",
                theme_advanced_path : false,
@@ -657,7 +728,7 @@ Array.prototype.remove = function(item) {
 function previewTheme(elm) {
        theme = $(elm).val();
        $.getJSON('pretheme?f=&theme=' + theme,function(data) {
-                       $('#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>');
+                       $('#theme-preview').html('<div id="theme-desc">' + data.desc + '</div><div id="theme-version">' + data.version + '</div><div id="theme-credits">' + data.credits + '</div>');
        });
 
 }