cookie.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*! jquery.cookie v1.4.1 | MIT */
  2. !function (a) {
  3. "function" == typeof define && define.amd ? define(["jquery"], a) : "object" == typeof exports ? a(require("jquery")) : a(jQuery)
  4. }(function (a) {
  5. function b(a) {
  6. return h.raw ? a : encodeURIComponent(a)
  7. }
  8. function c(a) {
  9. return h.raw ? a : decodeURIComponent(a)
  10. }
  11. function d(a) {
  12. return b(h.json ? JSON.stringify(a) : String(a))
  13. }
  14. function e(a) {
  15. 0 === a.indexOf('"') && (a = a.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, "\\"));
  16. try {
  17. return a = decodeURIComponent(a.replace(g, " ")), h.json ? JSON.parse(a) : a
  18. } catch (b) {
  19. }
  20. }
  21. function f(b, c) {
  22. var d = h.raw ? b : e(b);
  23. return a.isFunction(c) ? c(d) : d
  24. }
  25. var g = /\+/g, h = a.cookie = function (e, g, i) {
  26. if (void 0 !== g && !a.isFunction(g)) {
  27. if (i = a.extend({}, h.defaults, i), "number" == typeof i.expires) {
  28. var j = i.expires, k = i.expires = new Date;
  29. k.setTime(+k + 864e5 * j)
  30. }
  31. return document.cookie = [b(e), "=", d(g), i.expires ? "; expires=" + i.expires.toUTCString() : "", i.path ? "; path=" + i.path : "", i.domain ? "; domain=" + i.domain : "", i.secure ? "; secure" : ""].join("")
  32. }
  33. for (var l = e ? void 0 : {}, m = document.cookie ? document.cookie.split("; ") : [], n = 0, o = m.length; o > n; n++) {
  34. var p = m[n].split("="), q = c(p.shift()), r = p.join("=");
  35. if (e && e === q) {
  36. l = f(r, g);
  37. break
  38. }
  39. e || void 0 === (r = f(r)) || (l[q] = r)
  40. }
  41. return l
  42. };
  43. h.defaults = {}, a.removeCookie = function (b, c) {
  44. return void 0 === a.cookie(b) ? !1 : (a.cookie(b, "", a.extend({}, c, {expires: -1})), !a.cookie(b))
  45. }
  46. });