From caed53de6a064a79db6d2ad220e4f18437a1f1bb Mon Sep 17 00:00:00 2001 From: Daku Date: Sat, 18 Jun 2016 06:27:32 +0100 Subject: [PATCH] jQuery.cookie is deprecated so use js-cookie instead (+ composer), some js tweaking too Conflicts: ext/blotter/script.js ext/handle_pixel/script.js ext/index/script.js ext/pools/script.js lib/shimmie.js --- composer.json | 14 ++-- ext/pools/script.js | 5 +- ext/pools/theme.php | 16 ++-- lib/js.cookie.js | 151 ------------------------------------ themes/lite/setup.theme.php | 6 +- themes/material/script0.js | 8 +- 6 files changed, 24 insertions(+), 176 deletions(-) delete mode 100644 lib/js.cookie.js diff --git a/composer.json b/composer.json index d147f961..84bb6c8c 100644 --- a/composer.json +++ b/composer.json @@ -29,15 +29,17 @@ "bower-asset/jquery" : "1.12.3", "bower-asset/jquery-timeago" : "1.5.2", "bower-asset/tablesorter" : "2.0.5", - "bower-asset/mediaelement" : "2.21.1" + "bower-asset/mediaelement" : "2.21.1", + "bower-asset/js-cookie" : "2.1.1" }, "vendor-copy": { - "vendor/bower-asset/jquery/dist/jquery.min.js" : "lib/vendor/js/jquery-1.12.3.min.js", - "vendor/bower-asset/jquery/dist/jquery.min.map" : "lib/vendor/js/jquery-1.12.3.min.map", - "vendor/bower-asset/jquery-timeago/jquery.timeago.js" : "lib/vendor/js/jquery.timeago.js", - "vendor/bower-asset/tablesorter/jquery.tablesorter.min.js" : "lib/vendor/js/jquery.tablesorter.min.js" - "vendor/bower-asset/mediaelement/build/flashmediaelement.swf" : "lib/vendor/swf/flashmediaelement.swf" + "vendor/bower-asset/jquery/dist/jquery.min.js" : "lib/vendor/js/jquery-1.12.3.min.js", + "vendor/bower-asset/jquery/dist/jquery.min.map" : "lib/vendor/js/jquery-1.12.3.min.map", + "vendor/bower-asset/jquery-timeago/jquery.timeago.js" : "lib/vendor/js/jquery.timeago.js", + "vendor/bower-asset/tablesorter/jquery.tablesorter.min.js" : "lib/vendor/js/jquery.tablesorter.min.js", + "vendor/bower-asset/mediaelement/build/flashmediaelement.swf" : "lib/vendor/swf/flashmediaelement.swf", + "vendor/bower-asset/js-cookie/src/js.cookie.js" : "lib/vendor/js/js.cookie.js" }, "scripts": { diff --git a/ext/pools/script.js b/ext/pools/script.js index 88cec0e3..6b45792c 100644 --- a/ext/pools/script.js +++ b/ext/pools/script.js @@ -1,12 +1,9 @@ /*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 = 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(); - Cookies.set("shm_ui-order-pool", val, {expires: 365}); //FIXME: This won't play nice if COOKIE_PREFIX is not "shm_". + Cookies.set("shm_ui-order-pool", val, {path: '/', expires: 365}); //FIXME: This won't play nice if COOKIE_PREFIX is not "shm_". window.location.href = ''; }); }); diff --git a/ext/pools/theme.php b/ext/pools/theme.php index b0e07866..457eb793 100644 --- a/ext/pools/theme.php +++ b/ext/pools/theme.php @@ -86,14 +86,14 @@ class PoolsTheme extends Themelet { $html .= ""; - $order_html = ' - - '; + $order_html = ''; $this->display_top(null, "Pools"); $page->add_block(new Block("Order By", $order_html, "left", 15)); diff --git a/lib/js.cookie.js b/lib/js.cookie.js deleted file mode 100644 index 7f3dffde..00000000 --- a/lib/js.cookie.js +++ /dev/null @@ -1,151 +0,0 @@ -/*! - * 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 () {}); -})); diff --git a/themes/lite/setup.theme.php b/themes/lite/setup.theme.php index 7b130507..42a1d210 100644 --- a/themes/lite/setup.theme.php +++ b/themes/lite/setup.theme.php @@ -17,14 +17,14 @@ class CustomSetupTheme extends SetupTheme { $(\"#$i-toggle\").click(function() { $(\"#$i\").slideToggle(\"slow\", function() { if($(\"#$i\").is(\":hidden\")) { - $.cookie(\"$i-hidden\", 'true', {path: '/'}); + Cookies.set(\"$i-hidden\", 'true', {path: '/'}); } else { - $.cookie(\"$i-hidden\", 'false', {path: '/'}); + Cookies.set(\"$i-hidden\", 'false', {path: '/'}); } }); }); - if($.cookie(\"$i-hidden\") == 'true') { + if(Cookies.get(\"$i-hidden\") == 'true') { $(\"#$i\").hide(); } }); diff --git a/themes/material/script0.js b/themes/material/script0.js index 1fd32cd8..8d47ebb5 100644 --- a/themes/material/script0.js +++ b/themes/material/script0.js @@ -33,7 +33,7 @@ $(function(){ } else { $("#left-block").prependTo("#main-grid") } - $.cookie("ui-layout-type", layout_type, {path: '/', expires: 365}); + Cookies.set("ui-layout-type", layout_type, {path: '/', expires: 365}); zoom("width"); } @@ -55,10 +55,10 @@ $(function(){ } else { $("#left-block").prependTo("#main-grid") } - $.cookie("ui-layout-type", layout_type, {path: '/', expires: 365}); + Cookies.set("ui-layout-type", layout_type, {path: '/', expires: 365}); zoom("width"); } - current_layout = $.cookie("layout-type"); + current_layout = Cookies.get("layout-type"); if (current_layout != null) { if(current_layout =="top" || current_layout == "bottom"){ leftAddFullSize(current_layout); @@ -91,5 +91,5 @@ function zoom(zoom_type) { $(".shm-zoomer").val(zoom_type); - $.cookie("ui-image-zoom", zoom_type, {path: '/', expires: 365}); + Cookies.set("ui-image-zoom", zoom_type, {path: '/', expires: 365}); }