Skip to content

Commit 5764f3e

Browse files
Remove all jquery usage from the codebase
1 parent c7e34b7 commit 5764f3e

File tree

4 files changed

+22
-25
lines changed

4 files changed

+22
-25
lines changed

src/jquery.cookie.js

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@
88
(function (factory) {
99
if (typeof define === 'function' && define.amd) {
1010
// AMD (Register as an anonymous module)
11-
define(['jquery'], factory);
11+
define(factory);
1212
} else if (typeof exports === 'object') {
1313
// Node/CommonJS
14-
module.exports = factory(require('jquery'));
14+
module.exports = factory();
1515
} else {
1616
// Browser globals
17-
window.Cookies = factory(jQuery);
17+
window.Cookies = factory();
1818
}
19-
}(function ($) {
19+
}(function () {
2020

2121
var pluses = /\+/g;
2222

2323
function encode(s) {
24-
return config.raw ? s : encodeURIComponent(s);
24+
return api.raw ? s : encodeURIComponent(s);
2525
}
2626

2727
function decode(s) {
28-
return config.raw ? s : decodeURIComponent(s);
28+
return api.raw ? s : decodeURIComponent(s);
2929
}
3030

3131
function stringifyCookieValue(value) {
32-
return encode(config.json ? JSON.stringify(value) : String(value));
32+
return encode(api.json ? JSON.stringify(value) : String(value));
3333
}
3434

3535
function parseCookieValue(s) {
@@ -43,12 +43,12 @@
4343
// If we can't decode the cookie, ignore it, it's unusable.
4444
// If we can't parse the cookie, ignore it, it's unusable.
4545
s = decodeURIComponent(s.replace(pluses, ' '));
46-
return config.json ? JSON.parse(s) : s;
46+
return api.json ? JSON.parse(s) : s;
4747
} catch(e) {}
4848
}
4949

5050
function read(s, converter) {
51-
var value = config.raw ? s : parseCookieValue(s);
51+
var value = api.raw ? s : parseCookieValue(s);
5252
return isFunction(converter) ? converter(value) : value;
5353
}
5454

@@ -69,12 +69,12 @@
6969
return Object.prototype.toString.call(obj) === '[object Function]';
7070
}
7171

72-
var config = $.cookie = function (key, value, options) {
72+
var api = function (key, value, options) {
7373

7474
// Write
7575

7676
if (arguments.length > 1 && !isFunction(value)) {
77-
options = extend(config.defaults, options);
77+
options = extend(api.defaults, options);
7878

7979
if (typeof options.expires === 'number') {
8080
var days = options.expires, t = options.expires = new Date();
@@ -95,7 +95,7 @@
9595
var result = key ? undefined : {},
9696
// To prevent the for loop in the first place assign an empty array
9797
// in case there are no cookies at all. Also prevents odd result when
98-
// calling $.cookie().
98+
// calling "get()".
9999
cookies = document.cookie ? document.cookie.split('; ') : [],
100100
i = 0,
101101
l = cookies.length;
@@ -120,18 +120,16 @@
120120
return result;
121121
};
122122

123-
config.defaults = {};
123+
api.get = api.set = api;
124+
api.defaults = {};
124125

125-
$.removeCookie = function (key, options) {
126+
api.remove = function (key, options) {
126127
// Must not alter options, thus extending a fresh object...
127-
$.cookie(key, '', extend(options, { expires: -1 }));
128-
return !$.cookie(key);
128+
api(key, '', extend(options, { expires: -1 }));
129+
return !api(key);
129130
};
130131

131-
$.cookie.get = $.cookie;
132-
$.cookie.set = $.cookie;
133-
$.cookie.remove = $.removeCookie;
134-
$.cookie._extend = extend;
132+
api._extend = extend;
135133

136-
return $.cookie;
134+
return api;
137135
}));

test/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<title>jquery.cookie Test Suite</title>
66
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.14.0.css">
77
<script src="http://code.jquery.com/qunit/qunit-1.14.0.js"></script>
8-
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
98
<script src="../src/jquery.cookie.js"></script>
109
<script src="tests.js"></script>
1110
</head>

test/malformed_cookie.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<html>
33
<head>
44
<title></title>
5-
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
65
<script src="../src/jquery.cookie.js"></script>
76
<script>
87
try {

test/tests.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ test('invalid URL encoding', function () {
126126
asyncTest('malformed cookie value in IE (#88, #117)', function () {
127127
expect(1);
128128
// Sandbox in an iframe so that we can poke around with document.cookie.
129-
var iframe = $('<iframe src="malformed_cookie.html"></iframe>')[0];
130-
$(iframe).on('load', function () {
129+
var iframe = document.createElement('iframe');
130+
iframe.src = "malformed_cookie.html";
131+
iframe.addEventListener('load', function () {
131132
start();
132133
if (iframe.contentWindow.ok) {
133134
strictEqual(iframe.contentWindow.testValue, 'two', 'reads all cookie values, skipping duplicate occurences of "; "');

0 commit comments

Comments
 (0)