var BASE_URL = WWW,
CP = BASE_URL + 'cp/',
SOURCE_URL = '/resource/',
SOURCE_ORIGIN = BASE_URL + 'source/',
UPLOAD_URL = BASE_URL + 'source/',
UPLOAD_IMG = UPLOAD_URL + 'upload',
UPLOAD_FILE = UPLOAD_URL + 'upload',
WU_SWF = BASE_URL + 'msic/webuploader/Uploader.swf',
BRAND_ID = 0;
var YZ = {version: '1.0', author: 'lynn@elicht.cn', created: '20161118', elements: {}}, SOSO = {};
YZ.U = function (uri) {
uri = uri.replace(/\\/g, '/');
if (new RegExp("^[a-z]+:\/\/", 'gi').test(uri.toLowerCase()) || uri.substr(0, 1) == '/') {
return uri;
}
return BASE_URL + uri;
};
YZ.Mask = {
text: '正在处理,请稍候',
html: '
',
show: function (text) {
if (!this.el) {
this.el = $(this.html).appendTo(document.body);
this.masker = $(' ').appendTo(this.el);
}
this.masker.height(Math.max(this.el.height(), $(document.body).height(), $(document).height()));
this.setText(text || this.text)
},
hide: function () {
if (this.el) {
this.el.remove()
}
this.el = null
},
setText: function (text) {
if (this.el) {
this.el.find('span').text(text)
}
}
};
var Mask = YZ.Mask;
YZ.Top = function () {
var el = $('.modal');
el.is(':visible') ? el.scrollTop(0) : $(window).scrollTop(0);
};
T = YZ.Top;
YZ.Toast = function toast(msg, timeout) {
$('#toast').remove();
var el = $('' + msg + '
');
$(top.document.body).append(el);
window.setTimeout(function () {
el.remove()
}, timeout || 3000);
return el;
};
var toast = YZ.Toast;
YZ.Dialog = {
wins: {},
url: {},
show: function (option) {
if (typeof option == 'string') option = {url: option};
var url = option.url || this.url[option.name];
this.loaded = false;
this.callback = option.callback || null;
this.option = option;
if (option.name && this.wins[option.name]) {
this.wins[option.name].modal('show');
var onshow = this.wins[option.name].data('onDialogShow');
if ($.isFunction(onshow)) {
onshow.call(null, option);
}
return;
}
var self = this;
$('
').appendTo('body').load(url);
},
create: function (option) {
option = option || {};
if (typeof option == "string") option = {html: option};
var dialog = $('').appendTo(document.body);
if (option.fade !== false) dialog.addClass('fade');
if (option.cls) dialog.addClass(option.cls);
if (option.dialogCls) dialog.find('.modal-dialog').addClass(option.dialogCls);
var ct = dialog.find('.modal-content');
if (option.title) {
var html = '';
$(html).appendTo(ct);
}
$('
').html(option.html || '').appendTo(ct);
return dialog;
}
};
YZ.ajax = function (uri, callback, options) {
NProgress.start();
options = $.extend({}, options);
$.ajax({
url: YZ.U(uri),
type: options.type ? 'post' : 'get',
data: options.data,
dataType: options.dataType || 'json',
success: function (rs) {
NProgress.done();
if ($.isFunction(callback)) callback(rs);
},
error: function (rs) {
NProgress.done(), toast('提交失败,错误信息:' + rs.message);
}
});
};
YZ.Specification = {
generate: function (id) {
var dialog = YZ.Dialog.create({
html: '
',
cls: 'spec-editor',
dialogCls: 'modal-full'
}).on('hidden.bs.modal', function (e) {
dialog.remove();
}).modal();
var that = this;
dialog.find('.modal-body').load(YZ.U('light/spec/' + id), function () {
var selector = '#spec-editor-sidebar', el = $(selector), p = el.parent(), h = el.outerHeight(),
h1 = p.outerHeight();
dialog.on('scroll', function () {
var t = p.offset().top, t1 = t - dialog.offset().top, t2 = t1 < 0 ? -t1 : 0;
el.css('margin-top', t2 == 0 || (h1 + t1) > h ? t2 : (t2 + h1 + t1 - h));
}).scrollspy({target: selector, offset: dialog.offset().top - p.offset().top + 30});
that.render(dialog);
});
},
render: function (container) {
var light = {},
form = container.find('form'),
F = form.get(0),
imgList = form.find('.img-list'),
columns = {
project: ['name', 'number', 'product', 'quantity', 'position', 'linkman'],
company: ['name', 'logo', 'address', 'linkman', 'phone', 'email']
};
if (F.p_name && window.localStorage.project) {
var project = JSON.parse(window.localStorage.project);
columns.project.map(function (v, k) {
F['p_' + v].value = project[v] || '';
});
}
if (F.c_name && window.localStorage.company) {
var company = JSON.parse(window.localStorage.company);
columns.company.map(function (v, k) {
F['c_' + v].value = company[v] || '';
});
}
container.find('.btn-img-uploader').each(function () {
ImageButtonInit(this, null, true);
// var btn = $(this), options = btn.data('options');
// try {
// options = $.parseJSON('{' + options + '}');
// console.log(options);
// options.callback = function (rs, file, uploader) {
// $(options.input).val(rs.path);
// };
// ImageUploader(btn, options);
// } catch (e) {
// console.log("解析JSON出错(img-upload):" + options);
// console.log(this);
// }
});
var i = 0,
len = imgList.length,
item;
for (; i < len; i++) {
item = $(imgList[i]).find('li:first-child');
item.addClass('active').append(' ');
if (i >= 3) break;
}
var specPicture = $('#specPicture');
container.on('click', '.event-el', function (e) {
var el = $(this), func = el.data('func');
if (!func) return;
e.preventDefault();
switch (func) {
case 'param':
var text = el.find('span').text(), id = el.parent().parent().attr('id'), cls = 'active',
clear = el.parent().data('clear'), multi = el.parent().data('multi'), name = el.data('name'),
path = el.data('path');
if (!el.hasClass(cls) && specPicture.find('li.active').length > 4) {
toast('最多选择5张图');
return;
}
if (!multi) el.siblings().removeClass(cls); // multi为假是不可多选
if (clear) { // clear为真可以取消选择
el.toggleClass(cls);
if (el.hasClass(cls)) {
el.append(' ');
} else {
el.find('input').remove();
}
} else {
el.addClass(cls);
}
break;
case 'preview':
case 'print':
case 'download':
container.find('.param-selector-ct li.active').each(function () {
var li = $(this);
li.closest('.form-group').find('input').val(li.text());
});
if (F.p_name) {
var project = {};
columns.project.map(function (v, k) {
project[v] = F['p_' + v].value;
});
window.localStorage.project = JSON.stringify(project);
}
if (F.c_name) {
var company = {};
columns.company.map(function (v, k) {
company[v] = F['c_' + v].value;
});
window.localStorage.company = JSON.stringify(company);
}
form.attr('action', YZ.U('light/spec/' + func + '/' + F.id.value)).submit();
break;
}
});
}
};
YZ.Valid = function (el, message, focus) {
el = $(el);
var p = el.parent(), cls = ['has-error', 'help-block'], pp, block;
if (p.is('.input-group')) p = p.parent();
pp = p.is('.form-group') ? p : p.parents('.form-group');
if (!pp.length) pp = p.parents('.dl-group');
if (!pp.length) pp = p.parent();
pp.removeClass(cls[0]).find(JQS(cls[1])).remove();
if (message) {
p.append('' + message + '
');
pp.addClass(cls[0]);
if (focus) el.focus();
}
};
YZ.So = function () {
var form = $('.so-form-modal'), body = $(document.body), cls = 'hide', open = 'modal-open';
form.toggleClass(cls);
if (!form.hasClass(cls)) {
body.addClass(open);
form.find('.input-word').focus();
} else {
body.removeClass(open);
}
};
//意见反馈模态框
YZ.Feedback = {
modal: $(''),
init: function () {
var that = this,
modal = that.modal,
$Form = modal.find('#feedbackFrom'),
F = $Form.get(0),
submit = $Form.find('.feedback-footer .btn-submit');
$(F.file).change(function () {
$(this).parent().siblings('.help-txt').html($(this).val());
});
$Form.on('submit', function () {
var val = F.suggest.value,
title = modal.find('.alert-title');
title.html('');
if (val.length > 5) {
YZ.ajax('feedback/commit', function (rs) {
title.html('' +
'× ' +
'提交成功 ' +
'
');
submit.addClass('hide').next().removeClass('hide');
console.log(rs);
}, {
data: $Form.serialize(),
type: 'post'
})
} else {
title.html('' +
'× ' +
'请详细填写您的建议或意见' +
'
');
$(F.suggest).focus();
}
return false;
});
that.modal.on('hidden.bs.modal', function (e) {
clearForm();
submit.removeClass('hide').next().addClass('hide');
})
function clearForm() {
F.category.value = 1;
F.suggest.value = '';
F.contact.value = '';
$('.alert-title').html('');
}
},
show: function () {
this.modal.modal('show');
},
hide: function () {
this.modal.modal('hide');
}
}
YZ.appendStyle = function (style) {
var styleElems = document.getElementsByTagName("style");
if (styleElems.length == 0) {
var tempStyle = document.createElement("style");
tempStyle.setAttribute("type", "text/css");
document.getElementsByTagName("head")[0].appendChild(tempStyle);
}
var styleElem = styleElems[0],
style = style || '';
if (styleElem.styleSheet) {
styleElem.styleSheet.cssText += style;
} else {
styleElem.appendChild(document.createTextNode(style));
}
};
YZ.colortORgba = function (str, alpha) {
var sColor = str.toLowerCase(),
reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
if (sColor && reg.test(sColor)) {
if (sColor.length === 4) {
var sColorNew = "#";
for (var i = 1; i < 4; i += 1) {
sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1));
}
sColor = sColorNew;
}
//处理六位的颜色值
var sColorChange = [];
for (var i = 1; i < 7; i += 2) {
sColorChange.push(parseInt("0x" + sColor.slice(i, i + 2)));
}
return "rgb" + (alpha ? "a" : "") + "(" + sColorChange.join(",") + (alpha ? "," + alpha : "") + ")";
} else {
return sColor;
}
};
function setImgSize(img, size) {
img = img.replace(/\\/g, '/').split('/');
var n = img[img.length - 1].split('.');
n[0] = n[0].split('--')[0] + size;
img[img.length - 1] = n.join('.');
img = img.join('/');
return img
}
SOSO.getImageUrl = function (img, size) {
var flag = false;
if (typeof img == 'string') {
if (img.indexOf('http') == 0) return img;
var filename = img.split('/').pop();
if (filename.split('.')[0].length == 40) {
flag = true;
if (size === false) {
size = '.0';
} else {
size = (size + '').match(/\d+/g);
size = size ? ('.' + size[0]) : '';
}
}
}
if (!flag) size = size === false ? '' : (size || '');
if (typeof img == 'object' && img) {
if (img.path) {
return setImgSize(SOSO.getPathImage(img.path), size)
}
if (img.origin) {
return img.origin + img.filename + size + '.' + img.extension;
}
return (img.baseurl || SOURCE_URL) + img.dirname + img.name + size + '.' + img.ext
} else if (img) {
return setImgSize(img, size)
}
};
SOSO.getPathImage = function (path, size) {
if (typeof path == 'string') {
if (path.indexOf('http') == 0) return path;
var filename = path.split('/').pop();
if (filename.split('.')[0].length == 40) {
return SOSO.getImageUrl(SOURCE_ORIGIN + path, size);
} else if (typeof size != 'undefined') {
return SOSO.getImageUrl(SOURCE_URL + path, size);
}
return SOURCE_URL + path;
} else {
return SOSO.getImageUrl(path, size);
}
};
String.prototype.trim = function () {
return $.trim(this)
}
function isUsername(v) {
if (/^[0-9]+$/.test(v))return !1;
return /^[0-9a-zA-Z_\-]{4,20}$/.test(v.replace(/[\x80-\xff\u4e00-\u9fa5]/g, '00'))
}
function isEmail(n) {
return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(n)
}
function isMobile(n) {
return /^1[34578][0-9]{9}$/.test(n)
}
function affixCategory(element, options) {
if (element.length) {
var p = element.parent().parent(), h = p.height(), _h = element.height();
_h += element.offset().top - p.offset().top;
if (_h >= h) return;
p.css('min-height', _h);
if (element.data('isBindAffix')) return;
var hd = $('.header-affix'), top = hd.length && hd.data('spy') == 'affix' ? hd.outerHeight() : 0;
options = $.extend({
offset: {
top: element.offset().top - top,
bottom: function () {
var b = $(document.body).height() - p.height() - p.offset().top + 30;
return (this.bottom = b);
}
}
}, options);
element.css('top', top + 20).data('isBindAffix', true).affix(options).on('affix.bs.affix', function () {
element.css('position', 'fixed')
}).on('affix-top.bs.affix', function () {
element.css('position', 'static')
});
}
}
function carousel(obj, showPhotoNum) {
showPhotoNum = typeof showPhotoNum != 'undefined' ? parseInt(showPhotoNum) : 6;
var obj = $(obj),
divlen = Math.ceil(obj.find('.preview-list').width() / 60); // 每页显示的图片个数
var num = 1; // 当前所在页
var len = obj.find('.preview-list ul li').length; // 一共多少张
var pageCount = Math.ceil(len / divlen); // 一共多少页
var _last = Math.floor(len % divlen) // 最后一页的图片个数
var left = 0;
var preview = obj.find('.preview-img img');
obj.find('.preview-list').on('mouseover', 'li', function () {
var p = $(this), me = p.find('img'), cls = 'active', url = me.data('url');
if (!p.hasClass(cls) && url) {
p.parent().find('li.' + cls).removeClass(cls)
p.addClass(cls);
preview.attr('src', url);
}
});
if (len <= showPhotoNum) {
obj.find('.preview-ctrl-forward').addClass('disabled');
obj.find('.preview-ctrl-backward').addClass('disabled');
obj.find('.preview-ctrl-forward').css('cursor', 'default');
obj.find('.preview-ctrl-backward').css('cursor', 'default');
return;
}
obj.find('.preview-ctrl-forward').on('click', function (e) {
if (num <= 1) {
obj.find('.preview-ctrl-forward').addClass('disabled');
obj.find('.preview-ctrl-backward').removeClass('disabled');
e.stopPropagation();
return;
}
num--;
left = parseInt(obj.find('.preview-list ul').css('left'));
left += divlen * 60;
left = left > 0 ? 0 : left;
obj.find('.preview-list ul').stop().animate({'left': left}, 400);
e.stopPropagation();
});
obj.find('.preview-ctrl-backward').on('click', function (e) {
if (num >= pageCount) {
obj.find('.preview-ctrl-backward').addClass('disabled');
obj.find('.preview-ctrl-forward').removeClass('disabled');
num = pageCount;
e.stopPropagation();
return;
}
left = -(divlen * 60 * num);
if (num + 1 == pageCount && _last < divlen) {
var tmp = divlen - _last;
left += tmp * 60;
}
obj.find('.preview-list ul').stop().animate({'left': left}, 400);
num++;
e.stopPropagation();
});
}
function JQS(a) {
return '.' + a
}
+function (e) {
"use strict";
var t = function (t, n) {
this.options = n, this.$element = e(t), this.$backdrop = null, this.isShown = null, this.options.remote && this.$element.load(this.options.remote)
};
t.prototype = e.extend({}, e.fn.modal ? e.fn.modal.Constructor.prototype : {}), t.prototype.constructor = t, t.DEFAULTS = {
backdrop: !0,
keyboard: !0,
show: !0
}, t.prototype.show = function (t) {
var n = this, r = e.Event("show.bs.lightbox", {relatedTarget: t});
this.$element.trigger(r);
if (this.isShown || r.isDefaultPrevented())return;
this.isShown = !0, this.escape(), this.$element.on("click.dismiss.lightbox", '[data-dismiss="lightbox"]', e.proxy(this.hide, this)), this.preloadSize(function () {
n.backdrop(function () {
var r = e.support.transition && n.$element.hasClass("fade");
n.$element.parent().length || n.$element.appendTo(document.body), n.$element.show(), r && n.$element[0].offsetWidth, n.$element.addClass("in").attr("aria-hidden", !1), n.enforceFocus();
var i = e.Event("shown.bs.lightbox", {relatedTarget: t});
r ? n.$element.find(".lightbox-dialog").one(e.support.transition.end, function () {
n.$element.focus().trigger(i)
}).emulateTransitionEnd(300) : n.$element.focus().trigger(i)
})
})
}, t.prototype.hide = function (t, n) {
t && t.preventDefault(), t = e.Event("hide.bs.lightbox"), this.$element.trigger(t);
if (!this.isShown || t.isDefaultPrevented())return;
this.isShown = !1, this.escape(), e(document).off("focusin.bs.lightbox"), this.$element.removeClass("in").attr("aria-hidden", !0).off("click.dismiss.lightbox"), e.support.transition && this.$element.hasClass("fade") ? this.$element.one(e.support.transition.end, e.proxy(this.hideModal(n), this)).emulateTransitionEnd(300) : this.hideModal(n), this.options.remove && this.$element.remove();
}, t.prototype.enforceFocus = function () {
e(document).off("focusin.bs.lightbox").on("focusin.bs.lightbox", e.proxy(function (e) {
this.$element[0] !== e.target && !this.$element.has(e.target).length && this.$element.focus()
}, this))
}, t.prototype.escape = function () {
this.isShown && this.options.keyboard ? this.$element.on("keyup.dismiss.bs.lightbox", e.proxy(function (e) {
e.which == 27 && this.hide()
}, this)) : this.isShown || this.$element.off("keyup.dismiss.bs.lightbox")
}, t.prototype.hideModal = function (e) {
var t = this;
this.$element.hide(), this.backdrop(function () {
t.removeBackdrop(), e || t.$element.trigger("hidden.bs.lightbox")
})
}, t.prototype.backdrop = function (t) {
var n = this, r = this.$element.hasClass("fade") ? "fade" : "";
if (this.isShown && this.options.backdrop) {
var i = e.support.transition && r;
this.$backdrop = e('
').appendTo(document.body), this.$element.on("click.dismiss.lightbox", e.proxy(function (e) {
if (e.target !== e.currentTarget)return;
this.options.backdrop == "static" ? this.$element[0].focus.call(this.$element[0]) : this.hide.call(this)
}, this)), i && this.$backdrop[0].offsetWidth, this.$backdrop.addClass("in");
if (!t)return;
i ? this.$backdrop.one(e.support.transition.end, t).emulateTransitionEnd(150) : t()
} else!this.isShown && this.$backdrop ? (this.$backdrop.removeClass("in"), e.support.transition && this.$element.hasClass("fade") ? this.$backdrop.one(e.support.transition.end, t).emulateTransitionEnd(150) : t()) : t && t()
}, t.prototype.preloadSize = function (t) {
var n = e.Callbacks();
t && n.add(t);
var r = this, i, s, o, u, a, f, l, c, h, p;
i = e(window).height(), s = e(window).width(), o = parseInt(r.$element.find(".lightbox-content").css("padding-top"), 10), u = parseInt(r.$element.find(".lightbox-content").css("padding-bottom"), 10), a = parseInt(r.$element.find(".lightbox-content").css("padding-left"), 10), f = parseInt(r.$element.find(".lightbox-content").css("padding-right"), 10), l = r.$element.find(".lightbox-content").find("img:first");
if (l.length <= 0)return n.fire();
c = new Image, c.onload = function () {
c.width + a + f >= s && (h = c.width, p = c.height, c.width = s - a - f, c.height = p / h * c.width), c.height + o + u >= i && (h = c.width, p = c.height, c.height = i - o - u, c.width = h / p * c.height), r.$element.find(".lightbox-dialog").css({
position: "fixed",
width: c.width + a + f,
height: c.height + o + u,
top: i / 2 - (c.height + o + u) / 2,
left: "50%",
"margin-left": -1 * (c.width + a + f) / 2
}), r.$element.find(".lightbox-content").css({
width: c.width + a + f,
height: c.height + o + u
}), l.css({width: c.width, height: c.height}), n.fire()
}, c.src = l.attr("src")
}, t.prototype.slide = function (e) {
var t = this;
t.hide(t.event, !0), e == "next" && t.$element.next(".lightbox").length ? t.$element.next(".lightbox").lightbox("show") : e == "prev" && t.$element.prev(".lightbox").length ? t.$element.prev(".lightbox").lightbox("show") : t.$element.trigger("hidden.bs.lightbox")
};
var n = e.fn.lightbox;
e.fn.lightbox = function (n, r) {
return this.each(function () {
var i = e(this), s = i.data("bs.lightbox"), o = e.extend({}, t.DEFAULTS, i.data(), typeof n == "object" && n);
s || i.data("bs.lightbox", s = new t(this, o)), typeof n == "string" ? s[n](r) : o.show && s.show(r)
})
}, e.fn.lightbox.Constructor = t, e.fn.lightbox.noConflict = function () {
return e.fn.lightbox = n, this
}, e(document).on("click.bs.lightbox.data-api", '[data-toggle="lightbox"]', function (t) {
var n = e(this), r = n.attr("href"), i = e(n.attr("data-target") || r && r.replace(/.*(?=#[^\s]+$)/, "")),
s = i.data("lightbox") ? "toggle" : e.extend({remote: !/#/.test(r) && r}, i.data(), n.data());
t.preventDefault(), i.lightbox(s, this).one("hide", function () {
n.is(":visible") && n.focus()
})
}), e(document).on("click", ".lightbox-control", function (t) {
t.preventDefault();
var n = e(this);
n.parents(".lightbox").lightbox("slide", e(this).data("lightbox-slide"))
}), e(document).on("show.bs.lightbox", ".lightbox", function () {
e(document.body).addClass("lightbox-open")
}).on("hidden.bs.lightbox", ".lightbox", function () {
e(document.body).removeClass("lightbox-open")
})
}(window.jQuery);
function lightBox(el, options) {
options = options || {};
var c = $('
'), h = '';
if (options.src) {
h = $(' ').appendTo(c);
if (options.width) h.attr('width', options.width);
if (options.height) h.attr('height', options.height);
if (options.caption) c.append('');
} else if (options.html) {
c.html(html);
if (options.width) c.width(options.width);
if (options.height) h.height(options.height);
}
c = $('
').append(c);
c = $('
').hide().append(c).appendTo(document.body);
c.lightbox({remove: !0});
return c;
}
$(function () {
var dt1 = new Date();
var id = $.cookie('YZ_PAGE');
window.onbeforeunload = function () {
var dt2 = new Date();
var ms = dt2.getTime() > dt1.getTime() ? (dt2.getTime() - dt1.getTime()) / 1000 : 1;
var img = new Image();
img.src = WWW + 'feedback/unload?t=' + ms + '&id=' + id;
}
$('img').error(function () {
//$(this).hide();
//var downlight;
});
var so = $('#headerSoForm').on('submit', function (e) {
return false
});
so.find('input').on('focus', function () {
YZ.So()
});
so.find('button').on('click', function () {
YZ.So()
});
$('.product-preview').each(function () {
carousel(this);
});
$('.images-selector').on('mouseover', 'li', function () {
var me = $(this),
img = me.find('img'),
url = img.data('url'),
cls = 'active';
if (!me.hasClass(cls) && url) {
me.siblings('.' + cls).removeClass(cls);
me.addClass(cls);
me.parent().prev().find('img').attr('src', url);
}
});
var lightEffect = $('.light-effect-list-img');
if (lightEffect.length) {
lightEffect.on('click', 'a', function () {
var el = $(this), cls = 'active', p;
if (el.hasClass(cls)) return;
el.addClass(cls).siblings().removeClass(cls);
el.parent().parent().parent().find('.light-effect-img img').removeClass(cls).eq(el.index()).addClass(cls);
p = el.parent().parent().find('.light-effect-info');
p.find('h4').text(el.data('name'));
p.find('p').text(el.data('description'));
});
}
$('body').on('click dblclick', '.lightbox-img', function (e) {
var el = $(this),
img = el.is('img') ? el : el.find('img:first'),
src = img.data('source') || img.attr('src');
if (img.length && src) {
if (img.data('lightbox-dblclick')) {
if (e.type == 'dblclick') lightBox(img, {src: src});
} else if (e.type != 'dblclick') {
lightBox(img, {src: src});
}
}
});
$('.img-hover').hover(function () {
var el = $(this).find('img'), hover = el.data('hover'), src = el.data('src');
if (!src) {
src = el.attr('src');
el.data('src', src);
}
if (hover) el.attr('src', hover);
}, function () {
var el = $(this).find('img');
el.attr('src', el.data('src'));
});
window.setTimeout(function () {
affixCategory($('.category-affix-nav'));
}, 500);
$('[data-toggle="tooltip"]').tooltip();
$("#back-to-top").on("click", function () {
$(document.body).animate({
"scrollTop": 0
}, 200);
});
$('.popover-btn').each(function () {
var $pElem = $(this);
$pElem.popover({
html: true,
animation: true,
trigger: 'hover',
container: $(this),
content: function () {
return $($($pElem).data('contentElement')).html();
}
});
});
$('.navbar-nav>li>a.dropdown-toggle').on('click tap', function (e) {
if ($(window).width() > 768) e.stopPropagation();
});
$('.search-tab').on('click', 'li', function () {
$(this).siblings('li').removeClass('active');
$(this).addClass('active');
$(this).parents('form').find('input[name="cate"]').val($(this).data('id'));
});
var yzBtnStyle;
$('.yz-button').hover(
function () {
var high = $(this).data('high');
yzBtnStyle = $(this).attr('style');
if (high) {
$(this).attr('style', yzBtnStyle + high);
}
},
function () {
var high = $(this).data('high');
if (high) {
$(this).attr('style', yzBtnStyle);
}
}
);
YZ.Feedback.init();
$('#feed-back').on('click', function () {
YZ.Feedback.show();
});
$('.nav-menu-horizontal>li').mouseenter(function () {
var maxW = $('.container').width(),
ul = $('.nav-menu-horizontal>li:hover>.dropdown-menu-nav'),
navLeft = $('.container').offset().left,
liW = 0, ulLeft, clientW, overW;
if ($(window).width() > 769) {
if (ul.length > 0) {
ulLeft = ul.closest('li').offset().left;
ul.find('li').each(function () {
liW += $(this).width();
})
clientW = maxW - (ulLeft - navLeft);
overW = liW - clientW;
if (overW > 0) {
if (liW > maxW) {
ul.css('left', -(ulLeft - navLeft)).width(maxW);
} else {
ul.width(liW + 10).css('left', -overW);
}
} else {
ul.width(liW + 10).css('left', 0);
}
} else {
ul.css('left', 0);
}
}
});
var sideNavBar = $('.side-nav-bar');
if (sideNavBar.data('hoverColor')) {
var color = sideNavBar.data('color'),
fontColor = sideNavBar.data('fontColor'),
theme = sideNavBar.data('theme'),
hoverColor = sideNavBar.data('hoverColor'),
colorStyle = '.bar-menu-bottom > li:hover > a, .bar-menu-top > li:hover > a{background:' + color + ';color: #fff;}#back-to-top:hover {border-color: ' + color + ';}',
fontColorStyle = '.bar-menu-bottom > li > a, .bar-menu-top > li > a{color:' + fontColor + ' !important}.bar-menu-bottom,#back-to-top{border-top:1px solid ' + YZ.colortORgba(fontColor, .25) + ' !important}',
themeStyle = '.side-nav-bar{background:' + theme + '!important}',
hoverColorStyle = '.bar-menu-bottom > li:hover > a, .bar-menu-top > li:hover > a{color:' + hoverColor + ' !important}',
style = colorStyle + fontColorStyle + themeStyle + hoverColorStyle;
YZ.appendStyle(style);
}
//导航条溢出处理(小于1024px)
if ($(window).width() > 768 && $(window).width() <= 1024) {
var $header = $('.header'),
$navbar = $header.find('.navbar-nav'),
$navbarLi = $header.find('.navbar-nav > li'),
sumLiWidth = 0;
$navbar.find('li a').on('click', function (e) {
if ($(this).siblings('.nav').length > 0 && $(this).parent().is('.spill') == false) {
e.preventDefault();
}
});
$navbarLi.each(function (index, element) {
sumLiWidth = sumLiWidth + $navbarLi.eq(index).width();
if (sumLiWidth >= 600) {
$(element).addClass('spill');
}
});
if ($navbar.find('li.spill').length > 0) {
$navbar.find('li.spill').wrapAll(' ')
$navbar.find('.spill-con').before(' ');
}
}
});
// jq cookie
(function (factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery'], factory)
} else if (typeof exports === 'object') {
factory(require('jquery'))
} else {
factory(jQuery)
}
}(function ($) {
var pluses = /\+/g;
function encode(s) {
return config.raw ? s : encodeURIComponent(s)
}
function decode(s) {
return config.raw ? s : decodeURIComponent(s)
}
function stringifyCookieValue(value) {
return encode(config.json ? JSON.stringify(value) : String(value))
}
function parseCookieValue(s) {
if (s.indexOf('"') === 0) {
s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\')
}
try {
s = decodeURIComponent(s.replace(pluses, ' '));
return config.json ? JSON.parse(s) : s
} catch (e) {
}
}
function read(s, converter) {
var value = config.raw ? s : parseCookieValue(s);
return $.isFunction(converter) ? converter(value) : value
}
var config = $.cookie = function (key, value, options) {
if (value !== undefined && !$.isFunction(value)) {
options = $.extend({}, config.defaults, options);
if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setTime(+t + days * 864e+5)
}
return (document.cookie = [encode(key), '=', stringifyCookieValue(value), options.expires ? '; expires=' + options.expires.toUTCString() : '', options.path ? '; path=' + options.path : '', options.domain ? '; domain=' + options.domain : '', options.secure ? '; secure' : ''].join(''))
}
var result = key ? undefined : {};
var cookies = document.cookie ? document.cookie.split('; ') : [];
for (var i = 0, l = cookies.length; i < l; i++) {
var parts = cookies[i].split('=');
var name = decode(parts.shift());
var cookie = parts.join('=');
if (key && key === name) {
result = read(cookie, value);
break
}
if (!key && (cookie = read(cookie)) !== undefined) {
result[name] = cookie
}
}
return result
};
config.defaults = {};
$.removeCookie = function (key, options) {
if ($.cookie(key) === undefined) {
return false
}
$.cookie(key, '', $.extend({}, options, {expires: -1}));
return !$.cookie(key)
}
}));