var $ = require('yoho-jquery'), lazyLoad = require('yoho-jquery-lazyload'); var prising; require('yoho-jquery-dotdotdot'); // 资讯文字截取和lazyload function dotLazy() { // 文字截取 $('.msg-title, .msg-content .content').dotdotdot({ wrap: 'letter' }); // Lazyload lazyLoad($('#msg-list img.lazy')); } // 资讯点赞 $('.guang-page').on('click', '.like-icon', function() { var $this = $(this), msgId = $this.closest('.msg-content').data('id'), url; // 同一资讯多次点击归一处理 if (prising === msgId) { return; } prising = msgId; $this.toggleClass('liked'); // 点赞或取消点赞 if ($this.hasClass('liked')) { url = '/guang/info/praise'; } else { url = '/guang/info/cancelPraise'; } $.ajax({ type: 'GET', url: url, data: { id: msgId, time: new Date().getTime() } }).then(function(data) { if (data.code === 200) { if (data.data * 1 === 0) { $this.next('b').addClass('num-0').children('.num').html('0'); // 隐藏数字显示 } else { $this.next('b').removeClass('num-0').children('.num').html(data.data); } } prising = false; }); }).on('mouseenter mouseleave', '.like-icon', function() { $(this).closest('.like').toggleClass('hover'); }); dotLazy(); exports.dotLazy = dotLazy;