Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / ui / new_ui / ui / vendor / foundation / foundation.cookie.js @ faad3c72

History | View | Annotate | Download (2 kB)

1
/*!
2
 * jQuery Cookie Plugin v1.3
3
 * https://github.com/carhartl/jquery-cookie
4
 *
5
 * Copyright 2011, Klaus Hartl
6
 * Dual licensed under the MIT or GPL Version 2 licenses.
7
 * http://www.opensource.org/licenses/mit-license.php
8
 * http://www.opensource.org/licenses/GPL-2.0
9
 *
10
 * Modified to work with Zepto.js by ZURB
11
 */
12
(function ($, document, undefined) {
13

    
14
  var pluses = /\+/g;
15

    
16
  function raw(s) {
17
    return s;
18
  }
19

    
20
  function decoded(s) {
21
    return decodeURIComponent(s.replace(pluses, ' '));
22
  }
23

    
24
  var config = $.cookie = function (key, value, options) {
25

    
26
    // write
27
    if (value !== undefined) {
28
      options = $.extend({}, config.defaults, options);
29

    
30
      if (value === null) {
31
        options.expires = -1;
32
      }
33

    
34
      if (typeof options.expires === 'number') {
35
        var days = options.expires, t = options.expires = new Date();
36
        t.setDate(t.getDate() + days);
37
      }
38

    
39
      value = config.json ? JSON.stringify(value) : String(value);
40

    
41
      return (document.cookie = [
42
        encodeURIComponent(key), '=', config.raw ? value : encodeURIComponent(value),
43
        options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
44
        options.path    ? '; path=' + options.path : '',
45
        options.domain  ? '; domain=' + options.domain : '',
46
        options.secure  ? '; secure' : ''
47
      ].join(''));
48
    }
49

    
50
    // read
51
    var decode = config.raw ? raw : decoded;
52
    var cookies = document.cookie.split('; ');
53
    for (var i = 0, l = cookies.length; i < l; i++) {
54
      var parts = cookies[i].split('=');
55
      if (decode(parts.shift()) === key) {
56
        var cookie = decode(parts.join('='));
57
        return config.json ? JSON.parse(cookie) : cookie;
58
      }
59
    }
60

    
61
    return null;
62
  };
63

    
64
  config.defaults = {};
65

    
66
  $.removeCookie = function (key, options) {
67
    if ($.cookie(key) !== null) {
68
      $.cookie(key, null, options);
69
      return true;
70
    }
71
    return false;
72
  };
73

    
74
})(Foundation.zj, document);