Authored by 郭成尧

'shop-js'

@@ -43,7 +43,7 @@ var defaultOpt = require('../../common/query-param'); @@ -43,7 +43,7 @@ var defaultOpt = require('../../common/query-param');
43 43
44 var $listNav = $('#list-nav'), 44 var $listNav = $('#list-nav'),
45 45
46 - //导航数据信息 46 + // 导航数据信息
47 navInfo = { 47 navInfo = {
48 new: { 48 new: {
49 order: 1, 49 order: 1,
@@ -76,7 +76,7 @@ var $listNav = $('#list-nav'), @@ -76,7 +76,7 @@ var $listNav = $('#list-nav'),
76 end: false 76 end: false
77 } 77 }
78 }, 78 },
79 - $pre = $listNav.find('.active'), //纪录进入筛选前的active项,初始为选中项 79 + $pre = $listNav.find('.active'), // 纪录进入筛选前的active项,初始为选中项
80 searching; 80 searching;
81 81
82 var viewType = 1, // 1-首页,2-上新,3-人气 82 var viewType = 1, // 1-首页,2-上新,3-人气
@@ -90,7 +90,7 @@ $('.main-wrap').css({ @@ -90,7 +90,7 @@ $('.main-wrap').css({
90 position: 'static' 90 position: 'static'
91 }); 91 });
92 92
93 -//焦点效果 93 +// 焦点效果
94 if ($('.banner-swiper').find('li').size() > 1) { 94 if ($('.banner-swiper').find('li').size() > 1) {
95 bannerSwiper = new Swiper('.banner-swiper', { 95 bannerSwiper = new Swiper('.banner-swiper', {
96 lazyLoading: true, 96 lazyLoading: true,
@@ -116,7 +116,7 @@ if ($('.multi-browse').find('li').size() > 1) { @@ -116,7 +116,7 @@ if ($('.multi-browse').find('li').size() > 1) {
116 }); 116 });
117 } 117 }
118 118
119 -//根据热门品类的个数来改变样式展示 119 +// 根据热门品类的个数来改变样式展示
120 // 120 //
121 if ($('.category-list li').length % 4 !== 0) { 121 if ($('.category-list li').length % 4 !== 0) {
122 $('.category-list li:last-child').addClass('category-list-last-li'); 122 $('.category-list li:last-child').addClass('category-list-last-li');
@@ -143,7 +143,7 @@ function getPageGoods(info) { @@ -143,7 +143,7 @@ function getPageGoods(info) {
143 navType = info.data.type; 143 navType = info.data.type;
144 nav = navInfo[navType]; 144 nav = navInfo[navType];
145 145
146 - //不需要重新加载并且数据请求结束 146 + // 不需要重新加载并且数据请求结束
147 if (nav.end) { 147 if (nav.end) {
148 148
149 return; 149 return;
@@ -154,14 +154,14 @@ function getPageGoods(info) { @@ -154,14 +154,14 @@ function getPageGoods(info) {
154 type: 'GET', 154 type: 'GET',
155 url: info.url, 155 url: info.url,
156 data: info.data, 156 data: info.data,
157 - success: function (data) { 157 + success: function(data) {
158 if (data === ' ') { 158 if (data === ' ') {
159 nav.end = true; 159 nav.end = true;
160 } 160 }
161 161
162 info.callBack(data); 162 info.callBack(data);
163 }, 163 },
164 - error: function () { 164 + error: function() {
165 alert('网络断开连接了~'); 165 alert('网络断开连接了~');
166 searching = false; 166 searching = false;
167 } 167 }
@@ -191,7 +191,7 @@ function newData(callback) { @@ -191,7 +191,7 @@ function newData(callback) {
191 191
192 getParam(req); 192 getParam(req);
193 193
194 - req.callBack = function (data) { 194 + req.callBack = function(data) {
195 $('#new-arrival').append(data); 195 $('#new-arrival').append(data);
196 navInfo.new.page++; 196 navInfo.new.page++;
197 myScroll.refresh(); 197 myScroll.refresh();
@@ -216,7 +216,7 @@ function hotData(callback) { @@ -216,7 +216,7 @@ function hotData(callback) {
216 216
217 getParam(req); 217 getParam(req);
218 218
219 - req.callBack = function (data) { 219 + req.callBack = function(data) {
220 $('#popularity').append(data); 220 $('#popularity').append(data);
221 navInfo.hot.page++; 221 navInfo.hot.page++;
222 myScroll.refresh(); 222 myScroll.refresh();
@@ -242,10 +242,10 @@ myScroll = new IScroll('#wrapper', { @@ -242,10 +242,10 @@ myScroll = new IScroll('#wrapper', {
242 click: true 242 click: true
243 }); 243 });
244 244
245 -//首页导航  
246 -(function (nav, posNav, main) { 245 +// 首页导航
  246 +(function(nav, posNav, main) {
247 247
248 - $(nav + ' li, ' + posNav + ' li').not('li.all-goods').on('touchstart', function () { 248 + $(nav + ' li, ' + posNav + ' li').not('li.all-goods').on('touchstart', function() {
249 249
250 var index = $(this).index(), 250 var index = $(this).index(),
251 activeTab = $(this).attr('tab'); 251 activeTab = $(this).attr('tab');
@@ -323,7 +323,7 @@ function reNav1Pos() { @@ -323,7 +323,7 @@ function reNav1Pos() {
323 } 323 }
324 } 324 }
325 325
326 -myScroll.on('scroll', function () { 326 +myScroll.on('scroll', function() {
327 var scrollCall, 327 var scrollCall,
328 sTop = -this.y; 328 sTop = -this.y;
329 329
@@ -344,7 +344,7 @@ myScroll.on('scroll', function () { @@ -344,7 +344,7 @@ myScroll.on('scroll', function () {
344 } 344 }
345 345
346 if (sTop + winH * 2 > scH) { 346 if (sTop + winH * 2 > scH) {
347 - scrollCall = function () { 347 + scrollCall = function() {
348 var translate = 'translate3d(0, ' + (-scH) + 'px, 0)'; 348 var translate = 'translate3d(0, ' + (-scH) + 'px, 0)';
349 $nav1.css({ 349 $nav1.css({
350 transform: translate, 350 transform: translate,
@@ -369,14 +369,14 @@ myScroll.on('scroll', function () { @@ -369,14 +369,14 @@ myScroll.on('scroll', function () {
369 } 369 }
370 if (!$nav2.hasClass('hide')) { 370 if (!$nav2.hasClass('hide')) {
371 $nav2.addClass('hide'); 371 $nav2.addClass('hide');
372 - } //滑动距离不到导航1 372 + } // 滑动距离不到导航1
373 } else if (sTop < imgH + main1oH + nav1H) { 373 } else if (sTop < imgH + main1oH + nav1H) {
374 if ($nav1.hasClass('hide')) { 374 if ($nav1.hasClass('hide')) {
375 $nav1.removeClass('hide'); 375 $nav1.removeClass('hide');
376 } 376 }
377 if (!$nav2.hasClass('hide')) { 377 if (!$nav2.hasClass('hide')) {
378 $nav2.addClass('hide'); 378 $nav2.addClass('hide');
379 - } //滑动距离不到导航2 379 + } // 滑动距离不到导航2
380 380
381 if (sTop < imgH + main1H) { 381 if (sTop < imgH + main1H) {
382 if (!$nav1.hasClass('fixed-top')) { 382 if (!$nav1.hasClass('fixed-top')) {
@@ -434,7 +434,7 @@ myScroll.on('scroll', function () { @@ -434,7 +434,7 @@ myScroll.on('scroll', function () {
434 } 434 }
435 }); 435 });
436 436
437 -myScroll.on('scrollStart', function () { 437 +myScroll.on('scrollStart', function() {
438 438
439 // stop auto play when scroll 439 // stop auto play when scroll
440 bannerSwiper && bannerSwiper.stopAutoplay(); 440 bannerSwiper && bannerSwiper.stopAutoplay();
@@ -442,7 +442,7 @@ myScroll.on('scrollStart', function () { @@ -442,7 +442,7 @@ myScroll.on('scrollStart', function () {
442 multiSwiper && multiSwiper.stopAutoplay(); 442 multiSwiper && multiSwiper.stopAutoplay();
443 }); 443 });
444 444
445 -myScroll.on('scrollEnd', function () { 445 +myScroll.on('scrollEnd', function() {
446 446
447 // start auto play when scroll end 447 // start auto play when scroll end
448 bannerSwiper && bannerSwiper.startAutoplay(); 448 bannerSwiper && bannerSwiper.startAutoplay();
@@ -453,20 +453,20 @@ myScroll.on('scrollEnd', function () { @@ -453,20 +453,20 @@ myScroll.on('scrollEnd', function () {
453 }); 453 });
454 454
455 455
456 -document.addEventListener('touchmove', function (e) { 456 +document.addEventListener('touchmove', function(e) {
457 // sub classify不阻止默认事件 457 // sub classify不阻止默认事件
458 if ($(e.target).closest('.sub-classify').length === 0) { 458 if ($(e.target).closest('.sub-classify').length === 0) {
459 e.preventDefault(); 459 e.preventDefault();
460 } 460 }
461 }, false); 461 }, false);
462 462
463 -/*if (!isIphone) { 463 +/* if (!isIphone) {
464 return; 464 return;
465 }*/ 465 }*/
466 466
467 467
468 -//window onload 后重新refresh iscroll  
469 -$(window).load(function () { 468 +// window onload 后重新refresh iscroll
  469 +$(window).load(function() {
470 myScroll && myScroll.refresh(); 470 myScroll && myScroll.refresh();
471 imgH = $('#nav-top').outerHeight(); 471 imgH = $('#nav-top').outerHeight();
472 nav1H = $('#nav').outerHeight(); 472 nav1H = $('#nav').outerHeight();
@@ -474,7 +474,7 @@ $(window).load(function () { @@ -474,7 +474,7 @@ $(window).load(function () {
474 main1oH = $('#nav-main').outerHeight(); 474 main1oH = $('#nav-main').outerHeight();
475 nav2H = $('#list-nav').outerHeight(); 475 nav2H = $('#list-nav').outerHeight();
476 main2oH = $('#goods-container').outerHeight(); 476 main2oH = $('#goods-container').outerHeight();
477 - setTimeout(function () { 477 + setTimeout(function() {
478 scH = $('#scroller').outerHeight(); 478 scH = $('#scroller').outerHeight();
479 }, 1000); 479 }, 1000);
480 }); 480 });
@@ -500,7 +500,7 @@ function search(opt) { @@ -500,7 +500,7 @@ function search(opt) {
500 500
501 if (!opt.nextPage) { 501 if (!opt.nextPage) {
502 502
503 - //筛选项变更则重置reload为true 503 + // 筛选项变更则重置reload为true
504 for (att in navInfo) { 504 for (att in navInfo) {
505 if (navInfo.hasOwnProperty(att)) { 505 if (navInfo.hasOwnProperty(att)) {
506 navInfo[att].reload = true; 506 navInfo[att].reload = true;
@@ -559,11 +559,11 @@ function search(opt) { @@ -559,11 +559,11 @@ function search(opt) {
559 default: 559 default:
560 break; 560 break;
561 } 561 }
562 - $.extend(defaultOpt, ext); //扩展筛选项 562 + $.extend(defaultOpt, ext); // 扩展筛选项
563 } 563 }
564 } 564 }
565 565
566 - //导航类别 566 + // 导航类别
567 if ($pre.hasClass('new')) { 567 if ($pre.hasClass('new')) {
568 navType = 'newest'; 568 navType = 'newest';
569 } else if ($pre.hasClass('price')) { 569 } else if ($pre.hasClass('price')) {
@@ -578,7 +578,7 @@ function search(opt) { @@ -578,7 +578,7 @@ function search(opt) {
578 page = 1; 578 page = 1;
579 } else if (nav.end) { 579 } else if (nav.end) {
580 580
581 - //不需要重新加载并且数据请求结束 581 + // 不需要重新加载并且数据请求结束
582 return; 582 return;
583 } 583 }
584 $.extend(setting, defaultOpt, { 584 $.extend(setting, defaultOpt, {
@@ -601,7 +601,7 @@ function search(opt) { @@ -601,7 +601,7 @@ function search(opt) {
601 type: 'GET', 601 type: 'GET',
602 url: opt.url ? opt.url : '', 602 url: opt.url ? opt.url : '',
603 data: setting, 603 data: setting,
604 - success: function (data) { 604 + success: function(data) {
605 var $container, 605 var $container,
606 num; 606 num;
607 607
@@ -651,7 +651,7 @@ function search(opt) { @@ -651,7 +651,7 @@ function search(opt) {
651 651
652 bindGoodThumbClick(); 652 bindGoodThumbClick();
653 }, 653 },
654 - error: function () { 654 + error: function() {
655 tip.show('网络断开连接了~'); 655 tip.show('网络断开连接了~');
656 searching = false; 656 searching = false;
657 loading.hideLoadingMask(); 657 loading.hideLoadingMask();
@@ -660,11 +660,11 @@ function search(opt) { @@ -660,11 +660,11 @@ function search(opt) {
660 } 660 }
661 661
662 662
663 -$listNav.bind('contextmenu', function (e) { 663 +$listNav.bind('contextmenu', function(e) {
664 return false; 664 return false;
665 }); 665 });
666 666
667 -$subNav.on('touchend touchcancel', function (e) { 667 +$subNav.on('touchend touchcancel', function(e) {
668 var $this = $(e.target).closest('li'), 668 var $this = $(e.target).closest('li'),
669 cname, 669 cname,
670 nav, 670 nav,
@@ -681,11 +681,11 @@ $subNav.on('touchend touchcancel', function (e) { @@ -681,11 +681,11 @@ $subNav.on('touchend touchcancel', function (e) {
681 681
682 if ($this.hasClass('filter')) { 682 if ($this.hasClass('filter')) {
683 683
684 - //筛选面板切换状态 684 + // 筛选面板切换状态
685 if ($this.hasClass('active')) { 685 if ($this.hasClass('active')) {
686 filter.hideFilter(); 686 filter.hideFilter();
687 687
688 - //点击筛选钱的active项回复active 688 + // 点击筛选钱的active项回复active
689 $pre.addClass('active'); 689 $pre.addClass('active');
690 $this.removeClass('active'); 690 $this.removeClass('active');
691 691
@@ -730,7 +730,7 @@ $subNav.on('touchend touchcancel', function (e) { @@ -730,7 +730,7 @@ $subNav.on('touchend touchcancel', function (e) {
730 730
731 if ($this.hasClass('active')) { 731 if ($this.hasClass('active')) {
732 732
733 - //最新无排序切换 733 + // 最新无排序切换
734 if ($this.hasClass('new')) { 734 if ($this.hasClass('new')) {
735 return; 735 return;
736 } 736 }
@@ -740,9 +740,9 @@ $subNav.on('touchend touchcancel', function (e) { @@ -740,9 +740,9 @@ $subNav.on('touchend touchcancel', function (e) {
740 740
741 // 价格/折扣切换排序状态 741 // 价格/折扣切换排序状态
742 $this.find('.icon > .iconfont').toggleClass('cur'); 742 $this.find('.icon > .iconfont').toggleClass('cur');
743 - $pre = $this; //更新pre为当前项  
744 - nav.reload = true; //重置reload,HTML会被替换为逆序的HTML  
745 - 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; // 切换排序
746 746
747 $goodsContainer.children('.container:not(.hide)').addClass('hide'); 747 $goodsContainer.children('.container:not(.hide)').addClass('hide');
748 748
@@ -766,15 +766,15 @@ $subNav.on('touchend touchcancel', function (e) { @@ -766,15 +766,15 @@ $subNav.on('touchend touchcancel', function (e) {
766 } else { 766 } else {
767 $active = $subNav.find('.active'); 767 $active = $subNav.find('.active');
768 768
769 - $pre = $this; //$pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项 769 + $pre = $this; // $pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项
770 770
771 if ($active.hasClass('filter')) { 771 if ($active.hasClass('filter')) {
772 772
773 - //若之前active项为筛选,则隐藏筛选面板 773 + // 若之前active项为筛选,则隐藏筛选面板
774 filter.hideFilter(); 774 filter.hideFilter();
775 } else { 775 } else {
776 776
777 - //切换container显示 777 + // 切换container显示
778 $goodsContainer.children('.container:not(.hide)').addClass('hide'); 778 $goodsContainer.children('.container:not(.hide)').addClass('hide');
779 779
780 switch (navType) { 780 switch (navType) {
@@ -812,13 +812,13 @@ $subNav.on('touchend touchcancel', function (e) { @@ -812,13 +812,13 @@ $subNav.on('touchend touchcancel', function (e) {
812 }); 812 });
813 813
814 filter.initFilter({ 814 filter.initFilter({
815 - fCbFn: function (option) { 815 + fCbFn: function(option) {
816 search(option); 816 search(option);
817 myScroll.enable(); 817 myScroll.enable();
818 }, 818 },
819 - hCbFn: function () { 819 + hCbFn: function() {
820 820
821 - //切换active状态到$pre上 821 + // 切换active状态到$pre上
822 $pre.addClass('active'); 822 $pre.addClass('active');
823 $pre.siblings('.filter').removeClass('active'); 823 $pre.siblings('.filter').removeClass('active');
824 824
@@ -827,23 +827,23 @@ filter.initFilter({ @@ -827,23 +827,23 @@ filter.initFilter({
827 missStatus: true 827 missStatus: true
828 }); 828 });
829 829
830 -$listNav.on('touchstart', 'li', function (e) { 830 +$listNav.on('touchstart', 'li', function(e) {
831 $(this).addClass('bytouch'); 831 $(this).addClass('bytouch');
832 -}).on('touchend touchcancel', function () { 832 +}).on('touchend touchcancel', function() {
833 $listNav.find('li').removeClass('bytouch'); 833 $listNav.find('li').removeClass('bytouch');
834 myScroll.refresh(); 834 myScroll.refresh();
835 }); 835 });
836 836
837 -$nav2.on('touchstart', 'li', function (e) { 837 +$nav2.on('touchstart', 'li', function(e) {
838 $(this).addClass('bytouch'); 838 $(this).addClass('bytouch');
839 -}).on('touchend touchcancel', function () { 839 +}).on('touchend touchcancel', function() {
840 $nav2.find('li').removeClass('bytouch'); 840 $nav2.find('li').removeClass('bytouch');
841 myScroll.refresh(); 841 myScroll.refresh();
842 }); 842 });
843 843
844 -//底部导航点击 844 +// 底部导航点击
845 function fotterClick(group) { 845 function fotterClick(group) {
846 - $(group + ' li').on('touchstart', function () { 846 + $(group + ' li').on('touchstart', function() {
847 $('.sub-group').addClass('hide'); 847 $('.sub-group').addClass('hide');
848 $(this).find('.sub-group').removeClass('hide'); 848 $(this).find('.sub-group').removeClass('hide');
849 }); 849 });
@@ -859,15 +859,16 @@ function stopPropagation(e) { @@ -859,15 +859,16 @@ function stopPropagation(e) {
859 } 859 }
860 } 860 }
861 861
862 -$(document).bind('touchstart', function (e) { 862 +$(document).bind('touchstart', function(e) {
863 $('.sub-group').addClass('hide'); 863 $('.sub-group').addClass('hide');
864 }); 864 });
865 865
866 -$('.shop-foot-wrapper').bind('touchstart', function (e) { 866 +$('.shop-foot-wrapper').bind('touchstart', function(e) {
867 stopPropagation(e); 867 stopPropagation(e);
868 }); 868 });
  869 +
869 // 店铺收藏 || 取消收藏 870 // 店铺收藏 || 取消收藏
870 -$collect.on('touchstart', function () { 871 +$collect.on('touchstart', function() {
871 var opt; 872 var opt;
872 873
873 if (searching) { 874 if (searching) {
@@ -890,7 +891,7 @@ $collect.on('touchstart', function () { @@ -890,7 +891,7 @@ $collect.on('touchstart', function () {
890 opt: opt, 891 opt: opt,
891 type: 'shop' 892 type: 'shop'
892 }, 893 },
893 - success: function (data) { 894 + success: function(data) {
894 var url = ''; 895 var url = '';
895 896
896 if (data.code === 200) { 897 if (data.code === 200) {
@@ -903,11 +904,11 @@ $collect.on('touchstart', function () { @@ -903,11 +904,11 @@ $collect.on('touchstart', function () {
903 904
904 if (data.code === 401) { 905 if (data.code === 401) {
905 url = 'http://m.yohobuy.com/signin.html?refer=' + encodeURIComponent(location.href) + '&openby:yohobuy='; 906 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" 907 + url += JSON.stringify({'action': 'go.weblogin',
  908 + 'params': {
  909 + 'jumpurl': {'url': 'http://m.yohobuy.com' + location.pathname, 'param': info.data},
  910 + 'requesturl': {'param': {}, 'url': ''},
  911 + 'priority': 'N'
911 } 912 }
912 }); 913 });
913 914
@@ -916,13 +917,13 @@ $collect.on('touchstart', function () { @@ -916,13 +917,13 @@ $collect.on('touchstart', function () {
916 $('.jump-login').click(); 917 $('.jump-login').click();
917 } 918 }
918 919
919 - setTimeout(function () { 920 + setTimeout(function() {
920 myScroll.refresh(); 921 myScroll.refresh();
921 scH = $('#scroller').outerHeight(); 922 scH = $('#scroller').outerHeight();
922 }, 1000); 923 }, 1000);
923 searching = false; 924 searching = false;
924 }, 925 },
925 - error: function () { 926 + error: function() {
926 tip.show('网络断开连接了~'); 927 tip.show('网络断开连接了~');
927 searching = false; 928 searching = false;
928 } 929 }