/*! * artdialog 4.1.6 * date: 2012-07-16 22:57 * http://code.google.com/p/artdialog/ * (c) 2009-2012 tangbin, http://www.planeart.cn * * this is licensed under the gnu lgpl, version 2.1 or later. * for details, see: http://creativecommons.org/licenses/lgpl/2.1/ */ ;(function (window, undefined) { //if (window.jquery) return jquery; var $ = window.art = function (selector, context) { return new $.fn.init(selector, context); }, readybound = false, readylist = [], domcontentloaded, isopacity = 'opacity' in document.documentelement.style, quickexpr = /^(?:[^<]*(<[\w\w]+>)[^>]*$|#([\w\-]+)$)/, rclass = /[\n\t]/g, ralpha = /alpha\([^)]*\)/i, ropacity = /opacity=([^)]*)/, rfxnum = /^([+-]=)?([\d+-.]+)(.*)$/; if (window.$ === undefined) window.$ = $; $.fn = $.prototype = { constructor: $, /** * dom 就绪 * @param {function} 回调函数 */ ready: function (callback) { $.bindready(); if ($.isready) { callback.call(document, $); } else if (readylist) { readylist.push(callback); }; return this; }, /** * 判断样式类是否存在 * @param {string} 名称 * @return {boolean} */ hasclass: function (name) { var classname = ' ' + name + ' '; if ((' ' + this[0].classname + ' ').replace(rclass, ' ') .indexof(classname) > -1) return true; return false; }, /** * 添加样式类 * @param {string} 名称 */ addclass: function (name) { if (!this.hasclass(name)) this[0].classname += ' ' + name; return this; }, /** * 移除样式类 * @param {string} 名称 */ removeclass: function (name) { var elem = this[0]; if (!name) { elem.classname = ''; } else if (this.hasclass(name)) { elem.classname = elem.classname.replace(name, ' '); }; return this; }, /** * 读写样式
* css(name) 访问第一个匹配元素的样式属性
* css(properties) 把一个"名/值对"对象设置为所有匹配元素的样式属性
* css(name, value) 在所有匹配的元素中,设置一个样式属性的值
*/ css: function (name, value) { var i, elem = this[0], obj = arguments[0]; if (typeof name === 'string') { if (value === undefined) { return $.css(elem, name); } else { name === 'opacity' ? $.opacity.set(elem, value) : elem.style[name] = value; }; } else { for (i in obj) { i === 'opacity' ? $.opacity.set(elem, obj[i]) : elem.style[i] = obj[i]; }; }; return this; }, /** 显示元素 */ show: function () { return this.css('display', 'block'); }, /** 隐藏元素 */ hide: function () { return this.css('display', 'none'); }, /** * 获取相对文档的坐标 * @return {object} 返回left、top的数值 */ offset: function () { var elem = this[0], box = elem.getboundingclientrect(), doc = elem.ownerdocument, body = doc.body, docelem = doc.documentelement, clienttop = docelem.clienttop || body.clienttop || 0, clientleft = docelem.clientleft || body.clientleft || 0, top = box.top + (self.pageyoffset || docelem.scrolltop) - clienttop, left = box.left + (self.pagexoffset || docelem.scrollleft) - clientleft; return { left: left, top: top }; }, /** * 读写html - (不支持文本框) * @param {string} 内容 */ html: function (content) { var elem = this[0]; if (content === undefined) return elem.innerhtml; $.cleandata(elem.getelementsbytagname('*')); elem.innerhtml = content; return this; }, /** * 移除节点 */ remove: function () { var elem = this[0]; $.cleandata(elem.getelementsbytagname('*')); $.cleandata([elem]); elem.parentnode.removechild(elem); return this; }, /** * 事件绑定 * @param {string} 类型 * @param {function} 要绑定的函数 */ bind: function (type, callback) { $.event.add(this[0], type, callback); return this; }, /** * 移除事件 * @param {string} 类型 * @param {function} 要卸载的函数 */ unbind: function(type, callback) { $.event.remove(this[0], type, callback); return this; } }; $.fn.init = function (selector, context) { var match, elem; context = context || document; if (!selector) return this; if (selector.nodetype) { this[0] = selector; return this; }; if (selector === 'body' && context.body) { this[0] = context.body; return this; }; if (selector === 'head' || selector === 'html') { this[0] = context.getelementsbytagname(selector)[0]; return this; }; if (typeof selector === 'string') { match = quickexpr.exec(selector); if (match && match[2]) { elem = context.getelementbyid(match[2]); if (elem && elem.parentnode) this[0] = elem; return this; }; }; if (typeof selector === 'function') return $(document).ready(selector); this[0] = selector; return this; }; $.fn.init.prototype = $.fn; /** 空函数 */ $.noop = function () {}; /** 检测window */ $.iswindow = function (obj) { return obj && typeof obj === 'object' && 'setinterval' in obj; }; /** 数组判定 */ $.isarray = function (obj) { return object.prototype.tostring.call(obj) === '[object array]'; }; /** * 搜索子元素 * 注意:只支持nodename或.classname的形式,并且只返回第一个元素 * @param {string} */ $.fn.find = function (expr) { var value, elem = this[0], classname = expr.split('.')[1]; if (classname) { if (document.getelementsbyclassname) { value = elem.getelementsbyclassname(classname); } else { value = getelementsbyclassname(classname, elem); }; } else { value = elem.getelementsbytagname(expr); }; return $(value[0]); }; function getelementsbyclassname (classname, node, tag) { node = node || document; tag = tag || '*'; var i = 0, j = 0, classelements = [], els = node.getelementsbytagname(tag), elslen = els.length, pattern = new regexp("(^|\\s)" + classname + "(\\s|$)"); for (; i < elslen; i ++) { if (pattern.test(els[i].classname)) { classelements[j] = els[i]; j ++; }; }; return classelements; }; /** * 遍历 * @param {object} * @param {function} */ $.each = function (obj, callback) { var name, i = 0, length = obj.length, isobj = length === undefined; if (isobj) { for (name in obj) { if (callback.call(obj[name], name, obj[name]) === false) break; }; } else { for (var value = obj[0]; i < length && callback.call(value, i, value) !== false; value = obj[++i]) {}; }; return obj; }; /** * 读写缓存 * @param {htmlelement} 元素 * @param {string} 缓存名称 * @param {any} 数据 * @return {any} 如果无参数data则返回缓存数据 */ $.data = function (elem, name, data) { var cache = $.cache, id = uuid(elem); if (name === undefined) return cache[id]; if (!cache[id]) cache[id] = {}; if (data !== undefined) cache[id][name] = data; return cache[id][name]; }; /** * 删除缓存 * @param {htmlelement} 元素 * @param {string} 缓存名称 */ $.removedata = function (elem, name) { var empty = true, expando = $.expando, cache = $.cache, id = uuid(elem), thiscache = id && cache[id]; if (!thiscache) return; if (name) { delete thiscache[name]; for (var n in thiscache) empty = false; if (empty) delete $.cache[id]; } else { delete cache[id]; if (elem.removeattribute) { elem.removeattribute(expando); } else { elem[expando] = null; }; }; }; $.uuid = 0; $.cache = {}; $.expando = '@cache' + + new date // 标记元素唯一身份 function uuid (elem) { var expando = $.expando, id = elem === window ? 0 : elem[expando]; if (id === undefined) elem[expando] = id = ++ $.uuid; return id; }; /** * 事件机制 * @namespace * @requires [$.data, $.removedata] */ $.event = { /** * 添加事件 * @param {htmlelement} 元素 * @param {string} 事件类型 * @param {function} 要添加的函数 */ add: function (elem, type, callback) { var cache, listeners, that = $.event, data = $.data(elem, '@events') || $.data(elem, '@events', {}); cache = data[type] = data[type] || {}; listeners = cache.listeners = cache.listeners || []; listeners.push(callback); if (!cache.handler) { cache.elem = elem; cache.handler = that.handler(cache); elem.addeventlistener ? elem.addeventlistener(type, cache.handler, false) : elem.attachevent('on' + type, cache.handler); }; }, /** * 卸载事件 * @param {htmlelement} 元素 * @param {string} 事件类型 * @param {function} 要卸载的函数 */ remove: function (elem, type, callback) { var i, cache, listeners, that = $.event, empty = true, data = $.data(elem, '@events'); if (!data) return; if (!type) { for (i in data) that.remove(elem, i); return; }; cache = data[type]; if (!cache) return; listeners = cache.listeners; if (callback) { for (i = 0; i < listeners.length; i ++) { listeners[i] === callback && listeners.splice(i--, 1); }; } else { cache.listeners = []; }; if (cache.listeners.length === 0) { elem.removeeventlistener ? elem.removeeventlistener(type, cache.handler, false) : elem.detachevent('on' + type, cache.handler); delete data[type]; cache = $.data(elem, '@events'); for (var n in cache) empty = false; if (empty) $.removedata(elem, '@events'); }; }, /** @inner 事件句柄 */ handler: function (cache) { return function (event) { event = $.event.fix(event || window.event); for (var i = 0, list = cache.listeners, fn; fn = list[i++];) { if (fn.call(cache.elem, event) === false) { event.preventdefault(); event.stoppropagation(); }; }; }; }, /** @inner event对象兼容处理 */ fix: function (event) { if (event.target) return event; var event2 = { target: event.srcelement || document, preventdefault: function () {event.returnvalue = false}, stoppropagation: function () {event.cancelbubble = true} }; // ie6/7/8 在原生window.event对象写入数据会导致内存无法回收,应当采用拷贝 for (var i in event) event2[i] = event[i]; return event2; } }; /** * 清理元素集的事件与缓存 * @requires [$.removedata, $.event] * @param {htmlcollection} 元素集 */ $.cleandata = function (elems) { var i = 0, elem, len = elems.length, removeevent = $.event.remove, removedata = $.removedata; for (; i < len; i ++) { elem = elems[i]; removeevent(elem); removedata(elem); }; }; // dom就绪事件 $.isready = false; $.ready = function () { if (!$.isready) { if (!document.body) return settimeout($.ready, 13); $.isready = true; if (readylist) { var fn, i = 0; while ((fn = readylist[i++])) { fn.call(document, $); }; readylist = null; }; }; }; $.bindready = function () { if (readybound) return; readybound = true; if (document.readystate === 'complete') { return $.ready(); }; if (document.addeventlistener) { document.addeventlistener('domcontentloaded', domcontentloaded, false); window.addeventlistener('load', $.ready, false); } else if (document.attachevent) { document.attachevent('onreadystatechange', domcontentloaded); window.attachevent('onload', $.ready); var toplevel = false; try { toplevel = window.frameelement == null; } catch (e) {}; if (document.documentelement.doscroll && toplevel) { doscrollcheck(); }; }; }; if (document.addeventlistener) { domcontentloaded = function () { document.removeeventlistener('domcontentloaded', domcontentloaded, false); $.ready(); }; } else if (document.attachevent) { domcontentloaded = function () { if (document.readystate === 'complete') { document.detachevent('onreadystatechange', domcontentloaded); $.ready(); }; }; }; function doscrollcheck () { if ($.isready) return; try { document.documentelement.doscroll('left'); } catch (e) { settimeout(doscrollcheck, 1); return; }; $.ready(); }; // 获取css $.css = 'defaultview' in document && 'getcomputedstyle' in document.defaultview ? function (elem, name) { return document.defaultview.getcomputedstyle(elem, false)[name]; } : function (elem, name) { var ret = name === 'opacity' ? $.opacity.get(elem) : elem.currentstyle[name]; return ret || ''; }; // 跨浏览器处理opacity $.opacity = { get: function (elem) { return isopacity ? document.defaultview.getcomputedstyle(elem, false).opacity : ropacity.test((elem.currentstyle ? elem.currentstyle.filter : elem.style.filter) || '') ? (parsefloat(regexp.$1) / 100) + '' : 1; }, set: function (elem, value) { if (isopacity) return elem.style.opacity = value; var style = elem.style; style.zoom = 1; var opacity = 'alpha(opacity=' + value * 100 + ')', filter = style.filter || ''; style.filter = ralpha.test(filter) ? filter.replace(ralpha, opacity) : style.filter + ' ' + opacity; } }; /** * 获取滚动条位置 - [不支持写入] * $.fn.scrollleft, $.fn.scrolltop * @example 获取文档垂直滚动条:$(document).scrolltop() * @return {number} 返回滚动条位置 */ $.each(['left', 'top'], function (i, name) { var method = 'scroll' + name; $.fn[method] = function () { var elem = this[0], win; win = getwindow(elem); return win ? ('pagexoffset' in win) ? win[i ? 'pageyoffset' : 'pagexoffset'] : win.document.documentelement[method] || win.document.body[method] : elem[method]; }; }); function getwindow (elem) { return $.iswindow(elem) ? elem : elem.nodetype === 9 ? elem.defaultview || elem.parentwindow : false; }; /** * 获取窗口或文档尺寸 - [只支持window与document读取] * @example 获取文档宽度:$(document).width() 获取可视范围:$(window).width() * @return {number} */ $.each(['height', 'width'], function (i, name) { var type = name.tolowercase(); $.fn[type] = function (size) { var elem = this[0]; if (!elem) { return size == null ? null : this; }; return $.iswindow(elem) ? elem.document.documentelement['client' + name] || elem.document.body['client' + name] : (elem.nodetype === 9) ? math.max( elem.documentelement['client' + name], elem.body['scroll' + name], elem.documentelement['scroll' + name], elem.body['offset' + name], elem.documentelement['offset' + name] ) : null; }; }); /** * 简单ajax支持 * @example * $.ajax({ * url: url, * success: callback, * cache: cache * }); */ $.ajax = function (config) { var ajax = window.xmlhttprequest ? new xmlhttprequest() : new activexobject('microsoft.xmlhttp'), url = config.url; if (config.cache === false) { var ts = + new date, ret = url.replace(/([?&])_=[^&]*/, "$1_=" + ts ); url = ret + ((ret === url) ? (/\?/.test(url) ? "&" : "?") + "_=" + ts : ""); }; ajax.onreadystatechange = function() { if (ajax.readystate === 4 && ajax.status === 200) { config.success && config.success(ajax.responsetext); ajax.onreadystatechange = $.noop; }; }; ajax.open('get', url, 1); ajax.send(null); }; /** 动画引擎 - [不支持链式列队操作] */ $.fn.animate = function (prop, speed, easing, callback) { speed = speed || 400; if (typeof easing === 'function') callback = easing; easing = easing && $.easing[easing] ? easing : 'swing'; var elem = this[0], overflow, fx, parts, start, end, unit, opt = { speed: speed, easing: easing, callback: function () { if (overflow != null) elem.style.overflow = ''; callback && callback(); } }; opt.curanim = {}; $.each(prop, function (name, val) { opt.curanim[name] = val; }); $.each(prop, function (name, val) { fx = new $.fx(elem, opt, name); parts = rfxnum.exec(val); start = parsefloat(name === 'opacity' || (elem.style && elem.style[name] != null) ? $.css(elem, name) : elem[name]); end = parsefloat(parts[2]); unit = parts[3]; if (name === 'height' || name === 'width') { end = math.max(0, end); overflow = [elem.style.overflow, elem.style.overflowx, elem.style.overflowy]; }; fx.custom(start, end, unit); }); if (overflow != null) elem.style.overflow = 'hidden'; return this; }; $.timers = []; $.fx = function (elem, options, prop) { this.elem = elem; this.options = options; this.prop = prop; }; $.fx.prototype = { custom: function (from, to, unit) { var that = this; that.starttime = $.fx.now(); that.start = from; that.end = to; that.unit = unit; that.now = that.start; that.state = that.pos = 0; function t() { return that.step(); }; t.elem = that.elem; t(); $.timers.push(t); if (!$.timerid) $.timerid = setinterval($.fx.tick, 13); }, step: function () { var that = this, t = $.fx.now(), done = true; if (t >= that.options.speed + that.starttime) { that.now = that.end; that.state = that.pos = 1; that.update(); that.options.curanim[that.prop] = true; for (var i in that.options.curanim) { if (that.options.curanim[i] !== true) { done = false; }; }; if (done) that.options.callback.call(that.elem); return false; } else { var n = t - that.starttime; that.state = n / that.options.speed; that.pos = $.easing[that.options.easing](that.state, n, 0, 1, that.options.speed); that.now = that.start + ((that.end - that.start) * that.pos); that.update(); return true; }; }, update: function () { var that = this; if (that.prop === 'opacity') { $.opacity.set(that.elem, that.now); } else if (that.elem.style && that.elem.style[that.prop] != null) { that.elem.style[that.prop] = that.now + that.unit; } else { that.elem[that.prop] = that.now; }; } }; $.fx.now = function () { return + new date; }; $.easing = { linear: function (p, n, firstnum, diff) { return firstnum + diff * p; }, swing: function (p, n, firstnum, diff) { return ((-math.cos(p * math.pi) / 2) + 0.5) * diff + firstnum; } }; $.fx.tick = function () { var timers = $.timers; for (var i = 0; i < timers.length; i++) { !timers[i]() && timers.splice(i--, 1); }; !timers.length && $.fx.stop(); }; $.fx.stop = function () { clearinterval($.timerid); $.timerid = null; }; $.fn.stop = function () { var timers = $.timers; for (var i = timers.length - 1; i >= 0; i--) { if (timers[i].elem === this[0]) timers.splice(i, 1); }; return this; }; //-------------end return $}(window)); //------------------------------------------------ // 对话框模块 //------------------------------------------------ ;(function ($, window, undefined) { $.noop = $.noop || function () {}; // jquery 1.3.2 var _box, _thisscript, _skin, _path, _count = 0, _$window = $(window), _$document = $(document), _$html = $('html'), _elem = document.documentelement, _isie6 = window.vbarray && !window.xmlhttprequest, _ismobile = 'createtouch' in document && !('onmousemove' in _elem) || /(iphone|ipad|ipod)/i.test(navigator.useragent), _expando = 'artdialog' + + new date; var artdialog = function (config, ok, cancel) { config = config || {}; if (typeof config === 'string' || config.nodetype === 1) { config = {content: config, fixed: !_ismobile}; }; var api, defaults = artdialog.defaults, elem = config.follow = this.nodetype === 1 && this || config.follow; // 合并默认配置 for (var i in defaults) { if (config[i] === undefined) config[i] = defaults[i]; }; // 兼容v4.1.0之前的参数,未来版本将删除此 $.each({ok:"yesfn",cancel:"nofn",close:"closefn",init:"initfn",okval:"yestext",cancelval:"notext"}, function(i,o){config[i]=config[i]!==undefined?config[i]:config[o]}); // 返回跟随模式或重复定义的id if (typeof elem === 'string') elem = $(elem)[0]; config.id = elem && elem[_expando + 'follow'] || config.id || _expando + _count; api = artdialog.list[config.id]; if (elem && api) return api.follow(elem).zindex().focus(); art.phpcms_api = art.phpcms_api || []; var that_api = art.phpcms_api[config.id]; if (typeof that_api == 'object' && api) { api.data = {}; api.data.iframe = that_api }; if (api) return api.zindex().focus(); // 目前主流移动设备对fixed支持不好 if (_ismobile) config.fixed = false; // 按钮队列 if (!$.isarray(config.button)) { config.button = config.button ? [config.button] : []; }; if (ok !== undefined) config.ok = ok; if (cancel !== undefined) config.cancel = cancel; config.ok && config.button.push({ name: config.okval, callback: config.ok, focus: true }); config.cancel && config.button.push({ name: config.cancelval, callback: config.cancel }); // zindex全局配置 artdialog.defaults.zindex = config.zindex; _count ++; return artdialog.list[config.id] = _box ? _box._init(config) : new artdialog.fn._init(config); }; artdialog.fn = artdialog.prototype = { version: '4.1.6', closed: true, _init: function (config) { var that = this, dom, icon = config.icon, iconbg = icon && (_isie6 ? {png: 'icons/' + icon + '.png'} : {backgroundimage: 'url(\'' + config.path + '/skins/icons/' + icon + '.png\')'}); that.closed = false; that.config = config; that.dom = dom = that.dom || that._getdom(); dom.wrap.addclass(config.skin); dom.close[config.cancel === false ? 'hide' : 'show'](); dom.icon[0].style.display = icon ? '' : 'none'; dom.iconbg.css(iconbg || {background: 'none'}); dom.se.css('cursor', config.resize ? 'se-resize' : 'auto'); dom.title.css('cursor', config.drag ? 'move' : 'auto'); dom.content.css('padding', config.padding); that[config.show ? 'show' : 'hide'](true) that.button(config.button) .title(config.title) .content(config.content, config.iframe) .size(config.width, config.height) .time(config.time); config.follow ? that.follow(config.follow) : that.position(config.left, config.top); that.zindex().focus(); config.lock && that.lock(); that._addevent(); that._ie6pngfix(); _box = null; config.init && config.init.call(that, window); return that; }, /** * 设置内容 * @param {string, htmlelement} 内容 (可选) * @return {this, htmlelement} 如果无参数则返回内容容器dom对象 */ content: function (msg,url) { var prev, next, parent, display, 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, content = $content[0]; that._reset(1); iframe = null, isiframe = typeof url == 'string' && url != '', iframrid = 'atrdialogiframe_' + that.config.id; if (isiframe) { if (typeof pc_hash == 'string') url += (url.indexof('?') > -1 ? '&': '?') + 'pc_hash=' + pc_hash; iframe = document.createelement('iframe'); iframe.setattribute("frameborder", 0, 0); iframe.setattribute("width", that.config.width); iframe.setattribute("height", that.config.height); iframe.setattribute("padding", '0'); iframe.setattribute("id", iframrid); iframe.src = url; that.dom.content.css('padding', "5px 0px"); var _width = parseint(that.config.width)+5; that.dom.content.css('width', _width); that.dom.content.css('height', that.config.height); msg = iframe; }; that._elemback && that._elemback(); wrap.style.width = 'auto'; if (msg === undefined) return content; if (typeof msg === 'string') { $content.html(msg); } else if (msg && msg.nodetype === 1) { // 让传入的元素在对话框关闭后可以返回到原来的地方 display = msg.style.display; prev = msg.previoussibling; next = msg.nextsibling; parent = msg.parentnode; that._elemback = function () { if (prev && prev.parentnode) { prev.parentnode.insertbefore(msg, prev.nextsibling); } else if (next && next.parentnode) { next.parentnode.insertbefore(msg, next); } else if (parent) { parent.appendchild(msg); }; msg.style.display = display; that._elemback = null; }; $content.html(''); content.appendchild(msg); msg.style.display = 'block'; //content.focus(); //alert('1'); if (isiframe) art.phpcms_api[that.config.id] = msg.contentwindow }; // 新增内容后调整位置 if (!arguments[1]) { if (that.config.follow) { that.follow(that.config.follow); } else { 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(); that._runscript(content); return that; }, /** * 设置标题 * @param {string, boolean} 标题内容. 为false则隐藏标题栏 * @return {this, htmlelement} 如果无参数则返回内容器dom对象 */ title: function (text) { var dom = this.dom, wrap = dom.wrap, title = dom.title, classname = 'aui_state_notitle'; if (text === undefined) return title[0]; if (text === false) { title.hide().html(''); wrap.addclass(classname); } else { title.show().html(text || ''); wrap.removeclass(classname); }; return this; }, /** * 位置(相对于可视区域) * @param {number, string} * @param {number, string} */ position: function (left, top) { var that = this, config = that.config, wrap = that.dom.wrap[0], isfixed = _isie6 ? false : config.fixed, ie6fixed = _isie6 && that.config.fixed, docleft = _$document.scrollleft(), doctop = _$document.scrolltop(), dl = isfixed ? 0 : docleft, dt = isfixed ? 0 : doctop, ww = _$window.width(), wh = _$window.height(), ow = wrap.offsetwidth, oh = wrap.offsetheight, style = wrap.style; 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; style.left = math.max(left, dl) + 'px'; } else if (typeof left === 'string') { 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; style.top = math.max(top, dt) + 'px'; } else if (typeof top === 'string') { style.top = top; }; }; if (left !== undefined && top !== undefined) { that._follow = null; that._autopositiontype(); }; return that; }, /** * 尺寸 * @param {number, string} 宽度 * @param {number, string} 高度 */ size: function (width, height) { var maxwidth, maxheight, scalewidth, scaleheight, that = this, config = that.config, dom = that.dom, wrap = dom.wrap, main = dom.main, wrapstyle = wrap[0].style, style = main[0].style; if (width) { that._width = width.tostring().indexof('%') !== -1 ? width : null; maxwidth = _$window.width() - wrap[0].offsetwidth + main[0].offsetwidth; scalewidth = that._tonumber(width, maxwidth); width = scalewidth; if (typeof width === 'number') { wrapstyle.width = 'auto'; style.width = math.max(that.config.minwidth, width) + 'px'; wrapstyle.width = wrap[0].offsetwidth + 'px'; // 防止未定义宽度的表格遇到浏览器右边边界伸缩 } else if (typeof width === 'string') { style.width = width; width === 'auto' && wrap.css('width', 'auto'); }; }; if (height) { that._height = height.tostring().indexof('%') !== -1 ? height : null; maxheight = _$window.height() - wrap[0].offsetheight + main[0].offsetheight; scaleheight = that._tonumber(height, maxheight); height = scaleheight; //alert(height); if (typeof height === 'number') { style.height = math.max(that.config.minheight, height) + 'px'; } else if (typeof height === 'string') { style.height = height; //height === 'auto' && wrap.css('height', 'auto'); }; }; that._ie6selectfix(); return that; }, /** * 跟随元素 * @param {htmlelement, string} */ follow: function (elem) { var $elem, that = this, config = that.config; if (typeof elem === 'string' || elem && elem.nodetype === 1) { $elem = $(elem); elem = $elem[0]; }; // 隐藏元素不可用 if (!elem || !elem.offsetwidth && !elem.offsetheight) { return that.position(that._left, that._top); }; var expando = _expando + 'follow', winwidth = _$window.width(), winheight = _$window.height(), docleft = _$document.scrollleft(), doctop = _$document.scrolltop(), offset = $elem.offset(), width = elem.offsetwidth, height = elem.offsetheight, isfixed = _isie6 ? false : config.fixed, left = isfixed ? offset.left - docleft : offset.left, top = isfixed ? offset.top - doctop : offset.top, wrap = that.dom.wrap[0], style = wrap.style, wrapwidth = wrap.offsetwidth, wrapheight = wrap.offsetheight, setleft = left - (wrapwidth - width) / 2, settop = top + height, dl = isfixed ? 0 : docleft, dt = isfixed ? 0 : doctop; setleft = setleft < dl ? left : (setleft + wrapwidth > winwidth) && (left - wrapwidth > dl) ? left - wrapwidth + width : setleft; settop = (settop + wrapheight > winheight + dt) && (top - wrapheight > dt) ? top - wrapheight : settop; style.left = setleft + 'px'; style.top = settop + 'px'; that._follow && that._follow.removeattribute(expando); that._follow = elem; elem[expando] = config.id; that._autopositiontype(); return that; }, /** * 自定义按钮 * @example button({ name: 'login', callback: function () {}, disabled: false, focus: true }, .., ..) */ button: function () { var that = this, ags = arguments, dom = that.dom, buttons = dom.buttons, elem = buttons[0], strongbutton = 'aui_state_highlight', listeners = that._listeners = that._listeners || {}, list = $.isarray(ags[0]) ? ags[0] : [].slice.call(ags); if (ags[0] === undefined) return elem; $.each(list, function (i, val) { var name = val.name, isnewbutton = !listeners[name], button = !isnewbutton ? listeners[name].elem : document.createelement('button'); if (!listeners[name]) listeners[name] = {}; if (val.callback) listeners[name].callback = val.callback; if (val.classname) button.classname = val.classname; if (val.focus) { that._focus && that._focus.removeclass(strongbutton); that._focus = $(button).addclass(strongbutton); that.focus(); }; // internet explorer 的默认类型是 "button", // 而其他浏览器中(包括 w3c 规范)的默认值是 "submit" // @see http://www.w3school.com.cn/tags/att_button_type.asp button.setattribute('type', 'button'); button[_expando + 'callback'] = name; button.disabled = !!val.disabled; if (isnewbutton) { button.innerhtml = name; listeners[name].elem = button; elem.appendchild(button); }; }); buttons[0].style.display = list.length ? '' : 'none'; that._ie6selectfix(); return that; }, /** 显示对话框 */ show: function () { this.dom.wrap.show(); !arguments[0] && this._lockmaskwrap && this._lockmaskwrap.show(); return this; }, /** 隐藏对话框 */ hide: function () { this.dom.wrap.hide(); !arguments[0] && this._lockmaskwrap && this._lockmaskwrap.hide(); return this; }, /** 关闭对话框 */ close: function () { if (this.closed) return this; var that = this, dom = that.dom, wrap = dom.wrap, list = artdialog.list, fn = that.config.close, follow = that.config.follow; that.time(); if (typeof fn === 'function' && fn.call(that, window) === false) { return that; }; that.unlock(); // 置空内容 that._elemback && that._elemback(); wrap[0].classname = wrap[0].style.csstext = ''; dom.title.html(''); dom.content.html(''); dom.buttons.html(''); if (artdialog.focus === that) artdialog.focus = null; if (follow) follow.removeattribute(_expando + 'follow'); delete list[that.config.id]; that._removeevent(); that.hide(true)._setabsolute(); // 清空除this.dom之外临时对象,恢复到初始状态,以便使用单例模式 for (var i in that) { if (that.hasownproperty(i)) delete that[i]; }; // 移除htmlelement或重用 _box ? wrap.remove() : _box = that; return that; }, /** * 定时关闭 * @param {number} 单位为秒, 无参数则停止计时器 */ time: function (second) { var that = this, cancel = that.config.cancelval, timer = that._timer; timer && cleartimeout(timer); if (second) { that._timer = settimeout(function(){ that._click(cancel); }, 1000 * second); }; return that; }, /** 设置焦点 */ focus: function () { try { var elem = this._focus && this._focus[0] || this.dom.close[0]; elem && elem.focus(); } catch (e) {}; // ie对不可见元素设置焦点会报错 return this; }, /** 置顶对话框 */ zindex: function () { var that = this, dom = that.dom, wrap = dom.wrap, top = artdialog.focus, index = artdialog.defaults.zindex ++; // 设置叠加高度 wrap.css('zindex', index); that._lockmask && that._lockmask.css('zindex', index - 1); // 设置最高层的样式 top && top.dom.wrap.removeclass('aui_state_focus'); artdialog.focus = that; wrap.addclass('aui_state_focus'); return that; }, /** 设置屏锁 */ lock: function () { if (this._lock) return this; var that = this, index = artdialog.defaults.zindex - 1, wrap = that.dom.wrap, config = that.config, docwidth = _$document.width(), docheight = _$document.height(), lockmaskwrap = that._lockmaskwrap || $(document.body.appendchild(document.createelement('div'))), lockmask = that._lockmask || $(lockmaskwrap[0].appendchild(document.createelement('div'))), domtxt = '(document).documentelement', sizecss = _ismobile ? 'width:' + docwidth + 'px;height:' + docheight + 'px' : 'width:100%;height:100%', ie6css = _isie6 ? 'position:absolute;left:expression(' + domtxt + '.scrollleft);top:expression(' + domtxt + '.scrolltop);width:expression(' + domtxt + '.clientwidth);height:expression(' + domtxt + '.clientheight)' : ''; that.zindex(); wrap.addclass('aui_state_lock'); lockmaskwrap[0].style.csstext = sizecss + ';position:fixed;z-index:' + index + ';top:0;left:0;overflow:hidden;' + ie6css; lockmask[0].style.csstext = 'height:100%;background:' + config.background + ';filter:alpha(opacity=0);opacity:0'; // 让ie6锁屏遮罩能够盖住下拉控件 if (_isie6) lockmask.html( ''); lockmask.stop(); lockmask.bind('click', function () { that._reset(); }).bind('dblclick', function () { that._click(that.config.cancelval); }); if (config.duration === 0) { lockmask.css({opacity: config.opacity}); } else { lockmask.animate({opacity: config.opacity}, config.duration); }; that._lockmaskwrap = lockmaskwrap; that._lockmask = lockmask; that._lock = true; return that; }, /** 解开屏锁 */ unlock: function () { var that = this, lockmaskwrap = that._lockmaskwrap, lockmask = that._lockmask; if (!that._lock) return that; var style = lockmaskwrap[0].style; var un = function () { if (_isie6) { style.removeexpression('width'); style.removeexpression('height'); style.removeexpression('left'); style.removeexpression('top'); }; style.csstext = 'display:none'; _box && lockmaskwrap.remove(); }; lockmask.stop().unbind(); that.dom.wrap.removeclass('aui_state_lock'); if (!that.config.duration) {// 取消动画,快速关闭 un(); } else { lockmask.animate({opacity: 0}, that.config.duration, un); }; that._lock = false; return that; }, // 获取元素 _getdom: function () { var wrap = document.createelement('div'), body = document.body; wrap.style.csstext = 'position:absolute;left:0;top:0'; wrap.innerhtml = artdialog._templates; body.insertbefore(wrap, body.firstchild); var name, i = 0, dom = {wrap: $(wrap)}, els = wrap.getelementsbytagname('*'), elslen = els.length; for (; i < elslen; i ++) { name = els[i].classname.split('aui_')[1]; if (name) dom[name] = $(els[i]); }; return dom; }, // px与%单位转换成数值 (百分比单位按照最大值换算) // 其他的单位返回原值 _tonumber: function (thisvalue, maxvalue) { if (!thisvalue && thisvalue !== 0 || typeof thisvalue === 'number') { return thisvalue; }; var last = thisvalue.length - 1; if (thisvalue.lastindexof('px') === last) { thisvalue = parseint(thisvalue); } else if (thisvalue.lastindexof('%') === last) { thisvalue = parseint(maxvalue * thisvalue.split('%')[0] / 100); }; return thisvalue; }, // 让ie6 css支持png背景 _ie6pngfix: _isie6 ? function () { var i = 0, elem, png, pngpath, runtimestyle, path = artdialog.defaults.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='crop')"; }; }; } : $.noop, // 强制覆盖ie6下拉控件 _ie6selectfix: _isie6 ? 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(document.createelement('iframe')); $wrap[expando] = iframe; iframe.src = 'about:blank'; iframe.style.csstext = 'position:absolute;z-index:-1;left:0;top:0;' + 'filter:alpha(opacity=0);width:' + width + ';height:' + height; }; } : $.noop, // 解析html片段中自定义类型脚本,其this指向artdialog内部 // _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; /** 获取某对话框api */ artdialog.get = function (id) { return id === undefined ? artdialog.list : artdialog.list[id]; }; 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._templates = '
' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
' + '
' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
' + '
' + '
' + '' + '\xd7' + '' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' +'
'; /** * 默认配置 */ artdialog.defaults = { // 消息内容 content: '
loading..
', title: '\u6d88\u606f', // 标题. 默认'消息' button: null, // 自定义按钮 ok: null, // 确定按钮回调函数 cancel: null, // 取消按钮回调函数 init: null, // 对话框初始化后执行的函数 close: null, // 对话框关闭前执行的函数 okval: '\u786e\u5b9a', // 确定按钮文本. 默认'确定' cancelval: '\u53d6\u6d88', // 取消按钮文本. 默认'取消' width: 'auto', // 内容宽度 height: 'auto', // 内容高度 minwidth: 96, // 最小宽度限制 minheight: 32, // 最小高度限制 padding: '20px 25px', // 内容与边界填充距离 skin: '', // 皮肤名(预留接口,尚未实现) icon: null, // 消息图标名称 time: null, // 自动关闭时间 esc: true, // 是否支持esc键关闭 focus: true, // 是否支持对话框按钮自动聚焦 show: true, // 初始化后是否显示对话框 follow: null, // 跟随某元素(即让对话框在元素附近弹出) path: _path, // artdialog路径 lock: true, // 是否锁屏 background: '#000', // 遮罩颜色 opacity: .7, // 遮罩透明度 duration: 300, // 遮罩透明度渐变动画速度 fixed: false, // 是否静止定位 left: '50%', // x轴坐标 top: '38.2%', // y轴坐标 zindex: 1987, // 对话框叠加高度值(重要:此值不能超过浏览器最大限制) resize: true, // 是否允许用户调节尺寸 drag: true // 是否允许用户拖动位置 }; window.artdialog = $.dialog = $.artdialog = artdialog; }(this.art || this.jquery && (this.art = jquery), this)); //------------------------------------------------ // 对话框模块-拖拽支持(可选外置模块) //------------------------------------------------ ;(function ($) { var _dragevent, _use, _$window = $(window), _$document = $(document), _elem = document.documentelement, _isie6 = !('minwidth' in _elem.style), _islosecapture = 'onlosecapture' in _elem, _issetcapture = 'setcapture' in _elem; // 拖拽事件 artdialog.dragevent = function () { var that = this, proxy = function (name) { var fn = that[name]; that[name] = function () { return fn.apply(that, arguments); }; }; proxy('start'); proxy('move'); proxy('end'); }; artdialog.dragevent.prototype = { // 开始拖拽 onstart: $.noop, start: function (event) { _$document .bind('mousemove', this.move) .bind('mouseup', this.end); this._sclientx = event.clientx; this._sclienty = event.clienty; this.onstart(event.clientx, event.clienty); return false; }, // 正在拖拽 onmove: $.noop, move: function (event) { this._mclientx = event.clientx; this._mclienty = event.clienty; this.onmove( event.clientx - this._sclientx, event.clienty - this._sclienty ); return false; }, // 结束拖拽 onend: $.noop, end: function (event) { _$document .unbind('mousemove', this.move) .unbind('mouseup', this.end); this.onend(event.clientx, event.clienty); return false; } }; _use = function (event) { var limit, startwidth, startheight, startleft, starttop, isresize, api = artdialog.focus, //config = api.config, dom = api.dom, wrap = dom.wrap, title = dom.title, main = dom.main; // 清除文本选择 var clsselect = 'getselection' in window ? function () { window.getselection().removeallranges(); } : function () { try { document.selection.empty(); } catch (e) {}; }; // 对话框准备拖动 _dragevent.onstart = function (x, y) { if (isresize) { startwidth = main[0].offsetwidth; startheight = main[0].offsetheight; } else { startleft = wrap[0].offsetleft; starttop = wrap[0].offsettop; }; _$document.bind('dblclick', _dragevent.end); !_isie6 && _islosecapture ? title.bind('losecapture', _dragevent.end) : _$window.bind('blur', _dragevent.end); _issetcapture && title[0].setcapture(); wrap.addclass('aui_state_drag'); api.focus(); }; // 对话框拖动进行中 _dragevent.onmove = function (x, y) { if (isresize) { var wrapstyle = wrap[0].style, style = main[0].style, width = x + startwidth, height = y + startheight; wrapstyle.width = 'auto'; style.width = math.max(0, width) + 'px'; wrapstyle.width = wrap[0].offsetwidth + 'px'; style.height = math.max(0, height) + 'px'; } else { var style = wrap[0].style, left = math.max(limit.minx, math.min(limit.maxx, x + startleft)), top = math.max(limit.miny, math.min(limit.maxy, y + starttop)); style.left = left + 'px'; style.top = top + 'px'; }; clsselect(); api._ie6selectfix(); }; // 对话框拖动结束 _dragevent.onend = function (x, y) { _$document.unbind('dblclick', _dragevent.end); !_isie6 && _islosecapture ? title.unbind('losecapture', _dragevent.end) : _$window.unbind('blur', _dragevent.end); _issetcapture && title[0].releasecapture(); _isie6 && !api.closed && api._autopositiontype(); wrap.removeclass('aui_state_drag'); }; isresize = event.target === dom.se[0] ? true : false; limit = (function () { var maxx, maxy, wrap = api.dom.wrap[0], fixed = wrap.style.position === 'fixed', ow = wrap.offsetwidth, oh = wrap.offsetheight, ww = _$window.width(), wh = _$window.height(), dl = fixed ? 0 : _$document.scrollleft(), dt = fixed ? 0 : _$document.scrolltop(), // 坐标最大值限制 maxx = ww - ow + dl; maxy = wh - oh + dt; return { minx: dl, miny: dt, maxx: maxx, maxy: maxy }; })(); _dragevent.start(event); }; // 代理 mousedown 事件触发对话框拖动 _$document.bind('mousedown', function (event) { var api = artdialog.focus; if (!api) return; var target = event.target, config = api.config, dom = api.dom; if (config.drag !== false && target === dom.title[0] || config.resize !== false && target === dom.se[0]) { _dragevent = _dragevent || new artdialog.dragevent(); _use(event); return false;// 防止firefox与chrome滚屏 }; }); })(this.art || this.jquery && (this.art = jquery));