[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/resources/lib/jquery/ -> jquery.cookie.js (source)

   1  /*!
   2   * jQuery Cookie Plugin v1.3.1
   3   * https://github.com/carhartl/jquery-cookie
   4   *
   5   * Copyright 2013 Klaus Hartl
   6   * Released under the MIT license
   7   */
   8  (function ($, document, undefined) {
   9  
  10      var pluses = /\+/g;
  11  
  12  	function raw(s) {
  13          return s;
  14      }
  15  
  16  	function decoded(s) {
  17          return unRfc2068(decodeURIComponent(s.replace(pluses, ' ')));
  18      }
  19  
  20  	function unRfc2068(value) {
  21          if (value.indexOf('"') === 0) {
  22              // This is a quoted cookie as according to RFC2068, unescape
  23              value = value.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
  24          }
  25          return value;
  26      }
  27  
  28  	function fromJSON(value) {
  29          return config.json ? JSON.parse(value) : value;
  30      }
  31  
  32      var config = $.cookie = function (key, value, options) {
  33  
  34          // write
  35          if (value !== undefined) {
  36              options = $.extend({}, config.defaults, options);
  37  
  38              if (value === null) {
  39                  options.expires = -1;
  40              }
  41  
  42              if (typeof options.expires === 'number') {
  43                  var days = options.expires, t = options.expires = new Date();
  44                  t.setDate(t.getDate() + days);
  45              }
  46  
  47              value = config.json ? JSON.stringify(value) : String(value);
  48  
  49              return (document.cookie = [
  50                  encodeURIComponent(key), '=', config.raw ? value : encodeURIComponent(value),
  51                  options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
  52                  options.path    ? '; path=' + options.path : '',
  53                  options.domain  ? '; domain=' + options.domain : '',
  54                  options.secure  ? '; secure' : ''
  55              ].join(''));
  56          }
  57  
  58          // read
  59          var decode = config.raw ? raw : decoded;
  60          var cookies = document.cookie.split('; ');
  61          var result = key ? null : {};
  62          for (var i = 0, l = cookies.length; i < l; i++) {
  63              var parts = cookies[i].split('=');
  64              var name = decode(parts.shift());
  65              var cookie = decode(parts.join('='));
  66  
  67              if (key && key === name) {
  68                  result = fromJSON(cookie);
  69                  break;
  70              }
  71  
  72              if (!key) {
  73                  result[name] = fromJSON(cookie);
  74              }
  75          }
  76  
  77          return result;
  78      };
  79  
  80      config.defaults = {};
  81  
  82      $.removeCookie = function (key, options) {
  83          if ($.cookie(key) !== null) {
  84              $.cookie(key, null, options);
  85              return true;
  86          }
  87          return false;
  88      };
  89  
  90  })(jQuery, document);


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1