Authored by whb

index,css

define("index", ["jquery","handlebars","source-map","index","lazyload"], function(require, exports, module){
define("index", ["jquery","handlebars","source-map","index","lazyload","jquery.placeholder"], function(require, exports, module){
var webYohobuy;
require("js/common");
require("js/product/entry");
require("js/home/entry");
require("js/passport/entry");
module.exports = webYohobuy;
... ... @@ -3893,3 +3894,1397 @@ module.exports = function(data) {
};
});
define("js/passport/entry", ["jquery","jquery.placeholder"], function(require, exports, module){
/*
* 密码中心打包入口文件
*/
require("js/passport/reg");
require("js/passport/back");
require("js/passport/login");
require("js/passport/reset");
});
define("js/passport/reg", ["jquery"], function(require, exports, module){
/*
* @description 注册页js
* @time 2015/12/14
*/
var $ = require("jquery"),
regValidate = require("js/passport/mail-phone-regx"),
computeComplex = require("js/passport/pwd-strength");
var $registerPage = $('.register-page'),
$pwdTips = $('#pwd-tips'),
$pwdTip1 = $pwdTips.find('#pwd-tip1'),
$errTip = $('#err-tip'),
$registerBtn = $('#register-btn');
var $sendCaptcha = $('#send-captcha'),
caCount = 4,
validateResult = [];
var $pn = $('#phone-num'),
$mc = $('#msg-captcha'),
$pwd = $('#pwd'),
$repwd = $('#repwd'),
$ca = $('#captcha');
// 密码强度验证
var $pwdIntensity = $('.pwd-intensity'),
$pwdParent = $pwdIntensity.closest('.pwd-intensity-container');
//signup验证
var $region = $('#country-code'),
$regionSelect = $('#region');
setTimeout(function() {
$pn.val('');
$mc.val('');
$pwd.val('');
$repwd.val('');
$ca.val('');
}, 100);
//验证码位数
$ca.attr('maxlength', caCount);
//密码规则提示
$pwd.focus(function() {
$pwdTips.removeClass('hide');
}).blur(function() {
$pwdTips.addClass('hide');
});
//IE8 placeholder
//$('[placeholder]').placeholder();
// 存储校验信息
validateResult = [
{
id: 'phone-num',
message: '', //错误信息
status: false //当前的状态
},
{
id: 'captcha',
message: '',
status: false
},
{
id: 'msg-captcha',
message: '',
status: false
},
{
id: 'pwd',
message: '',
status: false
},
{
id: 'repwd',
message: '',
status: false
}
];
//手机号ajax校验
function phoneAjaxFn(callback) {
$.ajax({
url: '/passport/register/checkmobile',
type: 'POST',
data: {
mobile: $pn.val(),
area: $region.text().split('+')[1]
}
}).then(function(data) {
switch (data.code) {
case 200:
validateResult[0].message = '';
validateResult[0].status = true;
break;
case 400:
validateResult[0].message = data.message;
validateResult[0].status = false;
break;
}
callback();
});
}
//图形验证码ajax校验
function picCaptchaAjaxFn(callback) {
$.ajax({
type: 'POST',
url: '/passport/register/piccaptcha',
data: {
code: $ca.val(),
mobile: $pn.val(),
area: $region.text().split('+')[1]
}
}).then(function(data) {
switch (data.code) {
case 200:
validateResult[1].message = '';
validateResult[1].status = true;
break;
case 404:
validateResult[1].message = '图形验证码错误';
validateResult[1].status = false;
break;
}
callback();
});
}
//短信验证码ajax校验
function msgCaptchaAjaxFn(callback) {
$.ajax({
type: 'POST',
url: '/passport/register/msgcaptcha',
data: {
code: $ca.val(),
mobile: $pn.val(),
area: $region.text().split('+')[1]
}
}).then(function(data) {
switch (data.code) {
case 200:
validateResult[2].message = '';
validateResult[2].status = true;
break;
case 404:
validateResult[2].message = '短信验证码错误';
validateResult[2].status = false;
break;
}
callback();
});
}
// 验证
function validateRule($element, callback) {
var val = $.trim($element.val()),
regionCode;
//手机号校验
if ($element.hasClass('phone-num')) {
regionCode = $region.text();
if (val === '') {
validateResult[0].message = '请输入手机号码';
validateResult[0].status = false;
callback();
} else if (!regValidate.phoneRegx[regionCode].test(val)) {
validateResult[0].message = '手机号码格式不正确,请重新输入';
validateResult[0].status = false;
callback();
} else {
phoneAjaxFn(callback);
}
//图形验证码校验
} else if ($element.hasClass('captcha')) {
if (val === '') {
validateResult[1].message = '请输入图形验证码';
validateResult[1].status = false;
callback();
} else if (val.length <= 3) {
validateResult[1].message = '图形验证码为4位';
validateResult[1].status = false;
callback();
} else {
// 并且手机号正确
if (validateResult[0].status) {
picCaptchaAjaxFn(callback);
} else {
validateResult[1].message = '图形验证码错误';
validateResult[1].status = false;
callback();
}
}
//短信验证码校验
} else if ($element.hasClass('msg-captcha')) {
if (val === '') {
validateResult[2].message = '请输入短信验证码';
validateResult[2].status = false;
callback();
} else if (val.length <= 3) {
validateResult[2].message = '短信验证码为4位';
validateResult[2].status = false;
callback();
} else {
// 并且图形验证码正确
if (validateResult[1].status) {
msgCaptchaAjaxFn(callback);
} else {
validateResult[2].message = '短信验证码错误';
validateResult[2].status = false;
}
}
//密码校验
} else if ($element.hasClass('pwd')) {
if (val === '') {
validateResult[3].message = '请输入密码';
validateResult[3].status = false;
} else if (val.length < 6 || val.length > 20) {
validateResult[3].message = '密码只支持6-20位字符';
validateResult[3].status = false;
} else if (/\s/.test($element.val())) {
validateResult[3].message = '密码不能包含空格';
validateResult[3].status = false;
} else {
validateResult[3].message = '';
validateResult[3].status = true;
}
callback();
//二次密码校验
} else if ($element.hasClass('repwd')) {
if (val === '') {
validateResult[4].message = '请输入密码确认';
validateResult[4].status = false;
} else if ($pwd.val() !== val) {
validateResult[4].message = '与密码不一致,请重新输入';
validateResult[4].status = false;
} else {
validateResult[4].message = '';
validateResult[4].status = true;
}
callback();
}
}
//显示提示信息
function showErrTip() {
var show = false,
tipPosition,
$container,
i,
validateResultLen = validateResult.length;
for (i = 0; i < validateResultLen; i++) {
if (!show) {
//不可以通过status判断
if (!!validateResult[i].message) {
//显示错误提示
$errTip.find('span').text(validateResult[i].message);
$container = $('#' + validateResult[i].id);
tipPosition = $container.offset();
$errTip.css({
top: tipPosition.top - 40,
left: tipPosition.left
}).removeClass('hide');
show = true; //停止判断
} else {
$errTip.addClass('hide');
}
}
}
}
//显示红色边框
function showBorder() {
var $errInput,
i,
validateResultLen = validateResult.length;
for (i = 0; i < validateResultLen; i++) {
if (!!validateResult[i].message) {
//显示红色边框
$errInput = $('#' + validateResult[i].id);
$errInput.addClass('error');
} else {
//去掉红色边框
$errInput = $('#' + validateResult[i].id);
$errInput.removeClass('error');
}
}
}
// 密码强度验证
function pwdFn($obj) {
var pwd = $obj.val(),
pwdStrength = computeComplex(pwd),
level = 0;
if (pwdStrength === 0) {
level = 0;
} else if (pwdStrength <= 10) {
level = 1;
} else if (pwdStrength <= 20) {
level = 2;
} else {
level = 3;
}
switch (level) {
case 0:
$pwdParent.removeClass('red yellow green');
$pwdIntensity.removeClass('color');
break;
case 1:
$pwdParent.addClass('red').removeClass('yellow green');
$pwdIntensity.filter('.low').addClass('color');
$pwdIntensity.filter('.mid,.high').removeClass('color');
break;
case 2:
$pwdParent.addClass('yellow').removeClass('red green');
$pwdIntensity.filter('.low,.mid').addClass('color');
$pwdIntensity.filter('.high').removeClass('color');
break;
case 3:
$pwdParent.addClass('green').removeClass('yellow red');
$pwdIntensity.addClass('color');
break;
}
//提示框
if (pwd === '') {
$pwdTip1.removeClass('red yes no').addClass('default');
} else if (pwd.length < 6 || pwd.length > 20) {
$pwdTip1.removeClass('default yes').addClass('no red');
} else {
$pwdTip1.removeClass('default no red').addClass('yes');
}
}
// 失去焦点时开始校验
// Tips: 不可以在获得焦点的时候验证,获得焦点和失去焦点的间隔太小,如果中间存在ajax校验的话会出现问题
$registerPage.find('.va').keyup(function() {
var j,
statusLen = 0,
vLen = validateResult.length,
$that = $(this);
validateRule($(this), function() {
showErrTip(); // 显示错误提示
showBorder(); // 显示红色边框
// 如果validateResult中有4个status为true表示验证通过
for (j = 0; j < vLen; j++) {
if (validateResult[j].status) {
statusLen++;
}
}
if (statusLen === 4 && $('#agree-terms').is(':checked')) {
$registerBtn.removeClass('disable').removeAttr('disabled');
} else {
$registerBtn.addClass('disable').attr('disabled', 'true');
}
// 图形验证通过时,发送短信按钮可点击
if (validateResult[1].status) {
$sendCaptcha.removeClass('disable');
} else {
$sendCaptcha.addClass('disable');
}
//图形验证通过时,发送短信按钮可点击 end
});
// 如果是密码则校验强度
if (($that).hasClass('pwd')) {
pwdFn($that);
}
}).blur(function() {
/*validateRule($(this), function() {
showErrTip();
showBorder(); // 显示红色边框
});*/
});
$regionSelect.change(function() {
$region.text('+' + $('#region').val());
validateRule($pn, showErrTip); //验证
});
// 点击发送验证码
$sendCaptcha.click(function() {
var timeResidue = 10,
t;
if ($(this).hasClass('disable')) {
return;
}
//todo ajax
t = setInterval(function() {
if (timeResidue <= 0) {
$sendCaptcha.removeClass('disable').val('获取短信验证码');
clearInterval(t);
return;
}
$sendCaptcha.addClass('disable').val(timeResidue-- + '秒可重新发送');
}, 1000);
});
//form表单提交
$registerBtn.click(function() {
if ($(this).hasClass('disable')) {
return;
} else {
//ajax提交
$.ajax({
type: 'POST',
url: '/passport/register/mobileregister',
data: {
area: $region.text().split('+')[1],
mobile: $pn.val(),
captcha: $ca.val(),
code: $mc.val(),
password: $pwd.val()
}
}).then(function(data) {
var time = 0,
t,
refer = data.href;
t = setTimeout(function() {
time++;
}, 1000);
$.ajax({
type: 'POST',
url: '/passport/register/mobileregister',
data: {
session: data.session
}
}).then(function(data) {
if (data.code === 200 && t < 3) {
clearInterval(t);
location.href = refer;
}
});
if (t >= 3) {
clearInterval(t);
location.href = refer;
}
});
}
});
$('.change-captcha').click(function() {
var time = new Date(),
$captchaImg = $('.captcha-img'),
captchaImgSrc = $captchaImg.attr('src').split('?')[0];
$captchaImg.attr('src', captchaImgSrc + '?t=' + time.getTime());
});
});
define("js/passport/mail-phone-regx", [], function(require, exports, module){
/**
* 国家区号Map手机号码以及邮箱验证正则
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/12/11
*/
var countryPhoneRegx = {
'+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]{1}[0-9]{8}$/,
'+81': /^0[9|8|7][0-9]{9}$/,
'+61': /^[0-9]{11}$/
};
var emailRegx = /^[.\-_a-zA-Z0-9]+@[\-_a-zA-Z0-9]+\.[a-zA-Z0-9]/;
exports.phoneRegx = countryPhoneRegx;
exports.emailRegx = emailRegx;
});
define("js/passport/pwd-strength", [], function(require, exports, module){
/*
* 计算密码复杂度
*/
function gettype(str, i) {
if (str.charCodeAt(i) >= 48 && str.charCodeAt(i) <= 57) {
return 1;
} else if (str.charCodeAt(i) >= 97 && str.charCodeAt(i) <= 122) {
return 2;
} else if (str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 90) {
return 3;
}
return 4;
}
function isregular(cur, pre, type) {
var curCode = cur.charCodeAt(0);
var preCode = pre.charCodeAt(0);
if (curCode - preCode === 0) {
return true;
}
if (type !== 4 && (curCode - preCode === 1 || curCode - preCode === -1)) {
return true;
}
return false;
}
function getcomplex(curType, preType) {
if (preType === 0 || curType === preType) {
return 0;
} else if (curType === 4 || preType === 4) {
return 2;
} else {
return 1;
}
}
function computeComplex(password) {
var complex = 0,
length = password.length,
pre = '',
preType = 0,
i = 0,
cur,
curType;
for (i = 0; i < length; i++) {
cur = password.charAt(i);
curType = gettype(password, i);
if (preType !== curType || !isregular(cur, pre, curType)) {
complex += curType + getcomplex(curType, preType);
}
pre = cur;
preType = curType;
}
return complex;
}
module.exports = computeComplex;
});
define("js/passport/back", ["jquery","jquery.placeholder"], function(require, exports, module){
/**
* 找回密码
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/12/14
*/
var $ = require("jquery"),
phoneRegx = require("js/passport/mail-phone-regx").phoneRegx;
var $cr = $('#country-code-hide'),
$phoneNum = $('#phone-num'),
$ca = $('#captcha'),
$tipPanel = $('#tip-panel'),
emailReg = /^[.\-_a-zA-Z0-9]+@[\-_a-zA-Z0-9]+\.[a-zA-Z0-9]/,
acAccount = [
['qq.com', '163.com', '126.com', 'sina.com', 'gmail.com',
'sohu.com', 'hotmail.com', '139.com', '189.com'], //数字顺序
['gmail.com', 'qq.com', '163.com', '126.com', 'sina.com',
'sohu.com', 'hotmail.com', '139.com', '189.com'] //组合顺序
],
$ccList = $('#country-code-list'),
$cc = $('#country-code'),
$btn = $('#find-btn'),
$accErr = $('#account-err'),
$caErr = $('#captcha-err'),
time, //timeout-id
caCount = 4, //验证码位数
hasPh = false,
hasCa = false;
require("jquery.placeholder");
/*function getSource(column, postition, event) {
try {
dataLayer.push({
louceng: column,
weizhi: postition,
event: event
});
} catch (e) {}
}*/
function imgcode() {
$('#captcha-img').attr('src', 'http://www.yohobuy.com/passport/images?t=' + Math.random());
//getSource('yoho_family_web', '换一张', 'homepage_man');
}
function enableBtn() {
if (hasPh && hasCa) {
$btn.removeClass('disable').prop('disabled', false);
} else {
$btn.addClass('disable').prop('disabled', true);
}
}
function vaPn(v) {
var pass = true,
errTxt = '';
v = $.trim(v);
if (v !== '') {
if (/^[0-9]+$/.test(v)) {
if (phoneRegx[$cr.val()].test(v)) {
pass = true;
} else {
errTxt = '手机号码格式不正确, 请重新输入';
pass = false;
}
} else {
if (emailReg.test(v)) {
pass = true;
} else {
errTxt = '邮箱格式不正确, 请重新输入';
pass = false;
}
}
} else {
errTxt = '账户名不能为空';
pass = false;
}
hasPh = pass;
return {
pass: pass,
errTxt: errTxt
};
}
function vaCa() {
var v = $.trim($ca.val());
if (v === '' || v.length < caCount) {
hasCa = false;
enableBtn();
return;
} else {
$.ajax({
type: 'POST',
url: '/passport/back/authcode',
data: {
code: v,
mobile: $('#phone-num').val(),
area: $('#country-code-hide').val()
}
}).then(function(data) {
if (data.code === 200) {
hasCa = true;
} else {
hasCa = false;
imgcode();
}
enableBtn();
});
}
}
$ca.attr('maxlength', caCount);
//IE8 placeholder
$('input').placeholder();
$('#change-captcha, #captcha-img').on('click', function() {
imgcode();
});
$cc.on('click', function(e) {
e.stopPropagation();
if ($ccList.css('style') === 'block') {
$ccList.slideUp('fast');
} else {
$ccList.slideDown('fast');
}
});
$ccList.delegate('li', 'click', function(e) {
var $cur = $(this),
code = $cur.data('cc'),
pnVa;
e.stopPropagation();
$cr.val(code);
$cc.find('em').html($cur.text());
//切换后验证手机号码
if ($.trim($phoneNum.val()) !== '') {
pnVa = vaPn($phoneNum.val());
enableBtn();
if (hasPh) {
$accErr.addClass('hide');
$phoneNum.removeClass('error');
} else {
$accErr.removeClass('hide').text(pnVa.errTxt);
$phoneNum.addClass('error');
}
}
$ccList.slideUp('fast');
});
$(document).click(function() {
if ($tipPanel.css('display') === 'block') {
$tipPanel.slideUp();
}
if ($ccList.css('display') === 'block') {
$ccList.slideUp();
}
});
$phoneNum.keyup(function() {
var account = $.trim($(this).val()),
html = '',
acs,
i;
//输入@时显示自动补全列表
if (account.indexOf('@') !== -1 && account.lastIndexOf('@') === account.indexOf('@')) {
if (/^[0-9]*@$/.test(account)) {
//数字顺序
acs = acAccount[0];
} else {
acs = acAccount[1];
}
for (i = 0; i < acs.length; i++) {
html += '<li>' + account.slice(0, account.indexOf('@')) + '@' + acs[i] + '</li>';
}
$tipPanel.html(html).slideDown();
} else {
$tipPanel.slideUp();
}
vaPn(account);
enableBtn();
}).blur(function() {
time = setTimeout(function() {
var pnVa = vaPn($phoneNum.val());
if (pnVa.pass) {
$accErr.addClass('hide');
$phoneNum.removeClass('error');
} else {
$accErr.removeClass('hide').find('em').text(pnVa.errTxt);
$phoneNum.addClass('error');
}
}, 170);
}).focus(function() {
$(this).removeClass('error');
//focus隐藏错误提示
$accErr.addClass('hide');
});
//验证码在鼠标移开后验证, keyup时不再验证
$ca.blur(function() {
var errTxt = $.trim($ca.val()) === '' ? '验证码不能为空' : '验证码不正确';
if (hasCa) {
$caErr.addClass('hide');
$ca.removeClass('error');
} else {
$caErr.removeClass('hide').find('em').text(errTxt);
$ca.addClass('error');
//验证码错误则刷新验证码
imgcode();
}
}).focus(function() {
$(this).removeClass('error');
//focus隐藏错误提示
$caErr.addClass('hide');
}).keyup(function() {
vaCa();
});
$tipPanel.delegate('li', 'click', function(e) {
var account = $(this).text(),
pnVa;
e.stopPropagation();
$phoneNum.val(account);
if (time) {
clearTimeout(time);
pnVa = vaPn(account);
enableBtn();
if (pnVa.pass) {
$accErr.addClass('hide');
$phoneNum.removeClass('error');
} else {
$accErr.removeClass('hide').find('em').text(pnVa.errTx);
$phoneNum.addClass('error');
}
time = null;
}
$tipPanel.slideUp();
});
$('#find-btn').click(function(e) {
//getSource('yoho_family_web', '下一步按钮', 'homepage_man');
if (/^[0-9]+$/.test($.trim($phoneNum.val()))) {
$('#find-form').attr('action', '/passport/back/mobile');
}
if ($(this).hasClass('disable')) {
return;
}
if (!hasCa || !hasPh) {
e.preventDefault();
return true;
}
});
});
define("js/passport/login", ["jquery","jquery.placeholder"], function(require, exports, module){
/**
* 登录
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/12/11
*/
var $ = require("jquery");
var mailPostfix = {
num: ['qq.com', '163.com', '126.com', 'sina.com', 'gmail.com', 'sohu.com', 'hotmail.com', '139.com', '189.com'],
other: ['gmail.com', 'qq.com', '163.com', '126.com', 'sina.com', 'sohu.com', 'hotmail.com', '139.com', '189.com']
};
var $account = $('#account'),
$password = $('#password');
var $accountTip = $account.siblings('.err-tip'),
$passwordTip = $password.siblings('.err-tip'),
$capsLock = $('#caps-lock');
var $countryCodeHide = $('#country-code-hide'),
$countryCodeEm = $('#country-code > em'),
$countryList = $('#country-list');
var $emailAutoComplete = $('#email-autocomplete');
var mailPhoneRegx = require("js/passport/mail-phone-regx");
//checkbox status unicode
var checkbox = {
checked: '&#xe612;',
unchecked: '&#xe613;'
};
var emailAcTime;
require("jquery.placeholder");
//验证账户名
function validateAccount() {
var pass = false,
account = $.trim($account.val()),
err;
if (account !== '') {
if (/^[0-9]+$/.test(account)) {
//如果是纯数字,则作为手机号码处理
if (mailPhoneRegx.phoneRegx['+' + $countryCodeHide.val()].test(account)) {
pass = true;
} else {
pass = false;
err = '手机号码不正确,请重新输入';
}
} else {
if (mailPhoneRegx.emailRegx.test(account)) {
pass = true;
} else {
pass = false;
err = '邮箱格式不正确,请重新输入';
}
}
} else {
err = '请输入账户名';
}
if (pass) {
$accountTip.addClass('hide');
$account.removeClass('error');
} else {
$accountTip.removeClass('hide').children('em').text(err);
$account.addClass('error');
}
return pass;
}
//验证密码
function validatePassword() {
var pass = false,
password = $.trim($password.val()),
err;
if (password !== '') {
if (password.length < 6) {
err = '请输入长度为6-20字符的密码';
} else {
pass = true;
}
} else {
err = '请输入密码';
}
if (pass) {
$passwordTip.addClass('hide');
$password.removeClass('error');
} else {
$passwordTip.removeClass('hide').children('em').text(err);
$password.addClass('error');
}
}
//验证
function validate() {
var pass = true,
account = $.trim($account.val()),
password = $.trim($password.val());
if (account !== '') {
pass = validateAccount() && validatePassword();
} else {
pass = false;
$account.addClass('error');
if (password === '') {
//账户名和密码都为空的情况下点击登陆,只在账户输入框后显示错误提示
$accountTip.addClass('both-error').removeClass('hide').children('em').text('请输入账户名和密码');
$passwordTip.addClass('hide');
$password.addClass('error');
} else {
$accountTip.removeClass('hide').children('em').text('请输入账户名');
}
}
return pass;
}
$('[placeholder]').placeholder();
//展开地区列表
$('#country-code').on('click', function() {
if ($countryList.css('display') === 'none') {
$countryList.slideDown();
}
});
//选中地区列表项
$countryList.on('click', 'li', function() {
var $this = $(this),
cc = $this.data('cc');
$countryCodeEm.html($this.html());
$countryCodeHide.val(cc);
$countryList.slideUp();
});
//点击其他区域,收起区域列表
$(document).on('click', function(e) {
if ($(e.target).closest('#country-code').length > 0) {
return;
}
if ($countryList.css('display') === 'block') {
$countryList.slideUp();
}
});
//邮箱
$account.on('keyup', function() {
var account = $.trim($(this).val()),
html = '',
accountMatch,
matchStr,
postfix,
i;
//输入@时自动补全邮箱后缀
//此处>0非错误,用于避免输入的第一个字符为@被识别为邮箱
if (account.indexOf('@') > 0) {
accountMatch = account.match(/^[0-9]+@(.*)/);
if (accountMatch) {
//数字邮箱补全
postfix = mailPostfix.num;
} else {
postfix = mailPostfix.other;
}
matchStr = accountMatch[1];
for (i = 0; i < postfix.length; i++) {
if (postfix[i].indexOf(matchStr) > -1) {
html += '<li>' + account.slice(0, account.indexOf('@')) + '@' + postfix[i] + '</li>';
}
}
if (html !== '') {
$emailAutoComplete.html(html).removeClass('hide');
} else {
//隐藏autocomplete
$emailAutoComplete.html('').addClass('hide');
}
}
}).on('blur', function() {
emailAcTime = setTimeout(function() {
$emailAutoComplete.addClass('hide');
//验证
validateAccount();
}, 200);
});
//密码
$password.on('blur', function() {
validatePassword();
}).on('keypress', function(e) {
var code = e.which,
isShift = e.shiftKey || (code === 16) || false;
//CapsLock检测
if ((!isShift && (code >= 65 && code <= 90)) ||
(isShift && (code >= 97 && code <= 122))) {
$capsLock.removeClass('hide');
return;
}
$capsLock.addClass('hide');
});
//邮箱自动完成列表项点击
$emailAutoComplete.on('click', 'li', function() {
clearTimeout(emailAcTime); //清空默认关闭
$account.val($(this).text()).focus();
$emailAutoComplete.addClass('hide');
});
//记住登录状态
$('.remeber-me').on('click', function() {
var $this = $(this);
$this.toggleClass('checked');
if ($this.hasClass('checked')) {
$this.children('i').html(checkbox.checked);
} else {
$this.children('i').html(checkbox.unchecked);
}
});
//focus到输入框则隐藏错误提示和样式
$('.va').on('focus', function() {
var $this = $(this);
$this.removeClass('error');
$this.siblings('.err-tip').addClass('hide');
});
//登录
$('#login-btn').on('click', function() {
var pass = validate();
if (pass) {
$('#login-form').submit();
}
});
});
define("js/passport/reset", ["jquery","jquery.placeholder"], function(require, exports, module){
/**
* 找回密码
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/12/14
*/
var $ = require("jquery");
var $pwd = $('#pwd'),
$repwd = $('#re-input'),
$next = $('#reset-pwd-btn'),
$pwdErr = $('#pwd-err'),
$repwdErr = $('#repwd-err'),
$pwdTips = $('#pwd-tips');
var hasNoErrPw = false;
var $pwdIntensity = $('.pwd-intensity'),
$pwdParent = $pwdIntensity.closest('.pwd-intensity-container'),
$pwdTip1 = $('#pwd-tip1');
require("jquery.placeholder");
/*
* 计算密码复杂度
*/
function gettype(str, i) {
if (str.charCodeAt(i) >= 48 && str.charCodeAt(i) <= 57) {
return 1;
} else if (str.charCodeAt(i) >= 97 && str.charCodeAt(i) <= 122) {
return 2;
} else if (str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 90) {
return 3;
}
return 4;
}
function isregular(cur, pre, type) {
var curCode = cur.charCodeAt(0);
var preCode = pre.charCodeAt(0);
if (curCode - preCode === 0) {
return true;
}
if (type !== 4 && (curCode - preCode === 1 || curCode - preCode === -1)) {
return true;
}
return false;
}
function getcomplex(curType, preType) {
if (preType === 0 || curType === preType) {
return 0;
} else if (curType === 4 || preType === 4) {
return 2;
} else {
return 1;
}
}
function computeComplex(password) {
var complex = 0,
length = password.length,
pre = '',
preType = 0,
i = 0,
cur,
curType;
for (i = 0; i < length; i++) {
cur = password.charAt(i);
curType = gettype(password, i);
if (preType !== curType || !isregular(cur, pre, curType)) {
complex += curType + getcomplex(curType, preType);
}
pre = cur;
preType = curType;
}
return complex;
}
function pwdKeyupEvt() {
var pwd = $pwd.val(),
pwdStrength = computeComplex(pwd),
level = 0;
//TODO:自定义密码强度规则,需要修正
if (pwdStrength === 0) {
level = 0;
} else if (pwdStrength <= 10) {
level = 1;
} else if (pwdStrength <= 20) {
level = 2;
} else {
level = 3;
}
switch (level) {
case 0:
$pwdParent.removeClass('red yellow green');
$pwdIntensity.removeClass('color');
break;
case 1:
$pwdParent.addClass('red').removeClass('yellow green');
$pwdIntensity.filter('.low').addClass('color');
$pwdIntensity.filter('.mid,.high').removeClass('color');
break;
case 2:
$pwdParent.addClass('yellow').removeClass('red green');
$pwdIntensity.filter('.low,.mid').addClass('color');
$pwdIntensity.filter('.high').removeClass('color');
break;
case 3:
$pwdParent.addClass('green').removeClass('yellow red');
$pwdIntensity.addClass('color');
break;
}
//
if (pwd === '') {
hasNoErrPw = false;
$pwdTip1.removeClass('red yes no').addClass('default');
} else {
if (pwd.length < 6 || pwd.length > 20) {
hasNoErrPw = false;
$pwdTip1.removeClass('default yes').addClass('no red');
} else {
hasNoErrPw = true;
$pwdTip1.removeClass('default no red').addClass('yes');
}
//提示2不做验证
}
}
//IE8 placeholder
$('input').placeholder();
$('.va').keyup(function() {
var pass = true;
if ($(this).hasClass('pwd')) {
pwdKeyupEvt();
} else {
if ($(this).val() === '') {
pass = false;
}
}
if (pass && hasNoErrPw && $pwd.val() === $repwd.val()) {
pass = true;
} else {
pass = false;
}
if (pass) {
$next.removeClass('disable').prop('disabled', false);
} else {
$next.addClass('disable').prop('disabled', true);
}
}).blur(function() {
var v = $(this).val();
if ($(this).hasClass('pwd')) {
if (v === '') {
$(this).addClass('error');
$pwdErr.removeClass('hide').find('em').text('请输入密码');
} else if (v.length < 6 || v.length > 20) {
$(this).addClass('error');
$pwdErr.removeClass('hide').find('em').text('密码只支持6-20位');
} else {
$pwdErr.addClass('hide');
if ($repwd.val() !== '') {
if (v !== $repwd.val()) {
$repwd.addClass('error');
$repwdErr.removeClass('hide').find('em').text('两次密码输入不一致,请重新输入');
} else {
$repwd.removeClass('error');
$repwdErr.addClass('hide');
}
}
}
} else {
if (v === '') {
$(this).addClass('error');
$repwdErr.removeClass('hide').find('em').text('请输入密码确认');
} else {
if ($pwd.val() !== '' && v !== $pwd.val()) {
$(this).addClass('error');
$repwdErr.removeClass('hide').find('em').text('两次密码输入不一致,请重新输入');
} else {
$(this).removeClass('error');
$repwdErr.addClass('hide');
}
}
}
}).focus(function() {
$(this).removeClass('error');
//focus后错误提示隐藏
if ($(this).hasClass('pwd')) {
$pwdErr.addClass('hide');
} else {
$repwdErr.addClass('hide');
}
});
$pwd.focus(function() {
$pwdErr.addClass('hide');
$pwdTips.removeClass('hide');
}).blur(function() {
$pwdTips.addClass('hide');
});
$('#pwd, #repwd').keydown(function(e) {
var code = e.keyCode || e.which;
//空格输入过滤
if (code === 32) {
e.preventDefault();
return;
}
});
});
... ...
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.