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,25 +30,32 @@ 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, (docImg) ->
withImage(defaultUrl, (defaultImg) ->
size = defaultImg.width
withImage(bgUrl, (img) ->
canvas = document.createElement('canvas') canvas = document.createElement('canvas')
ctx = canvas.getContext('2d')
canvas.width = bgSize canvas.width = size
canvas.height = bgSize canvas.height = size
canvas.getContext('2d').drawImage(img, bgX, bgY) ctx.drawImage(defaultImg, 0, 0)
if defaultUrl == null docIconPercentage = 65
defaultUrl = favicon.href destinationCoords = size / 100 * (100 - docIconPercentage)
destinationSize = size / 100 * docIconPercentage
ctx.drawImage(docImg, sourceX, sourceY, sourceSize, sourceSize, destinationCoords, destinationCoords, destinationSize, destinationSize)
urlCache[doc.slug] = canvas.toDataURL() urlCache[doc.slug] = canvas.toDataURL()
favicon.href = urlCache[doc.slug] favicon.href = urlCache[doc.slug]
currentSlug = doc.slug currentSlug = doc.slug
) )
)
@resetFavicon = () -> @resetFavicon = () ->
if defaultUrl != null and currentSlug != null if defaultUrl != null and currentSlug != null

Loading…
Cancel
Save