SHOW:
|
|
- or go back to the newest paste.
| 1 | /* | |
| 2 | * SimpleModal 1.4.3 - jQuery Plugin | |
| 3 | * http://simplemodal.com/ | |
| 4 | * Copyright (c) 2012 Eric Martin | |
| 5 | * Licensed under MIT and GPL | |
| 6 | * Date: Sat, Sep 8 2012 07:52:31 -0700 | |
| 7 | */ | |
| 8 | (function (b) {
| |
| 9 | "function" === typeof define && define.amd ? define(["jquery"], b) : b(jQuery) | |
| 10 | })(function (b) {
| |
| 11 | var j = [], | |
| 12 | l = b(document), | |
| 13 | m = b.browser.msie && 6 === parseInt(b.browser.version) && "object" !== typeof window.XMLHttpRequest, | |
| 14 | o = b.browser.msie && 7 === parseInt(b.browser.version), | |
| 15 | n = null, | |
| 16 | k = b(window), | |
| 17 | h = []; | |
| 18 | b.modal = function (a, d) {
| |
| 19 | return b.modal.impl.init(a, d) | |
| 20 | }; | |
| 21 | b.modal.close = function () {
| |
| 22 | b.modal.impl.close() | |
| 23 | }; | |
| 24 | b.modal.focus = function (a) {
| |
| 25 | b.modal.impl.focus(a) | |
| 26 | }; | |
| 27 | b.modal.setContainerDimensions = function () {
| |
| 28 | b.modal.impl.setContainerDimensions() | |
| 29 | }; | |
| 30 | b.modal.setPosition = function () {
| |
| 31 | b.modal.impl.setPosition() | |
| 32 | }; | |
| 33 | b.modal.update = function (a, d) {
| |
| 34 | b.modal.impl.update(a, d) | |
| 35 | }; | |
| 36 | b.fn.modal = function (a) {
| |
| 37 | return b.modal.impl.init(this, a) | |
| 38 | }; | |
| 39 | b.modal.defaults = {
| |
| 40 | appendTo: "body", | |
| 41 | focus: !0, | |
| 42 | opacity: 50, | |
| 43 | overlayId: "simplemodal-overlay", | |
| 44 | overlayCss: {},
| |
| 45 | containerId: "simplemodal-container", | |
| 46 | containerCss: {},
| |
| 47 | dataId: "simplemodal-data", | |
| 48 | dataCss: {},
| |
| 49 | minHeight: null, | |
| 50 | minWidth: null, | |
| 51 | maxHeight: null, | |
| 52 | maxWidth: null, | |
| 53 | autoResize: !1, | |
| 54 | autoPosition: !0, | |
| 55 | zIndex: 1E3, | |
| 56 | close: !0, | |
| 57 | closeHTML: '<a class="modalCloseImg" title="Close"></a>', | |
| 58 | closeClass: "simplemodal-overlay", | |
| 59 | escClose: !0, | |
| 60 | overlayClose: !1, | |
| 61 | fixed: !0, | |
| 62 | position: null, | |
| 63 | persist: !1, | |
| 64 | modal: !0, | |
| 65 | onOpen: null, | |
| 66 | onShow: null, | |
| 67 | onClose: null | |
| 68 | }; | |
| 69 | b.modal.impl = {
| |
| 70 | d: {},
| |
| 71 | init: function (a, d) {
| |
| 72 | if (this.d.data) return !1; | |
| 73 | n = b.browser.msie && !b.support.boxModel; | |
| 74 | this.o = b.extend({}, b.modal.defaults, d);
| |
| 75 | this.zIndex = this.o.zIndex; | |
| 76 | this.occb = !1; | |
| 77 | if ("object" === typeof a) {
| |
| 78 | if (a = a instanceof b ? a : b(a), this.d.placeholder = !1, 0 < a.parent().parent().size() && (a.before(b("<span></span>").attr("id", "simplemodal-placeholder").css({
| |
| 79 | display: "none" | |
| 80 | })), this.d.placeholder = !0, this.display = a.css("display"), !this.o.persist)) this.d.orig = a.clone(!0)
| |
| 81 | } else if ("string" === typeof a || "number" === typeof a) a = b("<div></div>").html(a);
| |
| 82 | else return alert("SimpleModal Error: Unsupported data type: " + typeof a), this;
| |
| 83 | this.create(a); | |
| 84 | this.open(); | |
| 85 | b.isFunction(this.o.onShow) && this.o.onShow.apply(this, [this.d]); | |
| 86 | return this | |
| 87 | }, | |
| 88 | create: function (a) {
| |
| 89 | this.getDimensions(); | |
| 90 | if (this.o.modal && m) this.d.iframe = b('<iframe src="javascript:false;"></iframe>').css(b.extend(this.o.iframeCss, {
| |
| 91 | display: "none", | |
| 92 | opacity: 0, | |
| 93 | position: "fixed", | |
| 94 | height: h[0], | |
| 95 | width: h[1], | |
| 96 | zIndex: this.o.zIndex, | |
| 97 | top: 0, | |
| 98 | left: 0 | |
| 99 | })).appendTo(this.o.appendTo); | |
| 100 | this.d.overlay = b("<div></div>").attr("id", this.o.overlayId).addClass("simplemodal-overlay").css(b.extend(this.o.overlayCss, {
| |
| 101 | display: "none", | |
| 102 | opacity: this.o.opacity / 100, | |
| 103 | height: this.o.modal ? j[0] : 0, | |
| 104 | width: this.o.modal ? j[1] : 0, | |
| 105 | position: "fixed", | |
| 106 | left: 0, | |
| 107 | top: 0, | |
| 108 | zIndex: this.o.zIndex + 1 | |
| 109 | })).appendTo(this.o.appendTo); | |
| 110 | this.d.container = b("<div></div>").attr("id", this.o.containerId).addClass("simplemodal-container").css(b.extend({
| |
| 111 | position: this.o.fixed ? "fixed" : "absolute" | |
| 112 | }, this.o.containerCss, {
| |
| 113 | display: "none", | |
| 114 | zIndex: this.o.zIndex + 2 | |
| 115 | })).append(this.o.close && this.o.closeHTML ? b(this.o.closeHTML).addClass(this.o.closeClass) : "").appendTo(this.o.appendTo); | |
| 116 | this.d.wrap = b("<div></div>").attr("tabIndex", -1).addClass("simplemodal-wrap").css({
| |
| 117 | height: "100%", | |
| 118 | outline: 0, | |
| 119 | width: "100%" | |
| 120 | }).appendTo(this.d.container); | |
| 121 | this.d.data = a.attr("id", a.attr("id") || this.o.dataId).addClass("simplemodal-data").css(b.extend(this.o.dataCss, {
| |
| 122 | display: "none" | |
| 123 | })).appendTo("body");
| |
| 124 | this.setContainerDimensions(); | |
| 125 | this.d.data.appendTo(this.d.wrap); | |
| 126 | (m || n) && this.fixIE() | |
| 127 | }, | |
| 128 | bindEvents: function () {
| |
| 129 | var a = this; | |
| 130 | b("." + a.o.closeClass).bind("click.simplemodal", function (b) {
| |
| 131 | b.preventDefault(); | |
| 132 | a.close() | |
| 133 | }); | |
| 134 | a.o.modal && a.o.close && a.o.overlayClose && a.d.overlay.bind("click.simplemodal", function (b) {
| |
| 135 | b.preventDefault(); | |
| 136 | a.close() | |
| 137 | }); | |
| 138 | l.bind("keydown.simplemodal", function (b) {
| |
| 139 | a.o.modal && 9 === b.keyCode ? a.watchTab(b) : a.o.close && a.o.escClose && 27 === b.keyCode && (b.preventDefault(), a.close()) | |
| 140 | }); | |
| 141 | k.bind("resize.simplemodal orientationchange.simplemodal", function () {
| |
| 142 | a.getDimensions(); | |
| 143 | a.o.autoResize ? a.setContainerDimensions() : a.o.autoPosition && a.setPosition(); | |
| 144 | m || n ? a.fixIE() : a.o.modal && (a.d.iframe && a.d.iframe.css({
| |
| 145 | height: h[0], | |
| 146 | width: h[1] | |
| 147 | }), a.d.overlay.css({
| |
| 148 | height: j[0], | |
| 149 | width: j[1] | |
| 150 | })) | |
| 151 | }) | |
| 152 | }, | |
| 153 | unbindEvents: function () {
| |
| 154 | b("." + this.o.closeClass).unbind("click.simplemodal");
| |
| 155 | l.unbind("keydown.simplemodal");
| |
| 156 | k.unbind(".simplemodal");
| |
| 157 | this.d.overlay.unbind("click.simplemodal")
| |
| 158 | }, | |
| 159 | fixIE: function () {
| |
| 160 | var a = this.o.position; | |
| 161 | b.each([this.d.iframe || null, !this.o.modal ? null : this.d.overlay, "fixed" === this.d.container.css("position") ? this.d.container : null], function (b, f) {
| |
| 162 | if (f) {
| |
| 163 | var g = f[0].style; | |
| 164 | g.position = "absolute"; | |
| 165 | if (2 > b) g.removeExpression("height"), g.removeExpression("width"), g.setExpression("height", 'document.body.scrollHeight > document.body.clientHeight ? document.body.scrollHeight : document.body.clientHeight + "px"'), g.setExpression("width", 'document.body.scrollWidth > document.body.clientWidth ? document.body.scrollWidth : document.body.clientWidth + "px"');
| |
| 166 | else {
| |
| 167 | var c, e; | |
| 168 | a && a.constructor === Array ? (c = a[0] ? "number" === typeof a[0] ? a[0].toString() : a[0].replace(/px/, "") : f.css("top").replace(/px/, ""), c = -1 === c.indexOf("%") ? c + ' + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"' : parseInt(c.replace(/%/, "")) + ' * ((document.documentElement.clientHeight || document.body.clientHeight) / 100) + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"', a[1] && (e = "number" === typeof a[1] ? a[1].toString() : a[1].replace(/px/, ""), e = -1 === e.indexOf("%") ? e + ' + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"' : parseInt(e.replace(/%/, "")) + ' * ((document.documentElement.clientWidth || document.body.clientWidth) / 100) + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"')) : (c = '(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"', e = '(document.documentElement.clientWidth || document.body.clientWidth) / 2 - (this.offsetWidth / 2) + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"');
| |
| 169 | g.removeExpression("top");
| |
| 170 | g.removeExpression("left");
| |
| 171 | g.setExpression("top", c);
| |
| 172 | g.setExpression("left", e)
| |
| 173 | } | |
| 174 | } | |
| 175 | }) | |
| 176 | }, | |
| 177 | focus: function (a) {
| |
| 178 | var d = this, | |
| 179 | a = a && -1 !== b.inArray(a, ["first", "last"]) ? a : "first", | |
| 180 | f = b(":input:enabled:visible:" + a, d.d.wrap);
| |
| 181 | setTimeout(function () {
| |
| 182 | 0 < f.length ? f.focus() : d.d.wrap.focus() | |
| 183 | }, 10) | |
| 184 | }, | |
| 185 | getDimensions: function () {
| |
| 186 | var a = "undefined" === typeof window.innerHeight ? k.height() : window.innerHeight; | |
| 187 | j = [l.height(), l.width()]; | |
| 188 | h = [a, k.width()] | |
| 189 | }, | |
| 190 | getVal: function (a, b) {
| |
| 191 | return a ? "number" === typeof a ? a : "auto" === a ? 0 : 0 < a.indexOf("%") ? parseInt(a.replace(/%/, "")) / 100 * ("h" === b ? h[0] : h[1]) : parseInt(a.replace(/px/, "")) : null
| |
| 192 | }, | |
| 193 | update: function (a, b) {
| |
| 194 | if (!this.d.data) return !1; | |
| 195 | this.d.origHeight = this.getVal(a, "h"); | |
| 196 | this.d.origWidth = this.getVal(b, "w"); | |
| 197 | this.d.data.hide(); | |
| 198 | a && this.d.container.css("height", a);
| |
| 199 | b && this.d.container.css("width", b);
| |
| 200 | this.setContainerDimensions(); | |
| 201 | this.d.data.show(); | |
| 202 | this.o.focus && this.focus(); | |
| 203 | this.unbindEvents(); | |
| 204 | this.bindEvents() | |
| 205 | }, | |
| 206 | setContainerDimensions: function () {
| |
| 207 | var a = m || o, | |
| 208 | d = this.d.origHeight ? this.d.origHeight : b.browser.opera ? this.d.container.height() : this.getVal(a ? this.d.container[0].currentStyle.height : this.d.container.css("height"), "h"),
| |
| 209 | a = this.d.origWidth ? this.d.origWidth : b.browser.opera ? this.d.container.width() : this.getVal(a ? this.d.container[0].currentStyle.width : this.d.container.css("width"), "w"),
| |
| 210 | f = this.d.data.outerHeight(!0), | |
| 211 | g = this.d.data.outerWidth(!0); | |
| 212 | this.d.origHeight = this.d.origHeight || d; | |
| 213 | this.d.origWidth = this.d.origWidth || a; | |
| 214 | var c = this.o.maxHeight ? this.getVal(this.o.maxHeight, "h") : null, | |
| 215 | e = this.o.maxWidth ? this.getVal(this.o.maxWidth, "w") : null, | |
| 216 | c = c && c < h[0] ? c : h[0], | |
| 217 | e = e && e < h[1] ? e : h[1], | |
| 218 | i = this.o.minHeight ? this.getVal(this.o.minHeight, "h") : "auto", | |
| 219 | d = d ? this.o.autoResize && d > c ? c : d < i ? i : d : f ? f > c ? c : this.o.minHeight && "auto" !== i && f < i ? i : f : i, | |
| 220 | c = this.o.minWidth ? this.getVal(this.o.minWidth, "w") : "auto", | |
| 221 | a = a ? this.o.autoResize && a > e ? e : a < c ? c : a : g ? g > e ? e : this.o.minWidth && "auto" !== c && g < c ? c : g : c; | |
| 222 | this.d.container.css({
| |
| 223 | height: d, | |
| 224 | width: a | |
| 225 | }); | |
| 226 | this.d.wrap.css({
| |
| 227 | overflow: f > d || g > a ? "auto" : "visible" | |
| 228 | }); | |
| 229 | this.o.autoPosition && this.setPosition() | |
| 230 | }, | |
| 231 | setPosition: function () {
| |
| 232 | var a, b; | |
| 233 | a = h[0] / 2 - this.d.container.outerHeight(!0) / 2; | |
| 234 | b = h[1] / 2 - this.d.container.outerWidth(!0) / 2; | |
| 235 | var f = "fixed" !== this.d.container.css("position") ? k.scrollTop() : 0;
| |
| 236 | this.o.position && "[object Array]" === Object.prototype.toString.call(this.o.position) ? (a = f + (this.o.position[0] || a), b = this.o.position[1] || b) : a = f + a; | |
| 237 | this.d.container.css({
| |
| 238 | left: b, | |
| 239 | top: a | |
| 240 | }) | |
| 241 | }, | |
| 242 | watchTab: function (a) {
| |
| 243 | if (0 < b(a.target).parents(".simplemodal-container").length) {
| |
| 244 | if (this.inputs = b(":input:enabled:visible:first, :input:enabled:visible:last", this.d.data[0]), !a.shiftKey && a.target === this.inputs[this.inputs.length - 1] || a.shiftKey && a.target === this.inputs[0] || 0 === this.inputs.length) a.preventDefault(), this.focus(a.shiftKey ? "last" : "first")
| |
| 245 | } else a.preventDefault(), this.focus() | |
| 246 | }, | |
| 247 | open: function () {
| |
| 248 | this.d.iframe && this.d.iframe.show(); | |
| 249 | b.isFunction(this.o.onOpen) ? this.o.onOpen.apply(this, [this.d]) : (this.d.overlay.show(), this.d.container.show(), this.d.data.show()); | |
| 250 | this.o.focus && this.focus(); | |
| 251 | this.bindEvents() | |
| 252 | }, | |
| 253 | close: function () {
| |
| 254 | jQuery('body').removeClass('blur');
| |
| 255 | if (!this.d.data) return !1; | |
| 256 | this.unbindEvents(); | |
| 257 | if (b.isFunction(this.o.onClose) && !this.occb) this.occb = !0, this.o.onClose.apply(this, [this.d]); | |
| 258 | else {
| |
| 259 | if (this.d.placeholder) {
| |
| 260 | var a = b("#simplemodal-placeholder");
| |
| 261 | this.o.persist ? a.replaceWith(this.d.data.removeClass("simplemodal-data").css("display", this.display)) : (this.d.data.hide().remove(), a.replaceWith(this.d.orig))
| |
| 262 | } else this.d.data.hide().remove(); | |
| 263 | this.d.container.hide().remove(); | |
| 264 | this.d.overlay.hide(); | |
| 265 | this.d.iframe && this.d.iframe.hide().remove(); | |
| 266 | this.d.overlay.remove(); | |
| 267 | this.d = {}
| |
| 268 | } | |
| 269 | } | |
| 270 | } | |
| 271 | }); |