var _____WB$wombat$assign$function_____ = function(name) {return (self._wb_wombat && self._wb_wombat.local_init && self._wb_wombat.local_init(name)) || self[name]; };
if (!self.__WB_pmw) { self.__WB_pmw = function(obj) { this.__WB_source = obj; return this; } }
{
let window = _____WB$wombat$assign$function_____("window");
let self = _____WB$wombat$assign$function_____("self");
let document = _____WB$wombat$assign$function_____("document");
let location = _____WB$wombat$assign$function_____("location");
let top = _____WB$wombat$assign$function_____("top");
let parent = _____WB$wombat$assign$function_____("parent");
let frames = _____WB$wombat$assign$function_____("frames");
let opener = _____WB$wombat$assign$function_____("opener");
$k.fn.tips = function (config) {
var obj = function (selector, config) {
this.selector = selector;
this.config = $.extendEx({}, this.defConfig, config);
this.haveBrowserEvent = false;
}
obj.prototype.defConfig = {
//anim: 'kui-anim',
closeAnim: { className: 'kui-anim-close', speed: 200 },//speed的值设置为与classsName对应的样式一致,单位为毫秒.
time: 0,
tipsPosition: 'r',
theme: 'default',
time:0,
//iconCls: {
// info: 'icon-info',//icon-info、icon-xinxi3、icon-31tishi1、icon-tishi
// error:'icon-wrong' //icon-wrong、icon-cuowutishi、icon-close2、icon-guanbi2
// ok:icon-31yiguanzhudianpu、.icon-select、icon-yuanxingxuanzhong
//},
iconCls:'icon-info',
status: 'info'
};
obj.prototype.tips=function(){
var _obj = this;
if (_obj.config.theme == 'classic') {
_obj.tips_classic();
return;
}
if (_obj.config.theme == 'default') {
_obj.tips_default();
return;
}
}
obj.prototype.show = function () {
var _obj = this;
_obj.panel.show();
}
obj.prototype.hide = function () {
var _obj = this;
_obj.panel.hide();
}
obj.prototype.setContent = function (content) {
if (!content) {
content = '';
}
_obj.panel.find('.kui-tips-content').html(content);
}
obj.prototype.tips_default = function () {
var _obj = this;
if (!_obj.config.content) {
_obj.config.content = '';
}
var _html = '
' + _obj.config.content + '
';
var tipsPanel = $(_html).appendTo($('body'));
_obj.panel = tipsPanel;
if (_obj.config.anim) {
tipsPanel.addClass(_obj.config.anim);
}
tipsPanel.setStyle(this.config.style);
var contentPart = tipsPanel.find('.kui-tips-content');
var iconPart = tipsPanel.find('.icon');
contentPart.setStyle(this.config.contentPartStyle);
iconPart.setStyle(this.config.iconPartStyle);
_obj.setPosition_Default();
//定时关闭
if (this.config.time && this.config.time > 0) {
var timerId = setTimeout(function () {
clearTimeout(timerId);
_obj.close();
}, this.config.time);
}
}
obj.prototype.setPosition_Default = function () {
//.offset().left:相对于文档的偏移,包括了margin-left
//.position().left:相对于父元素的偏移,不包括margin-left
var _obj = this;
if (_obj.isClosed) {
return;
}
//var tipsArrowPart = _obj.panel.find('.kui-tips-arrow');
var left = _obj.selector.offset().left + _obj.selector.outerWidth();
var top = _obj.selector.offset().top;
//leftAdd、topAdd让用户有机会调整位置.
left += (this.config.leftAdd ? this.config.leftAdd : 0);
top += (this.config.topAdd ? this.config.topAdd : 0);
_obj.panel.css('left', left - $(document).scrollLeft());
_obj.panel.css('top', top - $(document).scrollTop());
if (!_obj.haveBrowserEvent) {//防止重复订阅事件导致网页变卡.
_obj.haveBrowserEvent = true;
$(window).resize(function () {
_obj.setPosition_Default();
});
$(window).scroll(function () {
_obj.setPosition_Default();
});
_obj.selector.parents().scroll(function () {
_obj.setPosition_Default();
});
}
};
obj.prototype.tips_classic = function () {
var _obj = this;
if (!_obj.config.content) {
_obj.config.content = '';
}
var _html = '' + _obj.config.content + '';
if (_obj.config.tipsPosition == 'r') {
_html += '';
}
if (_obj.config.tipsPosition == 'l') {
_html += '';
}
if (_obj.config.tipsPosition == 't') {
_html += '';
}
if (_obj.config.tipsPosition == 'b') {
_html += '';
}
_html += '
';
var tipsPanel = $(_html).appendTo($('body'));
_obj.panel = tipsPanel;
if (_obj.config.anim) {
tipsPanel.addClass(_obj.config.anim);
}
tipsPanel.setStyle(this.config.style);
//this.autoContentHeight();//放置setStyle()方法前执行,以便用户可以自定义高度覆盖.
var contentPart = tipsPanel.find('.kui-tips-content');
var tipsArrowPart = tipsPanel.find('.kui-tips-arrow');
contentPart.setStyle(this.config.contentPartStyle);
tipsArrowPart.setStyle(this.config.tipsArrowPartStyle);
_obj.setPosition_Classic();
//定时关闭
if (this.config.time && this.config.time > 0) {
var timerId = setTimeout(function () {
clearTimeout(timerId);
_obj.close();
}, this.config.time);
}
}
obj.prototype.close = function () {
var _obj = this;
if (_obj.config.closeAnim != false) {
var _timerID = window.setTimeout(function () {
window.clearTimeout(_timerID);
_obj.panel.remove();
_obj.isClosed = true;
}, _obj.config.closeAnim.speed)
_obj.panel.addClass('kui-anim-close');
}
else {
_obj.panel.remove();
_obj.isClosed = true;
}
}
obj.prototype.setPosition_Classic = function () {//仅供tips使用.
//.offset().left:相对于文档的偏移,包括了margin-left
//.position().left:相对于父元素的偏移,不包括margin-left
var _obj = this;
if (_obj.isClosed) {
return;
}
var tipsArrowPart = _obj.panel.find('.kui-tips-arrow');
var target = _obj.selector;
var left = 0;
var top = 0;
if (this.config.tipsPosition == 'r') {
left = target.offset().left + target.outerWidth(true) - parseInt(target.css('margin-left').split('px')[0], 10) - parseInt(target.css('margin-right').split('px')[0], 10) + tipsArrowPart.outerWidth() / 2;
}
if (this.config.tipsPosition == 'r' || this.config.tipsPosition == 'l') {
top = target.offset().top + parseInt(target.css('border-top-width').split('px')[0], 10) + target.innerHeight() / 2 - _obj.panel.innerHeight() / 2;
}
if (this.config.tipsPosition == 't') {
top = target.offset().top - _obj.panel.height() - tipsArrowPart.outerHeight() / 2;
}
if (this.config.tipsPosition == 'b') {
top = target.offset().top + target.outerHeight(true) - parseInt(target.css('margin-top').split('px')[0], 10) - parseInt(target.css('margin-bottom').split('px')[0], 10) + tipsArrowPart.outerHeight() / 2;
}
if (this.config.tipsPosition == 't' || this.config.tipsPosition == 'b') {
left = target.offset().left + parseInt(target.css('border-left-width').split('px')[0], 10);
}
if (this.config.tipsPosition == 'l') {
left = target.offset().left - _obj.panel.width() - tipsArrowPart.outerHeight() / 2;
}
//leftAdd、topAdd让用户有机会调整位置.
left += (this.config.leftAdd ? this.config.leftAdd : 0);
top += (this.config.topAdd ? this.config.topAdd : 0);
_obj.panel.css('left', left - $(document).scrollLeft());
_obj.panel.css('top', top - $(document).scrollTop());
if (!_obj.haveBrowserEvent) {//防止重复订阅事件导致网页变卡.
_obj.haveBrowserEvent = true;
$(window).resize(function () {
_obj.setPosition_Classic();
});
$(window).scroll(function () {
_obj.setPosition_Classic();
});
_obj.selector.parents().scroll(function () {
_obj.setPosition_Classic();
});
}
};
var _obj = new obj($(this.jo), config || {});
_obj.tips();
return _obj;
}
}