Committer: dpetrov
LJSUP-9126: Friends times. Hiding users, filtersU trunk/htdocs/js/journal.js
Modified: trunk/htdocs/js/journal.js =================================================================== --- trunk/htdocs/js/journal.js 2011-08-02 10:24:19 UTC (rev 19565) +++ trunk/htdocs/js/journal.js 2011-08-02 10:30:46 UTC (rev 19566) @@ -181,210 +181,6 @@ } }; -(function() { - var prev_page_start, have_prev, list; - - function getList( html ) { - var answer = jQuery( html ), - node = answer.find( '.b-friendstimes' ); - - return node - .add( answer.filter( 'script' ) ); - } - -FriendsTimes = { - initTime: +new Date(), - - init: function( node ) { - prev_page_start = node.attr( 'data-prev-page-start' ); - have_prev = parseInt( node.attr( 'data-have-prev' ), 10 ); - list = node; - - FriendsTimes.checkUnreaded({ - timeout: 5000 - }); - - if( have_prev ) { - FriendsTimes.bindLoadMore({ - max_load: 4 - }); - } - }, - - checkUnreaded: function(conf) { - setInterval(function() { - jQuery.ajax({ - url: LiveJournal.getAjaxUrl("ft_unreaded"), - data: { - after: Site.server_time - }, - dataType: "json", - timeout: conf.timeout - 1, - success: function(data) { - if (+data.unreaded) { - jQuery(".b-friendstimes-f5") - .show() - .find("b").text(data.unreaded); - } - } - }); - }, conf.timeout); - }, - - fetchContent: function( data, success, error ) { - jQuery.ajax({ - url: LiveJournal.getAjaxUrl("ft_more"), - data: data, - dataType: "html", - success: function(html) { - if( html ) { - var node = getList( html ), - li = node.children(), - scripts = node.filter( 'script' ); - - success( node, li, scripts ); - } else { - success; - } - }, - error: error - }); - }, - - /** - * Fetch new posts that have appeared since page load. - * Function loads new posts with ajax if the user is on the first page and there are ten - * or less new posts. - */ - fetchNew: function() { - var blockFunction = false, - content; - - function loadContent() { - FriendsTimes.fetchContent( { - boundary: list.attr( 'data-firstitem' ) - }, function( node, li, scripts ) { - var newBoundary = node.attr( 'data-firstitem' ), - newTs = +new Date(); - - if( li.length ) { - list.attr( 'data-firstitem', newBoundary ); - Site.server_time += Math.floor( ( newTs - FriendsTimes.initTime ) / 1000 ); - FriendsTimes.initTime = newTs; - content = li.add( scripts ); - } - } ); - } - - function renderContent() { - if( !content ) { setTimeout( renderContent, 1000 ); return; } - - jQuery(".b-friendstimes-f5").hide(); - - content - .css( 'opacity', 0.01 ) - .prependTo( list ); - - LiveJournal.parseLikeButtons(); - - setTimeout( function() { - if( jQuery.browser.msie && +jQuery.browser.version <= 8 ) { - content - .css( 'opacity', 1 ) - blockFunction = false; - content = null; - } else { - content - .animate( { opacity: 1 }, 300, function() { - blockFunction = false; - content = null; - } ); - } - }, 200 ); - } - - return function( event ) { - if( blockFunction ) { return false; } - - var unreadNumber = +jQuery(".b-friendstimes-f5 b").text(), - getArgs = LiveJournal.parseGetArgs( location.href ); - - if( unreadNumber > 10 || !!getArgs.to ) { - return; - } - - blockFunction = true; - var animateComplete = false; - jQuery( 'body,html' ).animate( { scrollTop: 0 }, 300, function() { - if( !animateComplete ) { - renderContent(); - animateComplete = true; - } - } ); - loadContent(); - - if( event ) { - event = jQuery.event.fix( event ); - event.preventDefault(); - event.stopPropagation(); - } - } - }(), - - bindLoadMore: function(conf) { - var $window = jQuery(window), - more_node = jQuery(".b-friendstimes-loading"), - loaded_count = 0; - - function loading_more() { - // preload - if ((jQuery(document).height() - 1000) <= ($window.scrollTop() + $window.height())) { - $window.unbind("scroll", loading_more); - FriendsTimes.fetchContent( { to: prev_page_start }, - function( node, li, scripts ) { - if( li ) { - loaded_count++; - list.append( li ).append( scripts ); - LiveJournal.parseLikeButtons(); - prev_page_start = node.attr( 'data-prev-page-start' ); - have_prev = parseInt( node.attr( 'data-have-prev' ), 10 ); - - if (loaded_count < conf.max_load) { - if( have_prev ) { - $window.scroll(loading_more); - } else { - more_node.remove(); - } - } else { - node.nextAll( '.b-friendstimes-pages' ) - .insertAfter( list ) - .show(); - more_node.remove(); - } - } else { - more_node.remove(); - } - }, function() { - // retry - setTimeout(loading_more, 5000); - } ); - } - } - - $window.scroll(loading_more); - loading_more(); - } -}; - -} )(); - -jQuery(function($) { - var ft = $( '#friendstimes' ) - if ( ft.length) { - FriendsTimes.init( ft.find( '.b-friendstimes' ) ); - } -}); - // Share at some S2 styles jQuery(document).click(function(e) {