Authored by 郭成尧

'shop-js'

@@ -13,10 +13,11 @@ var bannerSwiper, @@ -13,10 +13,11 @@ var bannerSwiper,
13 nav1H, 13 nav1H,
14 main1H, 14 main1H,
15 main1oH, 15 main1oH,
  16 + nav2H,
  17 + main2oH,
16 scH, 18 scH,
17 $nav1 = $('#pos-nav'), 19 $nav1 = $('#pos-nav'),
18 - $nav2 = $('#pos-list'),  
19 - sTop; 20 + $nav2 = $('#pos-list');
20 21
21 var tip = require('../../plugin/tip'), 22 var tip = require('../../plugin/tip'),
22 filter = require('../../plugin/filter'), 23 filter = require('../../plugin/filter'),
@@ -24,8 +25,6 @@ var tip = require('../../plugin/tip'), @@ -24,8 +25,6 @@ var tip = require('../../plugin/tip'),
24 25
25 var $subNav = $('.home-sub-nav'), 26 var $subNav = $('.home-sub-nav'),
26 $collect = $('#collect'), 27 $collect = $('#collect'),
27 - $categoryList = $('.category-list'),  
28 - $subGroup = $('.sub-group'),  
29 $goodsContainer = $('#goods-container'), 28 $goodsContainer = $('#goods-container'),
30 $goodsChildren = $goodsContainer.children(), 29 $goodsChildren = $goodsContainer.children(),
31 $ngc = $($goodsChildren.get(0)), 30 $ngc = $($goodsChildren.get(0)),
@@ -44,7 +43,7 @@ var defaultOpt = require('../../common/query-param'); @@ -44,7 +43,7 @@ var defaultOpt = require('../../common/query-param');
44 43
45 var $listNav = $('#list-nav'), 44 var $listNav = $('#list-nav'),
46 45
47 - // 导航数据信息 46 + //导航数据信息
48 navInfo = { 47 navInfo = {
49 new: { 48 new: {
50 order: 1, 49 order: 1,
@@ -53,13 +52,13 @@ var $listNav = $('#list-nav'), @@ -53,13 +52,13 @@ var $listNav = $('#list-nav'),
53 end: false 52 end: false
54 }, 53 },
55 hot: { 54 hot: {
56 - order: 0, 55 + order: 1,
57 reload: true, 56 reload: true,
58 page: 1, 57 page: 1,
59 end: false 58 end: false
60 }, 59 },
61 newest: { 60 newest: {
62 - order: 0, 61 + order: 1,
63 reload: true, 62 reload: true,
64 page: 0, 63 page: 0,
65 end: false 64 end: false
@@ -77,7 +76,7 @@ var $listNav = $('#list-nav'), @@ -77,7 +76,7 @@ var $listNav = $('#list-nav'),
77 end: false 76 end: false
78 } 77 }
79 }, 78 },
80 - $pre = $listNav.find('.active'), // 纪录进入筛选前的active项,初始为选中项 79 + $pre = $listNav.find('.active'), //纪录进入筛选前的active项,初始为选中项
81 searching; 80 searching;
82 81
83 var viewType = 1, // 1-首页,2-上新,3-人气 82 var viewType = 1, // 1-首页,2-上新,3-人气
@@ -85,16 +84,13 @@ var viewType = 1, // 1-首页,2-上新,3-人气 @@ -85,16 +84,13 @@ var viewType = 1, // 1-首页,2-上新,3-人气
85 listModValue = 4 - listCount % 4, 84 listModValue = 4 - listCount % 4,
86 listIndex; 85 listIndex;
87 86
88 -var subdomains = location.protocol + '//m.yohobuy.com';  
89 -  
90 -require('../../common');  
91 lazyLoad($('img.lazy')); 87 lazyLoad($('img.lazy'));
92 88
93 $('.main-wrap').css({ 89 $('.main-wrap').css({
94 position: 'static' 90 position: 'static'
95 }); 91 });
96 92
97 -// 焦点效果 93 +//焦点效果
98 if ($('.banner-swiper').find('li').size() > 1) { 94 if ($('.banner-swiper').find('li').size() > 1) {
99 bannerSwiper = new Swiper('.banner-swiper', { 95 bannerSwiper = new Swiper('.banner-swiper', {
100 lazyLoading: true, 96 lazyLoading: true,
@@ -120,18 +116,18 @@ if ($('.multi-browse').find('li').size() > 1) { @@ -120,18 +116,18 @@ if ($('.multi-browse').find('li').size() > 1) {
120 }); 116 });
121 } 117 }
122 118
123 -// 根据热门品类的个数来改变样式展示 119 +//根据热门品类的个数来改变样式展示
124 // 120 //
125 -if ($categoryList.find('li').length % 4 !== 0) { 121 +if ($('.category-list li').length % 4 !== 0) {
126 $('.category-list li:last-child').addClass('category-list-last-li'); 122 $('.category-list li:last-child').addClass('category-list-last-li');
127 } 123 }
128 124
129 -if ($categoryList.find('li').length < 4) {  
130 - $categoryList.addClass('category-list-top-board');  
131 - $categoryList.find('.buriedpoint').addClass('category-list-only-one-row'); 125 +if ($('.category-list li').length < 4) {
  126 + $('.category-list').addClass('category-list-top-board');
  127 + $('.category-list').find('.buriedpoint').addClass('category-list-only-one-row');
132 } 128 }
133 129
134 -if ($categoryList.find('li').length >= 5) { 130 +if ($('.category-list li').length >= 5) {
135 for (listIndex = listModValue; listIndex >= 0; listIndex--) { 131 for (listIndex = listModValue; listIndex >= 0; listIndex--) {
136 $('.category-list li').eq(listCount - 4 + listIndex - 1).addClass('category-list-last-full-row'); 132 $('.category-list li').eq(listCount - 4 + listIndex - 1).addClass('category-list-last-full-row');
137 } 133 }
@@ -147,7 +143,7 @@ function getPageGoods(info) { @@ -147,7 +143,7 @@ function getPageGoods(info) {
147 navType = info.data.type; 143 navType = info.data.type;
148 nav = navInfo[navType]; 144 nav = navInfo[navType];
149 145
150 - // 不需要重新加载并且数据请求结束 146 + //不需要重新加载并且数据请求结束
151 if (nav.end) { 147 if (nav.end) {
152 148
153 return; 149 return;
@@ -156,16 +152,16 @@ function getPageGoods(info) { @@ -156,16 +152,16 @@ function getPageGoods(info) {
156 searching = true; 152 searching = true;
157 $.ajax({ 153 $.ajax({
158 type: 'GET', 154 type: 'GET',
159 - url: subdomains + '/product/search/search', 155 + url: info.url,
160 data: info.data, 156 data: info.data,
161 - success: function(data) {  
162 - if (data === '') { 157 + success: function (data) {
  158 + if (data === ' ') {
163 nav.end = true; 159 nav.end = true;
164 } 160 }
165 161
166 info.callBack(data); 162 info.callBack(data);
167 }, 163 },
168 - error: function() { 164 + error: function () {
169 alert('网络断开连接了~'); 165 alert('网络断开连接了~');
170 searching = false; 166 searching = false;
171 } 167 }
@@ -185,16 +181,17 @@ function getParam(req) { @@ -185,16 +181,17 @@ function getParam(req) {
185 function newData(callback) { 181 function newData(callback) {
186 var req = {}; 182 var req = {};
187 183
  184 + req.url = location.protocol + '//m.yohobuy.com/index/search/search';
188 req.data = { 185 req.data = {
189 type: 'newest', 186 type: 'newest',
190 - order: '0', 187 + order: '1',
191 page: navInfo.new.page, 188 page: navInfo.new.page,
192 tagNew: '1' 189 tagNew: '1'
193 }; 190 };
194 191
195 getParam(req); 192 getParam(req);
196 193
197 - req.callBack = function(data) { 194 + req.callBack = function (data) {
198 $('#new-arrival').append(data); 195 $('#new-arrival').append(data);
199 navInfo.new.page++; 196 navInfo.new.page++;
200 myScroll.refresh(); 197 myScroll.refresh();
@@ -209,16 +206,17 @@ function newData(callback) { @@ -209,16 +206,17 @@ function newData(callback) {
209 function hotData(callback) { 206 function hotData(callback) {
210 var req = {}; 207 var req = {};
211 208
  209 + req.url = location.protocol + '//m.yohobuy.com/index/search/search';
212 req.data = { 210 req.data = {
213 type: 'hot', 211 type: 'hot',
214 - order: '0', 212 + order: '1',
215 page: navInfo.hot.page, 213 page: navInfo.hot.page,
216 showTag: '1' 214 showTag: '1'
217 }; 215 };
218 216
219 getParam(req); 217 getParam(req);
220 218
221 - req.callBack = function(data) { 219 + req.callBack = function (data) {
222 $('#popularity').append(data); 220 $('#popularity').append(data);
223 navInfo.hot.page++; 221 navInfo.hot.page++;
224 myScroll.refresh(); 222 myScroll.refresh();
@@ -233,21 +231,29 @@ function hotData(callback) { @@ -233,21 +231,29 @@ function hotData(callback) {
233 function tabChange(dom, index) { 231 function tabChange(dom, index) {
234 var li = dom.eq(index); 232 var li = dom.eq(index);
235 233
236 - dom.removeClass('active');  
237 - li.addClass('active');  
238 -  
239 - dom.removeClass('color');  
240 - li.addClass('color'); 234 + dom.removeClass('active color');
  235 + li.addClass('active color');
241 } 236 }
242 237
243 -// 首页导航  
244 -$.jqtab = function(nav, posNav, main) {  
245 238
246 - $(nav + ' li, ' + posNav + ' li').not('li.all-goods').on('touchstart', function() { 239 +myScroll = new IScroll('#wrapper', {
  240 + probeType: 3,
  241 + mouseWheel: true,
  242 + click: true
  243 +});
  244 +
  245 +//首页导航
  246 +(function (nav, posNav, main) {
  247 +
  248 + $(nav + ' li, ' + posNav + ' li').not('li.all-goods').on('touchstart', function () {
247 249
248 var index = $(this).index(), 250 var index = $(this).index(),
249 activeTab = $(this).attr('tab'); 251 activeTab = $(this).attr('tab');
250 252
  253 + if (!$('.filter-mask').hasClass('hide')) {
  254 + return;
  255 + }
  256 +
251 $nav1.removeClass('fixed-top'); 257 $nav1.removeClass('fixed-top');
252 tabChange($(nav + ' li'), index); 258 tabChange($(nav + ' li'), index);
253 tabChange($(posNav + ' li'), index); 259 tabChange($(posNav + ' li'), index);
@@ -263,49 +269,97 @@ $.jqtab = function(nav, posNav, main) { @@ -263,49 +269,97 @@ $.jqtab = function(nav, posNav, main) {
263 269
264 myScroll && myScroll.refresh(); 270 myScroll && myScroll.refresh();
265 scH = $('#scroller').outerHeight(); 271 scH = $('#scroller').outerHeight();
266 - $nav1.removeClass('fixed-top');  
267 - $nav1.removeClass('absolute');  
268 - $nav2.removeClass('fixed-top');  
269 - $nav2.removeClass('absolute'); 272 + $nav1.removeClass('fixed-top absolute');
  273 + $nav2.removeClass('fixed-top absolute');
270 } 274 }
  275 +
271 if (!$nav1.hasClass('hide')) { 276 if (!$nav1.hasClass('hide')) {
272 - myScroll.scrollTo(0, 0 - imgH); 277 + myScroll && myScroll.scrollTo(0, 0 - imgH);
273 } 278 }
274 $nav1.addClass('hide'); 279 $nav1.addClass('hide');
275 }); 280 });
276 -};  
277 -$.jqtab('#nav', '#pos-nav', '.main');  
278 -$('#wrapper').addClass('scroll-wrapper'); 281 +}('#nav', '#pos-nav', '.main'));
279 282
280 -myScroll = new IScroll('#wrapper', {  
281 - probeType: 3,  
282 - mouseWheel: true,  
283 - click: true  
284 -});  
285 -myScroll.on('scroll', function() { 283 +var theY;
  284 +
  285 +/**
  286 + * 筛选后内容变化,导致nav1位置错掉,重新计算确保位置正确显示
  287 + */
  288 +function reNav1Pos() {
  289 + var sTop = theY ? theY : 0;
  290 + if (sTop < imgH + main1oH + nav1H) {
  291 + if ($nav1.hasClass('hide')) {
  292 + $nav1.removeClass('hide');
  293 + }
  294 +
  295 + if (sTop < imgH + main1H) {
  296 + tra = 'translate3d(0, ' + (-scH) + 'px, 0)';
  297 + $nav1.addClass('fixed-top')
  298 + .removeClass('absolute')
  299 + .css({
  300 + transform: tra,
  301 + '-moz-transform': tra,
  302 + '-ms-transform': tra,
  303 + '-webkit-transform': tra
  304 + });
  305 + } else if (sTop < imgH + main1H + nav1H) {
  306 + if ($('#home-page').is(':hidden')) {
  307 + return false;
  308 + }
  309 + $nav1.addClass('absolute')
  310 + .removeClass('fixed-top');
  311 + tra = 'translate3d(0, ' + (imgH + main1H - sTop - scH) + 'px, 0)';
  312 + $nav1.css({
  313 + transform: tra,
  314 + '-moz-transform': tra,
  315 + '-ms-transform': tra,
  316 + '-webkit-transform': tra
  317 + });
  318 + }
  319 + } else {
  320 + if (!$nav1.hasClass('hide')) {
  321 + $nav1.addClass('hide');
  322 + }
  323 + }
  324 +}
  325 +
  326 +myScroll.on('scroll', function () {
286 var scrollCall, 327 var scrollCall,
287 sTop = -this.y; 328 sTop = -this.y;
288 329
  330 + var tra;
  331 +
  332 +
  333 + theY = sTop;
  334 + if (sTop + winH > scH - 0.25 * $goodsContainer.height() - 50) {
  335 + if ($pre !== undefined) {
  336 + search({
  337 + type: 'shop_id',
  338 + id: shopId,
  339 + brand: brand,
  340 + url: location.protocol + '//m.yohobuy.com/index/search/search',
  341 + nextPage: true
  342 + });
  343 + }
  344 + }
  345 +
289 if (sTop + winH * 2 > scH) { 346 if (sTop + winH * 2 > scH) {
  347 + scrollCall = function () {
  348 + var translate = 'translate3d(0, ' + (-scH) + 'px, 0)';
  349 + $nav1.css({
  350 + transform: translate,
  351 + '-moz-transform': translate,
  352 + '-ms-transform': translate,
  353 + '-webkit-transform': translate
  354 + });
  355 + };
290 switch (viewType) { 356 switch (viewType) {
291 case 2: 357 case 2:
292 - scrollCall = function() {  
293 - $nav1.css({  
294 - transform: 'translate(0, ' + (-scH) + 'px)'  
295 - });  
296 - };  
297 newData(scrollCall); 358 newData(scrollCall);
298 break; 359 break;
299 case 3: 360 case 3:
300 - scrollCall = function() {  
301 - $nav1.css({  
302 - transform: 'translate(0, ' + (-scH) + 'px)'  
303 - });  
304 - };  
305 hotData(scrollCall); 361 hotData(scrollCall);
306 break; 362 break;
307 - default:  
308 - break;  
309 } 363 }
310 } 364 }
311 365
@@ -315,24 +369,28 @@ myScroll.on('scroll', function() { @@ -315,24 +369,28 @@ myScroll.on('scroll', function() {
315 } 369 }
316 if (!$nav2.hasClass('hide')) { 370 if (!$nav2.hasClass('hide')) {
317 $nav2.addClass('hide'); 371 $nav2.addClass('hide');
318 - } // 滑动距离不到导航1  
319 - } else if (sTop < imgH + nav1H + main1oH) { 372 + } //滑动距离不到导航1
  373 + } else if (sTop < imgH + main1oH + nav1H) {
320 if ($nav1.hasClass('hide')) { 374 if ($nav1.hasClass('hide')) {
321 $nav1.removeClass('hide'); 375 $nav1.removeClass('hide');
322 } 376 }
323 if (!$nav2.hasClass('hide')) { 377 if (!$nav2.hasClass('hide')) {
324 $nav2.addClass('hide'); 378 $nav2.addClass('hide');
325 - }// 滑动距离不到导航2 379 + } //滑动距离不到导航2
326 380
327 if (sTop < imgH + main1H) { 381 if (sTop < imgH + main1H) {
328 if (!$nav1.hasClass('fixed-top')) { 382 if (!$nav1.hasClass('fixed-top')) {
  383 + tra = 'translate3d(0, ' + (-scH) + 'px, 0)';
329 $nav1.addClass('fixed-top') 384 $nav1.addClass('fixed-top')
330 .removeClass('absolute') 385 .removeClass('absolute')
331 .css({ 386 .css({
332 - transform: 'translate(0, ' + (-scH) + 'px)' 387 + transform: tra,
  388 + '-moz-transform': tra,
  389 + '-ms-transform': tra,
  390 + '-webkit-transform': tra
333 }); 391 });
334 } 392 }
335 - } else if (sTop < imgH + nav1H + main1H) { 393 + } else if (sTop < imgH + main1H + nav1H) {
336 if ($('#home-page').is(':hidden')) { 394 if ($('#home-page').is(':hidden')) {
337 return false; 395 return false;
338 } 396 }
@@ -340,8 +398,12 @@ myScroll.on('scroll', function() { @@ -340,8 +398,12 @@ myScroll.on('scroll', function() {
340 $nav1.addClass('absolute') 398 $nav1.addClass('absolute')
341 .removeClass('fixed-top'); 399 .removeClass('fixed-top');
342 } 400 }
  401 + tra = 'translate3d(0, ' + (imgH + main1H - sTop - scH) + 'px, 0)';
343 $nav1.css({ 402 $nav1.css({
344 - transform: 'translate(0, ' + (imgH + main1H - sTop - scH) + 'px)' 403 + transform: tra,
  404 + '-moz-transform': tra,
  405 + '-ms-transform': tra,
  406 + '-webkit-transform': tra
345 }); 407 });
346 } 408 }
347 } else { 409 } else {
@@ -361,28 +423,58 @@ myScroll.on('scroll', function() { @@ -361,28 +423,58 @@ myScroll.on('scroll', function() {
361 $nav2.addClass('absolute') 423 $nav2.addClass('absolute')
362 .removeClass('fixed-top'); 424 .removeClass('fixed-top');
363 } 425 }
  426 + tra = 'translate3d(0, ' + (-scH) + 'px, 0)';
364 $nav2.css({ 427 $nav2.css({
365 - transform: 'translate(0, ' + (-scH) + 'px)' 428 + transform: tra,
  429 + '-moz-transform': tra,
  430 + '-ms-transform': tra,
  431 + '-webkit-transform': tra
366 }); 432 });
367 } 433 }
368 } 434 }
369 - $('#scroller').trigger('scroll');  
370 }); 435 });
371 436
  437 +myScroll.on('scrollStart', function () {
372 438
  439 + // stop auto play when scroll
  440 + bannerSwiper && bannerSwiper.stopAutoplay();
373 441
374 -document.addEventListener('touchmove', function(e) {  
375 - e.preventDefault(); 442 + multiSwiper && multiSwiper.stopAutoplay();
  443 +});
  444 +
  445 +myScroll.on('scrollEnd', function () {
  446 +
  447 + // start auto play when scroll end
  448 + bannerSwiper && bannerSwiper.startAutoplay();
  449 +
  450 + multiSwiper && multiSwiper.startAutoplay();
  451 +
  452 + $('#scroller').trigger('scroll');
  453 +});
  454 +
  455 +
  456 +document.addEventListener('touchmove', function (e) {
  457 + // sub classify不阻止默认事件
  458 + if ($(e.target).closest('.sub-classify').length === 0) {
  459 + e.preventDefault();
  460 + }
376 }, false); 461 }, false);
377 462
378 -// window onload 后重新refresh iscroll  
379 -$(window).load(function() { 463 +/*if (!isIphone) {
  464 + return;
  465 + }*/
  466 +
  467 +
  468 +//window onload 后重新refresh iscroll
  469 +$(window).load(function () {
380 myScroll && myScroll.refresh(); 470 myScroll && myScroll.refresh();
381 imgH = $('#nav-top').outerHeight(); 471 imgH = $('#nav-top').outerHeight();
382 nav1H = $('#nav').outerHeight(); 472 nav1H = $('#nav').outerHeight();
383 main1H = $('#nav-main').height(); 473 main1H = $('#nav-main').height();
384 main1oH = $('#nav-main').outerHeight(); 474 main1oH = $('#nav-main').outerHeight();
385 - setTimeout(function() { 475 + nav2H = $('#list-nav').outerHeight();
  476 + main2oH = $('#goods-container').outerHeight();
  477 + setTimeout(function () {
386 scH = $('#scroller').outerHeight(); 478 scH = $('#scroller').outerHeight();
387 }, 1000); 479 }, 1000);
388 }); 480 });
@@ -399,12 +491,16 @@ function search(opt) { @@ -399,12 +491,16 @@ function search(opt) {
399 page; 491 page;
400 492
401 if (searching) { 493 if (searching) {
402 - return false; 494 + return;
  495 + }
  496 +
  497 + if (!opt.url) {
  498 + opt.url = location.protocol + '//m.yohobuy.com/index/search/search';
403 } 499 }
404 500
405 if (!opt.nextPage) { 501 if (!opt.nextPage) {
406 502
407 - // 筛选项变更则重置reload为true 503 + //筛选项变更则重置reload为true
408 for (att in navInfo) { 504 for (att in navInfo) {
409 if (navInfo.hasOwnProperty(att)) { 505 if (navInfo.hasOwnProperty(att)) {
410 navInfo[att].reload = true; 506 navInfo[att].reload = true;
@@ -463,11 +559,11 @@ function search(opt) { @@ -463,11 +559,11 @@ function search(opt) {
463 default: 559 default:
464 break; 560 break;
465 } 561 }
466 - $.extend(defaultOpt, ext); // 扩展筛选项 562 + $.extend(defaultOpt, ext); //扩展筛选项
467 } 563 }
468 } 564 }
469 565
470 - // 导航类别 566 + //导航类别
471 if ($pre.hasClass('new')) { 567 if ($pre.hasClass('new')) {
472 navType = 'newest'; 568 navType = 'newest';
473 } else if ($pre.hasClass('price')) { 569 } else if ($pre.hasClass('price')) {
@@ -482,7 +578,7 @@ function search(opt) { @@ -482,7 +578,7 @@ function search(opt) {
482 page = 1; 578 page = 1;
483 } else if (nav.end) { 579 } else if (nav.end) {
484 580
485 - // 不需要重新加载并且数据请求结束 581 + //不需要重新加载并且数据请求结束
486 return; 582 return;
487 } 583 }
488 $.extend(setting, defaultOpt, { 584 $.extend(setting, defaultOpt, {
@@ -503,9 +599,9 @@ function search(opt) { @@ -503,9 +599,9 @@ function search(opt) {
503 599
504 $.ajax({ 600 $.ajax({
505 type: 'GET', 601 type: 'GET',
506 - url: subdomains + '/product/search/search', 602 + url: opt.url ? opt.url : '',
507 data: setting, 603 data: setting,
508 - success: function(data) { 604 + success: function (data) {
509 var $container, 605 var $container,
510 num; 606 num;
511 607
@@ -523,7 +619,7 @@ function search(opt) { @@ -523,7 +619,7 @@ function search(opt) {
523 break; 619 break;
524 } 620 }
525 621
526 - if (data === '') { 622 + if (data === ' ') {
527 nav.end = true; 623 nav.end = true;
528 624
529 if (nav.reload) { 625 if (nav.reload) {
@@ -540,6 +636,8 @@ function search(opt) { @@ -540,6 +636,8 @@ function search(opt) {
540 } 636 }
541 } 637 }
542 638
  639 + scH = $('#scroller').outerHeight();
  640 +
543 nav.reload = false; 641 nav.reload = false;
544 nav.page = page; 642 nav.page = page;
545 643
@@ -548,13 +646,12 @@ function search(opt) { @@ -548,13 +646,12 @@ function search(opt) {
548 646
549 window.rePosFooter(); 647 window.rePosFooter();
550 648
551 - setTimeout(function() {  
552 - myScroll.refresh();  
553 - scH = $('#scroller').outerHeight();  
554 - }, 1000); 649 + myScroll.refresh();
  650 + reNav1Pos();
  651 +
555 bindGoodThumbClick(); 652 bindGoodThumbClick();
556 }, 653 },
557 - error: function() { 654 + error: function () {
558 tip.show('网络断开连接了~'); 655 tip.show('网络断开连接了~');
559 searching = false; 656 searching = false;
560 loading.hideLoadingMask(); 657 loading.hideLoadingMask();
@@ -562,55 +659,12 @@ function search(opt) { @@ -562,55 +659,12 @@ function search(opt) {
562 }); 659 });
563 } 660 }
564 661
565 -/**  
566 - * 获取url参数  
567 - */  
568 -function getQueryString(name) {  
569 - var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');  
570 - var r = window.location.search.substr(1).match(reg);  
571 -  
572 - if (r !== null) {  
573 - return window.unescape(r[2]);  
574 - }  
575 - return null;  
576 -}  
577 -  
578 -$.ajax({  
579 - type: 'GET',  
580 - url: subdomains + '/product/search/filter',  
581 - data: {  
582 - shop_id: brand ? '' : shopId,  
583 - brand: brand,  
584 - gender: getQueryString('gender'),  
585 - channel: getQueryString('channel')  
586 - },  
587 - success: function(data) {  
588 - $goodsContainer.append(data);  
589 -  
590 - // 初始化filter&注册filter回调  
591 - filter.initFilter({  
592 - fCbFn: search,  
593 - hCbFn: function() {  
594 -  
595 - // 切换active状态到$pre上  
596 - $pre.addClass('active');  
597 - $pre.siblings('.filter').removeClass('active');  
598 - },  
599 - missStatus: true  
600 - });  
601 -  
602 - setTimeout(function() {  
603 - myScroll.refresh();  
604 - scH = $('#scroller').outerHeight();  
605 - }, 1000);  
606 - }  
607 -});  
608 662
609 -$listNav.bind('contextmenu', function() { 663 +$listNav.bind('contextmenu', function (e) {
610 return false; 664 return false;
611 }); 665 });
612 666
613 -$subNav.on('touchend touchcancel', function(e) { 667 +$subNav.on('touchend touchcancel', function (e) {
614 var $this = $(e.target).closest('li'), 668 var $this = $(e.target).closest('li'),
615 cname, 669 cname,
616 nav, 670 nav,
@@ -627,20 +681,36 @@ $subNav.on('touchend touchcancel', function(e) { @@ -627,20 +681,36 @@ $subNav.on('touchend touchcancel', function(e) {
627 681
628 if ($this.hasClass('filter')) { 682 if ($this.hasClass('filter')) {
629 683
630 - // 筛选面板切换状态 684 + //筛选面板切换状态
631 if ($this.hasClass('active')) { 685 if ($this.hasClass('active')) {
632 filter.hideFilter(); 686 filter.hideFilter();
633 687
634 - // 点击筛选钱的active项回复active 688 + //点击筛选钱的active项回复active
635 $pre.addClass('active'); 689 $pre.addClass('active');
636 $this.removeClass('active'); 690 $this.removeClass('active');
  691 +
  692 + myScroll.enable();
637 } else { 693 } else {
638 $pre = $this.siblings('.active'); 694 $pre = $this.siblings('.active');
639 695
640 $pre.removeClass('active'); 696 $pre.removeClass('active');
641 $this.addClass('active'); 697 $this.addClass('active');
642 698
  699 + myScroll.scrollTo(0, -(imgH + main1oH + nav1H));
  700 +
  701 + theY = imgH + main1oH + nav1H;
  702 +
  703 + reNav1Pos();
  704 +
643 filter.showFilter(); 705 filter.showFilter();
  706 +
  707 + if ($this.closest('.pos-list').length > 0) {
  708 + $('.filter-mask').addClass('call-by-fix').css('top', '');
  709 + } else {
  710 + $('.filter-mask').removeClass('call-by-fix').css('top', $this.offset().top + nav1H);
  711 + }
  712 +
  713 + myScroll.disable();
644 } 714 }
645 } else { 715 } else {
646 if ($this.hasClass('new')) { 716 if ($this.hasClass('new')) {
@@ -654,11 +724,13 @@ $subNav.on('touchend touchcancel', function(e) { @@ -654,11 +724,13 @@ $subNav.on('touchend touchcancel', function(e) {
654 navType = 'discount'; 724 navType = 'discount';
655 } 725 }
656 726
  727 + myScroll.enable();
  728 +
657 nav = navInfo[navType]; 729 nav = navInfo[navType];
658 730
659 if ($this.hasClass('active')) { 731 if ($this.hasClass('active')) {
660 732
661 - // 最新无排序切换 733 + //最新无排序切换
662 if ($this.hasClass('new')) { 734 if ($this.hasClass('new')) {
663 return; 735 return;
664 } 736 }
@@ -668,9 +740,9 @@ $subNav.on('touchend touchcancel', function(e) { @@ -668,9 +740,9 @@ $subNav.on('touchend touchcancel', function(e) {
668 740
669 // 价格/折扣切换排序状态 741 // 价格/折扣切换排序状态
670 $this.find('.icon > .iconfont').toggleClass('cur'); 742 $this.find('.icon > .iconfont').toggleClass('cur');
671 - $pre = $this; // 更新pre为当前项  
672 - nav.reload = true; // 重置reload,HTML会被替换为逆序的HTML  
673 - nav.order = nav.order === 0 ? 1 : 0; // 切换排序 743 + $pre = $this; //更新pre为当前项
  744 + nav.reload = true; //重置reload,HTML会被替换为逆序的HTML
  745 + nav.order = nav.order === 0 ? 1 : 0; //切换排序
674 746
675 $goodsContainer.children('.container:not(.hide)').addClass('hide'); 747 $goodsContainer.children('.container:not(.hide)').addClass('hide');
676 748
@@ -694,15 +766,15 @@ $subNav.on('touchend touchcancel', function(e) { @@ -694,15 +766,15 @@ $subNav.on('touchend touchcancel', function(e) {
694 } else { 766 } else {
695 $active = $subNav.find('.active'); 767 $active = $subNav.find('.active');
696 768
697 - $pre = $this; // $pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项 769 + $pre = $this; //$pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项
698 770
699 if ($active.hasClass('filter')) { 771 if ($active.hasClass('filter')) {
700 772
701 - // 若之前active项为筛选,则隐藏筛选面板 773 + //若之前active项为筛选,则隐藏筛选面板
702 filter.hideFilter(); 774 filter.hideFilter();
703 } else { 775 } else {
704 776
705 - // 切换container显示 777 + //切换container显示
706 $goodsContainer.children('.container:not(.hide)').addClass('hide'); 778 $goodsContainer.children('.container:not(.hide)').addClass('hide');
707 779
708 switch (navType) { 780 switch (navType) {
@@ -731,6 +803,7 @@ $subNav.on('touchend touchcancel', function(e) { @@ -731,6 +803,7 @@ $subNav.on('touchend touchcancel', function(e) {
731 type: 'shop_id', 803 type: 'shop_id',
732 id: shopId, 804 id: shopId,
733 brand: brand, 805 brand: brand,
  806 + url: location.protocol + '//m.yohobuy.com/index/search/search',
734 nextPage: false 807 nextPage: false
735 }); 808 });
736 } 809 }
@@ -738,80 +811,68 @@ $subNav.on('touchend touchcancel', function(e) { @@ -738,80 +811,68 @@ $subNav.on('touchend touchcancel', function(e) {
738 e.stopPropagation(); 811 e.stopPropagation();
739 }); 812 });
740 813
  814 +filter.initFilter({
  815 + fCbFn: function (option) {
  816 + search(option);
  817 + myScroll.enable();
  818 + },
  819 + hCbFn: function () {
741 820
742 -function scrollHandler() {  
743 -  
744 - sTop = -myScroll.y;  
745 -  
746 - // 当scroll到1/4$goodsContainer高度后继续请求下一页数据  
747 - myScroll && myScroll.refresh();  
748 - if (sTop + winH > $('#scroller').height() - 0.25 * $goodsContainer.height() - 50) {  
749 - if ($pre !== undefined) {  
750 - search({  
751 - type: 'shop_id',  
752 - id: shopId,  
753 - brand: brand,  
754 - nextPage: true  
755 - });  
756 - }  
757 - }  
758 -}  
759 -  
760 -// srcoll to load more  
761 -$(window).scroll(function() {  
762 - window.requestAnimationFrame(scrollHandler);  
763 -});  
764 - 821 + //切换active状态到$pre上
  822 + $pre.addClass('active');
  823 + $pre.siblings('.filter').removeClass('active');
765 824
766 -// 初始请求最新第一页数据  
767 -search({  
768 - type: 'shop_id',  
769 - id: shopId,  
770 - brand: brand,  
771 - nextPage: false 825 + myScroll.enable();
  826 + },
  827 + missStatus: true
772 }); 828 });
773 829
774 -$listNav.on('touchstart', 'li', function() { 830 +$listNav.on('touchstart', 'li', function (e) {
775 $(this).addClass('bytouch'); 831 $(this).addClass('bytouch');
776 -}).on('touchend touchcancel', function() { 832 +}).on('touchend touchcancel', function () {
777 $listNav.find('li').removeClass('bytouch'); 833 $listNav.find('li').removeClass('bytouch');
778 myScroll.refresh(); 834 myScroll.refresh();
779 }); 835 });
780 836
781 -$nav2.on('touchstart', 'li', function() { 837 +$nav2.on('touchstart', 'li', function (e) {
782 $(this).addClass('bytouch'); 838 $(this).addClass('bytouch');
783 -}).on('touchend touchcancel', function() { 839 +}).on('touchend touchcancel', function () {
784 $nav2.find('li').removeClass('bytouch'); 840 $nav2.find('li').removeClass('bytouch');
785 myScroll.refresh(); 841 myScroll.refresh();
786 }); 842 });
787 843
788 -// 底部导航点击 844 +//底部导航点击
789 function fotterClick(group) { 845 function fotterClick(group) {
790 - $(group + ' li').on('touchstart', function() {  
791 - $subGroup.addClass('hide');  
792 - if ($(this).find('.sub-group').length > 0) {  
793 - $(this).find('.sub-group').removeClass('hide');  
794 - } 846 + $(group + ' li').on('touchstart', function () {
  847 + $('.sub-group').addClass('hide');
  848 + $(this).find('.sub-group').removeClass('hide');
795 }); 849 });
796 } 850 }
797 851
798 fotterClick('.shop-foot-wrapper'); 852 fotterClick('.shop-foot-wrapper');
799 853
800 -$(document).bind('touchstart', function(e) {  
801 - if ($(e.target).hasClass('good-category') || $(e.target).hasClass('sub-group')) {  
802 - return false; 854 +function stopPropagation(e) {
  855 + if (e.stopPropagation) {
  856 + e.stopPropagation();
  857 + } else {
  858 + e.cancelBubble = true;
803 } 859 }
804 - $subGroup.addClass('hide'); 860 +}
  861 +
  862 +$(document).bind('touchstart', function (e) {
  863 + $('.sub-group').addClass('hide');
805 }); 864 });
806 865
  866 +$('.shop-foot-wrapper').bind('touchstart', function (e) {
  867 + stopPropagation(e);
  868 +});
807 // 店铺收藏 || 取消收藏 869 // 店铺收藏 || 取消收藏
808 -$collect.on('touchstart', function() { 870 +$collect.on('touchstart', function () {
809 var opt; 871 var opt;
810 872
811 if (searching) { 873 if (searching) {
812 return; 874 return;
813 } 875 }
814 -  
815 searching = true; 876 searching = true;
816 877
817 if ($collect.hasClass('already-collect')) { 878 if ($collect.hasClass('already-collect')) {
@@ -821,15 +882,15 @@ $collect.on('touchstart', function() { @@ -821,15 +882,15 @@ $collect.on('touchstart', function() {
821 } 882 }
822 883
823 $.ajax({ 884 $.ajax({
824 - type: 'POST',  
825 - url: subdomains + '/product/opt/favoriteBrand', 885 + method: 'get',
  886 + url: location.protocol + '//m.yohobuy.com' + '/product/opt/favoriteBrand',
826 data: { 887 data: {
827 id: favId ? favId : shopId, 888 id: favId ? favId : shopId,
828 appVersion: appVersion, 889 appVersion: appVersion,
829 opt: opt, 890 opt: opt,
830 type: 'shop' 891 type: 'shop'
831 }, 892 },
832 - success: function(data) { 893 + success: function (data) {
833 var url = ''; 894 var url = '';
834 895
835 if (data.code === 200) { 896 if (data.code === 200) {
@@ -840,20 +901,28 @@ $collect.on('touchstart', function() { @@ -840,20 +901,28 @@ $collect.on('touchstart', function() {
840 } 901 }
841 } 902 }
842 903
843 - if (data.code === 400) {  
844 - url = data.url; 904 + if (data.code === 401) {
  905 + url = 'http://m.yohobuy.com/signin.html?refer=' + encodeURIComponent(location.href) + '&openby:yohobuy=';
  906 + url += JSON.stringify({"action": "go.weblogin",
  907 + "params": {
  908 + "jumpurl": {"url": 'http://m.yohobuy.com' + location.pathname, "param": info.data},
  909 + "requesturl": {"param": {}, "url": ""},
  910 + "priority": "N"
  911 + }
  912 + });
  913 +
845 $('body').append('<a href=\'' + url + '\'><span class="jump-login"><span></a>'); 914 $('body').append('<a href=\'' + url + '\'><span class="jump-login"><span></a>');
846 915
847 $('.jump-login').click(); 916 $('.jump-login').click();
848 } 917 }
849 918
850 - setTimeout(function() { 919 + setTimeout(function () {
851 myScroll.refresh(); 920 myScroll.refresh();
852 scH = $('#scroller').outerHeight(); 921 scH = $('#scroller').outerHeight();
853 }, 1000); 922 }, 1000);
854 searching = false; 923 searching = false;
855 }, 924 },
856 - error: function() { 925 + error: function () {
857 tip.show('网络断开连接了~'); 926 tip.show('网络断开连接了~');
858 searching = false; 927 searching = false;
859 } 928 }