var current_page_sid = 'V10-P3jjEtgki0Wv'; var tpl_liked_avatar_render,tpl_comment_render; var update_liked_avatar = function () { var $cnt = $('#wx_share_info_well .bdg_like'); var len = +$cnt.text(); return $.get('http://wxdev.doctorcom.com/ajax_get_liked_fromshare/' + current_page_sid, {len:len}) .done(function (ret) { if(ret.like_list.length > 0) { len = len + ret.like_list.length; $cnt.text(len); var h = tpl_liked_avatar_render(ret); $('#liked_users').prepend(h); _.delay(function () { $('#liked_users :hidden').fadeIn('slow'); var _new = $('#liked_users img.has-tooltip:lt('+len+')').tooltip('show'); _.delay(function() { _new.tooltip('hide'); }, 2000); }, 500); } }).always(function() { setTimeout(update_liked_avatar, 5000); }); }; var update_comment = function(lastid) { var $panel = $("#comment_panel"); var url = 'http://wxdev.doctorcom.com/ajax_get_sharecomment/page_id/' + current_page_sid + '/full'; if(_.isString(lastid) && lastid !== '') { url += '?lastid=' + $panel.data('lastid'); } return $.getJSON(url) .done(function (ret) { $panel.data('lastid', ret.data.lastid); if($panel.data('firstid') === undefined) { console.log('firstid' + ret.data.firstid) $panel.data('firstid', ret.data.firstid); } $panel.find(".comments_count").text(ret.data.comments_count); if(ret.data.comments.length > 0) { var h = tpl_comment_render(ret); $panel.find('.list-group').append(h) $panel.find('.comment_content').slideDown(); $panel.find('.panel-body').find('div:hidden').slideDown(); } }); }; var update_new_comment = function() { var $panel = $("#comment_panel"); var firstid = $panel.data('firstid'); if(!firstid) { return; } console.log('firstid: '+firstid) var url = 'http://wxdev.doctorcom.com/ajax_get_sharecomment/page_id/' + current_page_sid + '/full?firstid='+firstid; console.log(url); return $.getJSON(url) .done(function (ret) { if(ret.data.firstid) { $panel.data('firstid', ret.data.firstid); } $panel.find(".comments_count").text(ret.data.comments_count); if(ret.data.comments.length > 0) { var h = tpl_comment_render(ret); $panel.find('.list-group').prepend(h); $panel.find('.panel-body').find('div:hidden').slideDown(); } }) .always(function() { setTimeout(update_new_comment, 5000); }); }; $(function (){ tpl_liked_avatar_render = _.template($("#tpl_liked_avatar").html()); tpl_comment_render =_.template($("#tpl_comment").html()); update_liked_avatar(); update_comment() .done(function () { update_new_comment(); }); $("#wx_share_info_well").tooltip({ selector: '.has-tooltip' }); $('button.comment-more').on('click', function(evn) { var $panel = $("#comment_panel"); update_comment($panel.data('lastid')) .done(function(ret){ if(ret.data.limit < ret.data.comments.length || ret.data.comments.length == 0) { $(evn.currentTarget).text('到底啦!').prop('disabled', true); } }); }); });