Use GitHub's parent-child style

pull/972/head
Jasper van Merle 6 years ago
parent c36478ce82
commit 14e49f7014

@ -19,6 +19,9 @@ withImage = (url, action) ->
favicon = $('link[rel="icon"]') favicon = $('link[rel="icon"]')
if defaultUrl == null
defaultUrl = favicon.href
if urlCache[doc.slug] if urlCache[doc.slug]
favicon.href = urlCache[doc.slug] favicon.href = urlCache[doc.slug]
currentSlug = doc.slug currentSlug = doc.slug
@ -27,24 +30,31 @@ withImage = (url, action) ->
styles = window.getComputedStyle($("._icon-#{doc.slug}"), ':before') styles = window.getComputedStyle($("._icon-#{doc.slug}"), ':before')
bgUrl = styles['background-image'].slice(5, -2) bgUrl = styles['background-image'].slice(5, -2)
bgSize = if bgUrl.includes('@2x') then 32 else 16 sourceSize = if bgUrl.includes('@2x') then 32 else 16
bgX = parseInt(styles['background-position-x'].slice(0, -2)) sourceX = Math.abs(parseInt(styles['background-position-x'].slice(0, -2)))
bgY = parseInt(styles['background-position-y'].slice(0, -2)) sourceY = Math.abs(parseInt(styles['background-position-y'].slice(0, -2)))
withImage(bgUrl, (img) -> withImage(bgUrl, (docImg) ->
canvas = document.createElement('canvas') withImage(defaultUrl, (defaultImg) ->
size = defaultImg.width
canvas.width = bgSize canvas = document.createElement('canvas')
canvas.height = bgSize ctx = canvas.getContext('2d')
canvas.getContext('2d').drawImage(img, bgX, bgY)
if defaultUrl == null canvas.width = size
defaultUrl = favicon.href canvas.height = size
ctx.drawImage(defaultImg, 0, 0)
urlCache[doc.slug] = canvas.toDataURL() docIconPercentage = 65
favicon.href = urlCache[doc.slug] destinationCoords = size / 100 * (100 - docIconPercentage)
destinationSize = size / 100 * docIconPercentage
ctx.drawImage(docImg, sourceX, sourceY, sourceSize, sourceSize, destinationCoords, destinationCoords, destinationSize, destinationSize)
currentSlug = doc.slug urlCache[doc.slug] = canvas.toDataURL()
favicon.href = urlCache[doc.slug]
currentSlug = doc.slug
)
) )
@resetFavicon = () -> @resetFavicon = () ->

Loading…
Cancel
Save