diff --git a/assets/javascripts/lib/favicon.coffee b/assets/javascripts/lib/favicon.coffee index 8f3708e4..696bd784 100644 --- a/assets/javascripts/lib/favicon.coffee +++ b/assets/javascripts/lib/favicon.coffee @@ -28,12 +28,19 @@ withImage = (url, action) -> currentSlug = doc.slug return - styles = window.getComputedStyle($("._icon-#{doc.slug.split('~')[0]}"), ':before') + iconEl = $("._icon-#{doc.slug.split('~')[0]}") + return if iconEl == null + + styles = window.getComputedStyle(iconEl, ':before') + + backgroundPositionX = styles['background-position-x'] + backgroundPositionY = styles['background-position-y'] + return if backgroundPositionX == undefined || backgroundPositionY == undefined bgUrl = app.config.favicon_spritesheet sourceSize = 16 - sourceX = Math.abs(parseInt(styles['background-position-x'].slice(0, -2))) - sourceY = Math.abs(parseInt(styles['background-position-y'].slice(0, -2))) + sourceX = Math.abs(parseInt(backgroundPositionX.slice(0, -2))) + sourceY = Math.abs(parseInt(backgroundPositionY.slice(0, -2))) withImage(bgUrl, (docImg) -> withImage(defaultUrl, (defaultImg) ->