锘?*! * 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 鑾峰彇缁勪欢鏍稿績鏂囦欢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涓簍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涓婩ixed鏃犳姈鍔ㄩ潤姝㈠畾浣 * 濡傛灉浣犵殑椤甸潰鐨刪tml鍏冪礌璁惧畾浜嗚儗鏅浘鐗囪鎶婅缃儗鏅浘鐗囩殑css鍐欏埌body鍏冪礌涓 * 濡傛灉浣犱笉闇€瑕佺粍浠堕潤姝㈠畾浣嶏紙涔熷氨鏄殢灞忔粴鍔級鎴栨娈典唬鐮佸奖鍝嶄簡浣犵殑椤甸潰甯冨眬鍙皢姝ゆ浠g爜鍒犻櫎 */ _ie6 && (function(bg){ if( _$html.css(bg) !== 'fixed' ) { _$html.css({ zoom: 1,// 閬垮厤鍋跺皵鍑虹幇body鑳屾櫙鍥剧墖寮傚父鐨勬儏鍐 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; // 濡傛灉瀹氫箟浜唅d鍙傛暟鍒欒繑鍥炲瓨鍦ㄦ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'; //褰揷ancel鍙傛暟涓篺alse鏃堕殣钘忓叧闂寜閽 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} 鍐呭 (濡傛灉鍐呭鍓?涓瓧绗︿负鈥榰rl:鈥欏氨鍔犺浇鍗曠嫭椤甸潰鐨勫唴瀹归〉) * @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; }, /*! 瑙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鏂瑰紡鍔犺浇鍐呭椤垫椂鐨勫鐞嗕唬鐮 if( that.iframe ) { if( typeof fn === 'function' && fn.call(that, that.iframe.contentWindow, window) === false ) return that; // 閲嶈锛侀渶瑕侀噸缃甶frame鍦板潃锛屽惁鍒欎笅娆″嚭鐜扮殑瀵硅瘽妗嗗湪IE6銆?鏃犳硶鑱氱劍input // IE鍒犻櫎iframe鍚庯紝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]; // 绉婚櫎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(); // 娓呯┖闄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(); // 瀛樺偍鏈€澶у寲绐楀彛鍓嶇殑鐘舵€ 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璞℃垨绐楀彛涓璱frame鍔犺浇鐨勫唴瀹归〉鐨剋indow瀵硅薄 * @param {String} 鎸囧畾鐨刬d * @param {String} 鏄惁杩斿洖鐨勪负鎸囧畾id鐨勭獥鍙e璞 * 鐢ㄦ暟瀛?鏉ヨ〃绀虹湡锛屽鏋滀笉鍐欐垨鍐欏叾瀹冧负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, 鎸囧畾椤甸潰鐨剋indow瀵硅薄} * @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鐨剆rc灞炴€э紝IE6涓嬩笉寤惰繜鍔犺浇浼氬嚭鐜板姞杞借繘搴︽潯鐨凚UG that._frmTimer = setTimeout(function(){ $iframe.attr('src', url); }, 1); // iframe涓〉闈㈠姞杞藉畬鎴愬悗鎵ц鐨勫嚱鏁 var load = that._fmLoad = function() { $content.addClass('ui_state_full'); // 澧炲己绐楀彛缃《鍔熻兘锛宨frame鏂瑰紡鍔犺浇鍐呭鎴栬法鍩熷姞杞藉唴瀹归〉鏃剁偣绐楀彛鍐呭閮ㄥ垎缃《绐楀彛 // 閫氳繃浣跨敤閲嶇疆loading灞傛潵浼橀泤鐨勫畬鎴愭鍔熻兘锛屽湪focus鏂规硶涓湁姝ゅ姛鑳界殑鐩稿叧浠g爜 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瀵硅瘽妗嗘牱寮忔覆鏌撳紓甯 // 绐楀彛鏈€澶у寲鏃惰繖閲屼笉鐢ㄥ啀璁$畻绐楀彛鐨勫昂瀵稿拰浣嶇疆浜嗭紝濡傛灉鍐嶈绠楃獥鍙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灞炴€т负绐楀彛鑷韩瀵硅薄锛屽湪鍐呭椤典腑姝ゅ睘鎬у緢閲嶈 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; }, /*! 璁$畻鏈€澶у寲绐楀彛鏃剁獥鍙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噸鏂板畾浣嶏紝閿佸畾婊氬姩鏉″湪IE涓嬪氨浼氳Е鍙憆esize浜嬩欢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; } }); // 鍙屽嚮鏍囬鏍忔渶澶у寲杩樼獥鍙d簨浠 if( config.max ) DOM.title.bind('dblclick',function(){ that.max(); return false; }); }, /*! 鍗歌浇浜嬩欢浠g悊 */ _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 = {}; /*! * 鍏ㄥ眬蹇嵎閿 * 鐢变簬璺ㄦ鏋舵椂浜嬩欢鏄粦瀹氬埌鏈€椤跺眰椤甸潰锛屾墍浠ュ綋褰撳墠椤甸潰鍗歌浇鏃跺繀椤昏闄ょЩ姝や簨浠 * 鎵€浠ュ繀椤籾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, // 绐楀彛鏄惁鑷姩鑾峰彇鐒︾偣 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, // 鏄惁缂撳瓨绐楀彛鍐呭椤 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灞傜疆椤剁獥鍙f椂绐楀彛澶у皬鏀瑰彉鐩稿簲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.dialog2 = function() { var config = arguments; this.bind('click',function(){ lhgdialog.apply(this,config); return false; }); return this; }; window.lhgdialog = $.dialog2 = 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: true, resize: false }) .content(content) .time(time || 1.5, reIcon); }; })( this.jQuery||this.lhgcore, this.lhgdialog );