mirror of
https://github.com/processwire/processwire.git
synced 2025-08-14 18:55:56 +02:00
Update jquery.cookie.js to support SameSite attribute along with 'Lax' as default value to suppress warnings from Firefox. Plus update it to ask ProcessWire for default of 'secure' value on cookies.
This commit is contained in:
@@ -6,7 +6,9 @@
|
|||||||
* http://www.opensource.org/licenses/mit-license.php
|
* http://www.opensource.org/licenses/mit-license.php
|
||||||
* http://www.gnu.org/licenses/gpl.html
|
* http://www.gnu.org/licenses/gpl.html
|
||||||
*
|
*
|
||||||
* Updates added by Ryan (2016) to support getting/setting cookie values that are objects.
|
* Updates added by Ryan/RJC (2016) to support getting/setting cookie values that are objects.
|
||||||
|
* Updates added by Ryan/RJC (2020) to add SameSite suppport.
|
||||||
|
* Updates added by Ryan/RJC (2020) to make options.secure default to ProcessWire.config.https (when present).
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -65,6 +67,11 @@ jQuery.cookie = function(name, value, options) {
|
|||||||
// added by RJC for object value cookie support
|
// added by RJC for object value cookie support
|
||||||
value = 'JSON' + JSON.stringify(value);
|
value = 'JSON' + JSON.stringify(value);
|
||||||
}
|
}
|
||||||
|
if(typeof ProcessWire != 'undefined') {
|
||||||
|
if(typeof options.secure == 'undefined' && typeof ProcessWire.config.https != 'undefined') {
|
||||||
|
options.secure = ProcessWire.config.https; // added by Ryan to serve as default
|
||||||
|
}
|
||||||
|
}
|
||||||
var expires = '';
|
var expires = '';
|
||||||
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
|
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
|
||||||
var date;
|
var date;
|
||||||
@@ -81,8 +88,9 @@ jQuery.cookie = function(name, value, options) {
|
|||||||
// in the packed version for some reason...
|
// in the packed version for some reason...
|
||||||
var path = options.path ? '; path=' + (options.path) : '';
|
var path = options.path ? '; path=' + (options.path) : '';
|
||||||
var domain = options.domain ? '; domain=' + (options.domain) : '';
|
var domain = options.domain ? '; domain=' + (options.domain) : '';
|
||||||
|
var samesite = options.samesite ? '; SameSite=' + (options.samesite) : '; SameSite=Lax'; // RJC (Lax, Strict or None)
|
||||||
var secure = options.secure ? '; secure' : '';
|
var secure = options.secure ? '; secure' : '';
|
||||||
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
|
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, samesite, secure].join('');
|
||||||
} else { // only name given, get cookie
|
} else { // only name given, get cookie
|
||||||
var cookieValue = null;
|
var cookieValue = null;
|
||||||
if (document.cookie && document.cookie != '') {
|
if (document.cookie && document.cookie != '') {
|
||||||
|
@@ -1 +1 @@
|
|||||||
jQuery.cookie=function(b,j,m){if(typeof j!="undefined"){m=m||{};if(j===null){j="";m.expires=-1}else{if(typeof j=="object"){j="JSON"+JSON.stringify(j)}}var e="";if(m.expires&&(typeof m.expires=="number"||m.expires.toUTCString)){var f;if(typeof m.expires=="number"){f=new Date();f.setTime(f.getTime()+(m.expires*24*60*60*1000))}else{f=m.expires}e="; expires="+f.toUTCString()}var l=m.path?"; path="+(m.path):"";var g=m.domain?"; domain="+(m.domain):"";var a=m.secure?"; secure":"";document.cookie=[b,"=",encodeURIComponent(j),e,l,g,a].join("")}else{var d=null;if(document.cookie&&document.cookie!=""){var k=document.cookie.split(";");for(var h=0;h<k.length;h++){var c=jQuery.trim(k[h]);if(c.substring(0,b.length+1)==(b+"=")){d=decodeURIComponent(c.substring(b.length+1));break}}}if(typeof d=="string"){if(d.indexOf("JSON{")===0||d.indexOf("JSON[")===0){d=d.substring(4);d=JSON.parse(d)}}return d}};
|
jQuery.cookie=function(name,value,options){if(typeof value!="undefined"){options=options||{};if(value===null){value="";options.expires=-1}else if(typeof value=="object"){value="JSON"+JSON.stringify(value)}if(typeof ProcessWire!="undefined"){if(typeof options.secure=="undefined"&&typeof ProcessWire.config.https!="undefined"){options.secure=ProcessWire.config.https}}var expires="";if(options.expires&&(typeof options.expires=="number"||options.expires.toUTCString)){var date;if(typeof options.expires=="number"){date=new Date;date.setTime(date.getTime()+options.expires*24*60*60*1e3)}else{date=options.expires}expires="; expires="+date.toUTCString()}var path=options.path?"; path="+options.path:"";var domain=options.domain?"; domain="+options.domain:"";var samesite=options.samesite?"; SameSite="+options.samesite:"; SameSite=Lax";var secure=options.secure?"; secure":"";document.cookie=[name,"=",encodeURIComponent(value),expires,path,domain,samesite,secure].join("")}else{var cookieValue=null;if(document.cookie&&document.cookie!=""){var cookies=document.cookie.split(";");for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==name+"="){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break}}}if(typeof cookieValue=="string"){if(cookieValue.indexOf("JSON{")===0||cookieValue.indexOf("JSON[")===0){cookieValue=cookieValue.substring(4);cookieValue=JSON.parse(cookieValue)}}return cookieValue}};
|
Reference in New Issue
Block a user