锘?*! * 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 = '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
' + '
' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
' + '
' + '
' + '
' + '' + '' + '' + '\xd7' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
', /*! * _path ?峰??缁?浠舵?稿???浠?hgdialog.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; }; // 濡?????瀹?????elf涓?rue??涓?璺ㄦ??跺脊?猴???涓烘??堕??????娉??剧ず绗???瑰??绱? 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]); /*! 寮???E6 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????ody??绱?涓? * 濡???浣?涓???瑕?缁?浠堕??姝㈠?浣?锛?涔?灏辨????灞?婊??????姝ゆ?浠g??褰卞??浜?浣???椤甸?㈠?灞????姝ゆ?浠g????? */ _ie6 && (function(bg){ if( _$html.css(bg) !== 'fixed' ) { _$html.css({ zoom: 1,// ?垮???跺??虹??ody?????剧??寮?甯哥????? backgroundImage: 'url(about:blank)', backgroundAttachment: 'fixed' }); } })('backgroundAttachment'); /*!----------------------------------浠ヤ?涓?hgdialog?稿?浠g???ㄥ??----------------------------------*/ 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??绐??e?璞 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} ??棰???瀹? 涓?alse????????棰??? * @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} ???︿娇??frame?瑰???杞藉??瀹归〉 * @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} ?抽????e???ц?????璋??芥? */ 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'); // ?╁?绐??g疆椤跺???斤????ㄥ??frame?瑰???杞藉??瀹 // ??璺ㄥ????杞藉??瀹归〉?剁?圭??e??瀹逛富浣??ㄥ??缃?《绐?? 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; }, /*! 瑙i?ら??灞? */ 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(); // 褰?浣跨??frame?瑰???杞藉??瀹归〉?剁??澶???浠g?? if( that.iframe ) { if( typeof fn === 'function' && fn.call(that, that.iframe.contentWindow, window) === false ) return that; // ??瑕?锛???瑕???缃?frame?板??锛??﹀??涓?娆″?虹?扮??瀵硅?妗???E6??7??娉?????nput // IE????frame??锛?iframe浠??朵????ㄥ??瀛?涓??虹?颁?杩伴???锛?缃???rc????瀹规??瑙e?崇???规? $(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]; // 绉婚??TMLElement????? 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(); // 娓?绌洪??his.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(); // 瀛??ㄦ??澶у??绐??e?????舵?? 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??绐??e?璞℃??绐??d腑iframe??杞界????瀹归〉??window瀵硅薄 * @param {String} ??瀹???id * @param {String} ???﹁?????涓烘??瀹?id??绐??e?璞 * ?ㄦ?板?1?ヨ〃绀虹??锛?濡???涓????????跺?涓?alse * @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;'; // ???﹀??璁哥?瀛?. 榛?璁?rue 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 ); // 寤惰???杞?frame??src灞??э?IE6涓?涓?寤惰???杞戒??虹?板??杞借?搴︽?$??BUG that._frmTimer = setTimeout(function(){ $iframe.attr('src', url); }, 1); // iframe涓?〉?㈠??杞藉??????ц????芥? var load = that._fmLoad = function() { $content.addClass('ui_state_full'); // 澧?寮虹??g疆椤跺???斤?iframe?瑰???杞藉??瀹规??璺ㄥ????杞藉??瀹归〉?剁?圭??e??瀹归?ㄥ??缃?《绐?? // ??杩?浣跨?ㄩ??缃?oading灞??ヤ?????瀹???姝ゅ???斤???ocus?规?涓???姝ゅ???界???稿?充唬?? 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 + ';'; // 姝ら?ㄥ??浠g??缁???锛??ㄦ???ㄦ?瑰??澶у???_dragEvent.onmove?规?涓????姝ゅ???界???稿?充唬?? try{ iwin = that.content = iframe.contentWindow; // 瀹?涔?绐??e?璞?ontent灞??т负??瀹归〉??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瀵硅?妗??峰?娓叉??寮?甯 // 绐??f??澶у???惰???涓??ㄥ??璁$?绐??g??灏哄???浣?缃??锛?濡?????璁$?绐??d??虹?伴??浣? if( !that._maxState ) { that.size( iWidth, iHeight ) .position( config.left, config.top ); } // ??璺ㄥ???惰?瑕?瀵?oading灞???璁惧ぇ灏?锛?瑕?涓?瀹藉??搴﹂?戒负'auto' loading.style.width = main.width; loading.style.height = main.height; config.init && config.init.call( that, iwin, _top ); }; // 缁?瀹?iframe??绱?api灞??т负绐??h??韩瀵硅薄锛??ㄥ??瀹归〉涓??灞??у???瑕? that.iframe.api = that; $iframe.bind( 'load', load ); }, /*! ?峰??绐??e??绱? */ _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; }, /*! 璁$???澶у??绐??f?剁??g??灏哄? */ _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 }; }, /*! 璁?E6 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浼??虹?版??澶у??杩?????绐??i???板?浣?锛???瀹?婊??ㄦ?″??E涓?灏变?瑙﹀??resize浜?浠?UG 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; // 绐??h???浜?浠 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; } }); // ???绘??棰?????澶у??杩?绐??d?浠 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; /*! 姝ゅ?璞$?ㄦ?ュ??ㄨ?峰??︾?圭??绐??e?璞″?渚? */ lhgdialog.focus = null; /*! 瀛??ㄧ??e?渚???瀵硅薄??琛 */ lhgdialog.list = {}; /*! * ?ㄥ?蹇??烽? * ?变?璺ㄦ??舵?朵?浠舵???瀹??版??椤跺?椤甸?????浠ュ?褰???椤甸?㈠?歌浇?跺?椤昏??ょЩ姝や?浠 * ??浠ュ?椤?nbind姝や?浠剁?瀹????芥?帮???浠ヨ???瑕?缁?缁?瀹???浜?浠跺?涔?涓??芥? * 杩??峰?ㄥ???椤甸?㈠?歌浇?跺氨??互绉绘?浜?浠剁?瀹????稿??芥?帮?涓???涓?褰卞??椤跺?椤甸?㈡?浜?浠剁?瀹????跺??芥? */ 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, // 绐??f???﹁???ㄨ?峰???︾? parent: null, // ??寮?瀛?绐??g???剁??e?璞★?涓昏??ㄤ?澶?灞???灞?绐?? padding: '10px', // ??瀹逛?杈圭??濉???璺?绂 fixed: false, // ???﹂??姝㈠?浣? left: '50%', // X杞村???? top: '38.2%', // Y杞村???? max: true, // ???︽?剧ず??澶у????? min: true, // ???︽?剧ず??灏?????? zIndex: 1976, // 瀵硅?妗?????楂?搴﹀????瑕?锛?姝ゅ?间??借?杩?娴?瑙??ㄦ??澶ч???? resize: true, // ???﹀??璁哥?ㄦ?疯???灏哄? drag: true, // ???﹀??璁哥?ㄦ?锋???ㄤ?缃 cache: true, // ???︾?瀛?绐??e??瀹归〉 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(); // 浣跨??oading灞?缃?《绐??f?剁??eぇ灏??瑰???稿?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); }; /*! * 椤甸??OM??杞藉????ц???浠g?? */ $(function(){ // 瑙﹀??娴?瑙??ㄩ???缂?瀛??????剧?? setTimeout(function() { if(_count) return; lhgdialog({left:'-9999em',time:9,fixed:false,lock:false,focus:false}); },150); // 澧?寮?hgdialog???戒?楠?锛?????澶?缃?ā??锛?濡?涓???瑕??????わ? // ?叉?榧????藉??frame瀵艰?翠?娴???锛?瀵硅?澶у?璇?妗????ㄤ??? 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); }); /*! 浣跨??Q?瑰?璋??ㄧ?? */ $.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} ?剧ず?堕? (榛?璁?.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 );