diff --git a/ext/blotter/script.js b/ext/blotter/script.js index 25e3188c..dfffcf35 100644 --- a/ext/blotter/script.js +++ b/ext/blotter/script.js @@ -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(); } }); diff --git a/ext/handle_pixel/script.js b/ext/handle_pixel/script.js index 83bd56ac..b85094cc 100644 --- a/ext/handle_pixel/script.js +++ b/ext/handle_pixel/script.js @@ -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")); } }); diff --git a/ext/index/script.js b/ext/index/script.js index e1499c74..5f1ab8e2 100644 --- a/ext/index/script.js +++ b/ext/index/script.js @@ -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 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 () {}); +})); diff --git a/lib/shimmie.js b/lib/shimmie.js index 5f18651f..b899ebda 100644 --- a/lib/shimmie.js +++ b/lib/shimmie.js @@ -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]: ";