jquery-cookies-rails 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/app/assets/javascripts/jquery.cookies.js +413 -0
- data/lib/jquery-cookies-rails.rb +9 -0
- data/lib/jquery-cookies-rails/version.rb +12 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 72ce6daf269f8eb31dad2f90aadf91606578c539
|
4
|
+
data.tar.gz: d4d8b626670092617879341c95529a88b15f24e7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 80668e04d546d595e9a7f6aea4df23e64861814029fb5acbab9a512713417294960c9f9bb7d950907b3edb4af69b9ce3efc5a362bf417567a8c653c4eae32371
|
7
|
+
data.tar.gz: 72aa66a623eebe44c733ba272d27945883810e7be0bd4f48a55c8e91500b222451f6d73adc54b5d99a557a6b5d29edc3a76dfb98d96dbfd92ff3ac5c66c2a094
|
@@ -0,0 +1,413 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2005 - 2009, James Auldridge
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* Licensed under the BSD, MIT, and GPL (your choice!) Licenses:
|
6
|
+
* http://code.google.com/p/cookies/wiki/License
|
7
|
+
*
|
8
|
+
*/
|
9
|
+
var jaaulde = window.jaaulde || {};
|
10
|
+
jaaulde.utils = jaaulde.utils || {};
|
11
|
+
jaaulde.utils.cookies = ( function()
|
12
|
+
{
|
13
|
+
var cookies = [];
|
14
|
+
|
15
|
+
var defaultOptions = {
|
16
|
+
hoursToLive: null,
|
17
|
+
path: '/',
|
18
|
+
domain: null,
|
19
|
+
secure: false
|
20
|
+
};
|
21
|
+
/**
|
22
|
+
* resolveOptions - receive an options object and ensure all options are present and valid, replacing with defaults where necessary
|
23
|
+
*
|
24
|
+
* @access private
|
25
|
+
* @static
|
26
|
+
* @parameter Object options - optional options to start with
|
27
|
+
* @return Object complete and valid options object
|
28
|
+
*/
|
29
|
+
var resolveOptions = function( options )
|
30
|
+
{
|
31
|
+
var returnValue;
|
32
|
+
|
33
|
+
if( typeof options !== 'object' || options === null )
|
34
|
+
{
|
35
|
+
returnValue = defaultOptions;
|
36
|
+
}
|
37
|
+
else
|
38
|
+
{
|
39
|
+
returnValue = {
|
40
|
+
hoursToLive: ( typeof options.hoursToLive === 'number' && options.hoursToLive !== 0 ? options.hoursToLive : defaultOptions.hoursToLive ),
|
41
|
+
path: ( typeof options.path === 'string' && options.path !== '' ? options.path : defaultOptions.path ),
|
42
|
+
domain: ( typeof options.domain === 'string' && options.domain !== '' ? options.domain : defaultOptions.domain ),
|
43
|
+
secure: ( typeof options.secure === 'boolean' && options.secure ? options.secure : defaultOptions.secure )
|
44
|
+
};
|
45
|
+
}
|
46
|
+
|
47
|
+
return returnValue;
|
48
|
+
};
|
49
|
+
/**
|
50
|
+
* expiresGMTString - add given number of hours to current date/time and convert to GMT string
|
51
|
+
*
|
52
|
+
* @access private
|
53
|
+
* @static
|
54
|
+
* @parameter Integer hoursToLive - number of hours for which cookie should be valid
|
55
|
+
* @return String - GMT time representing current date/time plus number of hours given
|
56
|
+
*/
|
57
|
+
var expiresGMTString = function( hoursToLive )
|
58
|
+
{
|
59
|
+
var dateObject = new Date();
|
60
|
+
dateObject.setTime( dateObject.getTime() + ( hoursToLive * 60 * 60 * 1000 ) );
|
61
|
+
|
62
|
+
return dateObject.toGMTString();
|
63
|
+
};
|
64
|
+
/**
|
65
|
+
* assembleOptionsString - analyze options and assemble appropriate string for setting a cookie with those options
|
66
|
+
*
|
67
|
+
* @access private
|
68
|
+
* @static
|
69
|
+
* @parameter Object options - optional options to start with
|
70
|
+
* @return String - complete and valid cookie setting options
|
71
|
+
*/
|
72
|
+
var assembleOptionsString = function( options )
|
73
|
+
{
|
74
|
+
options = resolveOptions( options );
|
75
|
+
|
76
|
+
return (
|
77
|
+
( typeof options.hoursToLive === 'number' ? '; expires=' + expiresGMTString( options.hoursToLive ) : '' ) +
|
78
|
+
'; path=' + options.path +
|
79
|
+
( typeof options.domain === 'string' ? '; domain=' + options.domain : '' ) +
|
80
|
+
( options.secure === true ? '; secure' : '' )
|
81
|
+
);
|
82
|
+
};
|
83
|
+
/**
|
84
|
+
* splitCookies - retrieve document.cookie string and break it into a hash
|
85
|
+
*
|
86
|
+
* @access private
|
87
|
+
* @static
|
88
|
+
* @return Object - hash of cookies from document.cookie
|
89
|
+
*/
|
90
|
+
var splitCookies = function()
|
91
|
+
{
|
92
|
+
cookies = {};
|
93
|
+
var pair, name, value, separated = document.cookie.split( ';' );
|
94
|
+
for( var i = 0; i < separated.length; i = i + 1 )
|
95
|
+
{
|
96
|
+
pair = separated[i].split( '=' );
|
97
|
+
name = pair[0].replace( /^\s*/, '' ).replace( /\s*$/, '' );
|
98
|
+
value = decodeURIComponent( pair[1] );
|
99
|
+
cookies[name] = value;
|
100
|
+
}
|
101
|
+
return cookies;
|
102
|
+
};
|
103
|
+
|
104
|
+
var constructor = function(){};
|
105
|
+
|
106
|
+
/**
|
107
|
+
* get - get one, several, or all cookies
|
108
|
+
*
|
109
|
+
* @access public
|
110
|
+
* @paramater Mixed cookieName - String:name of single cookie; Array:list of multiple cookie names; Void (no param):if you want all cookies
|
111
|
+
* @return Mixed - String:if single cookie requested and found; Null:if single cookie requested and not found; Object:hash of multiple or all cookies
|
112
|
+
*/
|
113
|
+
constructor.prototype.get = function( cookieName )
|
114
|
+
{
|
115
|
+
var returnValue;
|
116
|
+
|
117
|
+
splitCookies();
|
118
|
+
|
119
|
+
if( typeof cookieName === 'string' )
|
120
|
+
{
|
121
|
+
returnValue = ( typeof cookies[cookieName] !== 'undefined' ) ? cookies[cookieName] : null;
|
122
|
+
}
|
123
|
+
else if( typeof cookieName === 'object' && cookieName !== null )
|
124
|
+
{
|
125
|
+
returnValue = {};
|
126
|
+
for( var item in cookieName )
|
127
|
+
{
|
128
|
+
if( typeof cookies[cookieName[item]] !== 'undefined' )
|
129
|
+
{
|
130
|
+
returnValue[cookieName[item]] = cookies[cookieName[item]];
|
131
|
+
}
|
132
|
+
else
|
133
|
+
{
|
134
|
+
returnValue[cookieName[item]] = null;
|
135
|
+
}
|
136
|
+
}
|
137
|
+
}
|
138
|
+
else
|
139
|
+
{
|
140
|
+
returnValue = cookies;
|
141
|
+
}
|
142
|
+
|
143
|
+
return returnValue;
|
144
|
+
};
|
145
|
+
/**
|
146
|
+
* filter - get array of cookies whose names match the provided RegExp
|
147
|
+
*
|
148
|
+
* @access public
|
149
|
+
* @paramater Object RegExp - The regular expression to match against cookie names
|
150
|
+
* @return Mixed - Object:hash of cookies whose names match the RegExp
|
151
|
+
*/
|
152
|
+
constructor.prototype.filter = function( cookieNameRegExp )
|
153
|
+
{
|
154
|
+
var returnValue = {};
|
155
|
+
|
156
|
+
splitCookies();
|
157
|
+
|
158
|
+
if( typeof cookieNameRegExp === 'string' )
|
159
|
+
{
|
160
|
+
cookieNameRegExp = new RegExp( cookieNameRegExp );
|
161
|
+
}
|
162
|
+
|
163
|
+
for( var cookieName in cookies )
|
164
|
+
{
|
165
|
+
if( cookieName.match( cookieNameRegExp ) )
|
166
|
+
{
|
167
|
+
returnValue[cookieName] = cookies[cookieName];
|
168
|
+
}
|
169
|
+
}
|
170
|
+
|
171
|
+
return returnValue;
|
172
|
+
};
|
173
|
+
/**
|
174
|
+
* set - set or delete a cookie with desired options
|
175
|
+
*
|
176
|
+
* @access public
|
177
|
+
* @paramater String cookieName - name of cookie to set
|
178
|
+
* @paramater Mixed value - Null:if deleting, String:value to assign cookie if setting
|
179
|
+
* @paramater Object options - optional list of cookie options to specify (hoursToLive, path, domain, secure)
|
180
|
+
* @return void
|
181
|
+
*/
|
182
|
+
constructor.prototype.set = function( cookieName, value, options )
|
183
|
+
{
|
184
|
+
if( typeof value === 'undefined' || value === null )
|
185
|
+
{
|
186
|
+
if( typeof options !== 'object' || options === null )
|
187
|
+
{
|
188
|
+
options = {};
|
189
|
+
}
|
190
|
+
value = '';
|
191
|
+
options.hoursToLive = -8760;
|
192
|
+
}
|
193
|
+
|
194
|
+
var optionsString = assembleOptionsString( options );
|
195
|
+
|
196
|
+
document.cookie = cookieName + '=' + encodeURIComponent( value ) + optionsString;
|
197
|
+
};
|
198
|
+
/**
|
199
|
+
* del - delete a cookie (domain and path options must match those with which the cookie was set; this is really an alias for set() with parameters simplified for this use)
|
200
|
+
*
|
201
|
+
* @access public
|
202
|
+
* @paramater MIxed cookieName - String name of cookie to delete, or Bool true to delete all
|
203
|
+
* @paramater Object options - optional list of cookie options to specify ( path, domain )
|
204
|
+
* @return void
|
205
|
+
*/
|
206
|
+
constructor.prototype.del = function( cookieName, options )
|
207
|
+
{
|
208
|
+
var allCookies = {};
|
209
|
+
|
210
|
+
if( typeof options !== 'object' || options === null )
|
211
|
+
{
|
212
|
+
options = {};
|
213
|
+
}
|
214
|
+
|
215
|
+
if( typeof cookieName === 'boolean' && cookieName === true )
|
216
|
+
{
|
217
|
+
allCookies = this.get();
|
218
|
+
}
|
219
|
+
else if( typeof cookieName === 'string' )
|
220
|
+
{
|
221
|
+
allCookies[cookieName] = true;
|
222
|
+
}
|
223
|
+
|
224
|
+
for( var name in allCookies )
|
225
|
+
{
|
226
|
+
if( typeof name === 'string' && name !== '' )
|
227
|
+
{
|
228
|
+
this.set( name, null, options );
|
229
|
+
}
|
230
|
+
}
|
231
|
+
};
|
232
|
+
/**
|
233
|
+
* test - test whether the browser is accepting cookies
|
234
|
+
*
|
235
|
+
* @access public
|
236
|
+
* @return Boolean
|
237
|
+
*/
|
238
|
+
constructor.prototype.test = function()
|
239
|
+
{
|
240
|
+
var returnValue = false, testName = 'cT', testValue = 'data';
|
241
|
+
|
242
|
+
this.set( testName, testValue );
|
243
|
+
|
244
|
+
if( this.get( testName ) === testValue )
|
245
|
+
{
|
246
|
+
this.del( testName );
|
247
|
+
returnValue = true;
|
248
|
+
}
|
249
|
+
|
250
|
+
return returnValue;
|
251
|
+
};
|
252
|
+
/**
|
253
|
+
* setOptions - set default options for calls to cookie methods
|
254
|
+
*
|
255
|
+
* @access public
|
256
|
+
* @param Object options - list of cookie options to specify (hoursToLive, path, domain, secure)
|
257
|
+
* @return void
|
258
|
+
*/
|
259
|
+
constructor.prototype.setOptions = function( options )
|
260
|
+
{
|
261
|
+
if( typeof options !== 'object' )
|
262
|
+
{
|
263
|
+
options = null;
|
264
|
+
}
|
265
|
+
|
266
|
+
defaultOptions = resolveOptions( options );
|
267
|
+
};
|
268
|
+
|
269
|
+
return new constructor();
|
270
|
+
} )();
|
271
|
+
|
272
|
+
( function()
|
273
|
+
{
|
274
|
+
if( window.jQuery )
|
275
|
+
{
|
276
|
+
( function( $ )
|
277
|
+
{
|
278
|
+
$.cookies = jaaulde.utils.cookies;
|
279
|
+
|
280
|
+
var extensions = {
|
281
|
+
/**
|
282
|
+
* $( 'selector' ).cookify - set the value of an input field or the innerHTML of an element to a cookie by the name or id of the field or element
|
283
|
+
* (radio and checkbox not yet supported)
|
284
|
+
* (field or element MUST have name or id attribute)
|
285
|
+
*
|
286
|
+
* @access public
|
287
|
+
* @param Object options - list of cookie options to specify
|
288
|
+
* @return Object jQuery
|
289
|
+
*/
|
290
|
+
cookify: function( options )
|
291
|
+
{
|
292
|
+
return this.each( function()
|
293
|
+
{
|
294
|
+
var i, resolvedName = false, resolvedValue = false, name = '', value = '', nameAttrs = ['name', 'id'], nodeName, inputType;
|
295
|
+
|
296
|
+
for( i in nameAttrs )
|
297
|
+
{
|
298
|
+
if( ! isNaN( i ) )
|
299
|
+
{
|
300
|
+
name = $( this ).attr( nameAttrs[ i ] );
|
301
|
+
if( typeof name === 'string' && name !== '' )
|
302
|
+
{
|
303
|
+
resolvedName = true;
|
304
|
+
break;
|
305
|
+
}
|
306
|
+
}
|
307
|
+
}
|
308
|
+
|
309
|
+
if( resolvedName )
|
310
|
+
{
|
311
|
+
nodeName = this.nodeName.toLowerCase();
|
312
|
+
if( nodeName !== 'input' && nodeName !== 'textarea' && nodeName !== 'select' && nodeName !== 'img' )
|
313
|
+
{
|
314
|
+
value = $( this ).html();
|
315
|
+
resolvedValue = true;
|
316
|
+
}
|
317
|
+
else
|
318
|
+
{
|
319
|
+
inputType = $( this ).attr( 'type' );
|
320
|
+
if( typeof inputType === 'string' && inputType !== '' )
|
321
|
+
{
|
322
|
+
inputType = inputType.toLowerCase();
|
323
|
+
}
|
324
|
+
if( inputType !== 'radio' && inputType !== 'checkbox' )
|
325
|
+
{
|
326
|
+
value = $( this ).val();
|
327
|
+
resolvedValue = true;
|
328
|
+
}
|
329
|
+
}
|
330
|
+
|
331
|
+
if( resolvedValue )
|
332
|
+
{
|
333
|
+
if( typeof value !== 'string' || value === '' )
|
334
|
+
{
|
335
|
+
value = null;
|
336
|
+
}
|
337
|
+
$.cookies.set( name, value, options );
|
338
|
+
}
|
339
|
+
}
|
340
|
+
} );
|
341
|
+
},
|
342
|
+
/**
|
343
|
+
* $( 'selector' ).cookieFill - set the value of an input field or the innerHTML of an element from a cookie by the name or id of the field or element
|
344
|
+
*
|
345
|
+
* @access public
|
346
|
+
* @return Object jQuery
|
347
|
+
*/
|
348
|
+
cookieFill: function()
|
349
|
+
{
|
350
|
+
return this.each( function()
|
351
|
+
{
|
352
|
+
var i, resolvedName = false, name = '', value, nameAttrs = ['name', 'id'], iteration = 0, nodeName;
|
353
|
+
|
354
|
+
for( i in nameAttrs )
|
355
|
+
{
|
356
|
+
if( ! isNaN( i ) )
|
357
|
+
{
|
358
|
+
name = $( this ).attr( nameAttrs[ i ] );
|
359
|
+
if( typeof name === 'string' && name !== '' )
|
360
|
+
{
|
361
|
+
resolvedName = true;
|
362
|
+
break;
|
363
|
+
}
|
364
|
+
}
|
365
|
+
}
|
366
|
+
|
367
|
+
if( resolvedName )
|
368
|
+
{
|
369
|
+
value = $.cookies.get( name );
|
370
|
+
if( value !== null )
|
371
|
+
{
|
372
|
+
nodeName = this.nodeName.toLowerCase();
|
373
|
+
if( nodeName === 'input' || nodeName === 'textarea' || nodeName === 'select' )
|
374
|
+
{
|
375
|
+
$( this ).val( value );
|
376
|
+
}
|
377
|
+
else
|
378
|
+
{
|
379
|
+
$( this ).html( value );
|
380
|
+
}
|
381
|
+
}
|
382
|
+
}
|
383
|
+
|
384
|
+
iteration = 0;
|
385
|
+
} );
|
386
|
+
},
|
387
|
+
/**
|
388
|
+
* $( 'selector' ).cookieBind - call cookie fill on matching elements, and bind their change events to cookify()
|
389
|
+
*
|
390
|
+
* @access public
|
391
|
+
* @param Object options - list of cookie options to specify
|
392
|
+
* @return Object jQuery
|
393
|
+
*/
|
394
|
+
cookieBind: function( options )
|
395
|
+
{
|
396
|
+
return this.each( function()
|
397
|
+
{
|
398
|
+
$( this ).cookieFill().change( function()
|
399
|
+
{
|
400
|
+
$( this ).cookify( options );
|
401
|
+
} );
|
402
|
+
} );
|
403
|
+
}
|
404
|
+
};
|
405
|
+
|
406
|
+
$.each( extensions, function( i )
|
407
|
+
{
|
408
|
+
$.fn[i] = this;
|
409
|
+
} );
|
410
|
+
|
411
|
+
} )( window.jQuery );
|
412
|
+
}
|
413
|
+
} )();
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jquery-cookies-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Auldridge
|
8
|
+
- Mike Virata-Stone
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-04-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: railties
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '3.0'
|
21
|
+
- - <
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '5.0'
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '3.0'
|
31
|
+
- - <
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
description: This gem wraps the jquery.cookies JavaScript library as a Rails asset
|
35
|
+
gem. The library is by James Auldridge, and the gem is packaged by Mike Virata-Stone.
|
36
|
+
email:
|
37
|
+
- mike@virata-stone.com
|
38
|
+
executables: []
|
39
|
+
extensions: []
|
40
|
+
extra_rdoc_files: []
|
41
|
+
files:
|
42
|
+
- lib/jquery-cookies-rails.rb
|
43
|
+
- lib/jquery-cookies-rails/version.rb
|
44
|
+
- app/assets/javascripts/jquery.cookies.js
|
45
|
+
homepage: https://code.google.com/p/cookies/
|
46
|
+
licenses:
|
47
|
+
- MIT
|
48
|
+
metadata: {}
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 2.0.3
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: Rails asset gem for jquery.cookies.
|
69
|
+
test_files: []
|