Advertisement
Guest User

Untitled

a guest
Jul 29th, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*jshint eqnull:true */
  2. /*!
  3.  * jQuery Cookie Plugin v1.1
  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) {
  12.  
  13.     var pluses = /\+/g;
  14.     function raw(s) {
  15.         return s;
  16.     }
  17.     function decoded(s) {
  18.         return decodeURIComponent(s.replace(pluses, ' '));
  19.     }
  20.  
  21.     $.cookie = function(key, value, options) {
  22.  
  23.         // key and at least value given, set cookie...
  24.         if (arguments.length > 1 && (!/Object/.test(Object.prototype.toString.call(value)) || value == null)) {
  25.             options = $.extend({}, $.cookie.defaults, options);
  26.  
  27.             if (value == null) {
  28.                 options.expires = -1;
  29.             }
  30.  
  31.             if (typeof options.expires === 'number') {
  32.                 var days = options.expires, t = options.expires = new Date();
  33.                 t.setDate(t.getDate() + days);
  34.             }
  35.  
  36.             value = String(value);
  37.  
  38.             return (document.cookie = [
  39.                 encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value),
  40.                 options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
  41.                 options.path    ? '; path=' + options.path : '',
  42.                 options.domain  ? '; domain=' + options.domain : '',
  43.                 options.secure  ? '; secure' : ''
  44.                 ].join(''));
  45.         }
  46.  
  47.         // key and possibly options given, get cookie...
  48.         options = value || $.cookie.defaults || {};
  49.         var decode = options.raw ? raw : decoded;
  50.         var cookies = document.cookie.split('; ');
  51.         for (var i = 0, parts; (parts = cookies[i] && cookies[i].split('=')); i++) {
  52.             if (decode(parts.shift()) === key) {
  53.                 return decode(parts.join('='));
  54.             }
  55.         }
  56.         return null;
  57.     };
  58.  
  59.     $.cookie.defaults = {};
  60.  
  61. })(jQuery, document);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement