From 062b9753405ab8200f592ef90fa85144bfe8ff82 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Thu, 31 Jul 2014 13:53:48 +0400 Subject: [PATCH] + 'always' method --- Ply.min.js | 466 +------------------------------- src/Ply.es6 | 11 +- src/dom.es6 | 3 - src/{promise.js => promise.es6} | 12 +- src/ui.es6 | 6 +- tests/Ply.ui.tests.js | 12 +- 6 files changed, 32 insertions(+), 478 deletions(-) rename src/{promise.js => promise.es6} (84%) diff --git a/Ply.min.js b/Ply.min.js index b190bcb..3e6b953 100644 --- a/Ply.min.js +++ b/Ply.min.js @@ -1,464 +1,2 @@ -/*! Ply 0.3.0 - MIT | git://github.com/rubaxa/Ply.git */ -!function (a) { - window.Ply = a(window) -}(function (a, b) { - "use strict"; - function c(a) { - return"function" == typeof a - } - - function d(a) { - if (O)return new O(a); - var b = P.Deferred(); - return a(b.resolve, b.reject), b - } - - function e(a) { - return O ? O.all(a) : P.when.apply(P, a) - } - - function f(a) { - return d(function (b) { - return b(a) - }) - } - - function g(a) { - return a && a.then ? a : f(a) - } - - function h(a, b) { - if (a)for (var c in a)a.hasOwnProperty(c) && b(a[c], c, a) - } - - function i(a) { - var b = {}; - return h(a, function (a, d) { - b[d] = c(a) ? a : a instanceof Object ? i(a) : a - }), b - } - - function j(a) { - for (var b = Array.prototype.slice, c = b.call(arguments, 1), d = 0, e = c.length; e > d; d++)h(c[d], function (b, c) { - a[c] = b - }); - return a - } - - function k(a, b) { - try { - return(b || H).querySelector(a) - } catch (c) { - return P(a, b)[0] - } - } - - function l(a, b) { - return a.getElementsByTagName(b) - } - - function m(a, b) { - try { - a && b && a.appendChild(b) - } catch (c) { - } - } - - function n(a) { - a && a.parentNode && a.parentNode.removeChild(a) - } - - function o(a, b, c) { - var d = c.handle = c.handle || function (b) { - b.target || (b.target = b.srcElement || H), 3 === b.target.nodeType && (b.target = b.target.parentNode), b.preventDefault || (b.preventDefault = function () { - b.returnValue = !1 - }), b.stopPropagation || (b.stopPropagation = function () { - b.cancelBubble = !0 - }), c.call(a, b) - }; - a.addEventListener ? a.addEventListener(b, d, !1) : a.attachEvent("on" + b, d) - } - - function p(a, b, c) { - var d = c.handle; - d && (a.removeEventListener ? a.removeEventListener(b, d, !1) : a.detachEvent("on" + b, d)) - } - - function q(a) { - if (null == a && (a = "div"), a.appendChild)return a; - if (a.skip)return H.createDocumentFragment(); - "string" == typeof a && (a = {tag: a}); - var b, c = a.children, d = Q.exec(a.tag || ""); - return delete a.children, a.tag = d[1] || "div", a.id = a.id || (d[2] || "").substr(1), d = (d[3] || "").split("."), d[0] = a.className || "", a.className = d.join(" "), b = H.createElement(a.tag), delete a.tag, h(a, function (c, d) { - if (c)if ("css" === d)t(b, a.css); else if ("text" === d)null != c && m(b, H.createTextNode(c)); else if ("html" === d)null != c && (b.innerHTML = c); else if ("ply" === d)b.setAttribute(M, c); else if (d in b)try { - b[d] = c - } catch (e) { - b.setAttribute(d, c) - } else/^data-/.test(d) && b.setAttribute(d, c) - }), c && c.appendChild ? m(b, c) : h(c, function (a, c) { - a && ("string" == typeof a ? a = {text: a} : "object" != typeof a && (a = {}), "string" == typeof c && (a.tag = a.tag || c), m(b, q(a))) - }), b - } - - function r(a) { - for (var b, c, d = l(a, "input"), e = 0, f = d.length; f > e; e++)if (b = d[e], "submit" === b.type)!c && (c = b); else if (!/hidden|check|radio/.test(b.type) && "" == b.value) { - c = b; - break - } - c || (c = l(a, "button")[0]); - try { - c.focus() - } catch (g) { - } - } - - function s(a) { - return u(!0), d(function (b) { - for (var c, d = l(a, "img"), e = d.length, f = e, g = function () { - if (--f <= 0) { - for (e = d.length; e--;)c = d[e], p(c, "load", g), p(c, "error", g); - u(!1), b() - } - }; e--;)c = d[e], c.complete ? f-- : (o(c, "load", g), o(c, "error", g)); - !f && g() - }) - } - - function t(a, b, c) { - if (a && a.style && b)if (b instanceof Object)for (var d in b)t(a, d, b[d]); else { - if (void 0 === c)return H.defaultView && H.defaultView.getComputedStyle ? c = H.defaultView.getComputedStyle(a, "") : a.currentStyle && (c = a.currentStyle), void 0 === b ? c : c[b]; - R[b] ? R[b](a.style, c) : a.style[K[b] || b] = c - } - } - - function u(a) { - var b = u.get(); - clearTimeout(u.pid), u.pid = a ? I(function () { - m(H.body, b) - }, 100) : I(function () { - n(b) - }, 100) - } - - function v(a, b) { - return q({css: {padding: "20px 20px 40px", display: "inline-block", position: "relative", textAlign: "left", whiteSpace: "normal", verticalAlign: "middle", transform: "translate3d(0, 0, 0)"}, children: b.baseHtml ? [ - {ply: ":layer", tag: ".ply-layer", className: b.mod, css: j({overflow: "hidden", position: "relative", backfaceVisibility: "hidden"}, b.layer), children: [b.flags.closeBtn && {ply: ":close", tag: ".ply-x", text: J.cross}, {tag: ".ply-inside", children: a}]} - ] : a}) - } - - function w(a) { - return q({ply: ":overlay", tag: ".ply-overlay", css: {top: 0, left: 0, right: 0, bottom: 0, position: "fixed"}, children: [ - {tag: "div", css: j({width: "100%", height: "100%"}, a)} - ]}) - } - - function x(a, b, c) { - a.wrapEl = q({tag: "form", css: {whiteSpace: "nowrap", zIndex: b.zIndex}}), c || (a.overlayEl = w(b.overlay), a.overlayBoxEl = a.overlayEl.firstChild, m(a.wrapEl, a.overlayEl)); - var d = q(); - t(d, {height: "100%", display: "inline-block", verticalAlign: "middle"}), m(a.wrapEl, d); - var e = b.el; - return a.el = e && e.cloneNode ? e.cloneNode(!0) : q({html: e || ""}), a.layerEl = v(a.el, b), a.contentEl = y(a.layerEl), a.context = new A(a.layerEl), m(a.wrapEl, a.layerEl), a.bodyEl = b.body && k(b.body) || H.body, a.wrapEl.tabIndex = -1, t(a.wrapEl, {top: 0, left: 0, right: 0, bottom: 0, position: "fixed", textAlign: "center", overflow: "auto", outline: 0}), a - } - - function y(a) { - return a.firstChild.lastChild.firstChild - } - - function z(a, b) { - b = a instanceof Object ? a : b || {}, b.el = b.el || a; - var c = this; - c.cid = "c" + F++, N.zIndex++, c.options = b = j({}, N, b), b.flags = j({}, N.flags, b.flags), x(c, b), c.setEffect(b.effect), c.fx = function (a) { - return!(c.fx.queue = c.fx.queue.then(a, a).then(function () { - return c - })) - }, c.fx.queue = f(), c.on("click", ":overlay", function () { - c.hasFlag("closeByOverlay") && c.closeBy("overlay") - }), c.on("click", ":close", function (a, b) { - a.preventDefault(), c.closeBy("BUTTON" === b.nodeName ? "cancel" : "x") - }), c.options.init(this) - } - - function A(a) { - this.el = a - } - - function B(a, b) { - return null == a ? {skip: !0} : ("string" == typeof a && (a = {text: a}), "object" == typeof a && (a.name = a.name || b), a) - } - - function C(a, b, c) { - var d, e = C[a]; - return e || (a = a.split(/\s+/).slice(0, -1).join(" "), e = b && (C[a + " [name=" + b.name + "]"] || C[a + " [type=" + b.type + "]"]) || C[a + " *"] || C[":default"]), d = q(e(b, c)), b && b.name && d.setAttribute(M + "-name", b.name), d.className += " ply-ui", d - } - - function D(a, b) { - D["_" + a] = b, D[a] = function (a, c) { - return d(function (d, e) { - b(a, c, d, e) - }).then(function (a) { - return a.appendChild || (a = C(":root", a)), a - }) - } - } - - function E(a, b, c, d) { - return b.mod = a, b.effect = b.effect || "slide", b.flags = j({closeBtn: !1}, b.flags), {header: c.title, content: c.form ? {"dialog-form": {children: c.form}} : {el: c.text || c}, ctrls: {ok: c.ok || d.ok, cancel: c.cancel === !1 ? null : c.cancel || d.cancel}} - } - - var F = 1, G = function () { - }, H = a.document, I = a.setTimeout, J = {ok: "OK", cancel: "Cancel", cross: "✖"}, K = function () { - var a = {}, b = H.createElement("div").style, c = "opacity transition transform perspective transformStyle transformOrigin backfaceVisibility".split(" "), d = ["Webkit", "Moz", "O", "MS"]; - return h(c, function (c, e) { - if (a[c] = c in b && c, !a[c])for (e = 0; 4 > e; e++) { - var f = d[e] + c.charAt(0).toUpperCase() + c.substr(1); - if (a[c] = f in b && f)break - } - }), a - }(), L = {esc: 27}, M = "data-ply", N = {zIndex: 1e4, layer: {}, overlay: {opacity: .6, backgroundColor: "rgb(0, 0, 0)"}, flags: {closeBtn: !0, bodyScroll: !1, closeByEsc: !0, closeByOverlay: !0, hideLayerInStack: !0, visibleOverlayInStack: !1}, baseHtml: !0, init: G, open: G, close: G, destroy: G, callback: G}, O = b || a.Promise, P = a.jQuery || a.Zepto || a.ender || a.$, Q = /^(\w+)?(#\w+)?((?:\.[\w_-]+)*)/i, R = {opacity: !K.opacity && function (a, b) { - a.zoom = 1, a.filter = "alpha(opacity=" + 100 * b + ")" - }}; - u.get = function () { - return u.el || (u.el = q({tag: ".ply-loading", children: {".ply-loading-spinner": !0}})) - }, z.fn = z.prototype = {constructor: z, _activate: function () { - if (!this.hasFlag("bodyScroll")) { - var a = this.bodyEl, b = q({css: {overflow: "auto", visibility: "hidden", height: "5px"}, children: [ - {tag: "div", css: {height: "100px"}} - ]}); - this.__overflow = t(a, "overflow"), this.__paddingRight = t(a, "paddingRight"), m(a, b), t(a, {overflow: "hidden", paddingRight: b.offsetWidth - b.firstChild.offsetWidth + "px"}), n(b) - } - o(this.wrapEl, "submit", this._getHandleEvent("submit")) - }, _deactivate: function () { - this.hasFlag("bodyScroll") || t(this.bodyEl, {overflow: this.__overflow, paddingRight: this.__paddingRight}), p(this.layerEl, "submit", this._getHandleEvent("submit")) - }, _getHandleEvent: function (a) { - var b = this, c = b.__handleEvent || (b.__handleEvent = {}); - return c[a] || (c[a] = function (c) { - b._handleEvent(a, c) - }), c[a] - }, _handleEvent: function (a, b) { - b.preventDefault(), this.closeBy(a) - }, applyEffect: function (a, b, c) { - return a = this[a] || a, a.nodeType || (c = b, b = a, a = this.layerEl), c = z.effects.get(c || this.effects), z.effects.apply.call(c, a, b) - }, closeBy: function (a) { - var b = this, c = {by: a, state: "submit" === a, layer: this, data: this.context.toJSON(), context: this.context}, d = this.options.callback(c); - g(d).then(function (a) { - a !== !1 && (b.result = c, b.close()) - }) - }, on: function (a, b, c) { - var d = this; - return c || (c = b, b = ":layer"), c["_" + b] = function (a) { - var e = a.target; - do if (1 === e.nodeType && e.getAttribute(M) === b)return c.call(d, a, e); while (e !== d.wrapEl && (e = e.parentNode)) - }, o(d.wrapEl, a, c["_" + b]), d - }, off: function (a, b, c) { - return c || (c = b, b = "layer"), p(this.wrapEl, a, c["_" + b] || G), this - }, hasFlag: function (a) { - return!!this.options.flags[a] - }, setEffect: function (a) { - return this.effects = z.effects.get(a), this - }, _toggleState: function (a, b) { - var c = this, d = a ? "open" : "close", f = z.stack.last; - return c.visible != a && (c.visible = a, c[a ? "_activate" : "_deactivate"](), z.stack[a ? "add" : "remove"](c), c.fx(function () { - return s(c.wrapEl).then(function () { - var g = z.stack.length === (a ? 1 : 0), h = f && f.hasFlag("hideLayerInStack"), i = g || c.hasFlag("visibleOverlayInStack"); - return a ? (!i && n(c.overlayBoxEl), m(c.bodyEl, c.wrapEl), c.wrapEl.focus(), r(c.layerEl), h && f.applyEffect("close.layer", b).then(function () { - n(f.layerEl) - })) : (f = z.stack.last) && (m(f.wrapEl, f.layerEl), f.hasFlag("hideLayerInStack") && f.applyEffect("open.layer", b).then(function () { - r(f.el) - })), e([c.applyEffect(d + ".layer", b), i && c.applyEffect("overlayEl", d + ".overlay", b)]).then(function () { - a || (n(c.wrapEl), m(c.overlayEl, c.overlayBoxEl)), c.options[d](c) - }) - }) - })), c.fx.queue - }, open: function (a) { - return this.result = null, this._toggleState(!0, a) - }, close: function (a) { - return this._toggleState(!1, a) - }, _swap: function (a, b, c, d, f) { - var g = this; - return g.visible ? g.fx(function () { - return s(b).then(function () { - return d(), e([g.applyEffect(a, "close.layer", c), g.applyEffect(b, "open.layer", c)]).then(function () { - n(a), f(), g.wrapEl.focus(), r(b) - }) - }) - }) : f(), g.fx.queue - }, swap: function (a, b) { - a = j({}, this.options, a); - var c = this, d = x({}, a, !0), e = b || a.effect ? z.effects.get(b || a.effect) : c.effects, f = c.layerEl, g = d.layerEl; - return c._swap(f, g, e, function () { - m(c.bodyEl, c.wrapEl), m(c.bodyEl, d.wrapEl) - }, function () { - n(d.wrapEl), m(c.wrapEl, g), c.el = d.el, c.layerEl = g, c.contentEl = y(g), c.context.el = g - }) - }, innerSwap: function (a, b) { - a = j({}, this.options, a); - var c = this, d = x({}, a, !0), e = b || a.effect ? z.effects.get(b || a.effect) : c.effects, f = k(".ply-inside", d.layerEl), g = k(".ply-inside", c.layerEl); - return c._swap(g, f, e, function () { - t(g, {width: g.offsetWidth + "px", position: "absolute"}), m(g.parentNode, f) - }, G) - }, destroy: function () { - n(this.wrapEl), this._deactivate(), z.stack.remove(this), this.visible = !1, this.options.destroy(this) - }}; - var S = [], T = S.push, U = S.splice; - return z.stack = {_idx: {}, last: null, length: 0, _pop: function (a) { - var b = z.stack.last; - a.keyCode === L.esc && b.hasFlag("closeByEsc") && b.closeBy("esc") - }, add: function (a) { - var b = T.call(this, a); - this.last = a, this._idx[a.cid] = b - 1, 1 === b && o(H, "keyup", this._pop) - }, remove: function (a) { - var b = this._idx[a.cid]; - b >= 0 && (U.call(this, b, 1), delete this._idx[a.cid], this.last = this[this.length - 1], this.last || p(H, "keyup", this._pop)) - }}, z.effects = {defaults: {duration: 300, open: {layer: null, overlay: null}, close: {layer: null, overlay: null}}, setup: function (a) { - this.defaults = this.get(a) - }, set: function (a) { - j(this, a) - }, get: function (a) { - function b(a) { - var b = /^([\w_-]+)(?::(\d+%?))?(\[[^\]]+\])?/.exec(a) || []; - return{name: b[1] || a, duration: b[2] || null, args: JSON.parse(b[3] || "null") || {}} - } - - function c(c, d, e) { - var f = b(d), g = c[f.name] || e || {}, h = f.duration || g.duration || c.duration || a.duration; - return"string" == typeof g && (g = b(g), delete g.args), /%/.test(g.duration) && (g.duration = parseInt(g.duration, 10) / 100 * h), g.duration = 0 | (g.duration || h), g - } - - var d = i(this.defaults); - if ("string" == typeof a) { - var e = b(a); - a = i(this[e.name] || {open: {}, close: {}}), a.duration = e.duration || a.duration, a.open.args = e.args[0], a.close.args = e.args[1] - } else if (a instanceof Array) { - var f = b(a[0]), g = b(a[1]), h = this[f.name], j = this[g.name]; - a = {open: i(h && h.open || {layer: a[0], overlay: a[0]}), close: i(j && j.close || {layer: a[1], overlay: a[1]})}, a.open.args = f.args[0], a.close.args = g.args[0] - } else a instanceof Object || (a = {}); - a.duration = 0 | (a.duration || d.duration); - for (var k in{open: 0, close: 0}) { - var l = a[k] || d[k] || {}; - "string" == typeof l && (l = {layer: l}), l.layer = c(l, "layer", d[k].layer), l.overlay = c(l, "overlay", d[k].overlay), void 0 === l.args && delete l.args, a[k] = l - } - return a - }, apply: function (a, b) { - b = b.split("."); - var e, g, j = this[b[0]], k = a.firstChild, l = [a.getAttribute("style"), k && k.getAttribute("style")]; - return K.transition && j && (g = j[b[1]]) && (e = z.effects[g.name]) && (e.to || e.from) ? (e = i(e), t(a, "transition", "none"), t(k, "transition", "none"), h(e.to, function (b, c, d) { - "&" === b && (d[c] = t(a, c)) - }), c(e.from) ? e.from(a, j.args) : e.from && t(a, e.from), d(function (b) { - e.width = a.offsetWidth, t(a, "transition", "all " + g.duration + "ms"), t(k, "transition", "all " + g.duration + "ms"), c(e.to) ? e.to(a, j.args) : t(a, e.to), I(b, g.duration) - }).then(function () { - a.setAttribute("style", l[0]), k && k.setAttribute("style", l[1]) - })) : f() - }}, z.effects.set({fade: {open: {layer: "fade-in:80%", overlay: "fade-in:100%"}, close: {layer: "fade-out:60%", overlay: "fade-out:60%"}}, scale: {open: {layer: "scale-in", overlay: "fade-in"}, close: {layer: "scale-out", overlay: "fade-out"}}, fall: {open: {layer: "fall-in", overlay: "fade-in"}, close: {layer: "fall-out", overlay: "fade-out"}}, slide: {open: {layer: "slide-in", overlay: "fade-in"}, close: {layer: "slide-out", overlay: "fade-out"}}, "3d-flip": {open: {layer: "3d-flip-in", overlay: "fade-in"}, close: {layer: "3d-flip-out", overlay: "fade-out"}}, "3d-sign": {open: {layer: "3d-sign-in", overlay: "fade-in"}, close: {layer: "3d-sign-out", overlay: "fade-out"}}, inner: {open: {layer: "inner-in"}, close: {layer: "inner-out"}}, "fade-in": {from: {opacity: 0}, to: {opacity: "&"}}, "fade-out": {to: {opacity: 0}}, "slide-in": {from: {opacity: 0, transform: "translateY(20%)"}, to: {opacity: "&", transform: "translateY(0)"}}, "slide-out": {to: {opacity: 0, transform: "translateY(20%)"}}, "fall-in": {from: {opacity: 0, transform: "scale(1.3)"}, to: {opacity: "&", transform: "scale(1)"}}, "fall-out": {to: {opacity: 0, transform: "scale(1.3)"}}, "scale-in": {from: {opacity: 0, transform: "scale(0.7)"}, to: {opacity: "&", transform: "scale(1)"}}, "scale-out": {to: {opacity: 0, transform: "scale(0.7)"}}, rotate3d: function (a, b, c, d, e) { - t(a, {perspective: "1300px"}), t(a.firstChild, {opacity: b, transform: "rotate" + c + "(" + d + "deg)", transformStyle: "preserve-3d", transformOrigin: e ? "50% 0" : "50%"}) - }, "3d-sign-in": {from: function (a) { - z.effects.rotate3d(a, 0, "X", -60, "50% 0") - }, to: function (a) { - t(a.firstChild, {opacity: 1, transform: "rotateX(0)"}) - }}, "3d-sign-out": {from: function (a) { - z.effects.rotate3d(a, 1, "X", 0, "50% 0") - }, to: function (a) { - t(a.firstChild, {opacity: 0, transform: "rotateX(-60deg)"}) - }}, "3d-flip-in": {from: function (a, b) { - z.effects.rotate3d(a, 0, "Y", b || -70) - }, to: function (a) { - t(a.firstChild, {opacity: 1, transform: "rotateY(0)"}) - }}, "3d-flip-out": {from: function (a) { - z.effects.rotate3d(a, 1, "Y", 0) - }, to: function (a, b) { - t(a.firstChild, {opacity: 0, transform: "rotateY(" + (b || 70) + "deg)"}) - }}, "inner-in": {from: function (a) { - t(a, "transform", "translateX(100%)") - }, to: function (a) { - t(a, "transform", "translateX(0%)") - }}, "inner-out": {from: function (a) { - t(a, "transform", "translateX(0%)") - }, to: function (a) { - t(a, "transform", "translateX(-100%)") - }}}), A.fn = A.prototype = {constructor: A, getEl: function (a) { - return this.el ? k("[" + M + '-name="' + a + '"]', this.el) : void 0 - }, val: function (a, b) { - var c = "string" == typeof a ? this.getEl(a) : a; - return c && null == c.value && (c = l(c, "input")[0] || l(c, "textarea")[0] || l(c, "select")[0]), c && null != b && (c.value = b), c && c.value || "" - }, toJSON: function () { - for (var a, b = this.el.querySelectorAll("[" + M + "-name]"), c = {}, d = b.length; d--;)a = b[d], c[a.getAttribute(M + "-name")] = this.val(a); - return c - }}, C.factory = function (a, b, c) { - C[a.replace(/^\s+|\s+$/g, "").replace(/\s+/g, " ")] = function (d, e) { - var f = H.createDocumentFragment(); - if (null != d || ":root" === a) { - d = c ? d : B(d), h(c ? d : d.children, function (b, c) { - var d = ((e || a) + " " + c).replace(/^:\w+\s+/, ""), g = C(d, B(b, c), d); - m(f, g) - }), c || delete d.children; - var g = b(d, f); - return g.appendChild || j(g, d), g - } - return f - } - }, C.factory(":default", function (a, b) { - return a.children = b, a - }), C.factory(":root", function (a) { - return{tag: ".ply-form", className: a.mod, children: [C(":header", a.header), C(":content", a.content), a.ctrls && C(":default", {tag: "div.ply-footer", children: a.ctrls})]} - }), C.factory(":header", function (a, b) { - return{tag: ".ply-header", text: a.text, children: b} - }), C.factory(":content", function (a, b) { - return{tag: ".ply-content", children: b} - }, !0), C.factory("ok", function (a) { - return{ply: ":ok", tag: "button.ply-ctrl.ply-ok", text: a === !0 ? J.ok : a} - }), C.factory("cancel", function (a) { - return{ply: ":close", tag: "button.ply-ctrl.ply-cancel", type: "reset", text: a === !0 ? J.cancel : a} - }), D.use = function (a, b, c, d, e) { - D["_" + a](b, c, d, e) - }, D("default", function (a, b, c) { - c(b || {}) - }), D("alert", function (a, b, c) { - c(E("alert", a, b, {ok: !0})) - }), D("confirm", function (a, b, c) { - c(E("confirm", a, b, {ok: !0, cancel: !0})) - }), D("prompt", function (a, b, c) { - c(E("prompt", a, b, {ok: !0, cancel: !0})) - }), C.factory("dialog-form *", function (a) { - return{tag: "input.ply-input", type: a.type || "text", name: a.name, value: a.value, required: !0, placeholder: a.hint || a.text} - }), z.create = function (a, b, c) { - c || (c = b, b = {}); - var d = D[a] || D["default"]; - return d(b, c).then(function (a) { - return new z(j(b, {el: a})) - }) - }, z.open = function (a, b, c) { - return z.create(a, b, c).then(function (a) { - return a.open() - }) - }, z.dialog = function (a, b, c) { - return a instanceof Object ? (b = b || {}, d(function (c, d) { - var e, f, g, i = b.initState, k = a, l = {}, m = function (a, c) { - (b.progress || G)(j({name: e.$name, index: e.$index, length: o, stack: k, current: e, layer: c}, a), l) - }, n = function (a, b, c) { - var d = JSON.parse(JSON.stringify(a.data)); - e = a, g = !0, (a.prepare || G)(d, l), z.create(a.ui || "alert", a.options || {}, d).then(function (d) { - var e; - f ? e = f[/^inner/.test(b) ? "innerSwap" : "swap"](d, b) : (f = d, e = f.open()), e.then(function () { - l[a.$name].el = f.layerEl, g = !1 - }), c(f) - }) - }, o = 0; - h(k, function (a, b) { - i = i || b, a.effects = a.effects || {}, a.$name = b, a.$index = o++, l[b] = new z.Context - }), k.$length = o, n(k[i], null, function (a) { - m({}, a), f.options.callback = function (a) { - if (g)return!1; - var b = a.state || "next" === e.back, f = k[e[b ? "next" : "back"]]; - return f ? (n(f, e[b ? "nextEffect" : "backEffect"], function (b) { - m(a, b) - }), !1) : void(a.state ? c : d)(a, l) - } - }) - })) : (c || (c = b || {}, b = {}), z.open(a, b, c).then(function (a) { - return d(function (b) { - a.options.close = function () { - b(a.result) - } - }) - })) - }, z.ui = C, z.factory = D, z.lang = J, z.css = t, z.cssHooks = R, z.keys = L, z.noop = G, z.each = h, z.extend = j, z.promise = d, z.support = K, z.defaults = N, z.attrName = M, z.Context = A, z.dom = {build: q, append: m, remove: n, addEvent: o, removeEvent: p}, z -}); +/*! Ply 0.4.0 - MIT | git://github.com/rubaxa/Ply.git */ +!function(a){"use strict";"function"==typeof define&&define.amd?define(a):window.Ply=a()}(function(){"use strict";function a(a){if(O)return new O(a);var b=M.Deferred();return a(b.resolve,b.reject),b}function b(a){return O?O.all(a):M.when.apply(M,a)}function c(b){return a(function(a){return a(b)})}function d(a){return a&&a.then?a:c(a)}function e(a){return"function"==typeof a}function f(a,b){if(a)for(var c in a)a.hasOwnProperty(c)&&b(a[c],c,a)}function g(a){var b={};return f(a,function(a,c){b[c]=e(a)?a:a instanceof Object?g(a):a}),b}function h(a){for(var b=Array.prototype.slice,c=b.call(arguments,1),d=0,e=c.length;e>d;d++)f(c[d],function(b,c){a[c]=b});return a}function i(a,b){try{return(b||G).querySelector(a)}catch(c){return M(a,b)[0]}}function j(a,b){return a.getElementsByTagName(b)}function k(a,b){try{a&&b&&a.appendChild(b)}catch(c){}}function l(a){a&&a.parentNode&&a.parentNode.removeChild(a)}function m(a,b,c){var d=c.handle=c.handle||function(b){b.target||(b.target=b.srcElement||G),3===b.target.nodeType&&(b.target=b.target.parentNode),b.preventDefault||(b.preventDefault=function(){b.returnValue=!1}),b.stopPropagation||(b.stopPropagation=function(){b.cancelBubble=!0}),c.call(a,b)};a.addEventListener?a.addEventListener(b,d,!1):a.attachEvent("on"+b,d)}function n(a,b,c){var d=c.handle;d&&(a.removeEventListener?a.removeEventListener(b,d,!1):a.detachEvent("on"+b,d))}function o(a){if(null==a&&(a="div"),a.appendChild)return a;if(a.skip)return G.createDocumentFragment();"string"==typeof a&&(a={tag:a});var b,c=a.children,d=P.exec(a.tag||"");return delete a.children,a.tag=d[1]||"div",a.id=a.id||(d[2]||"").substr(1),d=(d[3]||"").split("."),d[0]=a.className||"",a.className=d.join(" "),b=G.createElement(a.tag),delete a.tag,f(a,function(c,d){if(c)if("css"===d)r(b,a.css);else if("text"===d)null!=c&&k(b,G.createTextNode(c));else if("html"===d)null!=c&&(b.innerHTML=c);else if("ply"===d)b.setAttribute(L,c);else if(d in b)try{b[d]=c}catch(e){b.setAttribute(d,c)}else/^data-/.test(d)&&b.setAttribute(d,c)}),c&&c.appendChild?k(b,c):f(c,function(a,c){a&&("string"==typeof a?a={text:a}:"object"!=typeof a&&(a={}),"string"==typeof c&&(a.tag=a.tag||c),k(b,o(a)))}),b}function p(a){for(var b,c,d=j(a,"input"),e=0,f=d.length;f>e;e++)if(b=d[e],"submit"===b.type)!c&&(c=b);else if(!/hidden|check|radio/.test(b.type)&&""==b.value){c=b;break}c||(c=j(a,"button")[0]);try{c.focus()}catch(g){}}function q(b){return s(!0),a(function(a){for(var c,d=j(b,"img"),e=d.length,f=e,g=function(){if(--f<=0){for(e=d.length;e--;)c=d[e],n(c,"load",g),n(c,"error",g);s(!1),a()}};e--;)c=d[e],c.complete?f--:(m(c,"load",g),m(c,"error",g));!f&&g()})}function r(a,b,c){if(a&&a.style&&b)if(b instanceof Object)for(var d in b)r(a,d,b[d]);else{if(void 0===c)return G.defaultView&&G.defaultView.getComputedStyle?c=G.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];Q[b]?Q[b](a.style,c):a.style[J[b]||b]=c}}function s(a){var b=s.get();clearTimeout(s.pid),s.pid=a?H(function(){k(G.body,b)},100):H(function(){l(b)},100)}function t(a,b){return o({css:{padding:"20px 20px 40px",display:"inline-block",position:"relative",textAlign:"left",whiteSpace:"normal",verticalAlign:"middle",transform:"translate3d(0, 0, 0)"},children:b.baseHtml?[{ply:":layer",tag:".ply-layer",className:b.mod,css:h({overflow:"hidden",position:"relative",backfaceVisibility:"hidden"},b.layer),children:[b.flags.closeBtn&&{ply:":close",tag:".ply-x",text:I.cross},{tag:".ply-inside",children:a}]}]:a})}function u(a){return o({ply:":overlay",tag:".ply-overlay",css:{top:0,left:0,right:0,bottom:0,position:"fixed"},children:[{tag:"div",css:h({width:"100%",height:"100%"},a)}]})}function v(a,b,c){a.wrapEl=o({tag:"form",css:{whiteSpace:"nowrap",zIndex:b.zIndex}}),c||(a.overlayEl=u(b.overlay),a.overlayBoxEl=a.overlayEl.firstChild,k(a.wrapEl,a.overlayEl));var d=o();r(d,{height:"100%",display:"inline-block",verticalAlign:"middle"}),k(a.wrapEl,d);var e=b.el;return a.el=e&&e.cloneNode?e.cloneNode(!0):o({html:e||""}),a.layerEl=t(a.el,b),a.contentEl=w(a.layerEl),a.context=new y(a.layerEl),k(a.wrapEl,a.layerEl),a.bodyEl=b.body&&i(b.body)||G.body,a.wrapEl.tabIndex=-1,r(a.wrapEl,{top:0,left:0,right:0,bottom:0,position:"fixed",textAlign:"center",overflow:"auto",outline:0}),a}function w(a){return a.firstChild.lastChild.firstChild}function x(a,b){b=a instanceof Object?a:b||{},b.el=b.el||a;var d=this;d.cid="c"+D++,N.zIndex++,d.options=b=h({},N,b),b.flags=h({},N.flags,b.flags),v(d,b),d.setEffect(b.effect),d.fx=function(a){return!(d.fx.queue=d.fx.queue.then(a,a).then(function(){return d}))},d.fx.queue=c(),d.on("click",":overlay",function(){d.hasFlag("closeByOverlay")&&d.closeBy("overlay")}),d.on("click",":close",function(a,b){a.preventDefault(),d.closeBy("BUTTON"===b.nodeName?"cancel":"x")}),d.options.init(this)}function y(a){this.el=a}function z(a,b){return null==a?{skip:!0}:("string"==typeof a&&(a={text:a}),"object"==typeof a&&(a.name=a.name||b),a)}function A(a,b,c){var d,e=A[a];return e||(a=a.split(/\s+/).slice(0,-1).join(" "),e=b&&(A[a+" [name="+b.name+"]"]||A[a+" [type="+b.type+"]"])||A[a+" *"]||A[":default"]),d=o(e(b,c)),b&&b.name&&d.setAttribute(L+"-name",b.name),d.className+=" ply-ui",d}function B(b,c){B["_"+b]=c,B[b]=function(b,d){return a(function(a,e){c(b,d,a,e)}).then(function(a){return a.appendChild||(a=A(":root",a)),a})}}function C(a,b,c,d){return b.mod=a,b.effect=b.effect||"slide",b.flags=h({closeBtn:!1},b.flags),{header:c.title,content:c.form?{"dialog-form":{children:c.form}}:{el:c.text||c},ctrls:{ok:c.ok||d.ok,cancel:c.cancel===!1?null:c.cancel||d.cancel}}}var D=1,E=function(){},F=window,G=F.document,H=F.setTimeout,I={ok:"OK",cancel:"Cancel",cross:"✖"},J=function(){var a={},b=G.createElement("div").style,c="opacity transition transform perspective transformStyle transformOrigin backfaceVisibility".split(" "),d=["Webkit","Moz","O","MS"];return f(c,function(c,e){if(a[c]=c in b&&c,!a[c])for(e=0;4>e;e++){var f=d[e]+c.charAt(0).toUpperCase()+c.substr(1);if(a[c]=f in b&&f)break}}),a}(),K={esc:27},L="data-ply",M=window.jQuery||window.Zepto||window.ender||window.$,N={zIndex:1e4,layer:{},overlay:{opacity:.6,backgroundColor:"rgb(0, 0, 0)"},flags:{closeBtn:!0,bodyScroll:!1,closeByEsc:!0,closeByOverlay:!0,hideLayerInStack:!0,visibleOverlayInStack:!1},baseHtml:!0,init:E,open:E,close:E,destroy:E,callback:E},O=window.Deferred||window.Promise;c().always||(O.prototype.always=function(a){return this.then(a,a),this});var P=/^(\w+)?(#\w+)?((?:\.[\w_-]+)*)/i,Q={opacity:!J.opacity&&function(a,b){a.zoom=1,a.filter="alpha(opacity="+100*b+")"}};s.get=function(){return s.el||(s.el=o({tag:".ply-loading",children:{".ply-loading-spinner":!0}}))},x.fn=x.prototype={constructor:x,_activate:function(){if(!this.hasFlag("bodyScroll")){var a=this.bodyEl,b=o({css:{overflow:"auto",visibility:"hidden",height:"5px"},children:[{tag:"div",css:{height:"100px"}}]});this.__overflow=r(a,"overflow"),this.__paddingRight=r(a,"paddingRight"),k(a,b),r(a,{overflow:"hidden",paddingRight:b.offsetWidth-b.firstChild.offsetWidth+"px"}),l(b)}m(this.wrapEl,"submit",this._getHandleEvent("submit"))},_deactivate:function(){this.hasFlag("bodyScroll")||r(this.bodyEl,{overflow:this.__overflow,paddingRight:this.__paddingRight}),n(this.layerEl,"submit",this._getHandleEvent("submit"))},_getHandleEvent:function(a){var b=this,c=b.__handleEvent||(b.__handleEvent={});return c[a]||(c[a]=function(c){b._handleEvent(a,c)}),c[a]},_handleEvent:function(a,b){b.preventDefault(),this.closeBy(a)},applyEffect:function(a,b,c){return a=this[a]||a,a.nodeType||(c=b,b=a,a=this.layerEl),c=x.effects.get(c||this.effects),x.effects.apply.call(c,a,b)},closeBy:function(a){var b=this,c={by:a,state:"submit"===a,layer:this,data:this.context.toJSON(),context:this.context},e=this.options.callback(c);d(e).then(function(a){a!==!1&&(b.result=c,b.close())})},on:function(a,b,c){var d=this;return c||(c=b,b=":layer"),c["_"+b]=function(a){var e=a.target;do if(1===e.nodeType&&e.getAttribute(L)===b)return c.call(d,a,e);while(e!==d.wrapEl&&(e=e.parentNode))},m(d.wrapEl,a,c["_"+b]),d},off:function(a,b,c){return c||(c=b,b="layer"),n(this.wrapEl,a,c["_"+b]||E),this},hasFlag:function(a){return!!this.options.flags[a]},setEffect:function(a){return this.effects=x.effects.get(a),this},_toggleState:function(a,c){var d=this,e=a?"open":"close",f=x.stack.last;return d.visible!=a&&(d.visible=a,d[a?"_activate":"_deactivate"](),x.stack[a?"add":"remove"](d),d.fx(function(){return q(d.wrapEl).then(function(){var g=x.stack.length===(a?1:0),h=f&&f.hasFlag("hideLayerInStack"),i=g||d.hasFlag("visibleOverlayInStack");return a?(!i&&l(d.overlayBoxEl),k(d.bodyEl,d.wrapEl),d.wrapEl.focus(),p(d.layerEl),h&&f.applyEffect("close.layer",c).then(function(){l(f.layerEl)})):(f=x.stack.last)&&(k(f.wrapEl,f.layerEl),f.hasFlag("hideLayerInStack")&&f.applyEffect("open.layer",c).then(function(){p(f.el)})),b([d.applyEffect(e+".layer",c),i&&d.applyEffect("overlayEl",e+".overlay",c)]).then(function(){a||(l(d.wrapEl),k(d.overlayEl,d.overlayBoxEl)),d.options[e](d)})})})),d.fx.queue},open:function(a){return this.result=null,this._toggleState(!0,a)},close:function(a){return this._toggleState(!1,a)},_swap:function(a,c,d,e,f){var g=this;return g.visible?g.fx(function(){return q(c).then(function(){return e(),b([g.applyEffect(a,"close.layer",d),g.applyEffect(c,"open.layer",d)]).then(function(){l(a),f(),g.wrapEl.focus(),p(c)})})}):f(),g.fx.queue},swap:function(a,b){a=h({},this.options,a);var c=this,d=v({},a,!0),e=b||a.effect?x.effects.get(b||a.effect):c.effects,f=c.layerEl,g=d.layerEl;return c._swap(f,g,e,function(){k(c.bodyEl,c.wrapEl),k(c.bodyEl,d.wrapEl)},function(){l(d.wrapEl),k(c.wrapEl,g),c.el=d.el,c.layerEl=g,c.contentEl=w(g),c.context.el=g})},innerSwap:function(a,b){a=h({},this.options,a);var c=this,d=v({},a,!0),e=b||a.effect?x.effects.get(b||a.effect):c.effects,f=i(".ply-inside",d.layerEl),g=i(".ply-inside",c.layerEl);return c._swap(g,f,e,function(){r(g,{width:g.offsetWidth+"px",position:"absolute"}),k(g.parentNode,f)},E)},destroy:function(){l(this.wrapEl),this._deactivate(),x.stack.remove(this),this.visible=!1,this.options.destroy(this)}};var R=[],S=R.push,T=R.splice;return x.stack={_idx:{},last:null,length:0,_pop:function(a){var b=x.stack.last;a.keyCode===K.esc&&b.hasFlag("closeByEsc")&&b.closeBy("esc")},add:function(a){var b=S.call(this,a);this.last=a,this._idx[a.cid]=b-1,1===b&&m(G,"keyup",this._pop)},remove:function(a){var b=this._idx[a.cid];b>=0&&(T.call(this,b,1),delete this._idx[a.cid],this.last=this[this.length-1],this.last||n(G,"keyup",this._pop))}},x.effects={defaults:{duration:300,open:{layer:null,overlay:null},close:{layer:null,overlay:null}},setup:function(a){this.defaults=this.get(a)},set:function(a){h(this,a)},get:function(a){function b(a){var b=/^([\w_-]+)(?::(\d+%?))?(\[[^\]]+\])?/.exec(a)||[];return{name:b[1]||a,duration:b[2]||null,args:JSON.parse(b[3]||"null")||{}}}function c(c,d,e){var f=b(d),g=c[f.name]||e||{},h=f.duration||g.duration||c.duration||a.duration;return"string"==typeof g&&(g=b(g),delete g.args),/%/.test(g.duration)&&(g.duration=parseInt(g.duration,10)/100*h),g.duration=0|(g.duration||h),g}var d=g(this.defaults);if("string"==typeof a){var e=b(a);a=g(this[e.name]||{open:{},close:{}}),a.duration=e.duration||a.duration,a.open.args=e.args[0],a.close.args=e.args[1]}else if(a instanceof Array){var f=b(a[0]),h=b(a[1]),i=this[f.name],j=this[h.name];a={open:g(i&&i.open||{layer:a[0],overlay:a[0]}),close:g(j&&j.close||{layer:a[1],overlay:a[1]})},a.open.args=f.args[0],a.close.args=h.args[0]}else a instanceof Object||(a={});a.duration=0|(a.duration||d.duration);for(var k in{open:0,close:0}){var l=a[k]||d[k]||{};"string"==typeof l&&(l={layer:l}),l.layer=c(l,"layer",d[k].layer),l.overlay=c(l,"overlay",d[k].overlay),void 0===l.args&&delete l.args,a[k]=l}return a},apply:function(b,d){d=d.split(".");var h,i,j=this[d[0]],k=b.firstChild,l=[b.getAttribute("style"),k&&k.getAttribute("style")];return J.transition&&j&&(i=j[d[1]])&&(h=x.effects[i.name])&&(h.to||h.from)?(h=g(h),r(b,"transition","none"),r(k,"transition","none"),f(h.to,function(a,c,d){"&"===a&&(d[c]=r(b,c))}),e(h.from)?h.from(b,j.args):h.from&&r(b,h.from),a(function(a){h.width=b.offsetWidth,r(b,"transition","all "+i.duration+"ms"),r(k,"transition","all "+i.duration+"ms"),e(h.to)?h.to(b,j.args):r(b,h.to),H(a,i.duration)}).then(function(){b.setAttribute("style",l[0]),k&&k.setAttribute("style",l[1])})):c()}},x.effects.set({fade:{open:{layer:"fade-in:80%",overlay:"fade-in:100%"},close:{layer:"fade-out:60%",overlay:"fade-out:60%"}},scale:{open:{layer:"scale-in",overlay:"fade-in"},close:{layer:"scale-out",overlay:"fade-out"}},fall:{open:{layer:"fall-in",overlay:"fade-in"},close:{layer:"fall-out",overlay:"fade-out"}},slide:{open:{layer:"slide-in",overlay:"fade-in"},close:{layer:"slide-out",overlay:"fade-out"}},"3d-flip":{open:{layer:"3d-flip-in",overlay:"fade-in"},close:{layer:"3d-flip-out",overlay:"fade-out"}},"3d-sign":{open:{layer:"3d-sign-in",overlay:"fade-in"},close:{layer:"3d-sign-out",overlay:"fade-out"}},inner:{open:{layer:"inner-in"},close:{layer:"inner-out"}},"fade-in":{from:{opacity:0},to:{opacity:"&"}},"fade-out":{to:{opacity:0}},"slide-in":{from:{opacity:0,transform:"translateY(20%)"},to:{opacity:"&",transform:"translateY(0)"}},"slide-out":{to:{opacity:0,transform:"translateY(20%)"}},"fall-in":{from:{opacity:0,transform:"scale(1.3)"},to:{opacity:"&",transform:"scale(1)"}},"fall-out":{to:{opacity:0,transform:"scale(1.3)"}},"scale-in":{from:{opacity:0,transform:"scale(0.7)"},to:{opacity:"&",transform:"scale(1)"}},"scale-out":{to:{opacity:0,transform:"scale(0.7)"}},rotate3d:function(a,b,c,d,e){r(a,{perspective:"1300px"}),r(a.firstChild,{opacity:b,transform:"rotate"+c+"("+d+"deg)",transformStyle:"preserve-3d",transformOrigin:e?"50% 0":"50%"})},"3d-sign-in":{from:function(a){x.effects.rotate3d(a,0,"X",-60,"50% 0")},to:function(a){r(a.firstChild,{opacity:1,transform:"rotateX(0)"})}},"3d-sign-out":{from:function(a){x.effects.rotate3d(a,1,"X",0,"50% 0")},to:function(a){r(a.firstChild,{opacity:0,transform:"rotateX(-60deg)"})}},"3d-flip-in":{from:function(a,b){x.effects.rotate3d(a,0,"Y",b||-70)},to:function(a){r(a.firstChild,{opacity:1,transform:"rotateY(0)"})}},"3d-flip-out":{from:function(a){x.effects.rotate3d(a,1,"Y",0)},to:function(a,b){r(a.firstChild,{opacity:0,transform:"rotateY("+(b||70)+"deg)"})}},"inner-in":{from:function(a){r(a,"transform","translateX(100%)")},to:function(a){r(a,"transform","translateX(0%)")}},"inner-out":{from:function(a){r(a,"transform","translateX(0%)")},to:function(a){r(a,"transform","translateX(-100%)")}}}),y.fn=y.prototype={constructor:y,getEl:function(a){return this.el?i("["+L+'-name="'+a+'"]',this.el):void 0},val:function(a,b){var c="string"==typeof a?this.getEl(a):a;return c&&null==c.value&&(c=j(c,"input")[0]||j(c,"textarea")[0]||j(c,"select")[0]),c&&null!=b&&(c.value=b),c&&c.value||""},toJSON:function(){for(var a,b=this.el.querySelectorAll("["+L+"-name]"),c={},d=b.length;d--;)a=b[d],c[a.getAttribute(L+"-name")]=this.val(a);return c}},A.factory=function(a,b,c){A[a.replace(/^\s+|\s+$/g,"").replace(/\s+/g," ")]=function(d,e){var g=G.createDocumentFragment();if(null!=d||":root"===a){d=c?d:z(d),f(c?d:d.children,function(b,c){var d=((e||a)+" "+c).replace(/^:\w+\s+/,""),f=A(d,z(b,c),d);k(g,f)}),c||delete d.children;var i=b(d,g);return i.appendChild||h(i,d),i}return g}},A.factory(":default",function(a,b){return a.children=b,a}),A.factory(":root",function(a){return{tag:".ply-form",className:a.mod,children:[A(":header",a.header),A(":content",a.content),a.ctrls&&A(":default",{tag:"div.ply-footer",children:a.ctrls})]}}),A.factory(":header",function(a,b){return{tag:".ply-header",text:a.text,children:b}}),A.factory(":content",function(a,b){return{tag:".ply-content",children:b}},!0),A.factory("ok",function(a){return{ply:":ok",tag:"button.ply-ctrl.ply-ok",text:a===!0?I.ok:a}}),A.factory("cancel",function(a){return{ply:":close",tag:"button.ply-ctrl.ply-cancel",type:"reset",text:a===!0?I.cancel:a}}),B.use=function(a,b,c,d,e){B["_"+a](b,c,d,e)},B("default",function(a,b,c){c(b||{})}),B("alert",function(a,b,c){c(C("alert",a,b,{ok:!0}))}),B("confirm",function(a,b,c){c(C("confirm",a,b,{ok:!0,cancel:!0}))}),B("prompt",function(a,b,c){c(C("prompt",a,b,{ok:!0,cancel:!0}))}),A.factory("dialog-form *",function(a){return{tag:"input.ply-input",type:a.type||"text",name:a.name,value:a.value,required:!0,placeholder:a.hint||a.text}}),x.create=function(a,b,c){c||(c=b,b={});var d=B[a]||B["default"];return d(b,c).then(function(a){return new x(h(b,{el:a}))})},x.open=function(a,b,c){return x.create(a,b,c).then(function(a){return a.open()})},x.dialog=function(b,c,d){return b instanceof Object?(c=c||{},a(function(a,d){var e,g,i,j=c.initState,k=b,l={},m=function(a,b){(c.progress||E)(h({name:e.$name,index:e.$index,length:o,stack:k,current:e,layer:b},a),l)},n=function(a,b,c){var d=JSON.parse(JSON.stringify(a.data));e=a,i=!0,(a.prepare||E)(d,l),x.create(a.ui||"alert",a.options||{},d).then(function(d){var e;g?e=g[/^inner/.test(b)?"innerSwap":"swap"](d,b):(g=d,e=g.open()),e.then(function(){l[a.$name].el=g.layerEl,i=!1}),c(g)})},o=0;f(k,function(a,b){j=j||b,a.effects=a.effects||{},a.$name=b,a.$index=o++,l[b]=new x.Context}),k.$length=o,n(k[j],null,function(b){m({},b),g.options.callback=function(b){if(i)return!1;var c=b.state||"next"===e.back,f=k[e[c?"next":"back"]];return f?(n(f,e[c?"nextEffect":"backEffect"],function(a){m(b,a)}),!1):void(b.state?a:d)(b,l)}})})):(d||(d=c||{},c={}),x.open(b,c,d).then(function(b){return a(function(a,c){b.options.close=function(){(b.result.state?a:c)(b.result)}})}))},x.ui=A,x.factory=B,x.lang=I,x.css=r,x.cssHooks=Q,x.keys=K,x.noop=E,x.each=f,x.extend=h,x.promise=a,x.support=J,x.defaults=N,x.attrName=L,x.Context=y,x.dom={build:o,append:k,remove:l,addEvent:m,removeEvent:n},x}); \ No newline at end of file diff --git a/src/Ply.es6 b/src/Ply.es6 index 26923b2..9c626ab 100644 --- a/src/Ply.es6 +++ b/src/Ply.es6 @@ -4,8 +4,8 @@ * Обязательно нужен JSON и Promise */ -/*global require, define, window */ -((factory) => { +/*global require, define, window*/ +(factory => { 'use strict'; if( typeof define === 'function' && define.amd ){ @@ -39,6 +39,13 @@ ; + // + // $-like object + // + var $ = require('jquery'); + + + // // Настройки по умолчанию // diff --git a/src/dom.es6 b/src/dom.es6 index 56e0143..91f5385 100644 --- a/src/dom.es6 +++ b/src/dom.es6 @@ -3,9 +3,6 @@ */ -var $ = require('jquery'); - - /** * Разбор строки "tag#id.foo.bar" * @const {RegExp} diff --git a/src/promise.js b/src/promise.es6 similarity index 84% rename from src/promise.js rename to src/promise.es6 index f4440af..3115f81 100644 --- a/src/promise.js +++ b/src/promise.es6 @@ -6,7 +6,6 @@ var Promise = window.Deferred || window.Promise; - /** * Создать «Обещание» * @param {Function} executor @@ -59,3 +58,14 @@ function _cast(value) { return value && value.then ? value : _resolvePromise(value); } + + +// +// Проверяем поддержку метода always +// +if (!_resolvePromise().always) { + Promise.prototype.always = function (callback) { + this.then(callback, callback); + return this; + }; +} diff --git a/src/ui.es6 b/src/ui.es6 index d5a2905..0a36056 100644 --- a/src/ui.es6 +++ b/src/ui.es6 @@ -2,7 +2,7 @@ * @desc Диалоги */ -/*global define, Ply */ +/*global Ply */ ;;;(Ply => { 'use strict'; @@ -396,9 +396,9 @@ } return Ply.open(name, options, data).then((layer) => { - return _promise((resolve) => { + return _promise((resolve, reject) => { layer.options.close = () => { - resolve(layer.result); + (layer.result.state ? resolve : reject)(layer.result); }; }); }); diff --git a/tests/Ply.ui.tests.js b/tests/Ply.ui.tests.js index 7f8213e..8904700 100644 --- a/tests/Ply.ui.tests.js +++ b/tests/Ply.ui.tests.js @@ -2,14 +2,15 @@ module('Ply.ui'); - promiseTest('dialog("unknown")', function () { + asyncTest('dialog("unknown")', function () { setTimeout(function () { simulateEvent(Ply.stack.last.overlayEl, 'click'); }, 50); - return Ply.dialog('unknown').then(function (ui) { + Ply.dialog('unknown').always(function (ui) { equal(ui.by, 'overlay', 'ui.by'); equal(ui.state, false, 'ui.state'); + start(); }); }); @@ -27,18 +28,19 @@ }); - promiseTest('dialog("confirm")', function () { + asyncTest('dialog("confirm")', function () { setTimeout(function () { var el = Ply.stack.last.wrapEl; el.getElementsByTagName('button')[1].click(); }, 50); - return Ply.dialog('confirm', { effect: 'none:1' }, { + Ply.dialog('confirm', { effect: 'none:1' }, { title: "???", text: "!!!" - }).then(function (ui) { + }).always(function (ui) { equal(ui.by, 'cancel', 'ui.by'); equal(ui.state, false, 'ui.state'); + start(); }); });