/* artdialog 5 | (c) 2009-2012 tangbin | http://code.google.com/p/artdialog/ */ (function(g, h) { function i(a) { var c = f.expando, d = a === g ? 0 : a[c]; d === h && (a[c] = d = ++f.uuid); return d } var f = g.art = function(a, c) { return new f.fn.constructor(a, c) }, p = /^(?:[^<]*(<[\w\w]+>)[^>]*$|#([\w\-]+)$)/, o = /[\n\t]/g; if (g.$ === h) g.$ = f; f.fn = f.prototype = { constructor: function(a, c) { var d, c = c || document; if (!a) return this; if (a.nodetype) return this[0] = a, this; if ("string" === typeof a && (d = p.exec(a)) && d[2]) return (d = c.getelementbyid(d[2])) && d.parentnode && (this[0] = d), this; this[0] = a; return this }, hasclass: function(a) { return - 1 < (" " + this[0].classname + " ").replace(o, " ").indexof(" " + a + " ") ? !0 : !1 }, addclass: function(a) { this.hasclass(a) || (this[0].classname += " " + a); return this }, removeclass: function(a) { var c = this[0]; if (a) { if (this.hasclass(a)) c.classname = c.classname.replace(a, " ") } else c.classname = ""; return this }, css: function(a, c) { var d, e = this[0]; if ("string" === typeof a) { if (c === h) return f.css(e, a); e.style[a] = c } else for (d in a) e.style[d] = a[d]; return this }, show: function() { return this.css("display", "block") }, hide: function() { return this.css("display", "none") }, offset: function() { var a = this[0], c = a.getboundingclientrect(), d = a.ownerdocument, a = d.body, d = d.documentelement; return { left: c.left + (self.pagexoffset || d.scrollleft) - (d.clientleft || a.clientleft || 0), top: c.top + (self.pageyoffset || d.scrolltop) - (d.clienttop || a.clienttop || 0) } }, html: function(a) { var c = this[0]; if (a === h) return c.innerhtml; f.cleandata(c.getelementsbytagname("*")); c.innerhtml = a; return this }, remove: function() { var a = this[0]; f.cleandata(a.getelementsbytagname("*")); f.cleandata([a]); a.parentnode.removechild(a); return this }, bind: function(a, c) { f.event.add(this[0], a, c); return this }, unbind: function(a, c) { f.event.remove(this[0], a, c); return this } }; f.fn.constructor.prototype = f.fn; f.iswindow = function(a) { return a && "object" === typeof a && "setinterval" in a }; f.fn.find = function(a) { var c = this[0], d = a.split(".")[1]; if (d) if (document.getelementsbyclassname) d = c.getelementsbyclassname(d); else { for (var e = a = 0, b = [], c = (c || document).getelementsbytagname("*"), m = c.length, d = regexp("(^|\\s)" + d + "(\\s|$)"); a < m; a++) d.test(c[a].classname) && (b[e] = c[a], e++); d = b } else d = c.getelementsbytagname(a); return f(d[0]) }; f.each = function(a, c) { var d, e = 0, b = a.length; if (b === h) for (d in a) { if (!1 === c.call(a[d], d, a[d])) break } else for (d = a[0]; e < b && !1 !== c.call(d, e, d); d = a[++e]); return a }; f.data = function(a, c, d) { var e = f.cache, a = i(a); if (c === h) return e[a]; e[a] || (e[a] = {}); d !== h && (e[a][c] = d); return e[a][c] }; f.removedata = function(a, c) { var d = !0, e = f.expando, b = f.cache, m = i(a), n = m && b[m]; if (n) if (c) { delete n[c]; for (var k in n) d = !1; d && delete f.cache[m] } else delete b[m], a.removeattribute ? a.removeattribute(e) : a[e] = null }; f.uuid = 0; f.cache = {}; f.expando = "@cache" + +new date; f.event = { add: function(a, c, d) { var j; var e, b = f.event; e = f.data(a, "@events") || f.data(a, "@events", {}); j = e[c] = e[c] || {}, e = j; (e.listeners = e.listeners || []).push(d); if (!e.handler) e.elem = a, e.handler = b.handler(e), a.addeventlistener ? a.addeventlistener(c, e.handler, !1) : a.attachevent("on" + c, e.handler) }, remove: function(a, c, d) { var e, b, m; b = f.event; var n = !0, k = f.data(a, "@events"); if (k) if (c) { if (b = k[c]) { m = b.listeners; if (d) for (e = 0; e < m.length; e++) m[e] === d && m.splice(e--, 1); else b.listeners = []; if (0 === b.listeners.length) { a.removeeventlistener ? a.removeeventlistener(c, b.handler, !1) : a.detachevent("on" + c, b.handler); delete k[c]; b = f.data(a, "@events"); for (var r in b) n = !1; n && f.removedata(a, "@events") } } } else for (e in k) b.remove(a, e) }, handler: function(a) { return function(c) { for (var c = f.event.fix(c || g.event), d = 0, e = a.listeners, b; b = e[d++];) ! 1 === b.call(a.elem, c) && (c.preventdefault(), c.stoppropagation()) } }, fix: function(a) { if (a.target) return a; var c = { target: a.srcelement || document, preventdefault: function() { a.returnvalue = !1 }, stoppropagation: function() { a.cancelbubble = !0 } }, d; for (d in a) c[d] = a[d]; return c } }; f.cleandata = function(a) { for (var c = 0, d, e = a.length, b = f.event.remove, m = f.removedata; c < e; c++) d = a[c], b(d), m(d) }; f.css = "defaultview" in document && "getcomputedstyle" in document.defaultview ? function(a, c) { return document.defaultview.getcomputedstyle(a, !1)[c] }: function(a, c) { return a.currentstyle[c] || "" }; f.each(["left", "top"], function(a, c) { var d = "scroll" + c; f.fn[d] = function() { var c = this[0], b; return (b = f.iswindow(c) ? c: 9 === c.nodetype ? c.defaultview || c.parentwindow: !1) ? "pagexoffset" in b ? b[a ? "pageyoffset": "pagexoffset"] : b.document.documentelement[d] || b.document.body[d] : c[d] } }); f.each(["height", "width"], function(a, c) { var d = c.tolowercase(); f.fn[d] = function(a) { var b = this[0]; return ! b ? null == a ? null: this: f.iswindow(b) ? b.document.documentelement["client" + c] || b.document.body["client" + c] : 9 === b.nodetype ? math.max(b.documentelement["client" + c], b.body["scroll" + c], b.documentelement["scroll" + c], b.body["offset" + c], b.documentelement["offset" + c]) : null } }); return f })(window); (function(g, h, i) { if ("backcompat" === document.compatmode) throw error("artdialog: document types require more than xhtml1.0"); var f, p = 0, o = "artdialog" + +new date, a = h.vbarray && !h.xmlhttprequest, c = "createtouch" in document && !("onmousemove" in document) || /(iphone|ipad|ipod)/i.test(navigator.useragent), d = !a && !c, e = function(b, a, n) { b = b || {}; if ("string" === typeof b || 1 === b.nodetype) b = { content: b, fixed: !c }; var k; k = e.defaults; var r = b.follow = 1 === this.nodetype && this || b.follow, t; for (t in k) b[t] === i && (b[t] = k[t]); b.id = r && r[o + "follow"] || b.id || o + p; if (k = e.list[b.id]) return r && k.follow(r), k.zindex().focus(), k; if (!d) b.fixed = !1; if (!b.button || !b.button.push) b.button = []; if (a !== i) b.ok = a; b.ok && b.button.push({ id: "ok", value: b.okvalue, callback: b.ok, focus: !0 }); if (n !== i) b.cancel = n; b.cancel && b.button.push({ id: "cancel", value: b.cancelvalue, callback: b.cancel }); e.defaults.zindex = b.zindex; p++; return e.list[b.id] = f ? f.constructor(b) : new e.fn.constructor(b) }; e.version = "5.0"; e.fn = e.prototype = { constructor: function(b) { var a; this.closed = !1; this.config = b; this.dom = a = this.dom || this._getdom(); b.skin && a.wrap.addclass(b.skin); a.wrap.css("position", b.fixed ? "fixed": "absolute"); a.close[!1 === b.cancel ? "hide": "show"](); a.content.css("padding", b.padding); this.button.apply(this, b.button); this.title(b.title).content(b.content).size(b.width, b.height).time(b.time); b.follow ? this.follow(b.follow) : this.position(); this.zindex(); b.lock && this.lock(); this._addevent(); this[b.visible ? "visible": "hidden"]().focus(); f = null; b.initialize && b.initialize.call(this); return this }, content: function(b) { var a, c, e, d, f = this, v = this.dom.content, l = v[0]; this._elemback && (this._elemback(), delete this._elemback); if ("string" === typeof b) v.html(b); else if (b && 1 === b.nodetype) d = b.style.display, a = b.previoussibling, c = b.nextsibling, e = b.parentnode, this._elemback = function() { a && a.parentnode ? a.parentnode.insertbefore(b, a.nextsibling) : c && c.parentnode ? c.parentnode.insertbefore(b, c) : e && e.appendchild(b); b.style.display = d; f._elemback = null }, v.html(""), l.appendchild(b), g(b).show(); return this.position() }, title: function(b) { var a = this.dom, c = a.outer, a = a.title; ! 1 === b ? (a.hide().html(""), c.addclass("d-state-notitle")) : (a.show().html(b), c.removeclass("d-state-notitle")); return this }, position: function() { var b = this.dom, a = b.wrap[0], c = b.window, e = b.document, d = this.config.fixed, b = d ? 0 : e.scrollleft(), e = d ? 0 : e.scrolltop(), d = c.width(), f = c.height(), g = a.offsetheight, c = (d - a.offsetwidth) / 2 + b, d = d = (g < 4 * f / 7 ? 0.382 * f - g / 2 : (f - g) / 2) + e, a = a.style; a.left = math.max(c, b) + "px"; a.top = math.max(d, e) + "px"; return this }, size: function(b, a) { var c = this.dom.main[0].style; "number" === typeof b && (b += "px"); "number" === typeof a && (a += "px"); c.width = b; c.height = a; return this }, follow: function(b) { var a = g(b), c = this.config; if (!b || !b.offsetwidth && !b.offsetheight) return this.position(this._left, this._top); var d = c.fixed, e = o + "follow", f = this.dom, h = f.window, l = f.document, f = h.width(), h = h.height(), s = l.scrollleft(), l = l.scrolltop(), j = a.offset(), a = b.offsetwidth, i = d ? j.left - s: j.left, j = d ? j.top - l: j.top, q = this.dom.wrap[0], p = q.style, u = q.offsetwidth, q = q.offsetheight, w = i - (u - a) / 2, x = j + b.offsetheight, s = d ? 0 : s, d = d ? 0 : l; p.left = (w < s ? i: w + u > f && i - u > s ? i - u + a: w) + "px"; p.top = (x + q > h + d && j - q > d ? j - q: x) + "px"; this._follow && this._follow.removeattribute(e); this._follow = b; b[e] = c.id; return this }, button: function() { for (var b = this.dom.buttons, a = b[0], c = this._listeners = this._listeners || {}, d = [].slice.call(arguments), e = 0, f, h, l, i, j; e < d.length; e++) { f = d[e]; h = f.value; l = f.id || h; i = !c[l]; j = !i ? c[l].elem: document.createelement("input"); j.type = "button"; j.classname = "d-button"; c[l] || (c[l] = {}); if (h) j.value = h; if (f.width) j.style.width = f.width; if (f.callback) c[l].callback = f.callback; if (f.focus) this._focus && this._focus.removeclass("d-state-highlight"), this._focus = g(j).addclass("d-state-highlight"), this.focus(); j[o + "callback"] = l; j.disabled = !!f.disabled; if (i) c[l].elem = j, a.appendchild(j) } b[0].style.display = d.length ? "": "none"; return this }, visible: function() { this.dom.wrap.css("visibility", "visible"); this.dom.outer.addclass("d-state-visible"); this._islock && this._lockmask.show(); return this }, hidden: function() { this.dom.wrap.css("visibility", "hidden"); this.dom.outer.removeclass("d-state-visible"); this._islock && this._lockmask.hide(); return this }, close: function() { if (this.closed) return this; var b = this.dom, a = b.wrap, c = e.list, k = this.config.beforeunload, g = this.config.follow; if (k && !1 === k.call(this)) return this; if (e.focus === this) e.focus = null; g && g.removeattribute(o + "follow"); this._elemback && this._elemback(); this.time(); this.unlock(); this._removeevent(); delete c[this.config.id]; if (f) a.remove(); else { f = this; b.title.html(""); b.content.html(""); b.buttons.html(""); a[0].classname = a[0].style.csstext = ""; b.outer[0].classname = "d-outer"; a.css({ left: 0, top: 0, position: d ? "fixed": "absolute" }); for (var h in this) this.hasownproperty(h) && "dom" !== h && delete this[h]; this.hidden() } this.closed = !0; return this }, time: function(b) { var a = this, c = this._timer; c && cleartimeout(c); if (b) this._timer = settimeout(function() { a._click("cancel") }, b); return this }, focus: function() { if (this.config.focus) try { var b = this._focus && this._focus[0] || this.dom.close[0]; b && b.focus() } catch(a) {} return this }, zindex: function() { var b = this.dom, a = e.focus, c = e.defaults.zindex++; b.wrap.css("zindex", c); this._lockmask && this._lockmask.css("zindex", c - 1); a && a.dom.outer.removeclass("d-state-focus"); e.focus = this; b.outer.addclass("d-state-focus"); return this }, lock: function() { if (this._islock) return this; var b = this, a = this.dom, c = document.createelement("div"), f = g(c), i = e.defaults.zindex - 1; this.zindex(); a.outer.addclass("d-state-lock"); f.css({ zindex: i, position: "fixed", left: 0, top: 0, width: "100%", height: "100%", overflow: "hidden" }).addclass("d-mask"); d || f.css({ position: "absolute", width: g(h).width() + "px", height: g(document).height() + "px" }); f.bind("click", function() { b._reset() }).bind("dblclick", function() { //b._click("cancel") }); document.body.appendchild(c); this._lockmask = f; this._islock = !0; return this }, unlock: function() { if (!this._islock) return this; this._lockmask.unbind(); this._lockmask.hide(); this._lockmask.remove(); this.dom.outer.removeclass("d-state-lock"); this._islock = !1; return this }, _getdom: function() { var b = document.body; if (!b) throw error('artdialog: "documents.body" not ready'); var a = document.createelement("div"); a.style.csstext = "position:absolute;left:0;top:0"; a.innerhtml = e._templates; b.insertbefore(a, b.firstchild); for (var c = 0, d = {}, f = a.getelementsbytagname("*"), i = f.length; c < i; c++)(b = f[c].classname.split("d-")[1]) && (d[b] = g(f[c])); d.window = g(h); d.document = g(document); d.wrap = g(a); return d }, _click: function(b) { b = this._listeners[b] && this._listeners[b].callback; return "function" !== typeof b || !1 !== b.call(this) ? this.close() : this }, _reset: function() { var b = this.config.follow; b ? this.follow(b) : this.position() }, _addevent: function() { var b = this, a = this.dom; a.wrap.bind("click", function(c) { c = c.target; if (c.disabled) return ! 1; if (c === a.close[0]) return b._click("cancel"), !1; (c = c[o + "callback"]) && b._click(c) }).bind("mousedown", function() { b.zindex() }) }, _removeevent: function() { this.dom.wrap.unbind() } }; e.fn.constructor.prototype = e.fn; g.fn.dialog = g.fn.artdialog = function() { var b = arguments; this[this.live ? "live": "bind"]("click", function() { e.apply(this, b); return ! 1 }); return this }; e.focus = null; e.get = function(b) { return b === i ? e.list: e.list[b] }; e.list = {}; g(document).bind("keydown", function(b) { var a = b.target, c = a.nodename, d = /^input|textarea$/i, f = e.focus, b = b.keycode; f && f.config.esc && !(d.test(c) && "button" !== a.type) && 27 === b && f._click("cancel") }); g(h).bind("resize", function() { var b = e.list, a; for (a in b) b[a]._reset() }); e._templates = '
'; e.defaults = { content: '
loading..
', title: "message", button: null, ok: null, cancel: null, initialize: null, beforeunload: null, okvalue: "ok", cancelvalue: "cancel", width: "auto", height: "auto", padding: "20px 25px", skin: null, time: null, esc: !0, focus: !0, visible: !0, follow: null, lock: true, fixed: !1, zindex: 9999 }; this.artdialog = g.dialog = g.artdialog = e })(this.art || this.jquery, this);