/*!
* lhgcore dialog plugin v4.2.0
* date: 2012-04-19 10:55:11
* http://code.google.com/p/lhgdialog/
* copyright 2009-2012 lihuigang
*/
;(function( $, window, undefined ){
var _ie6 = window.activexobject && !window.xmlhttprequest,
_fn = function(){},
_count = 0,
_rurl = /^url:/,
_singleton,
onkeydown,
document = window.document,
expando = 'jdg' + (+new date),
dialogtpl =
'
' +
'' +
'' +
' | ' +
' | ' +
' | ' +
'
' +
'' +
' | ' +
'' +
'' +
' ' +
'' +
'' +
'' +
'' +
' | ' +
' ' +
'' +
' | ' +
'' +
'' +
' | ' +
' ' +
'' +
'' +
'' +
' | ' +
' ' +
'' +
' ' +
' ' +
' | ' +
' | ' +
'
' +
'' +
' | ' +
' | ' +
' | ' +
'
' +
'' +
'
',
/*!
* _path 获取组件核心文件lhgdialog.js所在的绝对路径
* _args 获取lhgdialog.js文件后的url参数组,如:lhgdialog.js?self=true&skin=aero中的?后面的内容
*/
_args, _path = (function( script, i, me )
{
var l = script.length;
for( ; i < l; i++ )
{
me = !!document.queryselector ?
script[i].src : script[i].getattribute('src',4);
if( me.substr(me.lastindexof('/')).indexof('lhgdialog') !== -1 )
break;
}
me = me.split('?'); _args = me[1];
return me[0].substr( 0, me[0].lastindexof('/') + 1 );
})(document.getelementsbytagname('script'),0),
/*!
* 获取url参数值函数
* @param {string}
* @return {string||null}
* @demo lhgdialog.js?skin=aero | _getargs('skin') => 'aero'
*/
_getargs = function( name )
{
if( _args )
{
var p = _args.split('&'), i = 0, l = p.length, a;
for( ; i < l; i++ )
{
a = p[i].split('=');
if( name === a[0] ) return a[1];
}
}
return null;
},
/*! 取皮肤样式名,默认为 default */
_skin = _getargs('skin') || 'default',
/*! 获取 lhgdialog 可跨级调用的最高层的 window 对象和 document 对象 */
_doc, _top = (function(w)
{
try{
_doc = w['top'].document; // 跨域|无权限
_doc.getelementsbytagname; // chrome 浏览器本地安全限制
}catch(e){
_doc = w.document; return w;
};
// 如果指定参数self为true则不跨框架弹出,或为框架集则无法显示第三方元素
if( _getargs('self') === 'true' ||
_doc.getelementsbytagname('frameset').length > 0 )
{
_doc = w.document; return w;
}
return w['top'];
})(window),
_root = _doc.documentelement, _doctype = _doc.compatmode === 'backcompat';
_$doc = $(_doc), _$top = $(_top), _$html = $(_doc.getelementsbytagname('html')[0]);
/*! 开启ie6 css背景图片缓存 */
try{
_doc.execcommand( 'backgroundimagecache', false, true );
}catch(e){};
/*! 在最顶层页面添加样式文件 */
(function(style){
if(!style)
{
var head = _doc.getelementsbytagname('head')[0],
link = _doc.createelement('link');
link.href = _path + 'skins/' + _skin + '.css';
link.rel = 'stylesheet';
link.id = 'lhgdialoglink';
head.insertbefore(link, head.firstchild);
}
})(_doc.getelementbyid('lhgdialoglink'));
/*!
* ie6下fixed无抖动静止定位
* 如果你的页面的html元素设定了背景图片请把设置背景图片的css写到body元素上
* 如果你不需要组件静止定位(也就是随屏滚动)或此段代码影响了你的页面布局可将此段代码删除
*/
_ie6 && (function(bg){
if( _$html.css(bg) !== 'fixed' )
{
_$html.css({
zoom: 1,// 避免偶尔出现body背景图片异常的情况
backgroundimage: 'url(about:blank)',
backgroundattachment: 'fixed'
});
}
})('backgroundattachment');
/*!----------------------------------以下为lhgdialog核心代码部分----------------------------------*/
var lhgdialog = function( config )
{
config = config || {};
var api, setting = lhgdialog.setting;
// 合并默认配置
for( var i in setting )
{
if( config[i] === undefined ) config[i] = setting[i];
}
config.id = config.id || expando + _count;
// 如果定义了id参数则返回存在此id的窗口对象
api = lhgdialog.list[config.id];
if(api) return api.zindex().focus();
// 按钮队列
config.button = config.button || [];
config.ok &&
config.button.push({
id: 'ok',
name: config.okval,
callback: config.ok,
focus: config.focus
});
config.cancel &&
config.button.push({
id: 'cancel',
name: config.cancelval,
callback: config.cancel
});
// zindex全局配置
lhgdialog.setting.zindex = config.zindex;
_count++;
return lhgdialog.list[config.id] = _singleton ?
_singleton._init(config) : new lhgdialog.fn._init( config );
};
lhgdialog.fn = lhgdialog.prototype =
{
constructor: lhgdialog,
_init: function( config )
{
var that = this, dom,
content = config.content,
isifr = _rurl.test(content);
that.opener = window;
that.config = config;
that.dom = dom = that.dom || that._getdom();
that.closed = false;
that.data = config.data;
// 假如提示性图标为真默认不显示最小化和最大化按钮
if( config.icon && !isifr )
{
config.min = false;
config.max = false;
dom.icon[0].style.display = '';
dom.icon[0].innerhtml = '';
}
else
dom.icon[0].style.display = 'none';
dom.wrap.addclass( config.skin ); // 多皮肤共存
dom.rb[0].style.cursor = config.resize ? 'se-resize' : 'auto';
dom.title[0].style.cursor = config.drag ? 'move' : 'auto';
dom.max[0].style.display = config.max ? 'inline-block' : 'none';
dom.min[0].style.display = config.min ? 'inline-block' : 'none';
dom.close[0].style.display = config.cancel === false ? 'none' : 'inline-block'; //当cancel参数为false时隐藏关闭按钮
dom.content[0].style.padding = config.padding;
that.button.apply( that, config.button );
that.title( config.title )
.content( content, true, isifr )
.size( config.width, config.height )
.position( config.left, config.top )
.time( config.time )
[config.show?'show':'hide'](true).zindex();
config.focus && that.focus();
config.lock && that.lock();
that._ie6pngfix()._addevent();
_singleton = null;
// 假如加载的是单独页面的内容页config.init函数会在内容页加载完成后执行,这里就不执行了
if( !isifr && config.init )
config.init.call( that, window );
return that;
},
/**
* 自定义按钮
* @example
button({
name: 'login',
callback: function(){},
disabled: false,
focus: true
}, .., ..)
*/
button: function()
{
var that = this, dom = that.dom,
buttons = dom.buttons[0],
focusbutton = 'ui_state_highlight',
listeners = that._listeners = that._listeners || {},
ags = [].slice.call(arguments),
i = 0, item, value, id, isnewbutton, button;
for( ; i < ags.length; i++ )
{
item = ags[i];
value = item.name;
id = item.id || value;
isnewbutton = !listeners[id];
button = !isnewbutton ? listeners[id].elem : _doc.createelement('input');
button.type = 'button';
if( !listeners[id] )
listeners[id] = {};
if( value )
button.value = value;
if( item.callback )
listeners[id].callback = item.callback;
if( item.focus )
{
that._focus && that._focus.removeclass(focusbutton);
that._focus = $(button).addclass(focusbutton);
that.focus();
}
button[expando + 'callback'] = id;
button.disabled = !!item.disabled;
if( isnewbutton )
{
listeners[id].elem = button;
buttons.appendchild(button);
}
}
buttons.style.display = ags.length ? '' : 'none';
that._ie6selectfix();
return that;
},
/**
* 设置标题
* @param {string, boolean} 标题内容. 为false则隐藏标题栏
* @return {this} 如果无参数则返回对象本身
*/
title: function( text )
{
if( text === undefined ) return this;
var dom = this.dom,
border = dom.border,
title = dom.title[0];
if( text === false )
{
title.style.display = 'none';
title.innerhtml = '';
border.addclass('ui_state_tips');
}
else
{
title.style.display = '';
title.innerhtml = text;
border.removeclass('ui_state_tips');
};
return this;
},
/*!
* 设置内容
* @param {string} 内容 (如果内容前3个字符为‘url:’就加载单独页面的内容页)
* @param {boolean} 是否为后增加的内容
* @param {boolean} 是否使用iframe方式加载内容页
* @return {this} 如果无参数则返回对象本身
*/
content: function( msg, add, frm )
{
if( msg === undefined ) return this;
var that = this, dom = that.dom,
wrap = dom.wrap[0],
width = wrap.offsetwidth,
height = wrap.offsetheight,
left = parseint(wrap.style.left),
top = parseint(wrap.style.top),
csswidth = wrap.style.width,
$content = dom.content,
loading = lhgdialog.setting.content;
// 假如内容中前3个字符为'url:'就加载相对路径的单独页面的内容页
if( frm )
{
$content[0].innerhtml = loading;
that._iframe( msg.split('url:')[1] );
}
else
$content.html( msg );
// 新增内容后调整位置
if( !add )
{
width = wrap.offsetwidth - width;
height = wrap.offsetheight - height;
left = left - width / 2;
top = top - height / 2;
wrap.style.left = math.max(left, 0) + 'px';
wrap.style.top = math.max(top, 0) + 'px';
if( csswidth && csswidth !== 'auto' )
wrap.style.width = wrap.offsetwidth + 'px';
that._autopositiontype();
}
that._ie6selectfix();
return that;
},
/**
* 尺寸
* @param {number, string} 宽度
* @param {number, string} 高度
*/
size: function( width, height )
{
var that = this, dom = that.dom,
wrap = dom.wrap[0],
style = dom.main[0].style;
wrap.style.width = 'auto';
if( typeof width === 'number' )
width = width + 'px';
if( typeof height === 'number' )
height = height + 'px';
style.width = width;
style.height = height;
if( width !== 'auto' ) // 防止未定义宽度的表格遇到浏览器右边边界伸缩
wrap.style.width = wrap.offsetwidth + 'px';
that._ie6selectfix();
return that;
},
/**
* 位置(相对于可视区域)
* @param {number, string}
* @param {number, string}
*/
position: function( left, top )
{
var that = this,
config = that.config,
wrap = that.dom.wrap[0],
style = wrap.style,
isfixed = _ie6 ? false : config.fixed,
ie6fixed = _ie6 && config.fixed,
docleft = _$top.scrollleft(),
doctop = _$top.scrolltop(),
dl = isfixed ? 0 : docleft,
dt = isfixed ? 0 : doctop,
ww = _$top.width(),
wh = _$top.height(),
ow = wrap.offsetwidth,
oh = wrap.offsetheight;
if( left || left === 0 )
{
that._left = left.tostring().indexof('%') !== -1 ? left : null;
left = that._tonumber(left, ww - ow);
if( typeof left === 'number' )
{
left = ie6fixed ? (left += docleft) : left + dl;
left = math.max(left,dl) + 'px';
}
style.left = left;
}
if( top || top === 0 )
{
that._top = top.tostring().indexof('%') !== -1 ? top : null;
top = that._tonumber(top, wh - oh);
if( typeof top === 'number' )
{
top = ie6fixed ? (top += doctop) : top + dt;
top = math.max(top,dt) + 'px';
}
style.top = top;
}
if( left !== undefined && top !== undefined )
that._autopositiontype();
return that;
},
/*!
* 定时关闭
* @param {number} 单位为秒, 无参数则停止计时器
* @param {function} 关闭窗口前执行的回调函数
*/
time: function( second, callback )
{
var that = this,
timer = that._timer;
timer && cleartimeout(timer);
callback && callback.call(that);
if(second)
{
that._timer = settimeout(function(){
that._click('cancel');
}, 1000 * second);
}
return that;
},
/*! 显示对话框 */
show: function( args )
{
this.dom.wrap[0].style.visibility = 'visible';
this.dom.border.addclass('ui_state_visible');
if( !args && this._lock )
$('#ldg_lockmask',_doc)[0].style.display = '';
return this;
},
/*! 隐藏对话框 */
hide: function( args )
{
this.dom.wrap[0].style.visibility = 'hidden';
this.dom.border.removeclass('ui_state_visible');
if( !args && this._lock )
$('#ldg_lockmask',_doc)[0].style.display = 'none';
return this;
},
/*! 置顶对话框 */
zindex: function()
{
var that = this, dom = that.dom,
load = that._load,
top = lhgdialog.focus,
index = lhgdialog.setting.zindex++;
// 设置叠加高度
dom.wrap[0].style.zindex = index;
// 设置最高层的样式
top && top.dom.border.removeclass('ui_state_focus');
lhgdialog.focus = that;
dom.border.addclass('ui_state_focus');
// 扩展窗口置顶功能,只用在iframe方式加载内容
// 或跨域加载内容页时点窗口内容主体部分置顶窗口
if( load && load.style.zindex )
load.style.display = 'none';
if( top && top !== that && top.iframe )
top._load.style.display = '';
return that;
},
/*! 设置焦点 */
focus: function()
{
try{
elemfocus = this._focus && this._focus[0] || this.dom.close[0];
elemfocus && elemfocus.focus();
}catch(e){};
return this;
},
/*! 锁屏 */
lock: function()
{
var that = this, frm,
index = lhgdialog.setting.zindex - 1,
config = that.config,
mask = $('#ldg_lockmask',_doc)[0],
style = mask ? mask.style : '',
positiontype = _ie6 ? 'absolute' : 'fixed';
if( !mask )
{
frm = '';
mask = _doc.createelement('div');
mask.id = 'ldg_lockmask';
mask.style.csstext = 'position:' + positiontype + ';left:0;top:0;width:100%;height:100%;overflow:hidden;';
style = mask.style;
if( _ie6 ) mask.innerhtml = frm;
_doc.body.appendchild( mask );
}
if( positiontype === 'absolute' )
{
style.width = _$top.width();
style.height = _$top.height();
style.top = _$top.scrolltop();
style.left = _$top.scrollleft();
that._setfixed( mask );
}
style.zindex = index;
style.display = '';
that.zindex();
that.dom.border.addclass('ui_state_lock');
that._lock = true;
return that;
},
/*! 解除锁屏 */
unlock: function()
{
var that = this,
config = that.config,
mask = $('#ldg_lockmask',_doc)[0];
if( mask && that._lock )
{
// 无限级锁屏
if( config.parent && config.parent._lock )
{
var index = config.parent.dom.wrap[0].style.zindex;
mask.style.zindex = parseint(index,10) - 1;
}
else
mask.style.display = 'none';
that.dom.border.removeclass('ui_state_lock');
}
that._lock = false;
return that;
},
/*! 关闭对话框 */
close: function()
{
var that = this, dom = that.dom,
wrap = dom.wrap,
list = lhgdialog.list,
fn = that.config.close;
that.time();
// 当使用iframe方式加载内容页时的处理代码
if( that.iframe )
{
if( typeof fn === 'function' && fn.call(that, that.iframe.contentwindow, window) === false )
return that;
// 重要!需要重置iframe地址,否则下次出现的对话框在ie6、7无法聚焦input
// ie删除iframe后,iframe仍然会留在内存中出现上述问题,置换src是最容易解决的方法
$(that.iframe).unbind('load',that._fmload).attr('src',"javascript:''").remove();
dom.content.removeclass('ui_state_full');
if( that._frmtimer ) cleartimeout(that._frmtimer);
}
else
{
if( typeof fn === 'function' && fn.call(that, window) === false )
return that;
}
that.unlock();
if( that._maxstate )
{
_$html.removeclass('ui_lock_scroll');
dom.res[0].style.display = 'none';
}
if( lhgdialog.focus === that ) lhgdialog.focus = null;
that._removeevent();
delete list[that.config.id];
// 移除htmlelement或重用
if( _singleton )
wrap.remove();
else
{
_singleton = that;
if( that._minstate )
{
dom.main[0].style.display = '';
dom.buttons[0].style.display = '';
dom.dialog[0].style.width = '';
}
dom.wrap[0].style.csstext = 'left:0;top:0;';
dom.wrap[0].classname = '';
dom.border.removeclass('ui_state_focus');
dom.title[0].innerhtml = '';
dom.content.html('');
dom.icon[0].innerhtml = '';
dom.buttons[0].innerhtml = '';
that.hide(true)._setabsolute();
// 清空除this.dom之外临时对象,恢复到初始状态,以便使用单例模式
for( var i in that )
{
if(that.hasownproperty(i) && i !== 'dom') delete that[i];
};
}
that.closed = true;
return that;
},
/*! 最大化窗口 */
max: function()
{
var that = this, maxsize,
dom = that.dom,
wrapstyle = dom.wrap[0].style,
mainstyle = dom.main[0].style,
rbstyle = dom.rb[0].style,
titlestyle = dom.title[0].style,
config = that.config,
top = _$top.scrolltop(),
left = _$top.scrollleft();
if( !that._maxstate )
{
_$html.addclass('ui_lock_scroll');
if( that._minstate )
that.min();
// 存储最大化窗口前的状态
that._or = {
t: wrapstyle.top,
l: wrapstyle.left,
w: mainstyle.width,
h: mainstyle.height,
d: config.drag,
r: config.resize,
rc: rbstyle.cursor,
tc: titlestyle.cursor
};
wrapstyle.top = top + 'px';
wrapstyle.left = left + 'px';
maxsize = that._maxsize();
that.size( maxsize.w, maxsize.h )._setabsolute();
if( _ie6 && _doctype )
wrapstyle.width = _$top.width() + 'px';
config.drag = false;
config.resize = false;
rbstyle.cursor = 'auto';
titlestyle.cursor = 'auto';
dom.max[0].style.display = 'none';
dom.res[0].style.display = 'inline-block';
that._maxstate = true;
}
else
{
_$html.removeclass('ui_lock_scroll');
wrapstyle.top = that._or.t;
wrapstyle.left = that._or.l;
that.size( that._or.w, that._or.h )._autopositiontype();
config.drag = that._or.d;
config.resize = that._or.r;
rbstyle.cursor = that._or.rc;
titlestyle.cursor = that._or.tc;
dom.res[0].style.display = 'none';
dom.max[0].style.display = 'inline-block';
delete that._or;
that._maxstate = false;
}
return that;
},
/*! 最小化窗口 */
min: function()
{
var that = this,
dom = that.dom,
main = dom.main[0].style,
buttons = dom.buttons[0].style,
dialog = dom.dialog[0].style,
rb = dom.rb[0].style.cursor,
resize = that.config.resize;
if( !that._minstate )
{
if( that._maxstate )
that.max();
that._minrz = {rzs:resize,btn:buttons.display};
main.display = 'none';
buttons.display = 'none';
dialog.width = main.width;
rb.cursor = 'auto';
resize = false;
that._minstate = true;
}
else
{
main.display = '';
buttons.display = that._minrz.btn;
dialog.width = '';
resize = that._minrz;
rb.cursor = that._minrz.rzs ? 'se-resize' : 'auto';
delete that._minrz;
that._minstate = false;
}
that._ie6selectfix();
return that;
},
/*!
* 获取指定id的窗口对象或窗口中iframe加载的内容页的window对象
* @param {string} 指定的id
* @param {string} 是否返回的为指定id的窗口对象
* 用数字1来表示真,如果不写或写其它为false
* @return {object|null}
*/
get: function( id, object )
{
if( lhgdialog.list[id] )
{
if( object === 1 )
return lhgdialog.list[id];
else
return lhgdialog.list[id].content || null;
}
return null;
},
/**
* 刷新或跳转指定页面
* @param {object, 指定页面的window对象}
* @param {string, 要跳转到的页面地址}
*/
reload: function( win, url, callback )
{
win = win || window;
try{
win.location.href = url ? url : win.location.href;
}
catch(e){ // 跨域
url = this.iframe.src;
$(this.iframe).attr('src', url);
};
callback && callback.call( this );
return this;
},
/*!
* 设置iframe方式加载内容页
*/
_iframe: function( url )
{
var that = this, iframe, $iframe, iwin, $idoc, $ibody, iwidth, iheight,
$content = that.dom.content,
config = that.config,
loading = that._load = $('.ui_loading',$content[0])[0],
initcss = 'position:absolute;left:-9999em;border:none 0;background:transparent',
loadcss = 'width:100%;height:100%;border:none 0;';
// 是否允许缓存. 默认true
if( config.cache === false )
{
var ts = (new date).gettime(),
ret = url.replace(/([?&])_=[^&]*/, '$1_=' + ts );
url = ret + ((ret === url) ? (/\?/.test(url) ? '&' : '?') + '_=' + ts : '');
}
iframe = that.iframe = _doc.createelement('iframe');
iframe.name = config.id;
iframe.style.csstext = initcss;
iframe.setattribute('frameborder', 0, 0);
$iframe = $(iframe);
$content[0].appendchild( iframe );
// 延迟加载iframe的src属性,ie6下不延迟加载会出现加载进度条的bug
that._frmtimer = settimeout(function(){
$iframe.attr('src', url);
}, 1);
// iframe中页面加载完成后执行的函数
var load = that._fmload = function()
{
$content.addclass('ui_state_full');
// 增强窗口置顶功能,iframe方式加载内容或跨域加载内容页时点窗口内容部分置顶窗口
// 通过使用重置loading层来优雅的完成此功能,在focus方法中有此功能的相关代码
var dom = that.dom, ltsize,
lt = dom.lt[0].offsetheight,
main = dom.main[0].style;
loading.style.csstext = 'display:none;position:absolute;background:#fff;opacity:0;' +
'filter:alpha(opacity=0);z-index:1;width:' + main.width + ';height:' + main.height + ';';
// 此部分代码结束,在拖动改变大小的_dragevent.onmove方法中还有此功能的相关代码
try{
iwin = that.content = iframe.contentwindow; // 定义窗口对象content属性为内容页的window对象
$idoc = $(iwin.document);
$ibody = $(iwin.document.body);
}catch(e){// 跨域
iframe.style.csstext = loadcss;
return;
}
// 获取iframe内部尺寸
iwidth = config.width === 'auto'
? $idoc.width() + (_ie6 ? 0 : parseint($ibody.css('marginleft')))
: config.width;
iheight = config.height === 'auto'
? $idoc.height() : config.height;
// 适应iframe尺寸
settimeout(function(){
iframe.style.csstext = loadcss;
},0);// settimeout: 防止ie6~7对话框样式渲染异常
// 窗口最大化时这里不用再计算窗口的尺寸和位置了,如果再计算窗口会出现错位
if( !that._maxstate )
{
that.size( iwidth, iheight )
.position( config.left, config.top );
}
// 非跨域时还要对loading层重设大小,要不宽和度都为'auto'
loading.style.width = main.width;
loading.style.height = main.height;
config.init && config.init.call( that, iwin, _top );
};
// 绑定iframe元素api属性为窗口自身对象,在内容页中此属性很重要
that.iframe.api = that;
$iframe.bind( 'load', load );
},
/*! 获取窗口元素 */
_getdom: function()
{
var wrap = _doc.createelement('div'),
body = _doc.body;
wrap.style.csstext = 'position:absolute;left:0;top:0;visibility:hidden;';
wrap.innerhtml = dialogtpl;
var name, i = 0,
dom = { wrap: $(wrap) },
els = wrap.getelementsbytagname('*'),
len = els.length;
for( ; i < len; i ++ )
{
name = els[i].classname.split('ui_')[1];
if(name) dom[name] = $(els[i]);
};
body.insertbefore(wrap, body.firstchild);
return dom;
},
/*!
* px与%单位转换成数值 (百分比单位按照最大值换算)
* 其他的单位返回原值
*/
_tonumber: function( thisvalue, maxvalue )
{
if( typeof thisvalue === 'number' )
return thisvalue;
if( thisvalue.indexof('%') !== -1 )
thisvalue = parseint(maxvalue * thisvalue.split('%')[0] / 100);
return thisvalue;
},
/*! 计算最大化窗口时窗口的尺寸 */
_maxsize: function()
{
var that = this, dom = that.dom,
wrap = dom.wrap[0],
main = dom.main[0],
maxwidth, maxheight;
maxwidth = _$top.width() - wrap.offsetwidth + main.offsetwidth;
maxheight = _$top.height() - wrap.offsetheight + main.offsetheight;
return { w: maxwidth, h: maxheight };
},
/*! 让ie6 css支持png背景 */
_ie6pngfix: function()
{
if( _ie6 )
{
var i = 0, elem, png, pngpath, runtimestyle,
path = lhgdialog.setting.path + '/skins/',
list = this.dom.wrap[0].getelementsbytagname('*');
for( ; i < list.length; i ++ )
{
elem = list[i];
png = elem.currentstyle['png'];
if( png )
{
pngpath = path + png;
runtimestyle = elem.runtimestyle;
runtimestyle.backgroundimage = 'none';
runtimestyle.filter = "progid:dximagetransform.microsoft." +
"alphaimageloader(src='" + pngpath + "',sizingmethod='scale')";
};
}
}
return this;
},
/*! 强制覆盖ie6下拉控件 */
_ie6selectfix: _ie6 ? function(){
var $wrap = this.dom.wrap,
wrap = $wrap[0],
expando = expando + 'iframemask',
iframe = $wrap[expando],
width = wrap.offsetwidth,
height = wrap.offsetheight;
width = width + 'px';
height = height + 'px';
if(iframe)
{
iframe.style.width = width;
iframe.style.height = height;
}else{
iframe = wrap.appendchild(_doc.createelement('iframe'));
$wrap[expando] = iframe;
iframe.src = "javascript:''";
iframe.style.csstext = 'position:absolute;z-index:-1;left:0;top:0;'
+ 'filter:alpha(opacity=0);width:' + width + ';height:' + height;
}
} : _fn,
/*! 自动切换定位类型 */
_autopositiontype: function()
{
this[this.config.fixed ? '_setfixed' : '_setabsolute']();
},
/*! 设置静止定位 */
_setfixed: function( el )
{
var style = el ? el.style : this.dom.wrap[0].style;
if( _ie6 )
{
var sleft = _$top.scrollleft(),
stop = _$top.scrolltop(),
left = parseint(style.left) - sleft,
top = parseint(style.top) - stop,
txt = _doctype ? 'this.ownerdocument.body' :
'this.ownerdocument.documentelement';
this._setabsolute();
style.setexpression( 'left', txt + '.scrollleft +' + left );
style.setexpression( 'top', txt + '.scrolltop +' + top );
}
else
style.position = 'fixed';
},
/*! 设置绝对定位 */
_setabsolute: function()
{
var style = this.dom.wrap[0].style;
if(_ie6)
{
style.removeexpression('left');
style.removeexpression('top');
}
style.position = 'absolute';
},
/*! 按钮回调函数触发 */
_click: function( name )
{
var that = this,
fn = that._listeners[name] && that._listeners[name].callback;
return typeof fn !== 'function' || fn.call(that, window) !== false ?
that.close() : that;
},
/*! 重置位置与尺寸 */
_reset: function()
{
var test = !!window.activexobject,
newsize,
that = this,
tw = _$top.width(),
tt = _$top.height(),
oldsize = that._winsize || tw * tt,
oldwidth = that._lockdocw || tw,
left = that._left,
top = that._top;
if(test)
{
//ie6下遮罩大小改变
if( that._lock && _ie6 )
$('#ldg_lockmask',_doc).css({ width:tw + 'px', height:tt + 17 + 'px' });
newwidth = that._lockdocw = tw;
//ie6~7 window.onresize bug
newsize = that._winsize = tw * tt;
if( oldsize === newsize ) return;
};
if( that._maxstate )
{
var size = that._maxsize();
that.size( size.w, size.h );
}
//ie6~8会出现最大化还原后窗口重新定位,锁定滚动条在ie下就会触发resize事件bug
if( test && math.abs(oldwidth - newwidth) === 17 ) return;
if( left || top )
that.position( left, top );
},
_addevent: function()
{
var resizetimer,
that = this,
config = that.config,
dom = that.dom;
// 窗口调节事件
that._winresize = function()
{
resizetimer && cleartimeout(resizetimer);
resizetimer = settimeout(function()
{
that._reset();
}, 140);
};
_$top.bind('resize', that._winresize);
// 监听点击
dom.wrap.bind('click', function(event){
var target = event.target, callbackid;
if( target.disabled ) return false; // ie bug
if( target === dom.close[0] )
{
that._click('cancel');
return false;
}
else if( target === dom.max[0] || target === dom.res[0] || target === dom.max_b[0]
|| target === dom.res_b[0] || target === dom.res_t[0] )
{
that.max();
return false;
}
else if( target === dom.min[0] || target === dom.min_b[0] )
{
that.min();
return false;
}
else
{
callbackid = target[expando + 'callback'];
callbackid && that._click(callbackid);
}
}).bind('mousedown',function(event){
that.zindex();
var target = event.target;
if( config.drag !== false && target === dom.title[0]
|| config.resize !== false && target === dom.rb[0] )
{
_use(event);
return false;
}
});
// 双击标题栏最大化还窗口事件
if( config.max )
dom.title.bind('dblclick',function(){ that.max(); return false; });
},
/*! 卸载事件代理 */
_removeevent: function()
{
var that = this,
dom = that.dom;
dom.wrap.unbind();
dom.title.unbind();
_$top.unbind('resize', that._winresize);
}
};
lhgdialog.fn._init.prototype = lhgdialog.fn;
/*! 此对象用来存储获得焦点的窗口对象实例 */
lhgdialog.focus = null;
/*! 存储窗口实例的对象列表 */
lhgdialog.list = {};
/*!
* 全局快捷键
* 由于跨框架时事件是绑定到最顶层页面,所以当当前页面卸载时必须要除移此事件
* 所以必须unbind此事件绑定的函数,所以这里要给绑定的事件定义个函数
* 这样在当前页面卸载时就可以移此事件绑定的相应函数,不而不影响顶层页面此事件绑定的其它函数
*/
onkeydown = function(event)
{
var target = event.target,
api = lhgdialog.focus,
keycode = event.keycode;
if( !api || !api.config.esc || api.config.cancel === false ) return;
keycode === 27 && api._click(api.config.cancelval);
};
_$doc.bind('keydown',onkeydown);
/*!
* 框架页面卸载前关闭所有穿越的对话框
* 同时移除拖动层和遮罩层
*/
_top != window && $(window).bind('unload',function()
{
var list = lhgdialog.list;
for( var i in list )
{
if(list[i])
list[i].close();
}
_singleton && _singleton.dom.wrap.remove();
_$doc.unbind('keydown',onkeydown);
$('#ldg_lockmask',_doc)[0] && $('#ldg_lockmask',_doc).remove();
$('#ldg_dragmask',_doc)[0] && $('#ldg_dragmask',_doc).remove();
});
/*! lhgdialog 的全局默认配置 */
lhgdialog.setting =
{
content: 'loading...
',
title: '\u89c6\u7a97 ', // 标题,默认'视窗'
button: null, // 自定义按钮
ok: null, // 确定按钮回调函数
cancel: null, // 取消按钮回调函数
init: null, // 对话框初始化后执行的函数
close: null, // 对话框关闭前执行的函数
okval: '\u786e\u5b9a', // 确定按钮文本,默认'确定'
cancelval: '\u53d6\u6d88', // 取消按钮文本,默认'取消'
skin: '', // 多皮肤共存预留接口
esc: true, // 是否支持esc键关闭
show: true, // 初始化后是否显示对话框
width: 'auto', // 内容宽度
height: 'auto', // 内容高度
icon: null, // 消息图标名称
path: _path, // lhgdialog路径
lock: false, // 是否锁屏
focus: true, // 窗口是否自动获取焦点
parent: null, // 打开子窗口的父窗口对象,主要用于多层锁屏窗口
padding: '10px', // 内容与边界填充距离
fixed: false, // 是否静止定位
left: '50%', // x轴坐标
top: '38.2%', // y轴坐标
max: true, // 是否显示最大化按钮
min: true, // 是否显示最小化按钮
zindex: 1976, // 对话框叠加高度值(重要:此值不能超过浏览器最大限制)
resize: true, // 是否允许用户调节尺寸
drag: true, // 是否允许用户拖动位置
cache: true, // 是否缓存窗口内容页
data: null, // 传递各种数据
extenddrag: false // 增加lhgdialog拖拽体验
};
/*!
*------------------------------------------------
* 对话框模块-拖拽支持(可选外置模块)
*------------------------------------------------
*/
var _use, _issetcapture = 'setcapture' in _root,
_islosecapture = 'onlosecapture' in _root;
lhgdialog.dragevent =
{
onstart: _fn,
start: function(event)
{
var that = lhgdialog.dragevent;
_$doc
.bind( 'mousemove', that.move )
.bind( 'mouseup', that.end );
that._sclientx = event.clientx;
that._sclienty = event.clienty;
that.onstart( event.clientx, event.clienty );
return false;
},
onmove: _fn,
move: function(event)
{
var that = lhgdialog.dragevent;
that.onmove(
event.clientx - that._sclientx,
event.clienty - that._sclienty
);
return false;
},
onend: _fn,
end: function(event)
{
var that = lhgdialog.dragevent;
_$doc
.unbind('mousemove', that.move)
.unbind('mouseup', that.end);
that.onend( event.clientx, event.clienty );
return false;
}
};
_use = function(event)
{
var limit, startwidth, startheight, startleft, starttop, isresize,
api = lhgdialog.focus,
config = api.config,
dom = api.dom,
wrap = dom.wrap[0],
title = dom.title,
main = dom.main[0],
_dragevent = lhgdialog.dragevent,
// 清除文本选择
clsselect = 'getselection' in _top ?
function(){
_top.getselection().removeallranges();
}:function(){
try{_doc.selection.empty();}catch(e){};
};
// 对话框准备拖动
_dragevent.onstart = function( x, y )
{
if( isresize )
{
startwidth = main.offsetwidth;
startheight = main.offsetheight;
}
else
{
startleft = wrap.offsetleft;
starttop = wrap.offsettop;
};
_$doc.bind( 'dblclick', _dragevent.end );
!_ie6 && _islosecapture
? title.bind('losecapture',_dragevent.end )
: _$top.bind('blur',_dragevent.end);
_issetcapture && title[0].setcapture();
dom.border.addclass('ui_state_drag');
api.focus();
};
// 对话框拖动进行中
_dragevent.onmove = function( x, y )
{
if( isresize )
{
var wrapstyle = wrap.style,
style = main.style,
width = x + startwidth,
height = y + startheight;
wrapstyle.width = 'auto';
config.width = style.width = math.max(0,width) + 'px';
wrapstyle.width = wrap.offsetwidth + 'px';
config.height = style.height = math.max(0,height) + 'px';
//api._ie6selectfix();
// 使用loading层置顶窗口时窗口大小改变相应loading层大小也得改变
api._load && $(api._load).css({width:style.width, height:style.height});
}
else
{
var style = wrap.style,
left = x + startleft,
top = y + starttop;
config.left = math.max( limit.minx, math.min(limit.maxx,left) );
config.top = math.max( limit.miny, math.min(limit.maxy,top) );
style.left = config.left + 'px';
style.top = config.top + 'px';
}
clsselect();
};
// 对话框拖动结束
_dragevent.onend = function( x, y )
{
_$doc.unbind('dblclick',_dragevent.end);
!_ie6 && _islosecapture
? title.unbind('losecapture',_dragevent.end)
: _$top.unbind('blur',_dragevent.end);
_issetcapture && title[0].releasecapture();
_ie6 && api._autopositiontype();
dom.border.removeclass('ui_state_drag');
};
isresize = event.target === dom.rb[0] ? true : false;
limit = (function(fixed)
{
var ow = wrap.offsetwidth,
// 向下拖动时不能将标题栏拖出可视区域
oh = title[0].offsetheight || 20,
ww = _$top.width(),
wh = _$top.height(),
dl = fixed ? 0 : _$top.scrollleft(),
dt = fixed ? 0 : _$top.scrolltop();
// 坐标最大值限制(在可视区域内)
maxx = ww - ow + dl;
maxy = wh - oh + dt;
return {
minx: dl,
miny: dt,
maxx: maxx,
maxy: maxy
};
})(wrap.style.position === 'fixed');
_dragevent.start(event);
};
/*!
* 页面dom加载完成执行的代码
*/
$(function(){
// 触发浏览器预先缓存背景图片
settimeout(function()
{
if(_count) return;
lhgdialog({left:'-9999em',time:9,fixed:false,lock:false,focus:false});
},150);
// 增强lhgdialog拖拽体验(可选外置模块,如不需要可删除)
// 防止鼠标落入iframe导致不流畅,对超大对话框拖动优化
lhgdialog.setting.extenddrag &&
(function(dragevent){
var mask = _doc.createelement('div'),
style = mask.style,
positiontype = _ie6 ? 'absolute' : 'fixed';
mask.id = 'ldg_dragmask';
style.csstext = 'display:none;position:' + positiontype + ';left:0;top:0;width:100%;height:100%;'
+ 'cursor:move;filter:alpha(opacity=0);opacity:0;background:#fff;pointer-events:none;';
_doc.body.appendchild(mask);
dragevent._start = dragevent.start;
dragevent._end = dragevent.end;
dragevent.start = function()
{
var api = lhgdialog.focus,
main = api.dom.main[0],
iframe = api.iframe;
dragevent._start.apply(this, arguments);
style.display = 'block';
style.zindex = lhgdialog.setting.zindex + 3;
if(positiontype === 'absolute')
{
style.width = _$top.width() + 'px';
style.height = _$top.height() + 'px';
style.left = _$doc.scrollleft() + 'px';
style.top = _$doc.scrolltop() + 'px';
};
if( iframe && main.offsetwidth * main.offsetheight > 307200 )
main.style.visibility = 'hidden';
};
dragevent.end = function()
{
var api = lhgdialog.focus;
dragevent._end.apply(this, arguments);
style.display = 'none';
if(api) api.dom.main[0].style.visibility = 'visible';
};
})(lhgdialog.dragevent);
});
/*! 使用jq方式调用窗口 */
$.fn.dialog = function()
{
var config = arguments;
this.bind('click',function(){ lhgdialog.apply(this,config); return false; });
return this;
};
window.lhgdialog = $.dialog = lhgdialog;
})( this.jquery || this.lhgcore, this );
/*!
*------------------------------------------------
* 对话框其它功能扩展模块(可选外置模块)
*------------------------------------------------
*/
;(function( $, lhgdialog, undefined ){
var _zindex = function()
{
return lhgdialog.setting.zindex;
};
/**
* 警告
* @param {string} 消息内容
*/
lhgdialog.alert = function( content, callback, parent )
{
return lhgdialog({
title: '警告',
id: 'alert',
zindex: _zindex(),
icon: 'alert.gif',
fixed: true,
lock: true,
content: content,
ok: true,
resize: false,
close: callback,
parent: parent || null
});
};
/**
* 确认
* @param {string} 消息内容
* @param {function} 确定按钮回调函数
* @param {function} 取消按钮回调函数
*/
lhgdialog.confirm = function( content, yes, no, parent )
{
return lhgdialog({
title: '确认',
id: 'confirm.gif',
zindex: _zindex(),
icon: 'confirm.gif',
fixed: true,
lock: true,
content: content,
resize: false,
parent: parent || null,
ok: function(here){
return yes.call(this, here);
},
cancel: function(here){
return no && no.call(this, here);
}
});
};
/**
* 提问
* @param {string} 提问内容
* @param {function} 回调函数. 接收参数:输入值
* @param {string} 默认值
*/
lhgdialog.prompt = function( content, yes, value, parent )
{
value = value || '';
var input;
return lhgdialog({
title: '提问',
id: 'prompt',
zindex: _zindex(),
icon: 'prompt.gif',
fixed: true,
lock: true,
parent: parent || null,
content: [
'',
content,
'
',
'',
'',
'
'
].join(''),
init: function(){
input = this.dom.content[0].getelementsbytagname('input')[0];
input.select();
input.focus();
},
ok: function(here){
return yes && yes.call(this, input.value, here);
},
cancel: true
});
};
/**
* 短暂提示
* @param {string} 提示内容
* @param {number} 显示时间 (默认1.5秒)
* @param {string} 提示图标 (注意要加扩展名)
* @param {function} 提示关闭时执行的回调函数
*/
lhgdialog.tips = function( content, time, icon, callback )
{
var reicon = icon ? function(){
this.dom.icon[0].innerhtml = '';
this.dom.icon[0].style.display = '';
if( callback ) this.config.close = callback;
} : function(){
this.dom.icon[0].style.display = 'none';
if( callback ) this.config.close = callback;
};
return lhgdialog({
id: 'tips',
zindex: _zindex(),
title: false,
cancel: false,
fixed: true,
lock: false,
resize: false
})
.content(content)
.time(time || 1.5, reicon);
};
})( this.jquery||this.lhgcore, this.lhgdialog );