Authored by xuqi

guang home hammer

@@ -49,7 +49,7 @@ info.initInfosEvt($infoList); @@ -49,7 +49,7 @@ info.initInfosEvt($infoList);
49 focus = $(this).hasClass('focus'); 49 focus = $(this).hasClass('focus');
50 50
51 state[type] = { 51 state[type] = {
52 - page: focus ? 1 : 0, 52 + page: focus ? 2 : 1,
53 gender: gender, 53 gender: gender,
54 type: type, 54 type: type,
55 end: false 55 end: false
@@ -82,7 +82,7 @@ navHammer.on('tap', function(e) { @@ -82,7 +82,7 @@ navHammer.on('tap', function(e) {
82 curType = $this.data('type'); 82 curType = $this.data('type');
83 83
84 //当未加载数据时去请求数据 84 //当未加载数据时去请求数据
85 - if (state[curType].page === 0) { 85 + if (state[curType].page === 1) {
86 loadMore($content, state[curType]); 86 loadMore($content, state[curType]);
87 } 87 }
88 88
@@ -98,6 +98,6 @@ navHammer.on('tap', function(e) { @@ -98,6 +98,6 @@ navHammer.on('tap', function(e) {
98 98
99 $(document).scroll(function() { 99 $(document).scroll(function() {
100 if ($(window).scrollTop() + winH >= $(document).height() - loadMoreH) { 100 if ($(window).scrollTop() + winH >= $(document).height() - loadMoreH) {
101 - loadMore($infos.not('hide'), state[curType]); 101 + loadMore($infos.not('.hide'), state[curType]);
102 } 102 }
103 }); 103 });
@@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
5 */ 5 */
6 6
7 var $ = require('jquery'), 7 var $ = require('jquery'),
  8 + Hammer = require('hammer'),
8 ellipsis = require('mlellipsis'), 9 ellipsis = require('mlellipsis'),
9 lazyLoad = require('yoho.lazyload'); 10 lazyLoad = require('yoho.lazyload');
10 11
@@ -46,36 +47,43 @@ function setLazyLoadAndMellipsis($infos) { @@ -46,36 +47,43 @@ function setLazyLoadAndMellipsis($infos) {
46 * @params $container 逛资讯列表容器 47 * @params $container 逛资讯列表容器
47 */ 48 */
48 function initInfosEvt($container) { 49 function initInfosEvt($container) {
49 - $container.delegate('.like-btn', 'tap', function(e) {  
50 - var $likeBtn = $(e.currentTarget),  
51 - $info = $likeBtn.closest('.guang-info'),  
52 - opt = 'ok';  
53 -  
54 - if ($likeBtn.hasClass('like')) {  
55 - opt = 'cancel';  
56 - } 50 + var cHammer = new Hammer($container[0]);
  51 +
  52 + cHammer.on('tap', function(e) {
  53 + var $this = $(e.target),
  54 + opt = 'ok',
  55 + $likeBtn,
  56 + $info;
  57 +
  58 + $likeBtn = $this.closest('.like-btn');
  59 + if ($likeBtn.length > 0) {
  60 + if ($likeBtn.hasClass('like')) {
  61 + opt = 'cancel';
  62 + }
57 63
58 - $.ajax({  
59 - type: 'POST',  
60 - url: '/guang/opt/praiseArticle',  
61 - data: {  
62 - id: $info.data('id'),  
63 - opt: opt  
64 - },  
65 - success: function(data) {  
66 - var code = data.code;  
67 -  
68 - if (code === 200) {  
69 - $likeBtn.next('.like-count').text(data.data);  
70 -  
71 - //切换点赞状态  
72 - $likeBtn.toggleClass('like'); 64 + $info = $this.closest('.guang-info');
  65 + $.ajax({
  66 + type: 'POST',
  67 + url: '/guang/opt/praiseArticle',
  68 + data: {
  69 + id: $info.data('id'),
  70 + opt: opt
  71 + },
  72 + success: function(data) {
  73 + var code = data.code;
  74 +
  75 + if (code === 200) {
  76 + $likeBtn.next('.like-count').text(data.data);
  77 +
  78 + //切换点赞状态
  79 + $likeBtn.toggleClass('like');
  80 + }
  81 + },
  82 + error: function() {
  83 + tip.show('网络断开连接了~');
73 } 84 }
74 - },  
75 - error: function() {  
76 - tip.show('网络断开连接了~');  
77 - }  
78 - }); 85 + });
  86 + }
79 }); 87 });
80 88
81 setLazyLoadAndMellipsis($container.find('.guang-info')); 89 setLazyLoadAndMellipsis($container.find('.guang-info'));
@@ -85,6 +93,8 @@ function initInfosEvt($container) { @@ -85,6 +93,8 @@ function initInfosEvt($container) {
85 * 资讯LoadMore 93 * 资讯LoadMore
86 */ 94 */
87 function loadMore($container, opt) { 95 function loadMore($container, opt) {
  96 + var num;
  97 +
88 if (searching) { 98 if (searching) {
89 return; 99 return;
90 } 100 }
@@ -93,18 +103,21 @@ function loadMore($container, opt) { @@ -93,18 +103,21 @@ function loadMore($container, opt) {
93 return; 103 return;
94 } 104 }
95 105
96 - if (opt.page === 0) { 106 + if (opt.page === 1) {
97 107
98 //显示loading 108 //显示loading
99 loading.showLoadingMask(); 109 loading.showLoadingMask();
100 } 110 }
101 111
  112 + num = $container.find('.guang-info').length;
102 searching = true; 113 searching = true;
103 $.ajax({ 114 $.ajax({
104 type: 'GET', 115 type: 'GET',
105 url: ' /guang/index/page', 116 url: ' /guang/index/page',
106 data: opt, 117 data: opt,
107 success: function(data) { 118 success: function(data) {
  119 + var $newItems;
  120 +
108 if (data === ' ') { 121 if (data === ' ') {
109 opt.end = true; 122 opt.end = true;
110 searching = false; 123 searching = false;
@@ -117,9 +130,15 @@ function loadMore($container, opt) { @@ -117,9 +130,15 @@ function loadMore($container, opt) {
117 } 130 }
118 $container.append(data); 131 $container.append(data);
119 132
120 - setLazyLoadAndMellipsis($container.find('.guang-info')); 133 + if (num > 0) {
  134 + $newItems = $container.find('.guang-info:gt(' + (num - 1) + ')');
  135 + } else {
  136 + $newItems = $container.find('.guang-info');
  137 + }
  138 +
  139 + setLazyLoadAndMellipsis($newItems);
121 140
122 - if (opt.page === 0) { 141 + if (opt.page === 1) {
123 loading.hideLoadingMask(); 142 loading.hideLoadingMask();
124 } 143 }
125 144
@@ -16,7 +16,7 @@ var $author = $('#author-infos'); @@ -16,7 +16,7 @@ var $author = $('#author-infos');
16 var $tag = $('#tag'); 16 var $tag = $('#tag');
17 17
18 var setting = { 18 var setting = {
19 - page: 1, 19 + page: 2,
20 end: false 20 end: false
21 }; 21 };
22 22