Fix blank mascots giving an error

This commit is contained in:
Zixaphir 2014-01-13 21:08:40 -07:00
parent d81c4cd568
commit 6b13767470
3 changed files with 12 additions and 18 deletions

View File

@ -13044,7 +13044,7 @@
} }
$.off(img, 'error', MascotTools.error); $.off(img, 'error', MascotTools.error);
$.replace(img, el); $.replace(img, el);
return MascotTools.position(); return MascotTools.position(mascot);
}, },
error: function() { error: function() {
var ctx, el, var ctx, el,
@ -13075,9 +13075,7 @@
enabled = Conf[string]; enabled = Conf[string];
if (!(len = enabled.length)) { if (!(len = enabled.length)) {
return MascotTools.change({ return MascotTools.change({
image: '', image: ''
height: 0,
width: 0
}); });
} }
Conf['mascot'] = name = enabled[i = Math.floor(Math.random() * len)]; Conf['mascot'] = name = enabled[i = Math.floor(Math.random() * len)];
@ -13360,12 +13358,11 @@
}; };
return reader.readAsText(file); return reader.readAsText(file);
}, },
position: function() { position: function(mascot) {
var mascot;
if (!Style.sheets.mascots) { if (!Style.sheets.mascots) {
return; 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}"; 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}";
} }
}; };

View File

@ -13033,7 +13033,7 @@
} }
$.off(img, 'error', MascotTools.error); $.off(img, 'error', MascotTools.error);
$.replace(img, el); $.replace(img, el);
return MascotTools.position(); return MascotTools.position(mascot);
}, },
error: function() { error: function() {
var ctx, el, var ctx, el,
@ -13064,9 +13064,7 @@
enabled = Conf[string]; enabled = Conf[string];
if (!(len = enabled.length)) { if (!(len = enabled.length)) {
return MascotTools.change({ return MascotTools.change({
image: '', image: ''
height: 0,
width: 0
}); });
} }
Conf['mascot'] = name = enabled[i = Math.floor(Math.random() * len)]; Conf['mascot'] = name = enabled[i = Math.floor(Math.random() * len)];
@ -13349,12 +13347,11 @@
}; };
return reader.readAsText(file); return reader.readAsText(file);
}, },
position: function() { position: function(mascot) {
var mascot;
if (!Style.sheets.mascots) { if (!Style.sheets.mascots) {
return; 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}"; 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}";
} }
}; };

View File

@ -42,7 +42,7 @@ MascotTools =
$.off img, 'error', MascotTools.error $.off img, 'error', MascotTools.error
$.replace img, el $.replace img, el
MascotTools.position() MascotTools.position mascot
error: -> error: ->
return unless @src return unless @src
@ -62,7 +62,7 @@ MascotTools =
toggle: -> toggle: ->
string = g.MASCOTSTRING string = g.MASCOTSTRING
enabled = Conf[string] 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)] Conf['mascot'] = name = enabled[i = Math.floor(Math.random() * len)]
@ -366,7 +366,7 @@ MascotTools =
reader.readAsText file reader.readAsText file
position: -> position: (mascot) ->
return unless Style.sheets.mascots 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') %>""" Style.sheets.mascots.textContent = """<%= grunt.file.read('src/General/css/mascot.css') %>"""