]> git.openstreetmap.org Git - rails.git/blob - vendor/assets/jquery/jquery.cookie.js
Give up on automatic resizing of text areas
[rails.git] / vendor / assets / jquery / jquery.cookie.js
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
13         var pluses = /\+/g;
14
15         function raw(s) {
16                 return s;
17         }
18
19         function decoded(s) {
20                 return decodeURIComponent(s.replace(pluses, ' '));
21         }
22
23         var config = $.cookie = function (key, value, options) {
24
25                 // write
26                 if (value !== undefined) {
27                         options = $.extend({}, config.defaults, options);
28
29                         if (value === null) {
30                                 options.expires = -1;
31                         }
32
33                         if (typeof options.expires === 'number') {
34                                 var days = options.expires, t = options.expires = new Date();
35                                 t.setDate(t.getDate() + days);
36                         }
37
38                         value = config.json ? JSON.stringify(value) : String(value);
39
40                         return (document.cookie = [
41                                 encodeURIComponent(key), '=', config.raw ? value : encodeURIComponent(value),
42                                 options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
43                                 options.path    ? '; path=' + options.path : '',
44                                 options.domain  ? '; domain=' + options.domain : '',
45                                 options.secure  ? '; secure' : ''
46                         ].join(''));
47                 }
48
49                 // read
50                 var decode = config.raw ? raw : decoded;
51                 var cookies = document.cookie.split('; ');
52                 for (var i = 0, parts; (parts = cookies[i] && cookies[i].split('=')); i++) {
53                         if (decode(parts.shift()) === key) {
54                                 var cookie = decode(parts.join('='));
55                                 return config.json ? JSON.parse(cookie) : cookie;
56                         }
57                 }
58
59                 return null;
60         };
61
62         config.defaults = {};
63
64         $.removeCookie = function (key, options) {
65                 if ($.cookie(key) !== null) {
66                         $.cookie(key, null, options);
67                         return true;
68                 }
69                 return false;
70         };
71
72 })(jQuery, document);