jQuery.cookie = function(d, e, b) { if (arguments.length > 1 && String(e) !== "[object Object]") { b = jQuery.extend({}, b); if (e === null || e === undefined) { b.expires = -1 } if (typeof b.expires === "number") { var g = b.expires, c = b.expires = new Date(); c.setDate(c.getDate() + g) } e = String(e); return (document.cookie = [encodeURIComponent(d), "=", b.raw ? e : encodeURIComponent(e), b.expires ? "; expires=" + b.expires.toUTCString() : "", b.path ? "; path=" + b.path : "", b.domain ? "; domain=" + b.domain : "", b.secure ? "; secure" : ""].join("")) } b = e || {}; var a, f = b.raw ? function(h) { return h } : decodeURIComponent; return (a = new RegExp("(?:^|; )" + encodeURIComponent(d) + "=([^;]*)").exec(document.cookie)) ? f(a[1]) : null }; (function(a) { a.fn.autosave = function(c) { var h = a.extend({}, a.fn.autosave.options, c); var g = false; var j = false; var f = 0; var d = 0; var b = 0; function e() { a(a.fn.autosave.options.saving).hide(); a(a.fn.autosave.options.autosave).click(function() { a.fn.autosave.go() }); a(a.fn.autosave.options.restore).click(function() { a.fn.autosave.restore(); return false }); a(a.fn.autosave.options.removeCookies).click(function() { a.fn.autosave.removeAllCookies(); return false }); a(window).unload(function() { a.fn.autosave.go(); return true }); setInterval(function() { if (j) { a.fn.autosave.go(); j = false } }, a.fn.autosave.options.interval); g = true } return this.filter(":text, :radio, :checkbox, select, textarea").each(function() { if (a(this).is(":text, textarea")) { a.fn.autosave.values.text[f] = this; a(this).keyup(function() { j = true }); f++ } else { if (a(this).is("select")) { a.fn.autosave.values.text[f] = this; a(this).change(function() { j = true }); f++ } else { if (a(this).is(":checkbox")) { a.fn.autosave.values.check[d] = this; a(this).click(function() { j = true }); d++ } else { a.fn.autosave.values.radio[b] = this; a(this).click(function() { j = true }); b++ } } } if (!g) { e() } }) }; a.fn.autosave.values = { text: {}, check: {}, radio: {} }; a.fn.autosave.options = { autosave: ".autosave", restore: ".autosave_restore", removeCookies: ".autosave_removecookies", saving: ".autosave_saving", interval: 10000, unique: "", onBeforeSave: function() { }, onAfterSave: function() { }, onBeforeRestore: function() { }, onAfterRestore: function() { }, cookieCharMaxSize: 2000, cookieExpiryLength: 1 }; a.fn.autosave.go = function() { a.fn.autosave.options.onBeforeSave(); var c = a.fn.autosave.values; var n = a.fn.autosave.options.unique; function b(m, k, o) { a.cookie("autosave_" + n + m + "_" + k, o, { expires: a.fn.autosave.options.cookieExpiryLength }) } function l(m) { var k = 1; while (a.cookie("autosave_" + n + m + "_" + k) !== null && k < 20) { a.cookie("autosave_" + n + m + "_" + k, null) } } for (i in c.text) { var f; var e = 0; f = a(c.text[i]).val(); size = f.length; if (size < a.fn.autosave.options.cookieCharMaxSize) { b(i, 0, f) } else { l(i); for (var d = 0; d < size; d += a.fn.autosave.options.cookieCharMaxSize) { b(i, e, f.substr(d, a.fn.autosave.options.cookieCharMaxSize)); e += 1 } } } var g = ""; for (i in c.check) { var f = a(c.check[i]).attr("checked") ? "1" : "0"; g += f + "," } a.cookie("autosave_" + n + "_check", g); var h = ""; for (i in c.radio) { if (a(c.radio[i]).is(":checked")) { h += i + "," } } a.cookie("autosave_" + n + "_radio", h); a.fn.autosave.saving(); a.fn.autosave.options.onAfterSave() }; a.fn.autosave.restore = function() { a.fn.autosave.options.onBeforeRestore(); var b = a.fn.autosave.values; var d = a.fn.autosave.options.unique; for (i in b.text) { var c = 0; var e = ""; while (a.cookie("autosave_" + d + i + "_" + c) !== null && c < 20) { e += a.cookie("autosave_" + d + i + "_" + c); c += 1 } a(b.text[i]).val(e) } var g = a.cookie("autosave_" + d + "_check").split(","); if (g !== null) { g.pop(); for (i in b.check) { var f = (g[i] == "1") ? "checked" : ""; a(b.check[i]).attr("checked", f) } } var h = a.cookie("autosave_" + d + "_radio").split(","); if (h !== null) { h.pop(); for (i in h) { a(b.radio[h[i]]).attr("checked", "checked") } } a.fn.autosave.options.onAfterRestore() }; a.fn.autosave.removeAllCookies = function() { var c = a.fn.autosave.options.unique; for (var d = 0; d < 200; d++) { var b = 0; while (a.cookie("autosave_" + c + d + "_" + b) !== null && b < 20) { a.cookie("autosave_" + c + d + "_" + b, null) } } a.cookie("autosave_" + c + "_check", null); a.cookie("autosave_" + c + "_radio", null) }; a.fn.autosave.saving = function() { a(a.fn.autosave.options.saving).show().fadeTo(1000, 1).fadeOut(500) } })(jQuery);
