Merge pull request #554 from shish/js-cookie-update
migrate to a non-deprecated (and dependency-free) cookie library
This commit is contained in:
commit
a7021e190e
8 changed files with 165 additions and 57 deletions
|
@ -4,14 +4,14 @@ $(document).ready(function() {
|
|||
$(".shm-blotter2-toggle").click(function() {
|
||||
$(".shm-blotter2").slideToggle("slow", function() {
|
||||
if($(".shm-blotter2").is(":hidden")) {
|
||||
$.cookie("ui-blotter2-hidden", 'true', {path: '/'});
|
||||
Cookies.set("ui-blotter2-hidden", 'true');
|
||||
}
|
||||
else {
|
||||
$.cookie("ui-blotter2-hidden", 'false', {path: '/'});
|
||||
Cookies.set("ui-blotter2-hidden", 'false');
|
||||
}
|
||||
});
|
||||
});
|
||||
if($.cookie("ui-blotter2-hidden") === 'true') {
|
||||
if(Cookies.get("ui-blotter2-hidden") === 'true') {
|
||||
$(".shm-blotter2").hide();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -21,7 +21,7 @@ $(function() {
|
|||
|
||||
$(".shm-zoomer").val(zoom_type);
|
||||
|
||||
$.cookie("ui-image-zoom", zoom_type, {path: '/', expires: 365});
|
||||
Cookies.set("ui-image-zoom", zoom_type, {expires: 365});
|
||||
}
|
||||
|
||||
$(".shm-zoomer").change(function(e) {
|
||||
|
@ -29,13 +29,13 @@ $(function() {
|
|||
});
|
||||
|
||||
$(".shm-main-image").click(function(e) {
|
||||
switch($.cookie("ui-image-zoom")) {
|
||||
switch(Cookies.get("ui-image-zoom")) {
|
||||
case "full": zoom("width"); break;
|
||||
default: zoom("full"); break;
|
||||
}
|
||||
});
|
||||
|
||||
if($.cookie("ui-image-zoom")) {
|
||||
zoom($.cookie("ui-image-zoom"));
|
||||
if(Cookies.get("ui-image-zoom")) {
|
||||
zoom(Cookies.get("ui-image-zoom"));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*jshint bitwise:false, curly:true, eqeqeq:true, evil:true, forin:false, noarg:true, noempty:true, nonew:true, undef:false, strict:false, browser:true, jquery:true */
|
||||
|
||||
$(function() {
|
||||
var blocked_tags = ($.cookie("ui-blocked-tags") || "").split(" ");
|
||||
var blocked_tags = (Cookies.get("ui-blocked-tags") || "").split(" ");
|
||||
var needs_refresh = false;
|
||||
for(var i=0; i<blocked_tags.length; i++) {
|
||||
var tag = blocked_tags[i];
|
||||
|
@ -34,9 +34,9 @@ $(function() {
|
|||
});
|
||||
|
||||
function select_blocked_tags() {
|
||||
var blocked_tags = prompt("Enter tags to ignore", $.cookie("ui-blocked-tags") || "My_Little_Pony");
|
||||
var blocked_tags = prompt("Enter tags to ignore", Cookies.get("ui-blocked-tags") || "My_Little_Pony");
|
||||
if(blocked_tags !== null) {
|
||||
$.cookie("ui-blocked-tags", blocked_tags.toLowerCase(), {path: '/', expires: 365});
|
||||
Cookies.set("ui-blocked-tags", blocked_tags.toLowerCase(), {expires: 365});
|
||||
location.reload(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*jshint bitwise:true, curly:true, forin:false, noarg:true, noempty:true, nonew:true, undef:true, strict:false, browser:true, jquery:true */
|
||||
|
||||
$(function() {
|
||||
var order_pool = $.cookie("shm_ui-order-pool") || "created";
|
||||
var order_pool = Cookies.get("shm_ui-order-pool") || "created";
|
||||
$("#order_pool option[value="+order_pool+"]").attr("selected", true);
|
||||
|
||||
$('#order_pool').change(function(){
|
||||
var val = $("#order_pool option:selected").val();
|
||||
$.cookie("shm_ui-order-pool", val, {path: '/', expires: 365}); //FIXME: This won't play nice if COOKIE_PREFIX is not "shm_".
|
||||
Cookies.set("shm_ui-order-pool", val, {expires: 365}); //FIXME: This won't play nice if COOKIE_PREFIX is not "shm_".
|
||||
window.location.href = '';
|
||||
});
|
||||
});
|
||||
|
|
|
@ -201,11 +201,11 @@ var Tagger = {
|
|||
x = xy[0];
|
||||
y = xy[1];
|
||||
}
|
||||
setCookie(config.title+"_tagger-position",x+" "+y,14);
|
||||
Cookies.set(config.title+"_tagger-position", x+" "+y, {expires: 14});
|
||||
},
|
||||
|
||||
load : function () {
|
||||
var p = getCookie(config.title+"_tagger-position");
|
||||
var p = Cookies.get(config.title+"_tagger-position");
|
||||
if(p) {
|
||||
var xy = p.split(" ");
|
||||
this.set(xy[0],xy[1]);
|
||||
|
|
8
lib/jquery.cookie-1.4.0.min.js
vendored
8
lib/jquery.cookie-1.4.0.min.js
vendored
|
@ -1,8 +0,0 @@
|
|||
/*!
|
||||
* jQuery Cookie Plugin v1.4.0
|
||||
* https://github.com/carhartl/jquery-cookie
|
||||
*
|
||||
* Copyright 2013 Klaus Hartl
|
||||
* Released under the MIT license
|
||||
*/
|
||||
(function(e){if(typeof define==="function"&&define.amd){define(["jquery"],e)}else{e(jQuery)}})(function(e){function n(e){return u.raw?e:encodeURIComponent(e)}function r(e){return u.raw?e:decodeURIComponent(e)}function i(e){return n(u.json?JSON.stringify(e):String(e))}function s(e){if(e.indexOf('"')===0){e=e.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,"\\")}try{e=decodeURIComponent(e.replace(t," "))}catch(n){return}try{return u.json?JSON.parse(e):e}catch(n){}}function o(t,n){var r=u.raw?t:s(t);return e.isFunction(n)?n(r):r}var t=/\+/g;var u=e.cookie=function(t,s,a){if(s!==undefined&&!e.isFunction(s)){a=e.extend({},u.defaults,a);if(typeof a.expires==="number"){var f=a.expires,l=a.expires=new Date;l.setDate(l.getDate()+f)}return document.cookie=[n(t),"=",i(s),a.expires?"; expires="+a.expires.toUTCString():"",a.path?"; path="+a.path:"",a.domain?"; domain="+a.domain:"",a.secure?"; secure":""].join("")}var c=t?undefined:{};var h=document.cookie?document.cookie.split("; "):[];for(var p=0,d=h.length;p<d;p++){var v=h[p].split("=");var m=r(v.shift());var g=v.join("=");if(t&&t===m){c=o(g,s);break}if(!t&&(g=o(g))!==undefined){c[m]=g}}return c};u.defaults={};e.removeCookie=function(t,n){if(e.cookie(t)!==undefined){e.cookie(t,"",e.extend({},n,{expires:-1}));return true}return false}});
|
151
lib/js.cookie.js
Normal file
151
lib/js.cookie.js
Normal file
|
@ -0,0 +1,151 @@
|
|||
/*!
|
||||
* JavaScript Cookie v2.1.2
|
||||
* https://github.com/js-cookie/js-cookie
|
||||
*
|
||||
* Copyright 2006, 2015 Klaus Hartl & Fagner Brack
|
||||
* Released under the MIT license
|
||||
*/
|
||||
;(function (factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define(factory);
|
||||
} else if (typeof exports === 'object') {
|
||||
module.exports = factory();
|
||||
} else {
|
||||
var OldCookies = window.Cookies;
|
||||
var api = window.Cookies = factory();
|
||||
api.noConflict = function () {
|
||||
window.Cookies = OldCookies;
|
||||
return api;
|
||||
};
|
||||
}
|
||||
}(function () {
|
||||
function extend () {
|
||||
var i = 0;
|
||||
var result = {};
|
||||
for (; i < arguments.length; i++) {
|
||||
var attributes = arguments[ i ];
|
||||
for (var key in attributes) {
|
||||
result[key] = attributes[key];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function init (converter) {
|
||||
function api (key, value, attributes) {
|
||||
var result;
|
||||
if (typeof document === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Write
|
||||
|
||||
if (arguments.length > 1) {
|
||||
attributes = extend({
|
||||
path: '/'
|
||||
}, api.defaults, attributes);
|
||||
|
||||
if (typeof attributes.expires === 'number') {
|
||||
var expires = new Date();
|
||||
expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5);
|
||||
attributes.expires = expires;
|
||||
}
|
||||
|
||||
try {
|
||||
result = JSON.stringify(value);
|
||||
if (/^[\{\[]/.test(result)) {
|
||||
value = result;
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
if (!converter.write) {
|
||||
value = encodeURIComponent(String(value))
|
||||
.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
|
||||
} else {
|
||||
value = converter.write(value, key);
|
||||
}
|
||||
|
||||
key = encodeURIComponent(String(key));
|
||||
key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent);
|
||||
key = key.replace(/[\(\)]/g, escape);
|
||||
|
||||
return (document.cookie = [
|
||||
key, '=', value,
|
||||
attributes.expires && '; expires=' + attributes.expires.toUTCString(), // use expires attribute, max-age is not supported by IE
|
||||
attributes.path && '; path=' + attributes.path,
|
||||
attributes.domain && '; domain=' + attributes.domain,
|
||||
attributes.secure ? '; secure' : ''
|
||||
].join(''));
|
||||
}
|
||||
|
||||
// Read
|
||||
|
||||
if (!key) {
|
||||
result = {};
|
||||
}
|
||||
|
||||
// To prevent the for loop in the first place assign an empty array
|
||||
// in case there are no cookies at all. Also prevents odd result when
|
||||
// calling "get()"
|
||||
var cookies = document.cookie ? document.cookie.split('; ') : [];
|
||||
var rdecode = /(%[0-9A-Z]{2})+/g;
|
||||
var i = 0;
|
||||
|
||||
for (; i < cookies.length; i++) {
|
||||
var parts = cookies[i].split('=');
|
||||
var cookie = parts.slice(1).join('=');
|
||||
|
||||
if (cookie.charAt(0) === '"') {
|
||||
cookie = cookie.slice(1, -1);
|
||||
}
|
||||
|
||||
try {
|
||||
var name = parts[0].replace(rdecode, decodeURIComponent);
|
||||
cookie = converter.read ?
|
||||
converter.read(cookie, name) : converter(cookie, name) ||
|
||||
cookie.replace(rdecode, decodeURIComponent);
|
||||
|
||||
if (this.json) {
|
||||
try {
|
||||
cookie = JSON.parse(cookie);
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
if (key === name) {
|
||||
result = cookie;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!key) {
|
||||
result[name] = cookie;
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
api.set = api;
|
||||
api.get = function (key) {
|
||||
return api(key);
|
||||
};
|
||||
api.getJSON = function () {
|
||||
return api.apply({
|
||||
json: true
|
||||
}, [].slice.call(arguments));
|
||||
};
|
||||
api.defaults = {};
|
||||
|
||||
api.remove = function (key, attributes) {
|
||||
api(key, '', extend(attributes, {
|
||||
expires: -1
|
||||
}));
|
||||
};
|
||||
|
||||
api.withConverter = init;
|
||||
|
||||
return api;
|
||||
}
|
||||
|
||||
return init(function () {});
|
||||
}));
|
|
@ -137,41 +137,6 @@ function getHTTPObject() {
|
|||
}
|
||||
|
||||
|
||||
/* get, set, and delete cookies */
|
||||
function getCookie( name ) {
|
||||
var start = document.cookie.indexOf( name + "=" );
|
||||
var len = start + name.length + 1;
|
||||
if ( ( !start ) && ( name !== document.cookie.substring( 0, name.length ) ) ) {
|
||||
return null;
|
||||
}
|
||||
if ( start === -1 ) { return null; }
|
||||
var end = document.cookie.indexOf( ";", len );
|
||||
if ( end === -1 ) { end = document.cookie.length; }
|
||||
return unescape( document.cookie.substring( len, end ) );
|
||||
}
|
||||
|
||||
function setCookie( name, value, expires, path, domain, secure ) {
|
||||
var today = new Date();
|
||||
today.setTime( today.getTime() );
|
||||
if ( expires ) {
|
||||
expires = expires * 1000 * 60 * 60 * 24;
|
||||
}
|
||||
var expires_date = new Date( today.getTime() + (expires) );
|
||||
document.cookie = name+"="+escape( value ) +
|
||||
( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
|
||||
( ( path ) ? ";path=" + path : "" ) +
|
||||
( ( domain ) ? ";domain=" + domain : "" ) +
|
||||
( ( secure ) ? ";secure" : "" );
|
||||
}
|
||||
|
||||
function deleteCookie( name, path, domain ) {
|
||||
if ( getCookie( name ) ) { document.cookie = name + "=" +
|
||||
( ( path ) ? ";path=" + path : "") +
|
||||
( ( domain ) ? ";domain=" + domain : "" ) +
|
||||
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
|
||||
}
|
||||
}
|
||||
|
||||
function replyTo(imageId, commentId, userId) {
|
||||
var box = $("#comment_on_"+imageId);
|
||||
var text = "[url=site://post/view/"+imageId+"#c"+commentId+"]@"+userId+"[/url]: ";
|
||||
|
|
Reference in a new issue