var Jiagle = Jiagle || {};
Jiagle.config = Jiagle.config || {};
var j = j || {};
var clab_tracker_fake = {
ready: function () {},
setEnableAutoTrackExitPage: function () {}
};
var clab_tracker = clab_tracker || clab_tracker_fake;
j.log = function () {
console.log.apply(this, arguments);
};
j.user = {
id: 0, // 用户id
usertype: 0, // 用户账号类型 buyer|supplier|designer
username: 0, // 用户账号名
collectProduct: [], // 收藏产品 id 列表
collectSupplier: [], // 收藏厂商 id 列表
data: {},
isLogin: function () {
return this.id > 0;
},
loadLoginStatus: function (fn) {
var that = this;
/* 顶部登录信息显示 js 脚本 */
$.ajax({
url: "",
type: "post",
dataType: 'json',
data: {
option: "com_jiudian",
task: "home.getUserLoginInfo",
isajax: "1",
},
success: function (obj) {
if (obj.userInfo) $("#user-login-info").html(obj.userInfo);
j.user = obj.user;
j.user.isLogin = that.isLogin;
j.user.loadLoginStatus = that.loadLoginStatus;
Jiagle.config.checklogin = true;
if (j.user.isLogin()) {
Jiagle.config.isLogin = true;
if (j.user.usertype === 'buyer') {
$('.j-nav-supplier').hide();
$('.j-nav-buyer').find('.txtk a').eq(0).hide();
$('.top2_ztc .zh_nav a').each(function (index, el) {
el = $(el);
if (index == 0) {
el.hide();
} else {
el.mouseover();
}
});
} else {
$('.j-nav-buyer').hide();
$('.j-nav-supplier').find('.txtk a').eq(0).hide();
$('.top2_ztc .zh_nav a').each(function (index, el) {
el = $(el);
if (index == 1) {
el.hide();
} else {
el.mouseover();
}
});
}
clab_tracker.ready(function(){
this.push({"pageType":"web"});
this.track("open_page", {
"identityType": "mobile",
"identityValue": j.user.data.mobile,
"identityType2": "email",
"identityValue2": j.user.data.email
});
});
}
if (j.ready.canDo) {
j.ready.canDo = false;
j.ready.fn.forEach(function (fn) {
fn();
});
delete j.ready.fn;
}
if (fn) fn();
},
error: function () {
if (j.ready.canDo) {
j.ready.canDo = false;
j.ready.fn.forEach(function (fn) {
fn();
});
delete j.ready.fn;
}
}
});
}
};
/**
* 错误码对应消息中英文对照 var msg = j.errorCode.getErrorMsg("30001");
* j.errorCode.thisSite 中文站 cn 英文站 en
*/
j.errorCode = {
'thisSite': 'cn',
'30001': ['参数不能为空!', 'Parameter cannot be null.'],
'30002': ['用户名不可以不填!', 'The user name cannot be left blank.'],
'300021': ['用户名格式错误!', 'User name format error.'],
'30003': ['密码不可以为不填!', 'Password cannot be left blank.'],
'30004': ['账号信息已存在,请修改!', 'The account information already exists.'],
'30050': ['请填写手机号码!', 'Please fill in your mobile phone number.'],
'30051': ['手机号已被注册!', 'The phone number has been registered.'],
'30100': ['验证码不能为空!', 'The verification code cannot be empty.'],
'30101': ['图片验证码不正确!', 'The picture verification code is not correct.'],
'30200': ['验证码发送失败!', 'Verification code sending failed.'],
'30201': ['验证码类型错误!', 'Verification code type error.'],
'302001': ['验证码发送失败。', 'Verification code sending failed!'],
'302002': ['验证码发送失败。', 'Verification code sending failed!!'],
'40006': ['您的手机号尚未注册', 'The phone number not been registered.'],
'300020': ['手机号格式错误!', 'The phone number format error.'],
getErrorMsg: function (code) {
if (this.thisSite == 'en') {
return this[code][1];
} else {
return this[code][0];
}
}
}
j.ready = function (fn) {
if (j.ready.canDo) {
j.ready.fn.push(fn);
} else {
fn();
}
}
j.ready.fn = [];
j.ready.canDo = true;
/**
* 用户登录,如果是已登陆状态则直接执行成功回调,否则弹出登录弹窗
*/
j.login = function (args) {
args = args || {};
var success = args.success || function () { //用户为已登陆状态后的回调
};
var cancel = args.cancel || function () { //用户关闭登录框选择不登录时的回调
return true;
};
var beforeLogin = args.beforeLogin || function () { //弹出登录框前回调
};
var auto = args.auto || true; //未登录时自动弹出登录窗口,默认为true,自动弹出登录,为false且未登录时不自动弹出登录窗口,并不执行任何回调,为false且已登录时调用success
if (j.user.isLogin()) {
beforeLogin();
success();
} else if (auto) {
beforeLogin();
location.href = '/login/';
}
};
/**
* 提示框
*/
j.alert = function (args) {
args = args || {};
if (typeof args === 'string' || typeof args === 'number') { //参数为字符串时,直接弹出内容
args = {'msg': args};
}
var msg = args.msg || '';
var ok = args.ok || function () {
return true;
};
var okText = args.okText || '确定';
var width = args.width || 400; //弹出层宽度,默认为400px
var height = args.height || 'auto'; //弹出层高度,默认自适应
alert(args.msg);
ok();
return;
var v_content = $('
');
var v_msg = $('');
v_msg.text(msg);
v_content.append(v_msg);
var v_btn = $('');
v_btn.text(okText);
v_content.append(v_btn);
var modal = j.modal({
'position': 'fixed',
'content': v_content,
'width': width,
'height': height,
'padding': '80px 40px 40px',
'close': function () {
ok();
return true;
}
});
v_btn.click(function () {
ok();
modal.close();
});
};
/**
* 确认框
*/
j.confirm = function (args) {
if (typeof args === 'string' || typeof args === 'number') { //参数为字符串时,直接弹出内容
args = {'msg': args};
}
args = args || {};
var msg = args.msg || '';
var ok = args.ok || function () {
return true;
};
var okText = args.okText || '确定';
var cancel = args.cancel || function () {
return true;
};
var cancelText = args.okText || '取消';
var width = args.width || 600; //弹出层宽度,默认为600px
var height = args.height || 'auto'; //弹出层高度,默认自适应
if (confirm(args.msg)) {
ok();
} else {
cancel();
}
return;
var v_content = $('');
var v_msg = $('');
v_msg.text(msg);
v_content.append(v_msg);
var v_btn_ok = $('');
var v_btn_cancel = $('');
v_btn_ok.text(okText);
v_btn_cancel.text(cancelText);
v_content.append(v_btn_ok);
v_content.append(v_btn_cancel);
var modal = j.modal({
'position': 'fixed',
'content': v_content,
'width': width,
'height': height,
'padding': '80px 40px 40px',
'close': function () {
cancel();
return true;
}
});
v_btn_ok.click(function () {
ok();
modal.close();
});
v_btn_cancel.click(function () {
cancel();
modal.close();
});
};
/**
* 模态框
* 返回modal对象,支持方法
* show:当初始参数hidden为true时,可使用show方法显示
* close:关闭并销毁模态框,不触发close事件
*/
j.modal = function (args) {
args = args || {};
//可用参数 start
var content = args.content || ''; //弹出层内容,默认为空
var padding = args.padding || '80px 80px 40px'; //弹出层底框内边距,默认80px 80px 60px
var hidden = args.hidden || false; //默认显示,为true时需要手工调用show方法
var blank = args.blank || false; //为true时不需要添加背景以及关闭按钮,默认添加
var position = args.position || 'absolute'; //弹出层定位,默认absolute,可使用'fixed'
var width = args.width || 900; //弹出层宽度,默认为900px
var height = args.height || 'auto';//弹出层高度,默认适应内容,fixed时请固定高度
var vertical = args.vertical || 100; //弹出层上下位置,仅在'position'为'absolute'时生效,'fixed'时居中
var background = args.background || '#fff'; //弹出层的背景色
var title = args.title || false; //弹出层的标题
var close = args.close || function () {
return true; //关闭模态框时的回调,返回true时会关闭,返回false时无法关闭
};
var callback = args.callback|| function () {
return true;
};
var mask = {};
args.mask = args.mask || {};
mask.disable = args.mask.disable || false; //是否需要遮罩层
mask.background = args.mask.background || 'rgba(0,0,0,0.3)'; //遮罩层层的背景色
mask.close = args.mask.close || false; //点击遮罩是否可以关闭弹窗,默认不可以关闭
var onShow = args.onShow || false; //显示时回调
//可用参数 end
var v_modal = $('');
var zIndex = j.modal.default["z-index"];
//初始化模态框
v_modal.css({
'width': '100%',
'height': $('body').height(),
'position': 'absolute',
'padding': 0,
'margin': 0,
'top': 0,
'left': 0,
'z-index': zIndex
});
if (mask.disable) {
} else {
//初始化遮罩
var v_mask = $('');
v_mask.css({
'width': '100%',
'height': '100%',
'position': position,
'padding': 0,
'margin': 0,
'top': 0,
'left': 0,
'z-index': zIndex + 1,
'background-color': mask.background
});
v_modal.append(v_mask);
if (mask.close) {
v_mask.click(f_close);
}
}
if (blank) {
v_modal.append(content);
} else {
//初始化背景
var v_content = $('');
v_content.css({
'width': width,
'height': height,
'padding': padding,
'position': position,
'z-index': zIndex + 2,
'margin': 'auto',
'left': 0,
'right': 0,
'background-color': background,
});
if (position === 'absolute') {
v_content.css({'top': vertical + $(document).scrollTop()})
} else {
v_content.css({'top': 0, 'bottom': 0})
}
v_modal.append(v_content);
//初始化关闭按钮
var v_close = $('');
v_close.css({
'position': 'absolute',
'background': 'url(/static/furniture/images/sp_close.png) no-repeat',
'width': 34,
'height': 34,
'right': 20,
'top': 20,
'cursor': 'pointer'
});
v_close.hover(function () {
v_close.css({
'background': 'url(/static/furniture/images/sp_close_on.png) no-repeat'
});
}, function () {
v_close.css({
'background': 'url(/static/furniture/images/sp_close.png) no-repeat'
});
});
v_close.click(f_close);
v_content.append(v_close);
if (title) {
var v_title = $('' + title + '
');
v_content.append(v_title);
}
//添加内容
v_content.append(content);
}
if (!hidden) {
f_show();
}
function f_show() {
$('body').append(v_modal);
f_resize();
if (onShow && typeof onShow === 'function') {
onShow();
}
callback();
}
function f_close() {
if (close()) {
v_modal.remove();
}
}
function f_resize() {
if (blank) return;
if (height === 'auto' && position === 'fixed') {
v_content.height(content.height());
}
}
return {
'close': function () {
v_modal.remove();
},
'show': f_show
};
};
j.modal.default = {
'z-index': 200
};
/**
* 表单验证
*/
j.check = {};
j.check.email = function (value) {
return /^.+@.+$/.test($.trim(value));
};
j.check.mobile = function (value) {
return /^1[0-9]{10}$/.test($.trim(value));
};
j.check.required = function (value) {
return $.trim(value).length > 0;
};
j.check.password = function (value) {
if (!/[0-9]/.test(value)) return false;
if (!/[a-z]/.test(value)) return false;
if (!/[A-Z]/.test(value)) return false;
return true;
};
j.check.username = function (value) {
if (!/[A-Za-z0-9]/.test(value)) return false;
if (value.length <= 6) return false;
return true;
};
j.check.radio = function (el) {
if (el.is(':checked')) {
return true;
}else {
return false;
}
};
/**
* 表单提交
* 输入类型必须是表单
* 返回类型必须是json
*/
j.submit = function (args) {
args = args || {};
var form = args.form || $(''); //需要提交的表单对象
var data = args.data || false;
var type, url;
type = args.type || form.attr('method'); //get还是post,默认使用表单的配置
url = args.url || form.attr('action') || location.href; //提交的url,默认使用form的action,为空使用当前链接
var timestamp = Date.parse(new Date());
if (url.indexOf("?") != -1){
url = url+'&'+timestamp;
}else {
url = url+'?'+timestamp;
}
var loading = args.loading !== false; //是否需要显示加载动画
var dataType = 'json'; //返回类型json,不可选
var success = args.success || function (data) { //成功的回调,会回传data部分的数据
};
var failure = args.failure || false; //后台返回,但处理结果code非200时的回调,会回传后台返回的全部数据
var code = args.code || false; //所有的错误代码
var error = args.error || function () { //ajax请求失败的回调,以jquery的ajax error回调为准
alert('服务器异常,请联系客服处理('+(new Date).toString()+'|('+data.status+'))');
if (loading) {
loading.close();
}
};
if (loading) {
loading = j.loading();
}
for (var i in data) {
var hidden = $('');
hidden.val(data[i]);
hidden.attr('name', i);
form.append(hidden);
}
data = form.serialize();
$.ajax({
'url': url,
'type': type,
'dataType': dataType,
'data': data,
'error': error,
'success': function (data) {
if (data.code === 200) {
success(data.data);
} else {
if (data.code == 628848) {
alert(data.msg);
} else if (code && code[data.code]) {
alert(code[data.code]);
} else if (failure) {
failure(data);
} else if (data.msg) {
alert(data.msg);
}
}
if (loading) {
loading.close();
}
}
})
};
/**
*
*/
j.choose = function (args) {
args = args || {};
var target = args.target; //需要添加选择功能的按钮
var file = args.file || true; //是否支持file input的功能
var drag = args.drag || true; //是否支持拖拽上传功能
var auto = args.auto || true; //是否选择完成后自动上传到服务器
var maxSize = args.maxSize || 4194304;//最大上传,默认4M
var type = args.type || 'image'; //上传类型,默认为image图片,可选video上传视频
var success = args.success || function (path) {//上传成功回调,回传图片地址
console.log(arguments);
};
var failure = args.failure || function (data) {
if (data.code == 14002){
alert('上传图片格式不正确')
}else if (data.code == 14003){
alert('上传图片不得超过4M')
}else {
alert('上传图片失败')
}
};
var error = args.error || function () {//网络或其他错误回调
console.log(arguments);
};
var noDrag = args.noDrag || function () {//浏览器不支持拖拽时的回调
};
var draggable = j.support.draggable();
if (!draggable) {
noDrag();
}
var images;
if (file) {
var v_file = $('');
target.click(function () {
v_file.click();
});
v_file.change(function () {
images = v_file[0].files;
doUpload();
});
}
if (drag) {
target.on({
'drop': function (e) {
images = e.originalEvent.dataTransfer.files;
doUpload();
return false;
},
'dragenter': function () {
},
'dragover': function () {
return false;
},
'dragleave': function () {
}
});
}
function doUpload() {
if (images.length === 0) {
failure({'code': 14001});
return false;
}
if (type === 'video') {
upload();
return;
}
if (images[0].type.indexOf('image') === -1) {
failure({'code': 14002});
return false;
}
if (images[0].size > maxSize) {
failure({'code': 14003});
return false;
}
if (auto) {
upload();
}
}
function upload() {
if (type === 'video') {
j.uploadVideo({
'video': images[0],
'input': v_file,
'success': success,
'failure': failure,
'error': error
});
} else if (type === 'image') {
j.uploadImage({
'image': images[0],
'input': v_file,
'success': success,
'failure': failure,
'error': error
});
}else if(type === 'front_page_image'){
j.frontPageUploadImage({
'image': images[0],
'input': v_file,
'success': success,
'failure': failure,
'error': error
});
}
}
return {
'upload': upload
};
};
j.support = {};
/**
* 判断浏览器是否支持拖拽
* @returns {boolean}
*/
j.support.draggable = function () {
var div = document.createElement('div');
var flag = ('draggable' in div) || ('ondragstart' in div && 'ondrop' in div);
j.supportDraggable = function () {
return flag;
};
return flag;
};
/**
* 进度条
*/
j.progressBar = function () {
var content = $('');
var bar = $('');
var value = $('0%
');
bar.append(value);
content.append(bar);
var modal = j.modal({
'blank': true,
'content': content,
'hidden': true
});
function show() {
modal.show();
}
function destroy() {
modal.close();
}
function progress(loaded, size) {
var pro = parseInt(loaded / size * 100) + '%';
if (pro > 100) pro = 100;
bar.width(pro);
value.text(pro);
}
return {
'show': show,
'destroy': destroy,
'progress': progress
};
};
/**
* 前台单图上传
*/
j.frontPageUploadImage = function (args) {
args = args || {};
var image = args.image || false;//需要上传的图片,image或者input二选一
var input = args.input || false;//需要上传的图片,image或者input二选一
var data = args.data || false;
var success = args.success || false;
var failure = args.failure || false;
var error = args.error || false;
if (XMLHttpRequest && image) {
var progressBar = j.progressBar();
var fd = new FormData();
var xhr = new XMLHttpRequest();
fd.append('task', 'upload.image');
fd.append('option', 'com_jiudian');
fd.append('image', image);
if (data) {
for (var i in data) {
fd.append(i, data[i]);
}
}
xhr.upload.addEventListener("progress", uploadProgress, false);
xhr.addEventListener("load", uploadComplete, false);
xhr.addEventListener("error", uploadFailed, false);
xhr.addEventListener("abort", uploadCanceled, false);
xhr.open("POST", location.href);
xhr.send(fd);
progressBar.show();
function uploadProgress(e) {
if (e.lengthComputable) {
var loaded = e.loaded;
progressBar.progress(loaded, image.size);
}
else {
progressBar.destroy();
}
}
function uploadComplete(e) {
progressBar.destroy();
try {
var response = JSON.parse(e.target.responseText);
if (response.code == 200) {
if (success) success(response.data);
} else {
if (failure) failure(response);
}
} catch (e) {
if (error) error(e);
}
}
function uploadFailed(e) {
progressBar.destroy();
if (error) error(e);
}
function uploadCanceled(e) {
progressBar.destroy();
if (error) error(e);
}
} else {
var form = $('')
form.append(input);
form.append('');
form.append('');
if (data) {
for (var i in data) {
form.append('');
}
}
form.ajaxSubmit(function (data) {
data = JSON.parse(data);
if (data.code == 200) {
success(data.data);
} else {
failure(data);
}
});
}
};
/**
* 单图上传
*/
j.uploadImage = function (args) {
args = args || {};
var image = args.image || false;//需要上传的图片,image或者input二选一
var input = args.input || false;//需要上传的图片,image或者input二选一
var data = args.data || false;
var success = args.success || false;
var failure = args.failure || false;
var error = args.error || false;
if (XMLHttpRequest && image) {
var progressBar = j.progressBar();
var fd = new FormData();
var xhr = new XMLHttpRequest();
fd.append('task', 'upload.image');
fd.append('option', 'com_jiudian_ucenter');
fd.append('image', image);
if (data) {
for (var i in data) {
fd.append(i, data[i]);
}
}
xhr.upload.addEventListener("progress", uploadProgress, false);
xhr.addEventListener("load", uploadComplete, false);
xhr.addEventListener("error", uploadFailed, false);
xhr.addEventListener("abort", uploadCanceled, false);
xhr.open("POST", location.href);
xhr.send(fd);
progressBar.show();
function uploadProgress(e) {
if (e.lengthComputable) {
var loaded = e.loaded;
progressBar.progress(loaded, image.size);
}
else {
progressBar.destroy();
}
}
function uploadComplete(e) {
progressBar.destroy();
try {
var response = JSON.parse(e.target.responseText);
if (response.code == 200) {
if (success) success(response.data);
} else {
if (failure) failure(response);
}
} catch (e) {
if (error) error(e);
}
}
function uploadFailed(e) {
progressBar.destroy();
if (error) error(e);
}
function uploadCanceled(e) {
progressBar.destroy();
if (error) error(e);
}
} else {
var form = $('')
form.append(input);
form.append('');
form.append('');
if (data) {
for (var i in data) {
form.append('');
}
}
form.ajaxSubmit(function (data) {
data = JSON.parse(data);
if (data.code == 200) {
success(data.data);
} else {
failure(data);
}
});
}
};
/**
* 弹出警告
*/
j.warning = function (args) {
args = args || {};
var target = args.target; //需要报错的目标对象,必填
if (!target) return;
var msg = args.msg || ''; //报错内容
var width = args.width || null; //错误框宽度
var focus = args.focus || false; //获得焦点
var speed = args.speed === 0 ? 0 : (args.speed || 5000); //错误信息的保留时间,默认5秒,为0时不消失
var left = args.left || 432;
var top = args.top || -1;
var lineHeight =args.lineHeight || 62;
var height =args.height || 62;
var warning = $('' + msg + '
');
warning.css({
'top': top,
'left': left,
'width': width,
'line-height':lineHeight,
'height':height
}
);
target.after(warning);
if (focus) {
if (target.is('input,select,textarea')) {
target.focus();
} else {
target.find('input,select,textarea').focus();
}
}
if (speed > 0) {
warning.fadeOut(speed, 'swing', close);
}
function close() {
warning.remove();
}
j.warning.instance.push(warning);
return {'close': close};
};
j.warning.instance = [];
j.warning.clear = function () {
while (j.warning.instance.length > 0) {
j.warning.instance.pop().remove();
}
};
/**
* 弹出警告
*/
j.warning3 = function (args) {
args = args || {};
var target = args.target; //需要报错的目标对象,必填
if (!target) return;
var msg = args.msg || ''; //报错内容
var width = args.width || null; //错误框宽度
var focus = args.focus || false; //获得焦点
var speed = args.speed === 0 ? 0 : (args.speed || 5000); //错误信息的保留时间,默认5秒,为0时不消失
var left = args.left || 432;
var top = args.top || -1;
var lineHeight =args.lineHeight || 62;
var height =args.height || 62;
var warning = $('' + msg + '
');
warning.css({
'top': top,
'left': left,
'width': width,
'line-height':lineHeight,
'height':height
}
);
target.after(warning);
if (focus) {
if (target.is('input')) {
target.focus();
} else {
target.find('input').focus();
}
}
if (speed > 0) {
warning.fadeOut(speed, 'swing', close);
}
function close() {
warning.remove();
}
j.warning3.instance.push(warning);
return {'close': close};
};
j.warning3.instance = [];
j.warning3.clear = function () {
while (j.warning3.instance.length > 0) {
j.warning3.instance.pop().remove();
}
};
/**
* 加载动画
*/
j.loading = function () {
var content = $('
');
var modal = j.modal({
'blank': true,
'content': content,
'mask': {'background': 'rgba(0,0,0,0)'}
});
function close() {
modal.close();
}
return {'close': close};
};
/**
* 模板绑定数据
*/
j.template = function (args) {
args = args || {};
var template = args.template; //模板的选择器例如#template
if (!template) return '';
template = $(template).html();
var data = args.data || {};
var bind = args.bind || function ($template) {
};
var temp = document.createElement("div");
for (var i in data) {
var html = data[i];
(temp.textContent != undefined) ? (temp.textContent = html) : (temp.innerText = html);
var reg = new RegExp("{\\$" + i + "}", "gm");
template = template.replace(reg, temp.innerHTML);
}
template = $(template);
bind(template);
return template;
};
/**
* 刷新页面
*/
j.reload = function () {
j.loading();
location.reload();
};
j.captcha = function () {
$('.captcha').each(function () {
var that = $(this);
var src = that.attr('src');
that.click(function () {
that.attr('src', src + "&rand=" + Math.random())
});
});
};
j.date = {};
j.date.early = function (date1, date2) {
if (date2) {
date2 = new Date(Date.parse(date2.replace(/-/g, "/")));
} else {
date2 = new Date();
}
date1 = new Date(Date.parse(date1.replace(/-/g, "/")));
return date1 < date2;
};
$(document).ready(function () {
Jiagle.config.isLogin = false;
Jiagle.config.checklogin = false;
j.user.loadLoginStatus(); // 初始化 OR 刷新用户登录信息
clab_tracker.setEnableAutoTrackExitPage(false);
});
j.ready(function () {
log_source_info(); //* 预备记录 source 信息 */
});
var warn_flag = 1;
function warn(el, p) {
if (warn_flag == 1) {
warn_flag = 0;
var warn = $('' + p + '
');
el.after(warn);
warn.fadeOut(3000, function () {
warn.remove();
warn_flag = 1;
});
}
}
// 弹框显示
function showBox(el) {
el.before('');
el.show();
$('.close-box').click(function () {
$(this).parent().hide();
$('.box-bg').remove();
})
}
function loginOfMobileCode(num, elem) {
elem = elem || ".getMobileCode"
num = num - 1;
$(elem).text(num);
if (num > 0) {
setTimeout(function () {
loginOfMobileCode(num, elem)
}, 1000);
} else {
$(elem).text("重新获取");
}
}
function reloadCapthcha(instanceNo) {
var captchaSrc = "/index.php?showCaptcha=True&instanceNo=" + instanceNo + "&time=" + new Date().getTime();
var imgCodeDom = $('.imgcode')
if (imgCodeDom) {
imgCodeDom.attr('src', captchaSrc);
}
}
/* 家具页面 js 脚本 */
function log_source_info() {
var web_url = location.href;
if (web_url.indexOf("source") != -1) {
var reg = new RegExp("(^|&)source=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
var source = r != null ? unescape(r[2]) : null;
if( !(/^[a-zA-Z]+$/.test(source)) ){
return ;
}
var obj = {source: source, url: web_url};
$.ajax({
type: 'POST',
url: 'https://www.jiagle.com/index.php?' + new Date().getTime() + Math.random() + '&option=com_j2_app&view=source&task=source.checkSource',
data: obj,
success: function (data) {
console.log(data);
}
})
}
}
$(document).ready(function () {
j.user.loadLoginStatus(); // 初始化 OR 刷新用户登录信息
});
j.ready(function () {
log_source_info(); //* 预备记录 source 信息 */
// $('.x_search').submit(function () {
// $('.x_search .x_btn').click();
// return false;
// });
//顶部搜索功能
// $('.x_search .x_btn').click(function () {
// var keyword = $.trim($('.x_search .search2').val());
// keyword = keyword.replace('_', " ");
// if (keyword) {
// keyword = escape(keyword).replace(/%u/g, "_");
// var url = $('.x_search .clic').data('href');
// url = url.replace('{keyword}', keyword);
// location.href = url;
// return false;
// }
// });
/* 家具页面底部订阅信息 js 脚本 */
var already_email = [];
var is_dyemail_doing = false;
$(".email_address input[type=button]").click(function () {
if( is_dyemail_doing ){
return false;
}
var email = $(".email_address .serch").val();
if (email === "") {
alert("邮箱地址为空!");
return false;
}
if(!j.check.email(email)){
alert("邮箱格式不正确!");
return false;
}
if($.inArray( email, already_email) !== -1){
alert("您已成功订阅,请勿重复提交!");
return false;
}
already_email.push(email);
is_dyemail_doing = true;
$.post("",
{
option: "com_jiudian",
task: "home.sendForjiajuDingyue",
isajax: "1",
email: email
},
function (data, status) {
alert("订阅成功!");
is_dyemail_doing = false;
}
);
return false;
});
/* 家具magazine js 脚本 */
var m_flag = 1, startX, startY, endX, endY, x, y, c, item;
$('#magz').bind('mouseenter', function (e) {
if (m_flag == 1) {
startX = e.pageX;
startY = e.pageY;
m_flag = 0;
}
});
$('#magz').bind('mouseleave', function (e) {
m_flag = 1;
});
$('#magz .item').bind('mouseenter', function (e) {
endX = e.pageX;
endY = e.pageY;
x = endX - startX;
y = endY - startY;
item = $(this);
c = item.find('.mag_code');
if (Math.abs(x) >= Math.abs(y)) {
if (x > 0) {
c.css({'top': '0', 'left': '-100%'});
c.animate({'left': '0%'}, 20);
} else {
c.css({'top': '0', 'left': '100%'});
c.animate({'left': '0'}, 20);
}
} else if (Math.abs(x) < Math.abs(y)) {
if (y > 0) {
c.css({'top': '-100%', 'left': '0'});
c.animate({'top': '0'}, 20);
} else if (y == 0) {
return
} else {
c.css({'top': '100%', 'left': '0'});
c.animate({'top': '0'}, 20);
}
}
item.bind('mouseleave', function (e) {
c.css({'top': '0', 'left': '0'});
startX = e.pageX;
startY = e.pageY;
x = startX - endX;
y = startY - endY;
if (Math.abs(x) >= Math.abs(y)) {
if (x > 0) {
c.animate({'left': '100%'}, 20);
} else {
c.animate({'left': '-100%'}, 20);
}
} else if (Math.abs(x) < Math.abs(y)) {
if (y > 0) {
c.animate({'top': '100%'}, 20);
} else {
c.animate({'top': '-100%'}, 20);
}
}
})
});
// 联系我们
$('.v-contact-re-us').click(function () {
var id = $(this).data('id');
j.login({
'success': function () {
j.submit({
data: {
task: 'ajax.contact',
option: 'com_jiudian',
cid: id
},
success: function (data) {
j.log(data);
var template = $('');
for (var i in data) {
var info = data[i];
var box = $('