%PDF- %PDF-
| Direktori : /disk/www/wwwroot/test-lingceed.echineselearning.biz/js/ |
| Current File : /disk/www/wwwroot/test-lingceed.echineselearning.biz/js/ecl-ft-form-tool.js |
/*
* 可能对表单功能造成影响的:
* 1. FT表单的HTML结构的变化
* 2. FT表单的HTML元素的class属性的修改、删除
* 3. FT表单增加、修改、删除了功能
* 不会对表单功能造成影响的:
* 1. FT表单上文字的变化
* 2. FT表单的HTML元素的style属性的变化
* 3. FT表单的HTML元素的class属性的增加
* 4. FT表单相关的class内容的调整
*/
(function() {
var _ft_form_url = 'https://www2.echineselearning.com/FreeApply.do'; // FT表单提交地址
var _ft_fail_form_url = 'https://www2.echineselearning.com/FreeApplyFailed.do'; // FT表单提交失败的地址
if (window.location.host.indexOf('local') >= 0) {
_ft_form_url = 'http://local-ecl:8080/FreeApply.do';
_ft_fail_form_url = 'http://local-ecl:8080/FreeApplyFailed.do';
}
if (window.location.host.indexOf('test-') >= 0) {
_ft_form_url = 'https://test-ecl.echineselearning.biz/FreeApply.do';
_ft_fail_form_url = '//test-ecl.echineselearning.biz/FreeApplyFailed.do';
}
if (window.location.host.indexOf('test-www-product') >= 0) {
_ft_form_url = 'https://test-ecl-product.echineselearning.biz/FreeApply.do';
_ft_fail_form_url = '//test-ecl-product.echineselearning.biz/FreeApplyFailed.do';
}
var eclFtFormTool = {
data : {
forms : [],
submiting : false
},
init : function() {
this._initForms(); // 初始化表单
this._initEmailAutoMatch(); // 初始化邮箱自动匹配功能
this._initCountry(); // 初始化国家
this._initTip(); // 初始化提示
this._initSubmitBtn(); // 初始化提交按钮
this._initSmallTip(); // 初始化小图标提示
},
_initForms : function() {
var theTool = this;
var hasEclAccessTool = typeof eclAccessTool != 'undefined';
var hasUUID = typeof uuid != 'undefined';
$('form.js-ft-form').each(function(i) {
var form = {};
form.form = $(this);
// 设置一个ID,方便后面需要的时候查询
form.form.attr('ft-form-id', 'ft-form-id-' + i);
// 检查是否是填验证码的FT表单
// 在lead过滤器里面的IP提交的lead,在保存后会再让填写一次验证码,才会进入第二步页面
if (form.form.hasClass('js-ft-code-form')) {
form.isCodeForm = true;
} else {
form.isCodeForm = false;
}
// 添加用户访问ID数据到表单里面
if (hasEclAccessTool) {
var uaid = eclAccessTool.getUserAccessId();
if (uaid != null) {
form.form.append('<input type="hidden" name="userAccessId" value="' + uaid + '" />');
}
}
// 添加lead提交ID数据到表单里面
var leadGuid = null;
if (hasUUID) {
leadGuid = uuid.v4().replace(new RegExp('-', 'gm'), '');
} else {
leadGuid = _generateUUID();
}
form.form.append('<input type="hidden" name="leadGuid" value="' + leadGuid + '" />');
// 保存表单对象
theTool.data.forms[i] = form;
});
},
_initEmailAutoMatch : function() {
if (this.data.forms.length > 0) {
// 自动补全插件配置
var emailOption = {
emailTip : "", // 输入框不显示内容
// 补全的邮箱
aEmail : ["gmail.com", "yahoo.com", "outlook.com", "hotmail.com", "live.com", "icloud.com", "mail.ru", "aol.com"],
className : "mailListBox" // 样式类名,需要改样式让设计找这个类
}
for (var i = 0; i < this.data.forms.length; i++) {
var $form = this.data.forms[i].form;
$form.find('input[name=email]').each(function() {
// 因为有的页面加载完之后高度会变化,所以在点击的时候再加载
$(this).data('tmp-init-mail', 'false');
$(this).click(function() {
if ($(this).data('tmp-init-mail') == 'false') {
$(this).data('tmp-init-mail', 'true');
if ($(this).emailMatch) {
$(this).emailMatch(emailOption);
}
}
});
});
}
}
},
_initCountry : function() {
if (this.data.forms.length > 0) {
for (var i = 0; i < this.data.forms.length; i++) {
var $form = this.data.forms[i].form;
$form.find('select[name=country]').each(function() {
_addCountryOptions($(this));
});
$form.find('div.js-ft-form-country-click-div').each(function() {
$(this).data('tmp-ft-form', $form);
$(this).click(function(e) {
e.stopPropagation(); // 阻止冒泡
_showCountrySelect($(this).data('tmp-ft-form'));
});
});
}
$('body').click(function() {
$('.js-ft-form-country-show-div').hide();
// $(".mailListBox").hide();
});
}
},
_initTip : function() {
if (this.data.forms.length > 0) {
for (var i = 0; i < this.data.forms.length; i++) {
var $form = this.data.forms[i].form;
$form.find('input[name=areacode]').each(function() {
var $ftForm = $form;
$(this).focus(function() {
$ftForm.find('div.js-ft-form-areacode-tip').show();
});
$(this).blur(function() {
$ftForm.find('div.js-ft-form-areacode-tip').hide();
});
$(this).keypress(function() {
$ftForm.find('div.js-ft-form-areacode-tip').hide();
});
});
$form.find('input[name=tel]').each(function() {
var $ftForm = $form;
$(this).focus(function() {
$ftForm.find('div.js-ft-form-tel-tip').show();
});
$(this).blur(function() {
$ftForm.find('div.js-ft-form-tel-tip').hide();
});
$(this).keypress(function() {
$ftForm.find('div.js-ft-form-tel-tip').hide();
});
});
}
}
},
_initSubmitBtn : function() {
if (this.data.forms.length > 0) {
var theTool = this;
for (var i = 0; i < this.data.forms.length; i++) {
var $form = this.data.forms[i].form;
var isCodeForm = this.data.forms[i].isCodeForm;
$form.find('.js-ft-form-submit-btn').each(function() {
var $ftForm = $form;
if (isCodeForm) {
// 点击提交表单按钮,首先验证表单(未填的不验证)
// 验证通过了,就先记录日志,然后提交表单
// 验证没通过,就记录日志,同时弹出错误提示
$(this).click(function() {
if (!theTool.data.submiting) {
theTool.data.submiting = true;
_checkCodeFtForm($ftForm, function() {
// 验证成功
// _submitFtLog($ftForm, 'ok', function() {
// _submitFtForm($ftForm);
// });
var host = window.location.host;
var otherObj = {
"host":host,
"normalLead":"ok"
};
supplementFormLog("lead", _ft_form_url, $ftForm, JSON.stringify(otherObj), function() {
_submitFtForm($ftForm);
});
}, function(errMsg) {
// 验证失败
// _submitFtLog($ftForm, 'fail');
var host = window.location.host;
var otherObj = {
"host":host,
"normalLead":"fail"
};
supplementFormLog("lead", _ft_form_url, $ftForm, JSON.stringify(otherObj));
_submitFailedFtForm($ftForm);
alert(errMsg);
theTool.data.submiting = false;
});
}
});
} else {
// 点击提交表单按钮,首先验证表单
// 验证通过了,就先记录日志,然后提交表单
// 验证没通过,就记录日志,同时弹出错误提示
$(this).click(function() {
if (!theTool.data.submiting) {
theTool.data.submiting = true;
_checkFtForm($ftForm, function() {
// 验证成功
// _submitFtLog($ftForm, 'ok', function() {
// _submitFtForm($ftForm);
// });
var host = window.location.host;
var otherObj = {
"host":host,
"normalLead":"ok"
};
supplementFormLog("lead", _ft_form_url, $ftForm, JSON.stringify(otherObj), function() {
_submitFtForm($ftForm);
});
}, function(errMsg) {
// 验证失败
// _submitFtLog($ftForm, 'fail');
var host = window.location.host;
var otherObj = {
"host":host,
"normalLead":"fail"
};
supplementFormLog("lead", _ft_form_url, $ftForm, JSON.stringify(otherObj));
_submitFailedFtForm($ftForm);
alert(errMsg);
theTool.data.submiting = false;
});
}
});
}
});
}
}
},
_initSmallTip : function() {
if (this.data.forms.length > 0) {
for (var i = 0; i < this.data.forms.length; i++) {
var $form = this.data.forms[i].form;
$form.find('.js-ft-form-strictly').each(function() {
$(this).data('tmp-ft-form-strictly', $form);
// 清除样式
$(this).data('tmp-ft-form-strictly').find('.js-ft-form-strictly-tip').removeClass("tip_pc");
$(this).data('tmp-ft-form-strictly').find('.js-ft-form-strictly-tip').removeClass("tip_pc_ipad");
$(this).data('tmp-ft-form-strictly').find('.js-ft-form-strictly-tip').removeClass("tip_mac");
console.log("ua 信息 ["+navigator.userAgent+"]")
if(/(iPad)/i.test(navigator.userAgent)){ // Ipad 使用样式
$(this).data('tmp-ft-form-strictly').find('.js-ft-form-strictly-tip').addClass("tip_pc_ipad");
}else if(navigator.userAgent.indexOf('Mac OS X') > -1){ // Mac 使用样式
$(this).data('tmp-ft-form-strictly').find('.js-ft-form-strictly-tip').addClass("tip_mac");
}else{ // PC 使用样式
$(this).data('tmp-ft-form-strictly').find('.js-ft-form-strictly-tip').addClass("tip_pc");
}
if(/(iPhone|Android|iPad)/i.test(navigator.userAgent)){
$(this).bind('touchstart',function(e) {
e.stopPropagation(); // 阻止冒泡
$(this).data('tmp-ft-form-strictly').find('.js-ft-form-strictly-tip').show();
});
}else{
$(this).click(function(e) {
e.stopPropagation(); // 阻止冒泡
$(this).data('tmp-ft-form-strictly').find('.js-ft-form-strictly-tip').show();
});
}
});
}
if(/(iPhone|Android|iPad)/i.test(navigator.userAgent)){
$('body').bind("touchstart",function(e) {
if(!$('.js-ft-form-strictly-tip').is(':hidden')){
$('.js-ft-form-strictly-tip').hide();
}
});
}else{
$('body').click(function() {
$('.js-ft-form-strictly-tip').hide();
});
}
}
}
};
var _arr_country = [
[ "af", "Afghanistan +93" ],[ "ax", "Aland Islands +358" ], [ "al", "Albania +355" ],
[ "dz", "Algeria +213" ], [ "as", "American Samoa +1" ], [ "ad", "Andorra +376" ], [ "ao", "Angola +244" ],
[ "ai", "Anguilla +1" ], [ "aq", "Antarctica +0" ], [ "ag", "Antigua and Barbuda +1" ], [ "ar", "Argentina +54" ],
[ "am", "Armenia +374" ], [ "aw", "Aruba +297" ], [ "au", "Australia +61" ], [ "at", "Austria +43" ], [ "az", "Azerbaijan +994" ],
[ "bs", "Bahamas +1" ], [ "bh", "Bahrain +973" ], [ "bd", "Bangladesh +880" ], [ "bb", "Barbados +1" ],
[ "by", "Belarus +375" ], [ "be", "Belgium +32" ], [ "bz", "Belize +501" ], [ "bj", "Benin +229" ], [ "bm", "Bermuda +1" ],
[ "bt", "Bhutan +975" ], [ "bo", "Bolivia +591" ],[ "bq", "Bonaire +599" ], [ "ba", "Bosnia and Herzegovina +387" ], [ "bw", "Botswana +267" ],
[ "bv", "Bouvet Island +47" ],[ "br", "Brazil +55" ],[ "io", "British Indian Ocean Territory +246" ],
[ "vg", "British Virgin Islands +1" ], [ "bn", "Brunei +673" ],[ "bg", "Bulgaria +359" ], [ "bf", "Burkina Faso +226" ],
[ "bi", "Burundi +257" ], [ "cv", "Cape Verde +238" ],[ "kh", "Cambodia +855" ],
[ "cm", "Cameroon +237" ],[ "ca", "Canada +1" ], [ "ky", "Cayman Islands +1" ], [ "cf", "Central African Republic +236" ],[ "td", "Chad +235" ],
[ "cl", "Chile +56" ], [ "cn", "China +86" ], [ "cx", "Christmas Island +61" ], [ "cc", "Cocos Islands +61" ],
[ "co", "Colombia +57" ], [ "km", "Comoros +269" ], [ "cg", "Congo +242" ], [ "cd", "Congo(DRC) +243" ],[ "ck", "Cook Islands +682" ],
[ "cr", "Costa Rica +506" ],[ "ci", "Côte d'Ivoire +225" ], [ "hr", "Croatia +385" ], [ "cu", "Cuba +53" ], [ "cw", "Curaçao +599" ],[ "cy", "Cyprus +357" ],
[ "cz", "Czech Republic +420" ], [ "dk", "Denmark +45" ], [ "dj", "Djibouti +253" ], [ "dm", "Dominica +1" ],
[ "do", "Dominican Republic +1" ], [ "tp", "East Timor +670" ], [ "ec", "Ecuador +593" ], [ "eg", "Egypt +20" ],
[ "sv", "El Salvador +503" ], [ "gq", "Equatorial Guinea +240" ], [ "er", "Eritrea +291" ], [ "ee", "Estonia +372" ],
[ "et", "Ethiopia +251" ], [ "fk", "Falkland Islands +500" ], [ "fo", "Faroe Islands +298" ], [ "fj", "Fiji +679" ],[ "fi", "Finland +358" ],
[ "fr", "France +33" ], [ "gf", "French Guiana +594" ], [ "pf", "French Polynesia +689" ],[ "tf", "French Southern Territories +262" ],
[ "ga", "Gabon +241" ], [ "gm", "Gambia +220" ], [ "ge", "Georgia +995" ], [ "de", "Germany +49" ], [ "gh", "Ghana +233" ],
[ "gi", "Gibraltar +350" ], [ "gr", "Greece +30" ], [ "gl", "Greenland +299" ], [ "gd", "Grenada +1" ],
[ "gp", "Guadeloupe +590" ], [ "gu", "Guam +1" ], [ "gt", "Guatemala +502" ],[ "gg", "Guernsey +44" ],[ "gn", "Guinea +224" ], [ "gw", "Guinea-Bissau +245" ],
[ "gy", "Guyana +592" ],[ "hk", "Hong Kong +852" ],[ "ht", "Haiti +509" ], [ "hn", "Honduras +504" ],
[ "hu", "Hungary +36" ], [ "is", "Iceland +354" ], [ "in", "India +91" ], [ "id", "Indonesia +62" ],
[ "ir", "Iran +98" ], [ "iq", "Iraq +964" ], [ "ie", "Ireland +353" ],[ "im", "Isle of Man +44" ], [ "il", "Israel +972" ], [ "it", "Italy +39" ],
[ "ci", "Ivory Coast +225" ], [ "jm", "Jamaica +1" ],[ "jy", "Jan Mayen +47" ], [ "jp", "Japan +81" ],[ "je", "Jersey +44" ], [ "jo", "Jordan +962" ],
[ "kz", "Kazakhstan +7" ], [ "ke", "Kenya +254" ], [ "ki", "Kiribati +686" ],[ "xk", "Kosovo +383" ],[ "kr", "Korea. South +82" ],[ "kp", "Korea. North +850" ],
[ "kw", "Kuwait +965" ], [ "kg", "Kyrgyzstan +996" ], [ "la", "Laos +856" ], [ "lv", "Latvia +371" ],
[ "lb", "Lebanon +961" ], [ "ls", "Lesotho +266" ], [ "lr", "Liberia +231" ], [ "ly", "Libya +218" ],
[ "li", "Liechtenstein +423" ], [ "lt", "Lithuania +370" ], [ "lu", "Luxembourg +352" ], [ "mo", "Macau +853" ],
[ "mk", "Macedonia +389" ], [ "mg", "Madagascar +261" ], [ "mw", "Malawi +265" ], [ "my", "Malaysia +60" ],
[ "mv", "Maldives +960" ], [ "ml", "Mali +223" ], [ "mt", "Malta +356" ], [ "mh", "Marshall Islands +692" ],
[ "mq", "Martinique +596" ], [ "mr", "Mauritania +222" ], [ "mu", "Mauritius +230" ], [ "yt", "Mayotte +262" ],
[ "mx", "Mexico +52" ], [ "fm", "Micronesia +691" ], [ "md", "Moldova +373" ], [ "mc", "Monaco +377" ], [ "mn", "Mongolia +976" ],[ "me", "Montenegro +382" ],
[ "ms", "Montserrat +1" ], [ "ma", "Morocco +212" ], [ "mz", "Mozambique +258" ], [ "mm", "Myanmar +95" ],
[ "na", "Namibia +264" ], [ "nr", "Nauru +674" ], [ "np", "Nepal +977" ], [ "nl", "Netherlands +31" ],
[ "an", "Netherlands Antilles +599" ], [ "nc", "New Caledonia +687" ], [ "nz", "New Zealand +64" ],
[ "ni", "Nicaragua +505" ], [ "ne", "Niger +227" ], [ "ng", "Nigeria +234" ], [ "nu", "Niue +683" ],
[ "nf", "Norfolk Island +672" ], [ "mp", "Northern Mariana Islands +1" ], [ "no", "Norway +47" ], [ "om", "Oman +968" ],
[ "pk", "Pakistan +92" ], [ "pw", "Palau +680" ],[ "ps", "Palestinian Authority +970" ], [ "pa", "Panama +507" ], [ "pg", "Papua New Guinea +675" ],
[ "py", "Paraguay +595" ], [ "pe", "Peru +51" ], [ "ph", "Philippines +63" ],[ "pn", "Pitcairn Islands +64" ],
[ "pl", "Poland +48" ], [ "pt", "Portugal +351" ], [ "pr", "Puerto Rico +1" ], [ "qa", "Qatar +974" ], [ "re", "Reunion +262" ],
[ "ro", "Romania +40" ], [ "ru", "Russia +7" ], [ "rw", "Rwanda +250" ],[ "sg", "Singapore +65" ],[ "bqsa", "Saba +599" ],[ "bl", "Saint Barthelemy +590" ],
[ "kn", "Saint Kitts and Nevis +1" ],[ "lc", "Saint Lucia +1" ], [ "ws", "Saint Martin +590" ],[ "vc", "Saint Vincent and the Grenadines +1" ],[ "ws", "Samoa +685" ],
[ "sm", "San Marino +378" ], [ "st", "Sao Tome and Principe +239" ],
[ "sa", "Saudi Arabia +966" ], [ "sn", "Senegal +221" ],[ "yu", "Serbia +381" ], [ "sc", "Seychelles +248" ], [ "sl", "Sierra Leone +232" ],[ "bqse", "Sint Eustatius +599" ],[ "sx", "Sint Maarten +1" ],
[ "sk", "Slovakia +421" ], [ "si", "Slovenia +386" ], [ "sp", "Solomon Islands +677" ],
[ "so", "Somalia +252" ], [ "za", "South Africa +27" ],[ "ss", "South Sudan +211" ], [ "es", "Spain +34" ], [ "lk", "Sri Lanka +94" ],
[ "sh", "St. Helena +290" ],[ "pm", "St. Pierre and Miquelon +508" ], [ "sd", "Sudan +249" ], [ "sr", "Suriname +597" ],
[ "sz", "Swaziland +268" ], [ "se", "Sweden +46" ], [ "ch", "Switzerland +41" ], [ "sy", "Syria +963" ], [ "tw", "Taiwan +886" ],
[ "tj", "Tajikistan +992" ], [ "tz", "Tanzania +255" ], [ "th", "Thailand +66" ],[ "tl", "Timor Leste +670" ], [ "tg", "Togo +228" ], [ "tk", "Tokelau +690" ],
[ "to", "Tonga +676" ], [ "tt", "Trinidad and Tobago +1" ], [ "tn", "Tunisia +216" ], [ "tr", "Turkey +90" ],
[ "tm", "Turkmenistan +993" ],[ "tc", "Turks and Caicos Islands +1" ], [ "tv", "Tuvalu +688" ],[ "us", "United States +1" ], [ "gb", "United Kingdom +44" ],
[ "vi", "U.S. Outlying Islands +1" ],[ "vi", "U.S. Virgin Islands +1" ], [ "ug", "Uganda +256" ], [ "ua", "Ukraine +380" ],
[ "ae", "United Arab Emirates +971" ], [ "uy", "Uruguay +598" ], [ "uz", "Uzbekistan +998" ],
[ "vu", "Vanuatu +678" ], [ "va", "Vatican City +379" ], [ "ve", "Venezuela +58" ], [ "vn", "Vietnam +84" ],[ "vi", "Virgin Islands +1" ],
[ "wf", "Wallis and Futuna +681" ], [ "ye", "Yemen +967" ],
[ "zr", "Zaire +243" ], [ "zm", "Zambia +260" ], [ "zw", "Zimbabwe +263" ]
];
var _arr_country_top = [
[ "us", "United States +1" ],[ "hk", "Hong Kong +852" ],[ "gb", "United Kingdom +44" ],
[ "sg", "Singapore +65" ], [ "ca", "Canada +1" ],[ "au", "Australia +61" ]
];
/**
* 添加国家选项
*
* @param selectObj select的jQuery对象
*/
function _addCountryOptions(selectObj) {
var countryTopLength = _arr_country_top.length;
var countryLength = _arr_country.length;
var optionsHtml = '<option value="">-select-</optioin>';
for (var i = 0; i < countryTopLength; i++) {
var adj = _arr_country_top[i][1]; //获取国家信息
var last = adj.substr(adj.lastIndexOf("+")); //截取区号
var qq = adj.lastIndexOf("+");
var str = adj.substr(0, qq - 3); //截取国家名称
optionsHtml += '<option value="' + _arr_country_top[i][0] + '">' + str + '</option>';
}
for (var i = 0; i < countryLength; i++) {
var adj = _arr_country[i][1]; //获取国家信息
var last = adj.substr(adj.lastIndexOf("+")); //截取区号
var qq = adj.lastIndexOf("+");
var str = adj.substr(0, qq - 3); //截取国家名称
optionsHtml += '<option value="' + _arr_country[i][0] + '">' + str + '</option>';
}
selectObj.html(optionsHtml);
}
/**
* 显示国家选择框
*
* @param formObj 触发显示事件的表单的jQuery对象
*/
function _showCountrySelect(formObj) {
if (countrySelectTool) {
countrySelectTool.init({
$countryListDiv : formObj.find('div.js-ft-form-country-show-div'),
// $fadeDiv : $('div.js-ft-form-country-fade'),
selectCode : formObj.find('input[name="country"]').val(),
selectAfterFunction : function(res) {
_selectCountry(formObj, res.country_code, res.country_name, res.country_areacode);
}
});
countrySelectTool.showCountryList();
}
}
/**
* 选中国家后赋予表单数据
*
* @param formObj 触发显示事件的表单的jQuery对象
* @param countryCode 国家编码
* @param countryName 国家名称
* @param countryAreacode 电话区号
*/
function _selectCountry(formObj, countryCode, countryName, countryAreacode) {
formObj.find('div.js-ft-form-country-show').text(countryName);
formObj.find('div.js-ft-form-areacode-show').text('+' + countryAreacode);
formObj.find('div.js-ft-form-areacode-show').show();
formObj.find('input[name="country"]').val(countryCode);
formObj.find('input[name="areacode"]').val(countryAreacode);
}
/**
* FT表单验证
*
* @param formObj FT表单jQuery对象
* @param successFunction 验证成功后调用的方法
* @param failFunction 验证失败后调用的方法,传入的参数是错误信息
*/
function _checkFtForm(formObj, successFunction, failFunction) {
var name = formObj.find('input[name=name]').val().trim();
var email = formObj.find('input[name=email]').val().trim();
var country = null;
if (formObj.find('select[name=country]').length > 0) {
country = formObj.find('select[name=country]').val().trim();
} else {
country = formObj.find('input[name=country]').val().trim();
}
var areacode = formObj.find('input[name=areacode]').val().trim();
var tel = formObj.find('input[name=tel]').val().trim();
var errMsg = '';
var formAction = formObj.attr('action');
var formQueryString = formAction.split('?')[1];
var differentiate = _getQueryString(formQueryString, "differentiate");
var website = _getQueryString(formQueryString, "website");
var language = _getQueryString(formQueryString, "language");
if (differentiate.indexOf("zh") >= 0 || website.indexOf("zh-hans") >= 0 || website.indexOf("lingceed") >= 0
|| website.indexOf("mfc") >= 0 || language.indexOf("zh-hans") >= 0 || website.indexOf("mandarinkidz") >= 0) {
// 中文网站,要用中文提示
if (name.length <= 0) {
errMsg += '请填写您的姓名\n';
}
if (email.length <= 0) {
errMsg += '请填写您的邮箱\n';
} else if (!_isEmail(email)) {
errMsg += '请填写有效的邮箱\n';
}
if (country.length < 1) {
errMsg += '请选择您所在的国家或地区\n';
}
if (areacode.length > 0 && areacode != "area code" && !_isValidPhone(areacode)) {
errMsg += '请填写有效的区号\n';
}
if (tel.length <= 0) {
errMsg += '请填写您的电话号码\n';
} else if (!_isValidPhone(tel)) {
errMsg += '请填写有效的电话号码\n';
}
} else if (differentiate.indexOf("en") >= 0) {
if (name.length <= 0) {
errMsg += 'Please fill in your name.\n';
}
if (email.length <= 0) {
errMsg += 'Please fill in your e-mail.\n';
} else if (!_isEmail(email)) {
errMsg += 'Please fill in a valid e-mail.\n';
}
if (country.length < 1) {
errMsg += 'Please select a country or region.\n';
}
if (areacode.length > 0 && areacode != "area code" && !_isValidPhone(areacode)) {
errMsg += 'Please fill in a valid area code.\n';
}
if (tel.length <= 0) {
errMsg += 'Please fill in your tel.\n';
} else if (!_isValidPhone(tel)) {
errMsg += 'Please fill in a valid telephone number.\n';
}
} else {
if (name.length <= 0) {
errMsg += 'Please fill in your name.\n';
}
if (email.length <= 0) {
errMsg += 'Please fill in your e-mail.\n';
} else if (!_isEmail(email)) {
errMsg += 'Please fill in a valid e-mail.\n';
}
if (country.length < 1) {
errMsg += 'Please select a country or region.\n';
}
if (areacode.length > 0 && areacode != "area code" && !_isValidPhone(areacode)) {
errMsg += 'Please fill in a valid area code.\n';
}
if (tel.length <= 0) {
errMsg += 'Please fill in your tel.\n';
} else if (!_isValidPhone(tel)) {
errMsg += 'Please fill in a valid telephone number.\n';
}
}
if (errMsg.length > 0) {
if (typeof failFunction == 'function') {
failFunction(errMsg);
}
} else {
if (typeof successFunction == 'function') {
successFunction();
}
}
}
/**
* FT表单验证(验证码页面)
*
* @param formObj FT表单jQuery对象
* @param successFunction 验证成功后调用的方法
* @param failFunction 验证失败后调用的方法,传入的参数是错误信息
*/
function _checkCodeFtForm(formObj, successFunction, failFunction) {
var email = formObj.find('input[name=email]').val().trim();
var areacode = formObj.find('input[name=areacode]').val().trim();
var tel = formObj.find('input[name=tel]').val().trim();
var verify = formObj.find('input[name=verify]').val().trim();
var errMsg = '';
if (email.length > 0 && !_isEmail(email)) {
errMsg += 'Please fill in a valid e-mail.\n';
}
if (areacode.length > 0 && areacode != "area code" && !_isValidPhone(areacode)) {
errMsg += 'Please fill in a valid area code.\n';
}
if (tel.length > 0 && !_isValidPhone(tel)) {
errMsg += 'Please fill in a valid telephone number.\n';
}
if (verify.length <= 0) {
errMsg += 'Please enter the verification code.';
} else if (verify.length != 4) {
errMsg += 'The verification code is incorrect. Please try again.\n';
}
if (errMsg.length > 0) {
if (typeof failFunction == 'function') {
failFunction(errMsg);
}
} else {
if (typeof successFunction == 'function') {
successFunction();
}
}
}
/**
* 提交FT表单
*
* @param formObj FT表单jQuery对象
*/
function _submitFtForm(formObj) {
var name = formObj.find('input[name=name]').val().trim();
if(name != null && name.indexOf("not_submit") != -1) {
console.log("日志已记录成功");
return;
}
var formAction = formObj.attr('action');
var formQueryString = formAction.split('?')[1];
formObj.attr('action', _ft_form_url + '?' + formQueryString);
formObj.submit();
}
/**
* 提交FT失败表单<br>
* 验证失败的也需要提交,如果全空就提交到未处理lead列表,否则都提交到正常lead列表
*
* @param formObj FT表单jQuery对象
*/
function _submitFailedFtForm(formObj) {
var formAction = formObj.attr('action');
var formQueryString = formAction.split('?')[1];
var name = formObj.find('input[name=name]').val().trim();
if(name != null && name.indexOf("not_submit") != -1) {
console.log("日志已记录成功");
return;
}
var email = formObj.find('input[name=email]').val().trim();
var country = null;
if (formObj.find('select[name=country]').length > 0) {
country = formObj.find('select[name=country]').val().trim();
} else {
country = formObj.find('input[name=country]').val().trim();
}
var areacode = formObj.find('input[name=areacode]').val().trim();
var tel = formObj.find('input[name=tel]').val().trim();
var type = _getQueryString(formQueryString, 'type');
var domain = _getQueryString(formQueryString, 'domain');
var name2 = _getQueryString(formQueryString, 'name2');
var fromType = '3';
var leadsId = '';
if (formObj.find('input[name=id]').length > 0) {
leadsId = formObj.find('input[name=id]').val().trim();
}
var leadGuid = '';
if (formObj.find('input[name=leadGuid]').length > 0) {
leadGuid = formObj.find('input[name=leadGuid]').val().trim();
}
var userAccessId = '';
if (formObj.find('input[name=userAccessId]').length > 0) {
userAccessId = formObj.find('input[name=userAccessId]').val().trim();
}
var submitUrl = _ft_form_url;
if (leadsId.length == 0 && name.length == 0 && email.length == 0 && country.length == 0 && areacode.length == 0
&& tel.length == 0) {
// 如果表单内容都为空,那么提交到未处理lead
submitUrl = _ft_fail_form_url;
}
$.ajax({
url : submitUrl,
data : {
id : leadsId,
name : name,
email : email,
country : country,
areacode : areacode,
tel : tel,
type : type,
domain : domain,
name2 : name2,
fromType : fromType,
leadGuid : leadGuid,
userAccessId : userAccessId,
isFailed:true
},
dataType : 'jsonp',
success : function(data) {
// do nothing
}
});
}
/**
* 获取URL参数中的参数值
*
* @param urlParam URL内容
* @param paramName 参数名
* @returns 参数值
*/
function _getQueryString(urlParam, paramName) {
var paramValue = "";
var isFound = false;
if (urlParam.length > 0 && urlParam.indexOf("=") > 1) {
var arrSource = unescape(urlParam).substring(0, urlParam.length).split("&");
var i = 0;
while (i < arrSource.length && !isFound) {
if (arrSource[i].indexOf("=") > 0) {
if (arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase()) {
paramValue = arrSource[i].split("=")[1];
isFound = true;
}
}
i++;
}
}
return paramValue;
}
/**
* 是否合法邮箱地址
*
* @param A 邮箱地址
*/
function _isEmail(A) {
if (A.length > 100) {
return false;
}
/* var B = "^([0-9a-zA-Z]+([_]|[.]|[0-9a-zA-Z-])*)@([a-zA-Z0-9-]+[.])+(net|NET|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT|biz|BIZ|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw|AD|AE|AF|AG|AI|AL|AM|AN|AO|AQ|AR|AS|AT|AU|AW|AX|AZ|BA|BB|BD|BE|BF|BG|BH|BI|BJ|BM|BN|BO|BR|BS|BT|BV|BW|BY|BZ|CA|CC|CD|CF|CG|CH|CI|CK|CL|CM|CN|CO|CR|CS|CU|CV|CX|CY|CZ|DE|DJ|DK|DM|DO|DZ|EC|EE|EG|EH|ER|ES|ET|FI|FJ|FK|FM|FO|FR|GA|GB|GD|GE|GF|GG|GH|GI|GL|GM|GN|GP|GQ|GR|GS|GT|GU|GW|GY|HK|HM|HN|HR|HT|HU|ID|IE|IL|IM|IN|IO|IQ|IR|IS|IT|JE|JM|JO|JP|KE|KG|KH|KI|KM|KN|KP|KR|KW|KY|KZ|LA|LB|LC|LI|LK|LR|LS|LT|LU|LV|LY|MA|MC|MD|MG|MH|MK|ML|MM|MN|MO|MP|MQ|MR|MS|MT|MU|MV|MW|MX|MY|MZ|NA|NC|NE|NF|NG|NI|NL|NO|NP|NR|NU|NZ|OM|PA|PE|PF|PG|PH|PK|PL|PM|PN|PR|PS|PT|PW|PY|QA|RE|RO|RU|RW|SA|SB|SC|SD|SE|SG|SH|SI|SJ|SK|SL|SM|SN|SO|SR|ST|SV|SY|SZ|TC|TD|TF|TG|TH|TJ|TK|TL|TM|TN|TO|TP|TR|TT|TV|TW|TZ|UA|UG|UK|UM|US|UY|UZ|VA|VC|VE|VG|VI|VN|VU|WF|WS|YE|YT|YU|ZA|ZM|ZW|info|pro|name|museum|coop|aero|ac|idv|zr|su|nt|ev|cq|eu|yr|me|t|INFO|PRO|NAME|MUSEUM|COOP|AERO|AC|IDV|ZR|SU|NT|EV|CQ|EU|YR|ME|T)$";
var C = new RegExp(B);
if (A.search(C) != -1) {
return true;
} else {
return false;
}*/
if (validateEmail(A)) {
return true;
}else {
return false;
}
}
function validateEmail(email) {
var re = /^[0-9A-Za-z]+([-_.][0-9A-Za-z]+)*@([A-Za-z0-9-]+[.])+[A-Za-zd]{2,}$/;
// alert("新的邮箱验证FT:"+re.test(email));
return re.test(email);
}
/**
* 是否合法电话
*
* @param A 电话号码
*/
function _isValidPhone(A) {
if (A.length > 0) {
var B = A.split('');
if (B.length > 0) {
for (var i = 0; i < B.length; i++) {
if (!(B[i] == '0' || B[i] == '1' || B[i] == '2' || B[i] == '3' || B[i] == '4' || B[i] == '5'
|| B[i] == '6' || B[i] == '7' || B[i] == '8' || B[i] == '9' || B[i] == '-' || B[i] == '+'
|| B[i] == '(' || B[i] == ')')) {
return false;
}
}
return true;
} else {
return false;
}
} else {
return false;
}
}
/**
* 为防止uuid.js没有正常加载,这里实现一个简单的创建uuid的方法,来备用
*/
function _generateUUID() {
var d = new Date().getTime();
var uuid = 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c == 'x' ? r : (r & 0x7 | 0x8)).toString(16);
});
return uuid;
}
/**
* 对字符串进行base64编码的方法
*/
function _Base64() {
var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
this.encode = function(input) {
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
input = _utf8_encode(input);
while (i < input.length) {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output + _keyStr.charAt(enc1) + _keyStr.charAt(enc2) + _keyStr.charAt(enc3)
+ _keyStr.charAt(enc4);
}
return output;
};
_utf8_encode = function(string) {
string = string.replace(/\r\n/g, "\n");
var utftext = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
} else if ((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
} else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
};
}
eclFtFormTool.init();
this.eclFtFormTool = eclFtFormTool;
// 点击主菜单的时候,关闭国家选择弹出框
this._mainMenuClickAfter = function() {
if (countrySelectTool) {
countrySelectTool.closeCountryList();
}
}
}).call(this);
// 下面是关于表单补充提交
var _form_log_url = 'https://www.dongyu.com/ecladm/form_record.php'; // FT表单提交日志地址
if (window.location.host.indexOf('localhost') >= 0) {
_form_log_url = 'http://localhost/form_record.php';
}
if (window.location.host.indexOf('test-') >= 0) {
_form_log_url = 'https://test-www.echineselearning.biz/ecladm/form_record.php';
}
/**
* 对字符串进行base64编码的方法
*/
function base64() {
var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
this.encode = function(input) {
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
input = _utf8_encode(input);
while (i < input.length) {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output + _keyStr.charAt(enc1) + _keyStr.charAt(enc2) + _keyStr.charAt(enc3)
+ _keyStr.charAt(enc4);
}
return output;
};
_utf8_encode = function(string) {
string = string.replace(/\r\n/g, "\n");
var utftext = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
} else if ((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
} else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
};
}
/**
* 提交表单日志
*
* @param formObj FT表单jQuery对象
* @param formCheck 表单是否验证通过(ok|fail)
* @param completeFunction 日志提交完成后调用的方法
*/
function supplementFormLog(formType, formUrl, formObj, other, completeFunction) {
// var formAction = formObj.attr('action');
// var formQueryString = formAction.split('?')[1];
// lead表单的other为host和normalLead,以json的格式"{'host':'','normalLead':'true'}"
// var host = window.location.host;
// var normalLead = formCheck == 'ok' ? 'true' : 'false';
var b = new base64();
// console.log(serializeObject(formObj));
var formDate = JSON.stringify(serializeObject(formObj));
formDate = b.encode(formDate);
$.ajax({
type : "get",
url : _form_log_url,
timeout : 3000, // 超时时间设置,单位毫秒
data : {
formType : formType,
formDate : formDate,
formUrl : formUrl,
other : other
},
dataType : 'jsonp',
jsonp : 'callback',
complete : function(XMLHttpRequest, status) {
if (typeof completeFunction == 'function') {
completeFunction();
}
}
});
}
function getUrlParamString(urlParam,paramName) {
paramValue = "";
isFound = false;
if (urlParam.length > 0 && urlParam.indexOf("=") > 1){
arrSource = unescape(urlParam).substring(0,urlParam.length).split("&");
var i = 0;
while (i < arrSource.length && !isFound){
if (arrSource[i].indexOf("=") > 0){
if(arrSource[i].split("=")[0].toLowerCase()== paramName.toLowerCase()){
paramValue = arrSource[i].split("=")[1];
isFound = true;
}
}
i++;
}
}
return paramValue;
}
function serializeObject(obj)
{
var o = {};
var a = obj.serializeArray();
$.each(a, function() {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
var url = obj.attr("action");
var type = getUrlParamString(url,"type");
var domain = getUrlParamString(url,"domain");
o.type = type;
o.domain = domain;
return o;
};
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
function getXhr() {
var httpreq = null;
//由于涉及跨域问题,这里优先使用ActiveXObject
if (window.ActiveXObject) {
try {
httpreq = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
httpreq = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
}
}
} else if (window.XMLHttpRequest) {
httpreq = new XMLHttpRequest();
}
return httpreq;
}
function checkIsConnect(url) {
var xmlhttp = getXhr();
xmlhttp.open("GET", url, false);
try {
xmlhttp.send(null);
} catch (e) {
return false;
}
if (xmlhttp.readyState == 4) {
//readyStatud == 4 表示与服务端完成交互,即可以连接
return true;
}
return false;
}