﻿(function (a) { function b() { if (a.fn.ajaxSubmit.debug && window.console && window.console.log) window.console.log("[jquery.form] " + Array.prototype.join.call(arguments, "")) } a.fn.ajaxSubmit = function (c) { function q() { function s(a, b) { if (window.ActiveXObject) { b = new ActiveXObject("Microsoft.XMLDOM"); b.async = "false"; b.loadXML(a) } else b = (new DOMParser).parseFromString(a, "text/xml"); return b && b.documentElement && b.documentElement.tagName != "parsererror" ? b : null } function r() { if (m++) return; i.detachEvent ? i.detachEvent("onload", r) : i.removeEventListener("load", r, false); var c = true; try { if (n) throw "timeout"; var d, f; f = i.contentWindow ? i.contentWindow.document : i.contentDocument ? i.contentDocument : i.document; var g = e.dataType == "xml" || f.XMLDocument || a.isXMLDoc(f); b("isXml=" + g); if (!g && (f.body == null || f.body.innerHTML == "")) { if (--q) { m = 0; setTimeout(r, 100); return } b("Could not access iframe DOM after 50 tries."); return } k.responseText = f.body ? f.body.innerHTML : null; k.responseXML = f.XMLDocument ? f.XMLDocument : f; k.getResponseHeader = function (a) { var b = { "content-type": e.dataType }; return b[a] }; if (e.dataType == "json" || e.dataType == "script") { var j = f.getElementsByTagName("textarea")[0]; if (j) k.responseText = j.value; else { var o = f.getElementsByTagName("pre")[0]; if (o) k.responseText = o.innerHTML } } else if (e.dataType == "xml" && !k.responseXML && k.responseText != null) { k.responseXML = s(k.responseText) } d = a.httpData(k, e.dataType) } catch (p) { c = false; a.handleError(e, k, "error", p) } if (c) { e.success(d, "success"); if (l) a.event.trigger("ajaxSuccess", [k, e]) } if (l) a.event.trigger("ajaxComplete", [k, e]); if (l && ! --a.active) a.event.trigger("ajaxStop"); if (e.complete) e.complete(k, c ? "success" : "error"); setTimeout(function () { h.remove(); k.responseXML = null }, 100) } var d = j[0]; if (a(":input[name=submit]", d).length) { alert('Error: Form elements must not be named "submit".'); return } var e = a.extend({}, a.ajaxSettings, c); var f = a.extend(true, {}, a.extend(true, {}, a.ajaxSettings), e); var g = "jqFormIO" + (new Date).getTime(); var h = a('<iframe id="' + g + '" name="' + g + '" src="' + e.iframeSrc + '" />'); var i = h[0]; h.css({ position: "absolute", top: "-1000px", left: "-1000px" }); var k = { aborted: 0, responseText: null, responseXML: null, status: 0, statusText: "n/a", getAllResponseHeaders: function () { }, getResponseHeader: function () { }, setRequestHeader: function () { }, abort: function () { this.aborted = 1; h.attr("src", e.iframeSrc) } }; var l = e.global; if (l && !(a.active++)) a.event.trigger("ajaxStart"); if (l) a.event.trigger("ajaxSend", [k, e]); if (f.beforeSend && f.beforeSend(k, f) === false) { f.global && a.active--; return } if (k.aborted) return; var m = 0; var n = 0; var o = d.clk; if (o) { var p = o.name; if (p && !o.disabled) { c.extraData = c.extraData || {}; c.extraData[p] = o.value; if (o.type == "image") { c.extraData[name + ".x"] = d.clk_x; c.extraData[name + ".y"] = d.clk_y } } } setTimeout(function () { var b = j.attr("target"), f = j.attr("action"); d.setAttribute("target", g); if (d.getAttribute("method") != "POST") d.setAttribute("method", "POST"); if (d.getAttribute("action") != e.url) d.setAttribute("action", e.url); if (!c.skipEncodingOverride) { j.attr({ encoding: "multipart/form-data", enctype: "multipart/form-data" }) } if (e.timeout) setTimeout(function () { n = true; r() }, e.timeout); var k = []; try { if (c.extraData) for (var l in c.extraData) k.push(a('<input type="hidden" name="' + l + '" value="' + c.extraData[l] + '" />').appendTo(d)[0]); h.appendTo("body"); i.attachEvent ? i.attachEvent("onload", r) : i.addEventListener("load", r, false); d.submit() } finally { d.setAttribute("action", f); b ? d.setAttribute("target", b) : j.removeAttr("target"); a(k).remove() } }, 10); var q = 50; } if (!this.length) { b("ajaxSubmit: skipping submit process - no element selected"); return this } if (typeof c == "function") c = { success: c }; var d = a.trim(this.attr("action")); if (d) { d = (d.match(/^([^#]+)/) || [])[1] } d = d || window.location.href || ""; c = a.extend({ url: d, type: this.attr("method") || "GET", iframeSrc: /^https/i.test(window.location.href || "") ? "javascript:false" : "about:blank" }, c || {}); var e = {}; this.trigger("form-pre-serialize", [this, c, e]); if (e.veto) { b("ajaxSubmit: submit vetoed via form-pre-serialize trigger"); return this } if (c.beforeSerialize && c.beforeSerialize(this, c) === false) { b("ajaxSubmit: submit aborted via beforeSerialize callback"); return this } var f = this.formToArray(c.semantic); if (c.data) { c.extraData = c.data; for (var g in c.data) { if (c.data[g] instanceof Array) { for (var h in c.data[g]) f.push({ name: g, value: c.data[g][h] }) } else f.push({ name: g, value: c.data[g] }) } } if (c.beforeSubmit && c.beforeSubmit(f, this, c) === false) { b("ajaxSubmit: submit aborted via beforeSubmit callback"); return this } this.trigger("form-submit-validate", [f, this, c, e]); if (e.veto) { b("ajaxSubmit: submit vetoed via form-submit-validate trigger"); return this } var i = a.param(f); if (c.type.toUpperCase() == "GET") { c.url += (c.url.indexOf("?") >= 0 ? "&" : "?") + i; c.data = null } else c.data = i; var j = this, k = []; if (c.resetForm) k.push(function () { j.resetForm() }); if (c.clearForm) k.push(function () { j.clearForm() }); if (!c.dataType && c.target) { var l = c.success || function () { }; k.push(function (b) { a(c.target).html(b).each(l, arguments) }) } else if (c.success) k.push(c.success); c.success = function (a, b) { for (var d = 0, e = k.length; d < e; d++) k[d].apply(c, [a, b, j]) }; var m = a("input:file", this).fieldValue(); var n = false; for (var o = 0; o < m.length; o++) if (m[o]) n = true; var p = false; if (m.length && c.iframe !== false || c.iframe || n || p) { if (c.closeKeepAlive) a.get(c.closeKeepAlive, q); else q() } else a.ajax(c); this.trigger("form-submit-notify", [this, c]); return this; }; a.fn.ajaxForm = function (b) { return this.ajaxFormUnbind().bind("submit.form-plugin", function () { a(this).ajaxSubmit(b); return false }).bind("click.form-plugin", function (b) { var c = b.target; var d = a(c); if (!d.is(":submit,input:image")) { var e = d.closest(":submit"); if (e.length == 0) return; c = e[0] } var f = this; f.clk = c; if (c.type == "image") { if (b.offsetX != undefined) { f.clk_x = b.offsetX; f.clk_y = b.offsetY } else if (typeof a.fn.offset == "function") { var g = d.offset(); f.clk_x = b.pageX - g.left; f.clk_y = b.pageY - g.top } else { f.clk_x = b.pageX - c.offsetLeft; f.clk_y = b.pageY - c.offsetTop } } setTimeout(function () { f.clk = f.clk_x = f.clk_y = null }, 100) }) }; a.fn.ajaxFormUnbind = function () { return this.unbind("submit.form-plugin click.form-plugin") }; a.fn.formToArray = function (b) { var c = []; if (this.length == 0) return c; var d = this[0]; var e = b ? d.getElementsByTagName("*") : d.elements; if (!e) return c; for (var f = 0, g = e.length; f < g; f++) { var h = e[f]; var i = h.name; if (!i) continue; if (b && d.clk && h.type == "image") { if (!h.disabled && d.clk == h) { c.push({ name: i, value: a(h).val() }); c.push({ name: i + ".x", value: d.clk_x }, { name: i + ".y", value: d.clk_y }) } continue } var j = a.fieldValue(h, true); if (j && j.constructor == Array) { for (var k = 0, l = j.length; k < l; k++) c.push({ name: i, value: j[k] }) } else if (j !== null && typeof j != "undefined") c.push({ name: i, value: j }) } if (!b && d.clk) { var m = a(d.clk), n = m[0], i = n.name; if (i && !n.disabled && n.type == "image") { c.push({ name: i, value: m.val() }); c.push({ name: i + ".x", value: d.clk_x }, { name: i + ".y", value: d.clk_y }) } } return c }; a.fn.formSerialize = function (b) { return a.param(this.formToArray(b)) }; a.fn.fieldSerialize = function (b) { var c = []; this.each(function () { var d = this.name; if (!d) return; var e = a.fieldValue(this, b); if (e && e.constructor == Array) { for (var f = 0, g = e.length; f < g; f++) c.push({ name: d, value: e[f] }) } else if (e !== null && typeof e != "undefined") c.push({ name: this.name, value: e }) }); return a.param(c) }; a.fn.fieldValue = function (b) { for (var c = [], d = 0, e = this.length; d < e; d++) { var f = this[d]; var g = a.fieldValue(f, b); if (g === null || typeof g == "undefined" || g.constructor == Array && !g.length) continue; g.constructor == Array ? a.merge(c, g) : c.push(g) } return c }; a.fieldValue = function (a, b) { var c = a.name, d = a.type, e = a.tagName.toLowerCase(); if (typeof b == "undefined") b = true; if (b && (!c || a.disabled || d == "reset" || d == "button" || (d == "checkbox" || d == "radio") && !a.checked || (d == "submit" || d == "image") && a.form && a.form.clk != a || e == "select" && a.selectedIndex == -1)) return null; if (e == "select") { var f = a.selectedIndex; if (f < 0) return null; var g = [], h = a.options; var i = d == "select-one"; var j = i ? f + 1 : h.length; for (var k = i ? f : 0; k < j; k++) { var l = h[k]; if (l.selected) { var m = l.value; if (!m) m = l.attributes && l.attributes["value"] && !l.attributes["value"].specified ? l.text : l.value; if (i) return m; g.push(m) } } return g } return a.value }; a.fn.clearForm = function () { return this.each(function () { a("input,select,textarea", this).clearFields() }) }; a.fn.clearFields = a.fn.clearInputs = function () { return this.each(function () { var a = this.type, b = this.tagName.toLowerCase(); if (a == "text" || a == "password" || b == "textarea") this.value = ""; else if (a == "checkbox" || a == "radio") this.checked = false; else if (b == "select") this.selectedIndex = -1 }) }; a.fn.resetForm = function () { return this.each(function () { if (typeof this.reset == "function" || typeof this.reset == "object" && !this.reset.nodeType) this.reset() }) }; a.fn.enable = function (a) { if (a == undefined) a = true; return this.each(function () { this.disabled = !a }) }; a.fn.selected = function (b) { if (b == undefined) b = true; return this.each(function () { var c = this.type; if (c == "checkbox" || c == "radio") this.checked = b; else if (this.tagName.toLowerCase() == "option") { var d = a(this).parent("select"); if (b && d[0] && d[0].type == "select-one") { d.find("option").selected(false) } this.selected = b } }) }; })(jQuery)
