Authored by wangqing

首页js和底部js

/**
* 尾部
* @author: wangqing<robin.wang@yoho.cn>
* @date: 2015/12/01
*/
var $ = require('yoho.jquery');
/**
* 订阅
* @return {[type]} [description]
*/
function actionSubscription() {
var $subscriberBox = $('#subscriberBox'),
$subscriberBtn = $('#subscriberBtn'),
emailReg = /^[.\-_a-zA-Z0-9]+@[\-_a-zA-Z0-9]+\.[a-zA-Z0-9]/;
var subscribeParam = {
method: 'open.subscriber.subscriber',
v: 1,
return_type: 'jsonp',
open_key: '12345'
};
var email = $.trim($subscriberBox.val());
var params = {};
$subscriberBox.focus(function() {
$(this).val('').css('color', '');
$subscriberBtn.removeClass('done').text('m');
});
//订阅Start
$subscriberBtn.click(function() {
if (email !== '' && emailReg.test(email)) {
$.extend(params, subscribeParam, {
email: email,
tmp: Math.random(),
uid: $.uid('_UID')
});
try {
$.getJSON('http://test.open.yohobuy.com' + '/?callback=?', params, function(data) {
if (data.data.result === 1) {
$subscriberBox.val('已订阅到:' + email);
$subscriberBtn.addClass('done').text('=');
} else {
$subscriberBox.css('color', 'red');
}
});
} catch (e) {
console.log(e.message);
}
} else {
$subscriberBox.css('color', 'red');
}
});
}
function change(now, icon, box) {
var obj = now;
var index = icon.index(this);
var offset = index * 3;
box.each(function() {
$(this).hide();
});
for (var i = offset; i < offset + 3; i++) {
box.eq(i).show();
}
now.each(function() {
$(this).children().removeClass('cur').html('o');
});
obj.children().addClass('cur').html('O');
}
function actionhomeFootChange() {
//有货services
$('#button-services a').click(function() {
change($(this), $('#button-services a'), $('#foot-services ul li'));
});
//更多有货产品
$('#button-mobile a').click(function() {
change($(this), $('#button-mobile a'), $('#foot-mobile ul li'));
});
//在线调查
$('#feedbackPage a').click(function() {
$('#feedbackPage').find('a').children('span').removeClass('cur').html('o');
$(this).children('span').addClass('cur').html('O');
var indexNum = $('#feedbackPage a').index(this);
$('.vote li').hide();
$('.vote li').eq(indexNum).show();
});
$('.vote li').each(function() {
var obj = this;
var index = $(this).index();
$(this).find('#feedbackBtn').click(function() {
var params = {};
var _solution = [];
$(obj).find('input').each(function() {
if ($(this).attr('checked') == true || $(this).attr('checked') == 'checked') {
_solution.push($(this).val());
}
});
var _answer = $(obj).find('#feedback_answer').val();
var _feedback = $(obj).find('#feedback_id').val();
var _question = $(obj).find('#question_id').val();
params['method'] = 'open.feedback.submit';
params['feedback_id'] = _feedback || 0;
params['question_id'] = _question || 0;
params['answer'] = _answer || '';
params['solution'] = _solution.join(',');
$.getData(apiDomain, params, function(reData) {
if (reData.result == 1) {
var voteCount = $('.vote li').length - 1;
if (index == voteCount) {
alert('感谢您的参与!');
return false;
}
var Next = index + 1;
$('.vote li').eq(index).hide();
$('.vote li').eq(Next).show();
$('#feedbackPage').children('a').eq(index).children('span').removeClass('cur').html('o');
$('#feedbackPage').children('a').eq(Next).children('span').addClass('cur').html('O');
}
return false;
});
});
});
}
exports.init = function() {
actionSubscription();//执行订阅
actionhomeFootChange();//底部事件
}
\ No newline at end of file
... ...
... ... @@ -6,11 +6,12 @@
var $ = require('yoho.jquery');
var $yohocookie = require('../plugin/yohocookie');
var $yohocart = require('../plugin/yohocart');
var yohodoT = require('../plugin/yohodoT');
var noticeSuccess = false;
require('../plugin/yohocookie');
require('../plugin/yohocart');
/**
* 获取头部banner的回调函数
* @param {[type]} data [description]
... ... @@ -560,7 +561,7 @@ function loadCartData() {
}
if ($('#miniCartBox .goods-list li').length < 1) {
shoppingInfo = $.cookie('_g');
shoppingData = JSON.parse('(' + shoppingInfo + ')');
shoppingData = eval('(' + shoppingInfo + ')');
if (shoppingData !== null) {
strK = '{"_k":"' + shoppingData._k + '","_nac":0' + ',"_ac":0,"_r":0}';
$.setcookie('_g', strK, {
... ... @@ -588,7 +589,7 @@ function delCartGoods(id, isreduce) {
isreduce: isreduce
}, function(jsonData) {
var shoppingInfo = $.cookie('_g');
var shoppingData = JSON.parse('(' + shoppingInfo + ')');
var shoppingData = eval('(' + shoppingInfo + ')');
var strK = '{"_k":"' + shoppingData._k + '","_nac":' + jsonData.total_goods_num + ',"_ac":0,"_r":0}';
$.setcookie('_g', strK, {
... ... @@ -601,13 +602,13 @@ function delCartGoods(id, isreduce) {
}
window.apiDomain = 'http://api.open.yohobuy.com';
window.cartTpl = '';
window.delCartGoods = delCartGoods;
/**
* 点击购物车
* @return {[type]} [description]
*/
function clickMiniCartBox() {
function actionClickMiniCartBox() {
var $target;
var shopcarurl = 'http://www.yohobuy.com/shopping/cart';
... ... @@ -803,8 +804,5 @@ exports.init = function() {
actionUpdateCartNum(); //更新购物车数量
actionLoopUpdCartNum(); //循环检测购物车数量
actionSearch(); //搜索执行
delCartGoods();
clickMiniCartBox();
$yohocookie();
$yohocart();
actionClickMiniCartBox(); //点击购物车跳转
};
\ No newline at end of file
... ...
var jQuery = require('jquery');
var jQuery = require('yoho.jquery');
var $yohocookie = require('./yohocookie');
(function($) {
... ... @@ -127,3 +127,6 @@ var $yohocookie = require('./yohocookie');
},
})
})(jQuery);
exports.init = function() {
}
\ No newline at end of file
... ...
var jQuery = require('jquery');
var jQuery = require('yoho.jquery');
(function($) {
$.extend({
... ...