From 6b1376747083f01cde5e5f2cb3afe8a0849b6d73 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Mon, 13 Jan 2014 21:08:40 -0700 Subject: [PATCH] Fix blank mascots giving an error --- builds/appchan-x.user.js | 11 ++++------- builds/crx/script.js | 11 ++++------- src/Theming/Mascots.coffee | 8 ++++---- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index c9535c7b1..ce0defd49 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -13044,7 +13044,7 @@ } $.off(img, 'error', MascotTools.error); $.replace(img, el); - return MascotTools.position(); + return MascotTools.position(mascot); }, error: function() { var ctx, el, @@ -13075,9 +13075,7 @@ enabled = Conf[string]; if (!(len = enabled.length)) { return MascotTools.change({ - image: '', - height: 0, - width: 0 + image: '' }); } Conf['mascot'] = name = enabled[i = Math.floor(Math.random() * len)]; @@ -13360,12 +13358,11 @@ }; return reader.readAsText(file); }, - position: function() { - var mascot; + position: function(mascot) { if (!Style.sheets.mascots) { return; } - mascot = Mascots[Conf['mascot']]; + (mascot.image != null) || (mascot = Mascots[Conf['mascot']] || {}); return Style.sheets.mascots.textContent = "#mascot img {\nheight: " + (mascot.height && isNaN(parseFloat(mascot.height)) ? mascot.height : mascot.height ? parseInt(mascot.height, 10) + 'px' : 'auto') + ";\nwidth: " + (mascot.width && isNaN(parseFloat(mascot.width)) ? mascot.width : mascot.width ? parseInt(mascot.width, 10) + 'px' : 'auto') + ";\n}\n#mascot {\nmargin: " + (mascot.vOffset || 0) + "px " + (mascot.hOffset || 0) + "px;\n}\n.sidebar-large #mascot {\nleft: " + (mascot.center ? 25 : 0) + "px;\nright: " + (mascot.center ? 25 : 0) + "px;\n}\n.mascot-position-above-post-form.post-form-style-fixed #mascot {\ntransform: translateY(-" + (QR.nodes ? QR.nodes.el.getBoundingClientRect().height : 0) + "px);\n}"; } }; diff --git a/builds/crx/script.js b/builds/crx/script.js index 893f4e483..e1a53c3d8 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -13033,7 +13033,7 @@ } $.off(img, 'error', MascotTools.error); $.replace(img, el); - return MascotTools.position(); + return MascotTools.position(mascot); }, error: function() { var ctx, el, @@ -13064,9 +13064,7 @@ enabled = Conf[string]; if (!(len = enabled.length)) { return MascotTools.change({ - image: '', - height: 0, - width: 0 + image: '' }); } Conf['mascot'] = name = enabled[i = Math.floor(Math.random() * len)]; @@ -13349,12 +13347,11 @@ }; return reader.readAsText(file); }, - position: function() { - var mascot; + position: function(mascot) { if (!Style.sheets.mascots) { return; } - mascot = Mascots[Conf['mascot']]; + (mascot.image != null) || (mascot = Mascots[Conf['mascot']] || {}); return Style.sheets.mascots.textContent = "#mascot img {\nheight: " + (mascot.height && isNaN(parseFloat(mascot.height)) ? mascot.height : mascot.height ? parseInt(mascot.height, 10) + 'px' : 'auto') + ";\nwidth: " + (mascot.width && isNaN(parseFloat(mascot.width)) ? mascot.width : mascot.width ? parseInt(mascot.width, 10) + 'px' : 'auto') + ";\n}\n#mascot {\nmargin: " + (mascot.vOffset || 0) + "px " + (mascot.hOffset || 0) + "px;\n}\n.sidebar-large #mascot {\nleft: " + (mascot.center ? 25 : 0) + "px;\nright: " + (mascot.center ? 25 : 0) + "px;\n}\n.mascot-position-above-post-form.post-form-style-fixed #mascot {\n-webkit-transform: translateY(-" + (QR.nodes ? QR.nodes.el.getBoundingClientRect().height : 0) + "px);\n}"; } }; diff --git a/src/Theming/Mascots.coffee b/src/Theming/Mascots.coffee index 5bec1bfc9..3bc0ffa23 100644 --- a/src/Theming/Mascots.coffee +++ b/src/Theming/Mascots.coffee @@ -42,7 +42,7 @@ MascotTools = $.off img, 'error', MascotTools.error $.replace img, el - MascotTools.position() + MascotTools.position mascot error: -> return unless @src @@ -62,7 +62,7 @@ MascotTools = toggle: -> string = g.MASCOTSTRING enabled = Conf[string] - return MascotTools.change {image: '', height: 0, width: 0} unless len = enabled.length + return MascotTools.change {image: ''} unless len = enabled.length Conf['mascot'] = name = enabled[i = Math.floor(Math.random() * len)] @@ -366,7 +366,7 @@ MascotTools = reader.readAsText file - position: -> + position: (mascot) -> return unless Style.sheets.mascots - mascot = Mascots[Conf['mascot']] + mascot.image? or mascot = Mascots[Conf['mascot']] or {} # event Style.sheets.mascots.textContent = """<%= grunt.file.read('src/General/css/mascot.css') %>"""