From b199c9e9e64bf7013dbb325fbf99f40dc69e3648 Mon Sep 17 00:00:00 2001 From: zhangxiaoru <1282857928@qq.com> Date: Wed, 14 Sep 2016 13:15:26 +0800 Subject: [PATCH] gulp ge --- static/dist/myohobuy/4.9.20/index-debug.js | 18300 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ static/dist/myohobuy/assets/img/sprite.me.png | Bin 25292 -> 0 bytes 2 files changed, 9150 insertions(+), 9150 deletions(-) diff --git a/static/dist/myohobuy/4.9.20/index-debug.js b/static/dist/myohobuy/4.9.20/index-debug.js index 2970a5f..5a3715d 100644 --- a/static/dist/myohobuy/4.9.20/index-debug.js +++ b/static/dist/myohobuy/4.9.20/index-debug.js @@ -563,6786 +563,5634 @@ $nav.on('touchstart', 'li', function() { }); define("js/category/brand", ["jquery","hammer","swiper","lazyload","index"], function(require, exports, module){ -/** - * 品牌一览 - * @author: liangzhifeng<zhifeng.liang@yoho.cn> - * @date: 2015/10/23 - */ - -var $ = require("jquery"), - Hammer = require("hammer"), - Swiper = require("swiper"), - loading = require("js/plugin/loading"), - lazyLoad = require("lazyload"); - -var ranToken = ' ??++ '; -var ranToken2 = ' ???--- '; - -var swiper, - $fixTitleBar, - $brandList = $('.brand-list'), - $icon = $('.search-icon'), - $genderItem = $('.genderNav li'), - $brandItem = $('.brandNav li'), - $newBrandWall = $('.new-brand-wall'), - $recommandBrandWall = $('.recommand-brand-wall'), - $searchAction = $('.search-action'), - $homebuttom = $('.homebuttom'), - $genderNav = $('.genderNav'), - $newSearch = $('.newbrand-search'), - $netHistory = $('.net-history'), - $navBtn = $('.nav-home'), - hotBrandsSwiper; - -var searchH = $('.newbrand-search').outerHeight(), - headerH = $('.yoho-header').outerHeight(), - brandSwipe = parseInt(searchH) + parseInt(headerH) - 1, - minBrandListTop; - -var brandsData, - $keyword = $('#keyword'), - clearTextHammer; - -var $history = $('.local-history'); -var $searchPage = $('.search-brand-page'); -var $historySearch = $('.history-search'); -var $hotSearch = $('.hot-search'); - -var $clearHistory = $('#clear-history'); - -var chHammer; - - -function changeBackground() { - var $brandList = $('.brand-list').find('p'); - - $brandList.on('touchstart', function() { - $brandList.css('background', '#fff'); - $(this).css('background', '#eee'); - }).on('touchend touchcancel', function() { - $(this).css('background', '#fff'); - }); -} -changeBackground(); - -/** - * 增加单条记录 - */ -function addHistory(brandName) { - $.ajax({ - type: 'POST', - url: '/brands/addBrandSearch', - data: 'brandName=' + encodeURIComponent(brandName), - success: function(data) { - }, - error: function() { - } - }); -} - -//比较大小 -function sequence(a, b) { - if (a.time > b.time) { - return 1; - } else if (a.time < b.time) { - return -1; - } else { - return 0; - } -} - -function searchInput() { - if ($keyword.val().length) { - $icon.css('color', '#444'); - - // $(this).closest('.search-box').css('width', '11.25rem'); - $searchAction.show().find('.clear-text').show(); - } else { - $icon.css('color', '#b2b2b2'); - - // $(this).closest('.search-box').css('width', '12.5rem'); - $searchAction.find('.clear-text').hide(); - - } - searchResult(); -} - -function isLocalStorageSupported() { - var testKey = 'test', - storage = Window.prototype.localStorage; - - try { - storage.setItem(testKey, 'testValue'); - storage.removeItem(testKey); - return true; - } catch (error) { - return false; - } -} - -//绑定提交前的存local操作 -function bindWriteLocal($brandList, list) { - $brandList.on('click', 'p , li', function(e) { - var brandName, brandId, brandDomain, url; - var a = $(this).find('a'); - var myDate = new Date(); - var query = a.attr('brandName') + ranToken2 + myDate.getTime(), - historys; - - brandName = a.attr('brandName'); - - brandId = a.attr('brandId'); - - brandDomain = a.attr('brandDomain'); - - url = a.attr('href'); - - e.preventDefault(); - - if ($netHistory.length > 0) { - addHistory(brandName); - - if (list) { - location.href = url; - return; - } - - $keyword.val(brandName); - searchInput(); - return; - } - - if (localStorage) { - if (isLocalStorageSupported()) { - historys = localStorage.getItem('historys-brand'); - } - - historys = historys ? historys : ''; - - if (historys.indexOf(ranToken + query + ranToken) > -1) { - - - $keyword.val(brandName); - searchInput(); - return; - } - - if (historys === '') { - query = ranToken + query; - } - - historys += query + ranToken; - - if (isLocalStorageSupported()) { - localStorage.setItem('historys-brand', historys); - } - } - - if (list) { - location.href = url; - return; - } - - $keyword.val(brandName); - searchInput(); - }); -} - -function searchResult() { - var keyword = ($keyword.val() + '').toLowerCase(); - var result = {}, - i = 0, - html = ''; - - if (keyword !== '') { - - // 遍历首字母搜索 - $.each(brandsData, function(k, v) { - if ($.isArray(v)) { - - // 遍历品牌,进行匹配 - $.each(v, function(i, brand) { - if (brand.searchName.toLowerCase().indexOf(keyword) > -1) { - result[k] = result[k] || []; - result[k].push(brand); - } - }); - } - }); - - // 根据搜索结果生成 HTML - $.each(result, function(k, v) { - var brandHtml = ['<div class="brand-list bar-', i, '">']; - - i++; - brandHtml.push('<div class="title-bar"><h2>'); - brandHtml.push(k); - brandHtml.push('</h2></div>'); - $.each(v, function(i, brand) { - - brandHtml.push('<p><a href="' + brand.url + '" brandName = "' + brand.name + - '" brandId = "' + brand.brandId + '" brandDomain = "' + brand.brandDomain + '">' + brand.name); - if (brand.isNew) { - brandHtml.push('<i class="icon-new">NEW</i>'); - } - if (brand.isHot) { - brandHtml.push('<i class="icon-hot">HOT</i>'); - } - brandHtml.push('</a></p>'); - }); - brandHtml.push('</div>'); - html += brandHtml.join(''); - - }); - } - - //没填入关键词时显示最热搜索 - if (keyword.length > 0) { - $('.search-brand-page').addClass('hide'); - } else { - $('.search-brand-page').removeClass('hide'); - } - - // 插入 dom,绑定事件 - $('.search-result').html(html); - changeBackground(); - bindWriteLocal($('.brand-list'), true); -} - -loading.showLoadingMask(); - -lazyLoad($('img.lazy')); -$('.yoho-header').css({ - 'z-index': 2, - position: 'fixed', - top: 0 -}); - -$homebuttom.css('top', '47px'); -$homebuttom.css('position', 'fixed'); - -$navBtn.on('touchstart', function() { - if ($homebuttom.hasClass('hide')) { - $genderNav.css('top', '47px'); - $newSearch.css('margin-top', '0px'); - $searchPage.css('margin-top', '0px'); - $('.banner-top').css('margin-top', '0px'); - } else { - $genderNav.css('top', '97px'); - $newSearch.css('margin-top', '47px'); - $searchPage.css('margin-top', '47px'); - $('.banner-top').css('margin-top', '47px'); - } -}); - -(function() { - if ($('.banner-top').length > 0) { - $('.hot-brands').css('padding-top', '0'); - } - - $('.hide-when-loading').show(); - loading.hideLoadingMask(); - - //banner滑动 - swiper = new Swiper('.swiper-container', { - lazyLoading: true, - loop: true, - autoplay: 3000, - pagination: '.swiper-pagination .pagination-inner' - }); - - //热门品牌滑动 - hotBrandsSwiper = new Swiper('.brands-swiper', { - grabCursor: true, - slidesPerView: 'auto', - wrapperClass: 'brands-list', - slideElement: 'li' - }); -})(); - -$fixTitleBar = $('<div class="title-bar fixed-title-bar"><h2></h2></div>'); -$fixTitleBar.css({ - position: 'fixed', - top: brandSwipe -}).hide(); -minBrandListTop = brandSwipe + $('.hot-brands').outerHeight() + $('.banner-top').outerHeight(); -$brandList.last().append($fixTitleBar); - -function scrollHandler() { - var scrTop = $(window).scrollTop(); - - if ($brandList.eq(0).offset().top < minBrandListTop) { - $fixTitleBar.hide(); - } - - $brandList.each(function() { - var offTop = $(this).offset().top - brandSwipe; - - if (scrTop >= offTop) { - $fixTitleBar.css({ - display: 'block' - }).find('h2').html($(this).find('.title-bar').text()); - } - - }); -} - -if ($('.brand-index-page').length > 0) { - /** - * srcoll to load more - */ - $(window).scroll(function() { - window.requestAnimationFrame(scrollHandler); - }); -} - - -if ($('.history-search').length > 0) { - bindWriteLocal($('.history-search'), false); -} - -if ($('.hot-search').length > 0) { - bindWriteLocal($('.hot-search'), false); -} - -if ($('.brand-search-page').length > 0) { - brandsData = $.parseJSON($('#brands-data').html()); - - $keyword.on('input', function() { - searchInput(); - }); - - // 2016.1.13 产品(高扬)要求进入页面默认显示取消按钮 - $icon.css('color', '#444'); - $keyword.closest('.search-box').css('width', '11.25rem'); - $searchAction.show().find('.clear-text').hide(); - - clearTextHammer = new Hammer($('.clear-text')[0]); - clearTextHammer.on('tap', function(e) { - $('.search-result').html(''); - $('#keyword').val('').trigger('input'); - e.preventDefault(); - e.srcEvent.stopPropagation(); - }); - - $('form.search-box').on('submit', function() { - return false; - }); - -} - -if ($genderItem.length > 0) { - $genderItem.on('touchstart', function() { - var index = $(this).data('id') + 1; - - $('.genderNav ul .active').removeClass('active'); - $(this).addClass('active'); - $('.hide-when-loading').hide(); - loading.showLoadingMask(); - function reload() { - window.location.search = 'channel=' + index; - } - setTimeout(reload.bind(this), 100); - }); -} - -if ($brandItem.length > 0) { - $brandItem.on('click', function() { - var index = $(this).data('id'); - - $('.brandNav ul .active').removeClass('active'); - $(this).addClass('active'); - - - if (index === 0) { - - $recommandBrandWall.not('.hide').addClass('hide'); - $newBrandWall.not('.hide').addClass('hide'); - $brandList.removeClass('hide'); - - } else if (index === 1) { - - $newBrandWall.removeClass('hide'); - $brandList.not('.hide').addClass('hide'); - $recommandBrandWall.not('.hide').addClass('hide'); - - } else { - - $recommandBrandWall.removeClass('hide'); - $brandList.not('.hide').addClass('hide'); - $newBrandWall.not('.hide').addClass('hide'); - - } - - }); -} - -/** - * 清除记录 - */ -function removeHistory() { - $.ajax({ - type: 'GET', - url: '/brands/delBrandHistory', - data: '', - success: function(data) { - }, - error: function() { - } - }); -} - -//初始化历史搜索的内容 - -if ($('.brand-search-page').length > 0) { - - chHammer = new Hammer($clearHistory[0]); - chHammer.on('tap', function() { - if (isLocalStorageSupported()) { - localStorage.removeItem('historys-brand'); - } - $history.html(''); - $historySearch.hide(); - $clearHistory.hide(); - - if ($('.net-search').length > 0) { - removeHistory(); - } - - window.rePosFooter(); - }); - - //搜索页面 - - (function() { - var html = '', - history, - historys, i, - localHistory, - brand,data, - time,netArr,dict,dictc,localArr, - combinArr,key,date,temp; - - localArr = []; - combinArr = []; - netArr = []; - - $netHistory.find('li').each(function() { - - brand = $(this).find('a').attr('brandName'); - time = $(this).find('a').attr('collectTime'); - dict = { - brand: brand, - time: time - },dictc,dict; - netArr.push(dict); - }); - - - if (localStorage) { - if (isLocalStorageSupported()) { - historys = localStorage.getItem('historys-brand'); - } - - if (historys && historys.length > 0) { - historys = historys.split(ranToken); - for (i = historys.length; i > 0; i--) { - history = historys[i - 1]; - - if (history === '') { - continue; - } - localHistory = history.split(ranToken2); - - brand = localHistory[0]; - time = localHistory[1]; - - dict = { - brand: brand, - time: time - }; - - localArr.push(dict); - - } - } - } - - if (localArr.length === 0 && netArr.length === 0) { - $historySearch.addClass('hide'); - return; - } - - - date = {}; - temp = {}; - if (localArr.length > 0) { - for (dictc in localArr) { - if (localArr.hasOwnProperty(dictc)) { - temp = localArr[dictc]; - if (!date[temp.brand] || date[temp.brand] < temp.time) { - date[temp.brand] = temp.time; - } - } - } - } - - if (netArr.length > 0) { - for (dict in netArr) { - if (netArr.hasOwnProperty(dict)) { - temp = netArr[dict]; - if (!date[temp.brand] || date[temp.brand] < temp.time) { - date[temp.brand] = temp.time; - } - } - } - } - - data = {}; - for (key in date) { - if (date.hasOwnProperty(key)) { - data = { - brand: key, - time: date[key] - }; - combinArr.push(data); - } - } - - combinArr.sort(sequence); - - if (combinArr.length > 0) { - for (i = combinArr.length - 1; i >= ((combinArr.length > 10) ? (combinArr.length - 10) : 0); i--) { - - brand = combinArr[i].brand; - time = combinArr[i].time; - - html += '<li><a brandName = "' + brand + - '">' + brand + '</li>'; - $history.removeClass('hide'); - - $history.html(html); - $clearHistory.removeClass('hide'); - - $hotSearch.removeClass('hide'); - window.rePosFooter(); - - } - } else { - $history.addClass('hide'); - } - - }()); - -} - -}); -define("js/plugin/loading", ["jquery"], function(require, exports, module){ -/** - * Loading mask - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/29 - */ - -var $ = require("jquery"); - -var $page = $('.yoho-page'); - -var $loading, - hasInit = false; - -/** modify by liangzhifeng at 2015.11.2 */ - -// 初始化 -function init($container) { - var html = '<div class="loading-mask hide">' + - '<div class="loading">' + - '<div></div><div></div><div></div>' + - '</div>' + - '</div>'; - - hasInit = true; - if ($container === undefined) { - $container = $page; - } - - $container.append(html); - - $loading = $container.children('.loading-mask'); -} - -//显示loading -function showLoadingMask() { - if (!hasInit) { - init(); - hasInit = true; - } - $loading.removeClass('hide'); -} - -//隐藏loading -function hideLoadingMask() { - $loading.addClass('hide'); -} - -exports.init = init; -exports.showLoadingMask = showLoadingMask; -exports.hideLoadingMask = hideLoadingMask; -}); -define("js/guang/entry", ["jquery","lazyload","swiper","hammer","mlellipsis","iscroll-probe","index"], function(require, exports, module){ -/** - * 逛打包入口 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/9 - */ - -require("js/guang/plus-star/list"); -require("js/guang/plus-star/detail"); - -require("js/guang/home"); -require("js/guang/list"); -require("js/guang/detail"); -require("js/guang/star-classroom"); -require("js/guang/calendar"); -require("js/guang/collocation-list"); -require("js/guang/check-top"); -}); -define("js/guang/plus-star/list", ["jquery","lazyload","swiper","index"], function(require, exports, module){ -/** - * PLUS+STAR列表页 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/10 - */ - -var $ = require("jquery"), - lazyLoad = require("lazyload"), - Swiper = require("swiper"); - -var $navs = $('#nav-tab > li'), - $contents = $('#ps-content > .content'); - -var mySwiper; - -lazyLoad($('img.lazy')); - -$('.star-content li').each(function(key, item) { - $(item).find('.swiper-container').addClass('swiper-' + key); - - mySwiper = new Swiper('.swiper-' + key, { - lazyLoading: true, - pagination: '.swiper-' + key + ' .pagination-inner' - }); -}); - -$('#nav-tab').bind('contextmenu', function(e) { - return false; -}); -$('#nav-tab').on('touchend touchcancel', function(e) { - var $this = $(e.target).closest('li'); - - if ($this.hasClass('focus')) { - return; - } - - $navs.toggleClass('focus'); - $contents.toggleClass('hide'); - - $(document).trigger('scroll'); //Trigger lazyLoad -}); -$('#nav-tab').on('touchstart', function(e) { - var target = e.target || e.srcElement; - - target.className = 'bytouch ' + target.className; -}).on('touchend touchcancel', function() { - $navs.removeClass('bytouch'); -}); -}); -define("js/guang/plus-star/detail", ["jquery","hammer","mlellipsis","lazyload","swiper","index"], function(require, exports, module){ -/** - * PLUS+STAR详情页 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/10 - */ - -var $ = require("jquery"), - Hammer = require("hammer"), - ellipsis = require("mlellipsis"), - lazyLoad = require("lazyload"); - -var $intro = $('#intro'), - $imt = $('#intro-more-txt'), - $infosContainer = $('#related-infos-container'); - -var info = require("js/guang/info"); - -var tip = require("js/plugin/tip"); - -var brandId = $('#brand-info').data('id'); - -var jumpToApp = $('#jump-to-app').val(); - -var mIntro, aIntro; - -var moreHammer, likeHammer, $goodName, $title; - -require("js/plugin/wx-share"); - -ellipsis.init(); - -//Init LazyLoad -lazyLoad($('img.lazy')); - -if ($('.good-detail-text .name').length > 0) { - $('.good-detail-text .name').each(function() { - $goodName = $(this); - $title = $goodName.find('a'); - - $title[0].mlellipsis(2); - }); -} - -//文字介绍文字截取 -$intro[0].mlellipsis(3); - -//获取截取文字和完整文字 -setTimeout(function() { - mIntro = $intro.text(); - aIntro = $intro.attr('title'); -}); - -info.initInfosEvt($infosContainer); - -//文字介绍收起与展开 -moreHammer = new Hammer(document.getElementById('more-intro-click-range')); -moreHammer.on('tap', function(e) { - var $this = $imt.parent(); - - $this.toggleClass('spread'); - - if ($this.hasClass('spread')) { - - //显示 - $intro.text(aIntro); - $imt.text('收起'); - } else { - - //隐藏 - $intro.text(mIntro); - $imt.text('more'); - - $(window).scrollTop(0, 400); //滑动到顶部 - } - - e.preventDefault(); //防止收缩后误点到商品产生跳转 -}); - -//品牌收藏 -likeHammer = new Hammer(document.getElementById('brand-like')); -likeHammer.on('tap', function(e) { - var opt = 'ok', - $this = $(e.target); - - - //jumpToApp = 1表示APP未登录的情况,此时不发送ajax请求而由a链接直接跳转APP - if (jumpToApp === '1') { - return; - } - - e.preventDefault(); - - if ($this.hasClass('like')) { - opt = 'cancel'; - } - - $.ajax({ - type: 'POST', - url: '/guang/opt/favoriteBrand', - data: { - id: brandId, - opt: opt - }, - success: function(data) { - if (data.code === 200) { - $this.toggleClass('like'); - tip.show(data.message); - } else if (data.code === 400 || data.code === 412) { - location.href = data.data; //未登录跳转登录页面 - } else { - tip.show(data.message); - } - }, - error: function() { - tip.show('网络断开连接了~'); - } - }); -}); -}); -define("js/guang/info", ["jquery","hammer","mlellipsis","lazyload","swiper","index"], function(require, exports, module){ -/** - * 资讯相关API - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/10 - */ - -var $ = require("jquery"), - Hammer = require("hammer"), - ellipsis = require("mlellipsis"), - lazyLoad = require("lazyload"), - Swiper = require("swiper"); - -var tip = require("js/plugin/tip"); -var loading = require("js/plugin/loading"); - -var $loadMoreInfo = $('#load-more-info'); -var $loading = $(''), - $noMore = $(''), - $swiper = $(''); - -var searching = false; -var mySwiper = {}; - -var isLoading = false; - -ellipsis.init(); - -if ($loadMoreInfo.length > 0) { - $loading = $loadMoreInfo.children('.loading'); - $noMore = $loadMoreInfo.children('.no-more'); -} - -// 获取url中的参数 -function getUrlParam(name) { - - // 构造一个含有目标参数的正则表达式对象 - var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)'); - - // 匹配目标参数 - var r = window.location.search.substr(1).match(reg); - - // 返回参数值 - if (r != null) { - return r[2]; - } - - return null; -} - -//初始化swiper -function initSwiper(typeId) { - if (typeof typeId === undefined) { - return; - } - mySwiper[typeId] = new Swiper('.swiper-cont-' + typeId, { - lazyLoading: true, - wrapperClass: 'swiper-wrap-' + typeId, - pagination: '.swiper-pagi-' + typeId, - autoplay: 3000 - }); -} - -/** - * 设置指定资讯项的Lazyload和文字截取 - * @params $infos 资讯项 - */ -function setLazyLoadAndMellipsis($infos) { - lazyLoad($infos.find('img.lazy')); - - $infos.each(function() { - var $this = $(this), - $title = $this.find('.info-title'), - $text = $this.find('.info-text'); - - $title[0].mlellipsis(2); - $text[0].mlellipsis(2); - }); -} - -/** - * 初始化资讯列表事件绑定 - * @params $container 逛资讯列表容器 - */ -function initInfosEvt($container) { - var cHammer; - - if (typeof $container === 'undefined') { - return; - } - if (typeof $container[0] === 'undefined') { - return; - } - cHammer = new Hammer($container[0]); - - //点赞或者收藏事件 - cHammer.on('tap', function(e) { - var $this = $(e.target), - opt = 'ok', - $btn, - $info, - yhChannel; - - //e.preventDefault(); - - //点赞 - $btn = $this.closest('.like-btn'); - if ($btn.length > 0 && !isLoading) { - e.preventDefault(); - if ($btn.hasClass('like')) { - opt = 'cancel'; - } - - $info = $this.closest('.guang-info'); - - isLoading = true; - - $.ajax({ - type: 'POST', - url: '/guang/opt/praiseArticle', - data: { - id: $info.data('id'), - opt: opt - }, - success: function(data) { - var code = data.code; - - - if (code === 200) { - $btn.next('.like-count').text(data.data); - - //切换点赞状态 - $btn.toggleClass('like'); - } - }, - error: function() { - tip.show('网络断开连接了~'); - }, - complete: function() { - isLoading = false; - } - }); - return; - } - - //APP收藏 - $btn = $this.closest('.collect-btn'); - if ($btn.length > 0) { - e.preventDefault(); - if ($btn.hasClass('collected')) { - opt = 'cancel'; - } - - $info = $this.closest('.guang-info'); - - if (getUrlParam('yh_channel')) { - yhChannel = getUrlParam('yh_channel'); - } - - $.ajax({ - type: 'POST', - url: '/guang/opt/collectArticle', - data: { - id: $info.data('id'), - opt: opt, - yh_channel: yhChannel, - uid: getUrlParam('uid') - }, - success: function(data) { - if (data.code && data.code === 200) { - - //切换收藏状态 - $btn.toggleClass('collected'); - } - }, - error: function() { - tip.show('网络断开连接了~'); - } - }); - } - }); - - setLazyLoadAndMellipsis($container.find('.guang-info')); -} - -/** - * 资讯LoadMore - * @param $container 资讯容器 jqyeryObject - * @param opt 请求参数 - * @param url[可选], 扩展请求的url而不使用默认值 - */ -function loadMore($container, opt, url) { - var num; - - if (searching) { - return; - } - - if (opt.end) { - return; - } - - if (opt.page === 1) { - - //显示loading - loading.showLoadingMask(); - } - - num = $container.find('.guang-info').length; - searching = true; - $.ajax({ - type: 'GET', - url: url ? url : '/guang/index/page',//对于指定url的使用指定url(存在不同的控制器) - data: opt, - success: function(data) { - var $newItems; - - if (data === ' ') { - opt.end = true; - searching = false; - - // - $loading.addClass('hide'); - $noMore.removeClass('hide'); - - return; - } - - $container.append(data); - - $swiper = $container.find('.swiper-container'); - if ($swiper.length) { - $swiper.addClass('swiper-cont-' + opt.type); - $swiper.children('.swiper-wrapper').addClass('swiper-wrap-' + opt.type); - $swiper.children('.swiper-pagination').addClass('swiper-pagi-' + opt.type); - initSwiper(opt.type); - } - - if (num > 0) { - $newItems = $container.find('.guang-info:gt(' + (num - 1) + ')'); - } else { - $newItems = $container.find('.guang-info'); - } - - setLazyLoadAndMellipsis($newItems); - - if (opt.page === 1) { - loading.hideLoadingMask(); - - $loading.removeClass('hide');//显示空屏加载时hide的隐藏 - - window.rePosFooter();//插入内容后重新计算底部位置 - } - - opt.page++; - - searching = false; - delete opt.isTab; - }, - error: function() { - tip.show('网络断开连接了~'); - searching = false; - delete opt.isTab; - } - }); -} - - -exports.mySwiper = mySwiper; -exports.initSwiper = initSwiper; -exports.initInfosEvt = initInfosEvt; -exports.setLazyLoadAndMellipsis = setLazyLoadAndMellipsis; -exports.loadMore = loadMore; - -}); -define("js/plugin/tip", ["jquery"], function(require, exports, module){ -/** - * 弹框提示 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/10 - */ -var $ = require("jquery"); - -var $tip, tipItime; - -/** - * 初始化提示框 - */ -(function() { - var tipHtml = '<div id="yoho-tip" class="yoho-tip"></div>'; - - //插入提示HTML - $('.yoho-page').append(tipHtml); - - $tip = $('#yoho-tip'); - $tip.on('touchend', function() { - $tip.hide(); - - //清除Timeout - clearTimeout(tipItime); - }); -}()); - -/** - * 显示提示 - */ -function show(con, dur) { - var content, duration; - - if (typeof con === 'undefined') { - return; - } - - content = con.toString(); - duration = (dur && dur > 0) ? dur : 2000; - - $tip.text(content).show(); - - tipItime = setTimeout(function() { - if ($tip.css('display') === 'block') { - $tip.hide(); - } - }, duration); -} - -exports.show = show; -}); -define("js/plugin/wx-share", ["jquery"], function(require, exports, module){ -/** - * 微信分享 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/30 - */ - -var $ = require("jquery"); - -module.exports = function() { - var _weChatInterface = '/life/getSignPackage'; - $.getJSON(_weChatInterface + '?pageurl=' + - encodeURIComponent(location.href.split('#')[0]) + '&callback=?', function (json) { - var _appId, _timestamp, _nonceStr, _signature; - - if (!wx) { - return; - } - - if (json !== undefined && json !== '') { - _appId = json.appId.toString(); - _timestamp = json.timestamp; - _nonceStr = json.nonceStr.toString(); - _signature = json.signature.toString(); - - wx.config({ - debug: false, - appId: _appId, - timestamp: _timestamp, - nonceStr: _nonceStr, - signature: _signature, - jsApiList: [ - 'checkJsApi', - 'onMenuShareTimeline', - 'onMenuShareAppMessage', - 'onMenuShareQQ', - 'onMenuShareWeibo', - 'hideMenuItems', - 'showMenuItems', - 'hideAllNonBaseMenuItem', - 'showAllNonBaseMenuItem', - 'translateVoice', - 'startRecord', - 'stopRecord', - 'onRecordEnd', - 'playVoice', - 'pauseVoice', - 'stopVoice', - 'uploadVoice', - 'downloadVoice', - 'chooseImage', - 'previewImage', - 'uploadImage', - 'downloadImage', - 'getNetworkType', - 'openLocation', - 'getLocation', - 'hideOptionMenu', - 'showOptionMenu', - 'closeWindow', - 'scanQRCode', - 'chooseWXPay', - 'openProductSpecificView', - 'addCard', - 'chooseCard', - 'openCard' - ] - }); - } - }); - - wx.ready(function () { - var shareTitle = $('#shareTitle').val(); - var shareImg = $('#shareImg').val(); - var shareDesc = $('#shareDesc').val(); - var shareLink = $('#shareLink').val(); - var shareData = { - title: shareTitle, - desc: shareDesc, - imgUrl: shareImg, - link: shareLink - }; - - wx.onMenuShareAppMessage(shareData); - wx.onMenuShareTimeline(shareData); - wx.onMenuShareQQ(shareData); - wx.onMenuShareWeibo(shareData); - }); -}; - -}); -define("js/guang/home", ["jquery","hammer","mlellipsis","lazyload","swiper","index"], function(require, exports, module){ -/** - * 逛首页 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/10 - */ - -var $ = require("jquery"); - -var info = require("js/guang/info"), - loadMore = info.loadMore; - -var $loadMoreInfo = $('#load-more-info'); -var $loading = $(''), - $noMore = $(''); - -var winH = $(window).height(); - -var $infoList = $('#info-list'), - $infos = $infoList.children('.info-list'), - $nav = $('#guang-nav'), - $curNav = $nav.children('.focus'), - curType = $curNav.data('type'); - -var state = {}; - -if ($loadMoreInfo.length > 0) { - $loading = $loadMoreInfo.children('.loading'); - $noMore = $loadMoreInfo.children('.no-more'); -} - -info.initSwiper(curType); - -info.initInfosEvt($infoList); - -//初始化各Nav下资讯加载的状态 -(function() { - var gender = $('#gender').val(); - - $nav.children('.guang-nav-item').each(function() { - var type = $(this).data('type'), - focus = $(this).hasClass('focus'); - - state[type] = { - page: focus ? 2 : 1, - gender: gender, - type: type, - end: false - }; - }); -}()); -$nav.bind('contextmenu', function(e) { - return false; -}); -$nav.on('touchend touchcancel', function(e) { - - var $this = $(e.target).closest('.guang-nav-item'), - $content, - index; - - if ($this.hasClass('focus')) { - return; - } - - - index = $this.index(); - - $this.addClass('focus'); - $curNav.removeClass('focus'); - - $content = $infos.eq(index); - - $curNav = $this; - curType = $this.data('type'); - - //当未加载数据时去请求数据 - if (state[curType].page === 1) { - - //无数据时隐藏正在加载和没有更多字样 - $loading.addClass('hide'); - $noMore.addClass('hide'); - - state[curType].isTab = true; - loadMore($content, state[curType]); - } else { - - //重置当前Tab的load-more - if (state[curType].end) { - $loading.addClass('hide'); - $noMore.removeClass('hide'); - } else { - $loading.removeClass('hide'); - $noMore.addClass('hide'); - } - } - - $infos.not('.hide').addClass('hide'); - $content.removeClass('hide'); - - if (state[curType].page === 1) { - window.rePosFooter();//进入空内容时重新定位footer位置 - } -}); - -function scrollHandler() { - var $c = $infos.not('.hide'); - - if ($(window).scrollTop() + winH >= $(document).height() - 0.25 * $c.height()) { - loadMore($c, state[curType]); - } -} - -//srcoll to load more -$(document).scroll(function() { - window.requestAnimationFrame(scrollHandler); -}); - -$nav.on('touchstart', function(e) { - var target = e.target || e.srcElement; - - target.className = 'bytouch ' + target.className; -}).on('touchend touchcancel', function() { - $nav.find('li').removeClass('bytouch'); -}); -}); -define("js/guang/list", ["jquery","hammer","mlellipsis","lazyload","swiper","index"], function(require, exports, module){ -/** - * 列表页,编辑页 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/10 - */ - -var $ = require("jquery"); - -var info = require("js/guang/info"), - loadMore = info.loadMore; - -var winH = $(window).height(); - -var $author = $('#author-infos'); -var $tag = $('#tag'); -var $gender = $('#gender'); -var $isApp = $('#isApp'); - -var setting = { - page: 2, - end: false -}; - -var $infos = $('#info-list'); - -info.initInfosEvt($infos); - -if ($author.length > 0) { - $.extend(setting, { - authorId: $author.data('id'), - isApp: $isApp.val() - }); -} - -if ($tag.length > 0) { - $.extend(setting, { - tag: $tag.val(), - gender: $gender.val(), - isApp: $isApp.val() - }); -} - -function scrollHandler() { - if ($(window).scrollTop() + winH >= $(document).height() - 0.25 * $infos.height()) { - loadMore($infos, setting); - } -} - -//srcoll to load more -$(window).scroll(function() { - window.requestAnimationFrame(scrollHandler); -}); - -}); -define("js/guang/detail", ["jquery","mlellipsis","lazyload","iscroll-probe"], function(require, exports, module){ -/** - * 逛详情页 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/13 - */ - -var $ = require("jquery"), - ellipsis = require("mlellipsis"), - lazyLoad = require("lazyload"), - IScroll = require("iscroll-probe"); - -var $authorIntro = $('.author .intro'); - -var pageInIscroll = false; - -var hasCollocationBlock = $('.collocation-block').length > 0 ? true : false; - -//collocation block variable -var thumbWidth = 0, - $fixedThumbContainer = $(''), - $coBlock, $thumbContainer, $thumbs, $prods, - scrollToEl; - -var scrollToEl = document.querySelector('#wrapper .collocation-block'); - -var winW = $(window).width(); - -var myScroll; - -require("js/plugin/wx-share")(); - -/** - * 计算搭配的箭头的位置 - * @param $curPos 当前focus的搭配项 - */ -function posCollocationArrow($curCo) { - var left = $curCo.offset().left, - bgPos = -winW + left + (thumbWidth / 2) + 'px'; - - $thumbContainer.css({ - backgroundPosition: bgPos + ' bottom' - }); - - if (pageInIscroll) { - $fixedThumbContainer.css({ - backgroundPosition: bgPos + ' bottom' - }); - } -} - -//搭配thumb的touch事件句柄 -function thumbTouchEvt(e) { - var $curCo = $(e.currentTarget), - index = $curCo.index(), - $brother, $brotherCo, - $curProds; - - if ($curCo.hasClass('focus')) { - return; - } - - $thumbs.filter('.focus').removeClass('focus'); - - if (pageInIscroll) { - if ($curCo.closest('.fixed-thumb-container').length > 0) { - $brother = $thumbContainer; - } else { - $brother = $fixedThumbContainer; - } - - $brotherCo = $brother.find('.thumb').eq(index); - $fixedThumbContainer.find('.thumb.focus').removeClass('focus'); - $brotherCo.addClass('focus'); - } - - $curCo.addClass('focus'); - - //定位arrow - posCollocationArrow($curCo); - - $prods.not('.hide').addClass('hide'); - $curProds = $prods.eq(index); - $curProds.removeClass('hide'); - - // - lazyLoad($curProds.find('.lazy')); - - if (pageInIscroll) { - if (myScroll) { - myScroll.scrollToElement(scrollToEl, 400); - } - } else { - $('body').animate({ - scrollTop: $coBlock.offset().top - }, 400); - } - - myScroll && myScroll.refresh(); -} - -// 初始化iscroll -function initIscroll() { - var $scroller = $('#scroller'), - $yohoHeader = $('.yoho-header'); - - var hH = 0, - winH, tcH, cbH, cbTop, fixedThumbDom; - - //考虑通用头部的影响:对offset().top以及winH做对应偏移 - if ($yohoHeader.length > 0) { - hH = $yohoHeader.outerHeight(); - } - - myScroll = new IScroll('#wrapper', { - probeType: 3, - mouseWheel: true, - click: true - }); - - document.addEventListener('touchmove', function(e) { - e.preventDefault(); - }, false); - - if (!hasCollocationBlock) { - myScroll.on('scroll', function() { - $scroller.trigger('scroll'); - }); - return; - } - - winH = $(window).height() - hH; - fixedThumbDom = $fixedThumbContainer[0]; - - tcH = $thumbContainer.outerHeight(); - cbH = $coBlock.outerHeight(); - cbTop = $coBlock.offset().top - hH; - - myScroll.on('scroll', function() { - var sTop = -this.y; - var classList = fixedThumbDom.className; - - if (sTop <= cbTop - winH + tcH) { - if (classList.indexOf('fixed-bottom') === -1) { - $fixedThumbContainer - .addClass('fixed-bottom') - .removeClass('hide'); - } - } else if (sTop <= cbTop) { - if (classList.indexOf('hide') === -1) { - $fixedThumbContainer - .addClass('hide') - .removeClass('fixed-bottom fixed-top'); - } - } else if (sTop <= cbTop + cbH - tcH) { - if (classList.indexOf('fixed-top') === -1) { - $fixedThumbContainer - .addClass('fixed-top') - .removeClass('hide absolute') - .css('top', ''); - } - } else if (sTop <= cbTop + cbH) { - if (classList.indexOf('absolute') === -1) { - $fixedThumbContainer - .addClass('absolute') - .removeClass('fixed-top hide'); - } - fixedThumbDom.style.top = cbTop + hH + cbH - tcH - sTop + 'px'; - } else if (sTop > cbTop + cbH) { - if (classList.indexOf('hide') === -1) { - $fixedThumbContainer - .addClass('hide') - .removeClass('absolute'); - } - } - $scroller.trigger('scroll'); - }); -} - -//window onload 后重新refresh iscroll -window.onload = function() { - myScroll && myScroll.refresh(); -}; - -// 图片加载完成之后重新 refresh iscroll -$('img').on('load', function() { - myScroll && myScroll.refresh(); -}); - -//初始化页面,包括是否使用iscorll初始化页面 -//接口暴露在HTML中,使用压缩名 -exports.i = function(useIscroll) { - var isIphone = navigator.userAgent.indexOf('iPhone') > 0 ? true : false; - var $this, $title; - - pageInIscroll = isIphone && useIscroll; - - ellipsis.init(); - - if ($('.good-detail-text .name').length > 0) { - $('.good-detail-text .name').each(function() { - $this = $(this); - $title = $this.find('a'); - - $title[0].mlellipsis(2); - }); - } - - lazyLoad($('.lazy')); - - //title mlellipsis - $('.info-list .title, .one-good .reco-name').each(function() { - this.mlellipsis(2); - }); - - //offset.left约等于marginLeft的值则表示介绍被换行,则清除intro的paddingTop让其更靠近头像和作者名 - if ($authorIntro.offset() && (parseInt($authorIntro.offset().left, 10) === - parseInt($authorIntro.css('margin-left'), 10))) { - $authorIntro.css('padding-top', 0); - } - - if (pageInIscroll) { - if ($('.yoho-header').length > 0) { - $('#wrapper').addClass('ios has-head'); - } else { - $('#wrapper').addClass('ios'); - } - } - - //有搭配模块,iphone使用iscroll初始化滚动并有固定的搭配栏,其他的没有 - if (hasCollocationBlock) { - $coBlock = $('.collocation-block'); - $thumbContainer = $coBlock.children('.thumb-container'); - $thumbs = $thumbContainer.find('li'); - $prods = $coBlock.find('.prod'); - - thumbWidth = $thumbs.width(); - - if (pageInIscroll) { - $fixedThumbContainer = $('#wrapper') - .after($thumbContainer.clone().addClass('fixed-thumb-container fixed-bottom')) - .next('.thumb-container'); - - //load img of fixed thumb container - lazyLoad($fixedThumbContainer.find('.lazy'), { - event: 'sporty' - }); - } - - //Init Arrow Position - posCollocationArrow($thumbs.filter('.focus')); - - $thumbContainer.delegate('.thumb', 'touchend', thumbTouchEvt); - - if (pageInIscroll) { - $fixedThumbContainer.delegate('.thumb', 'touchend', thumbTouchEvt); - - } - } - - if (pageInIscroll) { - initIscroll(); - } -}; -}); -define("js/guang/star-classroom", ["jquery","swiper","lazyload","index"], function(require, exports, module){ -/** - * 星潮教室-首页 - * @author: wsl<shuiling.wang@yoho.cn> - * @date: 2016/4/11 - */ - -var $ = require("jquery"), - Swiper = require("swiper"), - calendar = require("js/guang/calendar"), - lazyLoad = require("lazyload"), - tip = require("js/plugin/tip"); - -var bannerSwiper, collocationSwiper; - -lazyLoad($('img.lazy')); - -$('body').addClass('star-class-body'); - -function setAvatar($userAvatar) { - var myImage = new Image(), - avatar; - - // 部分老用户没有头像,显示默认头像 - avatar = $userAvatar.data('avatar'); - myImage.src = avatar; - myImage.onload = function() { - $userAvatar.css('background-image', 'url(' + avatar + ')'); - }; -} - -// 日历弹出框显示及粉丝排行榜数据组装 -function intimacyData(data) { - var $ul = $('.fan-charts-cont'), - $myIntimacy = $('.my-intimacy'), - $increased = $('.increased'), - signDay = data.signDay.split(','), - html = '', - style = '', - nowDate = new Date(), - nowYear = nowDate.getFullYear(), - nowMonth = nowDate.getMonth(), - nowDaysNub = calendar.calculateMonthDays(nowMonth, nowYear); - - var i, j; - - if (signDay.length > 0) { - for (i = 0; i < nowDaysNub; i++) { - for (j = 0; j < signDay.length; j++) { - if (i === parseInt(signDay[j])) { - $('.now-days').eq(i - 1).addClass('sign-item'); - } - } - } - } - - for (i = 0; i < data.fanCharts.length; i++) { - if (i === 0) { - style = 'font-bold'; - } else { - style = ''; - } - - html += '<li>' + - '<i class="rank-ico">' + data.fanCharts[i].num + '</i>' + - '<span data-avatar="' + data.fanCharts[i].img + '" class="rank-avatar"></span>' + - '<span class="fans-name">' + data.fanCharts[i].name + '</span>' + - '<div class="fans-intimacy">亲密度<span class="' + style + '">' + - data.fanCharts[i].intimacyNum + '</span></div>' + - '</li>'; - } - - $ul.html(html); - - $('.fan-charts-cont .rank-avatar').each(function(key, item) { - if ($(item).attr('data-avatar') !== '') { - setAvatar($(item)); - } - }); - - $myIntimacy.find('span').html(data.todayIntimacy); - $increased.find('span').html(data.todayIntimacy); - - if (data.intimacyNum === 0) { - $('.my-intimacy').hide(); - $('.increased').show(); - } else { - $('.my-intimacy').show(); - $('.increased').hide(); - } - - $('.pop-intimacy').css({ - zIndex: '10' - }).show(); - $('.classroom-mask').css({ - zIndex: '9' - }).show(); - $('body').css({ - overflow: 'hidden' - }); -} - -//当前字符串字节数统计 -function bytesCountAction(code, bytesCount) { - if (/^[\u0000-\u00ff]$/.test(code)) { - bytesCount += 1; - } else { - bytesCount += 2; - } - - return bytesCount; -} - -// 亲密度用户名字字数限制 -function limitUsername() { - var $name = $('.home-floor-sign').find('.user-name'), - nameVal = $name.html(), - nameSize = nameVal.length, - bytesCount = 0, - newName = ''; - - var i, code; - - for (i = 0; i < nameSize; i++) { - code = nameVal.charAt(i); - bytesCount = bytesCountAction(code, bytesCount); - - if (bytesCount < 5) { - newName += code; - } - } - - if (bytesCount > 8) { - newName += '..' + nameVal.charAt(nameSize - 1); - } else { - newName = nameVal; - } - - $name.html(newName); -} - -if ($('.banner-swiper').find('li').length > 1) { - bannerSwiper = new Swiper('.banner-swiper', { - lazyLoading: true, - lazyLoadingInPrevNext: true, - loop: true, - autoplay: 3000, - autoplayDisableOnInteraction: false, - paginationClickable: true, - slideElement: 'li', - pagination: '.banner-top .pagination-inner' - }); -} - -if ($('.collocation-swiper').find('li').length > 1) { - collocationSwiper = new Swiper('.collocation-swiper', { - lazyLoading: true, - lazyLoadingInPrevNext: true, - lazyLoadingOnTransitionStart: true, - grabCursor: true, - slidesPerView: 'auto', - slideElement: 'li', - watchSlidesVisibility: true - }); -} - -// 星鲜事显示点赞人数的区域 -if ($('.artice-zan').find('li').length > 0) { - $('.zan-more').show(); -} - -if ($('.home-floor-sign').length > 0) { - limitUsername(); -} - -// 星鲜事点赞事件 -$(document).on('touchstart', '.like-ico', function(event) { - var $that = $(this), - addString = ''; - - event.stopPropagation(); - - $.ajax({ - type: 'POST', - url: '/guang/starclass/setPraise', - data: { - articleId: $that.parents('li').attr('articleId') - }, - success: function(data) { - var code = data.code; - - if (code === 200) { - if ($that.hasClass('like')) { - $that.removeClass('like'); - } else { - $that.addClass('like'); - } - - if (data.num > 99) { - addString = '+'; - } else { - addString = ''; - } - - $that.parent().find('.zan-more').html(data.num + addString); - } - }, - error: function() { - tip.show('网络断开连接了~'); - } - }); -}); - -// 增加亲密度请求 -$('.add-intimacy').on('touchstart', function(event) { - event.stopPropagation(); - event.preventDefault(); - - $.ajax({ - type: 'GET', - url: '/guang/starclass/sign', - success: function(data) { - var code = data.code; - - if (code === 200) { - intimacyData(data.data); - } - - if (code === 201) { - if ($('#intimacy-link').length <= 0) { - $('body').append('<a href=\'' + data.data + '\' style="display:none;" id="intimacy-link">' + - '<span class="intimacy-link"></span></a>'); - } - - $('.intimacy-link').click(); - } - }, - error: function() { - tip.show('网络断开连接了~'); - } - }); -}); - -// 关闭日历弹出窗事件 -$('.pop-intimacy .pop-close, .classroom-mask').on('click', function() { - history.go(0); -}); - - -if ($('.user-head').attr('data-avatar') !== '') { - setAvatar($('.user-head')); -} - -}); -define("js/guang/calendar", ["jquery"], function(require, exports, module){ -/** - * 星潮教室 亲密度·日期 - * @author: wsl<shuiling.wang@yoho.cn> - * @date: 2016/4/11 - */ - -var $ = require("jquery"); - -var CalendarHandler = { - currentYear: 0, - currentMonth: 0, - initialize: function() { - var $calendarItem; - - $calendarItem = this.createCalendar(0, 0); - $('#Container').append($calendarItem); - }, - isRuiYear: function(aDate) { - return 0 === aDate % 4 && (aDate % 100 !== 0 || aDate % 400 === 0); - }, - calculateWeek: function(y, m, d) { - var arr, vDay, week; - - arr = '7123456'.split(''); - vDay = parseInt(d, 10); - week = arr[new Date(y, m - 1, vDay).getDay()]; - return week; - }, - calculateMonthDays: function(m, y) { - var mDay = 0; - var isRn; - - if (m === 0 || m === 1 || m === 3 || m === 5 || m === 7 || m === 8 || m === 10 || m === 12) { - mDay = 31; - } else { - if (m === 2) { - - // 判断是否为芮年 - isRn = this.isRuiYear(y); - if (isRn === true) { - mDay = 29; - } else { - mDay = 28; - } - } else { - mDay = 30; - } - } - return mDay; - }, - createCalendar: function(y, m) { - var $dayItem, nowDate, nowYear, nowMonth, nowDaysNub, nowWeek, lastMonthDaysNub, i, hasCreateDaysNub; - - var months = ['January', 'February', 'March', 'April', 'May', - 'June', 'July', 'August', 'September', 'October', 'November', 'December']; - - // var signDay = $('.sign-day').val(); - - $dayItem = $('<div class="day-item"></div>'); - - // 获取当前月份的天数 - nowDate = new Date(); - - nowYear = y === 0 ? nowDate.getFullYear() : y; - this.currentYear = nowYear; - nowMonth = m === 0 ? nowDate.getMonth() + 1 : m; - this.currentMonth = nowMonth; - nowDaysNub = this.calculateMonthDays(nowMonth, nowYear); - - window.nowDaysNub = nowDaysNub; - - $('.cur-year').html(nowYear); - $('.cur-month').html(months[nowMonth - 1]); - - // 获取当月第一天是星期几 - nowWeek = parseInt(this.calculateWeek(nowYear, nowMonth, 1)); - - // 获取上个月的天数 - lastMonthDaysNub = this.calculateMonthDays((nowMonth - 1), nowYear); - - if (nowWeek !== 0) { - - // 生成上月剩下的日期 - for (i = (lastMonthDaysNub - nowWeek); i < lastMonthDaysNub; i++) { - $dayItem.append('<div class="item last-item">' + (i + 1) + '</div>'); - } - } - - // 生成当月的日期 - for (i = 1; i <= nowDaysNub; i++) { - - // if (signDay.indexOf(i) > -1) { - // $dayItem.append('<div class="item signItem">' + i + '</div>'); - // } else { - // $dayItem.append('<div class="item">' + i + '</div>'); - // } - - $dayItem.append('<div class="item now-days">' + i + '</div>'); - } - - // 获取总共已经生成的天数 - hasCreateDaysNub = nowWeek + nowDaysNub; - - // 如果小于42,往下个月推算 - if (hasCreateDaysNub < 41) { - for (i = 0; i <= (41 - hasCreateDaysNub); i++) { - $dayItem.append('<div class="item last-item">' + (i + 1) + '</div>'); - } - } - - return $dayItem; - } -}; - -$(document).ready(function() { - CalendarHandler.initialize(); -}); - -exports.calculateMonthDays = CalendarHandler.calculateMonthDays; - -}); -define("js/guang/collocation-list", ["jquery","lazyload","mlellipsis"], function(require, exports, module){ -/** - * 星潮教室-星搭配分页加载 - * @author: wsl<shuiling.wang@yoho.cn> - * @date: 2016/4/12 - */ - -var $ = require("jquery"), - tip = require("js/plugin/tip"), - loading = require("js/plugin/loading"), - lazyLoad = require("lazyload"), - ellipsis = require("mlellipsis"), - stopLoading = false; - -var page = 1; - -ellipsis.init(); - -$('body').addClass('star-class-body'); - -function massageAJAX(page) { - var $this, $title, $cont; - - loading.showLoadingMask(); - $.ajax({ - type: 'GET', - url: '/guang/starclass/ajaxCollocation', - data: { - page: page - }, - dataType: 'html', - success: function(data) { - stopLoading = false; - - if (data === ' ') { - stopLoading = true; - tip.show('没有更多内容了'); - } - - $('.collocation-list').append(data); - - // 限制标题字数 - $('.cont-area').each(function() { - $this = $(this); - $title = $this.find('.title'); - $cont = $this.find('.cont-txt'); - - $title[0].mlellipsis(2); - $cont[0].mlellipsis(2); - }); - - loading.hideLoadingMask(); - lazyLoad($('img.lazy')); - }, - error: function() { - tip.show('网络断开连接了~'); - } - }); -} - -function scrollHandler() { - if (!stopLoading && ($(window).scrollTop() + $(window).height() > $('body').height() - 100)) { - stopLoading = true; - page++; - massageAJAX(page); - } -} - -// 分享成功 -window.successShare = function() { - $.ajax({ - type: 'POST', - url: '/guang/starclass/forward', - success: function(data) { - var code = data.code; - - if (code === 200 && data.data > 0) { - tip.show('分享成功,亲密度+10'); - } - }, - error: function() { - tip.show('网络断开连接了~'); - } - }); -}; - -$(window).scroll(function() { - scrollHandler(); -}); - -if ($('.collocation-list').find('li').length === 0) { - massageAJAX(1); -} - -// 星搭配收藏请求 -$(document).on('touchstart', '.collection', function(event) { - var $that = $(this), - $icon = $that.find('.collected-ico'); - - var type; - - event.stopPropagation(); - - if ($icon.hasClass('collected')) { - type = 'del'; - } else { - type = 'fav'; - } - - - $.ajax({ - type: 'POST', - url: '/guang/starclass/setFavorite', - data: { - articleId: $that.parents('li').attr('articleId'), - type: type - }, - success: function(data) { - var code = data.code; - - if (code === 200) { - if ($icon.hasClass('collected')) { - $icon.removeClass('collected'); - } else { - $icon.addClass('collected'); - } - - } - - if (code === 201) { - if ($('#collocation-link').length <= 0) { - $('body').append('<a href=\'' + data.data + '\' style="display:none;" id="collocation-link">' + - '<span class="collocation-link"></span></a>'); - } - - $('.collocation-link').click(); - } - }, - error: function() { - tip.show('网络断开连接了~'); - } - }); -}); - -}); -define("js/guang/check-top", ["jquery"], function(require, exports, module){ -/** - * 星潮教室-top100 - * @author: wsl<shuiling.wang@yoho.cn> - * @date: 2016/4/12 - */ - -var $ = require("jquery"); - -$('body').addClass('star-class-body'); - -function setAvatar($userAvatar) { - var myImage = new Image(), - avatar; - - // 部分老用户没有头像,显示默认头像 - avatar = $userAvatar.data('avatar'); - myImage.src = avatar; - myImage.onload = function() { - $userAvatar.css('background-image', 'url(' + avatar + ')'); - }; -} - -if ($('.ranking-area li').length > 0) { - $.each($('.ranking-area li'), function(key, item) { - setAvatar($(item).find('.rank-avatar')); - }); -} - -if ($('.user-avatar').attr('data-avatar') !== '') { - setAvatar($('.user-avatar')); -} -}); -define("js/home/entry", ["jquery","swiper","lazyload","hammer","mlellipsis","index"], function(require, exports, module){ -/** - * 首页打包入口 - * @author: liangzhifeng<zhifeng.liang@yoho.cn> - * @date: 2015/10/12 - */ - -require("js/home/home"); -require("js/home/maybe-like"); -}); -define("js/home/home", ["jquery","swiper","lazyload","hammer","mlellipsis","index"], function(require, exports, module){ -/** - * 首页 - * @author: liangzhifeng<zhifeng.liang@yoho.cn> - * @date: 2015/10/12 - */ -var $ = require("jquery"), - Swiper = require("swiper"), - lazyLoad = require("lazyload"), - noticeScroll = require("js/plugin/notice-scroll"), - $mobileWrap = $('.mobile-wrap'), - $overlay = $('.overlay'), - $sideNav = $('.side-nav'), - $subNav = $('.sub-nav'), - bannerSwiper, - recommendSwiper, - hotBrandsSwiper, - trendTopicSwiper, - goodsSwiper, - freshSwiper; - -var start = 0, - swiperClass, - $logotrans = $('.home-header .logo'), - openSideNav = false, - isen = true; - -var attachFastClick = require("js/home/fastclick"); -attachFastClick(document.body); - -lazyLoad($('img.lazy')); -noticeScroll('.notice', $('.notice').data('time') * 1000); - -$('.nav-btn').on('touchstart', function() { - $sideNav.css('pointer-events', 'none'); - $mobileWrap.addClass('menu-open'); - $overlay.show().css('opacity', 0.3); - $sideNav.addClass('on'); - openSideNav = true; - - setTimeout(function() { - $sideNav.css('pointer-events', 'auto'); - }, 400); - - return false; -}); - -function hideSideBar(){ - openSideNav = false; - if ($mobileWrap.hasClass('menu-open')) { - $mobileWrap.removeClass('menu-open'); - $overlay.hide(); - $('.sub-nav').removeClass('show'); - $sideNav.removeClass('on'); - } -} - -$overlay.on('touchstart', function() { - hideSideBar(); - return false; -}); - -$sideNav.on('touchmove scroll', function() { - return false; -}); - -// 点击一级导航,弹出二级导航 -$sideNav.on('touchend', 'li', function(e) { - if ($(this).find('.sub-nav').size() > 0) { - $('.sub-nav').removeClass('show'); - $(this).find('.sub-nav').addClass('show'); - $(this).find('.highlight').removeClass('highlight'); - } - - if (e.target.pathname === location.pathname) { - hideSideBar(); - return false; - } -}); +/** + * 品牌一览 + * @author: liangzhifeng<zhifeng.liang@yoho.cn> + * @date: 2015/10/23 + */ -// 返回一级导航,收起二级导航 -$subNav.each(function() { - $(this).find('li').eq(0).on('click', function() { - $('.sub-nav').removeClass('show'); - return false; - }); -}).on('touchstart', function(e) { - if (e.currentTarget !== e.target) { - $subNav.find('li').removeClass('current'); - } -}); +var $ = require("jquery"), + Hammer = require("hammer"), + Swiper = require("swiper"), + loading = require("js/plugin/loading"), + lazyLoad = require("lazyload"); -// 侧边栏点击背景色变化 -function highlight($elem) { - $elem.find('li').on('touchstart', function() { - $elem.find('.highlight').removeClass('highlight'); - $(this).addClass('highlight'); +var ranToken = ' ??++ '; +var ranToken2 = ' ???--- '; + +var swiper, + $fixTitleBar, + $brandList = $('.brand-list'), + $icon = $('.search-icon'), + $genderItem = $('.genderNav li'), + $brandItem = $('.brandNav li'), + $newBrandWall = $('.new-brand-wall'), + $recommandBrandWall = $('.recommand-brand-wall'), + $searchAction = $('.search-action'), + $homebuttom = $('.homebuttom'), + $genderNav = $('.genderNav'), + $newSearch = $('.newbrand-search'), + $netHistory = $('.net-history'), + $navBtn = $('.nav-home'), + hotBrandsSwiper; + +var searchH = $('.newbrand-search').outerHeight(), + headerH = $('.yoho-header').outerHeight(), + brandSwipe = parseInt(searchH) + parseInt(headerH) - 1, + minBrandListTop; + +var brandsData, + $keyword = $('#keyword'), + clearTextHammer; + +var $history = $('.local-history'); +var $searchPage = $('.search-brand-page'); +var $historySearch = $('.history-search'); +var $hotSearch = $('.hot-search'); + +var $clearHistory = $('#clear-history'); + +var chHammer; + + +function changeBackground() { + var $brandList = $('.brand-list').find('p'); + + $brandList.on('touchstart', function() { + $brandList.css('background', '#fff'); + $(this).css('background', '#eee'); }).on('touchend touchcancel', function() { - $(this).removeClass('highlight'); - }); -} -highlight($sideNav); -highlight($subNav); - - -// 头部banner轮播 -if ($('.banner-swiper').find('li').size() > 1) { - bannerSwiper = new Swiper('.banner-swiper', { - lazyLoading: true, - lazyLoadingInPrevNext: true, - loop: true, - autoplay: 3000, - autoplayDisableOnInteraction: false, - paginationClickable: true, - slideElement: 'li', - pagination: '.banner-top .pagination-inner' - }); -} - -// 热门品牌滑动 -hotBrandsSwiper = new Swiper('.brands-swiper', { - grabCursor: true, - slidesPerView: 'auto', - wrapperClass: 'brands-list', - slideElement: 'li' -}); - -// 推荐搭配滑动 -recommendSwiper = new Swiper('.recommend-swiper', { - grabCursor: true, - slidesPerView: 'auto', - wrapperClass: 'recommend-list', - slideElement: 'li' -}); - -// 潮品话题轮播 -if ($('.trend-topic-swiper').find('li').size() > 1) { - trendTopicSwiper = new Swiper('.trend-topic-swiper', { - loop: true, - autoplay: 3000, - autoplayDisableOnInteraction: false, - paginationClickable: true, - slideElement: 'li', - pagination: '.trend-topic-content .pagination-inner' - }); -} - -// 新人专享轮播 -if ($('.fresh-list-swiper').find('li').size() > 1) { - freshSwiper = new Swiper('.fresh-list-swiper', { - lazyLoading: true, - lazyLoadingInPrevNext: true, - grabCursor: true, - slidesPerView: 'auto', - slideElement: 'li', - watchSlidesVisibility: true - }); -} - -// 潮流上装/经典裤装等轮播 -$('.category-swiper').each(function(i, index) { - swiperClass = 'category-swiper' + i; - $(this).addClass(swiperClass); - if ($('.' + swiperClass).find('.swiper-slide').size() > 1) { - goodsSwiper = new Swiper('.' + swiperClass, { - loop: true, - autoplay: 3000, - autoplayDisableOnInteraction: false, - paginationClickable: true, - slideElement: 'li', - pagination: '.' + swiperClass + ' .pagination-inner' - }); - } -}); - -// logo动画 -function tsAnimate() { - start = start + 10; - $logotrans.css({ - transform: 'rotateX(' + start + 'deg)', - '-webkit-transform': 'rotateX(' + start + 'deg)', - '-moz-transform': 'rotateX(' + start + 'deg)' + $(this).css('background', '#fff'); }); - if (start / 90 % 2 === 1) { - if (isen) { - $logotrans.addClass('animate'); - isen = false; - } else { - $logotrans.removeClass('animate'); - isen = true; - } - } - if (start / 90 % 2 === 0 && start % 360 !== 0) { - window.setTimeout(tsAnimate, 3000); - } else { - if (start % 360 === 0) { - window.setTimeout(tsAnimate, 60 * 1000); - } else { - window.requestAnimationFrame(tsAnimate); - } - } } +changeBackground(); -setTimeout(tsAnimate, 3000); - -$('.home-header .iconfont').on('touchstart', function() { - $(this).addClass('highlight'); -}).on('touchend touchcancel', function() { - $(this).removeClass('highlight'); -}); - -// 底部留出tab 的高度 -window.reMarginFooter('.footer-tab'); - -// set cookie -exports.set = function(c) { - window.setCookie('_Channel', c, { - expires: 365, - domain: '.m.yohobuy.com' - }); -}; - -require("js/home/maybe-like")(); - -}); -define("js/plugin/notice-scroll", ["jquery"], function(require, exports, module){ /** - * 公告栏目滚动 - * bikai kai.bi@yoho.cn + * 增加单条记录 */ - -var $ = require("jquery"); - -function noticeScroll(selecter, time) { - var $notice = $(selecter), - $noticeItem = $notice.find('.notice-item'), - count = $noticeItem.length, - i = 1; - - selecter = selecter || '.notice'; - time = time || 3000; - - if (count > 1) { - setInterval(function() { - if (i >= count) { - i = 0; - } - $noticeItem.fadeOut(); - $notice.find('.item-' + i).fadeIn(); - i++; - }, time); - } +function addHistory(brandName) { + $.ajax({ + type: 'POST', + url: '/brands/addBrandSearch', + data: 'brandName=' + encodeURIComponent(brandName), + success: function(data) { + }, + error: function() { + } + }); } -module.exports = noticeScroll; - -}); -define("js/home/fastclick", [], function(require, exports, module){ -;(function () { - 'use strict'; - - /** - * @preserve FastClick: polyfill to remove click delays on browsers with touch UIs. - * - * @codingstandard ftlabs-jsv2 - * @copyright The Financial Times Limited [All Rights Reserved] - * @license MIT License (see LICENSE.txt) - */ - - /*jslint browser:true, node:true*/ - /*global define, Event, Node*/ - - - /** - * Instantiate fast-clicking listeners on the specified layer. - * - * @constructor - * @param {Element} layer The layer to listen on - * @param {Object} [options={}] The options to override the defaults - */ - function FastClick(layer, options) { - var oldOnClick; - - options = options || {}; - - /** - * Whether a click is currently being tracked. - * - * @type boolean - */ - this.trackingClick = false; - - - /** - * Timestamp for when click tracking started. - * - * @type number - */ - this.trackingClickStart = 0; - - - /** - * The element being tracked for a click. - * - * @type EventTarget - */ - this.targetElement = null; - - - /** - * X-coordinate of touch start event. - * - * @type number - */ - this.touchStartX = 0; - - - /** - * Y-coordinate of touch start event. - * - * @type number - */ - this.touchStartY = 0; +//比较大小 +function sequence(a, b) { + if (a.time > b.time) { + return 1; + } else if (a.time < b.time) { + return -1; + } else { + return 0; + } +} +function searchInput() { + if ($keyword.val().length) { + $icon.css('color', '#444'); - /** - * ID of the last touch, retrieved from Touch.identifier. - * - * @type number - */ - this.lastTouchIdentifier = 0; + // $(this).closest('.search-box').css('width', '11.25rem'); + $searchAction.show().find('.clear-text').show(); + } else { + $icon.css('color', '#b2b2b2'); + // $(this).closest('.search-box').css('width', '12.5rem'); + $searchAction.find('.clear-text').hide(); - /** - * Touchmove boundary, beyond which a click will be cancelled. - * - * @type number - */ - this.touchBoundary = options.touchBoundary || 10; + } + searchResult(); +} +function isLocalStorageSupported() { + var testKey = 'test', + storage = Window.prototype.localStorage; - /** - * The FastClick layer. - * - * @type Element - */ - this.layer = layer; + try { + storage.setItem(testKey, 'testValue'); + storage.removeItem(testKey); + return true; + } catch (error) { + return false; + } +} - /** - * The minimum time between tap(touchstart and touchend) events - * - * @type number - */ - this.tapDelay = options.tapDelay || 200; +//绑定提交前的存local操作 +function bindWriteLocal($brandList, list) { + $brandList.on('click', 'p , li', function(e) { + var brandName, brandId, brandDomain, url; + var a = $(this).find('a'); + var myDate = new Date(); + var query = a.attr('brandName') + ranToken2 + myDate.getTime(), + historys; - /** - * The maximum time for a tap - * - * @type number - */ - this.tapTimeout = options.tapTimeout || 700; + brandName = a.attr('brandName'); - if (FastClick.notNeeded(layer)) { - return; - } + brandId = a.attr('brandId'); - // Some old versions of Android don't have Function.prototype.bind - function bind(method, context) { - return function() { return method.apply(context, arguments); }; - } + brandDomain = a.attr('brandDomain'); + url = a.attr('href'); - var methods = ['onMouse', 'onClick', 'onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel']; - var context = this; - for (var i = 0, l = methods.length; i < l; i++) { - context[methods[i]] = bind(context[methods[i]], context); - } + e.preventDefault(); - // Set up event handlers as required - if (deviceIsAndroid) { - layer.addEventListener('mouseover', this.onMouse, true); - layer.addEventListener('mousedown', this.onMouse, true); - layer.addEventListener('mouseup', this.onMouse, true); - } + if ($netHistory.length > 0) { + addHistory(brandName); - layer.addEventListener('click', this.onClick, true); - layer.addEventListener('touchstart', this.onTouchStart, false); - layer.addEventListener('touchmove', this.onTouchMove, false); - layer.addEventListener('touchend', this.onTouchEnd, false); - layer.addEventListener('touchcancel', this.onTouchCancel, false); + if (list) { + location.href = url; + return; + } - // Hack is required for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2) - // which is how FastClick normally stops click events bubbling to callbacks registered on the FastClick - // layer when they are cancelled. - if (!Event.prototype.stopImmediatePropagation) { - layer.removeEventListener = function(type, callback, capture) { - var rmv = Node.prototype.removeEventListener; - if (type === 'click') { - rmv.call(layer, type, callback.hijacked || callback, capture); - } else { - rmv.call(layer, type, callback, capture); - } - }; + $keyword.val(brandName); + searchInput(); + return; + } - layer.addEventListener = function(type, callback, capture) { - var adv = Node.prototype.addEventListener; - if (type === 'click') { - adv.call(layer, type, callback.hijacked || (callback.hijacked = function(event) { - if (!event.propagationStopped) { - callback(event); - } - }), capture); - } else { - adv.call(layer, type, callback, capture); - } - }; - } + if (localStorage) { + if (isLocalStorageSupported()) { + historys = localStorage.getItem('historys-brand'); + } - // If a handler is already declared in the element's onclick attribute, it will be fired before - // FastClick's onClick handler. Fix this by pulling out the user-defined handler function and - // adding it as listener. - if (typeof layer.onclick === 'function') { + historys = historys ? historys : ''; - // Android browser on at least 3.2 requires a new reference to the function in layer.onclick - // - the old one won't work if passed to addEventListener directly. - oldOnClick = layer.onclick; - layer.addEventListener('click', function(event) { - oldOnClick(event); - }, false); - layer.onclick = null; - } - } + if (historys.indexOf(ranToken + query + ranToken) > -1) { - /** - * Windows Phone 8.1 fakes user agent string to look like Android and iPhone. - * - * @type boolean - */ - var deviceIsWindowsPhone = navigator.userAgent.indexOf("Windows Phone") >= 0; - /** - * Android requires exceptions. - * - * @type boolean - */ - var deviceIsAndroid = navigator.userAgent.indexOf('Android') > 0 && !deviceIsWindowsPhone; + $keyword.val(brandName); + searchInput(); + return; + } + if (historys === '') { + query = ranToken + query; + } - /** - * iOS requires exceptions. - * - * @type boolean - */ - var deviceIsIOS = /iP(ad|hone|od)/.test(navigator.userAgent) && !deviceIsWindowsPhone; + historys += query + ranToken; + if (isLocalStorageSupported()) { + localStorage.setItem('historys-brand', historys); + } + } - /** - * iOS 4 requires an exception for select elements. - * - * @type boolean - */ - var deviceIsIOS4 = deviceIsIOS && (/OS 4_\d(_\d)?/).test(navigator.userAgent); + if (list) { + location.href = url; + return; + } + $keyword.val(brandName); + searchInput(); + }); +} - /** - * iOS 6.0-7.* requires the target element to be manually derived - * - * @type boolean - */ - var deviceIsIOSWithBadTarget = deviceIsIOS && (/OS [6-7]_\d/).test(navigator.userAgent); +function searchResult() { + var keyword = ($keyword.val() + '').toLowerCase(); + var result = {}, + i = 0, + html = ''; - /** - * BlackBerry requires exceptions. - * - * @type boolean - */ - var deviceIsBlackBerry10 = navigator.userAgent.indexOf('BB10') > 0; + if (keyword !== '') { - /** - * Determine whether a given element requires a native click. - * - * @param {EventTarget|Element} target Target DOM element - * @returns {boolean} Returns true if the element needs a native click - */ - FastClick.prototype.needsClick = function(target) { - switch (target.nodeName.toLowerCase()) { + // 遍历首字母搜索 + $.each(brandsData, function(k, v) { + if ($.isArray(v)) { - // Don't send a synthetic click to disabled inputs (issue #62) - case 'button': - case 'select': - case 'textarea': - if (target.disabled) { - return true; - } + // 遍历品牌,进行匹配 + $.each(v, function(i, brand) { + if (brand.searchName.toLowerCase().indexOf(keyword) > -1) { + result[k] = result[k] || []; + result[k].push(brand); + } + }); + } + }); - break; - case 'input': + // 根据搜索结果生成 HTML + $.each(result, function(k, v) { + var brandHtml = ['<div class="brand-list bar-', i, '">']; - // File inputs need real clicks on iOS 6 due to a browser bug (issue #68) - if ((deviceIsIOS && target.type === 'file') || target.disabled) { - return true; - } + i++; + brandHtml.push('<div class="title-bar"><h2>'); + brandHtml.push(k); + brandHtml.push('</h2></div>'); + $.each(v, function(i, brand) { + + brandHtml.push('<p><a href="' + brand.url + '" brandName = "' + brand.name + + '" brandId = "' + brand.brandId + '" brandDomain = "' + brand.brandDomain + '">' + brand.name); + if (brand.isNew) { + brandHtml.push('<i class="icon-new">NEW</i>'); + } + if (brand.isHot) { + brandHtml.push('<i class="icon-hot">HOT</i>'); + } + brandHtml.push('</a></p>'); + }); + brandHtml.push('</div>'); + html += brandHtml.join(''); - break; - case 'label': - case 'iframe': // iOS8 homescreen apps can prevent events bubbling into frames - case 'video': - return true; - } + }); + } - return (/\bneedsclick\b/).test(target.className); - }; + //没填入关键词时显示最热搜索 + if (keyword.length > 0) { + $('.search-brand-page').addClass('hide'); + } else { + $('.search-brand-page').removeClass('hide'); + } + // 插入 dom,绑定事件 + $('.search-result').html(html); + changeBackground(); + bindWriteLocal($('.brand-list'), true); +} - /** - * Determine whether a given element requires a call to focus to simulate click into element. - * - * @param {EventTarget|Element} target Target DOM element - * @returns {boolean} Returns true if the element requires a call to focus to simulate native click. - */ - FastClick.prototype.needsFocus = function(target) { - switch (target.nodeName.toLowerCase()) { - case 'textarea': - return true; - case 'select': - return !deviceIsAndroid; - case 'input': - switch (target.type) { - case 'button': - case 'checkbox': - case 'file': - case 'image': - case 'radio': - case 'submit': - return false; - } +loading.showLoadingMask(); - // No point in attempting to focus disabled inputs - return !target.disabled && !target.readOnly; - default: - return (/\bneedsfocus\b/).test(target.className); - } - }; +lazyLoad($('img.lazy')); +$('.yoho-header').css({ + 'z-index': 2, + position: 'fixed', + top: 0 +}); +$homebuttom.css('top', '47px'); +$homebuttom.css('position', 'fixed'); - /** - * Send a click event to the specified element. - * - * @param {EventTarget|Element} targetElement - * @param {Event} event - */ - FastClick.prototype.sendClick = function(targetElement, event) { - var clickEvent, touch; +$navBtn.on('touchstart', function() { + if ($homebuttom.hasClass('hide')) { + $genderNav.css('top', '47px'); + $newSearch.css('margin-top', '0px'); + $searchPage.css('margin-top', '0px'); + $('.banner-top').css('margin-top', '0px'); + } else { + $genderNav.css('top', '97px'); + $newSearch.css('margin-top', '47px'); + $searchPage.css('margin-top', '47px'); + $('.banner-top').css('margin-top', '47px'); + } +}); - // On some Android devices activeElement needs to be blurred otherwise the synthetic click will have no effect (#24) - if (document.activeElement && document.activeElement !== targetElement) { - document.activeElement.blur(); - } +(function() { + if ($('.banner-top').length > 0) { + $('.hot-brands').css('padding-top', '0'); + } - touch = event.changedTouches[0]; + $('.hide-when-loading').show(); + loading.hideLoadingMask(); - // Synthesise a click event, with an extra attribute so it can be tracked - clickEvent = document.createEvent('MouseEvents'); - clickEvent.initMouseEvent(this.determineEventType(targetElement), true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null); - clickEvent.forwardedTouchEvent = true; - targetElement.dispatchEvent(clickEvent); - }; + //banner滑动 + swiper = new Swiper('.swiper-container', { + lazyLoading: true, + loop: true, + autoplay: 3000, + pagination: '.swiper-pagination .pagination-inner' + }); - FastClick.prototype.determineEventType = function(targetElement) { + //热门品牌滑动 + hotBrandsSwiper = new Swiper('.brands-swiper', { + grabCursor: true, + slidesPerView: 'auto', + wrapperClass: 'brands-list', + slideElement: 'li' + }); +})(); + +$fixTitleBar = $('<div class="title-bar fixed-title-bar"><h2></h2></div>'); +$fixTitleBar.css({ + position: 'fixed', + top: brandSwipe +}).hide(); +minBrandListTop = brandSwipe + $('.hot-brands').outerHeight() + $('.banner-top').outerHeight(); +$brandList.last().append($fixTitleBar); - //Issue #159: Android Chrome Select Box does not open with a synthetic click event - if (deviceIsAndroid && targetElement.tagName.toLowerCase() === 'select') { - return 'mousedown'; - } +function scrollHandler() { + var scrTop = $(window).scrollTop(); - return 'click'; - }; + if ($brandList.eq(0).offset().top < minBrandListTop) { + $fixTitleBar.hide(); + } + $brandList.each(function() { + var offTop = $(this).offset().top - brandSwipe; - /** - * @param {EventTarget|Element} targetElement - */ - FastClick.prototype.focus = function(targetElement) { - var length; + if (scrTop >= offTop) { + $fixTitleBar.css({ + display: 'block' + }).find('h2').html($(this).find('.title-bar').text()); + } - // Issue #160: on iOS 7, some input elements (e.g. date datetime month) throw a vague TypeError on setSelectionRange. These elements don't have an integer value for the selectionStart and selectionEnd properties, but unfortunately that can't be used for detection because accessing the properties also throws a TypeError. Just check the type instead. Filed as Apple bug #15122724. - if (deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month') { - length = targetElement.value.length; - targetElement.setSelectionRange(length, length); - } else { - targetElement.focus(); - } - }; + }); +} +if ($('.brand-index-page').length > 0) { + /** + * srcoll to load more + */ + $(window).scroll(function() { + window.requestAnimationFrame(scrollHandler); + }); +} - /** - * Check whether the given target element is a child of a scrollable layer and if so, set a flag on it. - * - * @param {EventTarget|Element} targetElement - */ - FastClick.prototype.updateScrollParent = function(targetElement) { - var scrollParent, parentElement; - scrollParent = targetElement.fastClickScrollParent; +if ($('.history-search').length > 0) { + bindWriteLocal($('.history-search'), false); +} - // Attempt to discover whether the target element is contained within a scrollable layer. Re-check if the - // target element was moved to another parent. - if (!scrollParent || !scrollParent.contains(targetElement)) { - parentElement = targetElement; - do { - if (parentElement.scrollHeight > parentElement.offsetHeight) { - scrollParent = parentElement; - targetElement.fastClickScrollParent = parentElement; - break; - } +if ($('.hot-search').length > 0) { + bindWriteLocal($('.hot-search'), false); +} - parentElement = parentElement.parentElement; - } while (parentElement); - } +if ($('.brand-search-page').length > 0) { + brandsData = $.parseJSON($('#brands-data').html()); - // Always update the scroll top tracker if possible. - if (scrollParent) { - scrollParent.fastClickLastScrollTop = scrollParent.scrollTop; - } - }; + $keyword.on('input', function() { + searchInput(); + }); + // 2016.1.13 产品(高扬)要求进入页面默认显示取消按钮 + $icon.css('color', '#444'); + $keyword.closest('.search-box').css('width', '11.25rem'); + $searchAction.show().find('.clear-text').hide(); - /** - * @param {EventTarget} targetElement - * @returns {Element|EventTarget} - */ - FastClick.prototype.getTargetElementFromEventTarget = function(eventTarget) { + clearTextHammer = new Hammer($('.clear-text')[0]); + clearTextHammer.on('tap', function(e) { + $('.search-result').html(''); + $('#keyword').val('').trigger('input'); + e.preventDefault(); + e.srcEvent.stopPropagation(); + }); - // On some older browsers (notably Safari on iOS 4.1 - see issue #56) the event target may be a text node. - if (eventTarget.nodeType === Node.TEXT_NODE) { - return eventTarget.parentNode; - } + $('form.search-box').on('submit', function() { + return false; + }); - return eventTarget; - }; +} +if ($genderItem.length > 0) { + $genderItem.on('touchstart', function() { + var index = $(this).data('id') + 1; - /** - * On touch start, record the position and scroll offset. - * - * @param {Event} event - * @returns {boolean} - */ - FastClick.prototype.onTouchStart = function(event) { - var targetElement, touch, selection; + $('.genderNav ul .active').removeClass('active'); + $(this).addClass('active'); + $('.hide-when-loading').hide(); + loading.showLoadingMask(); + function reload() { + window.location.search = 'channel=' + index; + } + setTimeout(reload.bind(this), 100); + }); +} - // Ignore multiple touches, otherwise pinch-to-zoom is prevented if both fingers are on the FastClick element (issue #111). - if (event.targetTouches.length > 1) { - return true; - } +if ($brandItem.length > 0) { + $brandItem.on('click', function() { + var index = $(this).data('id'); - targetElement = this.getTargetElementFromEventTarget(event.target); - touch = event.targetTouches[0]; + $('.brandNav ul .active').removeClass('active'); + $(this).addClass('active'); - if (deviceIsIOS) { - // Only trusted events will deselect text on iOS (issue #49) - selection = window.getSelection(); - if (selection.rangeCount && !selection.isCollapsed) { - return true; - } + if (index === 0) { - if (!deviceIsIOS4) { + $recommandBrandWall.not('.hide').addClass('hide'); + $newBrandWall.not('.hide').addClass('hide'); + $brandList.removeClass('hide'); - // Weird things happen on iOS when an alert or confirm dialog is opened from a click event callback (issue #23): - // when the user next taps anywhere else on the page, new touchstart and touchend events are dispatched - // with the same identifier as the touch event that previously triggered the click that triggered the alert. - // Sadly, there is an issue on iOS 4 that causes some normal touch events to have the same identifier as an - // immediately preceeding touch event (issue #52), so this fix is unavailable on that platform. - // Issue 120: touch.identifier is 0 when Chrome dev tools 'Emulate touch events' is set with an iOS device UA string, - // which causes all touch events to be ignored. As this block only applies to iOS, and iOS identifiers are always long, - // random integers, it's safe to to continue if the identifier is 0 here. - if (touch.identifier && touch.identifier === this.lastTouchIdentifier) { - event.preventDefault(); - return false; - } + } else if (index === 1) { - this.lastTouchIdentifier = touch.identifier; + $newBrandWall.removeClass('hide'); + $brandList.not('.hide').addClass('hide'); + $recommandBrandWall.not('.hide').addClass('hide'); - // If the target element is a child of a scrollable layer (using -webkit-overflow-scrolling: touch) and: - // 1) the user does a fling scroll on the scrollable layer - // 2) the user stops the fling scroll with another tap - // then the event.target of the last 'touchend' event will be the element that was under the user's finger - // when the fling scroll was started, causing FastClick to send a click event to that layer - unless a check - // is made to ensure that a parent layer was not scrolled before sending a synthetic click (issue #42). - this.updateScrollParent(targetElement); - } - } + } else { - this.trackingClick = true; - this.trackingClickStart = event.timeStamp; - this.targetElement = targetElement; + $recommandBrandWall.removeClass('hide'); + $brandList.not('.hide').addClass('hide'); + $newBrandWall.not('.hide').addClass('hide'); - this.touchStartX = touch.pageX; - this.touchStartY = touch.pageY; + } - // Prevent phantom clicks on fast double-tap (issue #36) - if ((event.timeStamp - this.lastClickTime) < this.tapDelay) { - event.preventDefault(); - } + }); +} - return true; - }; +/** + * 清除记录 + */ +function removeHistory() { + $.ajax({ + type: 'GET', + url: '/brands/delBrandHistory', + data: '', + success: function(data) { + }, + error: function() { + } + }); +} +//初始化历史搜索的内容 - /** - * Based on a touchmove event object, check whether the touch has moved past a boundary since it started. - * - * @param {Event} event - * @returns {boolean} - */ - FastClick.prototype.touchHasMoved = function(event) { - var touch = event.changedTouches[0], boundary = this.touchBoundary; +if ($('.brand-search-page').length > 0) { - if (Math.abs(touch.pageX - this.touchStartX) > boundary || Math.abs(touch.pageY - this.touchStartY) > boundary) { - return true; - } + chHammer = new Hammer($clearHistory[0]); + chHammer.on('tap', function() { + if (isLocalStorageSupported()) { + localStorage.removeItem('historys-brand'); + } + $history.html(''); + $historySearch.hide(); + $clearHistory.hide(); - return false; - }; + if ($('.net-search').length > 0) { + removeHistory(); + } + window.rePosFooter(); + }); - /** - * Update the last position. - * - * @param {Event} event - * @returns {boolean} - */ - FastClick.prototype.onTouchMove = function(event) { - if (!this.trackingClick) { - return true; - } + //搜索页面 + + (function() { + var html = '', + history, + historys, i, + localHistory, + brand,data, + time,netArr,dict,dictc,localArr, + combinArr,key,date,temp; + + localArr = []; + combinArr = []; + netArr = []; + + $netHistory.find('li').each(function() { + + brand = $(this).find('a').attr('brandName'); + time = $(this).find('a').attr('collectTime'); + dict = { + brand: brand, + time: time + },dictc,dict; + netArr.push(dict); + }); - // If the touch has moved, cancel the click tracking - if (this.targetElement !== this.getTargetElementFromEventTarget(event.target) || this.touchHasMoved(event)) { - this.trackingClick = false; - this.targetElement = null; - } - return true; - }; + if (localStorage) { + if (isLocalStorageSupported()) { + historys = localStorage.getItem('historys-brand'); + } + if (historys && historys.length > 0) { + historys = historys.split(ranToken); + for (i = historys.length; i > 0; i--) { + history = historys[i - 1]; - /** - * Attempt to find the labelled control for the given label element. - * - * @param {EventTarget|HTMLLabelElement} labelElement - * @returns {Element|null} - */ - FastClick.prototype.findControl = function(labelElement) { + if (history === '') { + continue; + } + localHistory = history.split(ranToken2); - // Fast path for newer browsers supporting the HTML5 control attribute - if (labelElement.control !== undefined) { - return labelElement.control; - } + brand = localHistory[0]; + time = localHistory[1]; - // All browsers under test that support touch events also support the HTML5 htmlFor attribute - if (labelElement.htmlFor) { - return document.getElementById(labelElement.htmlFor); - } + dict = { + brand: brand, + time: time + }; - // If no for attribute exists, attempt to retrieve the first labellable descendant element - // the list of which is defined here: http://www.w3.org/TR/html5/forms.html#category-label - return labelElement.querySelector('button, input:not([type=hidden]), keygen, meter, output, progress, select, textarea'); - }; + localArr.push(dict); + } + } + } - /** - * On touch end, determine whether to send a click event at once. - * - * @param {Event} event - * @returns {boolean} - */ - FastClick.prototype.onTouchEnd = function(event) { - var forElement, trackingClickStart, targetTagName, scrollParent, touch, targetElement = this.targetElement; + if (localArr.length === 0 && netArr.length === 0) { + $historySearch.addClass('hide'); + return; + } - if (!this.trackingClick) { - return true; - } - // Prevent phantom clicks on fast double-tap (issue #36) - if ((event.timeStamp - this.lastClickTime) < this.tapDelay) { - this.cancelNextClick = true; - return true; - } + date = {}; + temp = {}; + if (localArr.length > 0) { + for (dictc in localArr) { + if (localArr.hasOwnProperty(dictc)) { + temp = localArr[dictc]; + if (!date[temp.brand] || date[temp.brand] < temp.time) { + date[temp.brand] = temp.time; + } + } + } + } - if ((event.timeStamp - this.trackingClickStart) > this.tapTimeout) { - return true; - } + if (netArr.length > 0) { + for (dict in netArr) { + if (netArr.hasOwnProperty(dict)) { + temp = netArr[dict]; + if (!date[temp.brand] || date[temp.brand] < temp.time) { + date[temp.brand] = temp.time; + } + } + } + } - // Reset to prevent wrong click cancel on input (issue #156). - this.cancelNextClick = false; + data = {}; + for (key in date) { + if (date.hasOwnProperty(key)) { + data = { + brand: key, + time: date[key] + }; + combinArr.push(data); + } + } - this.lastClickTime = event.timeStamp; + combinArr.sort(sequence); - trackingClickStart = this.trackingClickStart; - this.trackingClick = false; - this.trackingClickStart = 0; + if (combinArr.length > 0) { + for (i = combinArr.length - 1; i >= ((combinArr.length > 10) ? (combinArr.length - 10) : 0); i--) { - // On some iOS devices, the targetElement supplied with the event is invalid if the layer - // is performing a transition or scroll, and has to be re-detected manually. Note that - // for this to function correctly, it must be called *after* the event target is checked! - // See issue #57; also filed as rdar://13048589 . - if (deviceIsIOSWithBadTarget) { - touch = event.changedTouches[0]; + brand = combinArr[i].brand; + time = combinArr[i].time; - // In certain cases arguments of elementFromPoint can be negative, so prevent setting targetElement to null - targetElement = document.elementFromPoint(touch.pageX - window.pageXOffset, touch.pageY - window.pageYOffset) || targetElement; - targetElement.fastClickScrollParent = this.targetElement.fastClickScrollParent; - } + html += '<li><a brandName = "' + brand + + '">' + brand + '</li>'; + $history.removeClass('hide'); - targetTagName = targetElement.tagName.toLowerCase(); - if (targetTagName === 'label') { - forElement = this.findControl(targetElement); - if (forElement) { - this.focus(targetElement); - if (deviceIsAndroid) { - return false; - } + $history.html(html); + $clearHistory.removeClass('hide'); - targetElement = forElement; - } - } else if (this.needsFocus(targetElement)) { + $hotSearch.removeClass('hide'); + window.rePosFooter(); - // Case 1: If the touch started a while ago (best guess is 100ms based on tests for issue #36) then focus will be triggered anyway. Return early and unset the target element reference so that the subsequent click will be allowed through. - // Case 2: Without this exception for input elements tapped when the document is contained in an iframe, then any inputted text won't be visible even though the value attribute is updated as the user types (issue #37). - if ((event.timeStamp - trackingClickStart) > 100 || (deviceIsIOS && window.top !== window && targetTagName === 'input')) { - this.targetElement = null; - return false; - } + } + } else { + $history.addClass('hide'); + } - this.focus(targetElement); - this.sendClick(targetElement, event); + }()); - // Select elements need the event to go through on iOS 4, otherwise the selector menu won't open. - // Also this breaks opening selects when VoiceOver is active on iOS6, iOS7 (and possibly others) - if (!deviceIsIOS || targetTagName !== 'select') { - this.targetElement = null; - event.preventDefault(); - } +} + +}); +define("js/plugin/loading", ["jquery"], function(require, exports, module){ +/** + * Loading mask + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/29 + */ - return false; - } +var $ = require("jquery"); - if (deviceIsIOS && !deviceIsIOS4) { +var $page = $('.yoho-page'); - // Don't send a synthetic click event if the target element is contained within a parent layer that was scrolled - // and this tap is being used to stop the scrolling (usually initiated by a fling - issue #42). - scrollParent = targetElement.fastClickScrollParent; - if (scrollParent && scrollParent.fastClickLastScrollTop !== scrollParent.scrollTop) { - return true; - } - } +var $loading, + hasInit = false; - // Prevent the actual click from going though - unless the target node is marked as requiring - // real clicks or if it is in the whitelist in which case only non-programmatic clicks are permitted. - if (!this.needsClick(targetElement)) { - event.preventDefault(); - this.sendClick(targetElement, event); - } +/** modify by liangzhifeng at 2015.11.2 */ - return false; - }; +// 初始化 +function init($container) { + var html = '<div class="loading-mask hide">' + + '<div class="loading">' + + '<div></div><div></div><div></div>' + + '</div>' + + '</div>'; + hasInit = true; + if ($container === undefined) { + $container = $page; + } - /** - * On touch cancel, stop tracking the click. - * - * @returns {void} - */ - FastClick.prototype.onTouchCancel = function() { - this.trackingClick = false; - this.targetElement = null; - }; + $container.append(html); + $loading = $container.children('.loading-mask'); +} - /** - * Determine mouse events which should be permitted. - * - * @param {Event} event - * @returns {boolean} - */ - FastClick.prototype.onMouse = function(event) { +//显示loading +function showLoadingMask() { + if (!hasInit) { + init(); + hasInit = true; + } + $loading.removeClass('hide'); +} - // If a target element was never set (because a touch event was never fired) allow the event - if (!this.targetElement) { - return true; - } +//隐藏loading +function hideLoadingMask() { + $loading.addClass('hide'); +} - if (event.forwardedTouchEvent) { - return true; - } +exports.init = init; +exports.showLoadingMask = showLoadingMask; +exports.hideLoadingMask = hideLoadingMask; +}); +define("js/guang/entry", ["jquery","lazyload","swiper","hammer","mlellipsis","iscroll-probe","index"], function(require, exports, module){ +/** + * 逛打包入口 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/9 + */ - // Programmatically generated events targeting a specific element should be permitted - if (!event.cancelable) { - return true; - } +require("js/guang/plus-star/list"); +require("js/guang/plus-star/detail"); - // Derive and check the target element to see whether the mouse event needs to be permitted; - // unless explicitly enabled, prevent non-touch click events from triggering actions, - // to prevent ghost/doubleclicks. - if (!this.needsClick(this.targetElement) || this.cancelNextClick) { +require("js/guang/home"); +require("js/guang/list"); +require("js/guang/detail"); +require("js/guang/star-classroom"); +require("js/guang/calendar"); +require("js/guang/collocation-list"); +require("js/guang/check-top"); +}); +define("js/guang/plus-star/list", ["jquery","lazyload","swiper","index"], function(require, exports, module){ +/** + * PLUS+STAR列表页 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/10 + */ - // Prevent any user-added listeners declared on FastClick element from being fired. - if (event.stopImmediatePropagation) { - event.stopImmediatePropagation(); - } else { +var $ = require("jquery"), + lazyLoad = require("lazyload"), + Swiper = require("swiper"); - // Part of the hack for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2) - event.propagationStopped = true; - } +var $navs = $('#nav-tab > li'), + $contents = $('#ps-content > .content'); - // Cancel the event - event.stopPropagation(); - event.preventDefault(); +var mySwiper; - return false; - } +lazyLoad($('img.lazy')); - // If the mouse event is permitted, return true for the action to go through. - return true; - }; +$('.star-content li').each(function(key, item) { + $(item).find('.swiper-container').addClass('swiper-' + key); + mySwiper = new Swiper('.swiper-' + key, { + lazyLoading: true, + pagination: '.swiper-' + key + ' .pagination-inner' + }); +}); - /** - * On actual clicks, determine whether this is a touch-generated click, a click action occurring - * naturally after a delay after a touch (which needs to be cancelled to avoid duplication), or - * an actual click which should be permitted. - * - * @param {Event} event - * @returns {boolean} - */ - FastClick.prototype.onClick = function(event) { - var permitted; +$('#nav-tab').bind('contextmenu', function(e) { + return false; +}); +$('#nav-tab').on('touchend touchcancel', function(e) { + var $this = $(e.target).closest('li'); - // It's possible for another FastClick-like library delivered with third-party code to fire a click event before FastClick does (issue #44). In that case, set the click-tracking flag back to false and return early. This will cause onTouchEnd to return early. - if (this.trackingClick) { - this.targetElement = null; - this.trackingClick = false; - return true; - } + if ($this.hasClass('focus')) { + return; + } - // Very odd behaviour on iOS (issue #18): if a submit element is present inside a form and the user hits enter in the iOS simulator or clicks the Go button on the pop-up OS keyboard the a kind of 'fake' click event will be triggered with the submit-type input element as the target. - if (event.target.type === 'submit' && event.detail === 0) { - return true; - } + $navs.toggleClass('focus'); + $contents.toggleClass('hide'); - permitted = this.onMouse(event); + $(document).trigger('scroll'); //Trigger lazyLoad +}); +$('#nav-tab').on('touchstart', function(e) { + var target = e.target || e.srcElement; - // Only unset targetElement if the click is not permitted. This will ensure that the check for !targetElement in onMouse fails and the browser's click doesn't go through. - if (!permitted) { - this.targetElement = null; - } + target.className = 'bytouch ' + target.className; +}).on('touchend touchcancel', function() { + $navs.removeClass('bytouch'); +}); +}); +define("js/guang/plus-star/detail", ["jquery","hammer","mlellipsis","lazyload","swiper","index"], function(require, exports, module){ +/** + * PLUS+STAR详情页 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/10 + */ - // If clicks are permitted, return true for the action to go through. - return permitted; - }; +var $ = require("jquery"), + Hammer = require("hammer"), + ellipsis = require("mlellipsis"), + lazyLoad = require("lazyload"); +var $intro = $('#intro'), + $imt = $('#intro-more-txt'), + $infosContainer = $('#related-infos-container'); - /** - * Remove all FastClick's event listeners. - * - * @returns {void} - */ - FastClick.prototype.destroy = function() { - var layer = this.layer; +var info = require("js/guang/info"); - if (deviceIsAndroid) { - layer.removeEventListener('mouseover', this.onMouse, true); - layer.removeEventListener('mousedown', this.onMouse, true); - layer.removeEventListener('mouseup', this.onMouse, true); - } +var tip = require("js/plugin/tip"); - layer.removeEventListener('click', this.onClick, true); - layer.removeEventListener('touchstart', this.onTouchStart, false); - layer.removeEventListener('touchmove', this.onTouchMove, false); - layer.removeEventListener('touchend', this.onTouchEnd, false); - layer.removeEventListener('touchcancel', this.onTouchCancel, false); - }; +var brandId = $('#brand-info').data('id'); +var jumpToApp = $('#jump-to-app').val(); - /** - * Check whether FastClick is needed. - * - * @param {Element} layer The layer to listen on - */ - FastClick.notNeeded = function(layer) { - var metaViewport; - var chromeVersion; - var blackberryVersion; - var firefoxVersion; +var mIntro, aIntro; - // Devices that don't support touch don't need FastClick - if (typeof window.ontouchstart === 'undefined') { - return true; - } +var moreHammer, likeHammer, $goodName, $title; - // Chrome version - zero for other browsers - chromeVersion = +(/Chrome\/([0-9]+)/.exec(navigator.userAgent) || [,0])[1]; +require("js/plugin/wx-share"); - if (chromeVersion) { +ellipsis.init(); - if (deviceIsAndroid) { - metaViewport = document.querySelector('meta[name=viewport]'); +//Init LazyLoad +lazyLoad($('img.lazy')); - if (metaViewport) { - // Chrome on Android with user-scalable="no" doesn't need FastClick (issue #89) - if (metaViewport.content.indexOf('user-scalable=no') !== -1) { - return true; - } - // Chrome 32 and above with width=device-width or less don't need FastClick - if (chromeVersion > 31 && document.documentElement.scrollWidth <= window.outerWidth) { - return true; - } - } +if ($('.good-detail-text .name').length > 0) { + $('.good-detail-text .name').each(function() { + $goodName = $(this); + $title = $goodName.find('a'); - // Chrome desktop doesn't need FastClick (issue #15) - } else { - return true; - } - } + $title[0].mlellipsis(2); + }); +} - if (deviceIsBlackBerry10) { - blackberryVersion = navigator.userAgent.match(/Version\/([0-9]*)\.([0-9]*)/); +//文字介绍文字截取 +$intro[0].mlellipsis(3); - // BlackBerry 10.3+ does not require Fastclick library. - // https://github.com/ftlabs/fastclick/issues/251 - if (blackberryVersion[1] >= 10 && blackberryVersion[2] >= 3) { - metaViewport = document.querySelector('meta[name=viewport]'); +//获取截取文字和完整文字 +setTimeout(function() { + mIntro = $intro.text(); + aIntro = $intro.attr('title'); +}); - if (metaViewport) { - // user-scalable=no eliminates click delay. - if (metaViewport.content.indexOf('user-scalable=no') !== -1) { - return true; - } - // width=device-width (or less than device-width) eliminates click delay. - if (document.documentElement.scrollWidth <= window.outerWidth) { - return true; - } - } - } - } +info.initInfosEvt($infosContainer); - // IE10 with -ms-touch-action: none or manipulation, which disables double-tap-to-zoom (issue #97) - if (layer.style.msTouchAction === 'none' || layer.style.touchAction === 'manipulation') { - return true; - } +//文字介绍收起与展开 +moreHammer = new Hammer(document.getElementById('more-intro-click-range')); +moreHammer.on('tap', function(e) { + var $this = $imt.parent(); - // Firefox version - zero for other browsers - firefoxVersion = +(/Firefox\/([0-9]+)/.exec(navigator.userAgent) || [,0])[1]; + $this.toggleClass('spread'); - if (firefoxVersion >= 27) { - // Firefox 27+ does not have tap delay if the content is not zoomable - https://bugzilla.mozilla.org/show_bug.cgi?id=922896 + if ($this.hasClass('spread')) { - metaViewport = document.querySelector('meta[name=viewport]'); - if (metaViewport && (metaViewport.content.indexOf('user-scalable=no') !== -1 || document.documentElement.scrollWidth <= window.outerWidth)) { - return true; - } - } + //显示 + $intro.text(aIntro); + $imt.text('收起'); + } else { - // IE11: prefixed -ms-touch-action is no longer supported and it's recomended to use non-prefixed version - // http://msdn.microsoft.com/en-us/library/windows/apps/Hh767313.aspx - if (layer.style.touchAction === 'none' || layer.style.touchAction === 'manipulation') { - return true; - } + //隐藏 + $intro.text(mIntro); + $imt.text('more'); - return false; - }; + $(window).scrollTop(0, 400); //滑动到顶部 + } + e.preventDefault(); //防止收缩后误点到商品产生跳转 +}); - /** - * Factory method for creating a FastClick object - * - * @param {Element} layer The layer to listen on - * @param {Object} [options={}] The options to override the defaults - */ - FastClick.attach = function(layer, options) { - return new FastClick(layer, options); - }; +//品牌收藏 +likeHammer = new Hammer(document.getElementById('brand-like')); +likeHammer.on('tap', function(e) { + var opt = 'ok', + $this = $(e.target); - if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) { + //jumpToApp = 1表示APP未登录的情况,此时不发送ajax请求而由a链接直接跳转APP + if (jumpToApp === '1') { + return; + } - // AMD. Register as an anonymous module. - define(function() { - return FastClick; - }); - } else if (typeof module !== 'undefined' && module.exports) { - module.exports = FastClick.attach; - module.exports.FastClick = FastClick; - } else { - window.FastClick = FastClick; - } -}()); - + e.preventDefault(); + + if ($this.hasClass('like')) { + opt = 'cancel'; + } + + $.ajax({ + type: 'POST', + url: '/guang/opt/favoriteBrand', + data: { + id: brandId, + opt: opt + }, + success: function(data) { + if (data.code === 200) { + $this.toggleClass('like'); + tip.show(data.message); + } else if (data.code === 400 || data.code === 412) { + location.href = data.data; //未登录跳转登录页面 + } else { + tip.show(data.message); + } + }, + error: function() { + tip.show('网络断开连接了~'); + } + }); }); -define("js/home/maybe-like", ["jquery","hammer","mlellipsis","lazyload"], function(require, exports, module){ +}); +define("js/guang/info", ["jquery","hammer","mlellipsis","lazyload","swiper","index"], function(require, exports, module){ /** - * “你可能喜欢”模块JS - * @author: liangzhifeng<zhifeng.liang@yoho.cn> - * @date: 2015/10/12 + * 资讯相关API + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/10 */ -module.exports = function(specificGender) { - var $ = require("jquery"), - Hammer = require("hammer"), - tip = require("js/plugin/tip"), - loading = require("js/plugin/loading"), - ellipsis = require("mlellipsis"), - lazyLoad = require("lazyload"); +var $ = require("jquery"), + Hammer = require("hammer"), + ellipsis = require("mlellipsis"), + lazyLoad = require("lazyload"), + Swiper = require("swiper"); - var navHammer, - winH = $(window).height(), - $goodList = $('#goods-list'), - searching = false, - page = 0, - gender = null, - num, - url, - RECPOSE = '110001'; +var tip = require("js/plugin/tip"); +var loading = require("js/plugin/loading"); - //The kidsType can be specified by the parameter. Add by @ZhaoBiao - var kidsType = specificGender === 'kids' || $('.mobile-wrap').hasClass('kids-wrap') ? true : false, - lifestyleType = specificGender === 'lifestyle' || - $('.mobile-wrap').hasClass('lifestyle-wrap') ? true : false, - yohoCoinType = $('.coin').length ? true : false, - logisticType = $('.logistic-page').length ? true : false; - var $curNav, - index, - $navList = $('#maybe-like-nav'); +var $loadMoreInfo = $('#load-more-info'); +var $loading = $(''), + $noMore = $(''), + $swiper = $(''); - var $footer; +var searching = false; +var mySwiper = {}; + +var isLoading = false; + +ellipsis.init(); + +if ($loadMoreInfo.length > 0) { + $loading = $loadMoreInfo.children('.loading'); + $noMore = $loadMoreInfo.children('.no-more'); +} + +// 获取url中的参数 +function getUrlParam(name) { + + // 构造一个含有目标参数的正则表达式对象 + var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)'); + + // 匹配目标参数 + var r = window.location.search.substr(1).match(reg); + + // 返回参数值 + if (r != null) { + return r[2]; + } + + return null; +} + +//初始化swiper +function initSwiper(typeId) { + if (typeof typeId === undefined) { + return; + } + mySwiper[typeId] = new Swiper('.swiper-cont-' + typeId, { + lazyLoading: true, + wrapperClass: 'swiper-wrap-' + typeId, + pagination: '.swiper-pagi-' + typeId, + autoplay: 3000 + }); +} + +/** + * 设置指定资讯项的Lazyload和文字截取 + * @params $infos 资讯项 + */ +function setLazyLoadAndMellipsis($infos) { + lazyLoad($infos.find('img.lazy')); + + $infos.each(function() { + var $this = $(this), + $title = $this.find('.info-title'), + $text = $this.find('.info-text'); + + $title[0].mlellipsis(2); + $text[0].mlellipsis(2); + }); +} + +/** + * 初始化资讯列表事件绑定 + * @params $container 逛资讯列表容器 + */ +function initInfosEvt($container) { + var cHammer; + + if (typeof $container === 'undefined') { + return; + } + if (typeof $container[0] === 'undefined') { + return; + } + cHammer = new Hammer($container[0]); + + //点赞或者收藏事件 + cHammer.on('tap', function(e) { + var $this = $(e.target), + opt = 'ok', + $btn, + $info, + yhChannel; + + //e.preventDefault(); + + //点赞 + $btn = $this.closest('.like-btn'); + if ($btn.length > 0 && !isLoading) { + e.preventDefault(); + if ($btn.hasClass('like')) { + opt = 'cancel'; + } + + $info = $this.closest('.guang-info'); + + isLoading = true; + + $.ajax({ + type: 'POST', + url: '/guang/opt/praiseArticle', + data: { + id: $info.data('id'), + opt: opt + }, + success: function(data) { + var code = data.code; + + + if (code === 200) { + $btn.next('.like-count').text(data.data); + + //切换点赞状态 + $btn.toggleClass('like'); + } + }, + error: function() { + tip.show('网络断开连接了~'); + }, + complete: function() { + isLoading = false; + } + }); + return; + } + + //APP收藏 + $btn = $this.closest('.collect-btn'); + if ($btn.length > 0) { + e.preventDefault(); + if ($btn.hasClass('collected')) { + opt = 'cancel'; + } - ellipsis.init(); + $info = $this.closest('.guang-info'); - //ajax url - if (kidsType) { - - url = '/product/recom/maylikekids'; - } else if (lifestyleType) { + if (getUrlParam('yh_channel')) { + yhChannel = getUrlParam('yh_channel'); + } - //有货币页面加载男生首页的数据 - url = specificGender === 'lifestyle' ? '/product/recom/maylike?gender=1,3&rec_pos=100001' : '/product/recom/maylikelife'; - } else if (yohoCoinType) { + $.ajax({ + type: 'POST', + url: '/guang/opt/collectArticle', + data: { + id: $info.data('id'), + opt: opt, + yh_channel: yhChannel, + uid: getUrlParam('uid') + }, + success: function(data) { + if (data.code && data.code === 200) { - gender = (specificGender === 'boys' || $('.mobile-wrap').hasClass('boys-wrap')) ? - '1,3&rec_pos=100009' : '2,3&rec_pos=100009', - url = '/product/recom/maylike?gender=' + gender; - RECPOSE = 110009; + //切换收藏状态 + $btn.toggleClass('collected'); + } + }, + error: function() { + tip.show('网络断开连接了~'); + } + }); + } + }); - } else if (logisticType) { //物流页面 - gender = (specificGender === 'boys' || $('.mobile-wrap').hasClass('boys-wrap')) ? - '1,3&rec_pos=100006' : '2,3&rec_pos=100006', - url = '/product/recom/maylike?gender=' + gender; - RECPOSE = 110006; + setLazyLoadAndMellipsis($container.find('.guang-info')); +} - } else { - gender = (specificGender === 'boys' || $('.mobile-wrap').hasClass('boys-wrap')) ? - '1,3&rec_pos=100001' : '2,3&rec_pos=100002', - url = '/product/recom/maylike?gender=' + gender; - } +/** + * 资讯LoadMore + * @param $container 资讯容器 jqyeryObject + * @param opt 请求参数 + * @param url[可选], 扩展请求的url而不使用默认值 + */ +function loadMore($container, opt, url) { + var num; - //日韩馆-你可能喜欢的 - if ($('.mobile-wrap').hasClass('yoho-channel-page')) { - url = '/product/recom/newPreference?template_id=' + $.queryString().template_id; + if (searching) { + return; } - //首页男生和女生,推荐位ID,埋点 - if (window.location.pathname === '/boys') { - RECPOSE = 110001; - } else if (window.location.pathname === '/girls') { - RECPOSE = 110002; + if (opt.end) { + return; } - $curNav = $navList.children('.focus'); - - if (lifestyleType) { - navHammer = $navList[0] ? new Hammer($navList[0]) : undefined; - if (navHammer) { - navHammer.on('tap', function(e) { - var $this = $(e.target).closest('li'), - $goods = $('.goods-list'), - $content; - - e.preventDefault(); - if ($this.hasClass('focus')) { - return; - } - - index = $this.index(); + if (opt.page === 1) { - $this.addClass('focus'); - $curNav.removeClass('focus'); + //显示loading + loading.showLoadingMask(); + } - $goods.not('.hide').addClass('hide'); - $content = $goods.eq(index); - $content.removeClass('hide'); + num = $container.find('.guang-info').length; + searching = true; + $.ajax({ + type: 'GET', + url: url ? url : '/guang/index/page',//对于指定url的使用指定url(存在不同的控制器) + data: opt, + success: function(data) { + var $newItems; - $curNav = $this; + if (data === ' ') { + opt.end = true; + searching = false; - $(document).trigger('scroll'); //Trigger lazyLoad - e.srcEvent.stopPropagation(); - }); - } - } + // + $loading.addClass('hide'); + $noMore.removeClass('hide'); - loading.init($('.maybe-like')); + return; + } - function search() { - if (searching) { - return; - } - searching = true; + $container.append(data); - loading.showLoadingMask(); + $swiper = $container.find('.swiper-container'); + if ($swiper.length) { + $swiper.addClass('swiper-cont-' + opt.type); + $swiper.children('.swiper-wrapper').addClass('swiper-wrap-' + opt.type); + $swiper.children('.swiper-pagination').addClass('swiper-pagi-' + opt.type); + initSwiper(opt.type); + } - //num = $goodList.find('.good-info').length; - $.ajax({ - type: 'GET', - url: url, - data: { - page: page + 1 - }, - success: function(data) { - var PRDID = []; - if (data === ' ') { - searching = false; - loading.hideLoadingMask(); + if (num > 0) { + $newItems = $container.find('.guang-info:gt(' + (num - 1) + ')'); + } else { + $newItems = $container.find('.guang-info'); + } - // 有货币页面不加载底部 - if (gender && !specificGender) { - if (gender === '1,3') { - url = '/boys/bottomBanner'; - } else { - url = '/girls/bottomBanner'; - } - $.ajax({ - type: 'GET', - url: url, - success: function(data) { - if (data && data.img) { - $('#load-more-img').show(); - $('#load-more-img a').attr('href', data.url); - $('#load-more-img a > img').attr('src', data.img); - } - }, - error: function() { - } - }); + setLazyLoadAndMellipsis($newItems); - } - return; - } + if (opt.page === 1) { + loading.hideLoadingMask(); - //加载到数据后,去除bottom样式,使得footer能够随着页面长度的增加改变位置 - if (data.length > 1) { - $footer ? null : $footer = $('#yoho-footer'); - $footer.hasClass('bottom') ? $footer.removeClass('bottom') : null; - } + $loading.removeClass('hide');//显示空屏加载时hide的隐藏 - num = $goodList.find('.good-info').length; + window.rePosFooter();//插入内容后重新计算底部位置 + } - $goodList.append(data); + opt.page++; - // 2015/10/31 fei.hong: 修复第一页分页不显示图片的问题 - if (num === 0) { - lazyLoad($goodList.find('.good-info').find('img.lazy')); - } else { - lazyLoad($goodList.find('.good-info:gt(' + (num - 1) + ')').find('img.lazy')); - } + searching = false; + delete opt.isTab; + }, + error: function() { + tip.show('网络断开连接了~'); + searching = false; + delete opt.isTab; + } + }); +} - searching = false; - loading.hideLoadingMask(); - page++; - $('.good-detail-text .name').each(function() { - var $this = $(this), - $title = $this.find('a'); +exports.mySwiper = mySwiper; +exports.initSwiper = initSwiper; +exports.initInfosEvt = initInfosEvt; +exports.setLazyLoadAndMellipsis = setLazyLoadAndMellipsis; +exports.loadMore = loadMore; - $title[0].mlellipsis(2); - }); +}); +define("js/plugin/tip", ["jquery"], function(require, exports, module){ +/** + * 弹框提示 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/10 + */ +var $ = require("jquery"); + +var $tip, tipItime; + +/** + * 初始化提示框 + */ +(function() { + var tipHtml = '<div id="yoho-tip" class="yoho-tip"></div>'; + + //插入提示HTML + $('.yoho-page').append(tipHtml); + + $tip = $('#yoho-tip'); + $tip.on('touchend', function() { + $tip.hide(); + + //清除Timeout + clearTimeout(tipItime); + }); +}()); + +/** + * 显示提示 + */ +function show(con, dur) { + var content, duration; + + if (typeof con === 'undefined') { + return; + } + + content = con.toString(); + duration = (dur && dur > 0) ? dur : 2000; + + $tip.text(content).show(); + + tipItime = setTimeout(function() { + if ($tip.css('display') === 'block') { + $tip.hide(); + } + }, duration); +} + +exports.show = show; +}); +define("js/plugin/wx-share", ["jquery"], function(require, exports, module){ +/** + * 微信分享 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/30 + */ - //为您优选埋点 start - $(data).closest('.good-info').each(function() { - PRDID.push($(this).data('id')); - }); - window.givePoint({ - 'REC_POSE': RECPOSE, - 'PRD_ID': PRDID.join(','), - 'PRD_NUM': $(data).closest('.good-info').length, - 'ACTION_ID': 0, - 'page_num': RECPOSE === 110009 ? 1 : page - }); - //为您优选埋点 end - }, - error: function() { - tip.show('网络断开连接了~'); - searching = false; - loading.hideLoadingMask(); - } - }); - } +var $ = require("jquery"); - $('.maybe-like p').on('touchstart', function(e) { - search(); - }); +module.exports = function() { + var _weChatInterface = '/life/getSignPackage'; + $.getJSON(_weChatInterface + '?pageurl=' + + encodeURIComponent(location.href.split('#')[0]) + '&callback=?', function (json) { + var _appId, _timestamp, _nonceStr, _signature; - function scrollHandler() { - if ($(window).scrollTop() + winH >= $(document).height() - 200) { - search(); + if (!wx) { + return; } - } - - // 优惠券页面直接加载你可能喜欢。add by @zhaobiao - if (specificGender) { - search(); - } - //srcoll to load more - $(window).scroll(function() { - window.requestAnimationFrame(scrollHandler); + if (json !== undefined && json !== '') { + _appId = json.appId.toString(); + _timestamp = json.timestamp; + _nonceStr = json.nonceStr.toString(); + _signature = json.signature.toString(); + + wx.config({ + debug: false, + appId: _appId, + timestamp: _timestamp, + nonceStr: _nonceStr, + signature: _signature, + jsApiList: [ + 'checkJsApi', + 'onMenuShareTimeline', + 'onMenuShareAppMessage', + 'onMenuShareQQ', + 'onMenuShareWeibo', + 'hideMenuItems', + 'showMenuItems', + 'hideAllNonBaseMenuItem', + 'showAllNonBaseMenuItem', + 'translateVoice', + 'startRecord', + 'stopRecord', + 'onRecordEnd', + 'playVoice', + 'pauseVoice', + 'stopVoice', + 'uploadVoice', + 'downloadVoice', + 'chooseImage', + 'previewImage', + 'uploadImage', + 'downloadImage', + 'getNetworkType', + 'openLocation', + 'getLocation', + 'hideOptionMenu', + 'showOptionMenu', + 'closeWindow', + 'scanQRCode', + 'chooseWXPay', + 'openProductSpecificView', + 'addCard', + 'chooseCard', + 'openCard' + ] + }); + } }); - //为您优选埋点 http://redmine.yoho.cn/issues/10116 - $('.maybe-like .goods-list').on('click', 'a', function() { - var index = $(this).closest('.good-info').index() + 1, - pageNum = 50; - window.givePoint({ - 'REC_POSE': RECPOSE, - 'PRD_ID': $(this).closest('.good-info').data('id'), - 'PRD_NUM': index % pageNum === 0 ? pageNum : index % pageNum, - 'ACTION_ID': 1, - 'page_num': Math.ceil(index / pageNum) - }); - return true; + wx.ready(function () { + var shareTitle = $('#shareTitle').val(); + var shareImg = $('#shareImg').val(); + var shareDesc = $('#shareDesc').val(); + var shareLink = $('#shareLink').val(); + var shareData = { + title: shareTitle, + desc: shareDesc, + imgUrl: shareImg, + link: shareLink + }; + + wx.onMenuShareAppMessage(shareData); + wx.onMenuShareTimeline(shareData); + wx.onMenuShareQQ(shareData); + wx.onMenuShareWeibo(shareData); }); }; }); -define("js/index/entry", ["jquery","hammer","handlebars","source-map","swiper","index"], function(require, exports, module){ +define("js/guang/home", ["jquery","hammer","mlellipsis","lazyload","swiper","index"], function(require, exports, module){ /** - * Index打包入口 + * 逛首页 * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/19 + * @date: 2015/10/10 */ -require("js/index/search"); -require("js/index/footer"); -require("js/index/channel"); -require("js/index/coupon"); +var $ = require("jquery"); + +var info = require("js/guang/info"), + loadMore = info.loadMore; + +var $loadMoreInfo = $('#load-more-info'); +var $loading = $(''), + $noMore = $(''); + +var winH = $(window).height(); + +var $infoList = $('#info-list'), + $infos = $infoList.children('.info-list'), + $nav = $('#guang-nav'), + $curNav = $nav.children('.focus'), + curType = $curNav.data('type'); + +var state = {}; + +if ($loadMoreInfo.length > 0) { + $loading = $loadMoreInfo.children('.loading'); + $noMore = $loadMoreInfo.children('.no-more'); +} + +info.initSwiper(curType); + +info.initInfosEvt($infoList); + +//初始化各Nav下资讯加载的状态 +(function() { + var gender = $('#gender').val(); + + $nav.children('.guang-nav-item').each(function() { + var type = $(this).data('type'), + focus = $(this).hasClass('focus'); + + state[type] = { + page: focus ? 2 : 1, + gender: gender, + type: type, + end: false + }; + }); +}()); +$nav.bind('contextmenu', function(e) { + return false; +}); +$nav.on('touchend touchcancel', function(e) { + + var $this = $(e.target).closest('.guang-nav-item'), + $content, + index; + + if ($this.hasClass('focus')) { + return; + } + + + index = $this.index(); + + $this.addClass('focus'); + $curNav.removeClass('focus'); + + $content = $infos.eq(index); + + $curNav = $this; + curType = $this.data('type'); + + //当未加载数据时去请求数据 + if (state[curType].page === 1) { + + //无数据时隐藏正在加载和没有更多字样 + $loading.addClass('hide'); + $noMore.addClass('hide'); + + state[curType].isTab = true; + loadMore($content, state[curType]); + } else { + + //重置当前Tab的load-more + if (state[curType].end) { + $loading.addClass('hide'); + $noMore.removeClass('hide'); + } else { + $loading.removeClass('hide'); + $noMore.addClass('hide'); + } + } + + $infos.not('.hide').addClass('hide'); + $content.removeClass('hide'); + + if (state[curType].page === 1) { + window.rePosFooter();//进入空内容时重新定位footer位置 + } +}); + +function scrollHandler() { + var $c = $infos.not('.hide'); + + if ($(window).scrollTop() + winH >= $(document).height() - 0.25 * $c.height()) { + loadMore($c, state[curType]); + } +} + +//srcoll to load more +$(document).scroll(function() { + window.requestAnimationFrame(scrollHandler); +}); + +$nav.on('touchstart', function(e) { + var target = e.target || e.srcElement; + + target.className = 'bytouch ' + target.className; +}).on('touchend touchcancel', function() { + $nav.find('li').removeClass('bytouch'); }); -define("js/index/search", ["jquery","hammer","handlebars","source-map"], function(require, exports, module){ +}); +define("js/guang/list", ["jquery","hammer","mlellipsis","lazyload","swiper","index"], function(require, exports, module){ +/** + * 列表页,编辑页 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/10 + */ + +var $ = require("jquery"); + +var info = require("js/guang/info"), + loadMore = info.loadMore; + +var winH = $(window).height(); + +var $author = $('#author-infos'); +var $tag = $('#tag'); +var $gender = $('#gender'); +var $isApp = $('#isApp'); + +var setting = { + page: 2, + end: false +}; + +var $infos = $('#info-list'); + +info.initInfosEvt($infos); + +if ($author.length > 0) { + $.extend(setting, { + authorId: $author.data('id'), + isApp: $isApp.val() + }); +} + +if ($tag.length > 0) { + $.extend(setting, { + tag: $tag.val(), + gender: $gender.val(), + isApp: $isApp.val() + }); +} + +function scrollHandler() { + if ($(window).scrollTop() + winH >= $(document).height() - 0.25 * $infos.height()) { + loadMore($infos, setting); + } +} + +//srcoll to load more +$(window).scroll(function() { + window.requestAnimationFrame(scrollHandler); +}); + +}); +define("js/guang/detail", ["jquery","mlellipsis","lazyload","iscroll-probe"], function(require, exports, module){ /** - * 搜索JS + * 逛详情页 * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/19 + * @date: 2015/10/13 */ var $ = require("jquery"), - security = require("js/plugin/security"), - tip = require("js/plugin/tip"), - Hammer = require("hammer"), - dialog = require("js/me/dialog"); + ellipsis = require("mlellipsis"), + lazyLoad = require("lazyload"), + IScroll = require("iscroll-probe"); -var $input = $('#search-input input'); +var $authorIntro = $('.author .intro'); -var $clear = $('#search-input .clear-input'); +var pageInIscroll = false; -var $form = $('#search-form'); +var hasCollocationBlock = $('.collocation-block').length > 0 ? true : false; -var $history = $('.history'); -var $historySearch = $('.history-search'); -var $clearHistory = $('#clear-history'); -var $buriedpoint = $('.buriedpoint'); -var $search = $('#search'); -var searchUrl = $search.closest('form').attr('action'); +//collocation block variable +var thumbWidth = 0, + $fixedThumbContainer = $(''), + $coBlock, $thumbContainer, $thumbs, $prods, + scrollToEl; -var writeSearch = require("js/index/write-search"); +var scrollToEl = document.querySelector('#wrapper .collocation-block'); -var ranToken = writeSearch.getRanToken(); -var historyval = writeSearch.getHistoryval(); +var winW = $(window).width(); -var chHammer, cHammer; +var myScroll; -chHammer = new Hammer($clearHistory[0]); +require("js/plugin/wx-share")(); -chHammer.on('tap', function() { - dialog.showDialog({ - dialogText: '您确定要删除您的最近搜索吗?', - hasFooter: { - leftBtnText: '取消', - rightBtnText: '确定' +/** + * 计算搭配的箭头的位置 + * @param $curPos 当前focus的搭配项 + */ +function posCollocationArrow($curCo) { + var left = $curCo.offset().left, + bgPos = -winW + left + (thumbWidth / 2) + 'px'; + + $thumbContainer.css({ + backgroundPosition: bgPos + ' bottom' + }); + + if (pageInIscroll) { + $fixedThumbContainer.css({ + backgroundPosition: bgPos + ' bottom' + }); + } +} + +//搭配thumb的touch事件句柄 +function thumbTouchEvt(e) { + var $curCo = $(e.currentTarget), + index = $curCo.index(), + $brother, $brotherCo, + $curProds; + + if ($curCo.hasClass('focus')) { + return; + } + + $thumbs.filter('.focus').removeClass('focus'); + + if (pageInIscroll) { + if ($curCo.closest('.fixed-thumb-container').length > 0) { + $brother = $thumbContainer; + } else { + $brother = $fixedThumbContainer; } - }, function() { - if (localStorage) { - localStorage.removeItem(historyval); + $brotherCo = $brother.find('.thumb').eq(index); + $fixedThumbContainer.find('.thumb.focus').removeClass('focus'); + $brotherCo.addClass('focus'); + } + + $curCo.addClass('focus'); + + //定位arrow + posCollocationArrow($curCo); + + $prods.not('.hide').addClass('hide'); + $curProds = $prods.eq(index); + $curProds.removeClass('hide'); + + // + lazyLoad($curProds.find('.lazy')); + + if (pageInIscroll) { + if (myScroll) { + myScroll.scrollToElement(scrollToEl, 400); } + } else { + $('body').animate({ + scrollTop: $coBlock.offset().top + }, 400); + } - $history.html(''); - $historySearch.hide(); - $clearHistory.hide(); + myScroll && myScroll.refresh(); +} - window.rePosFooter(); +// 初始化iscroll +function initIscroll() { + var $scroller = $('#scroller'), + $yohoHeader = $('.yoho-header'); - dialog.showDialog({ - dialogText: '删除成功', - autoHide: true, - fast: true - }); + var hH = 0, + winH, tcH, cbH, cbTop, fixedThumbDom; + + //考虑通用头部的影响:对offset().top以及winH做对应偏移 + if ($yohoHeader.length > 0) { + hH = $yohoHeader.outerHeight(); + } + + myScroll = new IScroll('#wrapper', { + probeType: 3, + mouseWheel: true, + click: true }); -}); -// 搜索输入联动 -function inputAction() { - var $searchAssociate = $('.search-associate'); - var $icon = $('.search-icon'); - var $searchItems = $('.search-items'); + document.addEventListener('touchmove', function(e) { + e.preventDefault(); + }, false); - $input.on('input', function() { - if ($input.val() === '') { - $icon.css('color', '#b2b2b2'); - $clear.addClass('hide'); - $searchAssociate.html(''); - $searchItems.show(); - $searchAssociate.hide(); - } else { - $icon.css('color', '#666'); - $clear.removeClass('hide'); - $searchAssociate.show(); - } + if (!hasCollocationBlock) { + myScroll.on('scroll', function() { + $scroller.trigger('scroll'); + }); + return; + } - // 联动搜索 - $.ajax({ - url: '/index/search/fuzzyDatas', - data: { - keyword: $input.val() - }, - dataType: 'json', - success: function(data) { - var ajaxHtml = ''; - var i; + winH = $(window).height() - hH; + fixedThumbDom = $fixedThumbContainer[0]; - if (data.length > 0) { - for (i = 0; i < data.length; i++) { - ajaxHtml += '<li><span class="keyword">' + data[i].keyword + '</span><span class="count">' + - data[i].count + ' items<i class="iconfont"></i></span></li>'; - } + tcH = $thumbContainer.outerHeight(); + cbH = $coBlock.outerHeight(); + cbTop = $coBlock.offset().top - hH; - $searchAssociate.html(ajaxHtml); - $searchItems.hide(); - } else { - $searchAssociate.html(''); - } + myScroll.on('scroll', function() { + var sTop = -this.y; + var classList = fixedThumbDom.className; - $searchAssociate.find('li').on('touchend', function() { - GoSearch($(this).find('.keyword').html()); - }); - }, - error: function() { - tip.show('网络断开连接了~'); + if (sTop <= cbTop - winH + tcH) { + if (classList.indexOf('fixed-bottom') === -1) { + $fixedThumbContainer + .addClass('fixed-bottom') + .removeClass('hide'); } - }); + } else if (sTop <= cbTop) { + if (classList.indexOf('hide') === -1) { + $fixedThumbContainer + .addClass('hide') + .removeClass('fixed-bottom fixed-top'); + } + } else if (sTop <= cbTop + cbH - tcH) { + if (classList.indexOf('fixed-top') === -1) { + $fixedThumbContainer + .addClass('fixed-top') + .removeClass('hide absolute') + .css('top', ''); + } + } else if (sTop <= cbTop + cbH) { + if (classList.indexOf('absolute') === -1) { + $fixedThumbContainer + .addClass('absolute') + .removeClass('fixed-top hide'); + } + fixedThumbDom.style.top = cbTop + hH + cbH - tcH - sTop + 'px'; + } else if (sTop > cbTop + cbH) { + if (classList.indexOf('hide') === -1) { + $fixedThumbContainer + .addClass('hide') + .removeClass('absolute'); + } + } + $scroller.trigger('scroll'); }); } -//跳到搜索页 -function GoSearch(query) { - //保存搜索的内容 - writeSearch.setHistoryValFun(query); - document.location.href = searchUrl + '?query=' + query; -} +//window onload 后重新refresh iscroll +window.onload = function() { + myScroll && myScroll.refresh(); +}; -//热门搜索、最近搜索事件 -$('.search-items .search-group').on('click', 'li', function(event) { - var query = ''; +// 图片加载完成之后重新 refresh iscroll +$('img').on('load', function() { + myScroll && myScroll.refresh(); +}); - if (event.target.nodeName === 'A') { - query = $(event.target).html(); - } +//初始化页面,包括是否使用iscorll初始化页面 +//接口暴露在HTML中,使用压缩名 +exports.i = function(useIscroll) { + var isIphone = navigator.userAgent.indexOf('iPhone') > 0 ? true : false; + var $this, $title; + + pageInIscroll = isIphone && useIscroll; + + ellipsis.init(); - if (event.target.nodeName === 'LI') { - query = $(event.target).find('a').html(); - } + if ($('.good-detail-text .name').length > 0) { + $('.good-detail-text .name').each(function() { + $this = $(this); + $title = $this.find('a'); - GoSearch(query); -}); + $title[0].mlellipsis(2); + }); + } -inputAction(); + lazyLoad($('.lazy')); -cHammer = new Hammer($clear[0]); -cHammer.on('tap', function() { - $input.val('').trigger('input'); -}); + //title mlellipsis + $('.info-list .title, .one-good .reco-name').each(function() { + this.mlellipsis(2); + }); -$search.on('touchend', function() { - var $buriedpoint = $form.find('.buriedpoint'); + //offset.left约等于marginLeft的值则表示介绍被换行,则清除intro的paddingTop让其更靠近头像和作者名 + if ($authorIntro.offset() && (parseInt($authorIntro.offset().left, 10) === + parseInt($authorIntro.css('margin-left'), 10))) { + $authorIntro.css('padding-top', 0); + } - if ($buriedpoint.val() === '') { - $buriedpoint.val($('#default-terms').val()); + if (pageInIscroll) { + if ($('.yoho-header').length > 0) { + $('#wrapper').addClass('ios has-head'); + } else { + $('#wrapper').addClass('ios'); + } } - //保存搜索的内容 - writeSearch.setHistoryValFun($buriedpoint.val()); + //有搭配模块,iphone使用iscroll初始化滚动并有固定的搭配栏,其他的没有 + if (hasCollocationBlock) { + $coBlock = $('.collocation-block'); + $thumbContainer = $coBlock.children('.thumb-container'); + $thumbs = $thumbContainer.find('li'); + $prods = $coBlock.find('.prod'); - if (security.hasDangerInput()) { - return false; - } + thumbWidth = $thumbs.width(); - $(this).closest('form').submit(); - return false; -}); + if (pageInIscroll) { + $fixedThumbContainer = $('#wrapper') + .after($thumbContainer.clone().addClass('fixed-thumb-container fixed-bottom')) + .next('.thumb-container'); -//初始化历史搜索的内容 -(function() { - var html = '', - history, - historys, i, num = 1; + //load img of fixed thumb container + lazyLoad($fixedThumbContainer.find('.lazy'), { + event: 'sporty' + }); + } - if (localStorage) { - historys = localStorage.getItem(historyval); + //Init Arrow Position + posCollocationArrow($thumbs.filter('.focus')); - if (historys && historys.length > 0) { - historys = historys.split(ranToken); - for (i = historys.length; i > 0; i--) { - history = historys[i - 1]; + $thumbContainer.delegate('.thumb', 'touchend', thumbTouchEvt); - if (history === '') { - continue; - } + if (pageInIscroll) { + $fixedThumbContainer.delegate('.thumb', 'touchend', thumbTouchEvt); - if (num++ > 10) { - break; - } + } + } - html += '<li><a href="javascript:void(0);">' + history + '</li>'; - } + if (pageInIscroll) { + initIscroll(); + } +}; +}); +define("js/guang/star-classroom", ["jquery","swiper","lazyload","index"], function(require, exports, module){ +/** + * 星潮教室-首页 + * @author: wsl<shuiling.wang@yoho.cn> + * @date: 2016/4/11 + */ + +var $ = require("jquery"), + Swiper = require("swiper"), + calendar = require("js/guang/calendar"), + lazyLoad = require("lazyload"), + tip = require("js/plugin/tip"); + +var bannerSwiper, collocationSwiper; + +lazyLoad($('img.lazy')); + +$('body').addClass('star-class-body'); + +function setAvatar($userAvatar) { + var myImage = new Image(), + avatar; + + // 部分老用户没有头像,显示默认头像 + avatar = $userAvatar.data('avatar'); + myImage.src = avatar; + myImage.onload = function() { + $userAvatar.css('background-image', 'url(' + avatar + ')'); + }; +} + +// 日历弹出框显示及粉丝排行榜数据组装 +function intimacyData(data) { + var $ul = $('.fan-charts-cont'), + $myIntimacy = $('.my-intimacy'), + $increased = $('.increased'), + signDay = data.signDay.split(','), + html = '', + style = '', + nowDate = new Date(), + nowYear = nowDate.getFullYear(), + nowMonth = nowDate.getMonth(), + nowDaysNub = calendar.calculateMonthDays(nowMonth, nowYear); + + var i, j; + + if (signDay.length > 0) { + for (i = 0; i < nowDaysNub; i++) { + for (j = 0; j < signDay.length; j++) { + if (i === parseInt(signDay[j])) { + $('.now-days').eq(i - 1).addClass('sign-item'); + } + } + } + } + + for (i = 0; i < data.fanCharts.length; i++) { + if (i === 0) { + style = 'font-bold'; + } else { + style = ''; + } + + html += '<li>' + + '<i class="rank-ico">' + data.fanCharts[i].num + '</i>' + + '<span data-avatar="' + data.fanCharts[i].img + '" class="rank-avatar"></span>' + + '<span class="fans-name">' + data.fanCharts[i].name + '</span>' + + '<div class="fans-intimacy">亲密度<span class="' + style + '">' + + data.fanCharts[i].intimacyNum + '</span></div>' + + '</li>'; + } + + $ul.html(html); + + $('.fan-charts-cont .rank-avatar').each(function(key, item) { + if ($(item).attr('data-avatar') !== '') { + setAvatar($(item)); + } + }); + + $myIntimacy.find('span').html(data.todayIntimacy); + $increased.find('span').html(data.todayIntimacy); + + if (data.intimacyNum === 0) { + $('.my-intimacy').hide(); + $('.increased').show(); + } else { + $('.my-intimacy').show(); + $('.increased').hide(); + } + + $('.pop-intimacy').css({ + zIndex: '10' + }).show(); + $('.classroom-mask').css({ + zIndex: '9' + }).show(); + $('body').css({ + overflow: 'hidden' + }); +} + +//当前字符串字节数统计 +function bytesCountAction(code, bytesCount) { + if (/^[\u0000-\u00ff]$/.test(code)) { + bytesCount += 1; + } else { + bytesCount += 2; + } + + return bytesCount; +} + +// 亲密度用户名字字数限制 +function limitUsername() { + var $name = $('.home-floor-sign').find('.user-name'), + nameVal = $name.html(), + nameSize = nameVal.length, + bytesCount = 0, + newName = ''; + + var i, code; + + for (i = 0; i < nameSize; i++) { + code = nameVal.charAt(i); + bytesCount = bytesCountAction(code, bytesCount); + + if (bytesCount < 5) { + newName += code; + } + } + + if (bytesCount > 8) { + newName += '..' + nameVal.charAt(nameSize - 1); + } else { + newName = nameVal; + } + + $name.html(newName); +} + +if ($('.banner-swiper').find('li').length > 1) { + bannerSwiper = new Swiper('.banner-swiper', { + lazyLoading: true, + lazyLoadingInPrevNext: true, + loop: true, + autoplay: 3000, + autoplayDisableOnInteraction: false, + paginationClickable: true, + slideElement: 'li', + pagination: '.banner-top .pagination-inner' + }); +} + +if ($('.collocation-swiper').find('li').length > 1) { + collocationSwiper = new Swiper('.collocation-swiper', { + lazyLoading: true, + lazyLoadingInPrevNext: true, + lazyLoadingOnTransitionStart: true, + grabCursor: true, + slidesPerView: 'auto', + slideElement: 'li', + watchSlidesVisibility: true + }); +} + +// 星鲜事显示点赞人数的区域 +if ($('.artice-zan').find('li').length > 0) { + $('.zan-more').show(); +} + +if ($('.home-floor-sign').length > 0) { + limitUsername(); +} + +// 星鲜事点赞事件 +$(document).on('touchstart', '.like-ico', function(event) { + var $that = $(this), + addString = ''; + + event.stopPropagation(); + + $.ajax({ + type: 'POST', + url: '/guang/starclass/setPraise', + data: { + articleId: $that.parents('li').attr('articleId') + }, + success: function(data) { + var code = data.code; + + if (code === 200) { + if ($that.hasClass('like')) { + $that.removeClass('like'); + } else { + $that.addClass('like'); + } + + if (data.num > 99) { + addString = '+'; + } else { + addString = ''; + } + + $that.parent().find('.zan-more').html(data.num + addString); + } + }, + error: function() { + tip.show('网络断开连接了~'); + } + }); +}); + +// 增加亲密度请求 +$('.add-intimacy').on('touchstart', function(event) { + event.stopPropagation(); + event.preventDefault(); + + $.ajax({ + type: 'GET', + url: '/guang/starclass/sign', + success: function(data) { + var code = data.code; + + if (code === 200) { + intimacyData(data.data); + } + + if (code === 201) { + if ($('#intimacy-link').length <= 0) { + $('body').append('<a href=\'' + data.data + '\' style="display:none;" id="intimacy-link">' + + '<span class="intimacy-link"></span></a>'); + } + + $('.intimacy-link').click(); + } + }, + error: function() { + tip.show('网络断开连接了~'); + } + }); +}); + +// 关闭日历弹出窗事件 +$('.pop-intimacy .pop-close, .classroom-mask').on('click', function() { + history.go(0); +}); + + +if ($('.user-head').attr('data-avatar') !== '') { + setAvatar($('.user-head')); +} - $history.html(html); - if (html !== '') { - $clearHistory.removeClass('hide'); - $historySearch.removeClass('hide'); - } - window.rePosFooter(); - } - } -}()); }); -define("js/plugin/security", ["jquery"], function(require, exports, module){ +define("js/guang/calendar", ["jquery"], function(require, exports, module){ /** - * 校验input, 防止SQL注入 - * @author: 赵彪<bill.zhao@yoho.cn> - * @date: 2015/11/30 + * 星潮教室 亲密度·日期 + * @author: wsl<shuiling.wang@yoho.cn> + * @date: 2016/4/11 */ -var $ = require("jquery"), - tip = require("js/plugin/tip"); - -/** - * hasStrangeInput() return true when input have danger value - * - * @param {Bool} needConvert Set if the danger input value should be converted to space - * @return {Bool} true/false If the input have danger value - */ -function hasDangerInput(needConvert) { +var $ = require("jquery"); - var $inputs = $('input[type!=hidden], textarea'); +var CalendarHandler = { + currentYear: 0, + currentMonth: 0, + initialize: function() { + var $calendarItem; - var validationPartten = /['"<>&\|]|--/g, - inputsLength = $inputs.length, - val, - i, - matchChars, + $calendarItem = this.createCalendar(0, 0); + $('#Container').append($calendarItem); + }, + isRuiYear: function(aDate) { + return 0 === aDate % 4 && (aDate % 100 !== 0 || aDate % 400 === 0); + }, + calculateWeek: function(y, m, d) { + var arr, vDay, week; - // to set if the input value should be coverted, and its default value is true; - willConvert = needConvert === undefined || typeof needConvert !== 'boolean' ? true : needConvert; + arr = '7123456'.split(''); + vDay = parseInt(d, 10); + week = arr[new Date(y, m - 1, vDay).getDay()]; + return week; + }, + calculateMonthDays: function(m, y) { + var mDay = 0; + var isRn; + if (m === 0 || m === 1 || m === 3 || m === 5 || m === 7 || m === 8 || m === 10 || m === 12) { + mDay = 31; + } else { + if (m === 2) { - for (i = 0; i < inputsLength; i++) { - val = $inputs.eq(i).val(); - if (validationPartten.test(val)) { - if (willConvert) { - $inputs.eq(i).val(val.replace(validationPartten, ' ')); + // 判断是否为芮年 + isRn = this.isRuiYear(y); + if (isRn === true) { + mDay = 29; + } else { + mDay = 28; + } } else { - matchChars = val.match(validationPartten).join(' '); - tip.show('不可以输入 ' + matchChars + ' 哦!'); + mDay = 30; } + } + return mDay; + }, + createCalendar: function(y, m) { + var $dayItem, nowDate, nowYear, nowMonth, nowDaysNub, nowWeek, lastMonthDaysNub, i, hasCreateDaysNub; + var months = ['January', 'February', 'March', 'April', 'May', + 'June', 'July', 'August', 'September', 'October', 'November', 'December']; - return !willConvert && true; - } - } + // var signDay = $('.sign-day').val(); + $dayItem = $('<div class="day-item"></div>'); - return false; -} + // 获取当前月份的天数 + nowDate = new Date(); + nowYear = y === 0 ? nowDate.getFullYear() : y; + this.currentYear = nowYear; + nowMonth = m === 0 ? nowDate.getMonth() + 1 : m; + this.currentMonth = nowMonth; + nowDaysNub = this.calculateMonthDays(nowMonth, nowYear); -exports.hasDangerInput = hasDangerInput; - -}); -define("js/me/dialog", ["jquery","handlebars","source-map","hammer"], function(require, exports, module){ -/* - * @Description: dialog - * @Time: 2015/11/18 - * @author: chenglong.wang - */ + window.nowDaysNub = nowDaysNub; -var $ = require("jquery"), - Handlebars = require("handlebars"), - Hammer = require("hammer"); + $('.cur-year').html(nowYear); + $('.cur-month').html(months[nowMonth - 1]); -var $dialogWrapper, - dialogTpl, - dialogTemplate; + // 获取当月第一天是星期几 + nowWeek = parseInt(this.calculateWeek(nowYear, nowMonth, 1)); -function getInstance() { - if (dialogTpl === undefined) { - dialogTpl = '<div id="dialog-wrapper" class="dialog-wrapper">' + - '<div class="dialog-box">' + - '{{# hasHeader}}' + - '{{/ hasHeader}}' + - '<div class="dialog-content">{{dialogText}}</div>' + - '{{# hasFooter}}' + - '<div class="dialog-footer">' + - '{{# leftBtnText}}' + - '<span class="dialog-left-btn tap-hightlight">{{.}}</span>' + - '{{/ leftBtnText}}' + - '{{# rightBtnText}}' + - '<span class="dialog-right-btn tap-hightlight">{{.}}</span>' + - '{{/ rightBtnText}}' + - '</div>' + - '{{/ hasFooter}}' + - '</div>' + - '</div>'; + // 获取上个月的天数 + lastMonthDaysNub = this.calculateMonthDays((nowMonth - 1), nowYear); + + if (nowWeek !== 0) { + + // 生成上月剩下的日期 + for (i = (lastMonthDaysNub - nowWeek); i < lastMonthDaysNub; i++) { + $dayItem.append('<div class="item last-item">' + (i + 1) + '</div>'); + } + } + + // 生成当月的日期 + for (i = 1; i <= nowDaysNub; i++) { + + // if (signDay.indexOf(i) > -1) { + // $dayItem.append('<div class="item signItem">' + i + '</div>'); + // } else { + // $dayItem.append('<div class="item">' + i + '</div>'); + // } + + $dayItem.append('<div class="item now-days">' + i + '</div>'); + } + + // 获取总共已经生成的天数 + hasCreateDaysNub = nowWeek + nowDaysNub; + + // 如果小于42,往下个月推算 + if (hasCreateDaysNub < 41) { + for (i = 0; i <= (41 - hasCreateDaysNub); i++) { + $dayItem.append('<div class="item last-item">' + (i + 1) + '</div>'); + } + } - dialogTemplate = Handlebars.compile(dialogTpl); + return $dayItem; } - return dialogTemplate; -} - -// fullWithBtn是供详情页获取限购码使用的特殊参数 -exports.showDialog = function(data, callback, callbackForLeft, fullWithBtn) { +}; - var dialogTemplate = getInstance(), - dialogStr = dialogTemplate(data), - $dialogBox, - defaultHideDuraton, - dialogWrapperHammer; +$(document).ready(function() { + CalendarHandler.initialize(); +}); - $('.dialog-wrapper').remove(); +exports.calculateMonthDays = CalendarHandler.calculateMonthDays; + +}); +define("js/guang/collocation-list", ["jquery","lazyload","mlellipsis"], function(require, exports, module){ +/** + * 星潮教室-星搭配分页加载 + * @author: wsl<shuiling.wang@yoho.cn> + * @date: 2016/4/12 + */ - $('body').append($(dialogStr)); +var $ = require("jquery"), + tip = require("js/plugin/tip"), + loading = require("js/plugin/loading"), + lazyLoad = require("lazyload"), + ellipsis = require("mlellipsis"), + stopLoading = false; - $dialogBox = $('.dialog-box'); - $dialogWrapper = $('.dialog-wrapper'); +var page = 1; +ellipsis.init(); - dialogWrapperHammer = new Hammer(document.getElementById('dialog-wrapper')); +$('body').addClass('star-class-body'); - // 显示 - if (data.fast) { - $dialogWrapper.css({ - display: 'block' - }); - } else { - $dialogWrapper.fadeIn(); - } +function massageAJAX(page) { + var $this, $title, $cont; - if (fullWithBtn) { - $('.dialog-wrapper .dialog-footer > span').css('width', '100%'); - $('.dialog-wrapper .dialog-content').css({ - 'padding-left': '1.85rem', - 'padding-right': '1.85rem' - }); - $dialogWrapper.css('z-index', '10'); - } + loading.showLoadingMask(); + $.ajax({ + type: 'GET', + url: '/guang/starclass/ajaxCollocation', + data: { + page: page + }, + dataType: 'html', + success: function(data) { + stopLoading = false; - $dialogBox.css({ - top: '50%', - marginTop: -($dialogBox.height() / 2) - }); + if (data === ' ') { + stopLoading = true; + tip.show('没有更多内容了'); + } - //隐藏 - if (data.autoHide) { - defaultHideDuraton = 1000; - if (data.autoHide > 1) { - defaultHideDuraton = data.autoHide; - } - setTimeout(function() { - $dialogWrapper.fadeOut(); - }, defaultHideDuraton); - } + $('.collocation-list').append(data); - //禁止在dialog上可以上下滚动 - $dialogWrapper.on('touchmove', function() { - return false; - }); + // 限制标题字数 + $('.cont-area').each(function() { + $this = $(this); + $title = $this.find('.title'); + $cont = $this.find('.cont-txt'); - dialogWrapperHammer.on('tap', function(event) { + $title[0].mlellipsis(2); + $cont[0].mlellipsis(2); + }); - if ($(event.target).hasClass('dialog-left-btn')) { - if (typeof callbackForLeft === 'function') { - callbackForLeft(); - } - $dialogWrapper.fadeOut(); - } else if ($(event.target).hasClass('dialog-right-btn')) { - callback(); + loading.hideLoadingMask(); + lazyLoad($('img.lazy')); + }, + error: function() { + tip.show('网络断开连接了~'); } - - // 防止出现点透问题 - event.preventDefault(); - event.srcEvent.stopPropagation(); }); -}; +} -exports.hideDialog = function() { - $('.dialog-wrapper').remove(); -}; - -}); -define("js/index/write-search", [], function(require, exports, module){ -/** - * 将搜索结果存localStorage - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/29 - */ - -var ranToken = ',', - historyval = 'historys1'; - -//获取分隔符 -function getRanToken() { - return ranToken; -} - -//存变量 -function getHistoryval() { - return historyval; -} - -//绑定提交前的存local操作 -function bindWirteLocal($form) { - $form.on('submit', function() { - var query = this.query.value; - - setHistoryValFun(query); - }); -} - -function setHistoryValFun(query) { - var historys; - if (localStorage) { - historys = localStorage.getItem(historyval); - - historys = historys ? historys.replace(new RegExp((query + ranToken), 'g'), '') : ''; - - if (historys === '') { - query = ranToken + query; - } - - historys += query + ranToken; - localStorage.setItem(historyval, historys); - } -} - -exports.getRanToken = getRanToken; -exports.getHistoryval = getHistoryval; -exports.setHistoryValFun = setHistoryValFun; - -exports.bindWirteLocal = bindWirteLocal; -}); -define("js/index/footer", ["jquery","hammer"], function(require, exports, module){ -/** - * 底部JS - * @author: liangzhifeng<zhifeng.liang@yoho.cn> - * @date: 2015/10/26 - */ - -var $ = require("jquery"), - Hammer = require("hammer"); - -var floatLayerBtnHammer; - -require("js/common"); - -/** - * 获取url参数 - */ -function getQueryString(name) { - var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'); - var r = window.location.search.substr(1).match(reg); - - if (r != null) { - return window.unescape(r[2]); - } - return null; -} - -function downLoadApp() { - var appUrl = 'http://www.yohoshow.com/about/index/yohobuyqr/'; - var clickedAt = new Date(); - - setTimeout(function() { - var mkt = getQueryString('mkt_code'); - - if ((new Date()) - clickedAt < 2000) { - if (mkt) { - appUrl += '?union_type=' + mkt; - } - window.location = appUrl; - } - }, 500); -} - -$('#float-layer-close').on('touchend', function(e) { - $('#float-layer-app').hide(); - window.setCookie('_float-layer-app', 'id490655927', - { - domain: '.yohobuy.com' - }); - window.setCookie('_float-layer-app-close', 1, - { - domain: '.yohobuy.com', - expires: 1 - }); - return false; -}); - -if ($('#float-layer-btn') && $('#float-layer-btn')[0]) { - floatLayerBtnHammer = new Hammer($('#float-layer-btn')[0]); - floatLayerBtnHammer.on('tap', function(e) { - downLoadApp('bottom'); - e.srcEvent.stopPropagation(); - }); - - if (typeof window.cookie === 'function' && !window.cookie('_float-layer-app')) { - $('#float-layer-app').show(); - } else { - $('#float-layer-app').hide(); - } -} - -}); -define("js/index/channel", ["jquery","hammer"], function(require, exports, module){ -/** - * 频道选择页面顶部搜索 - * @author: bikai<kai.bi@yoho.cn> - * @date: 2015/10/28 - */ -var $ = require("jquery"), - security = require("js/plugin/security"); +function scrollHandler() { + if (!stopLoading && ($(window).scrollTop() + $(window).height() > $('body').height() - 100)) { + stopLoading = true; + page++; + massageAJAX(page); + } +} -var $searchBox = $('.search-box'), - $box = $('.box'), - $indexSearch = $('.index-search'), - $indexLogo = $('.index-logo'), - $channelLink = $('.index-channel a:not(#yohood)'); +// 分享成功 +window.successShare = function() { + $.ajax({ + type: 'POST', + url: '/guang/starclass/forward', + success: function(data) { + var code = data.code; -var $search = $searchBox.children('input[type="text"]'), - $cancelSearch = $box.children('.no-search'), - $searchIcon = $searchBox.children('.search-icon'); + if (code === 200 && data.data > 0) { + tip.show('分享成功,亲密度+10'); + } + }, + error: function() { + tip.show('网络断开连接了~'); + } + }); +}; -require("js/common"); +$(window).scroll(function() { + scrollHandler(); +}); -$search.on('focus', function() { - $box.addClass('action'); - $indexLogo.addClass('action'); -}).on('input', function() { - if ($search.val() === '') { - $searchIcon.addClass('empty'); +if ($('.collocation-list').find('li').length === 0) { + massageAJAX(1); +} + +// 星搭配收藏请求 +$(document).on('touchstart', '.collection', function(event) { + var $that = $(this), + $icon = $that.find('.collected-ico'); + + var type; + + event.stopPropagation(); + + if ($icon.hasClass('collected')) { + type = 'del'; } else { - $searchIcon.removeClass('empty'); + type = 'fav'; } -}); -$cancelSearch.on('touchend', function() { - $box.removeClass('action'); - $indexLogo.removeClass('action'); - $search.blur(); - return false; -}); -$searchBox.children('.clear-text').on('touchstart', function() { - $search.val('').focus().trigger('input'); -}); + $.ajax({ + type: 'POST', + url: '/guang/starclass/setFavorite', + data: { + articleId: $that.parents('li').attr('articleId'), + type: type + }, + success: function(data) { + var code = data.code; -$searchBox.children('.search-icon').on('touchstart', function() { - if (security.hasDangerInput()) { - return false; - } - $indexSearch.submit(); -}); + if (code === 200) { + if ($icon.hasClass('collected')) { + $icon.removeClass('collected'); + } else { + $icon.addClass('collected'); + } -$searchBox.keyup(function(e) { - if (e.keyCode === 13) { - if (security.hasDangerInput()) { - return false; - } - $indexSearch.submit(); - } -}); + } -$('.index-channel img').on('load error', function() { - window.rePosFooter && window.rePosFooter(); -}); + if (code === 201) { + if ($('#collocation-link').length <= 0) { + $('body').append('<a href=\'' + data.data + '\' style="display:none;" id="collocation-link">' + + '<span class="collocation-link"></span></a>'); + } -$channelLink.on('touchstart', function() { - $channelLink.css({ - background: '#000', - color: '#fff', - borderColor: '#fff' - }); - $(this).css({ - background: 'rgba(255, 255, 255, 0.5)', - color: '#000', - borderColor: '#000' - }); -}).on('touchend touchcancel', function() { - $(this).css({ - background: '#000', - color: '#fff', - borderColor: '#fff' + $('.collocation-link').click(); + } + }, + error: function() { + tip.show('网络断开连接了~'); + } }); }); }); -define("js/index/coupon", ["jquery","swiper","index"], function(require, exports, module){ -/** - * Created by Administrator on 2016/4/13. - */ -var $ = require("jquery"), - Swiper = require("swiper"), - $receive = $('.main-right-receive'), - $mask = $('.floor-mask'), - $message = $('.floor-message'), - $tooltip = $('.floor-tooltip'), - tip = require("js/plugin/tip"); - -var bannerSwiper; - -// 获取url中的参数 -function getUrlParam(name) { - - // 构造一个含有目标参数的正则表达式对象 - var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)'); - - // 匹配目标参数 - var r = window.location.search.substr(1).match(reg); - - // 返回参数值 - if (r != null) { - return r[2]; - } - - return null; -} - -$receive.on('click', function() { - var $curDom = $(this), - req = ''; - - if (getUrlParam('app_version')) { - req += '&app_version=' + getUrlParam('app_version'); - } - - if (getUrlParam('uid')) { - req += '&uid=' + getUrlParam('uid'); - } - - $.ajax({ - url: '//m.yohobuy.com/coupon/receiveCoupon?code=' + getUrlParam('code') + req, - data: { - couponID: $curDom.parents('.coupon-floor').attr('coupon-id') - }, - dataType: 'json', - success: function(data) { - var msg = data.msg, - status = data.status, - newUrl = data.url + '?code=' + getUrlParam('code'); - - - if (data.isApp === true) { - newUrl = data.url; - } - if (data.noLogin === true) { - if ($('#intimacy-link').length <= 0) { - $('body').append('<a href=\'' + newUrl + '\' style="display:none;" id="intimacy-link">' + - '<span class="intimacy-link"></span></a>'); - } - - $('.intimacy-link').click(); - } else { - if (status) { - $curDom.hide(); - $curDom.next().show(); - $tooltip.show(); - - setTimeout(function() { - $tooltip.hide(); - }, 3000); - } else { - $message.find('.coupon-message-content').text(msg); - $mask.show(); - $message.show(); - } - } - }, - error: function() { - tip.show('网络异常!'); - } - }); -}); - -$('.coupon-floor a, .banner-top a').on('click', function() { - if ($(this).attr('href').length <= 0 || $(this).attr('href') === '#') { - return false; - } -}); - -if ($('.banner-swiper').find('li').length > 1) { - bannerSwiper = new Swiper('.banner-swiper', { - lazyLoading: true, - lazyLoadingInPrevNext: true, - loop: true, - autoplay: 3000, - autoplayDisableOnInteraction: false, - paginationClickable: true, - slideElement: 'li', - pagination: '.banner-top .pagination-inner' - }); -} - -$('.coupon-message-op-rel').on('click', function() { - location.reload(); -}); - -if ($('#noData').length > 0) { - if (location.href.indexOf('?openby:yohobuy=') <= 0) { - tip.show('网络异常!'); - } +define("js/guang/check-top", ["jquery"], function(require, exports, module){ +/** + * 星潮教室-top100 + * @author: wsl<shuiling.wang@yoho.cn> + * @date: 2016/4/12 + */ + +var $ = require("jquery"); + +$('body').addClass('star-class-body'); + +function setAvatar($userAvatar) { + var myImage = new Image(), + avatar; + + // 部分老用户没有头像,显示默认头像 + avatar = $userAvatar.data('avatar'); + myImage.src = avatar; + myImage.onload = function() { + $userAvatar.css('background-image', 'url(' + avatar + ')'); + }; +} + +if ($('.ranking-area li').length > 0) { + $.each($('.ranking-area li'), function(key, item) { + setAvatar($(item).find('.rank-avatar')); + }); +} + +if ($('.user-avatar').attr('data-avatar') !== '') { + setAvatar($('.user-avatar')); } - -$mask.on('click', function() { - $mask.hide(); - $message.hide(); }); - - +define("js/home/entry", ["jquery","swiper","lazyload","hammer","mlellipsis","index"], function(require, exports, module){ +/** + * 首页打包入口 + * @author: liangzhifeng<zhifeng.liang@yoho.cn> + * @date: 2015/10/12 + */ + +require("js/home/home"); +require("js/home/maybe-like"); }); -define("js/passport/entry", ["jquery","handlebars","source-map","hammer"], function(require, exports, module){ +define("js/home/home", ["jquery","swiper","lazyload","hammer","mlellipsis","index"], function(require, exports, module){ /** - * 注册、登录、密码找回打包入口 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/8 + * 首页 + * @author: liangzhifeng<zhifeng.liang@yoho.cn> + * @date: 2015/10/12 */ +var $ = require("jquery"), + Swiper = require("swiper"), + lazyLoad = require("lazyload"), + noticeScroll = require("js/plugin/notice-scroll"), + $mobileWrap = $('.mobile-wrap'), + $overlay = $('.overlay'), + $sideNav = $('.side-nav'), + $subNav = $('.sub-nav'), + bannerSwiper, + recommendSwiper, + hotBrandsSwiper, + trendTopicSwiper, + goodsSwiper, + freshSwiper; -//注册 -require("js/passport/register/register"); -require("js/passport/register/code"); -require("js/passport/register/password"); +var start = 0, + swiperClass, + $logotrans = $('.home-header .logo'), + openSideNav = false, + isen = true; -//登录 -require("js/passport/login/login"); -require("js/passport/login/international"); +var attachFastClick = require("js/home/fastclick"); +attachFastClick(document.body); -//密码找回 -require("js/passport/back/mobile"); -require("js/passport/back/code"); -require("js/passport/back/email"); -require("js/passport/back/email-success"); -require("js/passport/back/new-password"); +lazyLoad($('img.lazy')); +noticeScroll('.notice', $('.notice').data('time') * 1000); -//绑定手机 -require("js/passport/bind/bind"); -require("js/passport/bind/code"); -require("js/passport/bind/password"); +$('.nav-btn').on('touchstart', function() { + $sideNav.css('pointer-events', 'none'); + $mobileWrap.addClass('menu-open'); + $overlay.show().css('opacity', 0.3); + $sideNav.addClass('on'); + openSideNav = true; -// 关联手机 -require("js/passport/bind/relate"); - -}); -define("js/passport/register/register", ["jquery"], function(require, exports, module){ -/** - * 注册 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/8 - */ -var $ = require("jquery"); + setTimeout(function() { + $sideNav.css('pointer-events', 'auto'); + }, 400); -var $phoneNum = $('#phone-num'), - $countrySelect = $('#country-select'), - $areaCode = $('#area-code'), - $btnNext = $('#btn-next'); + return false; +}); -var api = require("js/passport/api"); -var tip = require("js/plugin/tip"); +function hideSideBar(){ + openSideNav = false; + if ($mobileWrap.hasClass('menu-open')) { + $mobileWrap.removeClass('menu-open'); + $overlay.hide(); + $('.sub-nav').removeClass('show'); + $sideNav.removeClass('on'); + } +} -var trim = $.trim; -var showErrTip = tip.show; +$overlay.on('touchstart', function() { + hideSideBar(); + return false; +}); -var requested = false; +$sideNav.on('touchmove scroll', function() { + return false; +}); -api.selectCssHack($('#country-select')); +// 点击一级导航,弹出二级导航 +$sideNav.on('touchend', 'li', function(e) { + if ($(this).find('.sub-nav').size() > 0) { + $('.sub-nav').removeClass('show'); + $(this).find('.sub-nav').addClass('show'); + $(this).find('.highlight').removeClass('highlight'); + } -api.bindClearEvt(); + if (e.target.pathname === location.pathname) { + hideSideBar(); + return false; + } +}); -$phoneNum.bind('input', function() { - if (trim($phoneNum.val()) === '') { - $btnNext.addClass('disable'); - } else { - $btnNext.removeClass('disable'); +// 返回一级导航,收起二级导航 +$subNav.each(function() { + $(this).find('li').eq(0).on('click', function() { + $('.sub-nav').removeClass('show'); + return false; + }); +}).on('touchstart', function(e) { + if (e.currentTarget !== e.target) { + $subNav.find('li').removeClass('current'); } }); -$countrySelect.change(function() { - $areaCode.text($countrySelect.val()); +// 侧边栏点击背景色变化 +function highlight($elem) { + $elem.find('li').on('touchstart', function() { + $elem.find('.highlight').removeClass('highlight'); + $(this).addClass('highlight'); + }).on('touchend touchcancel', function() { + $(this).removeClass('highlight'); + }); +} +highlight($sideNav); +highlight($subNav); + + +// 头部banner轮播 +if ($('.banner-swiper').find('li').size() > 1) { + bannerSwiper = new Swiper('.banner-swiper', { + lazyLoading: true, + lazyLoadingInPrevNext: true, + loop: true, + autoplay: 3000, + autoplayDisableOnInteraction: false, + paginationClickable: true, + slideElement: 'li', + pagination: '.banner-top .pagination-inner' + }); +} + +// 热门品牌滑动 +hotBrandsSwiper = new Swiper('.brands-swiper', { + grabCursor: true, + slidesPerView: 'auto', + wrapperClass: 'brands-list', + slideElement: 'li' }); -$btnNext.on('touchstart', function() { - var pn = trim($phoneNum.val()), - areaCode = $countrySelect.val(); +// 推荐搭配滑动 +recommendSwiper = new Swiper('.recommend-swiper', { + grabCursor: true, + slidesPerView: 'auto', + wrapperClass: 'recommend-list', + slideElement: 'li' +}); - if ($btnNext.hasClass('disable')) { - return; +// 潮品话题轮播 +if ($('.trend-topic-swiper').find('li').size() > 1) { + trendTopicSwiper = new Swiper('.trend-topic-swiper', { + loop: true, + autoplay: 3000, + autoplayDisableOnInteraction: false, + paginationClickable: true, + slideElement: 'li', + pagination: '.trend-topic-content .pagination-inner' + }); +} + +// 新人专享轮播 +if ($('.fresh-list-swiper').find('li').size() > 1) { + freshSwiper = new Swiper('.fresh-list-swiper', { + lazyLoading: true, + lazyLoadingInPrevNext: true, + grabCursor: true, + slidesPerView: 'auto', + slideElement: 'li', + watchSlidesVisibility: true + }); +} + +// 潮流上装/经典裤装等轮播 +$('.category-swiper').each(function(i, index) { + swiperClass = 'category-swiper' + i; + $(this).addClass(swiperClass); + if ($('.' + swiperClass).find('.swiper-slide').size() > 1) { + goodsSwiper = new Swiper('.' + swiperClass, { + loop: true, + autoplay: 3000, + autoplayDisableOnInteraction: false, + paginationClickable: true, + slideElement: 'li', + pagination: '.' + swiperClass + ' .pagination-inner' + }); + } +}); + +// logo动画 +function tsAnimate() { + start = start + 10; + $logotrans.css({ + transform: 'rotateX(' + start + 'deg)', + '-webkit-transform': 'rotateX(' + start + 'deg)', + '-moz-transform': 'rotateX(' + start + 'deg)' + }); + if (start / 90 % 2 === 1) { + if (isen) { + $logotrans.addClass('animate'); + isen = false; + } else { + $logotrans.removeClass('animate'); + isen = true; + } + } + if (start / 90 % 2 === 0 && start % 360 !== 0) { + window.setTimeout(tsAnimate, 3000); + } else { + if (start % 360 === 0) { + window.setTimeout(tsAnimate, 60 * 1000); + } else { + window.requestAnimationFrame(tsAnimate); + } } +} - if (requested) { - return false; - } +setTimeout(tsAnimate, 3000); +$('.home-header .iconfont').on('touchstart', function() { + $(this).addClass('highlight'); +}).on('touchend touchcancel', function() { + $(this).removeClass('highlight'); +}); - if (api.phoneRegx[areaCode].test(pn)) { +// 底部留出tab 的高度 +window.reMarginFooter('.footer-tab'); - requested = true; +// set cookie +exports.set = function(c) { + window.setCookie('_Channel', c, { + expires: 365, + domain: '.m.yohobuy.com' + }); +}; - $.ajax({ - url: '/passport/reg/verifymobile', - type: 'POST', - data: { - areaCode: areaCode.replace('+', ''), - phoneNum: pn - }, - success: function(data) { - if (data.code === 200) { - location.href = data.data; - } else { - showErrTip(data.message); - requested = false; - } - }, - error: function(err) { - showErrTip('出错了,请重试'); - requested = false; - } - }); - } else { - showErrTip('手机号格式不正确,请重新输入'); - } -}); +require("js/home/maybe-like")(); }); -define("js/passport/api", ["jquery"], function(require, exports, module){ +define("js/plugin/notice-scroll", ["jquery"], function(require, exports, module){ /** - * 登录注册公用API - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/8 + * 公告栏目滚动 + * bikai kai.bi@yoho.cn */ + var $ = require("jquery"); -var trim = $.trim; +function noticeScroll(selecter, time) { + var $notice = $(selecter), + $noticeItem = $notice.find('.notice-item'), + count = $noticeItem.length, + i = 1; -//邮箱验证规则 -var emailRegx = /^([a-zA-Z0-9]+[_|\_|\.|-]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.|-]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/; + selecter = selecter || '.notice'; + time = time || 3000; -//手机号码验证规则 -var phoneRegx = { - '+86': /^1[35847]{1}[0-9]{9}$/, - '+852': /^[965]{1}[0-9]{7}$/, - '+853': /^[0-9]{8}$/, - '+886': /^[0-9]{10}$/, - '+65': /^[98]{1}[0-9]{7}$/, - '+60': /^1[1234679]{1}[0-9]{8}$/, - '+1': /^[0-9]{10}$/, - '+82': /^01[0-9]{9}$/, - '+44': /^7[789][0-9]{8}$/, - '+81': /^0[9|8|7][0-9]{9}$/, - '+61': /^[0-9]{11}$/ -}; + if (count > 1) { + setInterval(function() { + if (i >= count) { + i = 0; + } + $noticeItem.fadeOut(); + $notice.find('.item-' + i).fadeIn(); + i++; + }, time); + } +} -/** - * 密码显示隐藏 - * @params opt 初始化参数 - */ -function bindEyesEvt(opt) { - var $hasEye = $('.has-eye'), - $eye; +module.exports = noticeScroll; + +}); +define("js/home/fastclick", [], function(require, exports, module){ +;(function () { + 'use strict'; - if (opt && opt.status === 'open') { - $hasEye.append('<div class="eye"></div>'); - } else { - $hasEye.append('<div class="eye close"></div>'); - } - $eye = $hasEye.children('.eye'); + /** + * @preserve FastClick: polyfill to remove click delays on browsers with touch UIs. + * + * @codingstandard ftlabs-jsv2 + * @copyright The Financial Times Limited [All Rights Reserved] + * @license MIT License (see LICENSE.txt) + */ - $eye.on('touchstart', function(e) { - var $this = $(this), - $pwd = $this.siblings('.pwd'); + /*jslint browser:true, node:true*/ + /*global define, Event, Node*/ - e.preventDefault(); - $this.toggleClass('close'); - //切换密码显示和文本显示 - if ($this.hasClass('close')) { - $pwd.attr('type', 'password'); - } else { - $pwd.attr('type', 'text'); - } - $pwd.focus(); - }); -} + /** + * Instantiate fast-clicking listeners on the specified layer. + * + * @constructor + * @param {Element} layer The layer to listen on + * @param {Object} [options={}] The options to override the defaults + */ + function FastClick(layer, options) { + var oldOnClick; -// 清空账号显示 -function bindClearEvt() { - var $hasClear = $('.has-clear'), - $clear; + options = options || {}; - $hasClear.append('<div class="clear-input"></div>'); - $clear = $hasClear.children('.clear-input'); + /** + * Whether a click is currently being tracked. + * + * @type boolean + */ + this.trackingClick = false; - $clear.on('touchstart', function(e) { - var $input = $clear.siblings('.input'); - $input.val('').trigger('input').focus(); - e.preventDefault(); - }); + /** + * Timestamp for when click tracking started. + * + * @type number + */ + this.trackingClickStart = 0; - //反向逻辑 - $hasClear.children('.input').bind('input', function() { - var $this = $(this), - $thisClear = $this.siblings('.clear-input'), - val = trim($this.val()); - if (val === '') { - $thisClear.hide(); - } else { - $thisClear.show(); - } - }); -} + /** + * The element being tracked for a click. + * + * @type EventTarget + */ + this.targetElement = null; -// 密码长度验证 -function pwdValidate(pwd) { - if (pwd.length >= 6 && pwd.length <= 20) { - return true; - } - return false; -} -// hack for resolving direction:rtl didn't work in android uc -function selectCssHack($countrySelect) { - var u = navigator.userAgent; + /** + * X-coordinate of touch start event. + * + * @type number + */ + this.touchStartX = 0; - function autoSelectWidth() { - var wordCount = $countrySelect.find('option:selected').text().length; - switch (wordCount) { + /** + * Y-coordinate of touch start event. + * + * @type number + */ + this.touchStartY = 0; - //分别有2,3,4个汉字的情况 - case 2: - $countrySelect.outerWidth(90); - break; - case 3: - $countrySelect.outerWidth(110); - break; - default: - $countrySelect.outerWidth(130); - } - } - if (u.match(/uc/i) && u.match(/android/i)) { - $countrySelect.change(function() { - autoSelectWidth(); - }); - } else { - $countrySelect.removeClass('in-android-uc'); - } -} + /** + * ID of the last touch, retrieved from Touch.identifier. + * + * @type number + */ + this.lastTouchIdentifier = 0; -//Exports APIs -module.exports = { - emailRegx: emailRegx, - phoneRegx: phoneRegx, - bindEyesEvt: bindEyesEvt, - bindClearEvt: bindClearEvt, - pwdValidate: pwdValidate, - selectCssHack: selectCssHack -}; -}); -define("js/passport/register/code", ["jquery"], function(require, exports, module){ -/** - * 注册-验证码 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/8 - */ -require("js/passport/code")(true); -}); -define("js/passport/code", ["jquery"], function(require, exports, module){ -/** - * 注册/找回密码-验证码 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/8 - */ -var $ = require("jquery"); + /** + * Touchmove boundary, beyond which a click will be cancelled. + * + * @type number + */ + this.touchBoundary = options.touchBoundary || 10; -module.exports = function(useInRegister, useForBind, useForRelate) { - var $captcha = $('#captcha'), - $btnNext = $('#btn-next'), - $captchaTip = $('#captcha-tip'), - nickname = $('#nickname').val(), - sourceType = $('#sourceType').val(), - openId = $('#openId').val(), - phoneNum = $('#phone-num').val(), - areaCode = $('#area-code').val().replace('+', ''); - var api = require("js/passport/api"); - var tip = require("js/plugin/tip"); + /** + * The FastClick layer. + * + * @type Element + */ + this.layer = layer; - var trim = $.trim; - var showErrTip = tip.show; + /** + * The minimum time between tap(touchstart and touchend) events + * + * @type number + */ + this.tapDelay = options.tapDelay || 200; - var urlMid = useInRegister ? 'reg' : 'back'; + /** + * The maximum time for a tap + * + * @type number + */ + this.tapTimeout = options.tapTimeout || 700; - var isReg = parseInt($('#isReg').val()); + if (FastClick.notNeeded(layer)) { + return; + } - function startBind() { - $.ajax({ - url: useForBind ? '/passport/bind/bindMobile' : '/passport/bind/relateMobile', - type: 'post', - data: { - areaCode: areaCode.replace('+', ''), - phoneNum: phoneNum, - openId: openId, - sourceType: sourceType, - nickname: nickname, - password: '', - code: trim($captcha.val()) - }, - success: function(res) { - if (res.code === 200) { - tip.show('登录成功'); - setTimeout(function() { - location.href = res.data.refer; - }, 2000); - } else { - tip.show(res.message); - } - }, - error: function(err) { - tip.show('登录失败,请重试!'); - } - }); - } + // Some old versions of Android don't have Function.prototype.bind + function bind(method, context) { + return function() { return method.apply(context, arguments); }; + } - function startReg() { - $.ajax({ - type: 'POST', - url: '/passport/' + urlMid + '/verifycode', - data: { - phoneNum: phoneNum, - areaCode: areaCode, - code: trim($captcha.val()), - token: $('#token').val() - }, - success: function(data) { - if (data.code === 200) { - location.href = data.data; - } else { - //验证码不正确,显示提示 - showErrTip(data.message); - } + var methods = ['onMouse', 'onClick', 'onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel']; + var context = this; + for (var i = 0, l = methods.length; i < l; i++) { + context[methods[i]] = bind(context[methods[i]], context); + } - } - }); - } + // Set up event handlers as required + if (deviceIsAndroid) { + layer.addEventListener('mouseover', this.onMouse, true); + layer.addEventListener('mousedown', this.onMouse, true); + layer.addEventListener('mouseup', this.onMouse, true); + } - function countDown() { - var count = 59, - itime; + layer.addEventListener('click', this.onClick, true); + layer.addEventListener('touchstart', this.onTouchStart, false); + layer.addEventListener('touchmove', this.onTouchMove, false); + layer.addEventListener('touchend', this.onTouchEnd, false); + layer.addEventListener('touchcancel', this.onTouchCancel, false); - itime = setInterval(function() { - if (count === 0) { - $captchaTip.text('重新发送').removeClass('disable'); - clearInterval(itime); - } else { - $captchaTip.text('重新发送 (' + count-- + '秒)'); - } - }, 1000); - } + // Hack is required for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2) + // which is how FastClick normally stops click events bubbling to callbacks registered on the FastClick + // layer when they are cancelled. + if (!Event.prototype.stopImmediatePropagation) { + layer.removeEventListener = function(type, callback, capture) { + var rmv = Node.prototype.removeEventListener; + if (type === 'click') { + rmv.call(layer, type, callback.hijacked || callback, capture); + } else { + rmv.call(layer, type, callback, capture); + } + }; - api.bindClearEvt(); + layer.addEventListener = function(type, callback, capture) { + var adv = Node.prototype.addEventListener; + if (type === 'click') { + adv.call(layer, type, callback.hijacked || (callback.hijacked = function(event) { + if (!event.propagationStopped) { + callback(event); + } + }), capture); + } else { + adv.call(layer, type, callback, capture); + } + }; + } - $captcha.bind('input', function() { - if (trim($captcha.val()) !== '') { - $btnNext.removeClass('disable'); - } else { - $btnNext.addClass('disable'); - } - }); + // If a handler is already declared in the element's onclick attribute, it will be fired before + // FastClick's onClick handler. Fix this by pulling out the user-defined handler function and + // adding it as listener. + if (typeof layer.onclick === 'function') { - //重新发送验证码 - $captchaTip.on('touchstart', function() { - if ($captchaTip.hasClass('disable')) { - return; - } + // Android browser on at least 3.2 requires a new reference to the function in layer.onclick + // - the old one won't work if passed to addEventListener directly. + oldOnClick = layer.onclick; + layer.addEventListener('click', function(event) { + oldOnClick(event); + }, false); + layer.onclick = null; + } + } - $.ajax({ - type: 'POST', - url: (useForBind || useForRelate) ? '/passport/bind/sendBindMsg' : '/passport/' + urlMid + '/sendcode', - data: { - phoneNum: phoneNum, - areaCode: areaCode - }, - success: function(data) { - if (data.code === 200) { - $captchaTip.text('重发验证码 (60秒)').addClass('disable'); - countDown(); - } else { + /** + * Windows Phone 8.1 fakes user agent string to look like Android and iPhone. + * + * @type boolean + */ + var deviceIsWindowsPhone = navigator.userAgent.indexOf("Windows Phone") >= 0; - //验证码不正确,显示提示 - showErrTip(data.message); - } - } - }); - }); + /** + * Android requires exceptions. + * + * @type boolean + */ + var deviceIsAndroid = navigator.userAgent.indexOf('Android') > 0 && !deviceIsWindowsPhone; - $btnNext.on('touchstart', function() { - if ($btnNext.hasClass('disable')) { - return; - } - if (useForBind || useForRelate) { - if (isReg) { - startBind(); - } else { - location.href = '/passport/bind/password?phoneNum=' + - phoneNum + '&areaCode=' + areaCode + '&openId=' + - openId + '&sourceType=' + sourceType + '&nickname=' + nickname + '&code=' + trim($captcha.val()); - } + /** + * iOS requires exceptions. + * + * @type boolean + */ + var deviceIsIOS = /iP(ad|hone|od)/.test(navigator.userAgent) && !deviceIsWindowsPhone; - } else { - startReg(); - } - }); - countDown(); -}; - -}); -define("js/passport/register/password", ["jquery"], function(require, exports, module){ -/** - * 注册-密码 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/8 - */ -var $ = require("jquery"); + /** + * iOS 4 requires an exception for select elements. + * + * @type boolean + */ + var deviceIsIOS4 = deviceIsIOS && (/OS 4_\d(_\d)?/).test(navigator.userAgent); -var $pwd = $('#pwd'), - $btnSure = $('#btn-sure'); -var api = require("js/passport/api"); -var tip = require("js/plugin/tip"); + /** + * iOS 6.0-7.* requires the target element to be manually derived + * + * @type boolean + */ + var deviceIsIOSWithBadTarget = deviceIsIOS && (/OS [6-7]_\d/).test(navigator.userAgent); + + /** + * BlackBerry requires exceptions. + * + * @type boolean + */ + var deviceIsBlackBerry10 = navigator.userAgent.indexOf('BB10') > 0; -var trim = $.trim; -var showErrTip = tip.show; + /** + * Determine whether a given element requires a native click. + * + * @param {EventTarget|Element} target Target DOM element + * @returns {boolean} Returns true if the element needs a native click + */ + FastClick.prototype.needsClick = function(target) { + switch (target.nodeName.toLowerCase()) { -api.bindEyesEvt({ - status: 'open' //默认眼睛打开 -}); + // Don't send a synthetic click to disabled inputs (issue #62) + case 'button': + case 'select': + case 'textarea': + if (target.disabled) { + return true; + } -$pwd.bind('input', function() { - if (trim($pwd.val()) === '') { - $btnSure.addClass('disable'); - } else { - $btnSure.removeClass('disable'); - } -}); + break; + case 'input': -$btnSure.on('touchstart', function() { - var pwd = trim($pwd.val()); + // File inputs need real clicks on iOS 6 due to a browser bug (issue #68) + if ((deviceIsIOS && target.type === 'file') || target.disabled) { + return true; + } - if ($btnSure.hasClass('disable')) { - return; - } + break; + case 'label': + case 'iframe': // iOS8 homescreen apps can prevent events bubbling into frames + case 'video': + return true; + } - if (api.pwdValidate(pwd) === false) { - showErrTip('密码6-20位,请重新输入'); - } else { - $.ajax({ - type: 'POST', - url: '/passport/reg/setpassword', - data: { - password: pwd, - phoneNum: $('#phone-num').val(), - areaCode: $('#area-code').val(), - token: $('#token').val() - }, - success: function(data) { - var res; + return (/\bneedsclick\b/).test(target.className); + }; - if (data.code === 200) { - res = data.data; - showErrTip('注册成功'); - $.ajax({ - url: res.session, - dataType: 'jsonp' - }); + /** + * Determine whether a given element requires a call to focus to simulate click into element. + * + * @param {EventTarget|Element} target Target DOM element + * @returns {boolean} Returns true if the element requires a call to focus to simulate native click. + */ + FastClick.prototype.needsFocus = function(target) { + switch (target.nodeName.toLowerCase()) { + case 'textarea': + return true; + case 'select': + return !deviceIsAndroid; + case 'input': + switch (target.type) { + case 'button': + case 'checkbox': + case 'file': + case 'image': + case 'radio': + case 'submit': + return false; + } - //1000ms后跳转页面 - setTimeout(function() { - location.href = res.href; - }, 1000); - } else { - showErrTip(data.message); - } - } - }); - } -}); -}); -define("js/passport/login/login", ["jquery"], function(require, exports, module){ -/** - * 登录 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/9/30 - */ -var $ = require("jquery"); + // No point in attempting to focus disabled inputs + return !target.disabled && !target.readOnly; + default: + return (/\bneedsfocus\b/).test(target.className); + } + }; -var $account = $('#account'), - $pwd = $('#pwd'), - $loginBtn = $('#btn-login'), - $mask = $('#retrive-pwd-mask'), - $ways = $('#retrive-pwd-ways'), + /** + * Send a click event to the specified element. + * + * @param {EventTarget|Element} targetElement + * @param {Event} event + */ + FastClick.prototype.sendClick = function(targetElement, event) { + var clickEvent, touch; - accPass = false, - pwdPass = false; + // On some Android devices activeElement needs to be blurred otherwise the synthetic click will have no effect (#24) + if (document.activeElement && document.activeElement !== targetElement) { + document.activeElement.blur(); + } -var api = require("js/passport/api"); -var tip = require("js/plugin/tip"); + touch = event.changedTouches[0]; -var trim = $.trim; -var showErrTip = tip.show; + // Synthesise a click event, with an extra attribute so it can be tracked + clickEvent = document.createEvent('MouseEvents'); + clickEvent.initMouseEvent(this.determineEventType(targetElement), true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null); + clickEvent.forwardedTouchEvent = true; + targetElement.dispatchEvent(clickEvent); + }; -//登录按钮状态切换 -function switchLoginBtnStatus() { - if (accPass && pwdPass) { - $loginBtn.removeClass('disable'); - } else { - $loginBtn.addClass('disable'); - } -} + FastClick.prototype.determineEventType = function(targetElement) { -//显示找回密码面板 -function showRetrivePanel() { - $mask.show(); - $ways.show(); -} + //Issue #159: Android Chrome Select Box does not open with a synthetic click event + if (deviceIsAndroid && targetElement.tagName.toLowerCase() === 'select') { + return 'mousedown'; + } -//隐藏找回密码面板 -function hideRetrivePanel() { - $mask.hide(); - $ways.hide(); -} + return 'click'; + }; -//密码显示与隐藏 -api.bindEyesEvt(); -//清空账号输入框 -api.bindClearEvt(); + /** + * @param {EventTarget|Element} targetElement + */ + FastClick.prototype.focus = function(targetElement) { + var length; -$account.bind('input', function() { - if (trim($account.val()) !== '') { - accPass = true; - } else { - accPass = false; - } - switchLoginBtnStatus(); -}); + // Issue #160: on iOS 7, some input elements (e.g. date datetime month) throw a vague TypeError on setSelectionRange. These elements don't have an integer value for the selectionStart and selectionEnd properties, but unfortunately that can't be used for detection because accessing the properties also throws a TypeError. Just check the type instead. Filed as Apple bug #15122724. + if (deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month') { + length = targetElement.value.length; + targetElement.setSelectionRange(length, length); + } else { + targetElement.focus(); + } + }; -$pwd.bind('input', function() { - if (trim($pwd.val()) === '') { - pwdPass = false; - } else { - pwdPass = true; - } - switchLoginBtnStatus(); -}); + /** + * Check whether the given target element is a child of a scrollable layer and if so, set a flag on it. + * + * @param {EventTarget|Element} targetElement + */ + FastClick.prototype.updateScrollParent = function(targetElement) { + var scrollParent, parentElement; -// Login -$loginBtn.on('touchstart', function() { - var acc = trim($account.val()), - pwd = trim($pwd.val()); + scrollParent = targetElement.fastClickScrollParent; - if ($loginBtn.hasClass('disable')) { - return; - } + // Attempt to discover whether the target element is contained within a scrollable layer. Re-check if the + // target element was moved to another parent. + if (!scrollParent || !scrollParent.contains(targetElement)) { + parentElement = targetElement; + do { + if (parentElement.scrollHeight > parentElement.offsetHeight) { + scrollParent = parentElement; + targetElement.fastClickScrollParent = parentElement; + break; + } - $loginBtn.text('正在登录...').addClass('disable'); + parentElement = parentElement.parentElement; + } while (parentElement); + } - //验证账号(数字或者邮箱)和密码合理性 - if ((/^[0-9]+$/.test(acc) || api.emailRegx.test(acc)) && api.pwdValidate(pwd)) { - $.ajax({ - type: 'POST', - url: '/passport/login/auth', - data: { - account: acc, - password: pwd - }, - success: function(data) { - var res; + // Always update the scroll top tracker if possible. + if (scrollParent) { + scrollParent.fastClickLastScrollTop = scrollParent.scrollTop; + } + }; - if (data.code === 200) { - res = data.data; - showErrTip('登录成功'); - location.href = res.href; - } else { - showErrTip(data.message); - } - }, - error: function() { - showErrTip('网络断开连接啦~'); - }, - complete: function() { - $loginBtn.text('登录').removeClass('disable'); - } - }); - } else { - showErrTip('账号或密码有错误,请重新输入'); - $loginBtn.text('登录').removeClass('disable'); - } -}); + /** + * @param {EventTarget} targetElement + * @returns {Element|EventTarget} + */ + FastClick.prototype.getTargetElementFromEventTarget = function(eventTarget) { + // On some older browsers (notably Safari on iOS 4.1 - see issue #56) the event target may be a text node. + if (eventTarget.nodeType === Node.TEXT_NODE) { + return eventTarget.parentNode; + } -$('#forget-pwd').on('touchstart', function() { - showRetrivePanel(); -}); + return eventTarget; + }; -$mask.on('touchstart', function() { - hideRetrivePanel(); -}); -$('#cancel-retrive').on('touchstart', function(e) { - e.preventDefault(); - hideRetrivePanel(); -}); + /** + * On touch start, record the position and scroll offset. + * + * @param {Event} event + * @returns {boolean} + */ + FastClick.prototype.onTouchStart = function(event) { + var targetElement, touch, selection; -//对初始有默认值的情况去初始化登录按钮状态 -$account.trigger('input'); -$pwd.trigger('input'); - -}); -define("js/passport/login/international", ["jquery"], function(require, exports, module){ -/** - * 国际账号登录 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/8 - */ -var $ = require("jquery"); + // Ignore multiple touches, otherwise pinch-to-zoom is prevented if both fingers are on the FastClick element (issue #111). + if (event.targetTouches.length > 1) { + return true; + } -var $phoneNum = $('#phone-num'), - $countrySelect = $('#country-select'), - $areaCode = $('#area-code'), - $pwd = $('#pwd'), - $loginBtn = $('#btn-login'), + targetElement = this.getTargetElementFromEventTarget(event.target); + touch = event.targetTouches[0]; - pnPass = false, - pwdPass = false; + if (deviceIsIOS) { -var api = require("js/passport/api"); -var tip = require("js/plugin/tip"); + // Only trusted events will deselect text on iOS (issue #49) + selection = window.getSelection(); + if (selection.rangeCount && !selection.isCollapsed) { + return true; + } -var trim = $.trim; -var showErrTip = tip.show; + if (!deviceIsIOS4) { -//登录按钮状态切换 -function switchLoginBtnStatus() { - if (pnPass && pwdPass) { - $loginBtn.removeClass('disable'); - } else { - $loginBtn.addClass('disable'); - } -} + // Weird things happen on iOS when an alert or confirm dialog is opened from a click event callback (issue #23): + // when the user next taps anywhere else on the page, new touchstart and touchend events are dispatched + // with the same identifier as the touch event that previously triggered the click that triggered the alert. + // Sadly, there is an issue on iOS 4 that causes some normal touch events to have the same identifier as an + // immediately preceeding touch event (issue #52), so this fix is unavailable on that platform. + // Issue 120: touch.identifier is 0 when Chrome dev tools 'Emulate touch events' is set with an iOS device UA string, + // which causes all touch events to be ignored. As this block only applies to iOS, and iOS identifiers are always long, + // random integers, it's safe to to continue if the identifier is 0 here. + if (touch.identifier && touch.identifier === this.lastTouchIdentifier) { + event.preventDefault(); + return false; + } -//Android-UC下显示select的direction:rtl无效的临时解决办法 -api.selectCssHack($countrySelect); + this.lastTouchIdentifier = touch.identifier; -//显示隐藏密码 -api.bindEyesEvt(); + // If the target element is a child of a scrollable layer (using -webkit-overflow-scrolling: touch) and: + // 1) the user does a fling scroll on the scrollable layer + // 2) the user stops the fling scroll with another tap + // then the event.target of the last 'touchend' event will be the element that was under the user's finger + // when the fling scroll was started, causing FastClick to send a click event to that layer - unless a check + // is made to ensure that a parent layer was not scrolled before sending a synthetic click (issue #42). + this.updateScrollParent(targetElement); + } + } -//清空手机号码 -api.bindClearEvt(); + this.trackingClick = true; + this.trackingClickStart = event.timeStamp; + this.targetElement = targetElement; -$phoneNum.bind('input', function() { - if (trim($phoneNum.val()) === '') { - pnPass = false; - } else { - pnPass = true; - } + this.touchStartX = touch.pageX; + this.touchStartY = touch.pageY; - switchLoginBtnStatus(); -}); + // Prevent phantom clicks on fast double-tap (issue #36) + if ((event.timeStamp - this.lastClickTime) < this.tapDelay) { + event.preventDefault(); + } -$pwd.bind('input', function() { - var pwd = trim($pwd.val()); + return true; + }; - if (pwd === '') { - pwdPass = false; - } else { - pwdPass = true; - } - switchLoginBtnStatus(); -}); + /** + * Based on a touchmove event object, check whether the touch has moved past a boundary since it started. + * + * @param {Event} event + * @returns {boolean} + */ + FastClick.prototype.touchHasMoved = function(event) { + var touch = event.changedTouches[0], boundary = this.touchBoundary; -$countrySelect.change(function() { - $areaCode.text($countrySelect.val()); -}); + if (Math.abs(touch.pageX - this.touchStartX) > boundary || Math.abs(touch.pageY - this.touchStartY) > boundary) { + return true; + } -$loginBtn.on('touchstart', function() { - var pn = trim($phoneNum.val()), - areaCode = $countrySelect.val(), - pwd = trim($pwd.val()); + return false; + }; - if ($loginBtn.hasClass('disable')) { - return; - } - $loginBtn.text('正在登录...').addClass('disable'); + /** + * Update the last position. + * + * @param {Event} event + * @returns {boolean} + */ + FastClick.prototype.onTouchMove = function(event) { + if (!this.trackingClick) { + return true; + } - if (api.phoneRegx[areaCode].test(pn) && api.pwdValidate(pwd)) { - $.ajax({ - type: 'POST', - url: '/passport/login/auth', - data: { - areaCode: areaCode.replace('+', ''), - account: pn, - password: pwd - }, - success: function(data) { - var res, - time; + // If the touch has moved, cancel the click tracking + if (this.targetElement !== this.getTargetElementFromEventTarget(event.target) || this.touchHasMoved(event)) { + this.trackingClick = false; + this.targetElement = null; + } - if (data.code === 200) { - res = data.data; - showErrTip('登录成功'); + return true; + }; - $.ajax({ - url: res.session, - dataType: 'jsonp', - success: function() { - clearTimeout(time); - //Cookie写入成功后,1s后跳转页面 - setTimeout(function() { - location.href = res.href; - }, 1000); - } - }); + /** + * Attempt to find the labelled control for the given label element. + * + * @param {EventTarget|HTMLLabelElement} labelElement + * @returns {Element|null} + */ + FastClick.prototype.findControl = function(labelElement) { - //3秒后强制跳转 - time = setTimeout(function() { - location.href = res.href; - }, 3000); + // Fast path for newer browsers supporting the HTML5 control attribute + if (labelElement.control !== undefined) { + return labelElement.control; + } - showErrTip('登录成功'); - } else { - showErrTip(data.message); - } - }, - error: function() { - showErrTip('网络断开连接啦~'); - }, - complete: function() { - $loginBtn.text('登录').removeClass('disable'); - } - }); - } else { - showErrTip('账号或密码有错误,请重新输入'); - $loginBtn.text('登录').removeClass('disable'); - } -}); + // All browsers under test that support touch events also support the HTML5 htmlFor attribute + if (labelElement.htmlFor) { + return document.getElementById(labelElement.htmlFor); + } + + // If no for attribute exists, attempt to retrieve the first labellable descendant element + // the list of which is defined here: http://www.w3.org/TR/html5/forms.html#category-label + return labelElement.querySelector('button, input:not([type=hidden]), keygen, meter, output, progress, select, textarea'); + }; -//对初始有默认值的情况去初始化登录按钮状态 -$phoneNum.trigger('input'); -$pwd.trigger('input'); -}); -define("js/passport/back/mobile", ["jquery"], function(require, exports, module){ -/** - * 找回密码-手机 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/8 - */ -var $ = require("jquery"); -var $phoneNum = $('#phone-num'), - $countrySelect = $('#country-select'), - $areaCode = $('#area-code'), - $btnNext = $('#btn-next'); + /** + * On touch end, determine whether to send a click event at once. + * + * @param {Event} event + * @returns {boolean} + */ + FastClick.prototype.onTouchEnd = function(event) { + var forElement, trackingClickStart, targetTagName, scrollParent, touch, targetElement = this.targetElement; -var api = require("js/passport/api"); -var tip = require("js/plugin/tip"); + if (!this.trackingClick) { + return true; + } -var trim = $.trim; -var showErrTip = tip.show; + // Prevent phantom clicks on fast double-tap (issue #36) + if ((event.timeStamp - this.lastClickTime) < this.tapDelay) { + this.cancelNextClick = true; + return true; + } -api.selectCssHack($('#country-select')); + if ((event.timeStamp - this.trackingClickStart) > this.tapTimeout) { + return true; + } -api.bindClearEvt(); + // Reset to prevent wrong click cancel on input (issue #156). + this.cancelNextClick = false; -$phoneNum.bind('input', function() { - if (trim($phoneNum.val()) === '') { - $btnNext.addClass('disable'); - } else { - $btnNext.removeClass('disable'); - } -}); + this.lastClickTime = event.timeStamp; -$countrySelect.change(function() { - $areaCode.text($countrySelect.val()); -}); + trackingClickStart = this.trackingClickStart; + this.trackingClick = false; + this.trackingClickStart = 0; -$btnNext.on('touchstart', function() { - var pn = trim($phoneNum.val()), - area = $countrySelect.val(); + // On some iOS devices, the targetElement supplied with the event is invalid if the layer + // is performing a transition or scroll, and has to be re-detected manually. Note that + // for this to function correctly, it must be called *after* the event target is checked! + // See issue #57; also filed as rdar://13048589 . + if (deviceIsIOSWithBadTarget) { + touch = event.changedTouches[0]; - if ($btnNext.hasClass('disable')) { - return; - } + // In certain cases arguments of elementFromPoint can be negative, so prevent setting targetElement to null + targetElement = document.elementFromPoint(touch.pageX - window.pageXOffset, touch.pageY - window.pageYOffset) || targetElement; + targetElement.fastClickScrollParent = this.targetElement.fastClickScrollParent; + } - if (api.phoneRegx[area].test(pn)) { - $.ajax({ - url: '/passport/back/sendcode', - type: 'POST', - data: { - areaCode: area.replace('+', ''), - phoneNum: pn - }, - success: function(data) { - if (data.code === 200) { - location.href = data.data; - } else { - showErrTip(data.message); - } - } - }); - } else { - showErrTip('手机号格式不正确,请重新输入'); - } -}); -}); -define("js/passport/back/code", ["jquery"], function(require, exports, module){ -/** - * 找回密码-验证码 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/8 - */ + targetTagName = targetElement.tagName.toLowerCase(); + if (targetTagName === 'label') { + forElement = this.findControl(targetElement); + if (forElement) { + this.focus(targetElement); + if (deviceIsAndroid) { + return false; + } -require("js/passport/code")(false); -}); -define("js/passport/back/email", ["jquery"], function(require, exports, module){ -/** - * 找回密码-邮箱找回 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/8 - */ -var $ = require("jquery"); + targetElement = forElement; + } + } else if (this.needsFocus(targetElement)) { -var $email = $('#email'), - $btnSure = $('#btn-sure'); + // Case 1: If the touch started a while ago (best guess is 100ms based on tests for issue #36) then focus will be triggered anyway. Return early and unset the target element reference so that the subsequent click will be allowed through. + // Case 2: Without this exception for input elements tapped when the document is contained in an iframe, then any inputted text won't be visible even though the value attribute is updated as the user types (issue #37). + if ((event.timeStamp - trackingClickStart) > 100 || (deviceIsIOS && window.top !== window && targetTagName === 'input')) { + this.targetElement = null; + return false; + } -var api = require("js/passport/api"); -var tip = require("js/plugin/tip"); + this.focus(targetElement); + this.sendClick(targetElement, event); -var trim = $.trim; -var showErrTip = tip.show; + // Select elements need the event to go through on iOS 4, otherwise the selector menu won't open. + // Also this breaks opening selects when VoiceOver is active on iOS6, iOS7 (and possibly others) + if (!deviceIsIOS || targetTagName !== 'select') { + this.targetElement = null; + event.preventDefault(); + } -api.bindClearEvt(); + return false; + } -$email.bind('input', function() { - if (trim($email.val()) === '') { - $btnSure.addClass('disable'); - } else { - $btnSure.removeClass('disable'); - } -}); + if (deviceIsIOS && !deviceIsIOS4) { -$btnSure.on('touchstart', function() { - var email = trim($email.val()); + // Don't send a synthetic click event if the target element is contained within a parent layer that was scrolled + // and this tap is being used to stop the scrolling (usually initiated by a fling - issue #42). + scrollParent = targetElement.fastClickScrollParent; + if (scrollParent && scrollParent.fastClickLastScrollTop !== scrollParent.scrollTop) { + return true; + } + } - if ($btnSure.hasClass('disable')) { - return; - } + // Prevent the actual click from going though - unless the target node is marked as requiring + // real clicks or if it is in the whitelist in which case only non-programmatic clicks are permitted. + if (!this.needsClick(targetElement)) { + event.preventDefault(); + this.sendClick(targetElement, event); + } - if (api.emailRegx.test(email)) { - $.ajax({ - url: '/passport/back/sendemail', - type: 'POST', - data: { - email: email - }, - success: function(data) { - if (data.code === 200) { - location.href = data.data; - } else { - showErrTip(data.message); - } - } - }); - } else { - showErrTip('邮箱格式不正确,请重新输入'); - } -}); -}); -define("js/passport/back/email-success", ["jquery"], function(require, exports, module){ -/** - * 找回密码-邮箱找回成功 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/8 - */ + return false; + }; -var $ = require("jquery"); -var $resend = $('#resend'); + /** + * On touch cancel, stop tracking the click. + * + * @returns {void} + */ + FastClick.prototype.onTouchCancel = function() { + this.trackingClick = false; + this.targetElement = null; + }; -var tip = require("js/plugin/tip"), - showTip = tip.show; -$resend.on('touchstart', function(e) { - e.preventDefault(); + /** + * Determine mouse events which should be permitted. + * + * @param {Event} event + * @returns {boolean} + */ + FastClick.prototype.onMouse = function(event) { - $.ajax({ - url: $resend.data('url'), - type: 'GET', - success: function(data) { - showTip(data.message); - } - }); -}); -}); -define("js/passport/back/new-password", ["jquery"], function(require, exports, module){ -/** - * 密码找回-新密码 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/8 - */ -var $ = require("jquery"); + // If a target element was never set (because a touch event was never fired) allow the event + if (!this.targetElement) { + return true; + } -var $pwd = $('#pwd'), - $btnOk = $('#btn-ok'); + if (event.forwardedTouchEvent) { + return true; + } -var api = require("js/passport/api"); -var tip = require("js/plugin/tip"); + // Programmatically generated events targeting a specific element should be permitted + if (!event.cancelable) { + return true; + } -var trim = $.trim; -var showErrTip = tip.show; + // Derive and check the target element to see whether the mouse event needs to be permitted; + // unless explicitly enabled, prevent non-touch click events from triggering actions, + // to prevent ghost/doubleclicks. + if (!this.needsClick(this.targetElement) || this.cancelNextClick) { -var $phoneNum = $('#phone-num'); + // Prevent any user-added listeners declared on FastClick element from being fired. + if (event.stopImmediatePropagation) { + event.stopImmediatePropagation(); + } else { -api.bindEyesEvt({ - status: 'open' -}); + // Part of the hack for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2) + event.propagationStopped = true; + } -$pwd.bind('input', function() { - if (trim($pwd.val()) === '') { - $btnOk.addClass('disable'); - } else { - $btnOk.removeClass('disable'); - } -}); + // Cancel the event + event.stopPropagation(); + event.preventDefault(); -$btnOk.on('touchstart', function() { - var pwd = trim($pwd.val()), - mobileBack = true, - setting, - url; + return false; + } - if ($btnOk.hasClass('disable')) { - return; - } + // If the mouse event is permitted, return true for the action to go through. + return true; + }; - setting = { - password: pwd - }; - if ($phoneNum.length === 0) { - mobileBack = false; - } + /** + * On actual clicks, determine whether this is a touch-generated click, a click action occurring + * naturally after a delay after a touch (which needs to be cancelled to avoid duplication), or + * an actual click which should be permitted. + * + * @param {Event} event + * @returns {boolean} + */ + FastClick.prototype.onClick = function(event) { + var permitted; - if (mobileBack) { - $.extend(setting, { - phoneNum: $phoneNum.val(), - areaCode: $('#areaCode').val(), - token: $('#token').val() - }); + // It's possible for another FastClick-like library delivered with third-party code to fire a click event before FastClick does (issue #44). In that case, set the click-tracking flag back to false and return early. This will cause onTouchEnd to return early. + if (this.trackingClick) { + this.targetElement = null; + this.trackingClick = false; + return true; + } - url = '/passport/back/passwordByMobile'; - } else { - $.extend(setting, { - code: $('#email-code').val() - }); + // Very odd behaviour on iOS (issue #18): if a submit element is present inside a form and the user hits enter in the iOS simulator or clicks the Go button on the pop-up OS keyboard the a kind of 'fake' click event will be triggered with the submit-type input element as the target. + if (event.target.type === 'submit' && event.detail === 0) { + return true; + } - url = '/passport/back/passwordByEmail'; - } + permitted = this.onMouse(event); + // Only unset targetElement if the click is not permitted. This will ensure that the check for !targetElement in onMouse fails and the browser's click doesn't go through. + if (!permitted) { + this.targetElement = null; + } - if (api.pwdValidate(pwd)) { - $.ajax({ - type: 'POST', - url: url, - data: setting, - success: function(data) { - if (data.code === 200) { - showErrTip('密码修改成功'); + // If clicks are permitted, return true for the action to go through. + return permitted; + }; - //1000ms后跳转页面 - setTimeout(function() { - location.href = data.data; - }, 1000); - } else { - showErrTip(data.message); - } - } - }); - } else { - showErrTip('密码6-20位,请重新输入'); - } -}); -}); -define("js/passport/bind/bind", ["jquery","handlebars","source-map","hammer"], function(require, exports, module){ -/** - * 注册 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/8 - */ -var $ = require("jquery"); - -var $phoneNum = $('#phone-num'), - $countrySelect = $('#country-select'), - $areaCode = $('#area-code'), - $openId = $('#openId'), - $nickname = $('#nickname'), - $sourceType = $('#sourceType'), - $btnNext = $('#btn-next'); - -var api = require("js/passport/api"), - tip = require("js/plugin/tip"), - dialog = require("js/me/dialog"); - -var trim = $.trim; -var showErrTip = tip.show; - -var requested = false; - -require("js/common"); - -function nextStep(url, mobileNo, areaCode) { - if (requested) { - return false; - } - - requested = true; - $btnNext.addClass('disable').html('绑定中...'); - - $.ajax({ - type: 'POST', - url: '/passport/bind/sendBindMsg', - data: { - phoneNum: mobileNo, - areaCode: areaCode.replace('+', '') - }, - success: function(res) { - - if (res.code === 200) { - - // 统计代码:用于统计从哪个渠道登录 - if (window._yas && window._yas.sendCustomInfo) { - window._yas.sendCustomInfo({ - 'loginRefer' : $sourceType.val() - }, false); - } - - location.href = url; - } else { - tip.show(res.message); - } - }, - error: function() { - tip.show('出错了,请重试!'); - $btnNext.removeClass('disable').html('下一步'); - requested = false; - } - }); -} - -api.selectCssHack($('#country-select')); - -api.bindClearEvt(); - -$phoneNum.bind('input', function() { - if (trim($phoneNum.val()) === '') { - $btnNext.addClass('disable'); - } else { - $btnNext.removeClass('disable'); - } -}); - -$countrySelect.change(function() { - $areaCode.text($countrySelect.val()); -}); - -$btnNext.on('touchstart', function() { - var pn = trim($phoneNum.val()), - openId = trim($openId.val()), - nickname = trim($nickname.val()), - sourceType = trim($sourceType.val()), - areaCode = $countrySelect.val(); - - if ($btnNext.hasClass('disable')) { - return; - } - - if (api.phoneRegx[areaCode].test(pn)) { - $.ajax({ - url: '/passport/bind/bindCheck', - type: 'POST', - data: { - areaCode: areaCode.replace('+', ''), - phoneNum: pn, - openId: openId, - sourceType: sourceType, - nickname: nickname - }, - success: function(res) { - if (res.code === 200) { - if (res.data.isReg === 1) { - dialog.showDialog({ - dialogText: '该手机号已注册过有货\n' + pn + ',确定绑定吗?', - hasFooter: { - leftBtnText: '更换号码', - rightBtnText: '继续绑定' - } - }, function() { - nextStep(res.data.next, pn, areaCode); - }); - } else if (res.data.isReg === 3) { - dialog.showDialog({ - dialogText: '该手机号已注册过有货\n' + pn + ',是否进行关联?', - hasFooter: { - leftBtnText: '更换号码', - rightBtnText: '确定' - } - }, function() { - nextStep(res.data.next, pn, areaCode); - }); - } else { - nextStep(res.data.next, pn, areaCode); - } - } else { - showErrTip(res.message); - } - } - }); - } else { - showErrTip('手机号格式不正确,请重新输入'); - } -}); - -if (/MicroMessenger/i.test(navigator.userAgent) && $.queryString().refer) { - $('.go-back').attr('href', decodeURIComponent($.queryString().refer)); -} - -}); -define("js/passport/bind/code", ["jquery"], function(require, exports, module){ -/** - * 注册-验证码 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/8 - */ -require("js/passport/code")(true, true); - -}); -define("js/passport/bind/password", ["jquery"], function(require, exports, module){ -/** - * 注册-密码 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/8 - */ -var $ = require("jquery"); + /** + * Remove all FastClick's event listeners. + * + * @returns {void} + */ + FastClick.prototype.destroy = function() { + var layer = this.layer; -var $pwd = $('#pwd'), - $btnSure = $('#btn-sure'); + if (deviceIsAndroid) { + layer.removeEventListener('mouseover', this.onMouse, true); + layer.removeEventListener('mousedown', this.onMouse, true); + layer.removeEventListener('mouseup', this.onMouse, true); + } -var api = require("js/passport/api"); -var tip = require("js/plugin/tip"); + layer.removeEventListener('click', this.onClick, true); + layer.removeEventListener('touchstart', this.onTouchStart, false); + layer.removeEventListener('touchmove', this.onTouchMove, false); + layer.removeEventListener('touchend', this.onTouchEnd, false); + layer.removeEventListener('touchcancel', this.onTouchCancel, false); + }; -var trim = $.trim; -var showErrTip = tip.show; -var nickname = $('#nickname').val(), - sourceType = $('#sourceType').val(), - openId = $('#openId').val(), - phoneNum = $('#phone-num').val(), - areaCode = $('#area-code').val().replace('+', ''), - code = $('#code').val(); + /** + * Check whether FastClick is needed. + * + * @param {Element} layer The layer to listen on + */ + FastClick.notNeeded = function(layer) { + var metaViewport; + var chromeVersion; + var blackberryVersion; + var firefoxVersion; -function startBind(password) { - $.ajax({ - url: '/passport/bind/bindMobile', - type: 'post', - data: { - areaCode: areaCode.replace('+', ''), - phoneNum: phoneNum, - openId: openId, - sourceType: sourceType, - nickname: nickname, - password: password, - code: code - }, - success: function(res) { - if (res.code === 200) { - tip.show('登录成功'); - setTimeout(function() { - location.href = res.data.refer; - }, 2000); - } else { - tip.show(res.message); - } - }, - error: function(err) { - tip.show('登录失败,请重试!'); - } - }); -} + // Devices that don't support touch don't need FastClick + if (typeof window.ontouchstart === 'undefined') { + return true; + } -api.bindEyesEvt({ - status: 'open' //默认眼睛打开 -}); + // Chrome version - zero for other browsers + chromeVersion = +(/Chrome\/([0-9]+)/.exec(navigator.userAgent) || [,0])[1]; -$pwd.bind('input', function() { - if (trim($pwd.val()) === '') { - $btnSure.addClass('disable'); - } else { - $btnSure.removeClass('disable'); - } -}); + if (chromeVersion) { -$btnSure.on('touchstart', function() { - var pwd = trim($pwd.val()); + if (deviceIsAndroid) { + metaViewport = document.querySelector('meta[name=viewport]'); - if ($btnSure.hasClass('disable')) { - return; - } + if (metaViewport) { + // Chrome on Android with user-scalable="no" doesn't need FastClick (issue #89) + if (metaViewport.content.indexOf('user-scalable=no') !== -1) { + return true; + } + // Chrome 32 and above with width=device-width or less don't need FastClick + if (chromeVersion > 31 && document.documentElement.scrollWidth <= window.outerWidth) { + return true; + } + } - if (api.pwdValidate(pwd) === false) { - showErrTip('密码6-20位,请重新输入'); - } else { - startBind(pwd); - } -}); - -}); -define("js/passport/bind/relate", ["jquery"], function(require, exports, module){ -/** - * 关联手机号-验证码 - */ + // Chrome desktop doesn't need FastClick (issue #15) + } else { + return true; + } + } -require("js/passport/code")(true, false, true); - -}); -define("js/product/entry", ["jquery","swiper","mlellipsis","lazyload","iscroll-probe","hammer","handlebars","source-map","index"], function(require, exports, module){ -/** - * 产品打包入口 - * @author: liangzhifeng<zhifeng.liang@yoho.cn> - * @date: 2015/10/12 - */ + if (deviceIsBlackBerry10) { + blackberryVersion = navigator.userAgent.match(/Version\/([0-9]*)\.([0-9]*)/); -require("js/product/newsale/newarrival"); -require("js/product/newsale/discount"); -require("js/product/list"); -require("js/product/detail/detail"); -require("js/product/detail/consultform"); -require("js/product/newsale/hot-rank"); -require("js/product/product-category"); -require("js/product/shop"); + // BlackBerry 10.3+ does not require Fastclick library. + // https://github.com/ftlabs/fastclick/issues/251 + if (blackberryVersion[1] >= 10 && blackberryVersion[2] >= 3) { + metaViewport = document.querySelector('meta[name=viewport]'); + + if (metaViewport) { + // user-scalable=no eliminates click delay. + if (metaViewport.content.indexOf('user-scalable=no') !== -1) { + return true; + } + // width=device-width (or less than device-width) eliminates click delay. + if (document.documentElement.scrollWidth <= window.outerWidth) { + return true; + } + } + } + } + + // IE10 with -ms-touch-action: none or manipulation, which disables double-tap-to-zoom (issue #97) + if (layer.style.msTouchAction === 'none' || layer.style.touchAction === 'manipulation') { + return true; + } + + // Firefox version - zero for other browsers + firefoxVersion = +(/Firefox\/([0-9]+)/.exec(navigator.userAgent) || [,0])[1]; + + if (firefoxVersion >= 27) { + // Firefox 27+ does not have tap delay if the content is not zoomable - https://bugzilla.mozilla.org/show_bug.cgi?id=922896 + + metaViewport = document.querySelector('meta[name=viewport]'); + if (metaViewport && (metaViewport.content.indexOf('user-scalable=no') !== -1 || document.documentElement.scrollWidth <= window.outerWidth)) { + return true; + } + } + + // IE11: prefixed -ms-touch-action is no longer supported and it's recomended to use non-prefixed version + // http://msdn.microsoft.com/en-us/library/windows/apps/Hh767313.aspx + if (layer.style.touchAction === 'none' || layer.style.touchAction === 'manipulation') { + return true; + } + + return false; + }; + + + /** + * Factory method for creating a FastClick object + * + * @param {Element} layer The layer to listen on + * @param {Object} [options={}] The options to override the defaults + */ + FastClick.attach = function(layer, options) { + return new FastClick(layer, options); + }; + + + if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) { + + // AMD. Register as an anonymous module. + define(function() { + return FastClick; + }); + } else if (typeof module !== 'undefined' && module.exports) { + module.exports = FastClick.attach; + module.exports.FastClick = FastClick; + } else { + window.FastClick = FastClick; + } +}()); + }); -define("js/product/newsale/newarrival", ["jquery","swiper","mlellipsis","lazyload","iscroll-probe","hammer","index"], function(require, exports, module){ +define("js/home/maybe-like", ["jquery","hammer","mlellipsis","lazyload"], function(require, exports, module){ /** - * 新品到着 + * “你可能喜欢”模块JS * @author: liangzhifeng<zhifeng.liang@yoho.cn> - * @date: 2015/10/24 + * @date: 2015/10/12 */ -var $ = require("jquery"), - Swiper = require("swiper"), - ellipsis = require("mlellipsis"), - lazyLoad = require("lazyload"); +module.exports = function(specificGender) { + var $ = require("jquery"), + Hammer = require("hammer"), + tip = require("js/plugin/tip"), + loading = require("js/plugin/loading"), + ellipsis = require("mlellipsis"), + lazyLoad = require("lazyload"); + + var navHammer, + winH = $(window).height(), + $goodList = $('#goods-list'), + searching = false, + page = 0, + gender = null, + num, + url, + RECPOSE = '110001'; + + //The kidsType can be specified by the parameter. Add by @ZhaoBiao + var kidsType = specificGender === 'kids' || $('.mobile-wrap').hasClass('kids-wrap') ? true : false, + lifestyleType = specificGender === 'lifestyle' || + $('.mobile-wrap').hasClass('lifestyle-wrap') ? true : false, + yohoCoinType = $('.coin').length ? true : false, + logisticType = $('.logistic-page').length ? true : false; + var $curNav, + index, + $navList = $('#maybe-like-nav'); + + var $footer; -var swiper, - $ngc, - $pgc, - $dgc; + ellipsis.init(); -var tip = require("js/plugin/tip"), - filter = require("js/plugin/filter"), - loading = require("js/plugin/loading"); + //ajax url + if (kidsType) { + + url = '/product/recom/maylikekids'; + } else if (lifestyleType) { -var $goodsContainer = $('#goods-container'), - $goodsChildren = $goodsContainer.children(), - $ngc = $($goodsChildren.get(0)), - $pgc = $($goodsChildren.get(1)).addClass('hide'), - $dgc = $($goodsChildren.get(2)).addClass('hide'); + //有货币页面加载男生首页的数据 + url = specificGender === 'lifestyle' ? '/product/recom/maylike?gender=1,3&rec_pos=100001' : '/product/recom/maylikelife'; + } else if (yohoCoinType) { -var winH = $(window).height(), - noResult = '<p class="no-result">未找到相关搜索结果</p>'; + gender = (specificGender === 'boys' || $('.mobile-wrap').hasClass('boys-wrap')) ? + '1,3&rec_pos=100009' : '2,3&rec_pos=100009', + url = '/product/recom/maylike?gender=' + gender; + RECPOSE = 110009; -//默认筛选条件 -var defaultOpt = require("js/product/query-param"); + } else if (logisticType) { //物流页面 + gender = (specificGender === 'boys' || $('.mobile-wrap').hasClass('boys-wrap')) ? + '1,3&rec_pos=100006' : '2,3&rec_pos=100006', + url = '/product/recom/maylike?gender=' + gender; + RECPOSE = 110006; -var storeOpt = $.extend({}, defaultOpt); //存储默认筛选条件以便重置 + } else { + gender = (specificGender === 'boys' || $('.mobile-wrap').hasClass('boys-wrap')) ? + '1,3&rec_pos=100001' : '2,3&rec_pos=100002', + url = '/product/recom/maylike?gender=' + gender; + } -var now = new Date(), - month = now.getMonth() + 1, - date = now.getDate(); + //日韩馆-你可能喜欢的 + if ($('.mobile-wrap').hasClass('yoho-channel-page')) { + url = '/product/recom/newPreference?template_id=' + $.queryString().template_id; + } -var $listNav = $('#list-nav'), + //首页男生和女生,推荐位ID,埋点 + if (window.location.pathname === '/boys') { + RECPOSE = 110001; + } else if (window.location.pathname === '/girls') { + RECPOSE = 110002; + } - //导航数据信息 - navInfo = { - today: { - reload: true, - page: 0, - end: false - }, - week: { - reload: true, - page: 0, - end: false - }, - sale: { - reload: true, - page: 0, - end: false - } - }, - $pre = $listNav.find('.active'), //纪录进入筛选前的active项,初始为选中项 - searching; + $curNav = $navList.children('.focus'); -require("js/product/suspend-cart"); //悬浮购物车 + if (lifestyleType) { + navHammer = $navList[0] ? new Hammer($navList[0]) : undefined; + if (navHammer) { + navHammer.on('tap', function(e) { + var $this = $(e.target).closest('li'), + $goods = $('.goods-list'), + $content; -ellipsis.init(); + e.preventDefault(); + if ($this.hasClass('focus')) { + return; + } -$('#today a').text(month + '月' + date + '号'); + index = $this.index(); -if ($('.swiper-container .swiper-slide').length > 1) { - swiper = new Swiper('.swiper-container', { - lazyLoading: true, - lazyLoadingInPrevNext: true, - loop: true, - autoplay: 3000, - autoplayDisableOnInteraction: true, - paginationClickable: true, - pagination: '.banner-top .pagination-inner' - }); -} + $this.addClass('focus'); + $curNav.removeClass('focus'); -/** - * 筛选注册的回调,筛选子项点击后逻辑 - * 需要执行search的场景:1.点选筛选项;2.relaod为true时切换导航;3.下拉加载 - * @param opt {type, id} - */ -function search(opt) { - var setting = {}, - ext, - att, - nav, navType, - dayLimit, - page; + $goods.not('.hide').addClass('hide'); + $content = $goods.eq(index); + $content.removeClass('hide'); - if (searching) { - return; + $curNav = $this; + + $(document).trigger('scroll'); //Trigger lazyLoad + e.srcEvent.stopPropagation(); + }); + } } - if (opt) { + loading.init($('.maybe-like')); - //筛选项变更则重置reload为true - for (att in navInfo) { - if (navInfo.hasOwnProperty(att)) { - navInfo[att].reload = true; - } + function search() { + if (searching) { + return; } + searching = true; - //处理active状态 - $listNav.children('.active').removeClass('active'); - $pre.addClass('active'); + loading.showLoadingMask(); - switch (opt.type) { - case 'gender': - ext = { - gender: opt.id - }; - break; - case 'brand': - ext = { - brand: opt.id - }; - break; - case 'sort': - ext = { - sort: opt.id - }; - break; - case 'color': - ext = { - color: opt.id - }; - break; - case 'ageLevel': - ext = { - age_level: opt.id - }; - break; - case 'size': - ext = { - size: opt.id - }; - break; - case 'price': - ext = { - price: opt.id - }; - break; - case 'discount': - ext = { - discount: opt.id - }; - break; - case 'limit': - ext = { - limit: opt.id - }; - break; - case 'channel': - ext = { - channel: opt.id - }; - break; - case 'p_d': - ext = { - p_d: opt.id - }; - break; - } + //num = $goodList.find('.good-info').length; + $.ajax({ + type: 'GET', + url: url, + data: { + page: page + 1 + }, + success: function(data) { + var PRDID = []; + if (data === ' ') { + searching = false; + loading.hideLoadingMask(); + + // 有货币页面不加载底部 + if (gender && !specificGender) { + if (gender === '1,3') { + url = '/boys/bottomBanner'; + } else { + url = '/girls/bottomBanner'; + } + $.ajax({ + type: 'GET', + url: url, + success: function(data) { + if (data && data.img) { + $('#load-more-img').show(); + $('#load-more-img a').attr('href', data.url); + $('#load-more-img a > img').attr('src', data.img); + } + }, + error: function() { + } + }); + + } + return; + } + + //加载到数据后,去除bottom样式,使得footer能够随着页面长度的增加改变位置 + if (data.length > 1) { + $footer ? null : $footer = $('#yoho-footer'); + $footer.hasClass('bottom') ? $footer.removeClass('bottom') : null; + } + + num = $goodList.find('.good-info').length; + + $goodList.append(data); + + // 2015/10/31 fei.hong: 修复第一页分页不显示图片的问题 + if (num === 0) { + lazyLoad($goodList.find('.good-info').find('img.lazy')); + } else { + lazyLoad($goodList.find('.good-info:gt(' + (num - 1) + ')').find('img.lazy')); + } + + searching = false; + loading.hideLoadingMask(); + page++; - $.extend(defaultOpt, ext); //扩展筛选项 - } + $('.good-detail-text .name').each(function() { + var $this = $(this), + $title = $this.find('a'); - //导航类别 - if ($pre.hasClass('today')) { - navType = 'today'; - dayLimit = 1; - } else if ($pre.hasClass('week')) { - navType = 'week'; - dayLimit = 2; - } else if ($pre.hasClass('sale')) { - navType = 'sale'; - dayLimit = 3; + $title[0].mlellipsis(2); + }); + + //为您优选埋点 start + $(data).closest('.good-info').each(function() { + PRDID.push($(this).data('id')); + }); + window.givePoint({ + 'REC_POSE': RECPOSE, + 'PRD_ID': PRDID.join(','), + 'PRD_NUM': $(data).closest('.good-info').length, + 'ACTION_ID': 0, + 'page_num': RECPOSE === 110009 ? 1 : page + }); + //为您优选埋点 end + }, + error: function() { + tip.show('网络断开连接了~'); + searching = false; + loading.hideLoadingMask(); + } + }); } - nav = navInfo[navType]; + $('.maybe-like p').on('touchstart', function(e) { + search(); + }); - page = nav.page + 1; - if (nav.reload) { - page = 1; - } else if (nav.end) { + function scrollHandler() { + if ($(window).scrollTop() + winH >= $(document).height() - 200) { + search(); + } + } - //不需要重新加载并且数据请求结束 - return; + // 优惠券页面直接加载你可能喜欢。add by @zhaobiao + if (specificGender) { + search(); } - $.extend(setting, defaultOpt, { - dayLimit: dayLimit, - page: page + //srcoll to load more + $(window).scroll(function() { + window.requestAnimationFrame(scrollHandler); }); - searching = true; - loading.showLoadingMask(); + //为您优选埋点 http://redmine.yoho.cn/issues/10116 + $('.maybe-like .goods-list').on('click', 'a', function() { + var index = $(this).closest('.good-info').index() + 1, + pageNum = 50; + window.givePoint({ + 'REC_POSE': RECPOSE, + 'PRD_ID': $(this).closest('.good-info').data('id'), + 'PRD_NUM': index % pageNum === 0 ? pageNum : index % pageNum, + 'ACTION_ID': 1, + 'page_num': Math.ceil(index / pageNum) + }); + return true; + }); +}; - $.ajax({ - type: 'GET', - url: '/product/newsale/selectNewSale', - data: setting, - success: function(data) { - var $container, - num; +}); +define("js/index/entry", ["jquery","hammer","handlebars","source-map","swiper","index"], function(require, exports, module){ +/** + * Index打包入口 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/19 + */ + +require("js/index/search"); +require("js/index/footer"); +require("js/index/channel"); +require("js/index/coupon"); +}); +define("js/index/search", ["jquery","hammer","handlebars","source-map"], function(require, exports, module){ +/** + * 搜索JS + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/19 + */ - switch (navType) { - case 'today': - $container = $ngc; - break; - case 'week': - $container = $pgc; - break; - case 'sale': - $container = $dgc; - break; - } +var $ = require("jquery"), + security = require("js/plugin/security"), + tip = require("js/plugin/tip"), + Hammer = require("hammer"), + dialog = require("js/me/dialog"); - if (data === ' ') { - nav.end = true; - if (nav.reload) { - $container.html(noResult); - } - } else { - if (nav.reload) { - $container.html(data); - lazyLoad($container.find('.lazy')); - } else { - num = $container.find('.good-info').length; - $container.append(data); +var $input = $('#search-input input'); - //lazy good-infos who append in - lazyLoad($container.find('.good-info:gt(' + (num - 1) + ') .lazy')); - } +var $clear = $('#search-input .clear-input'); - } +var $form = $('#search-form'); - nav.reload = false; - nav.page = page; +var $history = $('.history'); +var $historySearch = $('.history-search'); +var $clearHistory = $('#clear-history'); +var $buriedpoint = $('.buriedpoint'); +var $search = $('#search'); +var searchUrl = $search.closest('form').attr('action'); - searching = false; - loading.hideLoadingMask(); +var writeSearch = require("js/index/write-search"); - window.rePosFooter(); +var ranToken = writeSearch.getRanToken(); +var historyval = writeSearch.getHistoryval(); - $('.good-detail-text .name').each(function() { - var $this = $(this), - $title = $this.find('a'); +var chHammer, cHammer; - $title[0].mlellipsis(2); - }); - }, - error: function() { - tip.show('网络断开连接了~'); - searching = false; - loading.hideLoadingMask(); +chHammer = new Hammer($clearHistory[0]); + +chHammer.on('tap', function() { + dialog.showDialog({ + dialogText: '您确定要删除您的最近搜索吗?', + hasFooter: { + leftBtnText: '取消', + rightBtnText: '确定' } - }); + }, function() { -} + if (localStorage) { + localStorage.removeItem(historyval); + } -$.ajax({ - type: 'GET', - url: '/product/newsale/filter', - data: defaultOpt, - success: function(data) { - $goodsContainer.append(data); + $history.html(''); + $historySearch.hide(); + $clearHistory.hide(); - //初始化filter&注册filter回调 - filter.initFilter({ - fCbFn: search, - hCbFn: function() { + window.rePosFooter(); - //切换active状态到$pre上 - $pre.addClass('active'); - $pre.siblings('.filter').removeClass('active'); - } + dialog.showDialog({ + dialogText: '删除成功', + autoHide: true, + fast: true }); - } + }); }); -lazyLoad($('.lazy')); -$listNav.bind('contextmenu', function(e) { - return false; -}); +// 搜索输入联动 +function inputAction() { + var $searchAssociate = $('.search-associate'); + var $icon = $('.search-icon'); + var $searchItems = $('.search-items'); -//导航栏点击逻辑说明: -//1.点击非active项时切换active状态 -//2.价格和折扣active状态时继续点击切换排序 -//3.筛选无active时点击展开筛选面板 -//4.筛选有active时点击隐藏筛选面板并恢复点击筛选前active项的active状态 -//5.当前active为筛选并且点击其他项时,隐藏筛选面板 -// navHammer = new Hammer($listNav[0]); -$listNav.on('touchend touchcancel', function(e) { - var $this = $(e.target).closest('li'), - nav, - navType, - $active; + $input.on('input', function() { + if ($input.val() === '') { + $icon.css('color', '#b2b2b2'); + $clear.addClass('hide'); + $searchAssociate.html(''); + $searchItems.show(); + $searchAssociate.hide(); + } else { + $icon.css('color', '#666'); + $clear.removeClass('hide'); + $searchAssociate.show(); + } + + // 联动搜索 + $.ajax({ + url: '/index/search/fuzzyDatas', + data: { + keyword: $input.val() + }, + dataType: 'json', + success: function(data) { + var ajaxHtml = ''; + var i; + + if (data.length > 0) { + for (i = 0; i < data.length; i++) { + ajaxHtml += '<li><span class="keyword">' + data[i].keyword + '</span><span class="count">' + + data[i].count + ' items<i class="iconfont"></i></span></li>'; + } + + $searchAssociate.html(ajaxHtml); + $searchItems.hide(); + } else { + $searchAssociate.html(''); + } - e.preventDefault(); - if ($this.hasClass('filter')) { + $searchAssociate.find('li').on('touchend', function() { + GoSearch($(this).find('.keyword').html()); + }); + }, + error: function() { + tip.show('网络断开连接了~'); + } + }); + }); +} - //筛选面板切换状态 - if ($this.hasClass('active')) { - filter.hideFilter(); +//跳到搜索页 +function GoSearch(query) { + //保存搜索的内容 + writeSearch.setHistoryValFun(query); + document.location.href = searchUrl + '?query=' + query; +} - //点击筛选钱的active项回复active - $pre.addClass('active'); - $this.removeClass('active'); - } else { - $pre = $this.siblings('.active'); +//热门搜索、最近搜索事件 +$('.search-items .search-group').on('click', 'li', function(event) { + var query = ''; - $pre.removeClass('active'); - $this.addClass('active'); - filter.showFilter(); - } - } else { + if (event.target.nodeName === 'A') { + query = $(event.target).html(); + } - if ($this.hasClass('today')) { - navType = 'today'; - } else if ($this.hasClass('week')) { - navType = 'week'; - } else if ($this.hasClass('sale')) { - navType = 'sale'; - } + if (event.target.nodeName === 'LI') { + query = $(event.target).find('a').html(); + } - nav = navInfo[navType]; + GoSearch(query); +}); - if (!($this.hasClass('active'))) { +inputAction(); - $active = $this.siblings('.active'); +cHammer = new Hammer($clear[0]); +cHammer.on('tap', function() { + $input.val('').trigger('input'); +}); - $pre = $this; //$pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项 +$search.on('touchend', function() { + var $buriedpoint = $form.find('.buriedpoint'); - if ($active.hasClass('filter')) { + if ($buriedpoint.val() === '') { + $buriedpoint.val($('#default-terms').val()); + } - //若之前active项为筛选,则隐藏筛选面板 - filter.hideFilter(); - } else { + //保存搜索的内容 + writeSearch.setHistoryValFun($buriedpoint.val()); - //切换container显示 - $goodsContainer.children('.container:not(.hide)').addClass('hide'); + if (security.hasDangerInput()) { + return false; + } - switch (navType) { - case 'today': - $ngc.removeClass('hide'); - break; + $(this).closest('form').submit(); + return false; +}); - case 'week': - $pgc.removeClass('hide'); - break; +//初始化历史搜索的内容 +(function() { + var html = '', + history, + historys, i, num = 1; - case 'sale': - $dgc.removeClass('hide'); - break; - } + if (localStorage) { + historys = localStorage.getItem(historyval); - //重置筛选项 - filter.resetFilter(); - defaultOpt = $.extend({}, storeOpt); - } + if (historys && historys.length > 0) { + historys = historys.split(ranToken); + for (i = historys.length; i > 0; i--) { + history = historys[i - 1]; - $active.removeClass('active'); - $this.addClass('active'); - } + if (history === '') { + continue; + } - if (nav.reload) { - search(); - } - } - e.stopPropagation(); -}); + if (num++ > 10) { + break; + } -function scrollHandler() { + html += '<li><a href="javascript:void(0);">' + history + '</li>'; + } - //当scroll到1/4$goodsContainer高度后继续请求下一页数据 - if ($(window).scrollTop() + winH > - $(document).height() - 0.25 * $goodsContainer.height() - 50) { - if ($pre !== undefined) { - search(); + $history.html(html); + if (html !== '') { + $clearHistory.removeClass('hide'); + $historySearch.removeClass('hide'); + } + window.rePosFooter(); } } -} - -//srcoll to load more -$(window).scroll(function() { - window.requestAnimationFrame(scrollHandler); +}()); }); +define("js/plugin/security", ["jquery"], function(require, exports, module){ +/** + * 校验input, 防止SQL注入 + * @author: 赵彪<bill.zhao@yoho.cn> + * @date: 2015/11/30 + */ + +var $ = require("jquery"), + tip = require("js/plugin/tip"); + +/** + * hasStrangeInput() return true when input have danger value + * + * @param {Bool} needConvert Set if the danger input value should be converted to space + * @return {Bool} true/false If the input have danger value + */ +function hasDangerInput(needConvert) { + + var $inputs = $('input[type!=hidden], textarea'); + + var validationPartten = /['"<>&\|]|--/g, + inputsLength = $inputs.length, + val, + i, + matchChars, + + // to set if the input value should be coverted, and its default value is true; + willConvert = needConvert === undefined || typeof needConvert !== 'boolean' ? true : needConvert; + + + for (i = 0; i < inputsLength; i++) { + val = $inputs.eq(i).val(); + if (validationPartten.test(val)) { + if (willConvert) { + $inputs.eq(i).val(val.replace(validationPartten, ' ')); + } else { + matchChars = val.match(validationPartten).join(' '); + tip.show('不可以输入 ' + matchChars + ' 哦!'); + } + + + return !willConvert && true; + } + } + + + return false; +} + + +exports.hasDangerInput = hasDangerInput; -//初始请求最新第一页数据 -search(); - -$listNav.on('touchstart', 'li', function(e) { - $(this).addClass('bytouch'); -}).on('touchend touchcancel', function() { - $listNav.find('li').removeClass('bytouch'); }); +define("js/me/dialog", ["jquery","handlebars","source-map","hammer"], function(require, exports, module){ +/* + * @Description: dialog + * @Time: 2015/11/18 + * @author: chenglong.wang + */ + +var $ = require("jquery"), + Handlebars = require("handlebars"), + Hammer = require("hammer"); + +var $dialogWrapper, + dialogTpl, + dialogTemplate; + +function getInstance() { + if (dialogTpl === undefined) { + dialogTpl = '<div id="dialog-wrapper" class="dialog-wrapper">' + + '<div class="dialog-box">' + + '{{# hasHeader}}' + + '{{/ hasHeader}}' + + '<div class="dialog-content">{{dialogText}}</div>' + + '{{# hasFooter}}' + + '<div class="dialog-footer">' + + '{{# leftBtnText}}' + + '<span class="dialog-left-btn tap-hightlight">{{.}}</span>' + + '{{/ leftBtnText}}' + + '{{# rightBtnText}}' + + '<span class="dialog-right-btn tap-hightlight">{{.}}</span>' + + '{{/ rightBtnText}}' + + '</div>' + + '{{/ hasFooter}}' + + '</div>' + + '</div>'; + + dialogTemplate = Handlebars.compile(dialogTpl); + } + return dialogTemplate; +} + +// fullWithBtn是供详情页获取限购码使用的特殊参数 +exports.showDialog = function(data, callback, callbackForLeft, fullWithBtn) { + + var dialogTemplate = getInstance(), + dialogStr = dialogTemplate(data), + $dialogBox, + defaultHideDuraton, + dialogWrapperHammer; + + $('.dialog-wrapper').remove(); + + $('body').append($(dialogStr)); + + $dialogBox = $('.dialog-box'); + $dialogWrapper = $('.dialog-wrapper'); + + + dialogWrapperHammer = new Hammer(document.getElementById('dialog-wrapper')); + + // 显示 + if (data.fast) { + $dialogWrapper.css({ + display: 'block' + }); + } else { + $dialogWrapper.fadeIn(); + } + + if (fullWithBtn) { + $('.dialog-wrapper .dialog-footer > span').css('width', '100%'); + $('.dialog-wrapper .dialog-content').css({ + 'padding-left': '1.85rem', + 'padding-right': '1.85rem' + }); + $dialogWrapper.css('z-index', '10'); + } + + $dialogBox.css({ + top: '50%', + marginTop: -($dialogBox.height() / 2) + }); + + //隐藏 + if (data.autoHide) { + defaultHideDuraton = 1000; + if (data.autoHide > 1) { + defaultHideDuraton = data.autoHide; + } + setTimeout(function() { + $dialogWrapper.fadeOut(); + }, defaultHideDuraton); + } + + //禁止在dialog上可以上下滚动 + $dialogWrapper.on('touchmove', function() { + return false; + }); + + dialogWrapperHammer.on('tap', function(event) { + + if ($(event.target).hasClass('dialog-left-btn')) { + if (typeof callbackForLeft === 'function') { + callbackForLeft(); + } + $dialogWrapper.fadeOut(); + } else if ($(event.target).hasClass('dialog-right-btn')) { + callback(); + } + + // 防止出现点透问题 + event.preventDefault(); + event.srcEvent.stopPropagation(); + }); +}; + +exports.hideDialog = function() { + $('.dialog-wrapper').remove(); +}; }); -define("js/plugin/filter", ["jquery","iscroll-probe","hammer"], function(require, exports, module){ +define("js/index/write-search", [], function(require, exports, module){ /** - * 筛选JS - * 暴露三个接口:注册回调、显示filter、隐藏filter + * 将搜索结果存localStorage * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/19 + * @date: 2015/10/29 */ -var $ = require("jquery"), - IScroll = require("iscroll-probe") - Hammer = require("hammer"); - -var $filter; - -var fCbFn, hCbFn; //筛选和关闭的回调 - -var missStatus; //是否忽略选中状态 - -//隐藏筛选界面 -function hideFilter() { - $filter.addClass('hide'); -} +var ranToken = ',', + historyval = 'historys1'; -//显示筛选界面 -function showFilter() { - $filter.removeClass('hide'); +//获取分隔符 +function getRanToken() { + return ranToken; } -// 一级菜单点击时背景高亮 -function highlightMainItem() { - var $mainItem = $('.filter-body .classify'); - - $mainItem.on('touchstart', '.shower', function() { - var bpIdData = $(this).attr('data-bp-id') || ''; - - $mainItem.removeClass('highlight'); - $(this).addClass('highlight'); - - $(document).trigger('shouldSendBpData', [bpIdData]); - }).on('touchend touchcancel', '.shower', function() { - $(this).removeClass('highlight'); - }); +//存变量 +function getHistoryval() { + return historyval; } -// 子菜单点击时背景高亮 -function highlightSubItem() { - var $subItem = $('.filter-body .sub-item'); +//绑定提交前的存local操作 +function bindWirteLocal($form) { + $form.on('submit', function() { + var query = this.query.value; - $subItem.on('touchstart', function() { - $subItem.removeClass('highlight'); - $(this).addClass('highlight'); - }).on('touchend touchcancel', function() { - $(this).removeClass('highlight'); + setHistoryValFun(query); }); } -//主筛选项Tap事件句柄 -function classifyTapEvt($this) { - if ($this.hasClass('active')) { - return; - } - - $this.siblings('.active').removeClass('active'); - - $this.addClass('active'); - -} - -//子筛选项选中处理 -function setSubClassify($this) { - var $sub = $this.closest('.sub-classify'); - - var $shower = $sub.siblings('.shower'); - - var html, shower; - - if ($this.hasClass('chosed')) { - return $sub; - } - - $sub.children('.chosed').removeClass('chosed'); - $this.addClass('chosed'); - - html = $.trim($this.html()); - - shower = $.trim($shower.html()); - - $shower.html( - shower.substring(0, shower.indexOf('</span>') + 7) + //拆分出shower的title - html.substring(0, html.indexOf('<i')) //拆分选中筛选值 - ); - - if ($this.index() === 0) { - $shower.addClass('default'); - } else { - $shower.removeClass('default'); - } - - return $sub; -} - -//子筛选项Tap句柄 -function subClassifyTapEvt($this) { - var id = $this.data('id'); +function setHistoryValFun(query) { + var historys; + if (localStorage) { + historys = localStorage.getItem(historyval); - var $sub; + historys = historys ? historys.replace(new RegExp((query + ranToken), 'g'), '') : ''; - $sub = setSubClassify($this); + if (historys === '') { + query = ranToken + query; + } - if (fCbFn) { - fCbFn({ - type: $sub.data('type'), - id: id - }); + historys += query + ranToken; + localStorage.setItem(historyval, historys); } - - hideFilter(); } -//初始化筛选 -function initFilter(opt) { - var filterHammer; - - //注册回调 - fCbFn = opt.fCbFn; - hCbFn = opt.hCbFn; - - missStatus = opt.missStatus; - - highlightMainItem(); - highlightSubItem(); - - $filter = $('.filter-mask'); - - filterHammer = new Hammer($filter[0]); - filterHammer.on('tap', function(e) { - var $this = $(e.target), - $cur; - // e.preventDefault();//防止透点 - - if ($this.closest('.filter-body').length > 0) { - $cur = $this.closest('.sub-item'); - if ($cur.length > 0) { - - //tap subclassify - $cur = $this.closest('li'); - - subClassifyTapEvt($cur); - } else { - - //tap classify - $cur = $this.closest('.classify-item'); +exports.getRanToken = getRanToken; +exports.getHistoryval = getHistoryval; +exports.setHistoryValFun = setHistoryValFun; - e.srcEvent.stopPropagation(); +exports.bindWirteLocal = bindWirteLocal; +}); +define("js/index/footer", ["jquery","hammer"], function(require, exports, module){ +/** + * 底部JS + * @author: liangzhifeng<zhifeng.liang@yoho.cn> + * @date: 2015/10/26 + */ - classifyTapEvt($cur); - } - } else { - hideFilter(); +var $ = require("jquery"), + Hammer = require("hammer"); - if (hCbFn) { - hCbFn(); - } - } - }); - if(opt.isScroll){ - $("ul.sub-classify").each(function(){ +var floatLayerBtnHammer; - $(this).wrap("<div class='sub-classify-farther' data-type='" + $(this).data("type") + "'></div>"); - // $(this).removeClass("sub-classify"); +require("js/common"); - var lastY=0,y=0; - var $slider=$(this); +/** + * 获取url参数 + */ +function getQueryString(name) { + var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'); + var r = window.location.search.substr(1).match(reg); - $slider.on('touchstart', function(e) { - lastY = e.originalEvent.touches[0].pageY; - }); - $slider.on('touchmove', function(e) { - var curY = e.originalEvent.touches[0].pageY; - var deltaY = curY - lastY; - var height = $(this)[0].scrollHeight; - var limit = height - $(this).parent().height(); - y = y + deltaY; - if (y < limit * -1) - y = limit * -1; - if (y > 0) - y = 0; - var translate = 'translate3d(0,' + y + 'px,0)'; - $(this).css({ - '-moz-transform': translate, - '-ms-transform': translate, - 'transform': translate, - '-webkit-transform': translate, - }); - lastY = curY; - }); - $slider.on('touchend', function(e) {}); - }); + if (r != null) { + return window.unescape(r[2]); } - - + return null; } -//重置筛选面板 -function resetFilter() { - if (typeof $filter === 'undefined') { - return; - } +function downLoadApp() { + var appUrl = 'http://www.yohoshow.com/about/index/yohobuyqr/'; + var clickedAt = new Date(); - //重置子筛选项 - $('.sub-classify').each(function() { - setSubClassify($(this).children(':first-child')); - }); + setTimeout(function() { + var mkt = getQueryString('mkt_code'); - //重置主筛选项 - classifyTapEvt($('.classify > :first-child')); + if ((new Date()) - clickedAt < 2000) { + if (mkt) { + appUrl += '?union_type=' + mkt; + } + window.location = appUrl; + } + }, 500); } -exports.initFilter = initFilter; - -exports.showFilter = showFilter; +$('#float-layer-close').on('touchend', function(e) { + $('#float-layer-app').hide(); + window.setCookie('_float-layer-app', 'id490655927', + { + domain: '.yohobuy.com' + }); + window.setCookie('_float-layer-app-close', 1, + { + domain: '.yohobuy.com', + expires: 1 + }); + return false; +}); -exports.hideFilter = hideFilter; +if ($('#float-layer-btn') && $('#float-layer-btn')[0]) { + floatLayerBtnHammer = new Hammer($('#float-layer-btn')[0]); + floatLayerBtnHammer.on('tap', function(e) { + downLoadApp('bottom'); + e.srcEvent.stopPropagation(); + }); -exports.resetFilter = resetFilter; + if (typeof window.cookie === 'function' && !window.cookie('_float-layer-app')) { + $('#float-layer-app').show(); + } else { + $('#float-layer-app').hide(); + } +} }); -define("js/product/query-param", ["jquery"], function(require, exports, module){ +define("js/index/channel", ["jquery","hammer"], function(require, exports, module){ /** - * 提取查询参数 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/11/19 + * 频道选择页面顶部搜索 + * @author: bikai<kai.bi@yoho.cn> + * @date: 2015/10/28 */ - var $ = require("jquery"), - opt = {}; + security = require("js/plugin/security"); -$('.query-param').each(function() { - var $this = $(this); +var $searchBox = $('.search-box'), + $box = $('.box'), + $indexSearch = $('.index-search'), + $indexLogo = $('.index-logo'), + $channelLink = $('.index-channel a:not(#yohood)'); - opt[$this.data('attr')] = $this.val(); -}); +var $search = $searchBox.children('input[type="text"]'), + $cancelSearch = $box.children('.no-search'), + $searchIcon = $searchBox.children('.search-icon'); -module.exports = opt; -}); -define("js/product/suspend-cart", ["jquery"], function(require, exports, module){ -/** - * 悬浮购物车 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/11/1 - */ +require("js/common"); -var $ = require("jquery"); +$search.on('focus', function() { + $box.addClass('action'); + $indexLogo.addClass('action'); +}).on('input', function() { + if ($search.val() === '') { + $searchIcon.addClass('empty'); + } else { + $searchIcon.removeClass('empty'); + } +}); -var $cart = $('#suspend-cart'); +$cancelSearch.on('touchend', function() { + $box.removeClass('action'); + $indexLogo.removeClass('action'); + $search.blur(); + return false; +}); -$.ajax({ - type: 'GET', - url: '/cart/index/count', - success: function(data) { - var count; +$searchBox.children('.clear-text').on('touchstart', function() { + $search.val('').focus().trigger('input'); +}); - if (data.code === 200) { - count = data.data.cart_goods_count; - if (count > 99) { - count = '99+'; - } - if (count === 0) { - $('.cart-count').remove(); - } - $cart.find('.cart-count').html(count).removeClass('hide'); +$searchBox.children('.search-icon').on('touchstart', function() { + if (security.hasDangerInput()) { + return false; + } + $indexSearch.submit(); +}); + +$searchBox.keyup(function(e) { + if (e.keyCode === 13) { + if (security.hasDangerInput()) { + return false; } + $indexSearch.submit(); } }); + +$('.index-channel img').on('load error', function() { + window.rePosFooter && window.rePosFooter(); +}); + +$channelLink.on('touchstart', function() { + $channelLink.css({ + background: '#000', + color: '#fff', + borderColor: '#fff' + }); + $(this).css({ + background: 'rgba(255, 255, 255, 0.5)', + color: '#000', + borderColor: '#000' + }); +}).on('touchend touchcancel', function() { + $(this).css({ + background: '#000', + color: '#fff', + borderColor: '#fff' + }); +}); -}); -define("js/product/newsale/discount", ["jquery","swiper","mlellipsis","lazyload","iscroll-probe","hammer","index"], function(require, exports, module){ -/** - * 商品列表页 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/20 - */ - -var $ = require("jquery"), - Swiper = require("swiper"), - ellipsis = require("mlellipsis"), - lazyLoad = require("lazyload"); - -var swiper; - -var tip = require("js/plugin/tip"), - filter = require("js/plugin/filter"), - loading = require("js/plugin/loading"); - -var $goodsContainer = $('#goods-container'), - $goodsChildren = $goodsContainer.children(), - $ngc = $($goodsChildren.get(0)), - $pgc = $($goodsChildren.get(1)), - $dgc = $($goodsChildren.get(2)); - -var winH = $(window).height(), - noResult = '<p class="no-result">未找到相关搜索结果</p>'; - -//默认筛选条件 -var defaultOpt = require("js/product/query-param"); - -var $listNav = $('#list-nav'), - - //导航数据信息 - navInfo = { - newest: { - order: 1, - reload: true, - page: 0, - end: false - }, - price: { - order: 1, - reload: true, - page: 0, - end: false - }, - discount: { - order: 1, - reload: true, - page: 0, - end: false - } - }, - $pre = $listNav.find('.active'), //纪录进入筛选前的active项,初始为选中项 - searching; - -require("js/product/suspend-cart"); //悬浮购物车 - -ellipsis.init(); - -if ($('.swiper-container .swiper-slide').length > 1) { - swiper = new Swiper('.swiper-container', { - lazyLoading: true, - lazyLoadingInPrevNext: true, - loop: true, - autoplay: 3000, - autoplayDisableOnInteraction: true, - paginationClickable: true, - pagination: '.banner-top .pagination-inner' - }); -} - +}); +define("js/index/coupon", ["jquery","swiper","index"], function(require, exports, module){ /** - * 筛选注册的回调,筛选子项点击后逻辑 - * 需要执行search的场景:1.点选筛选项;2.relaod为true时切换导航;3.下拉加载 - * @param opt {type, id} + * Created by Administrator on 2016/4/13. */ -function search(opt) { - var setting = {}, - ext, - att, - nav, navType, - page; - - if (searching) { - return; - } - - if (opt) { - - //筛选项变更则重置reload为true - for (att in navInfo) { - if (navInfo.hasOwnProperty(att)) { - navInfo[att].reload = true; - } - } +var $ = require("jquery"), + Swiper = require("swiper"), + $receive = $('.main-right-receive'), + $mask = $('.floor-mask'), + $message = $('.floor-message'), + $tooltip = $('.floor-tooltip'), + tip = require("js/plugin/tip"); - //处理active状态 - $listNav.children('.active').removeClass('active'); - $pre.addClass('active'); +var bannerSwiper; - switch (opt.type) { - case 'gender': - ext = { - gender: opt.id - }; - break; - case 'brand': - ext = { - brand: opt.id - }; - break; - case 'ageLevel': - ext = { - age_level: opt.id - }; - break; - case 'sort': - ext = { - sort: opt.id - }; - break; - case 'color': - ext = { - color: opt.id - }; - break; - case 'size': - ext = { - size: opt.id - }; - break; - case 'price': - ext = { - price: opt.id - }; - break; - case 'discount': - ext = { - discount: opt.id - }; - break; - } +// 获取url中的参数 +function getUrlParam(name) { - $.extend(defaultOpt, ext); //扩展筛选项 - } + // 构造一个含有目标参数的正则表达式对象 + var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)'); + // 匹配目标参数 + var r = window.location.search.substr(1).match(reg); - //导航类别 - if ($pre.hasClass('new')) { - navType = 'newest'; - } else if ($pre.hasClass('price')) { - navType = 'price'; - } else if ($pre.hasClass('discount')) { - navType = 'discount'; + // 返回参数值 + if (r != null) { + return r[2]; } - nav = navInfo[navType]; + return null; +} - page = nav.page + 1; - if (nav.reload) { - page = 1; - } else if (nav.end) { +$receive.on('click', function() { + var $curDom = $(this), + req = ''; - //不需要重新加载并且数据请求结束 - return; + if (getUrlParam('app_version')) { + req += '&app_version=' + getUrlParam('app_version'); } - $.extend(setting, defaultOpt, { - type: navType, - order: nav.order, - page: page - }); - - searching = true; - loading.showLoadingMask(); + if (getUrlParam('uid')) { + req += '&uid=' + getUrlParam('uid'); + } $.ajax({ - type: 'GET', - url: '/product/newsale/selectNewSale', - data: setting, + url: '//m.yohobuy.com/coupon/receiveCoupon?code=' + getUrlParam('code') + req, + data: { + couponID: $curDom.parents('.coupon-floor').attr('coupon-id') + }, + dataType: 'json', success: function(data) { - var $container, - num; - - switch (navType) { - case 'newest': - $container = $ngc; - break; - case 'price': - $container = $pgc; - break; - case 'discount': - $container = $dgc; - break; - } + var msg = data.msg, + status = data.status, + newUrl = data.url + '?code=' + getUrlParam('code'); - if (data === ' ') { - nav.end = true; - if (nav.reload) { - $container.html(noResult); + if (data.isApp === true) { + newUrl = data.url; + } + if (data.noLogin === true) { + if ($('#intimacy-link').length <= 0) { + $('body').append('<a href=\'' + newUrl + '\' style="display:none;" id="intimacy-link">' + + '<span class="intimacy-link"></span></a>'); } + + $('.intimacy-link').click(); } else { - if (nav.reload) { - $container.html(data); - lazyLoad($container.find('.lazy')); - } else { - num = $container.find('.good-info').length; - $container.append(data); + if (status) { + $curDom.hide(); + $curDom.next().show(); + $tooltip.show(); - //lazy good-infos who append in - lazyLoad($container.find('.good-info:gt(' + (num - 1) + ') .lazy')); + setTimeout(function() { + $tooltip.hide(); + }, 3000); + } else { + $message.find('.coupon-message-content').text(msg); + $mask.show(); + $message.show(); } } + }, + error: function() { + tip.show('网络异常!'); + } + }); +}); - nav.reload = false; - nav.page = page; +$('.coupon-floor a, .banner-top a').on('click', function() { + if ($(this).attr('href').length <= 0 || $(this).attr('href') === '#') { + return false; + } +}); - searching = false; - loading.hideLoadingMask(); +if ($('.banner-swiper').find('li').length > 1) { + bannerSwiper = new Swiper('.banner-swiper', { + lazyLoading: true, + lazyLoadingInPrevNext: true, + loop: true, + autoplay: 3000, + autoplayDisableOnInteraction: false, + paginationClickable: true, + slideElement: 'li', + pagination: '.banner-top .pagination-inner' + }); +} - window.rePosFooter(); +$('.coupon-message-op-rel').on('click', function() { + location.reload(); +}); - $('.good-detail-text .name').each(function() { - var $this = $(this), - $title = $this.find('a'); +if ($('#noData').length > 0) { + if (location.href.indexOf('?openby:yohobuy=') <= 0) { + tip.show('网络异常!'); + } +} - $title[0].mlellipsis(2); - }); - }, - error: function() { - tip.show('网络断开连接了~'); - searching = false; - loading.hideLoadingMask(); - } - }); +$mask.on('click', function() { + $mask.hide(); + $message.hide(); +}); + + +}); +define("js/passport/entry", ["jquery","handlebars","source-map","hammer"], function(require, exports, module){ +/** + * 注册、登录、密码找回打包入口 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/8 + */ + +//注册 +require("js/passport/register/register"); +require("js/passport/register/code"); +require("js/passport/register/password"); + +//登录 +require("js/passport/login/login"); +require("js/passport/login/international"); + +//密码找回 +require("js/passport/back/mobile"); +require("js/passport/back/code"); +require("js/passport/back/email"); +require("js/passport/back/email-success"); +require("js/passport/back/new-password"); + +//绑定手机 +require("js/passport/bind/bind"); +require("js/passport/bind/code"); +require("js/passport/bind/password"); + +// 关联手机 +require("js/passport/bind/relate"); -} +}); +define("js/passport/register/register", ["jquery"], function(require, exports, module){ +/** + * 注册 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/8 + */ +var $ = require("jquery"); + +var $phoneNum = $('#phone-num'), + $countrySelect = $('#country-select'), + $areaCode = $('#area-code'), + $btnNext = $('#btn-next'); + +var api = require("js/passport/api"); +var tip = require("js/plugin/tip"); + +var trim = $.trim; +var showErrTip = tip.show; + +var requested = false; + +api.selectCssHack($('#country-select')); + +api.bindClearEvt(); + +$phoneNum.bind('input', function() { + if (trim($phoneNum.val()) === '') { + $btnNext.addClass('disable'); + } else { + $btnNext.removeClass('disable'); + } +}); + +$countrySelect.change(function() { + $areaCode.text($countrySelect.val()); +}); + +$btnNext.on('touchstart', function() { + var pn = trim($phoneNum.val()), + areaCode = $countrySelect.val(); + + if ($btnNext.hasClass('disable')) { + return; + } + + if (requested) { + return false; + } + + + if (api.phoneRegx[areaCode].test(pn)) { + + requested = true; + + $.ajax({ + url: '/passport/reg/verifymobile', + type: 'POST', + data: { + areaCode: areaCode.replace('+', ''), + phoneNum: pn + }, + success: function(data) { + if (data.code === 200) { + location.href = data.data; + } else { + showErrTip(data.message); + requested = false; + } + }, + error: function(err) { + showErrTip('出错了,请重试'); + requested = false; + } + }); + } else { + showErrTip('手机号格式不正确,请重新输入'); + } +}); -$.ajax({ - type: 'GET', - url: '/product/newsale/filter', - data: defaultOpt, - success: function(data) { - $goodsContainer.append(data); +}); +define("js/passport/api", ["jquery"], function(require, exports, module){ +/** + * 登录注册公用API + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/8 + */ +var $ = require("jquery"); + +var trim = $.trim; + +//邮箱验证规则 +var emailRegx = /^([a-zA-Z0-9]+[_|\_|\.|-]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.|-]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/; + +//手机号码验证规则 +var phoneRegx = { + '+86': /^1[35847]{1}[0-9]{9}$/, + '+852': /^[965]{1}[0-9]{7}$/, + '+853': /^[0-9]{8}$/, + '+886': /^[0-9]{10}$/, + '+65': /^[98]{1}[0-9]{7}$/, + '+60': /^1[1234679]{1}[0-9]{8}$/, + '+1': /^[0-9]{10}$/, + '+82': /^01[0-9]{9}$/, + '+44': /^7[789][0-9]{8}$/, + '+81': /^0[9|8|7][0-9]{9}$/, + '+61': /^[0-9]{11}$/ +}; + +/** + * 密码显示隐藏 + * @params opt 初始化参数 + */ +function bindEyesEvt(opt) { + var $hasEye = $('.has-eye'), + $eye; + + if (opt && opt.status === 'open') { + $hasEye.append('<div class="eye"></div>'); + } else { + $hasEye.append('<div class="eye close"></div>'); + } + $eye = $hasEye.children('.eye'); + + $eye.on('touchstart', function(e) { + var $this = $(this), + $pwd = $this.siblings('.pwd'); + + e.preventDefault(); + $this.toggleClass('close'); + + //切换密码显示和文本显示 + if ($this.hasClass('close')) { + $pwd.attr('type', 'password'); + } else { + $pwd.attr('type', 'text'); + } + $pwd.focus(); + }); +} + +// 清空账号显示 +function bindClearEvt() { + var $hasClear = $('.has-clear'), + $clear; + + $hasClear.append('<div class="clear-input"></div>'); + $clear = $hasClear.children('.clear-input'); + + $clear.on('touchstart', function(e) { + var $input = $clear.siblings('.input'); + + $input.val('').trigger('input').focus(); + e.preventDefault(); + }); + + //反向逻辑 + $hasClear.children('.input').bind('input', function() { + var $this = $(this), + $thisClear = $this.siblings('.clear-input'), + val = trim($this.val()); + + if (val === '') { + $thisClear.hide(); + } else { + $thisClear.show(); + } + }); +} + +// 密码长度验证 +function pwdValidate(pwd) { + if (pwd.length >= 6 && pwd.length <= 20) { + return true; + } + return false; +} + +// hack for resolving direction:rtl didn't work in android uc +function selectCssHack($countrySelect) { + var u = navigator.userAgent; + + function autoSelectWidth() { + var wordCount = $countrySelect.find('option:selected').text().length; + + switch (wordCount) { + + //分别有2,3,4个汉字的情况 + case 2: + $countrySelect.outerWidth(90); + break; + case 3: + $countrySelect.outerWidth(110); + break; + default: + $countrySelect.outerWidth(130); + } + } + + if (u.match(/uc/i) && u.match(/android/i)) { + $countrySelect.change(function() { + autoSelectWidth(); + }); + } else { + $countrySelect.removeClass('in-android-uc'); + } +} + +//Exports APIs +module.exports = { + emailRegx: emailRegx, + phoneRegx: phoneRegx, + bindEyesEvt: bindEyesEvt, + bindClearEvt: bindClearEvt, + pwdValidate: pwdValidate, + selectCssHack: selectCssHack +}; +}); +define("js/passport/register/code", ["jquery"], function(require, exports, module){ +/** + * 注册-验证码 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/8 + */ + +require("js/passport/code")(true); +}); +define("js/passport/code", ["jquery"], function(require, exports, module){ +/** + * 注册/找回密码-验证码 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/8 + */ +var $ = require("jquery"); + +module.exports = function(useInRegister, useForBind, useForRelate) { + var $captcha = $('#captcha'), + $btnNext = $('#btn-next'), + $captchaTip = $('#captcha-tip'), + nickname = $('#nickname').val(), + sourceType = $('#sourceType').val(), + openId = $('#openId').val(), + phoneNum = $('#phone-num').val(), + areaCode = $('#area-code').val().replace('+', ''); + + var api = require("js/passport/api"); + var tip = require("js/plugin/tip"); + + var trim = $.trim; + var showErrTip = tip.show; + + var urlMid = useInRegister ? 'reg' : 'back'; + + var isReg = parseInt($('#isReg').val()); + + function startBind() { + $.ajax({ + url: useForBind ? '/passport/bind/bindMobile' : '/passport/bind/relateMobile', + type: 'post', + data: { + areaCode: areaCode.replace('+', ''), + phoneNum: phoneNum, + openId: openId, + sourceType: sourceType, + nickname: nickname, + password: '', + code: trim($captcha.val()) + }, + success: function(res) { + if (res.code === 200) { + tip.show('登录成功'); + setTimeout(function() { + location.href = res.data.refer; + }, 2000); + } else { + tip.show(res.message); + } + }, + error: function(err) { + tip.show('登录失败,请重试!'); + } + }); + } + + function startReg() { + $.ajax({ + type: 'POST', + url: '/passport/' + urlMid + '/verifycode', + data: { + phoneNum: phoneNum, + areaCode: areaCode, + code: trim($captcha.val()), + token: $('#token').val() + }, + success: function(data) { + if (data.code === 200) { + location.href = data.data; + } else { + + //验证码不正确,显示提示 + showErrTip(data.message); + } + + } + }); + } + + function countDown() { + var count = 59, + itime; + + itime = setInterval(function() { + if (count === 0) { + $captchaTip.text('重新发送').removeClass('disable'); + clearInterval(itime); + } else { + $captchaTip.text('重新发送 (' + count-- + '秒)'); + } + }, 1000); + } + + api.bindClearEvt(); + + $captcha.bind('input', function() { + if (trim($captcha.val()) !== '') { + $btnNext.removeClass('disable'); + } else { + $btnNext.addClass('disable'); + } + }); + + //重新发送验证码 + $captchaTip.on('touchstart', function() { + if ($captchaTip.hasClass('disable')) { + return; + } + + $.ajax({ + type: 'POST', + url: (useForBind || useForRelate) ? '/passport/bind/sendBindMsg' : '/passport/' + urlMid + '/sendcode', + data: { + phoneNum: phoneNum, + areaCode: areaCode + }, + success: function(data) { + if (data.code === 200) { + $captchaTip.text('重发验证码 (60秒)').addClass('disable'); + countDown(); + } else { + + //验证码不正确,显示提示 + showErrTip(data.message); + } + } + }); + }); + + $btnNext.on('touchstart', function() { + if ($btnNext.hasClass('disable')) { + return; + } + + if (useForBind || useForRelate) { + if (isReg) { + startBind(); + } else { + location.href = '/passport/bind/password?phoneNum=' + + phoneNum + '&areaCode=' + areaCode + '&openId=' + + openId + '&sourceType=' + sourceType + '&nickname=' + nickname + '&code=' + trim($captcha.val()); + } + + } else { + startReg(); + } + }); + + countDown(); +}; - //初始化filter&注册filter回调 - filter.initFilter({ - fCbFn: search, - hCbFn: function() { +}); +define("js/passport/register/password", ["jquery"], function(require, exports, module){ +/** + * 注册-密码 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/8 + */ +var $ = require("jquery"); + +var $pwd = $('#pwd'), + $btnSure = $('#btn-sure'); + +var api = require("js/passport/api"); +var tip = require("js/plugin/tip"); + +var trim = $.trim; +var showErrTip = tip.show; + +api.bindEyesEvt({ + status: 'open' //默认眼睛打开 +}); + +$pwd.bind('input', function() { + if (trim($pwd.val()) === '') { + $btnSure.addClass('disable'); + } else { + $btnSure.removeClass('disable'); + } +}); + +$btnSure.on('touchstart', function() { + var pwd = trim($pwd.val()); + + if ($btnSure.hasClass('disable')) { + return; + } + + if (api.pwdValidate(pwd) === false) { + showErrTip('密码6-20位,请重新输入'); + } else { + $.ajax({ + type: 'POST', + url: '/passport/reg/setpassword', + data: { + password: pwd, + phoneNum: $('#phone-num').val(), + areaCode: $('#area-code').val(), + token: $('#token').val() + }, + success: function(data) { + var res; + + if (data.code === 200) { + res = data.data; + showErrTip('注册成功'); + + $.ajax({ + url: res.session, + dataType: 'jsonp' + }); + + //1000ms后跳转页面 + setTimeout(function() { + location.href = res.href; + }, 1000); + } else { + showErrTip(data.message); + } + } + }); + } +}); +}); +define("js/passport/login/login", ["jquery"], function(require, exports, module){ +/** + * 登录 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/9/30 + */ +var $ = require("jquery"); + +var $account = $('#account'), + $pwd = $('#pwd'), + $loginBtn = $('#btn-login'), + + $mask = $('#retrive-pwd-mask'), + $ways = $('#retrive-pwd-ways'), + + accPass = false, + pwdPass = false; + +var api = require("js/passport/api"); +var tip = require("js/plugin/tip"); + +var trim = $.trim; +var showErrTip = tip.show; + +//登录按钮状态切换 +function switchLoginBtnStatus() { + if (accPass && pwdPass) { + $loginBtn.removeClass('disable'); + } else { + $loginBtn.addClass('disable'); + } +} + +//显示找回密码面板 +function showRetrivePanel() { + $mask.show(); + $ways.show(); +} + +//隐藏找回密码面板 +function hideRetrivePanel() { + $mask.hide(); + $ways.hide(); +} + +//密码显示与隐藏 +api.bindEyesEvt(); + +//清空账号输入框 +api.bindClearEvt(); + +$account.bind('input', function() { + if (trim($account.val()) !== '') { + accPass = true; + } else { + accPass = false; + } + switchLoginBtnStatus(); +}); + +$pwd.bind('input', function() { + if (trim($pwd.val()) === '') { + pwdPass = false; + } else { + pwdPass = true; + } + switchLoginBtnStatus(); +}); + + +// Login +$loginBtn.on('touchstart', function() { + var acc = trim($account.val()), + pwd = trim($pwd.val()); + + if ($loginBtn.hasClass('disable')) { + return; + } + + $loginBtn.text('正在登录...').addClass('disable'); + + //验证账号(数字或者邮箱)和密码合理性 + if ((/^[0-9]+$/.test(acc) || api.emailRegx.test(acc)) && api.pwdValidate(pwd)) { + $.ajax({ + type: 'POST', + url: '/passport/login/auth', + data: { + account: acc, + password: pwd + }, + success: function(data) { + var res; + + if (data.code === 200) { + res = data.data; + + showErrTip('登录成功'); + location.href = res.href; + } else { + showErrTip(data.message); + } + }, + error: function() { + showErrTip('网络断开连接啦~'); + }, + complete: function() { + $loginBtn.text('登录').removeClass('disable'); + } + }); + } else { + showErrTip('账号或密码有错误,请重新输入'); + $loginBtn.text('登录').removeClass('disable'); + } +}); + + +$('#forget-pwd').on('touchstart', function() { + showRetrivePanel(); +}); + +$mask.on('touchstart', function() { + hideRetrivePanel(); +}); + +$('#cancel-retrive').on('touchstart', function(e) { + e.preventDefault(); + hideRetrivePanel(); +}); + +//对初始有默认值的情况去初始化登录按钮状态 +$account.trigger('input'); +$pwd.trigger('input'); - //切换active状态到$pre上 - $pre.addClass('active'); - $pre.siblings('.filter').removeClass('active'); - }, - missStatus: true - }); - } }); -lazyLoad($('.lazy')); - -//导航栏点击逻辑说明: -//1.点击非active项时切换active状态 -//2.价格和折扣active状态时继续点击切换排序 -//3.筛选无active时点击展开筛选面板 -//4.筛选有active时点击隐藏筛选面板并恢复点击筛选前active项的active状态 -//5.当前active为筛选并且点击其他项时,隐藏筛选面板 -$listNav.bind('contextmenu', function(e) { - return false; +define("js/passport/login/international", ["jquery"], function(require, exports, module){ +/** + * 国际账号登录 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/8 + */ +var $ = require("jquery"); + +var $phoneNum = $('#phone-num'), + $countrySelect = $('#country-select'), + $areaCode = $('#area-code'), + $pwd = $('#pwd'), + $loginBtn = $('#btn-login'), + + pnPass = false, + pwdPass = false; + +var api = require("js/passport/api"); +var tip = require("js/plugin/tip"); + +var trim = $.trim; +var showErrTip = tip.show; + +//登录按钮状态切换 +function switchLoginBtnStatus() { + if (pnPass && pwdPass) { + $loginBtn.removeClass('disable'); + } else { + $loginBtn.addClass('disable'); + } +} + +//Android-UC下显示select的direction:rtl无效的临时解决办法 +api.selectCssHack($countrySelect); + +//显示隐藏密码 +api.bindEyesEvt(); + +//清空手机号码 +api.bindClearEvt(); + +$phoneNum.bind('input', function() { + if (trim($phoneNum.val()) === '') { + pnPass = false; + } else { + pnPass = true; + } + + switchLoginBtnStatus(); +}); + +$pwd.bind('input', function() { + var pwd = trim($pwd.val()); + + if (pwd === '') { + pwdPass = false; + } else { + pwdPass = true; + } + + switchLoginBtnStatus(); +}); + +$countrySelect.change(function() { + $areaCode.text($countrySelect.val()); +}); + +$loginBtn.on('touchstart', function() { + var pn = trim($phoneNum.val()), + areaCode = $countrySelect.val(), + pwd = trim($pwd.val()); + + if ($loginBtn.hasClass('disable')) { + return; + } + + $loginBtn.text('正在登录...').addClass('disable'); + + if (api.phoneRegx[areaCode].test(pn) && api.pwdValidate(pwd)) { + $.ajax({ + type: 'POST', + url: '/passport/login/auth', + data: { + areaCode: areaCode.replace('+', ''), + account: pn, + password: pwd + }, + success: function(data) { + var res, + time; + + if (data.code === 200) { + res = data.data; + showErrTip('登录成功'); + + $.ajax({ + url: res.session, + dataType: 'jsonp', + success: function() { + clearTimeout(time); + + //Cookie写入成功后,1s后跳转页面 + setTimeout(function() { + location.href = res.href; + }, 1000); + } + }); + + //3秒后强制跳转 + time = setTimeout(function() { + location.href = res.href; + }, 3000); + + showErrTip('登录成功'); + } else { + showErrTip(data.message); + } + }, + error: function() { + showErrTip('网络断开连接啦~'); + }, + complete: function() { + $loginBtn.text('登录').removeClass('disable'); + } + }); + } else { + showErrTip('账号或密码有错误,请重新输入'); + $loginBtn.text('登录').removeClass('disable'); + } +}); + +//对初始有默认值的情况去初始化登录按钮状态 +$phoneNum.trigger('input'); +$pwd.trigger('input'); +}); +define("js/passport/back/mobile", ["jquery"], function(require, exports, module){ +/** + * 找回密码-手机 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/8 + */ +var $ = require("jquery"); + +var $phoneNum = $('#phone-num'), + $countrySelect = $('#country-select'), + $areaCode = $('#area-code'), + $btnNext = $('#btn-next'); + +var api = require("js/passport/api"); +var tip = require("js/plugin/tip"); + +var trim = $.trim; +var showErrTip = tip.show; + +api.selectCssHack($('#country-select')); + +api.bindClearEvt(); + +$phoneNum.bind('input', function() { + if (trim($phoneNum.val()) === '') { + $btnNext.addClass('disable'); + } else { + $btnNext.removeClass('disable'); + } +}); + +$countrySelect.change(function() { + $areaCode.text($countrySelect.val()); +}); + +$btnNext.on('touchstart', function() { + var pn = trim($phoneNum.val()), + area = $countrySelect.val(); + + if ($btnNext.hasClass('disable')) { + return; + } + + if (api.phoneRegx[area].test(pn)) { + $.ajax({ + url: '/passport/back/sendcode', + type: 'POST', + data: { + areaCode: area.replace('+', ''), + phoneNum: pn + }, + success: function(data) { + if (data.code === 200) { + location.href = data.data; + } else { + showErrTip(data.message); + } + } + }); + } else { + showErrTip('手机号格式不正确,请重新输入'); + } +}); }); +define("js/passport/back/code", ["jquery"], function(require, exports, module){ +/** + * 找回密码-验证码 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/8 + */ + +require("js/passport/code")(false); +}); +define("js/passport/back/email", ["jquery"], function(require, exports, module){ +/** + * 找回密码-邮箱找回 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/8 + */ +var $ = require("jquery"); + +var $email = $('#email'), + $btnSure = $('#btn-sure'); + +var api = require("js/passport/api"); +var tip = require("js/plugin/tip"); + +var trim = $.trim; +var showErrTip = tip.show; + +api.bindClearEvt(); + +$email.bind('input', function() { + if (trim($email.val()) === '') { + $btnSure.addClass('disable'); + } else { + $btnSure.removeClass('disable'); + } +}); + +$btnSure.on('touchstart', function() { + var email = trim($email.val()); + + if ($btnSure.hasClass('disable')) { + return; + } + + if (api.emailRegx.test(email)) { + $.ajax({ + url: '/passport/back/sendemail', + type: 'POST', + data: { + email: email + }, + success: function(data) { + if (data.code === 200) { + location.href = data.data; + } else { + showErrTip(data.message); + } + } + }); + } else { + showErrTip('邮箱格式不正确,请重新输入'); + } +}); +}); +define("js/passport/back/email-success", ["jquery"], function(require, exports, module){ +/** + * 找回密码-邮箱找回成功 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/8 + */ + +var $ = require("jquery"); + +var $resend = $('#resend'); + +var tip = require("js/plugin/tip"), + showTip = tip.show; + +$resend.on('touchstart', function(e) { + e.preventDefault(); + + $.ajax({ + url: $resend.data('url'), + type: 'GET', + success: function(data) { + showTip(data.message); + } + }); +}); +}); +define("js/passport/back/new-password", ["jquery"], function(require, exports, module){ +/** + * 密码找回-新密码 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/8 + */ +var $ = require("jquery"); + +var $pwd = $('#pwd'), + $btnOk = $('#btn-ok'); + +var api = require("js/passport/api"); +var tip = require("js/plugin/tip"); + +var trim = $.trim; +var showErrTip = tip.show; + +var $phoneNum = $('#phone-num'); + +api.bindEyesEvt({ + status: 'open' +}); + +$pwd.bind('input', function() { + if (trim($pwd.val()) === '') { + $btnOk.addClass('disable'); + } else { + $btnOk.removeClass('disable'); + } +}); + +$btnOk.on('touchstart', function() { + var pwd = trim($pwd.val()), + mobileBack = true, + setting, + url; + + if ($btnOk.hasClass('disable')) { + return; + } + + setting = { + password: pwd + }; + + if ($phoneNum.length === 0) { + mobileBack = false; + } + + if (mobileBack) { + $.extend(setting, { + phoneNum: $phoneNum.val(), + areaCode: $('#areaCode').val(), + token: $('#token').val() + }); + + url = '/passport/back/passwordByMobile'; + } else { + $.extend(setting, { + code: $('#email-code').val() + }); + + url = '/passport/back/passwordByEmail'; + } + + + if (api.pwdValidate(pwd)) { + $.ajax({ + type: 'POST', + url: url, + data: setting, + success: function(data) { + if (data.code === 200) { + showErrTip('密码修改成功'); + + //1000ms后跳转页面 + setTimeout(function() { + location.href = data.data; + }, 1000); + } else { + showErrTip(data.message); + } + } + }); + } else { + showErrTip('密码6-20位,请重新输入'); + } +}); +}); +define("js/passport/bind/bind", ["jquery","handlebars","source-map","hammer"], function(require, exports, module){ +/** + * 注册 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/8 + */ +var $ = require("jquery"); -$listNav.on('touchend touchcancel', function(e) { - var $this = $(e.target).closest('li'), - nav, - navType, - $active; - - e.preventDefault(); - - if (typeof $this === 'undefined' || $this.length === 0) { - return; - } - - if ($this.hasClass('filter')) { +var $phoneNum = $('#phone-num'), + $countrySelect = $('#country-select'), + $areaCode = $('#area-code'), + $openId = $('#openId'), + $nickname = $('#nickname'), + $sourceType = $('#sourceType'), + $btnNext = $('#btn-next'); - //筛选面板切换状态 - if ($this.hasClass('active')) { - filter.hideFilter(); +var api = require("js/passport/api"), + tip = require("js/plugin/tip"), + dialog = require("js/me/dialog"); - //点击筛选钱的active项回复active - $pre.addClass('active'); - $this.removeClass('active'); - } else { - $pre = $this.siblings('.active'); +var trim = $.trim; +var showErrTip = tip.show; - $pre.removeClass('active'); - $this.addClass('active'); +var requested = false; - filter.showFilter(); - } - } else { +require("js/common"); - if ($this.hasClass('new')) { - navType = 'newest'; - } else if ($this.hasClass('price')) { - navType = 'price'; - } else if ($this.hasClass('discount')) { - navType = 'discount'; - } +function nextStep(url, mobileNo, areaCode) { + if (requested) { + return false; + } - nav = navInfo[navType]; + requested = true; + $btnNext.addClass('disable').html('绑定中...'); - if ($this.hasClass('active')) { + $.ajax({ + type: 'POST', + url: '/passport/bind/sendBindMsg', + data: { + phoneNum: mobileNo, + areaCode: areaCode.replace('+', '') + }, + success: function(res) { - //最新无排序切换 - if ($this.hasClass('new')) { - return; - } + if (res.code === 200) { - if ($this.hasClass('price') || $this.hasClass('discount')) { + // 统计代码:用于统计从哪个渠道登录 + if (window._yas && window._yas.sendCustomInfo) { + window._yas.sendCustomInfo({ + 'loginRefer' : $sourceType.val() + }, false); + } - // 价格/折扣切换排序状态 - $this.find('.icon > .iconfont').toggleClass('cur'); - $pre = $this; //更新pre为当前项 - nav.reload = true; //重置reload,HTML会被替换为逆序的HTML - nav.order = nav.order === 0 ? 1 : 0; //切换排序 + location.href = url; + } else { + tip.show(res.message); } - } else { - $active = $this.siblings('.active'); + }, + error: function() { + tip.show('出错了,请重试!'); + $btnNext.removeClass('disable').html('下一步'); + requested = false; + } + }); +} - $pre = $this; //$pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项 +api.selectCssHack($('#country-select')); - if ($active.hasClass('filter')) { +api.bindClearEvt(); - //若之前active项为筛选,则隐藏筛选面板 - filter.hideFilter(); - } else { +$phoneNum.bind('input', function() { + if (trim($phoneNum.val()) === '') { + $btnNext.addClass('disable'); + } else { + $btnNext.removeClass('disable'); + } +}); - //切换container显示 - $goodsContainer.children('.container:not(.hide)').addClass('hide'); +$countrySelect.change(function() { + $areaCode.text($countrySelect.val()); +}); - switch (navType) { - case 'newest': - $ngc.removeClass('hide'); - break; +$btnNext.on('touchstart', function() { + var pn = trim($phoneNum.val()), + openId = trim($openId.val()), + nickname = trim($nickname.val()), + sourceType = trim($sourceType.val()), + areaCode = $countrySelect.val(); - case 'price': - $pgc.removeClass('hide'); - break; + if ($btnNext.hasClass('disable')) { + return; + } - case 'discount': - $dgc.removeClass('hide'); - break; + if (api.phoneRegx[areaCode].test(pn)) { + $.ajax({ + url: '/passport/bind/bindCheck', + type: 'POST', + data: { + areaCode: areaCode.replace('+', ''), + phoneNum: pn, + openId: openId, + sourceType: sourceType, + nickname: nickname + }, + success: function(res) { + if (res.code === 200) { + if (res.data.isReg === 1) { + dialog.showDialog({ + dialogText: '该手机号已注册过有货\n' + pn + ',确定绑定吗?', + hasFooter: { + leftBtnText: '更换号码', + rightBtnText: '继续绑定' + } + }, function() { + nextStep(res.data.next, pn, areaCode); + }); + } else if (res.data.isReg === 3) { + dialog.showDialog({ + dialogText: '该手机号已注册过有货\n' + pn + ',是否进行关联?', + hasFooter: { + leftBtnText: '更换号码', + rightBtnText: '确定' + } + }, function() { + nextStep(res.data.next, pn, areaCode); + }); + } else { + nextStep(res.data.next, pn, areaCode); + } + } else { + showErrTip(res.message); } } - - $active.removeClass('active'); - $this.addClass('active'); - } - - if (nav.reload) { - search(); - } + }); + } else { + showErrTip('手机号格式不正确,请重新输入'); } - e.stopPropagation(); }); -function scrollHandler() { - - //当scroll到1/4$goodsContainer高度后继续请求下一页数据 - if ($(window).scrollTop() + winH > - $(document).height() - 0.25 * $goodsContainer.height() - 50) { - if ($pre !== undefined) { - search(); - } - } +if (/MicroMessenger/i.test(navigator.userAgent) && $.queryString().refer) { + $('.go-back').attr('href', decodeURIComponent($.queryString().refer)); } -//srcoll to load more -$(window).scroll(function() { - window.requestAnimationFrame(scrollHandler); }); +define("js/passport/bind/code", ["jquery"], function(require, exports, module){ +/** + * 注册-验证码 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/8 + */ + +require("js/passport/code")(true, true); -//初始请求最新第一页数据 -search(); +}); +define("js/passport/bind/password", ["jquery"], function(require, exports, module){ +/** + * 注册-密码 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/8 + */ +var $ = require("jquery"); + +var $pwd = $('#pwd'), + $btnSure = $('#btn-sure'); + +var api = require("js/passport/api"); +var tip = require("js/plugin/tip"); + +var trim = $.trim; +var showErrTip = tip.show; + +var nickname = $('#nickname').val(), + sourceType = $('#sourceType').val(), + openId = $('#openId').val(), + phoneNum = $('#phone-num').val(), + areaCode = $('#area-code').val().replace('+', ''), + code = $('#code').val(); + +function startBind(password) { + $.ajax({ + url: '/passport/bind/bindMobile', + type: 'post', + data: { + areaCode: areaCode.replace('+', ''), + phoneNum: phoneNum, + openId: openId, + sourceType: sourceType, + nickname: nickname, + password: password, + code: code + }, + success: function(res) { + if (res.code === 200) { + tip.show('登录成功'); + setTimeout(function() { + location.href = res.data.refer; + }, 2000); + } else { + tip.show(res.message); + } + }, + error: function(err) { + tip.show('登录失败,请重试!'); + } + }); +} + +api.bindEyesEvt({ + status: 'open' //默认眼睛打开 +}); + +$pwd.bind('input', function() { + if (trim($pwd.val()) === '') { + $btnSure.addClass('disable'); + } else { + $btnSure.removeClass('disable'); + } +}); + +$btnSure.on('touchstart', function() { + var pwd = trim($pwd.val()); + + if ($btnSure.hasClass('disable')) { + return; + } + + if (api.pwdValidate(pwd) === false) { + showErrTip('密码6-20位,请重新输入'); + } else { + startBind(pwd); + } +}); -$listNav.on('touchstart', 'li', function(e) { - $(this).addClass('bytouch'); -}).on('touchend touchcancel', function() { - $listNav.find('li').removeClass('bytouch'); }); +define("js/passport/bind/relate", ["jquery"], function(require, exports, module){ +/** + * 关联手机号-验证码 + */ + +require("js/passport/code")(true, false, true); }); -define("js/product/list", ["jquery","hammer","mlellipsis","lazyload","iscroll-probe"], function(require, exports, module){ +define("js/product/entry", ["jquery","swiper","mlellipsis","lazyload","iscroll-probe","hammer","handlebars","source-map","index"], function(require, exports, module){ +/** + * 产品打包入口 + * @author: liangzhifeng<zhifeng.liang@yoho.cn> + * @date: 2015/10/12 + */ + +require("js/product/newsale/newarrival"); +require("js/product/newsale/discount"); +require("js/product/list"); +require("js/product/detail/detail"); +require("js/product/detail/consultform"); +require("js/product/newsale/hot-rank"); +require("js/product/product-category"); +require("js/product/shop"); +}); +define("js/product/newsale/newarrival", ["jquery","swiper","mlellipsis","lazyload","iscroll-probe","hammer","index"], function(require, exports, module){ /** - * 商品列表页 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/20 + * 新品到着 + * @author: liangzhifeng<zhifeng.liang@yoho.cn> + * @date: 2015/10/24 */ var $ = require("jquery"), - Hammer = require("hammer"), + Swiper = require("swiper"), ellipsis = require("mlellipsis"), lazyLoad = require("lazyload"); +var swiper, + $ngc, + $pgc, + $dgc; -//品牌页参数 -var $brandHeader = $('#brand-header'), - $introBox = $('#intro-box'); - -var filter = require("js/plugin/filter"); - -var writeSearch = require("js/index/write-search"); - -var tip = require("js/plugin/tip"); -var loading = require("js/plugin/loading"); +var tip = require("js/plugin/tip"), + filter = require("js/plugin/filter"), + loading = require("js/plugin/loading"); var $goodsContainer = $('#goods-container'), - $ngc = $goodsContainer.children('.new-goods'), - $pgc = $goodsContainer.children('.price-goods'), - $dgc = $goodsContainer.children('.discount-goods'); - -var winH = $(window).height(); - -var $input = $('#search-input input'), - $clear = $('#search-input .clear-input'), - $buriedpoint = $('.buriedpoint'), - $search = $('#search'); + $goodsChildren = $goodsContainer.children(), + $ngc = $($goodsChildren.get(0)), + $pgc = $($goodsChildren.get(1)).addClass('hide'), + $dgc = $($goodsChildren.get(2)).addClass('hide'); -var shopId,sort,brand,outlets,app_type; +var winH = $(window).height(), + noResult = '<p class="no-result">未找到相关搜索结果</p>'; //默认筛选条件 var defaultOpt = require("js/product/query-param"); +var storeOpt = $.extend({}, defaultOpt); //存储默认筛选条件以便重置 + +var now = new Date(), + month = now.getMonth() + 1, + date = now.getDate(); + var $listNav = $('#list-nav'), //导航数据信息 navInfo = { - newest: { - order: 1, + today: { reload: true, page: 0, end: false }, - price: { - order: 1, + week: { reload: true, page: 0, end: false }, - discount: { - order: 1, + sale: { reload: true, page: 0, end: false } }, $pre = $listNav.find('.active'), //纪录进入筛选前的active项,初始为选中项 - searching, - btnIntroHammer, - introHammer, - brandColHammer; - -ellipsis.init(); - -// 搜索输入联动 -function inputAction() { - var $searchAssociate = $('.search-associate'); - var $icon = $('.search-icon'); - var $searchItems = $('.search-items'); - - $input.on('input', function() { - if ($input.val() === '') { - $icon.css('color', '#b2b2b2'); - $clear.addClass('hide'); - $searchAssociate.html(''); - $searchItems.show(); - $searchAssociate.hide(); - } else { - $icon.css('color', '#666'); - $clear.removeClass('hide'); - $searchAssociate.show(); - } + searching; - // 联动搜索 - $.ajax({ - url: '/index/search/fuzzyDatas', - data: { - keyword: $input.val() - }, - dataType: 'json', - success: function(data) { - var ajaxHtml = ''; - var i; +require("js/product/suspend-cart"); //悬浮购物车 - if (data.length > 0) { - for (i = 0; i < data.length; i++) { - ajaxHtml += '<li><span class="keyword">' + data[i].keyword + '</span><span class="count">' + - data[i].count + ' items<i class="iconfont"></i></span></li>'; - } +ellipsis.init(); - $searchAssociate.html(ajaxHtml); - $searchItems.hide(); - } else { - $searchAssociate.html(''); - } +$('#today a').text(month + '月' + date + '号'); - $searchAssociate.find('li').on('touchend', function() { - $buriedpoint.val($(this).find('.keyword').html()); - $search.closest('form').submit(); - }); - }, - error: function() { - tip.show('网络断开连接了~'); - } - }); +if ($('.swiper-container .swiper-slide').length > 1) { + swiper = new Swiper('.swiper-container', { + lazyLoading: true, + lazyLoadingInPrevNext: true, + loop: true, + autoplay: 3000, + autoplayDisableOnInteraction: true, + paginationClickable: true, + pagination: '.banner-top .pagination-inner' }); } -inputAction(); - -$clear.on('touchend', function() { - $input.val('').trigger('input'); -}); - -/** - * 手动触发搜索 - */ -$search.on('touchend', function() { - $(this).closest('form').submit(); - return false; -}); - -/** - * 获取url参数 - */ -function getQueryString(name) { - var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'); - var r = window.location.search.substr(1).match(reg); - - if (r != null) { - return window.unescape(r[2]); - } - return null; -} - -shopId = getQueryString('shop_id'); -sort = getQueryString('sort'); -outlets = getQueryString('outlets'); -age_level = getQueryString('ageLevel'); -app_type = getQueryString('app_type'); - /** * 筛选注册的回调,筛选子项点击后逻辑 * 需要执行search的场景:1.点选筛选项;2.relaod为true时切换导航;3.下拉加载 @@ -7353,10 +6201,8 @@ function search(opt) { ext, att, nav, navType, - page, - $this, - $title, - params; + dayLimit, + page; if (searching) { return; @@ -7374,12 +6220,8 @@ function search(opt) { //处理active状态 $listNav.children('.active').removeClass('active'); $pre.addClass('active'); + switch (opt.type) { - case 'shop_id': - ext = { - shop_id: opt.id - }; - break; case 'gender': ext = { gender: opt.id @@ -7420,9 +6262,19 @@ function search(opt) { discount: opt.id }; break; - case 'outlets': + case 'limit': ext = { - outlets: opt.id + limit: opt.id + }; + break; + case 'channel': + ext = { + channel: opt.id + }; + break; + case 'p_d': + ext = { + p_d: opt.id }; break; } @@ -7431,84 +6283,58 @@ function search(opt) { } //导航类别 - if ($pre.hasClass('new')) { - navType = 'newest'; - } else if ($pre.hasClass('price')) { - navType = 'price'; - } else if ($pre.hasClass('discount')) { - navType = 'discount'; - } - - nav = navInfo[navType]; - - page = nav.page + 1; - if (nav.reload) { - page = 1; - } else if (nav.end) { - - //不需要重新加载并且数据请求结束 - return; - } - - params = { - type: navType, - order: nav.order, - page: page - }; - - if (shopId) { - params.shop_id = shopId; - } - - if (age_level) { - params.age_level = age_level - } - - if (sort) { - params.sort = sort; + if ($pre.hasClass('today')) { + navType = 'today'; + dayLimit = 1; + } else if ($pre.hasClass('week')) { + navType = 'week'; + dayLimit = 2; + } else if ($pre.hasClass('sale')) { + navType = 'sale'; + dayLimit = 3; } - if (brand) { - params.brand = brand; - } + nav = navInfo[navType]; - if (outlets) { - params.outlets = outlets; - } + page = nav.page + 1; + if (nav.reload) { + page = 1; + } else if (nav.end) { - if (app_type) { - params.app_type = app_type; + //不需要重新加载并且数据请求结束 + return; } - $.extend(setting, defaultOpt, params); + $.extend(setting, defaultOpt, { + dayLimit: dayLimit, + page: page + }); searching = true; loading.showLoadingMask(); $.ajax({ type: 'GET', - url: location.protocol + '//m.yohobuy.com/index/search/search', + url: '/product/newsale/selectNewSale', data: setting, success: function(data) { - var noResult = '<p class="no-result">未找到相关搜索结果</p>', - num, - $container; + var $container, + num; switch (navType) { - case 'newest': + case 'today': $container = $ngc; break; - case 'price': + case 'week': $container = $pgc; break; - case 'discount': + case 'sale': $container = $dgc; break; } if (data === ' ') { nav.end = true; - if (nav.reload) { $container.html(noResult); } @@ -7535,39 +6361,24 @@ function search(opt) { window.rePosFooter(); $('.good-detail-text .name').each(function() { - $this = $(this); - $title = $this.find('a'); + var $this = $(this), + $title = $this.find('a'); $title[0].mlellipsis(2); }); - - // 用于统计点击了商品列表的第几个商品,序号从1开始计算。 - if (window._yas) { - switch (navType) { - case 'newest': - window._yas(1 * new Date(), '1.0.16', 'yohobuy_m', window._ozuid, - '', $('.new-goods .good-info .good-detail-img .good-thumb')); - break; - case 'price': - window._yas(1 * new Date(), '1.0.16', 'yohobuy_m', window._ozuid, - '', $('.price-goods .good-info .good-detail-img .good-thumb')); - break; - case 'discount': - window._yas(1 * new Date(), '1.0.16', 'yohobuy_m', window._ozuid, - '', $('.discount-goods .good-info .good-detail-img .good-thumb')); - break; - } - } + }, + error: function() { + tip.show('网络断开连接了~'); + searching = false; + loading.hideLoadingMask(); } }); } -require("js/product/suspend-cart"); //悬浮购物车 - $.ajax({ type: 'GET', - url: location.protocol + '//m.yohobuy.com/search/filter', + url: '/product/newsale/filter', data: defaultOpt, success: function(data) { $goodsContainer.append(data); @@ -7584,10 +6395,11 @@ $.ajax({ }); } }); - lazyLoad($('.lazy')); -writeSearch.bindWirteLocal($('#search-form')); +$listNav.bind('contextmenu', function(e) { + return false; +}); //导航栏点击逻辑说明: //1.点击非active项时切换active状态 @@ -7595,18 +6407,14 @@ writeSearch.bindWirteLocal($('#search-form')); //3.筛选无active时点击展开筛选面板 //4.筛选有active时点击隐藏筛选面板并恢复点击筛选前active项的active状态 //5.当前active为筛选并且点击其他项时,隐藏筛选面板 - -$listNav.bind('contextmenu', function(e) { - return false; -}); - +// navHammer = new Hammer($listNav[0]); $listNav.on('touchend touchcancel', function(e) { var $this = $(e.target).closest('li'), nav, navType, $active; - var bpIdData = $(this).find('.buriedpoint').attr('data-bp-id') || ''; + e.preventDefault(); if ($this.hasClass('filter')) { //筛选面板切换状态 @@ -7621,37 +6429,22 @@ $listNav.on('touchend touchcancel', function(e) { $pre.removeClass('active'); $this.addClass('active'); - filter.showFilter(); } } else { - if ($this.hasClass('new')) { - navType = 'newest'; - } else if ($this.hasClass('price')) { - navType = 'price'; - } else if ($this.hasClass('discount')) { - navType = 'discount'; + if ($this.hasClass('today')) { + navType = 'today'; + } else if ($this.hasClass('week')) { + navType = 'week'; + } else if ($this.hasClass('sale')) { + navType = 'sale'; } nav = navInfo[navType]; - if ($this.hasClass('active')) { - - //最新无排序切换 - if ($this.hasClass('new')) { - return; - } - - if ($this.hasClass('price') || $this.hasClass('discount')) { + if (!($this.hasClass('active'))) { - // 价格/折扣切换排序状态 - $this.find('.icon > .iconfont').toggleClass('cur'); - $pre = $this; //更新pre为当前项 - nav.reload = true; //重置reload,HTML会被替换为逆序的HTML - nav.order = nav.order === 0 ? 1 : 0; //切换排序 - } - } else { $active = $this.siblings('.active'); $pre = $this; //$pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项 @@ -7666,279 +6459,317 @@ $listNav.on('touchend touchcancel', function(e) { $goodsContainer.children('.container:not(.hide)').addClass('hide'); switch (navType) { - case 'newest': + case 'today': $ngc.removeClass('hide'); break; - case 'price': + case 'week': $pgc.removeClass('hide'); break; - case 'discount': + case 'sale': $dgc.removeClass('hide'); break; } + + //重置筛选项 + filter.resetFilter(); + defaultOpt = $.extend({}, storeOpt); } $active.removeClass('active'); $this.addClass('active'); } + if (nav.reload) { - $(document).trigger('shouldSendBpData', [bpIdData]); search(); } } + e.stopPropagation(); +}); + +function scrollHandler() { + + //当scroll到1/4$goodsContainer高度后继续请求下一页数据 + if ($(window).scrollTop() + winH > + $(document).height() - 0.25 * $goodsContainer.height() - 50) { + if ($pre !== undefined) { + search(); + } + } +} + +//srcoll to load more +$(window).scroll(function() { + window.requestAnimationFrame(scrollHandler); +}); + +//初始请求最新第一页数据 +search(); + +$listNav.on('touchstart', 'li', function(e) { + $(this).addClass('bytouch'); +}).on('touchend touchcancel', function() { + $listNav.find('li').removeClass('bytouch'); +}); + }); +define("js/plugin/filter", ["jquery","iscroll-probe","hammer"], function(require, exports, module){ +/** + * 筛选JS + * 暴露三个接口:注册回调、显示filter、隐藏filter + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/19 + */ + +var $ = require("jquery"), + IScroll = require("iscroll-probe") + Hammer = require("hammer"); + +var $filter; + +var fCbFn, hCbFn; //筛选和关闭的回调 + +var missStatus; //是否忽略选中状态 + +//隐藏筛选界面 +function hideFilter() { + $filter.addClass('hide'); +} + +//显示筛选界面 +function showFilter() { + $filter.removeClass('hide'); +} + +// 一级菜单点击时背景高亮 +function highlightMainItem() { + var $mainItem = $('.filter-body .classify'); + + $mainItem.on('touchstart', '.shower', function() { + var bpIdData = $(this).attr('data-bp-id') || ''; + + $mainItem.removeClass('highlight'); + $(this).addClass('highlight'); + + $(document).trigger('shouldSendBpData', [bpIdData]); + }).on('touchend touchcancel', '.shower', function() { + $(this).removeClass('highlight'); + }); +} + +// 子菜单点击时背景高亮 +function highlightSubItem() { + var $subItem = $('.filter-body .sub-item'); + + $subItem.on('touchstart', function() { + $subItem.removeClass('highlight'); + $(this).addClass('highlight'); + }).on('touchend touchcancel', function() { + $(this).removeClass('highlight'); + }); +} + +//主筛选项Tap事件句柄 +function classifyTapEvt($this) { + if ($this.hasClass('active')) { + return; + } + + $this.siblings('.active').removeClass('active'); + + $this.addClass('active'); + +} + +//子筛选项选中处理 +function setSubClassify($this) { + var $sub = $this.closest('.sub-classify'); + + var $shower = $sub.siblings('.shower'); + + var html, shower; + + if ($this.hasClass('chosed')) { + return $sub; + } + + $sub.children('.chosed').removeClass('chosed'); + $this.addClass('chosed'); + + html = $.trim($this.html()); + + shower = $.trim($shower.html()); + + $shower.html( + shower.substring(0, shower.indexOf('</span>') + 7) + //拆分出shower的title + html.substring(0, html.indexOf('<i')) //拆分选中筛选值 + ); + + if ($this.index() === 0) { + $shower.addClass('default'); + } else { + $shower.removeClass('default'); + } + + return $sub; +} + +//子筛选项Tap句柄 +function subClassifyTapEvt($this) { + var id = $this.data('id'); + + var $sub; -function scrollHandler() { + $sub = setSubClassify($this); - //当scroll到1/4$goodsContainer高度后继续请求下一页数据 - if ($(window).scrollTop() + winH > - $(document).height() - 0.25 * $goodsContainer.height()) { - search(); + if (fCbFn) { + fCbFn({ + type: $sub.data('type'), + id: id + }); } + + hideFilter(); } -//srcoll to load more -$(window).scroll(function() { - window.requestAnimationFrame(scrollHandler); -}); +//初始化筛选 +function initFilter(opt) { + var filterHammer; -if ($brandHeader.length > 0) { + //注册回调 + fCbFn = opt.fCbFn; + hCbFn = opt.hCbFn; - //品牌介绍 - btnIntroHammer = new Hammer($brandHeader.children('.btn-intro')[0]); - btnIntroHammer.on('tap', function() { - $introBox.removeClass('hide'); + missStatus = opt.missStatus; - //防止混合scroll发生 - $('body').addClass('overflow-hidden'); - }); + highlightMainItem(); + highlightSubItem(); - //关闭品牌介绍 - introHammer = new Hammer(document.getElementById('intro-box')); - introHammer.on('tap', function(e) { - var $this = $(e.target); + $filter = $('.filter-mask'); - e.srcEvent.preventDefault(); + filterHammer = new Hammer($filter[0]); + filterHammer.on('tap', function(e) { + var $this = $(e.target), + $cur; + // e.preventDefault();//防止透点 - //关闭品牌介绍box - if ($this.closest('#brand-intro').length === 0 || $this.hasClass('close-intro')) { - $introBox.addClass('hide'); - $('body').removeClass('overflow-hidden'); - } - }); + if ($this.closest('.filter-body').length > 0) { + $cur = $this.closest('.sub-item'); + if ($cur.length > 0) { - //品牌收藏 - brandColHammer = new Hammer($brandHeader.children('.btn-col')[0]); - brandColHammer.on('tap', function(e) { - var $this = $(e.target).closest('.btn-col'); + //tap subclassify + $cur = $this.closest('li'); - var id = $brandHeader.data('id'), // ID 在 PHP 程序里已经根据是否是基础店铺或者品牌动态处理了 - isBaseShop = $brandHeader.data('isbaseshop'), //tar add 160825 标记是否是基础店铺,否则是品牌 - postUrl = '', // tar add 160825 根据是否是基础店铺,收藏还是取消动态更改 URL 地址 - postData = {}; // tar add 160825 根据是否是基础店铺,收藏还是取消动态更改 POST 数据 + subClassifyTapEvt($cur); + } else { - /* 根据是基础店铺还是品牌做处理 */ - if (isBaseShop) { - var appVersion = $('input[name="app_version"]').val(); + //tap classify + $cur = $this.closest('.classify-item'); - /* 如果是基础店铺,POST 的数据一样 */ - postData = { - shop_id: id, - app_version: appVersion - }; + e.srcEvent.stopPropagation(); - if ($this.hasClass('coled')) { - postUrl = '/product/index/cancelShopFav'; - } else { - postUrl = '/product/index/shopFav'; + classifyTapEvt($cur); } } else { + hideFilter(); - /* 品牌,收藏与取消收藏,请求 URL 一样 */ - postUrl = '/product/opt/favoriteBrand'; - if ($this.hasClass('coled')) { - postData = { - id: id, - opt: 'cancel' - }; - } else { - postData = { - id: id, - opt: 'ok' - }; + if (hCbFn) { + hCbFn(); } } + }); + if(opt.isScroll){ + $("ul.sub-classify").each(function(){ + $(this).wrap("<div class='sub-classify-farther' data-type='" + $(this).data("type") + "'></div>"); + // $(this).removeClass("sub-classify"); - $.ajax({ - type: 'POST', - url: postUrl, - data: postData, - success: function(data) { - if (data.code === 200) { - $this.toggleClass('coled'); + var lastY=0,y=0; + var $slider=$(this); - //提示 - if (postData.opt === 'ok') { - tip.show('添加收藏成功'); - } else { - tip.show('取消收藏成功'); - } - } else if (data.code === 400) { - location.href = data.data;//未登录跳转登录页 - } else { - tip.show(data.message); - } - }, - error: function() { - tip.show('网络断开连接了~'); - } + $slider.on('touchstart', function(e) { + lastY = e.originalEvent.touches[0].pageY; + }); + $slider.on('touchmove', function(e) { + var curY = e.originalEvent.touches[0].pageY; + var deltaY = curY - lastY; + var height = $(this)[0].scrollHeight; + var limit = height - $(this).parent().height(); + y = y + deltaY; + if (y < limit * -1) + y = limit * -1; + if (y > 0) + y = 0; + var translate = 'translate3d(0,' + y + 'px,0)'; + $(this).css({ + '-moz-transform': translate, + '-ms-transform': translate, + 'transform': translate, + '-webkit-transform': translate, + }); + lastY = curY; + }); + $slider.on('touchend', function(e) {}); }); - }); -} + } + -//初始请求最新第一页数据 -search(); +} -$listNav.on('touchstart', 'li', function() { - $listNav.find('li').removeClass('bytouch'); - $(this).addClass('bytouch'); -}).on('touchend touchcancel', 'li', function() { - $listNav.find('li').removeClass('bytouch'); -}); +//重置筛选面板 +function resetFilter() { + if (typeof $filter === 'undefined') { + return; + } -}); -define("js/product/detail/detail", ["jquery","swiper","hammer","lazyload","handlebars","source-map","index"], function(require, exports, module){ -/** - * 商品详情 - * @author: liangzhifeng<zhifeng.liang@yoho.cn> - * @date: 2015/10/20 - */ -var $ = require("jquery"), - Swiper = require("swiper"), - Hammer = require("hammer"), - lazyLoad = require("lazyload"); - -var goodsSwiper, - $discountFolder = $('.goodsDiscount .discount-folder'), - $discountArrow = $('.goodsDiscount .first-item span'); - -var goodsDiscountEl = document.getElementById('goodsDiscount'), - goodsDiscountHammer = goodsDiscountEl && new Hammer(goodsDiscountEl), - $discountFirstItem = $(goodsDiscountEl).find('.first-item'); - -var $cart = $('.cart-bar'); - -var appUrl = $('input[name="limitCodeUrl"]').val(); - -var dialog = require("js/me/dialog"); - - -//add extra marign-bottom for footer to show the yoho copyright -function showFooter() { - var $cartBar = $('.cart-bar'); - - var timer = setInterval(function() { - if ($cartBar) { - window.reMarginFooter('.cart-bar'); - clearInterval(timer); - } else { - $cartBar = $('.cart-bar'); - } - }, 200); -} - -showFooter(); - -require("js/product/detail/like"); - -lazyLoad($('img.lazy')); - -if ($('#goodsDiscount h1').length < 1) { - $('.dropdown').remove(); -} - -//顶部swiper -goodsSwiper = new Swiper('.banner-swiper', { - lazyLoading: true, - lazyLoadingInPrevNext: true, - paginationClickable: true, - pagination: '.banner-top .pagination-inner', - nextButton: '.my-swiper-button-next', - prevButton: '.my-swiper-button-prev', - spaceBetween: 3 -}); - - -//初始化goods-discount -if (0 === $discountFolder.children().length) { - $discountFolder.css('display', 'none'); - $discountArrow.html(''); -} - -//goods-discount下拉按钮点击事件 -if (goodsDiscountHammer && $discountFolder.children().length > 0) { - goodsDiscountHammer.on('tap', function(e) { - if ($discountFolder.is(':hidden')) { - $discountFirstItem.removeClass('short-text'); - $discountArrow.removeClass('icon-down').addClass('icon-up').html(''); - $discountFolder.slideDown(); - } else { - $discountFirstItem.addClass('short-text'); - $discountArrow.removeClass('icon-up').addClass('icon-down').html(''); - $discountFolder.slideUp(); - } - }); -} - -$('#limit-sale').on('touchend', function(e) { - var loginUrl = $('#loginUrl').val(), - time, - ifr; + //重置子筛选项 + $('.sub-classify').each(function() { + setSubClassify($(this).children(':first-child')); + }); + + //重置主筛选项 + classifyTapEvt($('.classify > :first-child')); +} + +exports.initFilter = initFilter; + +exports.showFilter = showFilter; + +exports.hideFilter = hideFilter; + +exports.resetFilter = resetFilter; + +}); +define("js/product/query-param", ["jquery"], function(require, exports, module){ +/** + * 提取查询参数 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/11/19 + */ - e.stopPropagation(); +var $ = require("jquery"), + opt = {}; - if(loginUrl) { - window.location = loginUrl; - } else { - dialog.showDialog({ - dialogText: '进入有货APP,获取限购码', - hasFooter: { - rightBtnText: '打开Yoho!Buy有货APP' - } - }, function() { - ifr = document.createElement('iframe'); - ifr.src = appUrl; - ifr.style.display = 'none'; - document.body.appendChild(ifr); - window.location.href = appUrl; +$('.query-param').each(function() { + var $this = $(this); - time = Date.now(); - window.setTimeout(function() { - document.body.removeChild(ifr); - if (Date.now()- time < 3200) { - window.location.href = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.yoho'; - } - }, 3000); + opt[$this.data('attr')] = $this.val(); +}); - }, undefined, true); +module.exports = opt; +}); +define("js/product/suspend-cart", ["jquery"], function(require, exports, module){ +/** + * 悬浮购物车 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/11/1 + */ - $('.dialog-wrapper').off('touchstart').on('touchstart', function(e) { - e.stopPropagation(); - if ($(e.target).hasClass('dialog-wrapper')) { - dialog.hideDialog(); - } - }); - } -}); +var $ = require("jquery"); -require("js/product/detail/desc"); -require("js/product/detail/comments-consults"); -require("js/product/recommend-for-you-product-desc"); +var $cart = $('#suspend-cart'); -//购物车商品数量 $.ajax({ type: 'GET', url: '/cart/index/count', @@ -7946,3076 +6777,4245 @@ $.ajax({ var count; if (data.code === 200) { - count = data.data.cart_goods_count || 0; - if (count === 0) { - return false; - } + count = data.data.cart_goods_count; if (count > 99) { count = '99+'; } - $cart.find('.num-tag').html(count).removeClass('hide'); + if (count === 0) { + $('.cart-count').remove(); + } + $cart.find('.cart-count').html(count).removeClass('hide'); } } }); - -if ($('.good-detail-page').length > 0) { - $('#yoho-footer').css('border-top', '1px solid #e0e0e0'); -} - - }); -define("js/product/detail/like", ["jquery"], function(require, exports, module){ +define("js/product/newsale/discount", ["jquery","swiper","mlellipsis","lazyload","iscroll-probe","hammer","index"], function(require, exports, module){ /** - * 商品详情 --添加收藏 - * @author: Lynnic - * @date: 2015/11/24 + * 商品列表页 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/20 */ - var $ = require("jquery"), - tip = require("js/plugin/tip"), - chosePanel = require("js/cart/chose-panel"); + Swiper = require("swiper"), + ellipsis = require("mlellipsis"), + lazyLoad = require("lazyload"); -var productId = $('#productId').val(); +var swiper; -var skn = $('#productSkn').val(), - productCode = $('#limitProductCode').val(); +var tip = require("js/plugin/tip"), + filter = require("js/plugin/filter"), + loading = require("js/plugin/loading"); - //门票 限购数量 -var ticketsLimit = $('#limitNum').val() || 0; +var $goodsContainer = $('#goods-container'), + $goodsChildren = $goodsContainer.children(), + $ngc = $($goodsChildren.get(0)), + $pgc = $($goodsChildren.get(1)), + $dgc = $($goodsChildren.get(2)); -$('#likeBtn').on('touchstart', function() { - var opt, - favorite; +var winH = $(window).height(), + noResult = '<p class="no-result">未找到相关搜索结果</p>'; + +//默认筛选条件 +var defaultOpt = require("js/product/query-param"); + +var $listNav = $('#list-nav'), + + //导航数据信息 + navInfo = { + newest: { + order: 1, + reload: true, + page: 0, + end: false + }, + price: { + order: 1, + reload: true, + page: 0, + end: false + }, + discount: { + order: 1, + reload: true, + page: 0, + end: false + } + }, + $pre = $listNav.find('.active'), //纪录进入筛选前的active项,初始为选中项 + searching; + +require("js/product/suspend-cart"); //悬浮购物车 + +ellipsis.init(); + +if ($('.swiper-container .swiper-slide').length > 1) { + swiper = new Swiper('.swiper-container', { + lazyLoading: true, + lazyLoadingInPrevNext: true, + loop: true, + autoplay: 3000, + autoplayDisableOnInteraction: true, + paginationClickable: true, + pagination: '.banner-top .pagination-inner' + }); +} + +/** + * 筛选注册的回调,筛选子项点击后逻辑 + * 需要执行search的场景:1.点选筛选项;2.relaod为true时切换导航;3.下拉加载 + * @param opt {type, id} + */ +function search(opt) { + var setting = {}, + ext, + att, + nav, navType, + page; + + if (searching) { + return; + } + + if (opt) { + + //筛选项变更则重置reload为true + for (att in navInfo) { + if (navInfo.hasOwnProperty(att)) { + navInfo[att].reload = true; + } + } + + //处理active状态 + $listNav.children('.active').removeClass('active'); + $pre.addClass('active'); + + switch (opt.type) { + case 'gender': + ext = { + gender: opt.id + }; + break; + case 'brand': + ext = { + brand: opt.id + }; + break; + case 'ageLevel': + ext = { + age_level: opt.id + }; + break; + case 'sort': + ext = { + sort: opt.id + }; + break; + case 'color': + ext = { + color: opt.id + }; + break; + case 'size': + ext = { + size: opt.id + }; + break; + case 'price': + ext = { + price: opt.id + }; + break; + case 'discount': + ext = { + discount: opt.id + }; + break; + } + + $.extend(defaultOpt, ext); //扩展筛选项 + } + + + //导航类别 + if ($pre.hasClass('new')) { + navType = 'newest'; + } else if ($pre.hasClass('price')) { + navType = 'price'; + } else if ($pre.hasClass('discount')) { + navType = 'discount'; + } + + nav = navInfo[navType]; - var $this = $(this); + page = nav.page + 1; + if (nav.reload) { + page = 1; + } else if (nav.end) { - if ($this.hasClass('liked')) { - opt = 'cancel'; - favorite = 0; - } else { - opt = 'ok'; - favorite = 1; + //不需要重新加载并且数据请求结束 + return; } + $.extend(setting, defaultOpt, { + type: navType, + order: nav.order, + page: page + }); + + searching = true; + loading.showLoadingMask(); + $.ajax({ - type: 'POST', - url: '/product/opt/favoriteProduct', - data: { - id: productId, - opt: opt - }, + type: 'GET', + url: '/product/newsale/selectNewSale', + data: setting, success: function(data) { - if (data.code === 200) { - $this.toggleClass('liked'); + var $container, + num; - if ('cancel' === opt) { - tip.show('取消收藏成功'); - } else if ('ok' === opt) { - tip.show('收藏成功'); + switch (navType) { + case 'newest': + $container = $ngc; + break; + case 'price': + $container = $pgc; + break; + case 'discount': + $container = $dgc; + break; + } + + if (data === ' ') { + nav.end = true; + + if (nav.reload) { + $container.html(noResult); } - } else if (data.code === 400) { - location.href = data.data;//未登录跳转登录页 } else { - tip.show(data.message); + if (nav.reload) { + $container.html(data); + lazyLoad($container.find('.lazy')); + } else { + num = $container.find('.good-info').length; + $container.append(data); + + //lazy good-infos who append in + lazyLoad($container.find('.good-info:gt(' + (num - 1) + ') .lazy')); + } } + + nav.reload = false; + nav.page = page; + + searching = false; + loading.hideLoadingMask(); + + window.rePosFooter(); + + $('.good-detail-text .name').each(function() { + var $this = $(this), + $title = $this.find('a'); + + $title[0].mlellipsis(2); + }); }, error: function() { tip.show('网络断开连接了~'); + searching = false; + loading.hideLoadingMask(); } }); - // 统计代码:用于统计用户加入或取消商品收藏的动作 - if (window._yas) { - window._yas.sendCustomInfo({ - pd: productId, - fa: favorite - }, true); - } - - return false; -}); - -$('#addtoCart').on('touchstart', function() { - - //门票验证登录 - if (ticketsLimit) { - if (!ticketCheckLogin()) { - return false; - } - } +} - $('.cart-bar').hide(); +$.ajax({ + type: 'GET', + url: '/product/newsale/filter', + data: defaultOpt, + success: function(data) { + $goodsContainer.append(data); - productCode && chosePanel.setLimitGoodModeWithSknId(productCode, skn); - chosePanel.show(); + //初始化filter&注册filter回调 + filter.initFilter({ + fCbFn: search, + hCbFn: function() { - //统计代码:用于统计用户加入购物车的动作 - if (window._yas) { - window._yas.sendCustomInfo({ - pd: productId, - by: 1 - }, true); + //切换active状态到$pre上 + $pre.addClass('active'); + $pre.siblings('.filter').removeClass('active'); + }, + missStatus: true + }); } +}); +lazyLoad($('.lazy')); +//导航栏点击逻辑说明: +//1.点击非active项时切换active状态 +//2.价格和折扣active状态时继续点击切换排序 +//3.筛选无active时点击展开筛选面板 +//4.筛选有active时点击隐藏筛选面板并恢复点击筛选前active项的active状态 +//5.当前active为筛选并且点击其他项时,隐藏筛选面板 +$listNav.bind('contextmenu', function(e) { return false; }); -ticketCheckOpen(); +$listNav.on('touchend touchcancel', function(e) { + var $this = $(e.target).closest('li'), + nav, + navType, + $active; -$('#buyLimit').on('touchstart', function() { - tip.show('打开APP可抢购该商品哦~'); - return false; -}); + e.preventDefault(); -//门票立即购买验证登录 - function ticketCheckLogin() { + if (typeof $this === 'undefined' || $this.length === 0) { + return; + } - if (!window.getUid()) { - var urlArray = window.location.href.split('?'); - window.location.href = '//m.yohobuy.com/signin.html?refer=' + urlArray[0] + '?product_type=ticket'; - return false; - } - return true; - } + if ($this.hasClass('filter')) { -// 门票登录后自动弹出 - function ticketCheckOpen() { - var showPannel = $('#showPannel').val(); - if (showPannel) { - chosePanel.show(); - } - } + //筛选面板切换状态 + if ($this.hasClass('active')) { + filter.hideFilter(); -}); -define("js/cart/chose-panel", ["jquery"], function(require, exports, module){ -/** - * 购物车选择尺寸、颜色和数量面板 - * 显示时构造当前商品信息的HTML插入yoho-page;消失则是直接清除HTML - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/10/21 - */ + //点击筛选钱的active项回复active + $pre.addClass('active'); + $this.removeClass('active'); + } else { + $pre = $this.siblings('.active'); + $pre.removeClass('active'); + $this.addClass('active'); -// bikai -// 增加init函数,异步请求的接口需要重新初始化一下选择列表 -// 异步渲染的模板统一插入 #chose-panel ,兼容页面多个选择框 + filter.showFilter(); + } + } else { -var $ = require("jquery"), - tip = require("js/plugin/tip"), - loading = require("js/plugin/loading"); + if ($this.hasClass('new')) { + navType = 'newest'; + } else if ($this.hasClass('price')) { + navType = 'price'; + } else if ($this.hasClass('discount')) { + navType = 'discount'; + } -var innerScroll = require("js/plugin/inner-scroll"); + nav = navInfo[navType]; -var $chosePanel = $('#chose-panel'), - $num, - $chosed, - $imgsThumb, - $leftNum, - leftNum, - confirming, - curColorIndex, - curSizeIndex, - hasChooseColor, - hasChooseSize, - $curSizeBlock, - $sizeRowList, - $curColorBlock, - $colorRowList, - cbFn, - $allChoseItems, - queryString, - $choseArea, - $cartBar, - $soonSoldOut = $('.soonSoldOut-tag'), - $yohoPage = $('.yoho-page'), - //门票 限购数量 - ticketsLimit = $('#limitNum').val() || 0, - single = $('#single').val() || 0; - $productSku = $('#productSku'), - $buyNumber = $('#buyNumber'), - $buyNowForm = $('#buyNowForm'); + if ($this.hasClass('active')) { -// 购物车编辑标相关变量 -var isEdit, - isSelected, - oldSknId; + //最新无排序切换 + if ($this.hasClass('new')) { + return; + } -// 限购商品的商品码。只有限购商品时才会设置。 -var limitProductCode, + if ($this.hasClass('price') || $this.hasClass('discount')) { - // 限购商品的skn。只有限购商品时才会设置。 - skn; + // 价格/折扣切换排序状态 + $this.find('.icon > .iconfont').toggleClass('cur'); + $pre = $this; //更新pre为当前项 + nav.reload = true; //重置reload,HTML会被替换为逆序的HTML + nav.order = nav.order === 0 ? 1 : 0; //切换排序 + } + } else { + $active = $this.siblings('.active'); -//禁用数字编辑 -function disableNumEdit() { - var $numBtn = $('.chose-panel').find('.num .btn>.iconfont'); + $pre = $this; //$pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项 - //添加disabled样式 - $numBtn.hasClass('disabled') ? null : $numBtn.addClass('disabled'); + if ($active.hasClass('filter')) { - $yohoPage.off('touchstart', '.btn-minus'); - $yohoPage.off('touchstart', '.btn-plus'); -} + //若之前active项为筛选,则隐藏筛选面板 + filter.hideFilter(); + } else { -// 初始化购物车面板显示 -function init() { - hasChooseColor = false; - hasChooseSize = false; - $curSizeBlock = null; - queryString = $.queryString(); - $imgsThumb = $('.chose-panel').find('.thumb'); - $choseArea = $('.chose-panel .main .chose-items'); - $allChoseItems = $('.chose-items'); - $sizeRowList = $('.size-list ul'); - $colorRowList = $('.color-list ul'); - $leftNum = $('#left-num'); - $cartBar = $('.cart-bar'); - curColorIndex = 0; - curSizeIndex = 0; - isEdit = 0; -} + //切换container显示 + $goodsContainer.children('.container:not(.hide)').addClass('hide'); -/* - * 设置当前面板为编辑模式 - * - * @param {String} sknId. 当前编辑商品的sknId - * - * @param {Bool} isThisGoodSelected. 当前编辑商品的在购物车中是否被选中 - * - * @return {undefined} - */ -function setEditModeWithSknId(sknId, isThisGoodSelected) { - $('#chose-btn-sure').html('确认'); - isEdit = 1; - oldSknId = sknId; - isSelected = isThisGoodSelected; -} + switch (navType) { + case 'newest': + $ngc.removeClass('hide'); + break; -/* - * 设置当前面板为限购商品模式 - * - * @param {String} code 当前限购商品的商品码 - * - * @param {String} sknId. 当前限购商品的sknId - * - * @return {undefined} - */ -function setLimitGoodModeWithSknId(code, sknId) { - disableNumEdit(); - $('#chose-btn-sure').html('立即购买'); - limitProductCode = code; - skn = sknId; -} + case 'price': + $pgc.removeClass('hide'); + break; -//删除面板 -function removePannel() { - var $pannel = $('.chose-panel'), - $promotionId = $('#promotionId'); + case 'discount': + $dgc.removeClass('hide'); + break; + } + } - if ($pannel) { - $pannel.remove(); - } + $active.removeClass('active'); + $this.addClass('active'); + } - if ($promotionId) { - $promotionId.remove(); + if (nav.reload) { + search(); + } } -} + e.stopPropagation(); +}); -function checkColorSizeNum() { +function scrollHandler() { - if (ticketsLimit) { - //门票 - if (!checkTickets()) { - return; + //当scroll到1/4$goodsContainer高度后继续请求下一页数据 + if ($(window).scrollTop() + winH > + $(document).height() - 0.25 * $goodsContainer.height() - 50) { + if ($pre !== undefined) { + search(); } } - - if (!hasChooseColor && !hasChooseSize) { - tip.show('请选择颜色和尺码~'); - return false; - } else if (!hasChooseColor) { - tip.show('请选择颜色~'); - return false; - } else if (!hasChooseSize) { - tip.show('请选择尺码~'); - return false; - } - return true; } -//检查门票选择 -function checkTickets() { - if (!hasChooseColor && !hasChooseSize) { - if (single) { - tip.show('请选择日期~'); - } else { - tip.show('请选择日期和区域~'); - }; - return false; - } else if (!hasChooseColor) { - tip.show('请选择日期~'); - return false; - } else if (!hasChooseSize && !single) { - tip.show('请选择区域~'); - return false; - } - return true; -} +//srcoll to load more +$(window).scroll(function() { + window.requestAnimationFrame(scrollHandler); +}); +//初始请求最新第一页数据 +search(); -function show(html, cb) { - if (html) { - $chosePanel.html(html); - if ($('#promotionId').val() !== '') { - disableNumEdit(); - } - init(); - } +$listNav.on('touchstart', 'li', function(e) { + $(this).addClass('bytouch'); +}).on('touchend touchcancel', function() { + $listNav.find('li').removeClass('bytouch'); +}); - $('.chose-panel').show(); - $num = $('#good-num'); - cbFn = cb; +}); +define("js/product/list", ["jquery","hammer","mlellipsis","lazyload","iscroll-probe"], function(require, exports, module){ +/** + * 商品列表页 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/20 + */ +var $ = require("jquery"), + Hammer = require("hammer"), + ellipsis = require("mlellipsis"), + lazyLoad = require("lazyload"); - innerScroll.disableScroll($choseArea); -} -//隐藏当前Panel -function hide() { - $('.chose-panel').hide(); - innerScroll.enableScroll($choseArea); +//品牌页参数 +var $brandHeader = $('#brand-header'), + $introBox = $('#intro-box'); - if ($cartBar.length > 0) { - $cartBar.show(); - } -} +var filter = require("js/plugin/filter"); -//修改加入购物车的文字和背景 -function updateConformButtonClassAndText() { - $chosed = $allChoseItems.find('.chosed'); - if (2 === $chosed.closest('.zero-stock').length) { - $('#chose-btn-sure').css('background-color', '#c0c0c0').html('已售罄'); - } else if (limitProductCode || ticketsLimit) { - $('#chose-btn-sure').css('background-color', '#eb0313').html('立即购买'); - } else { - $('#chose-btn-sure').css('background-color', '#eb0313').html(isEdit ? '确认' : '加入购物车'); - } -} +var writeSearch = require("js/index/write-search"); -//显示剩余件数 -function displayGoodNum(curGoodNum) { +var tip = require("js/plugin/tip"); +var loading = require("js/plugin/loading"); - //门票限购 - if (ticketsLimit) { - $allChoseItems.find('.num .left-num').html('限购' + ticketsLimit + '件'); - $leftNum.val(curGoodNum); - return; - } +var $goodsContainer = $('#goods-container'), + $ngc = $goodsContainer.children('.new-goods'), + $pgc = $goodsContainer.children('.price-goods'), + $dgc = $goodsContainer.children('.discount-goods'); - //数量大于 - if (curGoodNum > 0) { - if ($soonSoldOut.length > 0) { - $allChoseItems.find('.num .left-num').html('即将售罄'); - } else { - $allChoseItems.find('.num .left-num').html('剩余' + curGoodNum + '件'); - } +var winH = $(window).height(); - $leftNum.val(curGoodNum); +var $input = $('#search-input input'), + $clear = $('#search-input .clear-input'), + $buriedpoint = $('.buriedpoint'), + $search = $('#search'); - //数量小于0 - } else { - $allChoseItems.find('.num .left-num').html(''); - $leftNum.val(0); - } -} +var shopId,sort,brand,outlets,app_type; -//老的选中尺码去掉勾选,新的选中尺码加上勾选 -function changeSizeChosed(newSizeIndex) { - var sizes, - queryString, - i; +//默认筛选条件 +var defaultOpt = require("js/product/query-param"); - if (curColorIndex && $curSizeBlock && $curSizeBlock.length > 0) { - $curSizeBlock.removeClass('chosed'); - sizes = $sizeRowList.eq(newSizeIndex).children(); - for (i = 0; i < sizes.length; i++) { - if ($(sizes[i]).data('id') === $curSizeBlock.data('id')) { - $curSizeBlock = $(sizes[i]); - queryString = '#' + $curSizeBlock.data('id'); - curColorIndex = $(queryString).data('index'); - $curSizeBlock.addClass('chosed'); - return $curSizeBlock.data('num'); - } +var $listNav = $('#list-nav'), + + //导航数据信息 + navInfo = { + newest: { + order: 1, + reload: true, + page: 0, + end: false + }, + price: { + order: 1, + reload: true, + page: 0, + end: false + }, + discount: { + order: 1, + reload: true, + page: 0, + end: false } + }, + $pre = $listNav.find('.active'), //纪录进入筛选前的active项,初始为选中项 + searching, + btnIntroHammer, + introHammer, + brandColHammer; - //特殊处理: 老的选中尺码在新选中的颜色对应尺码中不存在,需要下述1,2,3 - // 1.重置尺码选择的标志变量. - $curSizeBlock = null; - hasChooseSize = false; - - // 2.当前颜色行隐藏 - $colorRowList.eq(curColorIndex).addClass('hide'); +ellipsis.init(); - // 3.目标颜色行第一行显示 - $colorRowList.eq(0).removeClass('hide'); - curColorIndex = 0; +// 搜索输入联动 +function inputAction() { + var $searchAssociate = $('.search-associate'); + var $icon = $('.search-icon'); + var $searchItems = $('.search-items'); - return -1; - } - return 0; -} + $input.on('input', function() { + if ($input.val() === '') { + $icon.css('color', '#b2b2b2'); + $clear.addClass('hide'); + $searchAssociate.html(''); + $searchItems.show(); + $searchAssociate.hide(); + } else { + $icon.css('color', '#666'); + $clear.removeClass('hide'); + $searchAssociate.show(); + } -//老的选中颜色去掉勾选,新的选中颜色加上勾选 -function changeColorChosed(newColorIndex) { - if (curSizeIndex && $curColorBlock && $curColorBlock.length > 0) { - $curColorBlock.removeClass('chosed'); - $curColorBlock = $($colorRowList.eq(newColorIndex).children().get(curSizeIndex - 1)); - $curColorBlock.addClass('chosed'); - return $curColorBlock.data('num'); - } - return 0; -} + // 联动搜索 + $.ajax({ + url: '/index/search/fuzzyDatas', + data: { + keyword: $input.val() + }, + dataType: 'json', + success: function(data) { + var ajaxHtml = ''; + var i; -//添加门票 -function addTickets(productSku, buyNumber) { - var data = { - productSku: productSku, - buyNumber: buyNumber - }; + if (data.length > 0) { + for (i = 0; i < data.length; i++) { + ajaxHtml += '<li><span class="keyword">' + data[i].keyword + '</span><span class="count">' + + data[i].count + ' items<i class="iconfont"></i></span></li>'; + } - //校验电子票 - $.ajax({ - url: '/cart/index/checkTickets', - dataType: 'json', - data: data, - type: 'post', - success: function (addRestult) { - if (addRestult.code != 200) { - if (addRestult.code == 401) { - var refer = window.location.href; - window.location.href = '//m.yohobuy.com/signin.html?refer=' + refer; + $searchAssociate.html(ajaxHtml); + $searchItems.hide(); + } else { + $searchAssociate.html(''); } - tip.show(addRestult.message); - } else { - $productSku.val(productSku); - $buyNumber.val(buyNumber); - $buyNowForm.submit(); - } - }, - error: function () { - tip.show('网络异常~'); - } + $searchAssociate.find('li').on('touchend', function() { + $buriedpoint.val($(this).find('.keyword').html()); + $search.closest('form').submit(); + }); + }, + error: function() { + tip.show('网络断开连接了~'); + } + }); }); } -init(); +inputAction(); +$clear.on('touchend', function() { + $input.val('').trigger('input'); +}); -$yohoPage.on('touchstart', '.chose-panel', function(e) { - var $cur = $(e.target); +/** + * 手动触发搜索 + */ +$search.on('touchend', function() { + $(this).closest('form').submit(); + return false; +}); - if ($cur.closest('.main').length > 0) { - return; - } +/** + * 获取url参数 + */ +function getQueryString(name) { + var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'); + var r = window.location.search.substr(1).match(reg); - //点击蒙版消失 - hide(); + if (r != null) { + return window.unescape(r[2]); + } + return null; +} - return false; -}); +shopId = getQueryString('shop_id'); +sort = getQueryString('sort'); +outlets = getQueryString('outlets'); +age_level = getQueryString('ageLevel'); +app_type = getQueryString('app_type'); -$yohoPage.on('touchstart', '.color-list .block', function() { - var $this = $(this), - index = $this.index(), - curGoodNum; +/** + * 筛选注册的回调,筛选子项点击后逻辑 + * 需要执行search的场景:1.点选筛选项;2.relaod为true时切换导航;3.下拉加载 + * @param opt {type, id} + */ +function search(opt) { + var setting = {}, + ext, + att, + nav, navType, + page, + $this, + $title, + params; - // 当前颜色已经是选中状态,再点击时 - if ($this.hasClass('chosed')) { + if (searching) { + return; + } - //清空剩余件数的提示 - $allChoseItems.find('.num .left-num').html(''); - $leftNum.val(0); - hasChooseColor = false; + if (opt) { - //当前尺码行隐藏 - $sizeRowList.eq(curSizeIndex).addClass('hide'); + //筛选项变更则重置reload为true + for (att in navInfo) { + if (navInfo.hasOwnProperty(att)) { + navInfo[att].reload = true; + } + } - //目标尺码行显示 - $sizeRowList.eq(0).removeClass('hide'); + //处理active状态 + $listNav.children('.active').removeClass('active'); + $pre.addClass('active'); + switch (opt.type) { + case 'shop_id': + ext = { + shop_id: opt.id + }; + break; + case 'gender': + ext = { + gender: opt.id + }; + break; + case 'brand': + ext = { + brand: opt.id + }; + break; + case 'sort': + ext = { + sort: opt.id + }; + break; + case 'color': + ext = { + color: opt.id + }; + break; + case 'ageLevel': + ext = { + age_level: opt.id + }; + break; + case 'size': + ext = { + size: opt.id + }; + break; + case 'price': + ext = { + price: opt.id + }; + break; + case 'discount': + ext = { + discount: opt.id + }; + break; + case 'outlets': + ext = { + outlets: opt.id + }; + break; + } - curSizeIndex = 0; + $.extend(defaultOpt, ext); //扩展筛选项 + } - //老的选中尺码去掉勾选,新的选中尺码加上勾选 - changeSizeChosed(0); + //导航类别 + if ($pre.hasClass('new')) { + navType = 'newest'; + } else if ($pre.hasClass('price')) { + navType = 'price'; + } else if ($pre.hasClass('discount')) { + navType = 'discount'; + } - // 当前颜色不是选中状态,选中时 - } else { - hasChooseColor = true; + nav = navInfo[navType]; - // 尺码行当前行隐藏 - $sizeRowList.eq(curSizeIndex).addClass('hide'); + page = nav.page + 1; + if (nav.reload) { + page = 1; + } else if (nav.end) { - //老的选中尺码去掉勾选,新的选中尺码加上勾选 - curGoodNum = changeSizeChosed(index + 1); - // 显示剩余数量 - displayGoodNum(curGoodNum); + //不需要重新加载并且数据请求结束 + return; + } - //尺码对应行显示 - $sizeRowList.eq(index + 1).removeClass('hide'); + params = { + type: navType, + order: nav.order, + page: page + }; - curSizeIndex = index + 1; - $curColorBlock = $this; + if (shopId) { + params.shop_id = shopId; + } - // 修改颜色时修改商品图片 - $imgsThumb.addClass('hide').eq(index).removeClass('hide'); + if (age_level) { + params.age_level = age_level } - // 颜色块切换勾选样式 - $this.siblings('.chosed').removeClass('chosed'); + if (sort) { + params.sort = sort; + } - // 特殊处理: 老的选中尺码在新选中的颜色对应尺码中不存在, 需要将颜色的第一行对应的颜色块加上勾选样式. - if (-1 === curGoodNum) { - $curColorBlock = $($colorRowList.eq(0).children().get(index)); - $curColorBlock.addClass('chosed'); + if (brand) { + params.brand = brand; + } - // 当前选择的颜色块,加上勾选样式 - } else { - $this.toggleClass('chosed'); + if (outlets) { + params.outlets = outlets; } - $('#good-num').val(1); + if (app_type) { + params.app_type = app_type; + } - // 设置按钮的样式和文字 - updateConformButtonClassAndText(); + $.extend(setting, defaultOpt, params); - //展览票 - if (ticketsLimit && single) { - //选中日期 - $curSizeBlock = $('.size-list .size-row .block').eq(index + 1); - $curSizeBlock.addClass('chosed'); - // 显示剩余数量 - displayGoodNum($curColorBlock.data('num')); - hasChooseSize = true; - return false; - } + searching = true; + loading.showLoadingMask(); + $.ajax({ + type: 'GET', + url: location.protocol + '//m.yohobuy.com/index/search/search', + data: setting, + success: function(data) { + var noResult = '<p class="no-result">未找到相关搜索结果</p>', + num, + $container; -}).on('touchstart', '.size-list .block', function() { - var $this = $(this), - index, - curGoodNum; + switch (navType) { + case 'newest': + $container = $ngc; + break; + case 'price': + $container = $pgc; + break; + case 'discount': + $container = $dgc; + break; + } - // 当前尺码已经是选中状态,再点击时 - if ($this.hasClass('chosed')) { + if (data === ' ') { + nav.end = true; - //清空剩余件数的提示 - $allChoseItems.find('.num .left-num').html(''); - $leftNum.val(0); - hasChooseSize = false; + if (nav.reload) { + $container.html(noResult); + } + } else { + if (nav.reload) { + $container.html(data); + lazyLoad($container.find('.lazy')); + } else { + num = $container.find('.good-info').length; + $container.append(data); - //当前颜色行隐藏 - $colorRowList.eq(curColorIndex).addClass('hide'); + //lazy good-infos who append in + lazyLoad($container.find('.good-info:gt(' + (num - 1) + ') .lazy')); + } - //目标颜色行显示 - $colorRowList.eq(0).removeClass('hide'); + } - curColorIndex = 0; + nav.reload = false; + nav.page = page; - //老的选中颜色去掉勾选,新的选中颜色加上勾选 - changeColorChosed(0); + searching = false; + loading.hideLoadingMask(); - // 当前尺码不是选中状态,选中时 - } else { - hasChooseSize = true; + window.rePosFooter(); - index = $('#' + $this.data('id')).data('index') - 1; + $('.good-detail-text .name').each(function() { + $this = $(this); + $title = $this.find('a'); - // 颜色当前行隐藏 - $colorRowList.eq(curColorIndex).addClass('hide'); + $title[0].mlellipsis(2); + }); - //老的选中颜色去掉勾选,新的选中颜色加上勾选 - curGoodNum = changeColorChosed(index + 1); + // 用于统计点击了商品列表的第几个商品,序号从1开始计算。 + if (window._yas) { + switch (navType) { + case 'newest': + window._yas(1 * new Date(), '1.0.16', 'yohobuy_m', window._ozuid, + '', $('.new-goods .good-info .good-detail-img .good-thumb')); + break; + case 'price': + window._yas(1 * new Date(), '1.0.16', 'yohobuy_m', window._ozuid, + '', $('.price-goods .good-info .good-detail-img .good-thumb')); + break; + case 'discount': + window._yas(1 * new Date(), '1.0.16', 'yohobuy_m', window._ozuid, + '', $('.discount-goods .good-info .good-detail-img .good-thumb')); + break; + } + } + } + }); - // 显示剩余数量 - displayGoodNum(curGoodNum); +} - //颜色对应行显示 - $colorRowList.eq(index + 1).removeClass('hide'); +require("js/product/suspend-cart"); //悬浮购物车 - curColorIndex = index + 1; - $curSizeBlock = $this; +$.ajax({ + type: 'GET', + url: location.protocol + '//m.yohobuy.com/search/filter', + data: defaultOpt, + success: function(data) { + $goodsContainer.append(data); + + //初始化filter&注册filter回调 + filter.initFilter({ + fCbFn: search, + hCbFn: function() { + + //切换active状态到$pre上 + $pre.addClass('active'); + $pre.siblings('.filter').removeClass('active'); + } + }); } +}); - // 颜色块切换勾选样式 - $this.siblings('.chosed').removeClass('chosed'); - $this.toggleClass('chosed'); - $('#good-num').val(1); +lazyLoad($('.lazy')); - // 设置按钮的样式和文字 - updateConformButtonClassAndText(); +writeSearch.bindWirteLocal($('#search-form')); + +//导航栏点击逻辑说明: +//1.点击非active项时切换active状态 +//2.价格和折扣active状态时继续点击切换排序 +//3.筛选无active时点击展开筛选面板 +//4.筛选有active时点击隐藏筛选面板并恢复点击筛选前active项的active状态 +//5.当前active为筛选并且点击其他项时,隐藏筛选面板 + +$listNav.bind('contextmenu', function(e) { + return false; }); -$yohoPage.on('touchstart', '.btn-minus', function() { - var num = parseInt($num.val(), 10); +$listNav.on('touchend touchcancel', function(e) { + var $this = $(e.target).closest('li'), + nav, + navType, + $active; + var bpIdData = $(this).find('.buriedpoint').attr('data-bp-id') || ''; - leftNum = $('#left-num').val(); + if ($this.hasClass('filter')) { - if (!checkColorSizeNum()) { - return; - } + //筛选面板切换状态 + if ($this.hasClass('active')) { + filter.hideFilter(); - if (num === 1 || 0 === leftNum - 0) { - tip.show('您选择的数量不能为零~'); - return; - } - if (num < 0) { - tip.show('您选择的数量不能为负数~'); - return; - } + //点击筛选钱的active项回复active + $pre.addClass('active'); + $this.removeClass('active'); + } else { + $pre = $this.siblings('.active'); - $num.val(num - 1); -}).on('touchstart', '.btn-plus', function() { - var num = parseInt($num.val(), 10), - maxTips = ticketsLimit ? '每人只可购买' + ticketsLimit + '张当日门票' : '您选择的数量超过了最大库存量~'; + $pre.removeClass('active'); + $this.addClass('active'); - leftNum = ticketsLimit || $('#left-num').val(); + filter.showFilter(); + } + } else { - if (!checkColorSizeNum()) { - return; - } + if ($this.hasClass('new')) { + navType = 'newest'; + } else if ($this.hasClass('price')) { + navType = 'price'; + } else if ($this.hasClass('discount')) { + navType = 'discount'; + } - if (num - 0 === leftNum || 0 === leftNum) { - return; - } + nav = navInfo[navType]; + + if ($this.hasClass('active')) { - //TODO:库存数验证 - if (num > leftNum - 1) { - tip.show(maxTips); - return; - } - $num.val(num + 1); -}).on('touchstart', '#chose-btn-sure', function() { + //最新无排序切换 + if ($this.hasClass('new')) { + return; + } - var productSku, - buyNumber = $('#good-num').val() - 0, + if ($this.hasClass('price') || $this.hasClass('discount')) { - promotionId, - cartGoodData, - url, - num = parseInt($num.val(), 10); + // 价格/折扣切换排序状态 + $this.find('.icon > .iconfont').toggleClass('cur'); + $pre = $this; //更新pre为当前项 + nav.reload = true; //重置reload,HTML会被替换为逆序的HTML + nav.order = nav.order === 0 ? 1 : 0; //切换排序 + } + } else { + $active = $this.siblings('.active'); - //颜色尺码没有选择 - if (!checkColorSizeNum()) { - return; - } + $pre = $this; //$pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项 - if ($('#chose-btn-sure').html() === '已售罄') { - return; - } + if ($active.hasClass('filter')) { - leftNum = $('#left-num').val() - 0; + //若之前active项为筛选,则隐藏筛选面板 + filter.hideFilter(); + } else { - if (num > leftNum) { - tip.show('您选择的数量超过了最大库存量~'); - return; - } - if (num < 0) { - tip.show('您选择的数量小于一件~'); - return; - } - $chosed = $('.block-list>ul>li.chosed'); + //切换container显示 + $goodsContainer.children('.container:not(.hide)').addClass('hide'); - if (2 === $chosed.length && 0 === $chosed.closest('.zero-stock').length) { - productSku = $curSizeBlock.data('skuid'); - promotionId = $('#promotionId').val(); - if (confirming) { - return false; - } + switch (navType) { + case 'newest': + $ngc.removeClass('hide'); + break; - if (!ticketsLimit) { - confirming = true; - } + case 'price': + $pgc.removeClass('hide'); + break; - loading.showLoadingMask(); + case 'discount': + $dgc.removeClass('hide'); + break; + } + } - //立即购买门票 - if (ticketsLimit) { - addTickets(productSku, buyNumber); - return; + $active.removeClass('active'); + $this.addClass('active'); + } + if (nav.reload) { + $(document).trigger('shouldSendBpData', [bpIdData]); + search(); } + } +}); - //针对是否处于编辑模式设置不同的url和需要post的数据 - if (isEdit) { - cartGoodData = { - new_product_sku: productSku, - old_product_sku: oldSknId, - buy_number: buyNumber, - selected: isSelected - }; +function scrollHandler() { - url = '/cart/index/modify'; + //当scroll到1/4$goodsContainer高度后继续请求下一页数据 + if ($(window).scrollTop() + winH > + $(document).height() - 0.25 * $goodsContainer.height()) { + search(); + } +} - } else if (limitProductCode) { +//srcoll to load more +$(window).scroll(function() { + window.requestAnimationFrame(scrollHandler); +}); - $(this).css('background-color', '#ccc').removeAttr('id'); +if ($brandHeader.length > 0) { - // 当前面板选择的是限购商品 - url = $('#limitProductPay').val() + '?limitproductcode=' + limitProductCode + '&sku=' + - productSku + '&skn=' + skn + '&buy_number=' + buyNumber; + //品牌介绍 + btnIntroHammer = new Hammer($brandHeader.children('.btn-intro')[0]); + btnIntroHammer.on('tap', function() { + $introBox.removeClass('hide'); - removePannel(); - loading.showLoadingMask(); + //防止混合scroll发生 + $('body').addClass('overflow-hidden'); + }); - // 调用接口判断商品是否可以购买 - $.ajax({ - url: url - }).then(function(res) { + //关闭品牌介绍 + introHammer = new Hammer(document.getElementById('intro-box')); + introHammer.on('tap', function(e) { + var $this = $(e.target); - // 如果有错,则商品不可购买,执行页面刷新,否则跳到结算页面 - if (res.error) { - tip.show(res.message); - setTimeout(function() { - location.reload(); - }, 2000); - } else { - location.href = url; - } - }).fail(function() { - tip.show('网络异常!'); - setTimeout(function() { - location.reload(); - }, 2000); - }); + e.srcEvent.preventDefault(); - return false; + //关闭品牌介绍box + if ($this.closest('#brand-intro').length === 0 || $this.hasClass('close-intro')) { + $introBox.addClass('hide'); + $('body').removeClass('overflow-hidden'); + } + }); - } else { - cartGoodData = { - productSku: productSku, - buyNumber: buyNumber, - promotionId: promotionId, - isEdit: isEdit, - cartType: queryString.cartType - }; + //品牌收藏 + brandColHammer = new Hammer($brandHeader.children('.btn-col')[0]); + brandColHammer.on('tap', function(e) { + var $this = $(e.target).closest('.btn-col'); - url = '/cart/index/add'; - } + var id = $brandHeader.data('id'), // ID 在 PHP 程序里已经根据是否是基础店铺或者品牌动态处理了 + isBaseShop = $brandHeader.data('isbaseshop'), //tar add 160825 标记是否是基础店铺,否则是品牌 + postUrl = '', // tar add 160825 根据是否是基础店铺,收藏还是取消动态更改 URL 地址 + postData = {}; // tar add 160825 根据是否是基础店铺,收藏还是取消动态更改 POST 数据 - $.ajax({ - method: 'POST', - url: url, - data: cartGoodData - }).done(function(res) { - var cartNum; + /* 根据是基础店铺还是品牌做处理 */ + if (isBaseShop) { + var appVersion = $('input[name="app_version"]').val(); - loading.hideLoadingMask(); - if (res.code === 200 && !isEdit) { - cartNum = res.data.goods_count; - if (cartNum > 99) { - cartNum = '99+'; - } - $('.num-tag').html(cartNum).removeClass('hide'); - confirming = false; + /* 如果是基础店铺,POST 的数据一样 */ + postData = { + shop_id: id, + app_version: appVersion + }; - if (cbFn) { - cbFn(); - } - } - if (res.message && !isEdit) { - tip.show(res.message); + if ($this.hasClass('coled')) { + postUrl = '/product/index/cancelShopFav'; + } else { + postUrl = '/product/index/shopFav'; } + } else { - hide(); + /* 品牌,收藏与取消收藏,请求 URL 一样 */ + postUrl = '/product/opt/favoriteBrand'; + if ($this.hasClass('coled')) { + postData = { + id: id, + opt: 'cancel' + }; + } else { + postData = { + id: id, + opt: 'ok' + }; + } + } - if (isEdit) { - loading.showLoadingMask(); - //延迟刷新,否则面板可能无法隐藏 - setTimeout(function() { + $.ajax({ + type: 'POST', + url: postUrl, + data: postData, + success: function(data) { + if (data.code === 200) { + $this.toggleClass('coled'); - //获取当前页面商品类型:普通商品/预售商品 - window.location.href = '/cart/index/index?cartType=' + $('#cartType').val(); - }, 1); + //提示 + if (postData.opt === 'ok') { + tip.show('添加收藏成功'); + } else { + tip.show('取消收藏成功'); + } + } else if (data.code === 400) { + location.href = data.data;//未登录跳转登录页 + } else { + tip.show(data.message); + } + }, + error: function() { + tip.show('网络断开连接了~'); } - }).fail(function() { - tip.show('网络出了点问题~'); - }).always(function() { - confirming = false; }); - } + }); +} +//初始请求最新第一页数据 +search(); + +$listNav.on('touchstart', 'li', function() { + $listNav.find('li').removeClass('bytouch'); + $(this).addClass('bytouch'); +}).on('touchend touchcancel', 'li', function() { + $listNav.find('li').removeClass('bytouch'); }); -exports.init = init; -exports.show = show; -exports.remove = removePannel; -exports.setEditModeWithSknId = setEditModeWithSknId; -exports.disableNumEdit = disableNumEdit; -exports.setLimitGoodModeWithSknId = setLimitGoodModeWithSknId; - }); -define("js/plugin/inner-scroll", ["jquery"], function(require, exports, module){ +define("js/product/detail/detail", ["jquery","swiper","hammer","lazyload","handlebars","source-map","index"], function(require, exports, module){ /** - * 弹出层可以滚动,遮盖层禁止滚动插件 - * - * @author liangzhifeng<zhifeng.liang@yoho.cn> - * @date: 2016/02/22 + * 商品详情 + * @author: liangzhifeng<zhifeng.liang@yoho.cn> + * @date: 2015/10/20 */ +var $ = require("jquery"), + Swiper = require("swiper"), + Hammer = require("hammer"), + lazyLoad = require("lazyload"); -var $ = require("jquery"); +var goodsSwiper, + $discountFolder = $('.goodsDiscount .discount-folder'), + $discountArrow = $('.goodsDiscount .first-item span'); -function preventDefault(e) { - e = e || window.event; - e.preventDefault && e.preventDefault(); - e.returnValue = false; -} +var goodsDiscountEl = document.getElementById('goodsDiscount'), + goodsDiscountHammer = goodsDiscountEl && new Hammer(goodsDiscountEl), + $discountFirstItem = $(goodsDiscountEl).find('.first-item'); -function stopPropagation(e) { - e = e || window.event; - e.stopPropagation && e.stopPropagation(); - e.cancelBubble = false; -} +var $cart = $('.cart-bar'); -function innerScroll(e) { - var delta = e.wheelDelta || e.originalEvent.wheelDelta || e.detail || 0, - box = $(this).get(0); +var appUrl = $('input[name="limitCodeUrl"]').val(); - // 阻止冒泡到document - // document上已经preventDefault - stopPropagation(e); +var dialog = require("js/me/dialog"); - if ($(box).height() + box.scrollTop >= box.scrollHeight) { - if (delta < 0) { - preventDefault(e); - return false; - } - } - if (box.scrollTop === 0) { - if (delta > 0) { - preventDefault(e); - return false; +//add extra marign-bottom for footer to show the yoho copyright +function showFooter() { + var $cartBar = $('.cart-bar'); + + var timer = setInterval(function() { + if ($cartBar) { + window.reMarginFooter('.cart-bar'); + clearInterval(timer); + } else { + $cartBar = $('.cart-bar'); } - } + }, 200); } -function disableScroll($choseArea) { - var startX, startY; - - // 内部可滚 - $choseArea.on('mousewheel', innerScroll); - - // 移动端touch重写 - $choseArea.on('touchstart', function(e) { - startX = e.originalEvent.changedTouches[0].pageX; - startY = e.originalEvent.changedTouches[0].pageY; - }); - - // 仿innerScroll方法 - $choseArea.on('touchmove', function(e) { - var deltaX = e.originalEvent.changedTouches[0].pageX - startX, - deltaY = e.originalEvent.changedTouches[0].pageY - startY; - - var box = $(this).get(0); - - e.stopPropagation(); - - - // 只能纵向滚 - if (Math.abs(deltaY) < Math.abs(deltaX)) { - e.preventDefault(); - return false; - } +showFooter(); +require("js/product/detail/like"); - if ($(box).height() + box.scrollTop >= box.scrollHeight) { - if (deltaY < 0) { - e.preventDefault(); - return false; - } - } - if (box.scrollTop === 0) { - if (deltaY > 0) { - e.preventDefault(); - return false; - } - } - }); +lazyLoad($('img.lazy')); - $(document).on('mousewheel', preventDefault); - $(document).on('touchmove', preventDefault); +if ($('#goodsDiscount h1').length < 1) { + $('.dropdown').remove(); } -function enableScroll($choseArea) { +//顶部swiper +goodsSwiper = new Swiper('.banner-swiper', { + lazyLoading: true, + lazyLoadingInPrevNext: true, + paginationClickable: true, + pagination: '.banner-top .pagination-inner', + nextButton: '.my-swiper-button-next', + prevButton: '.my-swiper-button-prev', + spaceBetween: 3 +}); - $choseArea.off('touchstart'); - $choseArea.off('touchmove'); - $choseArea.off('mousewheel'); - $(document).off('mousewheel', preventDefault); - $(document).off('touchmove', preventDefault); +//初始化goods-discount +if (0 === $discountFolder.children().length) { + $discountFolder.css('display', 'none'); + $discountArrow.html(''); } -exports.enableScroll = enableScroll; -exports.disableScroll = disableScroll; -}); -define("js/product/detail/desc", ["jquery","lazyload","swiper","index"], function(require, exports, module){ -/** - * 商品详情 --异步加载页面下半部分 - * @author: liangzhifeng<zhifeng.liang@yoho.cn> - * @date: 2015/11/18 - */ -var $ = require("jquery"), - lazyLoad = require("lazyload"), - Swiper = require("swiper"), - loading = require("js/plugin/loading"), - tip = require("js/plugin/tip"); - -var introUrl = $('#introUrl').val(), - winH = $(window).height(), - $productDesc, - searching = false, - end = false; - -var sizeSwiper, - refSwiper; - - -//判断是否要显示向左滑动提示 -function hiddenTips($ele) { - var offsetContainer, - offsetLastColumn; - - if ($ele.length > 0) { - offsetContainer = $ele[0].getBoundingClientRect().right; - offsetLastColumn = $ele.find('.swiper-slide:last-child')[0].getBoundingClientRect().right; - - - if (offsetLastColumn - offsetContainer < 0) { - $ele.next('.tips').css('display', 'none'); +//goods-discount下拉按钮点击事件 +if (goodsDiscountHammer && $discountFolder.children().length > 0) { + goodsDiscountHammer.on('tap', function(e) { + if ($discountFolder.is(':hidden')) { + $discountFirstItem.removeClass('short-text'); + $discountArrow.removeClass('icon-down').addClass('icon-up').html(''); + $discountFolder.slideDown(); } else { - $ele.next('.tips').css('display', 'block'); - } - } -} - -//function isFlexSupport() { -// var flex = document.createElement('p').style.flex, -// webkitFlex = document.createElement('p').style.webkitFlex, -// flexWrap = document.createElement('p').style.flexWrap; -// -// if ((flex === '' || webkitFlex === '') && flexWrap === '') { -// return true; -// } else { -// return false; -// } -//} - -function wrapElements(selector, count) { - var elArr = null; - - $(selector).each(function(idx, el) { - elArr = $(selector).slice(idx, idx + count); - - if (elArr.length === count && idx % count === 0) { - $(elArr).wrapAll($('<div class="js-wraper"></div>')); + $discountFirstItem.addClass('short-text'); + $discountArrow.removeClass('icon-up').addClass('icon-down').html(''); + $discountFolder.slideUp(); } }); } +$('#limit-sale').on('touchend', function(e) { + var loginUrl = $('#loginUrl').val(), + time, + ifr; + e.stopPropagation(); -function search() { - if (searching || end) { - return; - } - searching = true; - - // alert($('#reference-swiper-container .swiper-wrapper').width()); - - loading.showLoadingMask(); - - $.ajax({ - type: 'GET', - url: introUrl, - success: function(data) { - $productDesc = $('#productDesc'); - $productDesc.append(data); + if(loginUrl) { + window.location = loginUrl; + } else { + dialog.showDialog({ + dialogText: '进入有货APP,获取限购码', + hasFooter: { + rightBtnText: '打开Yoho!Buy有货APP' + } + }, function() { + ifr = document.createElement('iframe'); + ifr.src = appUrl; + ifr.style.display = 'none'; + document.body.appendChild(ifr); + window.location.href = appUrl; - window.rePosFooter(); + time = Date.now(); + window.setTimeout(function() { + document.body.removeChild(ifr); + if (Date.now()- time < 3200) { + window.location.href = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.yoho'; + } + }, 3000); - lazyLoad($productDesc.find('img.lazy')); + }, undefined, true); - //尺码信息左右滑动 - sizeSwiper = new Swiper('#size-swiper-container',{ - slidesPerView: 'auto' - }); + $('.dialog-wrapper').off('touchstart').on('touchstart', function(e) { + e.stopPropagation(); + if ($(e.target).hasClass('dialog-wrapper')) { + dialog.hideDialog(); + } + }); + } +}); - //模特试穿左右滑动 - refSwiper = new Swiper('#reference-swiper-container',{ - slidesPerView: 'auto' - }); +require("js/product/detail/desc"); +require("js/product/detail/comments-consults"); +require("js/product/recommend-for-you-product-desc"); - hiddenTips($('#size-swiper-container')); - hiddenTips($('#reference-swiper-container')); +//购物车商品数量 +$.ajax({ + type: 'GET', + url: '/cart/index/count', + success: function(data) { + var count; - //if (!isFlexSupport()) { - // $('.detail .column').removeClass('column').addClass('oldbox'); - //} - wrapElements('.detail .column', 2); - searching = false; - end = true; - loading.hideLoadingMask(); - }, - error: function() { - tip.show('网络断开连接了~'); - searching = false; - loading.hideLoadingMask(); + if (data.code === 200) { + count = data.data.cart_goods_count || 0; + if (count === 0) { + return false; + } + if (count > 99) { + count = '99+'; + } + $cart.find('.num-tag').html(count).removeClass('hide'); } - }); -} - -function scrollHandler() { - if (!end || $(window).scrollTop() + winH >= $(document).height() - 200) { - search(); } +}); + +if ($('.good-detail-page').length > 0) { + $('#yoho-footer').css('border-top', '1px solid #e0e0e0'); } -//srcoll to load more -$(window).scroll(function() { - window.requestAnimationFrame(scrollHandler); -}); }); -define("js/product/detail/comments-consults", ["jquery","hammer"], function(require, exports, module){ +define("js/product/detail/like", ["jquery"], function(require, exports, module){ /** - * 商品详情 --评论和咨询tab + * 商品详情 --添加收藏 * @author: Lynnic - * @date: 2015/11/18 + * @date: 2015/11/24 */ + + var $ = require("jquery"), - tip = require("js/plugin/tip"), - Hammer = require("hammer"); + tip = require("js/plugin/tip"), + chosePanel = require("js/cart/chose-panel"); -var commentsNum,consultsNum; +var productId = $('#productId').val(); -var navtabEle = document.getElementById('nav-tab'), - navtabHammer = navtabEle && new Hammer(navtabEle), +var skn = $('#productSkn').val(), + productCode = $('#limitProductCode').val(); - gotoConsultEle = document.getElementById('goto-consult'), - gotoConsultHammer = gotoConsultEle && new Hammer(gotoConsultEle), + //门票 限购数量 +var ticketsLimit = $('#limitNum').val() || 0; - readmore = document.getElementById('readmore'), - readmoreHammer = readmore && new Hammer(readmore); +$('#likeBtn').on('touchstart', function() { + var opt, + favorite; + var $this = $(this); + if ($this.hasClass('liked')) { + opt = 'cancel'; + favorite = 0; + } else { + opt = 'ok'; + favorite = 1; + } -(function() { - consultsNum = $('#nav-tab .consults-num').html() - 0; + $.ajax({ + type: 'POST', + url: '/product/opt/favoriteProduct', + data: { + id: productId, + opt: opt + }, + success: function(data) { + if (data.code === 200) { + $this.toggleClass('liked'); + + if ('cancel' === opt) { + tip.show('取消收藏成功'); + } else if ('ok' === opt) { + tip.show('收藏成功'); + } + } else if (data.code === 400) { + location.href = data.data;//未登录跳转登录页 + } else { + tip.show(data.message); + } + }, + error: function() { + tip.show('网络断开连接了~'); + } + }); + + // 统计代码:用于统计用户加入或取消商品收藏的动作 + if (window._yas) { + window._yas.sendCustomInfo({ + pd: productId, + fa: favorite + }, true); + } + + return false; +}); + +$('#addtoCart').on('touchstart', function() { + + //门票验证登录 + if (ticketsLimit) { + if (!ticketCheckLogin()) { + return false; + } + } + + $('.cart-bar').hide(); + + productCode && chosePanel.setLimitGoodModeWithSknId(productCode, skn); + chosePanel.show(); + + //统计代码:用于统计用户加入购物车的动作 + if (window._yas) { + window._yas.sendCustomInfo({ + pd: productId, + by: 1 + }, true); + } + + return false; +}); + +ticketCheckOpen(); + +$('#buyLimit').on('touchstart', function() { + tip.show('打开APP可抢购该商品哦~'); + return false; +}); + +//门票立即购买验证登录 + function ticketCheckLogin() { + + if (!window.getUid()) { + var urlArray = window.location.href.split('?'); + window.location.href = '//m.yohobuy.com/signin.html?refer=' + urlArray[0] + '?product_type=ticket'; + return false; + } + return true; + } + +// 门票登录后自动弹出 + function ticketCheckOpen() { + var showPannel = $('#showPannel').val(); + if (showPannel) { + chosePanel.show(); + } + } + +}); +define("js/cart/chose-panel", ["jquery"], function(require, exports, module){ +/** + * 购物车选择尺寸、颜色和数量面板 + * 显示时构造当前商品信息的HTML插入yoho-page;消失则是直接清除HTML + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/10/21 + */ + + +// bikai +// 增加init函数,异步请求的接口需要重新初始化一下选择列表 +// 异步渲染的模板统一插入 #chose-panel ,兼容页面多个选择框 + +var $ = require("jquery"), + tip = require("js/plugin/tip"), + loading = require("js/plugin/loading"); + +var innerScroll = require("js/plugin/inner-scroll"); + +var $chosePanel = $('#chose-panel'), + $num, + $chosed, + $imgsThumb, + $leftNum, + leftNum, + confirming, + curColorIndex, + curSizeIndex, + hasChooseColor, + hasChooseSize, + $curSizeBlock, + $sizeRowList, + $curColorBlock, + $colorRowList, + cbFn, + $allChoseItems, + queryString, + $choseArea, + $cartBar, + $soonSoldOut = $('.soonSoldOut-tag'), + $yohoPage = $('.yoho-page'), + //门票 限购数量 + ticketsLimit = $('#limitNum').val() || 0, + single = $('#single').val() || 0; + $productSku = $('#productSku'), + $buyNumber = $('#buyNumber'), + $buyNowForm = $('#buyNowForm'); + +// 购物车编辑标相关变量 +var isEdit, + isSelected, + oldSknId; + +// 限购商品的商品码。只有限购商品时才会设置。 +var limitProductCode, + + // 限购商品的skn。只有限购商品时才会设置。 + skn; + +//禁用数字编辑 +function disableNumEdit() { + var $numBtn = $('.chose-panel').find('.num .btn>.iconfont'); + + //添加disabled样式 + $numBtn.hasClass('disabled') ? null : $numBtn.addClass('disabled'); + + $yohoPage.off('touchstart', '.btn-minus'); + $yohoPage.off('touchstart', '.btn-plus'); +} + +// 初始化购物车面板显示 +function init() { + hasChooseColor = false; + hasChooseSize = false; + $curSizeBlock = null; + queryString = $.queryString(); + $imgsThumb = $('.chose-panel').find('.thumb'); + $choseArea = $('.chose-panel .main .chose-items'); + $allChoseItems = $('.chose-items'); + $sizeRowList = $('.size-list ul'); + $colorRowList = $('.color-list ul'); + $leftNum = $('#left-num'); + $cartBar = $('.cart-bar'); + curColorIndex = 0; + curSizeIndex = 0; + isEdit = 0; +} - commentsNum = $('#nav-tab .comments-num').html() - 0; +/* + * 设置当前面板为编辑模式 + * + * @param {String} sknId. 当前编辑商品的sknId + * + * @param {Bool} isThisGoodSelected. 当前编辑商品的在购物车中是否被选中 + * + * @return {undefined} + */ +function setEditModeWithSknId(sknId, isThisGoodSelected) { + $('#chose-btn-sure').html('确认'); + isEdit = 1; + oldSknId = sknId; + isSelected = isThisGoodSelected; +} - $('#nav-tab li').each(function() { - $(this).removeClass('focus'); - }); +/* + * 设置当前面板为限购商品模式 + * + * @param {String} code 当前限购商品的商品码 + * + * @param {String} sknId. 当前限购商品的sknId + * + * @return {undefined} + */ +function setLimitGoodModeWithSknId(code, sknId) { + disableNumEdit(); + $('#chose-btn-sure').html('立即购买'); + limitProductCode = code; + skn = sknId; +} - $('#feedback-content .content').each(function() { - $(this).addClass('hide'); - }); - if (0 !== commentsNum) { - $('#nav-tab .comment-nav').addClass('focus'); - $('#feedback-content .comment-content').removeClass('hide'); +//删除面板 +function removePannel() { + var $pannel = $('.chose-panel'), + $promotionId = $('#promotionId'); - } else if (0 !== consultsNum) { - $('#nav-tab .consult-nav').addClass('focus'); - $('#feedback-content .consult-content').removeClass('hide'); + if ($pannel) { + $pannel.remove(); } - $('.goods-consults .consult-item:lt(2)').removeClass('hide'); -})(); - -if (navtabHammer) { - navtabHammer.on('tap', function(e) { - var $this = $(e.target).closest('li'); - var index = $this.index(); - - if ($this.hasClass('comment-nav') && 0 === commentsNum) { - tip.show('暂无商品评价'); - } else { - if (!$this.hasClass('focus')) { + if ($promotionId) { + $promotionId.remove(); + } +} - $('#nav-tab li').each(function() { - $(this).removeClass('focus'); - }); - $('#feedback-content .content').each(function() { - $(this).addClass('hide'); - }); +function checkColorSizeNum() { - $this.addClass('focus'); - $('#feedback-content .content:eq(' + index + ')').removeClass('hide'); - } + if (ticketsLimit) { + //门票 + if (!checkTickets()) { + return; } - }); -} - -// if (consultFooterHammer) { -// consultFooterHammer.on('tap', function() { -// location.href = $(consultFooterEle).data('href'); -// }); -// } + } -if (gotoConsultHammer) { - gotoConsultHammer.on('tap', function() { - location.href = $(gotoConsultEle).find('a').attr('href'); - }); + if (!hasChooseColor && !hasChooseSize) { + tip.show('请选择颜色和尺码~'); + return false; + } else if (!hasChooseColor) { + tip.show('请选择颜色~'); + return false; + } else if (!hasChooseSize) { + tip.show('请选择尺码~'); + return false; + } + return true; } -//咨询页面固定header -if ($('.goods-consults-page').length > 0) { - $('#yoho-header').css('position', 'fixed').css('top', '0'); +//检查门票选择 +function checkTickets() { + if (!hasChooseColor && !hasChooseSize) { + if (single) { + tip.show('请选择日期~'); + } else { + tip.show('请选择日期和区域~'); + }; + return false; + } else if (!hasChooseColor) { + tip.show('请选择日期~'); + return false; + } else if (!hasChooseSize && !single) { + tip.show('请选择区域~'); + return false; + } + return true; } -if ($('.goods-consults-page').length > 0) { - $('#yoho-footer').css('border-top', '1px solid #e0e0e0'); -} -if (readmoreHammer) { - readmoreHammer.on('tap', function() { - $('.readmore').hide(); - $('.goods-consults').find('.consult-item').removeClass('hide'); - return false; - }); -} +function show(html, cb) { + if (html) { + $chosePanel.html(html); + if ($('#promotionId').val() !== '') { + disableNumEdit(); + } + init(); + } -require("js/product/detail/fav"); + $('.chose-panel').show(); + $num = $('#good-num'); + cbFn = cb; -}); -define("js/product/detail/fav", ["jquery","hammer"], function(require, exports, module){ -/** - * 商品详情咨询页 --点赞和帮助功能 - * @author: Lynnic - * @date: 2015/12/09 - */ - - var $ = require("jquery"), - Hammer = require("hammer"), - tip = require("js/plugin/tip"); - -var goodsConsultsEle = $('#goods-consults')[0], - goodsConsultsHammer = goodsConsultsEle && new Hammer(goodsConsultsEle); - -var productId, - total; - -function showCountPlus($el) { - var $count = $el.find('.animate-count'); - - $count.css('display', 'inline'); - $count.animate({ - opacity: 0.25, - fontSize: '0.7rem', - right: '-=5' - }, 300, function() { - $count.css('display', 'none'); - }); -} - -(function() { - var queryStr = window.location.search.substring(1); - - productId = queryStr.split('&')[0].split('=')[1]; - total = queryStr.split('&')[1] ? queryStr.split('&')[1].split('=')[1] : undefined; -})(); - -if (goodsConsultsHammer) { - - goodsConsultsHammer.on('tap', function(e) { - - var $this = $(e.target).closest('li'), - id = $this.closest('.consult-item').data('id'), - count = $this.find('.count').html() - 0, - url; - - if (!$this.hasClass('highlight')) { - - if ($this.hasClass('fav')) { - url = '/product/detail/consultupvote'; - } else if ($this.hasClass('useful')) { - url = '/product/detail/consultuseful'; - } - - $.ajax({ - method: 'post', - url: url, - data: { - id: id, - productId: productId, - total: total - } - }).done(function(data) { - if (data.code === 200) { - showCountPlus($this); - $this.addClass('highlight'); - $this.find('.count').html(count + 1); - } else if (data.code === 401) { - location.href = data.data;//未登录跳转登录页 - } - }).fail(function(data) { - tip.show('网络断开连接了~'); - }); - - } - }); -} -}); -define("js/product/recommend-for-you-product-desc", ["swiper","jquery","index"], function(require, exports, module){ -/** - * 为您优选 - * @author: liangzhifeng<zhifeng.liang@yoho.cn> - * @date: 2015/11/16 - */ - - -var Swiper = require("swiper"), - $ = require("jquery"); - -var recommendSwiper, - $recommendForYou = $('.recommend-for-you'), - preferenceUrl = $('#preferenceUrl').val(), - winH = $(window).height(), - end = false, - requesting = false; - - -function request() { - if (requesting || end) { - return; - } - - requesting = true; - - if (preferenceUrl) { - $.get(preferenceUrl).then(function(html) { - if (html.length < 5) { - $recommendForYou.css('display', 'none'); - } else { - $recommendForYou.html(html).show(); - if ($('#swiper-recommend').length) { - recommendSwiper = new Swiper('#swiper-recommend', { - slidesPerView: 'auto', - grabCursor: true, - slideElement: 'a', - lazyLoading: true, - watchSlidesVisibility: true - }); - } - } - - requesting = false; - end = true; - - window.rePosFooter(); - - }).fail(function() { - $recommendForYou.hide(); - }); - } -} - -function scrollHandler() { - if (!end || $(window).scrollTop() + winH >= $(document).height() - 200) { - request(); - } -} - -$(window).scroll(function() { - window.requestAnimationFrame(scrollHandler); -}); + innerScroll.disableScroll($choseArea); +} -}); -define("js/product/detail/consultform", ["jquery"], function(require, exports, module){ -/** - * 我要咨询提交页面 - * @author: liangzhifeng<zhifeng.liang@yoho.cn> - * @date: 2015/12/01 - */ -var $ = require("jquery"), - tip = require("js/plugin/tip"), - loading = require("js/plugin/loading"); - -var $consultForm = $('.consult-form'), - $submit = $('#submit'), - $content = $('#content'), - productId = $('#product_id').val(), - isSubmiting; - -$submit.on('touchend', function() { - $content.blur(); - $consultForm.submit(); - return false; -}).on('touchstart', function() { - $(this).addClass('highlight'); -}).on('touchend touchcancel', function() { - $(this).removeClass('highlight'); -}); - -$content.on('focus', function() { - if ($content.val() === '请输入咨询内容') { - $content.val(''); - } -}).on('blur', function() { - if ($content.val() === '') { - $content.val('请输入咨询内容'); - } -}); - -// 提交表单请求 -$consultForm.on('submit', function() { - var content; - - if (isSubmiting) { - return false; - } - - // 简单的表单校验 - content = $content.val(); - if (!content || content === '请输入咨询内容') { - tip.show('咨询内容不能为空'); - return false; - } - - isSubmiting = true; - loading.showLoadingMask(); - $.ajax({ - method: 'POST', - url: '/product/detail/consultsubmit', - data: { - product_id: productId, - content: content - } - }).then(function(res) { - if ($.type(res) !== 'object') { - res = {}; - } - if (res.code !== 200) { - tip.show(res.message || '网络出了点问题~'); - isSubmiting = false; - loading.hideLoadingMask(); - } else { - tip.show('提交成功~'); - setTimeout(function() { - window.history.go(-1); - }, 3000); - } - }).fail(function() { - tip.show('网络出了点问题~'); - isSubmiting = false; - }); - return false; -}); +//隐藏当前Panel +function hide() { + $('.chose-panel').hide(); + innerScroll.enableScroll($choseArea); -}); -define("js/product/newsale/hot-rank", ["jquery","swiper","lazyload","index"], function(require, exports, module){ -var $ = require("jquery"), - Swiper = require("swiper"), - lazyLoad = require("lazyload"), - loading = require("js/plugin/loading"); - -var page = 1, - winH, - listTop, - navSwiper, - notab = 0, - sort = '', - id = '', - hotrankNav, - noResult = '<p class="no-result">未找到相关搜索结果</p>'; - -require("js/product/suspend-cart"); - -function hotrank(page, sort, tabId, notab) { - loading.showLoadingMask(); - $.ajax({ - type: 'GET', - url: '/product/newsale/selectHotrank?' + sort, - dataType: 'html', - data: { - page: page, - tab_id: tabId, - notab: notab - }, - success: function(data) { - if (data === ' ') { - if ($('.rank-main').length < 1 && $('.goods-nav').length < 1) { - $('#hotRank').html(noResult); - } else { - if (page === 1) { - hotrankNav = $('.goods-nav').prop('outerHTML'); - - $('#hotRank').html(hotrankNav + noResult); - } - } - } else { - $('.no-result').remove(); - if (page === 1) { - $('.rank-main').remove(); - } - $('#hotRank').append(data); - } - - lazyLoad($('img.lazy')); - $('.rank-main ul li:gt(9)').find('.item-content i').removeClass('top'); - winH = $(window).height(); - if ($('.rank-main').length !== 0) { - $('#yoho-footer').css('position', 'static'); - listTop = $('.rank-main').find('ul').offset().top; - } else { - $('#yoho-footer').css({ - position: 'fixed', - width: '100%' - }); - } - navSwiper = new Swiper('.s-goods-nav', { - grabCursor: true, - slidesPerView: 'auto', - slideElement: 'li' - }); - loading.hideLoadingMask(); - } - }); -} - -function scrollHandler() { - if (page === 2) { - return; - } - if ($(window).scrollTop() + winH < listTop + $('#hotRank').height() - 100) { - return; - } - page = 2; - notab = 1; - hotrank(page, sort, id, notab); -} - -$(window).scroll(function() { - window.requestAnimationFrame(scrollHandler); -}); - -hotrank(page, sort, id, notab); -$('#hotRank').on('touchend touchcancel', function(e) { - var ev = ev || window.event; - var target = ev.target || ev.srcElement; - - if (target.nodeName.toLowerCase() === 'span') { - $('.s-goods-nav .nav-item').removeClass('active'); - target.parentNode.className = 'active ' + target.parentNode.className; - id = target.getAttribute('data-id') ? target.getAttribute('data-id') : ''; - sort = target.getAttribute('data-sort') ? target.getAttribute('data-sort') : ''; - page = 1; - notab = 1; - hotrank(page, sort, id, notab); - } -}); -$('#hotRank').bind('contextmenu', function(e) { - return false; -}); -$('#hotRank').on('touchstart', function(e) { - var ev = ev || window.event; - var target = ev.target || ev.srcElement; - - if (target.nodeName.toLowerCase() === 'span') { - target.parentNode.className = 'bgActive ' + target.parentNode.className; - } -}).on('touchend touchcancel', function() { - $('.s-goods-nav .nav-item').removeClass('bgActive'); -}); - + if ($cartBar.length > 0) { + $cartBar.show(); + } +} + +//修改加入购物车的文字和背景 +function updateConformButtonClassAndText() { + $chosed = $allChoseItems.find('.chosed'); + if (2 === $chosed.closest('.zero-stock').length) { + $('#chose-btn-sure').css('background-color', '#c0c0c0').html('已售罄'); + } else if (limitProductCode || ticketsLimit) { + $('#chose-btn-sure').css('background-color', '#eb0313').html('立即购买'); + } else { + $('#chose-btn-sure').css('background-color', '#eb0313').html(isEdit ? '确认' : '加入购物车'); + } +} + +//显示剩余件数 +function displayGoodNum(curGoodNum) { + + //门票限购 + if (ticketsLimit) { + $allChoseItems.find('.num .left-num').html('限购' + ticketsLimit + '件'); + $leftNum.val(curGoodNum); + return; + } + + //数量大于 + if (curGoodNum > 0) { + if ($soonSoldOut.length > 0) { + $allChoseItems.find('.num .left-num').html('即将售罄'); + } else { + $allChoseItems.find('.num .left-num').html('剩余' + curGoodNum + '件'); + } + + $leftNum.val(curGoodNum); + + //数量小于0 + } else { + $allChoseItems.find('.num .left-num').html(''); + $leftNum.val(0); + } +} + +//老的选中尺码去掉勾选,新的选中尺码加上勾选 +function changeSizeChosed(newSizeIndex) { + var sizes, + queryString, + i; + + if (curColorIndex && $curSizeBlock && $curSizeBlock.length > 0) { + $curSizeBlock.removeClass('chosed'); + sizes = $sizeRowList.eq(newSizeIndex).children(); + for (i = 0; i < sizes.length; i++) { + if ($(sizes[i]).data('id') === $curSizeBlock.data('id')) { + $curSizeBlock = $(sizes[i]); + queryString = '#' + $curSizeBlock.data('id'); + curColorIndex = $(queryString).data('index'); + $curSizeBlock.addClass('chosed'); + return $curSizeBlock.data('num'); + } + } + //特殊处理: 老的选中尺码在新选中的颜色对应尺码中不存在,需要下述1,2,3 + // 1.重置尺码选择的标志变量. + $curSizeBlock = null; + hasChooseSize = false; + + // 2.当前颜色行隐藏 + $colorRowList.eq(curColorIndex).addClass('hide'); + + // 3.目标颜色行第一行显示 + $colorRowList.eq(0).removeClass('hide'); + curColorIndex = 0; + + return -1; + } + return 0; +} + +//老的选中颜色去掉勾选,新的选中颜色加上勾选 +function changeColorChosed(newColorIndex) { + if (curSizeIndex && $curColorBlock && $curColorBlock.length > 0) { + $curColorBlock.removeClass('chosed'); + $curColorBlock = $($colorRowList.eq(newColorIndex).children().get(curSizeIndex - 1)); + $curColorBlock.addClass('chosed'); + return $curColorBlock.data('num'); + } + return 0; +} + +//添加门票 +function addTickets(productSku, buyNumber) { + var data = { + productSku: productSku, + buyNumber: buyNumber + }; + + //校验电子票 + $.ajax({ + url: '/cart/index/checkTickets', + dataType: 'json', + data: data, + type: 'post', + success: function (addRestult) { + if (addRestult.code != 200) { + if (addRestult.code == 401) { + var refer = window.location.href; + window.location.href = '//m.yohobuy.com/signin.html?refer=' + refer; + } + tip.show(addRestult.message); + } else { + $productSku.val(productSku); + $buyNumber.val(buyNumber); + $buyNowForm.submit(); + } + }, + error: function () { + tip.show('网络异常~'); + } + + }); +} + +init(); + + +$yohoPage.on('touchstart', '.chose-panel', function(e) { + var $cur = $(e.target); + + if ($cur.closest('.main').length > 0) { + return; + } + + //点击蒙版消失 + hide(); + + return false; }); -define("js/product/product-category", ["jquery"], function(require, exports, module){ -/** - * 分类 - * @author: berry<lixia.zhang@yoho.cn> - * @date: 2016/4/25 - */ -var $ = require("jquery"); - -var $allProductCell = $('.allproduct'), - $categoryContainer = $('.category-container'), - $contents = $categoryContainer.children('.content'), - $subLevelItem = $categoryContainer.find('.sub-level li'), - $trilangle = $categoryContainer.find('.primary-level-trilangle'); - -//初始化container高度 -(function() { - var $header = $('.yoho-header'); - var h = $(window).height() - $header.outerHeight() - $allProductCell.outerHeight(); - var trilangleRightMargin = $(window).width() * 0.55; - - $categoryContainer.css('min-height', h); - $trilangle.css('margin-right', trilangleRightMargin); - $contents.height(h); - -}()); - - -$categoryContainer.on('touchend', function(e) { - var $this = $(e.target), - $subLevel, - $cur, index, - $subLevelContainer, $trilangleItem; - - $cur = $this.closest('.p-level-item'); - - $subLevelContainer = $this.closest('.content').find('.sub-level-container'); - $subLevelContainer.removeClass('hide'); - - if ($cur.length > 0) { - index = $cur.index(); - $subLevel = $this.closest('.content').find('.sub-level'); - $trilangleItem = $this.closest('.content').find('.primary-level-trilangle'); - - if ($this.hasClass('focus')) { - return; - } - - $subLevel.not('.hide').addClass('hide'); - $subLevel.eq(index).removeClass('hide'); - - $trilangleItem.not('.hide').addClass('hide'); - $trilangleItem.eq(index).removeClass('hide'); - } -}); - -$categoryContainer.find('.sub-level').on('touchstart', 'li', function() { - $subLevelItem.removeClass('highlight'); - $(this).addClass('highlight'); -}).on('touchend touchcancel', 'li', function() { - $(this).removeClass('highlight'); -}); - -$allProductCell.on('touchstart', function() { - $(this).addClass('highlight'); -}).on('touchend touchcancel', function() { - $(this).removeClass('highlight'); -}); -}); -define("js/product/shop", ["jquery","iscroll-probe","lazyload","swiper","hammer","index"], function(require, exports, module){ -/** - * 品牌店铺首页 - */ -var $ = require("jquery"), - IScroll = require("iscroll-probe"), - lazyLoad = require("lazyload"), - Swiper = require("swiper"), - bannerSwiper, - multiSwiper, - myScroll, - imgH, - nav1H, - main1H, - main1oH, - nav2H, - main2oH, - scH, - $nav1 = $('#pos-nav'), - $nav2 = $('#pos-list'), - sTop; +$yohoPage.on('touchstart', '.color-list .block', function() { + var $this = $(this), + index = $this.index(), + curGoodNum; -var tip = require("js/plugin/tip"), - filter = require("js/plugin/filter"), - loading = require("js/plugin/loading"); + // 当前颜色已经是选中状态,再点击时 + if ($this.hasClass('chosed')) { + + //清空剩余件数的提示 + $allChoseItems.find('.num .left-num').html(''); + $leftNum.val(0); + hasChooseColor = false; + + //当前尺码行隐藏 + $sizeRowList.eq(curSizeIndex).addClass('hide'); + + //目标尺码行显示 + $sizeRowList.eq(0).removeClass('hide'); + + curSizeIndex = 0; + + //老的选中尺码去掉勾选,新的选中尺码加上勾选 + changeSizeChosed(0); + + // 当前颜色不是选中状态,选中时 + } else { + hasChooseColor = true; + + // 尺码行当前行隐藏 + $sizeRowList.eq(curSizeIndex).addClass('hide'); + + //老的选中尺码去掉勾选,新的选中尺码加上勾选 + curGoodNum = changeSizeChosed(index + 1); + // 显示剩余数量 + displayGoodNum(curGoodNum); + + //尺码对应行显示 + $sizeRowList.eq(index + 1).removeClass('hide'); + + curSizeIndex = index + 1; + $curColorBlock = $this; + + // 修改颜色时修改商品图片 + $imgsThumb.addClass('hide').eq(index).removeClass('hide'); + } + + // 颜色块切换勾选样式 + $this.siblings('.chosed').removeClass('chosed'); + + // 特殊处理: 老的选中尺码在新选中的颜色对应尺码中不存在, 需要将颜色的第一行对应的颜色块加上勾选样式. + if (-1 === curGoodNum) { + $curColorBlock = $($colorRowList.eq(0).children().get(index)); + $curColorBlock.addClass('chosed'); + + // 当前选择的颜色块,加上勾选样式 + } else { + $this.toggleClass('chosed'); + } + + $('#good-num').val(1); + + // 设置按钮的样式和文字 + updateConformButtonClassAndText(); + + //展览票 + if (ticketsLimit && single) { + //选中日期 + $curSizeBlock = $('.size-list .size-row .block').eq(index + 1); + $curSizeBlock.addClass('chosed'); + // 显示剩余数量 + displayGoodNum($curColorBlock.data('num')); + hasChooseSize = true; + return false; + } + + +}).on('touchstart', '.size-list .block', function() { + var $this = $(this), + index, + curGoodNum; + + // 当前尺码已经是选中状态,再点击时 + if ($this.hasClass('chosed')) { -var $subNav = $('.home-sub-nav'), - $goodsContainer = $('#goods-container'), - $goodsChildren = $goodsContainer.children(), - $ngc = $($goodsChildren.get(0)), - $pgc = $($goodsChildren.get(1)), - $dgc = $($goodsChildren.get(2)), - shopId = $('input[name="shop_id"]').val(), - appVersion = $('input[name="app_version"]').val(), - brand = $('input[name="brand"]').val(), - favId = $('input[name="favId"]').val(); + //清空剩余件数的提示 + $allChoseItems.find('.num .left-num').html(''); + $leftNum.val(0); + hasChooseSize = false; -var winH = $(window).height(), - noResult = '<p class="no-result">未找到相关搜索结果</p>'; + //当前颜色行隐藏 + $colorRowList.eq(curColorIndex).addClass('hide'); -//默认筛选条件 -var defaultOpt = require("js/product/query-param"); + //目标颜色行显示 + $colorRowList.eq(0).removeClass('hide'); -var $listNav = $('#list-nav'), + curColorIndex = 0; - //导航数据信息 - navInfo = { - new: { - order: 1, - reload: true, - page: 1, - end: false - }, - hot: { - order: 1, - reload: true, - page: 1, - end: false - }, - newest: { - order: 1, - reload: true, - page: 0, - end: false - }, - price: { - order: 1, - reload: true, - page: 0, - end: false - }, - discount: { - order: 1, - reload: true, - page: 0, - end: false - } - }, - $pre = $listNav.find('.active'), //纪录进入筛选前的active项,初始为选中项 - searching; + //老的选中颜色去掉勾选,新的选中颜色加上勾选 + changeColorChosed(0); -var viewType = 1, // 1-首页,2-上新,3-人气 - listCount = $('.category-list li').length, - listModValue = 4 - listCount % 4, - listIndex; + // 当前尺码不是选中状态,选中时 + } else { + hasChooseSize = true; + index = $('#' + $this.data('id')).data('index') - 1; + // 颜色当前行隐藏 + $colorRowList.eq(curColorIndex).addClass('hide'); -//焦点效果 -if ($('.banner-swiper').find('li').size() > 1) { - bannerSwiper = new Swiper('.banner-swiper', { - lazyLoading: true, - lazyLoadingInPrevNext: true, - loop: true, - autoplay: 3000, - autoplayDisableOnInteraction: false, - paginationClickable: true, - slideElement: 'li', - pagination: '.banner-top .pagination-inner' - }); -} + //老的选中颜色去掉勾选,新的选中颜色加上勾选 + curGoodNum = changeColorChosed(index + 1); -if ($('.multi-browse').find('li').size() > 1) { - multiSwiper = new Swiper('.multi-browse', { - lazyLoading: true, - lazyLoadingInPrevNext: true, - lazyLoadingOnTransitionStart: true, - grabCursor: true, - slidesPerView: 'auto', - slideElement: 'li', - watchSlidesVisibility: true - }); -} + // 显示剩余数量 + displayGoodNum(curGoodNum); -//根据热门品类的个数来改变样式展示 -// -if ($('.category-list li').length % 4 !== 0) { - $('.category-list li:last-child').addClass('category-list-last-li'); -} + //颜色对应行显示 + $colorRowList.eq(index + 1).removeClass('hide'); -if ($('.category-list li').length < 4) { - $('.category-list').addClass('category-list-top-board'); - $('.category-list').find('.buriedpoint').addClass('category-list-only-one-row'); -} else if ($('.category-list li').length >= 5) { - for (listIndex = listModValue; listIndex >= 0; listIndex--) { - $('.category-list li').eq(listCount - 4 + listIndex - 1).addClass('category-list-last-full-row'); + curColorIndex = index + 1; + $curSizeBlock = $this; } -} -function getPageGoods(info) { - var nav, navType; + // 颜色块切换勾选样式 + $this.siblings('.chosed').removeClass('chosed'); + $this.toggleClass('chosed'); + $('#good-num').val(1); - if (searching) { - return; - } + // 设置按钮的样式和文字 + updateConformButtonClassAndText(); +}); - navType = info.data.type; - nav = navInfo[navType]; +$yohoPage.on('touchstart', '.btn-minus', function() { + var num = parseInt($num.val(), 10); - //不需要重新加载并且数据请求结束 - if (nav.end) { + leftNum = $('#left-num').val(); + if (!checkColorSizeNum()) { return; } - searching = true; - $.ajax({ - type: 'GET', - url: info.url, - data: info.data, - success: function(data) { - if (data === ' ') { - nav.end = true; - } - - info.callBack(data); - }, - error: function() { - alert('网络断开连接了~'); - searching = false; - } - }); -} - -function getParam(req) { - if (brand) { - req.data.brand = brand; + if (num === 1 || 0 === leftNum - 0) { + tip.show('您选择的数量不能为零~'); + return; } - - if (shopId) { - req.data.shop_id = shopId; + if (num < 0) { + tip.show('您选择的数量不能为负数~'); + return; } -} - -function newData(callback) { - var req = {}; - - req.url = location.protocol + '//m.yohobuy.com/index/search/search'; - req.data = { - type: 'new', - order: '1', - page: navInfo.new.page, - tagNew: '1' - }; - getParam(req); + $num.val(num - 1); +}).on('touchstart', '.btn-plus', function() { + var num = parseInt($num.val(), 10), + maxTips = ticketsLimit ? '每人只可购买' + ticketsLimit + '张当日门票' : '您选择的数量超过了最大库存量~'; - req.callBack = function(data) { - $('#new-arrival').append(data); - navInfo.new.page++; - myScroll.refresh(); - lazyLoad($('#new-arrival .lazy')); - scH = $('#scroller').outerHeight(); - searching = false; - callback && $.isFunction(callback) && callback(); - }; - getPageGoods(req); -} + leftNum = ticketsLimit || $('#left-num').val(); -function hotData(callback) { - var req = {}; + if (!checkColorSizeNum()) { + return; + } - req.url = location.protocol + '//m.yohobuy.com/index/search/search'; - req.data = { - type: 'hot', - order: '1', - page: navInfo.hot.page, - showTag: '1' - }; + if (num - 0 === leftNum || 0 === leftNum) { + return; + } - getParam(req); + //TODO:库存数验证 + if (num > leftNum - 1) { + tip.show(maxTips); + return; + } + $num.val(num + 1); +}).on('touchstart', '#chose-btn-sure', function() { - req.callBack = function(data) { - $('#popularity').append(data); - navInfo.hot.page++; - myScroll.refresh(); - lazyLoad($('#popularity .lazy')); - scH = $('#scroller').outerHeight(); - searching = false; - callback && $.isFunction(callback) && callback(); - }; - getPageGoods(req); -} + var productSku, + buyNumber = $('#good-num').val() - 0, -function tabChange(dom, index) { - var li = dom.eq(index); + promotionId, + cartGoodData, + url, + num = parseInt($num.val(), 10); - dom.removeClass('active color'); - li.addClass('active color'); -} + //颜色尺码没有选择 + if (!checkColorSizeNum()) { + return; + } + if ($('#chose-btn-sure').html() === '已售罄') { + return; + } + leftNum = $('#left-num').val() - 0; + if (num > leftNum) { + tip.show('您选择的数量超过了最大库存量~'); + return; + } + if (num < 0) { + tip.show('您选择的数量小于一件~'); + return; + } + $chosed = $('.block-list>ul>li.chosed'); -//首页导航 -(function(nav, posNav, main) { + if (2 === $chosed.length && 0 === $chosed.closest('.zero-stock').length) { + productSku = $curSizeBlock.data('skuid'); + promotionId = $('#promotionId').val(); + if (confirming) { + return false; + } - $(nav + ' li, ' + posNav + ' li').not('li.all-goods').on('touchstart', function() { + if (!ticketsLimit) { + confirming = true; + } - var index = $(this).index(), - activeTab = $(this).attr('tab'); + loading.showLoadingMask(); - if (!$('.filter-mask').hasClass('hide')) { + //立即购买门票 + if (ticketsLimit) { + addTickets(productSku, buyNumber); return; } - $nav1.removeClass('fixed-top'); - tabChange($(nav + ' li'), index); - tabChange($(posNav + ' li'), index); - $(main).hide(); - $('#' + activeTab).fadeIn(); - if (activeTab === 'new-arrival') { - newData(); - viewType = 2; - } else if (activeTab === 'popularity') { - hotData(); - viewType = 3; - } else if (activeTab === 'home-page') { - $nav1.removeClass('fixed-top absolute'); - $nav2.removeClass('fixed-top absolute'); - } - myScroll && myScroll.refresh(); - scH = $('#scroller').outerHeight(); - if (!$nav1.hasClass('hide')) { - myScroll && myScroll.scrollTo(0, 0 - imgH); - } - $nav1.addClass('hide'); - }); -}('#nav', '#pos-nav', '.main')); + //针对是否处于编辑模式设置不同的url和需要post的数据 + if (isEdit) { + cartGoodData = { + new_product_sku: productSku, + old_product_sku: oldSknId, + buy_number: buyNumber, + selected: isSelected + }; -var theY; + url = '/cart/index/modify'; -/** - * 筛选后内容变化,导致nav1位置错掉,重新计算确保位置正确显示 - */ -function reNav1Pos() { - var sTop = theY ? theY : 0; - if (sTop < imgH + main1oH + nav1H) { - if ($nav1.hasClass('hide')) { - $nav1.removeClass('hide'); - } + } else if (limitProductCode) { - if (sTop < imgH + main1H) { - tra = 'translate3d(0, ' + (-scH) + 'px, 0)'; - $nav1.addClass('fixed-top') - .removeClass('absolute') - .css({ - transform: tra, - '-moz-transform': tra, - '-ms-transform': tra, - '-webkit-transform': tra - }); - } else if (sTop < imgH + main1H + nav1H) { - if ($('#home-page').is(':hidden')) { - return false; - } - $nav1.addClass('absolute') - .removeClass('fixed-top'); - tra = 'translate3d(0, ' + (imgH + main1H - sTop - scH) + 'px, 0)'; - $nav1.css({ - transform: tra, - '-moz-transform': tra, - '-ms-transform': tra, - '-webkit-transform': tra - }); - } - } else { - if (!$nav1.hasClass('hide')) { - $nav1.addClass('hide'); - } - } -} + $(this).css('background-color', '#ccc').removeAttr('id'); + // 当前面板选择的是限购商品 + url = $('#limitProductPay').val() + '?limitproductcode=' + limitProductCode + '&sku=' + + productSku + '&skn=' + skn + '&buy_number=' + buyNumber; -function scrollHandler() { - var scrollCall, - sTop = -this.y; + removePannel(); + loading.showLoadingMask(); - var tra; + // 调用接口判断商品是否可以购买 + $.ajax({ + url: url + }).then(function(res) { - theY = sTop; - if (sTop + winH > scH - 0.25 * $goodsContainer.height() - 50) { - if ($pre !== undefined) { - search({ - type: 'shop_id', - id: shopId, - brand: brand, - url: location.protocol + '//m.yohobuy.com/index/search/search', - nextPage: true + // 如果有错,则商品不可购买,执行页面刷新,否则跳到结算页面 + if (res.error) { + tip.show(res.message); + setTimeout(function() { + location.reload(); + }, 2000); + } else { + location.href = url; + } + }).fail(function() { + tip.show('网络异常!'); + setTimeout(function() { + location.reload(); + }, 2000); }); - } - } - if (sTop + winH * 2 > scH) { - scrollCall = function() { - var translate = 'translate3d(0, ' + (-scH) + 'px, 0)'; - $nav1.css({ - transform: translate, - '-moz-transform': translate, - '-ms-transform': translate, - '-webkit-transform': translate - }); - }; - switch (viewType) { - case 2: - newData(scrollCall); - break; - case 3: - hotData(scrollCall); - break; - } - } + return false; - if (sTop < imgH) { - if (!$nav1.hasClass('hide')) { - $nav1.addClass('hide'); - } - if (!$nav2.hasClass('hide')) { - $nav2.addClass('hide'); - } //滑动距离不到导航1 - } else if (sTop < imgH + main1oH + nav1H) { - if ($nav1.hasClass('hide')) { - $nav1.removeClass('hide'); + } else { + cartGoodData = { + productSku: productSku, + buyNumber: buyNumber, + promotionId: promotionId, + isEdit: isEdit, + cartType: queryString.cartType + }; + + url = '/cart/index/add'; } - if (!$nav2.hasClass('hide')) { - $nav2.addClass('hide'); - } //滑动距离不到导航2 - if (sTop < imgH + main1H) { - if (!$nav1.hasClass('fixed-top')) { - tra = 'translate3d(0, ' + (-scH) + 'px, 0)'; - $nav1.addClass('fixed-top') - .removeClass('absolute') - .css({ - transform: tra, - '-moz-transform': tra, - '-ms-transform': tra, - '-webkit-transform': tra - }); - } - } else if (sTop < imgH + main1H + nav1H) { - if ($('#home-page').is(':hidden')) { - return false; + $.ajax({ + method: 'POST', + url: url, + data: cartGoodData + }).done(function(res) { + var cartNum; + + loading.hideLoadingMask(); + if (res.code === 200 && !isEdit) { + cartNum = res.data.goods_count; + if (cartNum > 99) { + cartNum = '99+'; + } + $('.num-tag').html(cartNum).removeClass('hide'); + confirming = false; + + if (cbFn) { + cbFn(); + } } - if (!$nav1.hasClass('absolute')) { - $nav1.addClass('absolute') - .removeClass('fixed-top'); + if (res.message && !isEdit) { + tip.show(res.message); } - tra = 'translate3d(0, ' + (imgH + main1H - sTop - scH) + 'px, 0)'; - $nav1.css({ - transform: tra, - '-moz-transform': tra, - '-ms-transform': tra, - '-webkit-transform': tra - }); - } - } else { - if ($('#home-page').is(':hidden')) { - return false; - } - if (!$nav1.hasClass('hide')) { - $nav1.addClass('hide'); - } - if ($nav2.hasClass('hide')) { - $nav2.removeClass('hide'); - } + hide(); - if (sTop < scH) { - if (!$nav2.hasClass('absolute')) { - $nav2.addClass('absolute') - .removeClass('fixed-top'); - } - tra = 'translate3d(0, ' + (-scH) + 'px, 0)'; - $nav2.css({ - transform: tra, - '-moz-transform': tra, - '-ms-transform': tra, - '-webkit-transform': tra - }); - } + if (isEdit) { + loading.showLoadingMask(); + + //延迟刷新,否则面板可能无法隐藏 + setTimeout(function() { + + //获取当前页面商品类型:普通商品/预售商品 + window.location.href = '/cart/index/index?cartType=' + $('#cartType').val(); + }, 1); + } + }).fail(function() { + tip.show('网络出了点问题~'); + }).always(function() { + confirming = false; + }); } -} -document.addEventListener('touchmove', function(e) { - // sub classify不阻止默认事件 - if ($(e.target).closest('.sub-classify').length === 0) { - e.preventDefault(); - } -}, false); +}); + +exports.init = init; +exports.show = show; +exports.remove = removePannel; +exports.setEditModeWithSknId = setEditModeWithSknId; +exports.disableNumEdit = disableNumEdit; +exports.setLimitGoodModeWithSknId = setLimitGoodModeWithSknId; + +}); +define("js/plugin/inner-scroll", ["jquery"], function(require, exports, module){ +/** + * 弹出层可以滚动,遮盖层禁止滚动插件 + * + * @author liangzhifeng<zhifeng.liang@yoho.cn> + * @date: 2016/02/22 + */ + +var $ = require("jquery"); + +function preventDefault(e) { + e = e || window.event; + e.preventDefault && e.preventDefault(); + e.returnValue = false; +} + +function stopPropagation(e) { + e = e || window.event; + e.stopPropagation && e.stopPropagation(); + e.cancelBubble = false; +} + +function innerScroll(e) { + var delta = e.wheelDelta || e.originalEvent.wheelDelta || e.detail || 0, + box = $(this).get(0); + + // 阻止冒泡到document + // document上已经preventDefault + stopPropagation(e); + + + if ($(box).height() + box.scrollTop >= box.scrollHeight) { + if (delta < 0) { + preventDefault(e); + return false; + } + } + if (box.scrollTop === 0) { + if (delta > 0) { + preventDefault(e); + return false; + } + } +} + +function disableScroll($choseArea) { + var startX, startY; + + // 内部可滚 + $choseArea.on('mousewheel', innerScroll); + + // 移动端touch重写 + $choseArea.on('touchstart', function(e) { + startX = e.originalEvent.changedTouches[0].pageX; + startY = e.originalEvent.changedTouches[0].pageY; + }); + + // 仿innerScroll方法 + $choseArea.on('touchmove', function(e) { + var deltaX = e.originalEvent.changedTouches[0].pageX - startX, + deltaY = e.originalEvent.changedTouches[0].pageY - startY; + + var box = $(this).get(0); + + e.stopPropagation(); + + + // 只能纵向滚 + if (Math.abs(deltaY) < Math.abs(deltaX)) { + e.preventDefault(); + return false; + } + + + if ($(box).height() + box.scrollTop >= box.scrollHeight) { + if (deltaY < 0) { + e.preventDefault(); + return false; + } + } + if (box.scrollTop === 0) { + if (deltaY > 0) { + e.preventDefault(); + return false; + } + } + }); + + $(document).on('mousewheel', preventDefault); + $(document).on('touchmove', preventDefault); +} + +function enableScroll($choseArea) { + + $choseArea.off('touchstart'); + $choseArea.off('touchmove'); + $choseArea.off('mousewheel'); + + $(document).off('mousewheel', preventDefault); + $(document).off('touchmove', preventDefault); +} + +exports.enableScroll = enableScroll; +exports.disableScroll = disableScroll; +}); +define("js/product/detail/desc", ["jquery","lazyload","swiper","index"], function(require, exports, module){ +/** + * 商品详情 --异步加载页面下半部分 + * @author: liangzhifeng<zhifeng.liang@yoho.cn> + * @date: 2015/11/18 + */ +var $ = require("jquery"), + lazyLoad = require("lazyload"), + Swiper = require("swiper"), + loading = require("js/plugin/loading"), + tip = require("js/plugin/tip"); + +var introUrl = $('#introUrl').val(), + winH = $(window).height(), + $productDesc, + searching = false, + end = false; + +var sizeSwiper, + refSwiper; + + +//判断是否要显示向左滑动提示 +function hiddenTips($ele) { + var offsetContainer, + offsetLastColumn; + + if ($ele.length > 0) { + offsetContainer = $ele[0].getBoundingClientRect().right; + offsetLastColumn = $ele.find('.swiper-slide:last-child')[0].getBoundingClientRect().right; + + + if (offsetLastColumn - offsetContainer < 0) { + $ele.next('.tips').css('display', 'none'); + } else { + $ele.next('.tips').css('display', 'block'); + } + } +} + +//function isFlexSupport() { +// var flex = document.createElement('p').style.flex, +// webkitFlex = document.createElement('p').style.webkitFlex, +// flexWrap = document.createElement('p').style.flexWrap; +// +// if ((flex === '' || webkitFlex === '') && flexWrap === '') { +// return true; +// } else { +// return false; +// } +//} + +function wrapElements(selector, count) { + var elArr = null; + + $(selector).each(function(idx, el) { + elArr = $(selector).slice(idx, idx + count); + + if (elArr.length === count && idx % count === 0) { + $(elArr).wrapAll($('<div class="js-wraper"></div>')); + } + }); +} + + + +function search() { + if (searching || end) { + return; + } + searching = true; + + // alert($('#reference-swiper-container .swiper-wrapper').width()); + + loading.showLoadingMask(); + + $.ajax({ + type: 'GET', + url: introUrl, + success: function(data) { + $productDesc = $('#productDesc'); + $productDesc.append(data); + + window.rePosFooter(); + + lazyLoad($productDesc.find('img.lazy')); + + //尺码信息左右滑动 + sizeSwiper = new Swiper('#size-swiper-container',{ + slidesPerView: 'auto' + }); + + //模特试穿左右滑动 + refSwiper = new Swiper('#reference-swiper-container',{ + slidesPerView: 'auto' + }); + + hiddenTips($('#size-swiper-container')); + hiddenTips($('#reference-swiper-container')); + + //if (!isFlexSupport()) { + // $('.detail .column').removeClass('column').addClass('oldbox'); + //} + wrapElements('.detail .column', 2); + searching = false; + end = true; + loading.hideLoadingMask(); + }, + error: function() { + tip.show('网络断开连接了~'); + searching = false; + loading.hideLoadingMask(); + } + }); +} + +function scrollHandler() { + if (!end || $(window).scrollTop() + winH >= $(document).height() - 200) { + search(); + } +} + +//srcoll to load more +$(window).scroll(function() { + window.requestAnimationFrame(scrollHandler); +}); + + +}); +define("js/product/detail/comments-consults", ["jquery","hammer"], function(require, exports, module){ +/** + * 商品详情 --评论和咨询tab + * @author: Lynnic + * @date: 2015/11/18 + */ +var $ = require("jquery"), + tip = require("js/plugin/tip"), + Hammer = require("hammer"); + +var commentsNum,consultsNum; + +var navtabEle = document.getElementById('nav-tab'), + navtabHammer = navtabEle && new Hammer(navtabEle), + + gotoConsultEle = document.getElementById('goto-consult'), + gotoConsultHammer = gotoConsultEle && new Hammer(gotoConsultEle), + + readmore = document.getElementById('readmore'), + readmoreHammer = readmore && new Hammer(readmore); + + + +(function() { + consultsNum = $('#nav-tab .consults-num').html() - 0; + + commentsNum = $('#nav-tab .comments-num').html() - 0; + + $('#nav-tab li').each(function() { + $(this).removeClass('focus'); + }); + + $('#feedback-content .content').each(function() { + $(this).addClass('hide'); + }); + if (0 !== commentsNum) { + $('#nav-tab .comment-nav').addClass('focus'); + $('#feedback-content .comment-content').removeClass('hide'); + + } else if (0 !== consultsNum) { + $('#nav-tab .consult-nav').addClass('focus'); + $('#feedback-content .consult-content').removeClass('hide'); + } + + $('.goods-consults .consult-item:lt(2)').removeClass('hide'); +})(); + +if (navtabHammer) { + navtabHammer.on('tap', function(e) { + var $this = $(e.target).closest('li'); + var index = $this.index(); + + if ($this.hasClass('comment-nav') && 0 === commentsNum) { + tip.show('暂无商品评价'); + } else { + if (!$this.hasClass('focus')) { + + $('#nav-tab li').each(function() { + $(this).removeClass('focus'); + }); + $('#feedback-content .content').each(function() { + $(this).addClass('hide'); + }); + + $this.addClass('focus'); + $('#feedback-content .content:eq(' + index + ')').removeClass('hide'); + } + } + }); +} + +// if (consultFooterHammer) { +// consultFooterHammer.on('tap', function() { +// location.href = $(consultFooterEle).data('href'); +// }); +// } + +if (gotoConsultHammer) { + gotoConsultHammer.on('tap', function() { + location.href = $(gotoConsultEle).find('a').attr('href'); + }); +} + +//咨询页面固定header +if ($('.goods-consults-page').length > 0) { + $('#yoho-header').css('position', 'fixed').css('top', '0'); +} + +if ($('.goods-consults-page').length > 0) { + $('#yoho-footer').css('border-top', '1px solid #e0e0e0'); +} + +if (readmoreHammer) { + readmoreHammer.on('tap', function() { + $('.readmore').hide(); + $('.goods-consults').find('.consult-item').removeClass('hide'); + return false; + }); +} + +require("js/product/detail/fav"); + +}); +define("js/product/detail/fav", ["jquery","hammer"], function(require, exports, module){ +/** + * 商品详情咨询页 --点赞和帮助功能 + * @author: Lynnic + * @date: 2015/12/09 + */ + + var $ = require("jquery"), + Hammer = require("hammer"), + tip = require("js/plugin/tip"); + +var goodsConsultsEle = $('#goods-consults')[0], + goodsConsultsHammer = goodsConsultsEle && new Hammer(goodsConsultsEle); + +var productId, + total; + +function showCountPlus($el) { + var $count = $el.find('.animate-count'); + + $count.css('display', 'inline'); + $count.animate({ + opacity: 0.25, + fontSize: '0.7rem', + right: '-=5' + }, 300, function() { + $count.css('display', 'none'); + }); +} + +(function() { + var queryStr = window.location.search.substring(1); + + productId = queryStr.split('&')[0].split('=')[1]; + total = queryStr.split('&')[1] ? queryStr.split('&')[1].split('=')[1] : undefined; +})(); + +if (goodsConsultsHammer) { + + goodsConsultsHammer.on('tap', function(e) { + + var $this = $(e.target).closest('li'), + id = $this.closest('.consult-item').data('id'), + count = $this.find('.count').html() - 0, + url; + + if (!$this.hasClass('highlight')) { + + if ($this.hasClass('fav')) { + url = '/product/detail/consultupvote'; + } else if ($this.hasClass('useful')) { + url = '/product/detail/consultuseful'; + } + + $.ajax({ + method: 'post', + url: url, + data: { + id: id, + productId: productId, + total: total + } + }).done(function(data) { + if (data.code === 200) { + showCountPlus($this); + $this.addClass('highlight'); + $this.find('.count').html(count + 1); + } else if (data.code === 401) { + location.href = data.data;//未登录跳转登录页 + } + }).fail(function(data) { + tip.show('网络断开连接了~'); + }); + + } + }); +} -/*if (!isIphone) { - return; -}*/ +}); +define("js/product/recommend-for-you-product-desc", ["swiper","jquery","index"], function(require, exports, module){ +/** + * 为您优选 + * @author: liangzhifeng<zhifeng.liang@yoho.cn> + * @date: 2015/11/16 + */ + + +var Swiper = require("swiper"), + $ = require("jquery"); + +var recommendSwiper, + $recommendForYou = $('.recommend-for-you'), + preferenceUrl = $('#preferenceUrl').val(), + winH = $(window).height(), + end = false, + requesting = false; + + +function request() { + if (requesting || end) { + return; + } + + requesting = true; + + if (preferenceUrl) { + $.get(preferenceUrl).then(function(html) { + if (html.length < 5) { + $recommendForYou.css('display', 'none'); + } else { + $recommendForYou.html(html).show(); + if ($('#swiper-recommend').length) { + recommendSwiper = new Swiper('#swiper-recommend', { + slidesPerView: 'auto', + grabCursor: true, + slideElement: 'a', + lazyLoading: true, + watchSlidesVisibility: true + }); + } + } + + requesting = false; + end = true; + + window.rePosFooter(); + + }).fail(function() { + $recommendForYou.hide(); + }); + } +} + +function scrollHandler() { + if (!end || $(window).scrollTop() + winH >= $(document).height() - 200) { + request(); + } +} + +$(window).scroll(function() { + window.requestAnimationFrame(scrollHandler); +}); +}); +define("js/product/detail/consultform", ["jquery"], function(require, exports, module){ +/** + * 我要咨询提交页面 + * @author: liangzhifeng<zhifeng.liang@yoho.cn> + * @date: 2015/12/01 + */ +var $ = require("jquery"), + tip = require("js/plugin/tip"), + loading = require("js/plugin/loading"); + +var $consultForm = $('.consult-form'), + $submit = $('#submit'), + $content = $('#content'), + productId = $('#product_id').val(), + isSubmiting; + +$submit.on('touchend', function() { + $content.blur(); + $consultForm.submit(); + return false; +}).on('touchstart', function() { + $(this).addClass('highlight'); +}).on('touchend touchcancel', function() { + $(this).removeClass('highlight'); +}); + +$content.on('focus', function() { + if ($content.val() === '请输入咨询内容') { + $content.val(''); + } +}).on('blur', function() { + if ($content.val() === '') { + $content.val('请输入咨询内容'); + } +}); + +// 提交表单请求 +$consultForm.on('submit', function() { + var content; + + if (isSubmiting) { + return false; + } + + // 简单的表单校验 + content = $content.val(); + if (!content || content === '请输入咨询内容') { + tip.show('咨询内容不能为空'); + return false; + } + + isSubmiting = true; + loading.showLoadingMask(); + $.ajax({ + method: 'POST', + url: '/product/detail/consultsubmit', + data: { + product_id: productId, + content: content + } + }).then(function(res) { + if ($.type(res) !== 'object') { + res = {}; + } + if (res.code !== 200) { + tip.show(res.message || '网络出了点问题~'); + isSubmiting = false; + loading.hideLoadingMask(); + } else { + tip.show('提交成功~'); + setTimeout(function() { + window.history.go(-1); + }, 3000); + } + }).fail(function() { + tip.show('网络出了点问题~'); + isSubmiting = false; + }); + return false; +}); -//window ready 后重新refresh iscroll -$(window).ready(function() { - myScroll && myScroll.refresh(); - imgH = $('#nav-top').outerHeight(); - nav1H = $('#nav').outerHeight(); - main1H = $('#nav-main').height(); - main1oH = $('#nav-main').outerHeight(); - nav2H = $('#list-nav').outerHeight(); - main2oH = $('#goods-container').outerHeight(); +}); +define("js/product/newsale/hot-rank", ["jquery","swiper","lazyload","index"], function(require, exports, module){ +var $ = require("jquery"), + Swiper = require("swiper"), + lazyLoad = require("lazyload"), + loading = require("js/plugin/loading"); + +var page = 1, + winH, + listTop, + navSwiper, + notab = 0, + sort = '', + id = '', + hotrankNav, + noResult = '<p class="no-result">未找到相关搜索结果</p>'; + +require("js/product/suspend-cart"); + +function hotrank(page, sort, tabId, notab) { + loading.showLoadingMask(); + $.ajax({ + type: 'GET', + url: '/product/newsale/selectHotrank?' + sort, + dataType: 'html', + data: { + page: page, + tab_id: tabId, + notab: notab + }, + success: function(data) { + if (data === ' ') { + if ($('.rank-main').length < 1 && $('.goods-nav').length < 1) { + $('#hotRank').html(noResult); + } else { + if (page === 1) { + hotrankNav = $('.goods-nav').prop('outerHTML'); + + $('#hotRank').html(hotrankNav + noResult); + } + } + } else { + $('.no-result').remove(); + if (page === 1) { + $('.rank-main').remove(); + } + $('#hotRank').append(data); + } + + lazyLoad($('img.lazy')); + $('.rank-main ul li:gt(9)').find('.item-content i').removeClass('top'); + winH = $(window).height(); + if ($('.rank-main').length !== 0) { + $('#yoho-footer').css('position', 'static'); + listTop = $('.rank-main').find('ul').offset().top; + } else { + $('#yoho-footer').css({ + position: 'fixed', + width: '100%' + }); + } + navSwiper = new Swiper('.s-goods-nav', { + grabCursor: true, + slidesPerView: 'auto', + slideElement: 'li' + }); + loading.hideLoadingMask(); + } + }); +} + +function scrollHandler() { + if (page === 2) { + return; + } + if ($(window).scrollTop() + winH < listTop + $('#hotRank').height() - 100) { + return; + } + page = 2; + notab = 1; + hotrank(page, sort, id, notab); +} + +$(window).scroll(function() { + window.requestAnimationFrame(scrollHandler); +}); + +hotrank(page, sort, id, notab); +$('#hotRank').on('touchend touchcancel', function(e) { + var ev = ev || window.event; + var target = ev.target || ev.srcElement; + + if (target.nodeName.toLowerCase() === 'span') { + $('.s-goods-nav .nav-item').removeClass('active'); + target.parentNode.className = 'active ' + target.parentNode.className; + id = target.getAttribute('data-id') ? target.getAttribute('data-id') : ''; + sort = target.getAttribute('data-sort') ? target.getAttribute('data-sort') : ''; + page = 1; + notab = 1; + hotrank(page, sort, id, notab); + } +}); +$('#hotRank').bind('contextmenu', function(e) { + return false; +}); +$('#hotRank').on('touchstart', function(e) { + var ev = ev || window.event; + var target = ev.target || ev.srcElement; + + if (target.nodeName.toLowerCase() === 'span') { + target.parentNode.className = 'bgActive ' + target.parentNode.className; + } +}).on('touchend touchcancel', function() { + $('.s-goods-nav .nav-item').removeClass('bgActive'); +}); + +}); +define("js/product/product-category", ["jquery"], function(require, exports, module){ +/** + * 分类 + * @author: berry<lixia.zhang@yoho.cn> + * @date: 2016/4/25 + */ +var $ = require("jquery"); + +var $allProductCell = $('.allproduct'), + $categoryContainer = $('.category-container'), + $contents = $categoryContainer.children('.content'), + $subLevelItem = $categoryContainer.find('.sub-level li'), + $trilangle = $categoryContainer.find('.primary-level-trilangle'); + +//初始化container高度 +(function() { + var $header = $('.yoho-header'); + var h = $(window).height() - $header.outerHeight() - $allProductCell.outerHeight(); + var trilangleRightMargin = $(window).width() * 0.55; + + $categoryContainer.css('min-height', h); + $trilangle.css('margin-right', trilangleRightMargin); + $contents.height(h); + +}()); + + +$categoryContainer.on('touchend', function(e) { + var $this = $(e.target), + $subLevel, + $cur, index, + $subLevelContainer, $trilangleItem; + + $cur = $this.closest('.p-level-item'); + + $subLevelContainer = $this.closest('.content').find('.sub-level-container'); + $subLevelContainer.removeClass('hide'); + + if ($cur.length > 0) { + index = $cur.index(); + $subLevel = $this.closest('.content').find('.sub-level'); + $trilangleItem = $this.closest('.content').find('.primary-level-trilangle'); + + if ($this.hasClass('focus')) { + return; + } + + $subLevel.not('.hide').addClass('hide'); + $subLevel.eq(index).removeClass('hide'); + + $trilangleItem.not('.hide').addClass('hide'); + $trilangleItem.eq(index).removeClass('hide'); + } +}); + +$categoryContainer.find('.sub-level').on('touchstart', 'li', function() { + $subLevelItem.removeClass('highlight'); + $(this).addClass('highlight'); +}).on('touchend touchcancel', 'li', function() { + $(this).removeClass('highlight'); +}); + +$allProductCell.on('touchstart', function() { + $(this).addClass('highlight'); +}).on('touchend touchcancel', function() { + $(this).removeClass('highlight'); +}); +}); +define("js/product/shop", ["jquery","iscroll-probe","lazyload","swiper","hammer","index"], function(require, exports, module){ +/** + * 品牌店铺首页 + */ - myScroll = new IScroll('#wrapper', { - probeType: 2, - mouseWheel: false, - click: true - }); +var $ = require("jquery"), + IScroll = require("iscroll-probe"), + lazyLoad = require("lazyload"), + Swiper = require("swiper"), + bannerSwiper, + multiSwiper, + myScroll, + imgH, + nav1H, + main1H, + main1oH, + nav2H, + main2oH, + scH, + $nav1 = $('#pos-nav'), + $nav2 = $('#pos-list'), + sTop; - setTimeout(function() { - scH = $('#scroller').outerHeight(); - }, 1000); +var tip = require("js/plugin/tip"), + filter = require("js/plugin/filter"), + loading = require("js/plugin/loading"); +var $subNav = $('.home-sub-nav'), + $goodsContainer = $('#goods-container'), + $goodsChildren = $goodsContainer.children(), + $ngc = $($goodsChildren.get(0)), + $pgc = $($goodsChildren.get(1)), + $dgc = $($goodsChildren.get(2)), + shopId = $('input[name="shop_id"]').val(), + appVersion = $('input[name="app_version"]').val(), + brand = $('input[name="brand"]').val(), + favId = $('input[name="favId"]').val(); - myScroll.on('scroll', scrollHandler); +var winH = $(window).height(), + noResult = '<p class="no-result">未找到相关搜索结果</p>'; - myScroll.on('scrollStart', function() { +//默认筛选条件 +var defaultOpt = require("js/product/query-param"); - // stop auto play when scroll - bannerSwiper && bannerSwiper.stopAutoplay(); +var $listNav = $('#list-nav'), - multiSwiper && multiSwiper.stopAutoplay(); - }); + //导航数据信息 + navInfo = { + new: { + order: 1, + reload: true, + page: 1, + end: false + }, + hot: { + order: 1, + reload: true, + page: 1, + end: false + }, + newest: { + order: 1, + reload: true, + page: 0, + end: false + }, + price: { + order: 1, + reload: true, + page: 0, + end: false + }, + discount: { + order: 1, + reload: true, + page: 0, + end: false + } + }, + $pre = $listNav.find('.active'), //纪录进入筛选前的active项,初始为选中项 + searching; - myScroll.on('scrollEnd', function() { +var viewType = 1, // 1-首页,2-上新,3-人气 + listCount = $('.category-list li').length, + listModValue = 4 - listCount % 4, + listIndex; - // start auto play when scroll end - bannerSwiper && bannerSwiper.startAutoplay(); - multiSwiper && multiSwiper.startAutoplay(); - $('#scroller').trigger('scroll'); - scrollHandler.bind(this)(); +//焦点效果 +if ($('.banner-swiper').find('li').size() > 1) { + bannerSwiper = new Swiper('.banner-swiper', { + lazyLoading: true, + lazyLoadingInPrevNext: true, + loop: true, + autoplay: 3000, + autoplayDisableOnInteraction: false, + paginationClickable: true, + slideElement: 'li', + pagination: '.banner-top .pagination-inner' }); - lazyLoad($('img.lazy')); -}); - -function bindGoodThumbClick() { - $(document).trigger('rebindBpEvent'); } -function search(opt) { - var setting = {}, - ext, - att, - nav, navType, - page; +if ($('.multi-browse').find('li').size() > 1) { + multiSwiper = new Swiper('.multi-browse', { + lazyLoading: true, + lazyLoadingInPrevNext: true, + lazyLoadingOnTransitionStart: true, + grabCursor: true, + slidesPerView: 'auto', + slideElement: 'li', + watchSlidesVisibility: true + }); +} - if (searching) { - return; - } +//根据热门品类的个数来改变样式展示 +// +if ($('.category-list li').length % 4 !== 0) { + $('.category-list li:last-child').addClass('category-list-last-li'); +} - if (!opt.url) { - opt.url = location.protocol + '//m.yohobuy.com/index/search/search'; +if ($('.category-list li').length < 4) { + $('.category-list').addClass('category-list-top-board'); + $('.category-list').find('.buriedpoint').addClass('category-list-only-one-row'); +} else if ($('.category-list li').length >= 5) { + for (listIndex = listModValue; listIndex >= 0; listIndex--) { + $('.category-list li').eq(listCount - 4 + listIndex - 1).addClass('category-list-last-full-row'); } +} - if (!opt.nextPage) { - - //筛选项变更则重置reload为true - for (att in navInfo) { - if (navInfo.hasOwnProperty(att)) { - navInfo[att].reload = true; - } - } +function getPageGoods(info) { + var nav, navType; - $listNav.children('.active').removeClass('active'); - $pre.addClass('active'); - if (opt.hasOwnProperty('id')) { - switch (opt.type) { - case 'shop_id': - ext = { - shop_id: opt.id - }; - break; - case 'gender': - ext = { - gender: opt.id - }; - break; - case 'brand': - ext = { - brand: opt.id - }; - break; - case 'sort': - ext = { - sort: opt.id - }; - break; - case 'color': - ext = { - color: opt.id - }; - break; - case 'size': - ext = { - size: opt.id - }; - break; - case 'price': - ext = { - price: opt.id - }; - break; - case 'discount': - ext = { - discount: opt.id - }; - break; - case 'ageLevel': - ext = { - age_level: opt.id - }; - break; - } - $.extend(defaultOpt, ext); //扩展筛选项 - } + if (searching) { + return; } - //导航类别 - if ($pre.hasClass('new')) { - navType = 'newest'; - } else if ($pre.hasClass('price')) { - navType = 'price'; - } else if ($pre.hasClass('discount')) { - navType = 'discount'; - } + navType = info.data.type; nav = navInfo[navType]; - page = nav.page + 1; - if (nav.reload) { - page = 1; - } else if (nav.end) { + //不需要重新加载并且数据请求结束 + if (nav.end) { - //不需要重新加载并且数据请求结束 return; } - $.extend(setting, defaultOpt, { - type: navType, - order: nav.order, - page: page - }); - - if (brand) { - setting.brand = brand; - } - if (shopId) { - setting.shop_id = shopId; - } searching = true; - loading.showLoadingMask(); - $.ajax({ type: 'GET', - url: opt.url ? opt.url : '', - data: setting, + url: info.url, + data: info.data, success: function(data) { - var $container, - num; - - switch (navType) { - case 'newest': - $container = $ngc; - break; - case 'price': - $container = $pgc; - break; - case 'discount': - $container = $dgc; - break; - } - if (data === ' ') { nav.end = true; - - if (nav.reload) { - $container.html(noResult); - } - } else { - if (nav.reload) { - $container.html(data); - lazyLoad($container.find('.lazy')); - } else { - num = $container.find('.good-info').length; - $container.append(data); - lazyLoad($container.find('.good-info:gt(' + (num - 1) + ') .lazy')); - } } - scH = $('#scroller').outerHeight(); + info.callBack(data); + }, + error: function() { + alert('网络断开连接了~'); + searching = false; + } + }); +} + +function getParam(req) { + if (brand) { + req.data.brand = brand; + } + + if (shopId) { + req.data.shop_id = shopId; + } +} + +function newData(callback) { + var req = {}; + + req.url = location.protocol + '//m.yohobuy.com/index/search/search'; + req.data = { + type: 'new', + order: '1', + page: navInfo.new.page, + tagNew: '1' + }; + + getParam(req); - nav.reload = false; - nav.page = page; + req.callBack = function(data) { + $('#new-arrival').append(data); + navInfo.new.page++; + myScroll.refresh(); + lazyLoad($('#new-arrival .lazy')); + scH = $('#scroller').outerHeight(); + searching = false; + callback && $.isFunction(callback) && callback(); + }; + getPageGoods(req); +} - searching = false; - loading.hideLoadingMask(); +function hotData(callback) { + var req = {}; - window.rePosFooter(); + req.url = location.protocol + '//m.yohobuy.com/index/search/search'; + req.data = { + type: 'hot', + order: '1', + page: navInfo.hot.page, + showTag: '1' + }; - myScroll.refresh(); - reNav1Pos(); + getParam(req); - bindGoodThumbClick(); - }, - error: function() { - tip.show('网络断开连接了~'); - searching = false; - loading.hideLoadingMask(); - } - }); + req.callBack = function(data) { + $('#popularity').append(data); + navInfo.hot.page++; + myScroll.refresh(); + lazyLoad($('#popularity .lazy')); + scH = $('#scroller').outerHeight(); + searching = false; + callback && $.isFunction(callback) && callback(); + }; + getPageGoods(req); } +function tabChange(dom, index) { + var li = dom.eq(index); -$listNav.bind('contextmenu', function(e) { - return false; -}); + dom.removeClass('active color'); + li.addClass('active color'); +} -$subNav.on('touchend touchcancel', function(e) { - var $this = $(e.target).closest('li'), - cname, - nav, - navType, - $active; - var bpIdData = $this.attr('data-bp-id') || ''; - e.preventDefault(); - $(document).trigger('shouldSendBpData', [bpIdData]); - if (typeof $this === 'undefined' || $this.length === 0) { - return; - } - if ($this.hasClass('filter')) { +//首页导航 +(function(nav, posNav, main) { - //筛选面板切换状态 - if ($this.hasClass('active')) { - filter.hideFilter(); + $(nav + ' li, ' + posNav + ' li').not('li.all-goods').on('touchstart', function() { - //点击筛选钱的active项回复active - $pre.addClass('active'); - $this.removeClass('active'); + var index = $(this).index(), + activeTab = $(this).attr('tab'); - myScroll && myScroll.enable(); - } else { - $pre = $this.siblings('.active'); + if (!$('.filter-mask').hasClass('hide')) { + return; + } - $pre.removeClass('active'); - $this.addClass('active'); + $nav1.removeClass('fixed-top'); + tabChange($(nav + ' li'), index); + tabChange($(posNav + ' li'), index); + $(main).hide(); + $('#' + activeTab).fadeIn(); + if (activeTab === 'new-arrival') { + newData(); + viewType = 2; + } else if (activeTab === 'popularity') { + hotData(); + viewType = 3; + } else if (activeTab === 'home-page') { + $nav1.removeClass('fixed-top absolute'); + $nav2.removeClass('fixed-top absolute'); + } + myScroll && myScroll.refresh(); + scH = $('#scroller').outerHeight(); + if (!$nav1.hasClass('hide')) { + myScroll && myScroll.scrollTo(0, 0 - imgH); + } + $nav1.addClass('hide'); + }); +}('#nav', '#pos-nav', '.main')); - myScroll && myScroll.scrollTo(0, -(imgH + main1oH + nav1H)); +var theY; - theY = imgH + main1oH + nav1H; +/** + * 筛选后内容变化,导致nav1位置错掉,重新计算确保位置正确显示 + */ +function reNav1Pos() { + var sTop = theY ? theY : 0; + if (sTop < imgH + main1oH + nav1H) { + if ($nav1.hasClass('hide')) { + $nav1.removeClass('hide'); + } - reNav1Pos(); + if (sTop < imgH + main1H) { + tra = 'translate3d(0, ' + (-scH) + 'px, 0)'; + $nav1.addClass('fixed-top') + .removeClass('absolute') + .css({ + transform: tra, + '-moz-transform': tra, + '-ms-transform': tra, + '-webkit-transform': tra + }); + } else if (sTop < imgH + main1H + nav1H) { + if ($('#home-page').is(':hidden')) { + return false; + } + $nav1.addClass('absolute') + .removeClass('fixed-top'); + tra = 'translate3d(0, ' + (imgH + main1H - sTop - scH) + 'px, 0)'; + $nav1.css({ + transform: tra, + '-moz-transform': tra, + '-ms-transform': tra, + '-webkit-transform': tra + }); + } + } else { + if (!$nav1.hasClass('hide')) { + $nav1.addClass('hide'); + } + } +} - filter.showFilter(); - if ($this.closest('.pos-list').length > 0) { - $('.filter-mask').addClass('call-by-fix').css('top', ''); - } else { - $('.filter-mask').removeClass('call-by-fix').css('top', $this.offset().top + nav1H); - } +function scrollHandler() { + var scrollCall, + sTop = -this.y; - myScroll && myScroll.disable(); + var tra; + + theY = sTop; + if (sTop + winH > scH - 0.25 * $goodsContainer.height() - 50) { + if ($pre !== undefined) { + search({ + type: 'shop_id', + id: shopId, + brand: brand, + url: location.protocol + '//m.yohobuy.com/index/search/search', + nextPage: true + }); } - } else { - if ($this.hasClass('new')) { - cname = '.new'; - navType = 'newest'; - } else if ($this.hasClass('price')) { - cname = '.price'; - navType = 'price'; - } else if ($this.hasClass('discount')) { - cname = '.discount'; - navType = 'discount'; + } + + if (sTop + winH * 2 > scH) { + scrollCall = function() { + var translate = 'translate3d(0, ' + (-scH) + 'px, 0)'; + $nav1.css({ + transform: translate, + '-moz-transform': translate, + '-ms-transform': translate, + '-webkit-transform': translate + }); + }; + switch (viewType) { + case 2: + newData(scrollCall); + break; + case 3: + hotData(scrollCall); + break; + } + } + + if (sTop < imgH) { + if (!$nav1.hasClass('hide')) { + $nav1.addClass('hide'); + } + if (!$nav2.hasClass('hide')) { + $nav2.addClass('hide'); + } //滑动距离不到导航1 + } else if (sTop < imgH + main1oH + nav1H) { + if ($nav1.hasClass('hide')) { + $nav1.removeClass('hide'); + } + if (!$nav2.hasClass('hide')) { + $nav2.addClass('hide'); + } //滑动距离不到导航2 + + if (sTop < imgH + main1H) { + if (!$nav1.hasClass('fixed-top')) { + tra = 'translate3d(0, ' + (-scH) + 'px, 0)'; + $nav1.addClass('fixed-top') + .removeClass('absolute') + .css({ + transform: tra, + '-moz-transform': tra, + '-ms-transform': tra, + '-webkit-transform': tra + }); + } + } else if (sTop < imgH + main1H + nav1H) { + if ($('#home-page').is(':hidden')) { + return false; + } + if (!$nav1.hasClass('absolute')) { + $nav1.addClass('absolute') + .removeClass('fixed-top'); + } + tra = 'translate3d(0, ' + (imgH + main1H - sTop - scH) + 'px, 0)'; + $nav1.css({ + transform: tra, + '-moz-transform': tra, + '-ms-transform': tra, + '-webkit-transform': tra + }); + } + } else { + if ($('#home-page').is(':hidden')) { + return false; } - myScroll && myScroll.enable(); - - nav = navInfo[navType]; - - if ($this.hasClass('active')) { + if (!$nav1.hasClass('hide')) { + $nav1.addClass('hide'); + } + if ($nav2.hasClass('hide')) { + $nav2.removeClass('hide'); + } - //最新无排序切换 - if ($this.hasClass('new')) { - return; + if (sTop < scH) { + if (!$nav2.hasClass('absolute')) { + $nav2.addClass('absolute') + .removeClass('fixed-top'); } + tra = 'translate3d(0, ' + (-scH) + 'px, 0)'; + $nav2.css({ + transform: tra, + '-moz-transform': tra, + '-ms-transform': tra, + '-webkit-transform': tra + }); + } + } +} - if ($this.hasClass('price') || $this.hasClass('discount')) { - $this = $subNav.find(cname); +document.addEventListener('touchmove', function(e) { + // sub classify不阻止默认事件 + if ($(e.target).closest('.sub-classify').length === 0) { + e.preventDefault(); + } +}, false); - // 价格/折扣切换排序状态 - $this.find('.icon > .iconfont').toggleClass('cur'); - $pre = $this; //更新pre为当前项 - nav.reload = true; //重置reload,HTML会被替换为逆序的HTML - nav.order = nav.order === 0 ? 1 : 0; //切换排序 +/*if (!isIphone) { + return; +}*/ - $goodsContainer.children('.container:not(.hide)').addClass('hide'); - switch (navType) { - case 'newest': - $ngc.removeClass('hide'); - break; +//window ready 后重新refresh iscroll +$(window).ready(function() { + myScroll && myScroll.refresh(); + imgH = $('#nav-top').outerHeight(); + nav1H = $('#nav').outerHeight(); + main1H = $('#nav-main').height(); + main1oH = $('#nav-main').outerHeight(); + nav2H = $('#list-nav').outerHeight(); + main2oH = $('#goods-container').outerHeight(); - case 'price': - $pgc.removeClass('hide'); - break; - case 'discount': - $dgc.removeClass('hide'); - break; - } + myScroll = new IScroll('#wrapper', { + probeType: 2, + mouseWheel: false, + click: true + }); - } - } else { - $active = $subNav.find('.active'); + setTimeout(function() { + scH = $('#scroller').outerHeight(); + }, 1000); - $pre = $this; //$pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项 - if ($active.hasClass('filter')) { + myScroll.on('scroll', scrollHandler); - //若之前active项为筛选,则隐藏筛选面板 - filter.hideFilter(); - } else { + myScroll.on('scrollStart', function() { - //切换container显示 - $goodsContainer.children('.container:not(.hide)').addClass('hide'); + // stop auto play when scroll + bannerSwiper && bannerSwiper.stopAutoplay(); - switch (navType) { - case 'newest': - $ngc.removeClass('hide'); - break; + multiSwiper && multiSwiper.stopAutoplay(); + }); - case 'price': - $pgc.removeClass('hide'); - break; + myScroll.on('scrollEnd', function() { - case 'discount': - $dgc.removeClass('hide'); - break; - } - } + // start auto play when scroll end + bannerSwiper && bannerSwiper.startAutoplay(); - $subNav.children().removeClass('active'); - $subNav.find(cname).addClass('active'); - } + multiSwiper && multiSwiper.startAutoplay(); - if (nav.reload) { - search({ - type: 'shop_id', - id: shopId, - brand: brand, - url: location.protocol + '//m.yohobuy.com/index/search/search', - nextPage: false - }); - } - } - e.stopPropagation(); + $('#scroller').trigger('scroll'); + scrollHandler.bind(this)(); + }); + lazyLoad($('img.lazy')); }); -filter.initFilter({ - fCbFn: function(option) { - search(option); - myScroll && myScroll.enable(); - }, - hCbFn: function() { - - //切换active状态到$pre上 - $pre.addClass('active'); - $pre.siblings('.filter').removeClass('active'); +function bindGoodThumbClick() { + $(document).trigger('rebindBpEvent'); +} - myScroll && myScroll.enable(); - }, - missStatus: true -}); +function search(opt) { + var setting = {}, + ext, + att, + nav, navType, + page; -$listNav.on('touchstart', 'li', function(e) { - $(this).addClass('bytouch'); -}).on('touchend touchcancel', function() { - $listNav.find('li').removeClass('bytouch'); - myScroll && myScroll.refresh(); -}); + if (searching) { + return; + } -$nav2.on('touchstart', 'li', function(e) { - $(this).addClass('bytouch'); -}).on('touchend touchcancel', function() { - $nav2.find('li').removeClass('bytouch'); - myScroll && myScroll.refresh(); -}); + if (!opt.url) { + opt.url = location.protocol + '//m.yohobuy.com/index/search/search'; + } -//底部导航点击 -function fotterClick(group) { - $(group + ' li').on('touchstart', function() { - $('.sub-group').addClass('hide'); - $(this).find('.sub-group').removeClass('hide'); - }); -} + if (!opt.nextPage) { -fotterClick('.shop-foot-wrapper'); + //筛选项变更则重置reload为true + for (att in navInfo) { + if (navInfo.hasOwnProperty(att)) { + navInfo[att].reload = true; + } + } -function stopPropagation(e) { - if (e.stopPropagation) { - e.stopPropagation(); - } else { - e.cancelBubble = true; + $listNav.children('.active').removeClass('active'); + $pre.addClass('active'); + if (opt.hasOwnProperty('id')) { + switch (opt.type) { + case 'shop_id': + ext = { + shop_id: opt.id + }; + break; + case 'gender': + ext = { + gender: opt.id + }; + break; + case 'brand': + ext = { + brand: opt.id + }; + break; + case 'sort': + ext = { + sort: opt.id + }; + break; + case 'color': + ext = { + color: opt.id + }; + break; + case 'size': + ext = { + size: opt.id + }; + break; + case 'price': + ext = { + price: opt.id + }; + break; + case 'discount': + ext = { + discount: opt.id + }; + break; + case 'ageLevel': + ext = { + age_level: opt.id + }; + break; + } + $.extend(defaultOpt, ext); //扩展筛选项 + } } -} - -$(document).bind('touchstart', function() { - $('.sub-group').addClass('hide'); -}); -$('.shop-foot-wrapper').bind('touchstart', function(e) { - stopPropagation(e); -}); + //导航类别 + if ($pre.hasClass('new')) { + navType = 'newest'; + } else if ($pre.hasClass('price')) { + navType = 'price'; + } else if ($pre.hasClass('discount')) { + navType = 'discount'; + } + nav = navInfo[navType]; -//收藏 -function postCollect(info) { - var url = ''; + page = nav.page + 1; + if (nav.reload) { + page = 1; + } else if (nav.end) { - if (searching) { + //不需要重新加载并且数据请求结束 return; } + $.extend(setting, defaultOpt, { + type: navType, + order: nav.order, + page: page + }); + + if (brand) { + setting.brand = brand; + } + if (shopId) { + setting.shop_id = shopId; + } + searching = true; + loading.showLoadingMask(); $.ajax({ - method: 'get', - url: location.protocol + '//m.yohobuy.com' + info.url, - data: info.data, - + type: 'GET', + url: opt.url ? opt.url : '', + data: setting, success: function(data) { + var $container, + num; - if (data.code === 200) { - if ($('#collect').hasClass('alreadyCollect')) { - $('#collect').attr('class', 'notCollect'); + switch (navType) { + case 'newest': + $container = $ngc; + break; + case 'price': + $container = $pgc; + break; + case 'discount': + $container = $dgc; + break; + } + + if (data === ' ') { + nav.end = true; + + if (nav.reload) { + $container.html(noResult); + } + } else { + if (nav.reload) { + $container.html(data); + lazyLoad($container.find('.lazy')); } else { - $('#collect').attr('class', 'alreadyCollect'); + num = $container.find('.good-info').length; + $container.append(data); + lazyLoad($container.find('.good-info:gt(' + (num - 1) + ') .lazy')); } } - if (data.code === 401) { - url = 'http://m.yohobuy.com/signin.html?refer=' + encodeURIComponent(location.href) + '&openby:yohobuy='; - url += JSON.stringify({"action": "go.weblogin", "params": { "jumpurl": { "url": 'http://m.yohobuy.com' + location.pathname, "param": info.data }, "requesturl": { "param": {}, "url": "" }, "priority": "N" } }); - - $('body').append('<a href=\'' + url + '\'><span class="jump-login"><span></a>'); + scH = $('#scroller').outerHeight(); - $('.jump-login').click(); - } + nav.reload = false; + nav.page = page; - setTimeout(function() { - myScroll.refresh(); - scH = $('#scroller').outerHeight(); - }, 1000); searching = false; + loading.hideLoadingMask(); + + window.rePosFooter(); + + myScroll.refresh(); + reNav1Pos(); + + bindGoodThumbClick(); }, error: function() { - alert('网络断开连接了~'); + tip.show('网络断开连接了~'); searching = false; + loading.hideLoadingMask(); } }); } -function collectShop() { - var qew = {}; - qew.url = '/product/index/shopFav'; - qew.data = { - shop_id: favId ? favId : shopId, - app_version: appVersion - }; - postCollect(qew); -} +$listNav.bind('contextmenu', function(e) { + return false; +}); -function cancelShop() { - var qew = {}; +$subNav.on('touchend touchcancel', function(e) { + var $this = $(e.target).closest('li'), + cname, + nav, + navType, + $active; + var bpIdData = $this.attr('data-bp-id') || ''; - qew.url = '/product/index/cancelShopFav'; - qew.data = { - shop_id: favId ? favId : shopId, - app_version: appVersion - }; - postCollect(qew); -} + e.preventDefault(); + $(document).trigger('shouldSendBpData', [bpIdData]); -$('#collect').on('touchstart', function(e) { - if ($('#collect').hasClass('alreadyCollect')) { - cancelShop(); - } else { - collectShop(); + if (typeof $this === 'undefined' || $this.length === 0) { + return; } -}); - -}); -define("js/me/entry", ["jquery","hammer","lazyload","swiper","handlebars","source-map","mlellipsis","index"], function(require, exports, module){ -/** - * 个人中心js打包入口文件 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/11/10 - */ - -require("js/me/order"); -require("js/me/order-detail"); -require("js/me/fav"); -require("js/me/suggest"); -require("js/me/index"); -require("js/me/coupons"); -require("js/me/online-service"); -require("js/me/address"); -require("js/me/suggest"); -require("js/me/browse-record"); -require("js/me/address-act"); -require("js/me/logistic"); -require("js/me/pay"); -require("js/me/personal-details"); -require("js/me/currency"); -require("js/me/currency-new"); -require("js/me/message"); -require("js/me/message-detail"); -require("js/me/address-modify"); - -}); -define("js/me/order", ["jquery","hammer","lazyload","swiper","handlebars","source-map","index"], function(require, exports, module){ -/** - * 个人中心--我的订单 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/11/10 - */ -var $ = require("jquery"), - Hammer = require("hammer"), - lazyLoad = require("lazyload"), - tip = require("js/plugin/tip"), - Swiper = require("swiper"); + if ($this.hasClass('filter')) { -var $navLi = $('#order-nav > li'), - $orderContainer = $('#order-container'); + //筛选面板切换状态 + if ($this.hasClass('active')) { + filter.hideFilter(); -var $curContainer = $orderContainer.children('.orders:not(.hide)');//保存当前显示的order-container + //点击筛选钱的active项回复active + $pre.addClass('active'); + $this.removeClass('active'); -var winH = $(window).height(); + myScroll && myScroll.enable(); + } else { + $pre = $this.siblings('.active'); -var activeType = $navLi.filter('.active').data('type'); //当前active的项的index + $pre.removeClass('active'); + $this.addClass('active'); -var order = { - page: 0, - end: false -}; + myScroll && myScroll.scrollTo(0, -(imgH + main1oH + nav1H)); -var inAjax = false; + theY = imgH + main1oH + nav1H; -var loading = require("js/plugin/loading"); + reNav1Pos(); -var dialog = require("js/me/dialog"); - -var orderHammer, - $reaMask = $('.reason-mask'), - reasonSwiper; - -// 减少计时 -function downCount(item) { - var hoursItem = item.find('.hours'); - - var difference = hoursItem.text(),// difference of dates - interval; - /** - * Main downCount function that calculates everything - */ - function countdown() { - - // basic math variables - var _second = 1000, - _minute = _second * 60, - _hour = _minute * 60, - _day = _hour * 24, - hours, - minutes, - seconds; - - // calculate dates - hours = Math.floor((difference % _day) / _hour), - minutes = Math.floor((difference % _hour) / _minute), - seconds = Math.floor((difference % _minute) / _second); - - // fix dates so that it will show two digets - hours = (String(hours).length >= 2) ? hours : '0' + hours; - minutes = (String(minutes).length >= 2) ? minutes : '0' + minutes; - seconds = (String(seconds).length >= 2) ? seconds : '0' + seconds; - - // set to DOM - item.removeClass('hide'); - if (hours === '00') { - hoursItem.text('剩余' + minutes + ':' + seconds); - } else { - hoursItem.text('剩余' + hours + ':' + minutes + ':' + seconds); - } + filter.showFilter(); - difference -= 1000; + if ($this.closest('.pos-list').length > 0) { + $('.filter-mask').addClass('call-by-fix').css('top', ''); + } else { + $('.filter-mask').removeClass('call-by-fix').css('top', $this.offset().top + nav1H); + } - if (difference <= 0) { - clearInterval(interval);// stop timer - return; + myScroll && myScroll.disable(); } - } - if (difference !== '' && difference > 0) { - interval = setInterval(countdown, 1000);// start - } -} - -// 初始化时间 -function setTime() { - - $('.order').each(function() { - var item = $(this).find('.count-down'); - - if (!$(this).hasClass('hide')) { - downCount(item); + } else { + if ($this.hasClass('new')) { + cname = '.new'; + navType = 'newest'; + } else if ($this.hasClass('price')) { + cname = '.price'; + navType = 'price'; + } else if ($this.hasClass('discount')) { + cname = '.discount'; + navType = 'discount'; } - }); -} - -//加载订单 -function getOrders(option) { - var opt = { - type: activeType, - page: order.page + 1 - }; - - var show = option && !option.noLoadingMask; - - if (inAjax) { - return; - } - inAjax = true; - show && loading.showLoadingMask(); + myScroll && myScroll.enable(); - $.ajax({ - type: 'GET', - url: '/home/getOrders', - data: opt, - success: function(data) { - var num; + nav = navInfo[navType]; - if (data !== ' ') { - order.page = opt.page; + if ($this.hasClass('active')) { - if (opt.page === 1) { - $curContainer.html(data); - lazyLoad($curContainer.find('.lazy'), { - try_again_css: 'order-failure' - }); - } else { - num = $curContainer.children('.order').length; - $curContainer.append(data); + //最新无排序切换 + if ($this.hasClass('new')) { + return; + } - //lazyload - lazyLoad($curContainer.children('.order:gt(' + (num - 1) + ')').find('.lazy'), { - try_again_css: 'order-failure' - }); - } + if ($this.hasClass('price') || $this.hasClass('discount')) { + $this = $subNav.find(cname); - window.rePosFooter(); //重新计算底部位置 - } else { - order.end = true; - } + // 价格/折扣切换排序状态 + $this.find('.icon > .iconfont').toggleClass('cur'); + $pre = $this; //更新pre为当前项 + nav.reload = true; //重置reload,HTML会被替换为逆序的HTML + nav.order = nav.order === 0 ? 1 : 0; //切换排序 - inAjax = false; - show && loading.hideLoadingMask(); - setTime(); - } - }); -} + $goodsContainer.children('.container:not(.hide)').addClass('hide'); -lazyLoad({ - try_again_css: 'order-failure' -}); + switch (navType) { + case 'newest': + $ngc.removeClass('hide'); + break; -//初始化导航 -(function() { - var liCount = $navLi.length; + case 'price': + $pgc.removeClass('hide'); + break; - //默认4个导航项 - if (liCount === 4) { - return; - } + case 'discount': + $dgc.removeClass('hide'); + break; + } - $navLi.width(100 / liCount + '%'); -}()); + } + } else { + $active = $subNav.find('.active'); -loading.init($('body')); //满屏loading + $pre = $this; //$pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项 -//点击订单区域跳转订单详情页 -orderHammer = new Hammer(document.getElementById('order-container')); -orderHammer.on('tap', function(e) { - var $cur = $(e.target), - $order, - id, - url; + if ($active.hasClass('filter')) { - if ($cur.closest('.locHref').length > 0) { - return; - } + //若之前active项为筛选,则隐藏筛选面板 + filter.hideFilter(); + } else { - $order = $cur.closest('.order'); - id = $order.data('id'); + //切换container显示 + $goodsContainer.children('.container:not(.hide)').addClass('hide'); - $reaMask.data('orderId', id); + switch (navType) { + case 'newest': + $ngc.removeClass('hide'); + break; - if ($cur.closest('.del').length > 0) { + case 'price': + $pgc.removeClass('hide'); + break; - //Order delete - dialog.showDialog({ - dialogText: '确定删除订单吗?', - hasFooter: { - leftBtnText: '取消', - rightBtnText: '确定' + case 'discount': + $dgc.removeClass('hide'); + break; + } } - }, function() { - $.ajax({ - type: 'GET', - url: '/home/delOrder', - data: { - id: id - }, - success: function(data) { - dialog.hideDialog(); - if (data.message) { - tip.show(data.message); - } - if (data.code === 200) { - //删除订单页面刷新 - window.location.reload(); - } - }, - error: function() { - tip.show('取消订单失败'); - } + $subNav.children().removeClass('active'); + $subNav.find(cname).addClass('active'); + } + + if (nav.reload) { + search({ + type: 'shop_id', + id: shopId, + brand: brand, + url: location.protocol + '//m.yohobuy.com/index/search/search', + nextPage: false }); - }); - } else if ($cur.closest('.cancel').length > 0) { - $reaMask.css('visibility', 'visible'); - } else if ($cur.closest('.order-goods').length > 0) { - - //Location to order detail - url = $order.data('href'); - location.href = url; - } else if ($cur.closest('.rebuy').length > 0) { - $.ajax({ - type: 'GET', - url: '/home/readd', - data: { - orderCode: id - }, - success: function(res) { - tip.show(res.message); - location.href = '/cart/index/index'; - }, - error: function(res) { - tip.show(res.message); - } - }); + } } + e.stopPropagation(); }); -function scrollHandler() { - if (order.end === false && $(window).scrollTop() + winH > - $(document).height() - 0.25 * $orderContainer.height()) { +filter.initFilter({ + fCbFn: function(option) { + search(option); + myScroll && myScroll.enable(); + }, + hCbFn: function() { - //下拉请求时不显示mask - getOrders({ - noLoadingMask: true - }); - } -} + //切换active状态到$pre上 + $pre.addClass('active'); + $pre.siblings('.filter').removeClass('active'); -//srcoll to load more -$(window).scroll(function() { - window.requestAnimationFrame(scrollHandler); + myScroll && myScroll.enable(); + }, + missStatus: true }); -//初始化请求第一页数据 -getOrders(); - -$(function() { - reasonSwiper = new Swiper('.box-main', { - direction: 'vertical', - slidesPerView: 5, - centeredSlides: true, - initialSlide: 0, - onSlideChangeStart: function(reasonSwiper) { - var activeIndex = reasonSwiper.activeIndex, - slides = reasonSwiper.slides, - i = 0; - - if (slides.length !== 1) { - if (activeIndex === 0) { - for (i = 1; i < slides.length; i++) { - $(slides[i]).css('transform', ''); - } - } else if (activeIndex === slides.length - 1) { - for (i = 0; i < activeIndex; i++) { - $(slides[i]).css('transform', 'rotateX(' + (30 + (activeIndex - i) * 12) + 'deg)'); - } - } else { - for (i = 0; i < activeIndex; i++) { - $(slides[i]).css('transform', 'rotateX(' + (30 + (activeIndex - i) * 12) + 'deg)'); - } - for (i = activeIndex + 1; i < slides.length; i++) { - $(slides[i]).css('transform', ''); - } - } - } - $(slides[activeIndex]).css('transform', ''); - } - }); +$listNav.on('touchstart', 'li', function(e) { + $(this).addClass('bytouch'); +}).on('touchend touchcancel', function() { + $listNav.find('li').removeClass('bytouch'); + myScroll && myScroll.refresh(); }); -$reaMask.find('.box-cmp').on('touchend', function(e) { - var selSolid = reasonSwiper.slides[reasonSwiper.activeIndex], - reason = $(selSolid).text(), - reasonId = $(selSolid).data('reasonId'); +$nav2.on('touchstart', 'li', function(e) { + $(this).addClass('bytouch'); +}).on('touchend touchcancel', function() { + $nav2.find('li').removeClass('bytouch'); + myScroll && myScroll.refresh(); +}); - $.ajax({ - type: 'GET', - url: '/home/cancelOrder', - data: { - id: $reaMask.data('orderId'), - reason: reason, - reasonId: reasonId - } - }).then(function(res) { - $reaMask.fadeOut(); - if ($.type(res) !== 'object') { - return; - } - if (res.message) { - tip.show(res.message); - } - setTimeout(function() { - window.location.href = '/home/orders'; - }, 2000); - }).fail(function() { - tip.show('网络错误'); +//底部导航点击 +function fotterClick(group) { + $(group + ' li').on('touchstart', function() { + $('.sub-group').addClass('hide'); + $(this).find('.sub-group').removeClass('hide'); }); -}); +} -$reaMask.on('touchend', function(event) { - if (event.target.className !== 'reason-mask') { - return false; +fotterClick('.shop-foot-wrapper'); + +function stopPropagation(e) { + if (e.stopPropagation) { + e.stopPropagation(); + } else { + e.cancelBubble = true; } +} - $reaMask.css('visibility', 'hidden'); - event.stopPropagation(); -}); +$(document).bind('touchstart', function() { + $('.sub-group').addClass('hide'); }); -define("js/me/order-detail", ["jquery","lazyload","hammer","handlebars","source-map","swiper","index"], function(require, exports, module){ -/** - * 订单详情页 - * @author: xuqi<qi.xu@yoho.cn> - * @date: 2015/11/16 - */ -var $ = require("jquery"), - lazyLoad = require("lazyload"), - Hammer = require("hammer"), - dialog = require("js/me/dialog"), - tip = require("js/plugin/tip"), - orderId = $('#order-detail').data('id'), - $countDownHours = $('.hours'), - $countdownContainer = $('.count-down'), - Swiper = require("swiper"), - $ownerInfo = $('.owner-info'), - $reaMask = $('.reason-mask'), - reasonSwiper, - optHammer; - -lazyLoad({ - try_again_css: 'order-failure' -}); - -function downCount(options) { - - var difference = options,// difference of dates - interval; - /** - * Main downCount function that calculates everything - */ - function countdown() { - - // basic math variables - var _second = 1000, - _minute = _second * 60, - _hour = _minute * 60, - _day = _hour * 24, - hours, - minutes, - seconds; - - // calculate dates - hours = Math.floor((difference % _day) / _hour), - minutes = Math.floor((difference % _hour) / _minute), - seconds = Math.floor((difference % _minute) / _second); - - // fix dates so that it will show two digets - hours = (String(hours).length >= 2) ? hours : '0' + hours; - minutes = (String(minutes).length >= 2) ? minutes : '0' + minutes; - seconds = (String(seconds).length >= 2) ? seconds : '0' + seconds; - - // set to DOM - $countdownContainer.removeClass('hide'); - if (hours === '00') { - $countDownHours.text('剩余' + minutes + ':' + seconds); - } else { - $countDownHours.text('剩余' + hours + ':' + minutes + ':' + seconds); - } +$('.shop-foot-wrapper').bind('touchstart', function(e) { + stopPropagation(e); +}); - difference -= 1000; +//收藏 +function postCollect(info) { + var url = ''; - if (difference < 0) { - clearInterval(interval);// stop timer - return; - } - } - if (difference !== '' && difference > 0) { - interval = setInterval(countdown, 1000);// start + if (searching) { + return; } -} - -downCount($countDownHours.text()); + searching = true; -//订单删除 -optHammer = new Hammer(document.getElementsByClassName('opt')[0]); -optHammer.on('tap', function(e) { - var $cur = $(e.target); + $.ajax({ + method: 'get', + url: location.protocol + '//m.yohobuy.com' + info.url, + data: info.data, - if ($cur.hasClass('btn-del')) { + success: function(data) { - //删除订单 - dialog.showDialog({ - dialogText: '确定删除订单吗?', - hasFooter: { - leftBtnText: '取消', - rightBtnText: '确定' - } - }, function() { - $.ajax({ - type: 'GET', - url: '/home/delOrder', - data: { - id: orderId - } - }).then(function(res) { - $('#dialog-wrapper').hide(); - if ($.type(res) !== 'object') { - return; - } - if (res.message) { - tip.show(res.message); + if (data.code === 200) { + if ($('#collect').hasClass('alreadyCollect')) { + $('#collect').attr('class', 'notCollect'); + } else { + $('#collect').attr('class', 'alreadyCollect'); } - setTimeout(function() { - window.location.href = '/home/orders'; - }, 2000); - }).fail(function() { - tip.show('网络错误'); - }); - }); - } else if ($cur.hasClass('btn-cancel')) { - $reaMask.css('visibility', 'visible'); - } else if ($cur.hasClass('btn-rebuy')) { - $.ajax({ - type: 'GET', - url: '/home/readd', - data: { - orderCode: orderId - }, - success: function(res) { - tip.show(res.message); - location.href = '/cart/index/index'; - }, - error: function(res) { - tip.show(res.message); } - }); - } -}); -if ($ownerInfo.data('changeable') === true) { - $ownerInfo.find('.rest').show(); - $ownerInfo.on('touchend', function() { - location.href = $ownerInfo.data('url'); - }); -} + if (data.code === 401) { + url = 'http://m.yohobuy.com/signin.html?refer=' + encodeURIComponent(location.href) + '&openby:yohobuy='; + url += JSON.stringify({"action": "go.weblogin", "params": { "jumpurl": { "url": 'http://m.yohobuy.com' + location.pathname, "param": info.data }, "requesturl": { "param": {}, "url": "" }, "priority": "N" } }); + + $('body').append('<a href=\'' + url + '\'><span class="jump-login"><span></a>'); -$(function() { - reasonSwiper = new Swiper('.box-main', { - initialSlide: 0, - centeredSlides: true, - slidesPerView: 5, - direction: 'vertical', - onSlideChangeStart: function(reasonSwiper) { - var activeIndex = reasonSwiper.activeIndex, - slides = reasonSwiper.slides, - i = 0; - - if (slides.length !== 1) { - if (activeIndex === 0) { - for (i = 1; i < slides.length; i++) { - $(slides[i]).css('transform', ''); - } - } else if (activeIndex === slides.length - 1) { - for (i = 0; i < activeIndex; i++) { - $(slides[i]).css('transform', 'rotateX(' + (30 + (activeIndex - i) * 12) + 'deg)'); - } - } else { - for (i = 0; i < activeIndex; i++) { - $(slides[i]).css('transform', 'rotateX(' + (30 + (activeIndex - i) * 12) + 'deg)'); - } - for (i = activeIndex + 1; i < slides.length; i++) { - $(slides[i]).css('transform', ''); - } - } + $('.jump-login').click(); } - $(slides[activeIndex]).css('transform', ''); + + setTimeout(function() { + myScroll.refresh(); + scH = $('#scroller').outerHeight(); + }, 1000); + searching = false; + }, + error: function() { + alert('网络断开连接了~'); + searching = false; } }); -}); +} + +function collectShop() { + var qew = {}; -$reaMask.find('.box-cmp').on('touchend', function(e) { - var selSolid = reasonSwiper.slides[reasonSwiper.activeIndex], - reason = $(selSolid).text(), - reasonId = $(selSolid).data('reasonId'); + qew.url = '/product/index/shopFav'; + qew.data = { + shop_id: favId ? favId : shopId, + app_version: appVersion + }; + postCollect(qew); +} - $.ajax({ - type: 'GET', - url: '/home/cancelOrder', - data: { - id: orderId, - reason: reason, - reasonId: reasonId - } - }).then(function(res) { - $reaMask.fadeOut(); - if ($.type(res) !== 'object') { - return; - } - if (res.message) { - tip.show(res.message); - } - setTimeout(function() { - window.location.href = '/home/orders'; - }, 2000); - }).fail(function() { - tip.show('网络错误'); - }); -}); +function cancelShop() { + var qew = {}; + + qew.url = '/product/index/cancelShopFav'; + qew.data = { + shop_id: favId ? favId : shopId, + app_version: appVersion + }; + postCollect(qew); +} -$reaMask.on('touchend', function(event) { - if (event.target.className !== 'reason-mask') { - return false; +$('#collect').on('touchstart', function(e) { + if ($('#collect').hasClass('alreadyCollect')) { + cancelShop(); + } else { + collectShop(); } +}); + +}); +define("js/me/entry", ["jquery","hammer","lazyload","swiper","handlebars","source-map","mlellipsis","index"], function(require, exports, module){ +/** + * 个人中心js打包入口文件 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/11/10 + */ + +require("js/me/order"); +require("js/me/order-detail"); +require("js/me/fav"); +require("js/me/suggest"); +require("js/me/index"); +require("js/me/coupons"); +require("js/me/online-service"); +require("js/me/address"); +require("js/me/suggest"); +require("js/me/browse-record"); +require("js/me/address-act"); +require("js/me/logistic"); +require("js/me/pay"); +require("js/me/personal-details"); +require("js/me/currency"); +require("js/me/currency-new"); +require("js/me/message"); +require("js/me/message-detail"); +require("js/me/address-modify"); - $reaMask.css('visibility', 'hidden'); - event.stopPropagation(); }); +define("js/me/order", ["jquery","hammer","lazyload","swiper","handlebars","source-map","index"], function(require, exports, module){ +/** + * 个人中心--我的订单 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/11/10 + */ + +var $ = require("jquery"), + Hammer = require("hammer"), + lazyLoad = require("lazyload"), + tip = require("js/plugin/tip"), + Swiper = require("swiper"); + +var $navLi = $('#order-nav > li'), + $orderContainer = $('#order-container'); + +var $curContainer = $orderContainer.children('.orders:not(.hide)');//保存当前显示的order-container + +var winH = $(window).height(); + +var activeType = $navLi.filter('.active').data('type'); //当前active的项的index + +var order = { + page: 0, + end: false +}; + +var inAjax = false; + +var loading = require("js/plugin/loading"); + +var dialog = require("js/me/dialog"); + +var orderHammer, + $reaMask = $('.reason-mask'), + reasonSwiper; + +// 减少计时 +function downCount(item) { + var hoursItem = item.find('.hours'); + + var difference = hoursItem.text(),// difference of dates + interval; + /** + * Main downCount function that calculates everything + */ + function countdown() { + + // basic math variables + var _second = 1000, + _minute = _second * 60, + _hour = _minute * 60, + _day = _hour * 24, + hours, + minutes, + seconds; + + // calculate dates + hours = Math.floor((difference % _day) / _hour), + minutes = Math.floor((difference % _hour) / _minute), + seconds = Math.floor((difference % _minute) / _second); + + // fix dates so that it will show two digets + hours = (String(hours).length >= 2) ? hours : '0' + hours; + minutes = (String(minutes).length >= 2) ? minutes : '0' + minutes; + seconds = (String(seconds).length >= 2) ? seconds : '0' + seconds; + + // set to DOM + item.removeClass('hide'); + if (hours === '00') { + hoursItem.text('剩余' + minutes + ':' + seconds); + } else { + hoursItem.text('剩余' + hours + ':' + minutes + ':' + seconds); + } + + difference -= 1000; + + if (difference <= 0) { + clearInterval(interval);// stop timer + return; + } + } + if (difference !== '' && difference > 0) { + interval = setInterval(countdown, 1000);// start + } +} + +// 初始化时间 +function setTime() { + + $('.order').each(function() { + var item = $(this).find('.count-down'); + + if (!$(this).hasClass('hide')) { + downCount(item); + } + }); +} + +//加载订单 +function getOrders(option) { + var opt = { + type: activeType, + page: order.page + 1 + }; + + var show = option && !option.noLoadingMask; + + if (inAjax) { + return; + } + + inAjax = true; + show && loading.showLoadingMask(); + + $.ajax({ + type: 'GET', + url: '/home/getOrders', + data: opt, + success: function(data) { + var num; + + if (data !== ' ') { + order.page = opt.page; + + if (opt.page === 1) { + $curContainer.html(data); + lazyLoad($curContainer.find('.lazy'), { + try_again_css: 'order-failure' + }); + } else { + num = $curContainer.children('.order').length; + $curContainer.append(data); + + //lazyload + lazyLoad($curContainer.children('.order:gt(' + (num - 1) + ')').find('.lazy'), { + try_again_css: 'order-failure' + }); + } + + window.rePosFooter(); //重新计算底部位置 + } else { + order.end = true; + } + + inAjax = false; + show && loading.hideLoadingMask(); + setTime(); + } + }); +} + +lazyLoad({ + try_again_css: 'order-failure' +}); + +//初始化导航 +(function() { + var liCount = $navLi.length; + + //默认4个导航项 + if (liCount === 4) { + return; + } + + $navLi.width(100 / liCount + '%'); +}()); + +loading.init($('body')); //满屏loading + +//点击订单区域跳转订单详情页 +orderHammer = new Hammer(document.getElementById('order-container')); +orderHammer.on('tap', function(e) { + var $cur = $(e.target), + $order, + id, + url; + + if ($cur.closest('.locHref').length > 0) { + return; + } + + $order = $cur.closest('.order'); + id = $order.data('id'); + + $reaMask.data('orderId', id); + + if ($cur.closest('.del').length > 0) { + + //Order delete + dialog.showDialog({ + dialogText: '确定删除订单吗?', + hasFooter: { + leftBtnText: '取消', + rightBtnText: '确定' + } + }, function() { + $.ajax({ + type: 'GET', + url: '/home/delOrder', + data: { + id: id + }, + success: function(data) { + dialog.hideDialog(); + if (data.message) { + tip.show(data.message); + } + if (data.code === 200) { + + //删除订单页面刷新 + window.location.reload(); + } + }, + error: function() { + tip.show('取消订单失败'); + } + }); + }); + } else if ($cur.closest('.cancel').length > 0) { + $reaMask.css('visibility', 'visible'); + } else if ($cur.closest('.order-goods').length > 0) { + + //Location to order detail + url = $order.data('href'); + location.href = url; + } else if ($cur.closest('.rebuy').length > 0) { + $.ajax({ + type: 'GET', + url: '/home/readd', + data: { + orderCode: id + }, + success: function(res) { + tip.show(res.message); + location.href = '/cart/index/index'; + }, + error: function(res) { + tip.show(res.message); + } + }); + } +}); + +function scrollHandler() { + if (order.end === false && $(window).scrollTop() + winH > + $(document).height() - 0.25 * $orderContainer.height()) { + + //下拉请求时不显示mask + getOrders({ + noLoadingMask: true + }); + } +} + +//srcoll to load more +$(window).scroll(function() { + window.requestAnimationFrame(scrollHandler); +}); + +//初始化请求第一页数据 +getOrders(); + +$(function() { + reasonSwiper = new Swiper('.box-main', { + direction: 'vertical', + slidesPerView: 5, + centeredSlides: true, + initialSlide: 0, + onSlideChangeStart: function(reasonSwiper) { + var activeIndex = reasonSwiper.activeIndex, + slides = reasonSwiper.slides, + i = 0; + + if (slides.length !== 1) { + if (activeIndex === 0) { + for (i = 1; i < slides.length; i++) { + $(slides[i]).css('transform', ''); + } + } else if (activeIndex === slides.length - 1) { + for (i = 0; i < activeIndex; i++) { + $(slides[i]).css('transform', 'rotateX(' + (30 + (activeIndex - i) * 12) + 'deg)'); + } + } else { + for (i = 0; i < activeIndex; i++) { + $(slides[i]).css('transform', 'rotateX(' + (30 + (activeIndex - i) * 12) + 'deg)'); + } + for (i = activeIndex + 1; i < slides.length; i++) { + $(slides[i]).css('transform', ''); + } + } + } + $(slides[activeIndex]).css('transform', ''); + } + }); +}); + +$reaMask.find('.box-cmp').on('touchend', function(e) { + var selSolid = reasonSwiper.slides[reasonSwiper.activeIndex], + reason = $(selSolid).text(), + reasonId = $(selSolid).data('reasonId'); + + $.ajax({ + type: 'GET', + url: '/home/cancelOrder', + data: { + id: $reaMask.data('orderId'), + reason: reason, + reasonId: reasonId + } + }).then(function(res) { + $reaMask.fadeOut(); + if ($.type(res) !== 'object') { + return; + } + if (res.message) { + tip.show(res.message); + } + setTimeout(function() { + window.location.href = '/home/orders'; + }, 2000); + }).fail(function() { + tip.show('网络错误'); + }); +}); + +$reaMask.on('touchend', function(event) { + if (event.target.className !== 'reason-mask') { + return false; + } + + $reaMask.css('visibility', 'hidden'); + event.stopPropagation(); +}); +}); +define("js/me/order-detail", ["jquery","lazyload","hammer","handlebars","source-map","swiper","index"], function(require, exports, module){ +/** + * 订单详情页 + * @author: xuqi<qi.xu@yoho.cn> + * @date: 2015/11/16 + */ + +var $ = require("jquery"), + lazyLoad = require("lazyload"), + Hammer = require("hammer"), + dialog = require("js/me/dialog"), + tip = require("js/plugin/tip"), + orderId = $('#order-detail').data('id'), + $countDownHours = $('.hours'), + $countdownContainer = $('.count-down'), + Swiper = require("swiper"), + $ownerInfo = $('.owner-info'), + $reaMask = $('.reason-mask'), + reasonSwiper, + optHammer; + +lazyLoad({ + try_again_css: 'order-failure' +}); + +function downCount(options) { + + var difference = options,// difference of dates + interval; + /** + * Main downCount function that calculates everything + */ + function countdown() { + + // basic math variables + var _second = 1000, + _minute = _second * 60, + _hour = _minute * 60, + _day = _hour * 24, + hours, + minutes, + seconds; + + // calculate dates + hours = Math.floor((difference % _day) / _hour), + minutes = Math.floor((difference % _hour) / _minute), + seconds = Math.floor((difference % _minute) / _second); + + // fix dates so that it will show two digets + hours = (String(hours).length >= 2) ? hours : '0' + hours; + minutes = (String(minutes).length >= 2) ? minutes : '0' + minutes; + seconds = (String(seconds).length >= 2) ? seconds : '0' + seconds; + + // set to DOM + $countdownContainer.removeClass('hide'); + if (hours === '00') { + $countDownHours.text('剩余' + minutes + ':' + seconds); + } else { + $countDownHours.text('剩余' + hours + ':' + minutes + ':' + seconds); + } + + difference -= 1000; + + if (difference < 0) { + clearInterval(interval);// stop timer + return; + } + } + if (difference !== '' && difference > 0) { + interval = setInterval(countdown, 1000);// start + } +} + +downCount($countDownHours.text()); + +//订单删除 +optHammer = new Hammer(document.getElementsByClassName('opt')[0]); +optHammer.on('tap', function(e) { + var $cur = $(e.target); + + if ($cur.hasClass('btn-del')) { + + //删除订单 + dialog.showDialog({ + dialogText: '确定删除订单吗?', + hasFooter: { + leftBtnText: '取消', + rightBtnText: '确定' + } + }, function() { + $.ajax({ + type: 'GET', + url: '/home/delOrder', + data: { + id: orderId + } + }).then(function(res) { + $('#dialog-wrapper').hide(); + if ($.type(res) !== 'object') { + return; + } + if (res.message) { + tip.show(res.message); + } + setTimeout(function() { + window.location.href = '/home/orders'; + }, 2000); + }).fail(function() { + tip.show('网络错误'); + }); + }); + } else if ($cur.hasClass('btn-cancel')) { + $reaMask.css('visibility', 'visible'); + } else if ($cur.hasClass('btn-rebuy')) { + $.ajax({ + type: 'GET', + url: '/home/readd', + data: { + orderCode: orderId + }, + success: function(res) { + tip.show(res.message); + location.href = '/cart/index/index'; + }, + error: function(res) { + tip.show(res.message); + } + }); + } +}); + +if ($ownerInfo.data('changeable') === true) { + $ownerInfo.find('.rest').show(); + $ownerInfo.on('touchend', function() { + location.href = $ownerInfo.data('url'); + }); +} + +$(function() { + reasonSwiper = new Swiper('.box-main', { + initialSlide: 0, + centeredSlides: true, + slidesPerView: 5, + direction: 'vertical', + onSlideChangeStart: function(reasonSwiper) { + var activeIndex = reasonSwiper.activeIndex, + slides = reasonSwiper.slides, + i = 0; + + if (slides.length !== 1) { + if (activeIndex === 0) { + for (i = 1; i < slides.length; i++) { + $(slides[i]).css('transform', ''); + } + } else if (activeIndex === slides.length - 1) { + for (i = 0; i < activeIndex; i++) { + $(slides[i]).css('transform', 'rotateX(' + (30 + (activeIndex - i) * 12) + 'deg)'); + } + } else { + for (i = 0; i < activeIndex; i++) { + $(slides[i]).css('transform', 'rotateX(' + (30 + (activeIndex - i) * 12) + 'deg)'); + } + for (i = activeIndex + 1; i < slides.length; i++) { + $(slides[i]).css('transform', ''); + } + } + } + $(slides[activeIndex]).css('transform', ''); + } + }); +}); + +$reaMask.find('.box-cmp').on('touchend', function(e) { + var selSolid = reasonSwiper.slides[reasonSwiper.activeIndex], + reason = $(selSolid).text(), + reasonId = $(selSolid).data('reasonId'); + + $.ajax({ + type: 'GET', + url: '/home/cancelOrder', + data: { + id: orderId, + reason: reason, + reasonId: reasonId + } + }).then(function(res) { + $reaMask.fadeOut(); + if ($.type(res) !== 'object') { + return; + } + if (res.message) { + tip.show(res.message); + } + setTimeout(function() { + window.location.href = '/home/orders'; + }, 2000); + }).fail(function() { + tip.show('网络错误'); + }); +}); + +$reaMask.on('touchend', function(event) { + if (event.target.className !== 'reason-mask') { + return false; + } + + $reaMask.css('visibility', 'hidden'); + event.stopPropagation(); +}); }); define("js/me/fav", ["jquery","hammer","swiper","handlebars","source-map","index"], function(require, exports, module){ @@ -12500,33 +12500,33 @@ $(window).scroll(function() { couponAJAX(statu, page); }); define("js/me/online-service", ["jquery"], function(require, exports, module){ -/** - * 在线客服 - * @author: bikai<kai.bi@yoho.cn> - * @date: 2015/11/16 - */ -var $ = require("jquery"); - -var $questionTab = $('.question-tab .tab-item'); - -$questionTab.on('touchend', function() { - var clickTab = $(this).data('tab'); - - clickTab = '[data-tab-name="' + clickTab + '"]'; - - $questionTab.removeClass('current'); - $(this).addClass('current'); - - $('.question-list').removeClass('current'); - $(clickTab).addClass('current'); -}); - -$('.yoho-page').on('touchstart', '.connect-item, .question-item', function() { - $(this).siblings().removeClass('highlight'); - $(this).addClass('highlight'); -}).on('touchend touchcancel', '.connect-item, .question-item', function() { - $(this).removeClass('highlight'); -}); +/** + * 在线客服 + * @author: bikai<kai.bi@yoho.cn> + * @date: 2015/11/16 + */ +var $ = require("jquery"); + +var $questionTab = $('.question-tab .tab-item'); + +$questionTab.on('touchend', function() { + var clickTab = $(this).data('tab'); + + clickTab = '[data-tab-name="' + clickTab + '"]'; + + $questionTab.removeClass('current'); + $(this).addClass('current'); + + $('.question-list').removeClass('current'); + $(clickTab).addClass('current'); +}); + +$('.yoho-page').on('touchstart', '.connect-item, .question-item', function() { + $(this).siblings().removeClass('highlight'); + $(this).addClass('highlight'); +}).on('touchend touchcancel', '.connect-item, .question-item', function() { + $(this).removeClass('highlight'); +}); }); define("js/me/address", ["jquery","hammer"], function(require, exports, module){ @@ -14885,195 +14885,195 @@ $('.confirm-btn, .nav-back').on('touchstart', function(e) { // initData(); }); define("js/cart/select-coupon", ["jquery","handlebars","source-map","hammer","mlellipsis"], function(require, exports, module){ -/** - * 优惠券选择 - * @author: bikai<kai.bi@yoho.cn> - * @date: 2015/12/10 - */ - -var $ = require("jquery"), - Handlebars = require("handlebars"), - Hammer = require("hammer"), - ellipsis = require("mlellipsis"), - loading = require("js/plugin/loading"), - tip = require("js/plugin/tip"), - orderInfo = require("js/cart/order-info").orderInfo; - -var isGetData; - -var conponTmpl = Handlebars.compile($('#tmpl-coupon').html()), - conponNotAvaliableTmpl = Handlebars.compile($('#tmpl-coupon-not-avaliable').html()), - $newCoupon = $('#new-coupon'), - $couponList = $('#coupon-list'); - -var winH = $(window).height(); - -require("js/common"); - -function fixedLayOut() { - var $null = $('.null'), - navH = $('.nav-title').height(), - nullH = $null.height(); - - if ($null.length === 0) { - return false; - } - - $null.css({ - top: winH / 2 - nullH / 2 + navH - }); -} - -ellipsis.init(); - -$newCoupon.on('submit', function() { - var $this = $(this); - - if (!$this.find('[name="couponCode"]').val()) { - tip.show('请输入优惠券码'); - return false; - } - $.ajax({ - method: 'POST', - url: '/cart/index/couponSearch', - data: $this.serialize() - }).then(function(res) { - if (res.message) { - tip.show(res.message); - } - if (res.code === 200) { - tip.show('优惠券可用'); - orderInfo('couponCode', res.data.coupon_code); - orderInfo('couponName', res.data.coupon_title); - window.location.href = '/cart/index/orderEnsure'; - } - }).fail(function() { - tip.show('网络错误'); - }); - return false; -}); - -$couponList.on('touchstart', '.employ-main', function() { - var $this = $(this); - - $this.siblings().removeClass('focus'); - $this.addClass('focus'); -}).on('touchend touchcancel', '.employ-main', function() { - var $this = $(this); - - $this.siblings().removeClass('focus'); - $this.removeClass('focus'); -}); - -$('body').on('touchend', '.not-use', function() { - orderInfo('couponCode', null); - orderInfo('couponName', null); - location.href = '/cart/index/orderEnsure'; -}); - - -$newCoupon.find('input').on('input', function() { - if ($(this).val() !== '') { - $newCoupon.find('.submit').css('background', '#444'); - } else { - $newCoupon.find('.submit').css('background', '#b0b0b0'); - } -}); - -function getCouponHandle(allCoupons) { - var notAvailableCoupons, - coupons; - - // 空数组表示没有优惠券 - if ($.isArray(allCoupons)) { - $('.coupon-wrap').html($('#tmpl-no-coupon').html()); - fixedLayOut(); - return; - } - - // 把可用和不可用的优惠券分离出来 - notAvailableCoupons = allCoupons.notAvailableCoupons; - coupons = allCoupons.coupons; - - $.each(coupons, function(i, coupon) { - coupon.couponValue = Math.floor(coupon.couponValue); - }); - - $.each(notAvailableCoupons, function(i, coupon) { - coupon.couponValue = Math.floor(coupon.couponValue); - }); - - // 渲染可用的优惠券 - $couponList.append(conponTmpl({ - coupons: coupons - })).find('.employ-main').each(function(i, elem) { - var employHammer = new Hammer(elem); - - employHammer.on('tap', function(e) { - var $this = $(e.srcEvent.currentTarget); - var couponCode = $this.data('coupon-code'); - - $.ajax({ - method: 'POST', - url: '/cart/index/couponSearch', - data: { - couponCode: couponCode - } - }).then(function(res) { - if (res.code === 200) { - - //tip.show('优惠券可用'); - orderInfo('couponCode', res.data.coupon_code); - orderInfo('couponName', res.data.coupon_title); - window.location.href = '/cart/index/orderEnsure'; - } else if (res.message) { - tip.show(res.message); - } - }).fail(function() { - tip.show('网络错误'); - }); - }); - }); - - if (notAvailableCoupons.length) { - $('.not-avaliable-coupon-line').show(); - } - $('#coupon-list-not').append(conponNotAvaliableTmpl({ - notAvailableCoupons: notAvailableCoupons - })); - window.rePosFooter(); - -} - -function getCouponDate() { - - if (isGetData) { - return; - } - - loading.showLoadingMask(); - isGetData = true; - - $.ajax({ - type: 'GET', - url: '/cart/index/couponList', - dataType: 'json' - }).then(getCouponHandle).fail(function() { - - // tip.show('加载优惠券失败'); - }).always(function() { - isGetData = false; - loading.hideLoadingMask(); - }); -} - -getCouponDate(); - -// $(window).scroll(function() { -// if ($(window).scrollTop() + $(window).height() > $('body').height() * 0.9) { -// getCouponDate(); -// } -// }); +/** + * 优惠券选择 + * @author: bikai<kai.bi@yoho.cn> + * @date: 2015/12/10 + */ + +var $ = require("jquery"), + Handlebars = require("handlebars"), + Hammer = require("hammer"), + ellipsis = require("mlellipsis"), + loading = require("js/plugin/loading"), + tip = require("js/plugin/tip"), + orderInfo = require("js/cart/order-info").orderInfo; + +var isGetData; + +var conponTmpl = Handlebars.compile($('#tmpl-coupon').html()), + conponNotAvaliableTmpl = Handlebars.compile($('#tmpl-coupon-not-avaliable').html()), + $newCoupon = $('#new-coupon'), + $couponList = $('#coupon-list'); + +var winH = $(window).height(); + +require("js/common"); + +function fixedLayOut() { + var $null = $('.null'), + navH = $('.nav-title').height(), + nullH = $null.height(); + + if ($null.length === 0) { + return false; + } + + $null.css({ + top: winH / 2 - nullH / 2 + navH + }); +} + +ellipsis.init(); + +$newCoupon.on('submit', function() { + var $this = $(this); + + if (!$this.find('[name="couponCode"]').val()) { + tip.show('请输入优惠券码'); + return false; + } + $.ajax({ + method: 'POST', + url: '/cart/index/couponSearch', + data: $this.serialize() + }).then(function(res) { + if (res.message) { + tip.show(res.message); + } + if (res.code === 200) { + tip.show('优惠券可用'); + orderInfo('couponCode', res.data.coupon_code); + orderInfo('couponName', res.data.coupon_title); + window.location.href = '/cart/index/orderEnsure'; + } + }).fail(function() { + tip.show('网络错误'); + }); + return false; +}); + +$couponList.on('touchstart', '.employ-main', function() { + var $this = $(this); + + $this.siblings().removeClass('focus'); + $this.addClass('focus'); +}).on('touchend touchcancel', '.employ-main', function() { + var $this = $(this); + + $this.siblings().removeClass('focus'); + $this.removeClass('focus'); +}); + +$('body').on('touchend', '.not-use', function() { + orderInfo('couponCode', null); + orderInfo('couponName', null); + location.href = '/cart/index/orderEnsure'; +}); + + +$newCoupon.find('input').on('input', function() { + if ($(this).val() !== '') { + $newCoupon.find('.submit').css('background', '#444'); + } else { + $newCoupon.find('.submit').css('background', '#b0b0b0'); + } +}); + +function getCouponHandle(allCoupons) { + var notAvailableCoupons, + coupons; + + // 空数组表示没有优惠券 + if ($.isArray(allCoupons)) { + $('.coupon-wrap').html($('#tmpl-no-coupon').html()); + fixedLayOut(); + return; + } + + // 把可用和不可用的优惠券分离出来 + notAvailableCoupons = allCoupons.notAvailableCoupons; + coupons = allCoupons.coupons; + + $.each(coupons, function(i, coupon) { + coupon.couponValue = Math.floor(coupon.couponValue); + }); + + $.each(notAvailableCoupons, function(i, coupon) { + coupon.couponValue = Math.floor(coupon.couponValue); + }); + + // 渲染可用的优惠券 + $couponList.append(conponTmpl({ + coupons: coupons + })).find('.employ-main').each(function(i, elem) { + var employHammer = new Hammer(elem); + + employHammer.on('tap', function(e) { + var $this = $(e.srcEvent.currentTarget); + var couponCode = $this.data('coupon-code'); + + $.ajax({ + method: 'POST', + url: '/cart/index/couponSearch', + data: { + couponCode: couponCode + } + }).then(function(res) { + if (res.code === 200) { + + //tip.show('优惠券可用'); + orderInfo('couponCode', res.data.coupon_code); + orderInfo('couponName', res.data.coupon_title); + window.location.href = '/cart/index/orderEnsure'; + } else if (res.message) { + tip.show(res.message); + } + }).fail(function() { + tip.show('网络错误'); + }); + }); + }); + + if (notAvailableCoupons.length) { + $('.not-avaliable-coupon-line').show(); + } + $('#coupon-list-not').append(conponNotAvaliableTmpl({ + notAvailableCoupons: notAvailableCoupons + })); + window.rePosFooter(); + +} + +function getCouponDate() { + + if (isGetData) { + return; + } + + loading.showLoadingMask(); + isGetData = true; + + $.ajax({ + type: 'GET', + url: '/cart/index/couponList', + dataType: 'json' + }).then(getCouponHandle).fail(function() { + + // tip.show('加载优惠券失败'); + }).always(function() { + isGetData = false; + loading.hideLoadingMask(); + }); +} + +getCouponDate(); + +// $(window).scroll(function() { +// if ($(window).scrollTop() + $(window).height() > $('body').height() * 0.9) { +// getCouponDate(); +// } +// }); }); define("js/cart/select-address", ["jquery","hammer"], function(require, exports, module){ diff --git a/static/dist/myohobuy/assets/img/sprite.me.png b/static/dist/myohobuy/assets/img/sprite.me.png index a66a10e..6b05ca7 100644 Binary files a/static/dist/myohobuy/assets/img/sprite.me.png and b/static/dist/myohobuy/assets/img/sprite.me.png differ -- libgit2 0.24.0