Showing
6 changed files
with
94 additions
and
31 deletions
@@ -11,8 +11,12 @@ var info = require('./info'), | @@ -11,8 +11,12 @@ var info = require('./info'), | ||
11 | setLazyLoadAndMellipsis = info.setLazyLoadAndMellipsis, | 11 | setLazyLoadAndMellipsis = info.setLazyLoadAndMellipsis, |
12 | loadMore = info.loadMore; | 12 | loadMore = info.loadMore; |
13 | 13 | ||
14 | +var $loadMoreInfo = $('#load-more-info'); | ||
15 | +var $loading = $(''), | ||
16 | + $noMore = $(''); | ||
17 | + | ||
14 | var winH = $(window).height(), | 18 | var winH = $(window).height(), |
15 | - loadMoreH = $('#load-more').height(); | 19 | + loadMoreH = $loadMoreInfo.height(); |
16 | 20 | ||
17 | var $infoList = $('#info-list'), | 21 | var $infoList = $('#info-list'), |
18 | $infos = $infoList.children('.info-list'), | 22 | $infos = $infoList.children('.info-list'), |
@@ -24,6 +28,11 @@ var state = {}; | @@ -24,6 +28,11 @@ var state = {}; | ||
24 | 28 | ||
25 | var mySwiper; | 29 | var mySwiper; |
26 | 30 | ||
31 | +if ($loadMoreInfo.length > 0) { | ||
32 | + $loading = $loadMoreInfo.children('.loading'); | ||
33 | + $noMore = $loadMoreInfo.children('.no-more'); | ||
34 | +} | ||
35 | + | ||
27 | mySwiper = new Swiper('.swiper-container', { | 36 | mySwiper = new Swiper('.swiper-container', { |
28 | lazyLoading: true, | 37 | lazyLoading: true, |
29 | pagination: '.swiper-pagination' | 38 | pagination: '.swiper-pagination' |
@@ -33,13 +42,16 @@ info.initInfosEvt($infoList); | @@ -33,13 +42,16 @@ info.initInfosEvt($infoList); | ||
33 | 42 | ||
34 | //初始化各Nav下资讯加载的状态 | 43 | //初始化各Nav下资讯加载的状态 |
35 | (function() { | 44 | (function() { |
45 | + var gender = $('#gender').val(); | ||
46 | + | ||
36 | $nav.children('.guang-nav-item').each(function() { | 47 | $nav.children('.guang-nav-item').each(function() { |
37 | var type = $(this).data('type'); | 48 | var type = $(this).data('type'); |
38 | 49 | ||
39 | state[type] = { | 50 | state[type] = { |
40 | page: 1, | 51 | page: 1, |
41 | - end: false, | ||
42 | - type: type | 52 | + gender: gender, |
53 | + type: type, | ||
54 | + end: false | ||
43 | }; | 55 | }; |
44 | }); | 56 | }); |
45 | }()); | 57 | }()); |
@@ -68,10 +80,19 @@ $nav.delegate('.guang-nav-item', 'touchstart', function() { | @@ -68,10 +80,19 @@ $nav.delegate('.guang-nav-item', 'touchstart', function() { | ||
68 | 80 | ||
69 | $curNav = $this; | 81 | $curNav = $this; |
70 | curType = $this.data('type'); | 82 | curType = $this.data('type'); |
83 | + | ||
84 | + //重置当前Tab的load-more | ||
85 | + if (state[curType].end) { | ||
86 | + $loading.addClass('hide'); | ||
87 | + $noMore.removeClass('hide'); | ||
88 | + } else { | ||
89 | + $loading.removeClass('hide'); | ||
90 | + $noMore.addClass('hide'); | ||
91 | + } | ||
71 | }); | 92 | }); |
72 | 93 | ||
73 | $(document).scroll(function() { | 94 | $(document).scroll(function() { |
74 | - if ($(window).scrollTop() + winH >= $(document).height() - loadMoreH && !state[curType].end) { | 95 | + if ($(window).scrollTop() + winH >= $(document).height() - loadMoreH) { |
75 | loadMore($infos, state[curType]); | 96 | loadMore($infos, state[curType]); |
76 | } | 97 | } |
77 | }); | 98 | }); |
@@ -10,10 +10,19 @@ var $ = require('yoho.zepto'), | @@ -10,10 +10,19 @@ var $ = require('yoho.zepto'), | ||
10 | 10 | ||
11 | var tip = require('../plugin/tip'); | 11 | var tip = require('../plugin/tip'); |
12 | 12 | ||
13 | +var $loadMoreInfo = $('#load-more-info'); | ||
14 | +var $loading = $(''), | ||
15 | + $noMore = $(''); | ||
16 | + | ||
13 | var loading = false; | 17 | var loading = false; |
14 | 18 | ||
15 | ellipsis.init(); | 19 | ellipsis.init(); |
16 | 20 | ||
21 | +if ($loadMoreInfo.length > 0) { | ||
22 | + $loading = $loadMoreInfo.children('.loading'); | ||
23 | + $noMore = $loadMoreInfo.children('.no-more'); | ||
24 | +} | ||
25 | + | ||
17 | /** | 26 | /** |
18 | * 设置指定资讯项的Lazyload和文字截取 | 27 | * 设置指定资讯项的Lazyload和文字截取 |
19 | * @params $infos 资讯项 | 28 | * @params $infos 资讯项 |
@@ -43,17 +52,19 @@ function initInfosEvt($container) { | @@ -43,17 +52,19 @@ function initInfosEvt($container) { | ||
43 | url: '/guang/info/prise', //TODO:cancelPrise | 52 | url: '/guang/info/prise', //TODO:cancelPrise |
44 | data: { | 53 | data: { |
45 | id: $info.data('id') | 54 | id: $info.data('id') |
55 | + }, | ||
56 | + success: function(data) { | ||
57 | + var code = data.code; | ||
58 | + | ||
59 | + if (code === 200) { | ||
60 | + $likeBtn.next('.like-count').text(data.data); | ||
61 | + } else if (code === 400) { | ||
62 | + tip.show('未登录'); | ||
63 | + } | ||
64 | + }, | ||
65 | + error: function() { | ||
66 | + tip.show('网络断开连接了~'); | ||
46 | } | 67 | } |
47 | - }).then(function(data) { | ||
48 | - var code = data.code; | ||
49 | - | ||
50 | - if (code === 200) { | ||
51 | - $likeBtn.next('.like-count').text(data.data); | ||
52 | - } else if (code === 400) { | ||
53 | - tip.show('未登录'); | ||
54 | - } | ||
55 | - }, function() { | ||
56 | - tip.show('网络断开连接了~'); | ||
57 | }); | 68 | }); |
58 | }); | 69 | }); |
59 | 70 | ||
@@ -70,30 +81,42 @@ function loadMore($container, opt) { | @@ -70,30 +81,42 @@ function loadMore($container, opt) { | ||
70 | return; | 81 | return; |
71 | } | 82 | } |
72 | 83 | ||
84 | + if (opt.end) { | ||
85 | + return; | ||
86 | + } | ||
87 | + | ||
73 | loading = true; | 88 | loading = true; |
74 | $.ajax({ | 89 | $.ajax({ |
75 | - type: 'GET', | ||
76 | - url: '/infos/get', | ||
77 | - data: opt | ||
78 | - }).then(function(data) { | ||
79 | - var res, | ||
80 | - $newInfos; | 90 | + type: 'POST', |
91 | + url: ' /guang/list/page', | ||
92 | + data: opt, | ||
93 | + success: function(data) { | ||
94 | + var $newInfos; | ||
95 | + | ||
96 | + //请求结束 | ||
97 | + if (data === ' ') { | ||
98 | + opt.end = true; | ||
99 | + loading = false; | ||
81 | 100 | ||
82 | - if (data.code === 200) { | ||
83 | - res = data.data; | 101 | + // |
102 | + $loading.addClass('hide'); | ||
103 | + $noMore.removeClass('hide'); | ||
84 | 104 | ||
85 | - if (res.end) { | ||
86 | - opt.end = true; | 105 | + return; |
87 | } | 106 | } |
88 | 107 | ||
89 | - $container.append(res.infos); | 108 | + $container.append(data); |
90 | $newInfos = $container.find('.guang-info:gt(' + (infosNum - 1) + ')'); | 109 | $newInfos = $container.find('.guang-info:gt(' + (infosNum - 1) + ')'); |
91 | setLazyLoadAndMellipsis($newInfos); | 110 | setLazyLoadAndMellipsis($newInfos); |
92 | 111 | ||
93 | opt.page++; | 112 | opt.page++; |
94 | - } | ||
95 | 113 | ||
96 | - loading = false; | 114 | + loading = false; |
115 | + }, | ||
116 | + error: function() { | ||
117 | + tip.show('网络断开连接了~'); | ||
118 | + loading = false; | ||
119 | + } | ||
97 | }); | 120 | }); |
98 | } | 121 | } |
99 | 122 |
@@ -12,6 +12,9 @@ var info = require('./info'), | @@ -12,6 +12,9 @@ var info = require('./info'), | ||
12 | var winH = $(window).height(), | 12 | var winH = $(window).height(), |
13 | loadMoreH = $('#load-more').height(); | 13 | loadMoreH = $('#load-more').height(); |
14 | 14 | ||
15 | +var $author = $('#author-infos'); | ||
16 | +var $tag = $('#tag'); | ||
17 | + | ||
15 | var setting = { | 18 | var setting = { |
16 | page: 1, | 19 | page: 1, |
17 | end: false | 20 | end: false |
@@ -21,11 +24,19 @@ var $infos = $('#info-list'); | @@ -21,11 +24,19 @@ var $infos = $('#info-list'); | ||
21 | 24 | ||
22 | info.initInfosEvt($infos); | 25 | info.initInfosEvt($infos); |
23 | 26 | ||
24 | -$(document).scroll(function() { | ||
25 | - if (setting.end) { | ||
26 | - return; | ||
27 | - } | 27 | +if ($author.length > 0) { |
28 | + $.extend(setting, { | ||
29 | + authorId: $author.data('id') | ||
30 | + }); | ||
31 | +} | ||
28 | 32 | ||
33 | +if ($tag.length > 0) { | ||
34 | + $.extend(setting, { | ||
35 | + tag: $tag.val() | ||
36 | + }); | ||
37 | +} | ||
38 | + | ||
39 | +$(document).scroll(function() { | ||
29 | if ($(window).scrollTop() + winH >= $(document).height() - loadMoreH) { | 40 | if ($(window).scrollTop() + winH >= $(document).height() - loadMoreH) { |
30 | loadMore($infos, setting); | 41 | loadMore($infos, setting); |
31 | } | 42 | } |
@@ -51,6 +51,10 @@ a { | @@ -51,6 +51,10 @@ a { | ||
51 | outline: none; | 51 | outline: none; |
52 | } | 52 | } |
53 | 53 | ||
54 | +.hide { | ||
55 | + display: none; | ||
56 | +} | ||
57 | + | ||
54 | @font-face { | 58 | @font-face { |
55 | font-family: "iconfont"; | 59 | font-family: "iconfont"; |
56 | src: font-url('iconfont.eot'); /* IE9*/ | 60 | src: font-url('iconfont.eot'); /* IE9*/ |
@@ -51,6 +51,7 @@ | @@ -51,6 +51,7 @@ | ||
51 | </div> | 51 | </div> |
52 | <span class="no-more status hide">没有更多啦</span> | 52 | <span class="no-more status hide">没有更多啦</span> |
53 | </div> | 53 | </div> |
54 | + <input id="gender" type="hidden" value={{gender}}> | ||
54 | {{/ guang}} | 55 | {{/ guang}} |
55 | </div> | 56 | </div> |
56 | {{> layout/footer}} | 57 | {{> layout/footer}} |
@@ -25,6 +25,9 @@ | @@ -25,6 +25,9 @@ | ||
25 | </div> | 25 | </div> |
26 | <span class="no-more status hide">没有更多啦</span> | 26 | <span class="no-more status hide">没有更多啦</span> |
27 | </div> | 27 | </div> |
28 | + {{#if tag}} | ||
29 | + <input id="tag" type="hidden" value={{tag}}> | ||
30 | + {{/if}} | ||
28 | {{/ guang}} | 31 | {{/ guang}} |
29 | </div> | 32 | </div> |
30 | {{> layout/footer}} | 33 | {{> layout/footer}} |
-
Please register or login to post a comment