source: extensions/Autosize/js/autosize.cookie.js @ 22360

Last change on this file since 22360 was 22360, checked in by cljosse, 11 years ago

[extensions] Autosize update to piwigo 2.5 (fix bugs with pamooramics, charlies's )

File size: 2.2 KB
Line 
1if (typeof jQuery.cookie != "function") {
2  var cookie_options = null;
3
4  jQuery.cookie = function (name, value, options) {
5    if (typeof value != 'undefined') { // name and value given, set cookie
6      options = options || {};
7      if (value === null) {
8        value = '';
9        options.expires = -1;
10      }
11      var expires = '';
12      if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
13        var date;
14        if (typeof options.expires == 'number') {
15          date = new Date();
16          date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
17        } else {
18          date = options.expires;
19        }
20        expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
21      }
22      // CAUTION: Needed to parenthesize options.path and options.domain
23      // in the following expressions, otherwise they evaluate to undefined
24      // in the packed version for some reason...
25      cookie_options = options;
26      var path = options.path ? '; path=' + (options.path) : '';
27      var domain = options.domain ? '; domain=' + (options.domain) : '';
28      var secure = options.secure ? '; secure' : '';
29      document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
30    } else { // only name given, get cookie
31      var cookieValue = null;
32      if (name == "*") cookieValue = new Array();
33      if (document.cookie && document.cookie != '') {
34        var cookies = document.cookie.split(';');
35        for (var i = 0; i < cookies.length; i++) {
36          var cookie = jQuery.trim(cookies[i]);
37          // Does this cookie string begin with the name we want?
38          if (cookie.substring(0, name.length + 1) == (name + '=')) {
39            cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
40            break;
41          } else if (name == "*") {
42
43            cookie_name = cookie.split("=")[0];
44            cookie_value = cookie.split("=")[1];
45            cookieValue[cookie_name] = decodeURIComponent(cookie_value);
46
47          }
48        }
49      }
50      return cookieValue;
51    }
52  };
53  //=========================================================================
54}
Note: See TracBrowser for help on using the repository browser.