...
|
...
|
@@ -11,88 +11,181 @@ var vipInfoCombine = null; //用户信息编译模板 |
|
|
var loginInfoCombine = null; //登录信息编译模板
|
|
|
var apiDomain = 'http://api.open.yohobuy.com'; //获取数据的地址
|
|
|
var cartTpl = ''; //购物车模板
|
|
|
/**
|
|
|
* 搜寻的时候过滤非法字符(+-/:等非法字符单独出现)
|
|
|
* @type {RegExp}
|
|
|
*/
|
|
|
var reg = /^[\^\!\+\-\(\)\:\[\]\\\{\}\~\*\?\|\&\;\/\s]{0,}$/g;
|
|
|
var keyword = '';
|
|
|
var link = '';
|
|
|
var dataLayer = [];
|
|
|
var requestFrame = null;
|
|
|
var logoanimationstart = 0;
|
|
|
var $logotrans = $('.icon-logo');
|
|
|
var isen = true;
|
|
|
var loopdurationtime = 500;
|
|
|
var globaltimeout;
|
|
|
var onetimeoout;
|
|
|
/**
|
|
|
* banner和地址的映射
|
|
|
* @type {Object}
|
|
|
*/
|
|
|
var bannerMap = {
|
|
|
listboys: '4f78b0f418fc42314d8b6e791cfb7fa8',
|
|
|
listgirls: '00c1f025a51b6b597dc37925951ea27d',
|
|
|
listkids: 'b02df11184727701ade1b6de9737d08c',
|
|
|
listlifestyle: 'fd35c52dced0c880976ba858346d1fc5',
|
|
|
searchboys: '9fb8986ea700cc27a8057361c3924394',
|
|
|
searchgirls: 'e3e207a1443ca60c8037fe52a5560c18',
|
|
|
searchkids: '620fc77f479da8feaeb06f2324e5d0bb',
|
|
|
searchlifestyle: 'a3c93301c6ffaf3ed0f36a4a451be36d',
|
|
|
uniquebrandboys: '2ebb0810c0d1a67e5229149c9c3aba7d',
|
|
|
uniquebrandgirls: '99e23385f4ba4b65f406b7e2968ac821',
|
|
|
uniquebrandkids: 'a74ebc9b17840c91b9ea46568111fe6b',
|
|
|
uniquebrandlifestyle: '0e8c81ead53f56302baa4d0ad967f527',
|
|
|
brandsboys: '77b352db07129c76a9d532acad149f9f',
|
|
|
brandsgirls: 'bf047f16e52ebc38be5ce9c7623831e6',
|
|
|
brandskids: 'e3ae1ce9b5e13c6d271ef3eccb831652',
|
|
|
brandslifestyle: 'e4ac8029c30f65d7f1af030980d140fe',
|
|
|
newboys: '869d3c5f3b450fb52101d00a61ce87cb',
|
|
|
newgirls: 'd953b6dfdac02483d1dcce8d96055954',
|
|
|
newkids: '0874cb6d75df8e0e78f2d475e53ecc08',
|
|
|
newlifestyle: '43e8fc8e178115c262bbce2bd0012db7',
|
|
|
saleboys: 'c846e3165c994769b4201d8c32f3ae9b',
|
|
|
salegirls: '52b1d389edcbc62d65de71b80c4d6ad0',
|
|
|
salekids: 'ad8b1703c761ba00973868ab5199cc27',
|
|
|
salelifestyle: '7acc64905c70ac91846f43fb2cec4bbd',
|
|
|
homeboys: 'b0856a771ef1b59ab1234c74688fa42d',
|
|
|
homegirls: '2bd61fa12e4933211518f70fe5ce3c48',
|
|
|
homekids: '895c59e8c64b40399c9533509507320c',
|
|
|
homelifestyle: '2e037d4e25d2767352ca3e0a4627f7bd',
|
|
|
indexboys: '0c911d3000f52e8ca7cffb74f5864c29',
|
|
|
indexgirls: 'b645b8980c423ab30485e0a9d08c2ef7',
|
|
|
indexkids: '17f6d5d5d454d2c507bc5fcbc90f7756',
|
|
|
indexlifestyle: '735cd393e841762af8793c346abbbc36'
|
|
|
};
|
|
|
var cookieMap = {};
|
|
|
|
|
|
function getSource(column, postition, event) {
|
|
|
try {
|
|
|
dataLayer.push({
|
|
|
louceng: column,
|
|
|
weizhi: postition,
|
|
|
event: event
|
|
|
});
|
|
|
} catch (e) {}
|
|
|
}
|
|
|
|
|
|
function submitSearch() {
|
|
|
var $keywordinput = $('#query_key').val();
|
|
|
var column = 'Search';
|
|
|
var postition = 'Head Search';
|
|
|
var event = 'Search';
|
|
|
var $formatkeyword,
|
|
|
$formatkeywordinput;
|
|
|
|
|
|
$formatkeyword = $.trim(keyword.toLowerCase());
|
|
|
$formatkeywordinput = $.trim($keywordinput.toLowerCase());
|
|
|
getSource(column, postition, event);
|
|
|
if (link !== '' && keyword !== '' && $formatkeyword === $formatkeywordinput) {
|
|
|
location.href = link.replace('\'', '');
|
|
|
} else {
|
|
|
if (reg.test($keywordinput)) {
|
|
|
location.href = 'http://search.yohobuy.com/error?query=' + $keywordinput + '&result=error';
|
|
|
} else {
|
|
|
$('#searchForm').submit();
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
* 定义购物车扩展
|
|
|
*/
|
|
|
|
|
|
(function($) {
|
|
|
$.fn.miniCart = function(options) {
|
|
|
var defaults = {
|
|
|
'cookie': '_g',
|
|
|
'cartNum': ''
|
|
|
};
|
|
|
var params = $.extend(defaults, options);
|
|
|
var cartInfo = eval('(' + window.cookie(params.cookie) + ')');
|
|
|
function actionGoodsCart() {
|
|
|
var defaults = {
|
|
|
cookie: '_g',
|
|
|
cartNum: ''
|
|
|
};
|
|
|
var params = '';
|
|
|
var cartInfo = '';
|
|
|
var queryNum = 0;
|
|
|
var listIndex = 0;
|
|
|
var tmpList = 0;
|
|
|
var totalNum = 0;
|
|
|
var text = '';
|
|
|
|
|
|
$.fn.miniCart = function(options) {
|
|
|
params = $.extend(defaults, options);
|
|
|
if (typeof window.cookie(params.cookie) === 'undefined') {
|
|
|
cartInfo = null;
|
|
|
} else {
|
|
|
cartInfo = json2.parse(window.cookie(params.cookie));
|
|
|
}
|
|
|
if (cartInfo != null) {
|
|
|
var totalNum = parseInt(cartInfo._nac) + parseInt(cartInfo._ac);
|
|
|
if (totalNum == 0) {
|
|
|
totalNum = parseInt(cartInfo._nac) + parseInt(cartInfo._ac);
|
|
|
if (totalNum === 0) {
|
|
|
$('#icart-num').attr('class', 'icart-num icart-none');
|
|
|
} else {
|
|
|
$('#icart-num').attr('class', 'icart-num');
|
|
|
}
|
|
|
$(params.cartNum).html(totalNum);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
$.fn.search = function(searchDomain) {
|
|
|
var query_num = 0;
|
|
|
var list_index = 0;
|
|
|
var tmp_list = 0;
|
|
|
|
|
|
function getKeywords(obj) {
|
|
|
var key = $.trim($(obj).val());
|
|
|
|
|
|
key = key.replace(new RegExp("'", "gm"), ''); //去掉特殊字符
|
|
|
if (key == '') {
|
|
|
|
|
|
key = key.replace(new RegExp('\'', 'gm'), ''); //去掉特殊字符
|
|
|
if (key === '') {
|
|
|
$('.search-list').hide();
|
|
|
return false;
|
|
|
}
|
|
|
key = encodeURI(key); //编码
|
|
|
key = encodeURI(key);
|
|
|
$.get(searchDomain + '?callback=?&query=' + key, function(htmlData) {
|
|
|
$('.search-list').html(htmlData['data']);
|
|
|
query_num = $('.search-list').children('li').length;
|
|
|
list_index = -1;
|
|
|
if (query_num > 0) {
|
|
|
$('.search-list').html(htmlData.data);
|
|
|
queryNum = $('.search-list').children('li').length;
|
|
|
listIndex = -1;
|
|
|
if (queryNum > 0) {
|
|
|
$('.search-list').show();
|
|
|
} else {
|
|
|
$('.search-list').hide();
|
|
|
}
|
|
|
//绑定事件
|
|
|
$('.search-list').find('a').hover(function() {
|
|
|
$(this).css("background-color", "#eee");
|
|
|
$(this).css('background-color', '#eee');
|
|
|
}, function() {
|
|
|
$(this).css("background-color", "#fff");
|
|
|
$(this).css('background-color', '#fff');
|
|
|
});
|
|
|
}, 'jsonp');
|
|
|
}
|
|
|
|
|
|
function getText(obj) {
|
|
|
$('.search-list li:eq(' + tmp_list + ')').children('a').css("background-color", "#fff");
|
|
|
$('.search-list li:eq(' + list_index + ')').children('a').css("background-color", "#eee");
|
|
|
var text = $('.search-list li:eq(' + list_index + ')').children('a').attr("title");
|
|
|
$('.search-list li:eq(' + tmpList + ')').children('a').css('background-color', '#fff');
|
|
|
$('.search-list li:eq(' + listIndex + ')').children('a').css('background-color', '#eee');
|
|
|
text = $('.search-list li:eq(' + listIndex + ')').children('a').attr('title');
|
|
|
$('#query_key').val(text);
|
|
|
}
|
|
|
return this.each(function() {
|
|
|
$(this).keyup(function(event) {
|
|
|
if (event.which == 38) {
|
|
|
if (query_num == 0) {
|
|
|
if (event.which === 38) {
|
|
|
if (queryNum === 0) {
|
|
|
return false;
|
|
|
}
|
|
|
if (list_index == -1) {
|
|
|
list_index = 0;
|
|
|
if (listIndex === -1) {
|
|
|
listIndex = 0;
|
|
|
}
|
|
|
tmp_list = list_index;
|
|
|
list_index = (list_index - 1 + query_num) % query_num;
|
|
|
tmpList = listIndex;
|
|
|
listIndex = (listIndex - 1 + queryNum) % queryNum;
|
|
|
getText(this);
|
|
|
} else if (event.which == 40) {
|
|
|
if (query_num == 0) {
|
|
|
} else if (event.which === 40) {
|
|
|
if (queryNum === 0) {
|
|
|
return false;
|
|
|
}
|
|
|
tmp_list = list_index;
|
|
|
list_index = (list_index + 1) % query_num;
|
|
|
tmpList = listIndex;
|
|
|
listIndex = (listIndex + 1) % queryNum;
|
|
|
getText(this);
|
|
|
} else if (event.which == 13) {
|
|
|
} else if (event.which === 13) {
|
|
|
submitSearch();
|
|
|
} else {
|
|
|
getKeywords(this);
|
...
|
...
|
@@ -103,27 +196,31 @@ var cartTpl = ''; //购物车模板 |
|
|
$.extend({
|
|
|
getData: function(domain, options, onSuccess) {
|
|
|
var defaults = {
|
|
|
'page': 1,
|
|
|
'method': '',
|
|
|
'v': 1,
|
|
|
'return_type': 'jsonp',
|
|
|
'open_key': '12345',
|
|
|
'tmp': Math.random()
|
|
|
page: 1,
|
|
|
method: '',
|
|
|
v: 1,
|
|
|
return_type: 'jsonp',
|
|
|
open_key: '12345',
|
|
|
tmp: Math.random()
|
|
|
};
|
|
|
if (typeof(domain) == undefined || domain == '') {
|
|
|
var params = '';
|
|
|
|
|
|
if (typeof(domain) === undefined || domain === '') {
|
|
|
console.log('请设置请求的api地址');
|
|
|
return false;
|
|
|
}
|
|
|
var params = $.extend(defaults, options);
|
|
|
params = $.extend(defaults, options);
|
|
|
params.page = params.page || 1;
|
|
|
if (params.method == '') {
|
|
|
if (params.method === '') {
|
|
|
console.log('请设置请求的URL');
|
|
|
return false;
|
|
|
}
|
|
|
try {
|
|
|
$.getJSON(domain + '/?callback=?', params, function(_data) {
|
|
|
if (onSuccess != '') {
|
|
|
eval(onSuccess(_data.data));
|
|
|
if (onSuccess !== '') {
|
|
|
if(typeof onSuccess(_data.data) !=='undefined'){
|
|
|
json2.parse(onSuccess(_data.data));
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
});
|
...
|
...
|
@@ -133,14 +230,15 @@ var cartTpl = ''; //购物车模板 |
|
|
},
|
|
|
getShoppingKey: function() {
|
|
|
var shoppingInfo = window.cookie('_g');
|
|
|
if (typeof shoppingInfo == 'undefined' || shoppingInfo == null) {
|
|
|
var shoppingData = json2.parse(shoppingInfo);
|
|
|
|
|
|
if (typeof shoppingInfo === 'undefined' || shoppingInfo === null) {
|
|
|
return '';
|
|
|
}
|
|
|
var shoppingData = eval('(' + shoppingInfo + ')');
|
|
|
return shoppingData._k;
|
|
|
},
|
|
|
})
|
|
|
})($);
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
/**
|
|
|
* 判断为1的helper
|
|
|
* @param {[type]} v1 [description]
|
...
|
...
|
@@ -248,7 +346,7 @@ function checkNotice() { |
|
|
function getBannerData(code) {
|
|
|
var script = document.createElement('script');
|
|
|
|
|
|
script.src = 'http://new.yohobuy.com/resource/getbanner?content_code=' +
|
|
|
script.src = 'http://www.yohobuy.com/common/getbanner?content_code=' +
|
|
|
code + '&client_type=web&callback=JsonPCallBack';
|
|
|
document.getElementsByTagName('head')[0].appendChild(script);
|
|
|
}
|
...
|
...
|
@@ -350,7 +448,7 @@ function isSupportCss3Animation() { |
|
|
* @param {Array} ) { var thisFunc, prefixList [description]
|
|
|
* @return {[type]} [description]
|
|
|
*/
|
|
|
function requestFrameCloser() {
|
|
|
function requestFrameAct() {
|
|
|
var prefixList = ['webkit', 'moz', 'ms'];
|
|
|
var func1 = prefixList[0] + 'RequestAnimationFrame';
|
|
|
var func2 = prefixList[1] + 'RequestAnimationFrame';
|
...
|
...
|
@@ -377,11 +475,6 @@ function requestFrameCloser() { |
|
|
}
|
|
|
|
|
|
|
|
|
var requestFrame = requestFrameCloser();
|
|
|
var logoanimationstart = 0;
|
|
|
var $logotrans = $('.icon-logo');
|
|
|
var isen = true;
|
|
|
|
|
|
/**
|
|
|
* css3动画
|
|
|
* @return {[type]} [description]
|
...
|
...
|
@@ -416,9 +509,6 @@ function tsAnimate() { |
|
|
}
|
|
|
}
|
|
|
|
|
|
var loopdurationtime = 500;
|
|
|
var globaltimeout;
|
|
|
var onetimeoout;
|
|
|
/**
|
|
|
* 淡出
|
|
|
* @return {[type]} [description]
|
...
|
...
|
@@ -452,6 +542,7 @@ function fadeAnimate() { |
|
|
*/
|
|
|
function actionTopLogoAnimate() {
|
|
|
if (isSupportCss3Animation()) {
|
|
|
requestFrame = requestFrameAct();
|
|
|
window.setTimeout(tsAnimate, 3000);
|
|
|
} else {
|
|
|
window.setTimeout(fadeAnimate, 3000);
|
...
|
...
|
@@ -484,85 +575,7 @@ function actionAddKeyWords() { |
|
|
});
|
|
|
}
|
|
|
}
|
|
|
var dataLayer = [];
|
|
|
|
|
|
function getSource(column, postition, event) {
|
|
|
try {
|
|
|
dataLayer.push({
|
|
|
louceng: column,
|
|
|
weizhi: postition,
|
|
|
event: event
|
|
|
});
|
|
|
} catch (e) {}
|
|
|
}
|
|
|
/**
|
|
|
* 搜寻的时候过滤非法字符(+-/:等非法字符单独出现)
|
|
|
* @type {RegExp}
|
|
|
*/
|
|
|
var reg = /^[\^\!\+\-\(\)\:\[\]\\\{\}\~\*\?\|\&\;\/\s]{0,}$/g;
|
|
|
var keyword = '';
|
|
|
var link = '';
|
|
|
|
|
|
var submitSearch = function() {
|
|
|
var $keywordinput = $('#query_key').val();
|
|
|
var column = 'Search';
|
|
|
var postition = 'Head Search';
|
|
|
var event = 'Search';
|
|
|
var $formatkeyword,
|
|
|
$formatkeywordinput;
|
|
|
|
|
|
$formatkeyword = $.trim(keyword.toLowerCase());
|
|
|
$formatkeywordinput = $.trim($keywordinput.toLowerCase());
|
|
|
getSource(column, postition, event);
|
|
|
if (link !== '' && keyword !== '' && $formatkeyword === $formatkeywordinput) {
|
|
|
location.href = link.replace('\'', '');
|
|
|
} else {
|
|
|
if (reg.test($keywordinput)) {
|
|
|
location.href = 'http://search.yohobuy.com/error?query=' + $keywordinput + '&result=error';
|
|
|
} else {
|
|
|
$('#searchForm').submit();
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
/**
|
|
|
* banner和地址的映射
|
|
|
* @type {Object}
|
|
|
*/
|
|
|
var bannerMap = {
|
|
|
listboys: '4f78b0f418fc42314d8b6e791cfb7fa8',
|
|
|
listgirls: '00c1f025a51b6b597dc37925951ea27d',
|
|
|
listkids: 'b02df11184727701ade1b6de9737d08c',
|
|
|
listlifestyle: 'fd35c52dced0c880976ba858346d1fc5',
|
|
|
searchboys: '9fb8986ea700cc27a8057361c3924394',
|
|
|
searchgirls: 'e3e207a1443ca60c8037fe52a5560c18',
|
|
|
searchkids: '620fc77f479da8feaeb06f2324e5d0bb',
|
|
|
searchlifestyle: 'a3c93301c6ffaf3ed0f36a4a451be36d',
|
|
|
uniquebrandboys: '2ebb0810c0d1a67e5229149c9c3aba7d',
|
|
|
uniquebrandgirls: '99e23385f4ba4b65f406b7e2968ac821',
|
|
|
uniquebrandkids: 'a74ebc9b17840c91b9ea46568111fe6b',
|
|
|
uniquebrandlifestyle: '0e8c81ead53f56302baa4d0ad967f527',
|
|
|
brandsboys: '77b352db07129c76a9d532acad149f9f',
|
|
|
brandsgirls: 'bf047f16e52ebc38be5ce9c7623831e6',
|
|
|
brandskids: 'e3ae1ce9b5e13c6d271ef3eccb831652',
|
|
|
brandslifestyle: 'e4ac8029c30f65d7f1af030980d140fe',
|
|
|
newboys: '869d3c5f3b450fb52101d00a61ce87cb',
|
|
|
newgirls: 'd953b6dfdac02483d1dcce8d96055954',
|
|
|
newkids: '0874cb6d75df8e0e78f2d475e53ecc08',
|
|
|
newlifestyle: '43e8fc8e178115c262bbce2bd0012db7',
|
|
|
saleboys: 'c846e3165c994769b4201d8c32f3ae9b',
|
|
|
salegirls: '52b1d389edcbc62d65de71b80c4d6ad0',
|
|
|
salekids: 'ad8b1703c761ba00973868ab5199cc27',
|
|
|
salelifestyle: '7acc64905c70ac91846f43fb2cec4bbd',
|
|
|
homeboys: 'b0856a771ef1b59ab1234c74688fa42d',
|
|
|
homegirls: '2bd61fa12e4933211518f70fe5ce3c48',
|
|
|
homekids: '895c59e8c64b40399c9533509507320c',
|
|
|
homelifestyle: '2e037d4e25d2767352ca3e0a4627f7bd',
|
|
|
indexboys: '0c911d3000f52e8ca7cffb74f5864c29',
|
|
|
indexgirls: 'b645b8980c423ab30485e0a9d08c2ef7',
|
|
|
indexkids: '17f6d5d5d454d2c507bc5fcbc90f7756',
|
|
|
indexlifestyle: '735cd393e841762af8793c346abbbc36'
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* cookie 初始化
|
...
|
...
|
@@ -623,8 +636,6 @@ function actionInitCookie() { |
|
|
* cookie集合
|
|
|
* @type {Object}
|
|
|
*/
|
|
|
var cookieMap = {};
|
|
|
|
|
|
function actionExeCookieMap() {
|
|
|
var cookies = document.cookie;
|
|
|
var cookiearr = cookies.split(';');
|
...
|
...
|
@@ -634,8 +645,11 @@ function actionExeCookieMap() { |
|
|
|
|
|
for (i = 0; i < cookiearr.length; i++) {
|
|
|
temparr = cookiearr[i].split('=');
|
|
|
key = temparr[0].replace(/\s/g, '');
|
|
|
cookieMap[key] = temparr[1];
|
|
|
if(typeof temparr[0] !== 'undefined'){
|
|
|
key = temparr[0].replace(/\s/g, '');
|
|
|
cookieMap[key] = temparr[1];
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
/**
|
...
|
...
|
@@ -917,7 +931,6 @@ function actionGetBannerAndNotice() { |
|
|
}
|
|
|
|
|
|
getBannerData(code); //获得banner信息
|
|
|
getNoticeData(code); //获得公告信息
|
|
|
|
|
|
}
|
|
|
|
...
|
...
|
@@ -1142,6 +1155,7 @@ function init() { |
|
|
actionExeTemplate(); //处理模板
|
|
|
actionInitCookie(); //初始化cookie
|
|
|
actionExeCookieMap(); //格式化cookie
|
|
|
actionGoodsCart(); //初始化购物车插件
|
|
|
actionYoHoGroup(); // yoho集团鼠标效果
|
|
|
actionTopTagToggle(); // yoho上部分开关
|
|
|
actionTopLogoAnimate(); //yoho logo动画
|
...
|
...
|
|