diff --git a/public/javascripts/ctrl.js b/public/javascripts/ctrl.js index 60d05f6cc6..9575327d68 100644 --- a/public/javascripts/ctrl.js +++ b/public/javascripts/ctrl.js @@ -5,6 +5,11 @@ if (typeof console == "undefined" || typeof console.log == "undefined") console // declare now, populate later var lichess_translations = []; +$.cookie.defaults = { + path: '/', + domain: document.domain.replace(/^\w+\.(.+)$/, '$1') +}; + var lichess = { socket: null, socketDefaults: { diff --git a/public/javascripts/deps.min.js b/public/javascripts/deps.min.js index 518832cf33..c596fc68b8 100644 --- a/public/javascripts/deps.min.js +++ b/public/javascripts/deps.min.js @@ -142,3 +142,70 @@ function(a){var b=N++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?) u,function(a,b){return"'+\n_.escape("+w(b)+")+\n'"}).replace(d.interpolate||u,function(a,b){return"'+\n("+w(b)+")+\n'"}).replace(d.evaluate||u,function(a,b){return"';\n"+w(b)+"\n;__p+='"})+"';\n";d.variable||(a="with(obj||{}){\n"+a+"}\n");var a="var __p='';var print=function(){__p+=Array.prototype.join.call(arguments, '')};\n"+a+"return __p;\n",e=new Function(d.variable||"obj","_",a);if(c)return e(c,b);c=function(a){return e.call(this,a,b)};c.source="function("+(d.variable||"obj")+"){\n"+a+"}";return c}; b.chain=function(a){return b(a).chain()};var m=function(a){this._wrapped=a};b.prototype=m.prototype;var x=function(a,c){return c?b(a).chain():a},M=function(a,c){m.prototype[a]=function(){var a=i.call(arguments);J.call(a,this._wrapped);return x(c.apply(b,a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];m.prototype[a]=function(){var d=this._wrapped;b.apply(d,arguments);var e=d.length;(a=="shift"||a=="splice")&&e===0&&delete d[0];return x(d, this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];m.prototype[a]=function(){return x(b.apply(this._wrapped,arguments),this._chain)}});m.prototype.chain=function(){this._chain=true;return this};m.prototype.value=function(){return this._wrapped}}).call(this); + +/*! + * jQuery Cookie Plugin v1.2 + * https://github.com/carhartl/jquery-cookie + */ +(function ($, document, undefined) { + + var pluses = /\+/g; + + function raw(s) { + return s; + } + + function decoded(s) { + return decodeURIComponent(s.replace(pluses, ' ')); + } + + var config = $.cookie = function (key, value, options) { + + // write + if (value !== undefined) { + options = $.extend({}, config.defaults, options); + + if (value === null) { + options.expires = -1; + } + + if (typeof options.expires === 'number') { + var days = options.expires, t = options.expires = new Date(); + t.setDate(t.getDate() + days); + } + + value = config.json ? JSON.stringify(value) : String(value); + + return (document.cookie = [ + encodeURIComponent(key), '=', config.raw ? value : encodeURIComponent(value), + options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE + options.path ? '; path=' + options.path : '', + options.domain ? '; domain=' + options.domain : '', + options.secure ? '; secure' : '' + ].join('')); + } + + // read + var decode = config.raw ? raw : decoded; + var cookies = document.cookie.split('; '); + for (var i = 0, parts; (parts = cookies[i] && cookies[i].split('=')); i++) { + if (decode(parts.shift()) === key) { + var cookie = decode(parts.join('=')); + return config.json ? JSON.parse(cookie) : cookie; + } + } + + return null; + }; + + config.defaults = {}; + + $.removeCookie = function (key, options) { + if ($.cookie(key) !== null) { + $.cookie(key, null, options); + return true; + } + return false; + }; + +})(jQuery, document); diff --git a/public/javascripts/socket.js b/public/javascripts/socket.js index 7a6deb2f72..62ab2ab807 100644 --- a/public/javascripts/socket.js +++ b/public/javascripts/socket.js @@ -145,7 +145,7 @@ $.websocket.prototype = { if (self.ws) { self.ws.close(); self.ws = null; } }, onError: function(e) { - if ($("#websocket-fail").length == 0) { + if (!$.cookie("wsok") && $("#websocket-fail").length == 0) { $.ajax("/assets/websocket-fail.html", { success: function(html) { $('body').prepend("
" + html + "
"); @@ -154,6 +154,7 @@ $.websocket.prototype = { } }, onSuccess: function() { + $.cookie("wsok", 1); $("#websocket-fail").remove(); } } diff --git a/public/javascripts/vendor/jquery.cookie.js b/public/javascripts/vendor/jquery.cookie.js new file mode 100644 index 0000000000..9e911a605c --- /dev/null +++ b/public/javascripts/vendor/jquery.cookie.js @@ -0,0 +1,72 @@ +/*jshint eqnull:true */ +/*! + * jQuery Cookie Plugin v1.2 + * https://github.com/carhartl/jquery-cookie + * + * Copyright 2011, Klaus Hartl + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://www.opensource.org/licenses/mit-license.php + * http://www.opensource.org/licenses/GPL-2.0 + */ +(function ($, document, undefined) { + + var pluses = /\+/g; + + function raw(s) { + return s; + } + + function decoded(s) { + return decodeURIComponent(s.replace(pluses, ' ')); + } + + var config = $.cookie = function (key, value, options) { + + // write + if (value !== undefined) { + options = $.extend({}, config.defaults, options); + + if (value === null) { + options.expires = -1; + } + + if (typeof options.expires === 'number') { + var days = options.expires, t = options.expires = new Date(); + t.setDate(t.getDate() + days); + } + + value = config.json ? JSON.stringify(value) : String(value); + + return (document.cookie = [ + encodeURIComponent(key), '=', config.raw ? value : encodeURIComponent(value), + options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE + options.path ? '; path=' + options.path : '', + options.domain ? '; domain=' + options.domain : '', + options.secure ? '; secure' : '' + ].join('')); + } + + // read + var decode = config.raw ? raw : decoded; + var cookies = document.cookie.split('; '); + for (var i = 0, parts; (parts = cookies[i] && cookies[i].split('=')); i++) { + if (decode(parts.shift()) === key) { + var cookie = decode(parts.join('=')); + return config.json ? JSON.parse(cookie) : cookie; + } + } + + return null; + }; + + config.defaults = {}; + + $.removeCookie = function (key, options) { + if ($.cookie(key) !== null) { + $.cookie(key, null, options); + return true; + } + return false; + }; + +})(jQuery, document); diff --git a/public/stylesheets/common.css b/public/stylesheets/common.css index af36ebf0ca..eb8845a32f 100644 --- a/public/stylesheets/common.css +++ b/public/stylesheets/common.css @@ -245,7 +245,6 @@ div.side_menu a.active { #nb_connected_players { float: left; color: #999; - font-style: italic; border-left: 1px solid #ccc; } a.goto_nav {