...
|
...
|
@@ -5,10 +5,14 @@ |
|
|
*/
|
|
|
|
|
|
var $ = require('jquery');
|
|
|
|
|
|
|
|
|
var $yohocookie = require('./common/yohocookie');
|
|
|
var $yohocart = require('./common/yohocart');
|
|
|
var yohodoT = require('../plugin/yohodoT');
|
|
|
var noticeSuccess = false;
|
|
|
|
|
|
/**
|
|
|
* 获取头部banner的回调函数
|
|
|
* @param {[type]} data [description]
|
|
|
*/
|
|
|
function JsonPCallBack(data) {
|
|
|
var topbanner;
|
|
|
|
...
|
...
|
@@ -22,6 +26,10 @@ function JsonPCallBack(data) { |
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取头部服务器维护的回调
|
|
|
* @param {[type]} data [description]
|
|
|
*/
|
|
|
function NoticeCallBack(data) {
|
|
|
if (+data.code === 200) {
|
|
|
noticeSuccess = true;
|
...
|
...
|
@@ -375,6 +383,62 @@ window.bannerMap = { |
|
|
indexkids: '17f6d5d5d454d2c507bc5fcbc90f7756',
|
|
|
indexlifestyle: '735cd393e841762af8793c346abbbc36'
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* cookie 初始化
|
|
|
* @return {[type]} [description]
|
|
|
*/
|
|
|
function actionInitCookie() {
|
|
|
var $cookieGender = $.cookie('_Gender');
|
|
|
var $target = $('.cure');
|
|
|
|
|
|
if (typeof $cookieGender !== 'undefined' && $cookieGender !== '') {
|
|
|
$.setcookie('_Gender', 1, {
|
|
|
path: '/',
|
|
|
domain: '.yohobuy.com',
|
|
|
expires: 7
|
|
|
});
|
|
|
}
|
|
|
if ($target.find('.name-cn a').text() === '男生') {
|
|
|
$.setcookie('_Gender', '1,3', {
|
|
|
path: '/',
|
|
|
domain: '.yohobuy.com',
|
|
|
expires: 7
|
|
|
});
|
|
|
$.setcookie('_Channel', 'boys', {
|
|
|
path: '/',
|
|
|
domain: '.yohobuy.com',
|
|
|
expires: 7
|
|
|
});
|
|
|
}
|
|
|
if ($target.find('.name-cn a').text() === '女生') {
|
|
|
$.setcookie('_Gender', '2,3', {
|
|
|
path: '/',
|
|
|
domain: '.yohobuy.com',
|
|
|
expires: 7
|
|
|
});
|
|
|
$.setcookie('_Channel', 'girls', {
|
|
|
path: '/',
|
|
|
domain: '.yohobuy.com',
|
|
|
expires: 7
|
|
|
});
|
|
|
}
|
|
|
if ($target.find('.name-cn a').text() === '创意生活') {
|
|
|
$.setcookie('_Channel', 'lifestyle', {
|
|
|
path: '/',
|
|
|
domain: '.yohobuy.com',
|
|
|
expires: 7
|
|
|
});
|
|
|
}
|
|
|
if ($target.find('.name-cn a').text() === '潮童') {
|
|
|
$.setcookie('_Channel', 'kids', {
|
|
|
path: '/',
|
|
|
domain: '.yohobuy.com',
|
|
|
expires: 7
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* cookie集合
|
|
|
* @type {Object}
|
...
|
...
|
@@ -394,9 +458,207 @@ function actionExeCookieMap() { |
|
|
window.cookieMap[key] = temparr[1];
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
* 一级菜单点击(会设置cookie)
|
|
|
* @return {[type]} [description]
|
|
|
*/
|
|
|
function actionFirstMenuClick() {
|
|
|
var $cookieGender;
|
|
|
|
|
|
$('.first-nav-item').click(function() {
|
|
|
$cookieGender = $.cookie('_Gender');
|
|
|
if (typeof $cookieGender !== 'undefined' && $cookieGender !== '') {
|
|
|
$.setcookie('_Gender', 1, {
|
|
|
path: '/',
|
|
|
domain: '.yohobuy.com',
|
|
|
expires: 7
|
|
|
});
|
|
|
}
|
|
|
if ($(this).find('.name-cn a').text() === '男生') {
|
|
|
$.setcookie('_Gender', '1,3', {
|
|
|
path: '/',
|
|
|
domain: '.yohobuy.com',
|
|
|
expires: 7
|
|
|
});
|
|
|
$.setcookie('_Channel', 'boys', {
|
|
|
path: '/',
|
|
|
domain: '.yohobuy.com',
|
|
|
expires: 7
|
|
|
});
|
|
|
}
|
|
|
if ($(this).find('.name-cn a').text() === '女生') {
|
|
|
$.setcookie('_Gender', '2,3', {
|
|
|
path: '/',
|
|
|
domain: '.yohobuy.com',
|
|
|
expires: 7
|
|
|
});
|
|
|
$.setcookie('_Channel', 'girls', {
|
|
|
path: '/',
|
|
|
domain: '.yohobuy.com',
|
|
|
expires: 7
|
|
|
});
|
|
|
}
|
|
|
if ($(this).find('.name-cn a').text() === '创意生活') {
|
|
|
$.setcookie('_Channel', 'lifestyle', {
|
|
|
path: '/',
|
|
|
domain: '.yohobuy.com',
|
|
|
expires: 7
|
|
|
});
|
|
|
}
|
|
|
if ($(this).find('.name-cn a').text() === '潮童') {
|
|
|
$.setcookie('_Channel', 'kids', {
|
|
|
path: '/',
|
|
|
domain: '.yohobuy.com',
|
|
|
expires: 7
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
|
|
|
$('#backToOld').click(function() {
|
|
|
$.setcookie('_New', 1, {
|
|
|
path: '/',
|
|
|
domain: '.yohobuy.com'
|
|
|
});
|
|
|
location.href = 'http://www.yohobuy.com';
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 购物车商品数量
|
|
|
* @return {[type]} [description]
|
|
|
*/
|
|
|
function actionUpdateCartNum() {
|
|
|
$('#miniCartBox').miniCart({
|
|
|
cartNum: '.ic-infomation'
|
|
|
});
|
|
|
}
|
|
|
/**
|
|
|
* 加载购物车数据
|
|
|
* @return {[type]} [description]
|
|
|
*/
|
|
|
function loadCartData() {
|
|
|
var shoppingInfo,
|
|
|
shoppingData,
|
|
|
strK;
|
|
|
|
|
|
$.getData(window.apiDomain, {
|
|
|
method: 'open.Shoppingcart.getCartData',
|
|
|
shopping_key: $.getShoppingKey()
|
|
|
}, function(jsonData) {
|
|
|
if (window.cartTpl === '') {
|
|
|
window.cartTpl = yohodoT.template($('#mini-cart-tpl').html());
|
|
|
}
|
|
|
$('#miniCartBox').children('.gobuy-wrapper').html(window.cartTpl({
|
|
|
cartData: jsonData
|
|
|
}));
|
|
|
if (parseInt($('.ic-infomation').html()) === 0) {
|
|
|
$('#miniCartBox .gobuy-wrapper').html('<div class="gobuy-empty">' +
|
|
|
'<h3 class="information">您的购物车暂无商品</h3></div>');
|
|
|
}
|
|
|
if ($('#miniCartBox .goods-list li').length < 1) {
|
|
|
shoppingInfo = $.cookie('_g');
|
|
|
shoppingData = eval('(' + shoppingInfo + ')');
|
|
|
if (shoppingData !== null) {
|
|
|
strK = '{"_k":"' + shoppingData._k + '","_nac":0' + ',"_ac":0,"_r":0}';
|
|
|
$.setcookie('_g', strK, {
|
|
|
path: '/',
|
|
|
domain: '.yohobuy.com'
|
|
|
});
|
|
|
}
|
|
|
$('.ic-infomation').html(0);
|
|
|
$('#miniCartBox .gobuy-wrapper').html('<div class="gobuy-empty">' +
|
|
|
'<h3 class="information">您的购物车暂无商品</h3></div>');
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
/**
|
|
|
* 删除购物车数据
|
|
|
* @param {[type]} id [description]
|
|
|
* @param {Boolean} isreduce [description]
|
|
|
* @return {[type]} [description]
|
|
|
*/
|
|
|
function delCartGoods(id, isreduce) {
|
|
|
$.getData(window.apiDomain, {
|
|
|
method: 'open.Shoppingcart.delone',
|
|
|
shopping_key: $.getShoppingKey(),
|
|
|
id: id,
|
|
|
isreduce: isreduce
|
|
|
}, function(jsonData) {
|
|
|
var shoppingInfo = $.cookie('_g');
|
|
|
var shoppingData = eval('(' + shoppingInfo + ')');
|
|
|
var strK = '{"_k":"' + shoppingData._k + '","_nac":' + jsonData.total_goods_num + ',"_ac":0,"_r":0}';
|
|
|
|
|
|
$.setcookie('_g', strK, {
|
|
|
path: '/',
|
|
|
domain: '.yohobuy.com'
|
|
|
});
|
|
|
loadCartData();
|
|
|
actionUpdateCartNum();
|
|
|
});
|
|
|
}
|
|
|
window.apiDomain = 'http://api.open.yohobuy.com';
|
|
|
window.cartTpl = '';
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 点击购物车
|
|
|
* @return {[type]} [description]
|
|
|
*/
|
|
|
function clickMiniCartBox() {
|
|
|
var $target;
|
|
|
var shopcarurl = 'http://www.yohobuy.com/shopping/cart';
|
|
|
|
|
|
$('#miniCartBox').on('click', function(e) {
|
|
|
$target = $(e.target);
|
|
|
if ($target.hasClass('gobuy')) {
|
|
|
window.location.href = shopcarurl;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 显示购物车效果
|
|
|
* @param {Boolean} isShow [description]
|
|
|
* @return {[type]} [description]
|
|
|
*/
|
|
|
function showMiniCart(isShow) {
|
|
|
if (isShow === 1) {
|
|
|
$('#miniCartBox').addClass('list-cur');
|
|
|
$('.gobuy-wrapper').show();
|
|
|
if (parseInt($('.ic-infomation').html()) !== 0) {
|
|
|
$('#miniCartBox .gobuy-wrapper').html('<div class="gobuy-loading">' +
|
|
|
'<h3 class="information">加载中,请稍后</h3></div>');
|
|
|
loadCartData();
|
|
|
} else {
|
|
|
$('#miniCartBox .gobuy-wrapper').html('<div class="gobuy-empty">' +
|
|
|
'<h3 class="information">您的购物车暂无商品</h3></div>');
|
|
|
}
|
|
|
} else {
|
|
|
$('#miniCartBox').removeClass('list-cur');
|
|
|
$('.gobuy-wrapper').hide();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 鼠标购物车的滑入滑出效果
|
|
|
* @return {[type]} [description]
|
|
|
*/
|
|
|
function actionGoodsCarMouseEffect() {
|
|
|
var $target;
|
|
|
|
|
|
$('#miniCartBox').mouseenter(function(e) {
|
|
|
$target = $(e.target);
|
|
|
if ($target.attr('id') === 'miniCartBox' || $target.attr('class') === 'ic-infomation') {
|
|
|
showMiniCart(1);
|
|
|
}
|
|
|
});
|
|
|
$('#miniCartBox').mouseleave(function(e) {
|
|
|
showMiniCart(0);
|
|
|
});
|
|
|
}
|
|
|
/**
|
|
|
* 获得banner & 异常通知
|
|
|
* @return {[type]} [description]
|
|
|
*/
|
...
|
...
|
@@ -496,15 +758,47 @@ function actionBrandChange() { |
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
* 循环检测购物车数量
|
|
|
* @return {[type]} [description]
|
|
|
*/
|
|
|
function actionLoopUpdCartNum() {
|
|
|
setInterval(actionUpdateCartNum, 2000);
|
|
|
}
|
|
|
/**
|
|
|
* 处理模板
|
|
|
* @return {[type]} [description]
|
|
|
*/
|
|
|
function actionExeTemplate() {
|
|
|
var resulthtml = $('#goodcartempwarpper').html().replace(/\%L/g, '{{').replace(/\%R/g, '}}');
|
|
|
|
|
|
$('#goodcartempwarpper').html(resulthtml);
|
|
|
}
|
|
|
/**
|
|
|
* 执行搜索
|
|
|
* @return {[type]} [description]
|
|
|
*/
|
|
|
function actionSearch() {
|
|
|
var searchDomain = 'http://search.yohobuy.com/api/suggest';
|
|
|
|
|
|
$('#query_key').search(searchDomain);
|
|
|
}
|
|
|
/**
|
|
|
* 初始化函数
|
|
|
* @return {[type]} [description]
|
|
|
*/
|
|
|
exports.init = function() {
|
|
|
actionExeCookieMap();
|
|
|
actionYoHoGroup();
|
|
|
actionTopTagToggle();
|
|
|
actionTopLogoAnimate();
|
|
|
actionGetBannerAndNotice();
|
|
|
actionBrandChange();
|
|
|
actionAddKeyWords();
|
|
|
actionExeTemplate(); //处理模板
|
|
|
actionInitCookie(); //初始化cookie
|
|
|
actionExeCookieMap(); //格式化cookie
|
|
|
actionYoHoGroup(); // yoho集团鼠标效果
|
|
|
actionTopTagToggle(); // yoho上部分开关
|
|
|
actionTopLogoAnimate(); //yoho logo动画
|
|
|
actionGetBannerAndNotice(); // 获取banner和服务器维护提示
|
|
|
actionBrandChange(); //切换品牌
|
|
|
actionAddKeyWords(); //跳转后增加关键字
|
|
|
actionFirstMenuClick(); //一级菜单点击(会设置cookie)
|
|
|
actionGoodsCarMouseEffect(); //鼠标滑入滑出效果
|
|
|
actionUpdateCartNum(); //更新购物车数量
|
|
|
actionLoopUpdCartNum(); //循环检测购物车数量
|
|
|
actionSearch(); //搜索执行
|
|
|
}; |
|
|
\ No newline at end of file |
...
|
...
|
|