diff --git a/index.html b/index.html index ef61a19..7d0a671 100644 --- a/index.html +++ b/index.html @@ -166,6 +166,10 @@ + + + + + _runScript: function (elem) { + var fun, i = 0, n = 0, + tags = elem.getElementsByTagName('script'), + length = tags.length, + script = []; + + for (; i < length; i ++) { + if (tags[i].type === 'text/dialog') { + script[n] = tags[i].innerHTML; + n ++; + }; + }; + + if (script.length) { + script = script.join(''); + fun = new Function(script); + fun.call(this); + }; + }, + + // 自动切换定位类型 + _autoPositionType: function () { + this[this.config.fixed ? '_setFixed' : '_setAbsolute']();///////////// + }, + + + // 设置静止定位 + // IE6 Fixed @see: http://www.planeart.cn/?p=877 + _setFixed: (function () { + _isIE6 && $(function () { + var bg = 'backgroundAttachment'; + if (_$html.css(bg) !== 'fixed' && _$body.css(bg) !== 'fixed') { + _$html.css({ + zoom: 1,// 避免偶尔出现body背景图片异常的情况 + backgroundImage: 'url(about:blank)', + backgroundAttachment: 'fixed' + }); + }; + }); + + return function () { + var $elem = this.DOM.wrap, + style = $elem[0].style; + + if (_isIE6) { + var left = parseInt($elem.css('left')), + top = parseInt($elem.css('top')), + sLeft = _$document.scrollLeft(), + sTop = _$document.scrollTop(), + txt = '(document.documentElement)'; + + this._setAbsolute(); + style.setExpression('left', 'eval(' + txt + '.scrollLeft + ' + + (left - sLeft) + ') + "px"'); + style.setExpression('top', 'eval(' + txt + '.scrollTop + ' + + (top - sTop) + ') + "px"'); + } else { + style.position = 'fixed'; + }; + }; + }()), + + // 设置绝对定位 + _setAbsolute: function () { + var style = this.DOM.wrap[0].style; + + if (_isIE6) { + 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 (test) { + var newSize, + that = this, + oldSize = that._winSize || _$window.width() * _$window.height(), + elem = that._follow, + width = that._width, + height = that._height, + left = that._left, + top = that._top; + + if (test) { + // IE6~7 window.onresize bug + newSize = that._winSize = _$window.width() * _$window.height(); + if (oldSize === newSize) return; + }; + + if (width || height) that.size(width, height); + + if (elem) { + that.follow(elem); + } else if (left || top) { + that.position(left, top); + }; + }, + + // 事件代理 + _addEvent: function () { + var resizeTimer, + that = this, + config = that.config, + isIE = 'CollectGarbage' in window, + DOM = that.DOM; + + // 窗口调节事件 + that._winResize = function () { + resizeTimer && clearTimeout(resizeTimer); + resizeTimer = setTimeout(function () { + that._reset(isIE); + }, 40); + }; + _$window.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(config.cancelVal); + return false; + } else { + callbackID = target[_expando + 'callback']; + callbackID && that._click(callbackID); + }; + + that._ie6SelectFix(); + }) + .bind('mousedown', function () { + that.zIndex(); + }); + }, + + // 卸载事件代理 + _removeEvent: function () { + var that = this, + DOM = that.DOM; + + DOM.wrap.unbind(); + _$window.unbind('resize', that._winResize); + } + +}; + +artDialog.fn._init.prototype = artDialog.fn; +$.fn.dialog = $.fn.artDialog = function () { + var config = arguments; + this[this.live ? 'live' : 'bind']('click', function () { + artDialog.apply(this, config); + return false; + }); + return this; +}; + + + +/** 最顶层的对话框API */ +artDialog.focus = null; + + + +/** 对话框列表 */ +artDialog.list = {}; + + + +// 全局快捷键 +_$document.bind('keydown', function (event) { + var target = event.target, + nodeName = target.nodeName, + rinput = /^INPUT|TEXTAREA$/, + api = artDialog.focus, + keyCode = event.keyCode; + + if (!api || !api.config.esc || rinput.test(nodeName)) return; + + keyCode === 27 && api._click(api.config.cancelVal); +}); + + + +// 获取artDialog路径 +_path = window['_artDialog_path'] || (function (script, i, me) { + for (i in script) { + // 如果通过第三方脚本加载器加载本文件,请保证文件名含有"artDialog"字符 + if (script[i].src && script[i].src.indexOf('artDialog') !== -1) me = script[i]; + }; + + _thisScript = me || script[script.length - 1]; + me = _thisScript.src.replace(/\\/g, '/'); + return me.lastIndexOf('/') < 0 ? '.' : me.substring(0, me.lastIndexOf('/')); +}(document.getElementsByTagName('script'))); + + + +// 无阻塞载入CSS (如"artDialog.js?skin=aero") +_skin = _thisScript.src.split('skin=')[1]; +if (_skin) { + var link = document.createElement('link'); + link.rel = 'stylesheet'; + link.href = _path + '/skins/' + _skin + '.css?' + artDialog.fn.version; + _thisScript.parentNode.insertBefore(link, _thisScript); +}; + + + +// 触发浏览器预先缓存背景图片 +_$window.bind('load', function () { + setTimeout(function () { + if (_count) return; + artDialog({left: '-9999em',time: 9,fixed: false,lock: false,focus: false}); + }, 150); +}); + + + +// 开启IE6 CSS背景图片缓存 +try { + document.execCommand('BackgroundImageCache', false, true); +} catch (e) {}; + + + + +// 使用uglifyjs压缩能够预先处理"+"号以合并字符串 +// uglifyjs: http://marijnhaverbeke.nl/uglifyjs +artDialog.fn._templates = +'
' ++ ' | ' ++ ' | ' ++ ' | ||||||
' ++ ' | '
++ ' '
++ ' '
++ '
| '
++ '' ++ ' | ||||||
' ++ ' | ' ++ ' | ' ++ ' |