not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.0 KiB

  1. /*jshint eqnull:true */
  2. /*!
  3. * jQuery Cookie Plugin v1.2
  4. * https://github.com/carhartl/jquery-cookie
  5. *
  6. * Copyright 2011, Klaus Hartl
  7. * Dual licensed under the MIT or GPL Version 2 licenses.
  8. * http://www.opensource.org/licenses/mit-license.php
  9. * http://www.opensource.org/licenses/GPL-2.0
  10. */
  11. (function ($, document, undefined) {
  12. var pluses = /\+/g;
  13. function raw(s) {
  14. return s;
  15. }
  16. function decoded(s) {
  17. return decodeURIComponent(s.replace(pluses, ' '));
  18. }
  19. $.cookie = function (key, value, options) {
  20. // key and at least value given, set cookie...
  21. if (value !== undefined && !/Object/.test(Object.prototype.toString.call(value))) {
  22. options = $.extend({}, $.cookie.defaults, options);
  23. if (value === null) {
  24. options.expires = -1;
  25. }
  26. if (typeof options.expires === 'number') {
  27. var days = options.expires, t = options.expires = new Date();
  28. t.setDate(t.getDate() + days);
  29. }
  30. value = String(value);
  31. return (document.cookie = [
  32. encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value),
  33. options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
  34. options.path ? '; path=' + options.path : '',
  35. options.domain ? '; domain=' + options.domain : '',
  36. options.secure ? '; secure' : ''
  37. ].join(''));
  38. }
  39. // key and possibly options given, get cookie...
  40. options = value || $.cookie.defaults || {};
  41. var decode = options.raw ? raw : decoded;
  42. var cookies = document.cookie.split('; ');
  43. for (var i = 0, parts; (parts = cookies[i] && cookies[i].split('=')); i++) {
  44. if (decode(parts.shift()) === key) {
  45. return decode(parts.join('='));
  46. }
  47. }
  48. return null;
  49. };
  50. $.cookie.defaults = {};
  51. $.removeCookie = function (key, options) {
  52. if ($.cookie(key, options) !== null) {
  53. $.cookie(key, null, options);
  54. return true;
  55. }
  56. return false;
  57. };
  58. })(jQuery, document);