[devdocsgjs/main: 566/1867] Set favicon to documentation icon on open
- From: Andy Holmes <andyholmes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devdocsgjs/main: 566/1867] Set favicon to documentation icon on open
- Date: Fri, 19 Nov 2021 23:47:16 +0000 (UTC)
commit d640a8ee221c26ad4612595157e6cbe9f0fd5709
Author: Jasper van Merle <jaspervmerle gmail com>
Date: Mon Jan 28 17:51:28 2019 +0100
Set favicon to documentation icon on open
assets/javascripts/views/sidebar/doc_list.coffee | 25 ++++++++++++++++++++++++
1 file changed, 25 insertions(+)
---
diff --git a/assets/javascripts/views/sidebar/doc_list.coffee
b/assets/javascripts/views/sidebar/doc_list.coffee
index c72877a8..d24c2476 100644
--- a/assets/javascripts/views/sidebar/doc_list.coffee
+++ b/assets/javascripts/views/sidebar/doc_list.coffee
@@ -94,6 +94,8 @@ class app.views.DocList extends app.View
$.stopEvent(event)
doc = app.docs.findBy 'slug', event.target.getAttribute('data-slug')
+ @setFaviconForDoc(doc)
+
if doc and not @lists[doc.slug]
@lists[doc.slug] = if doc.types.isEmpty()
new app.views.EntryList doc.entries.all()
@@ -111,6 +113,29 @@ class app.views.DocList extends app.View
delete @lists[doc.slug]
return
+ setFaviconForDoc: (doc) ->
+ link = $("a._list-item[data-slug='#{doc.slug}']")
+ styles = window.getComputedStyle(link, ':before')
+
+ bgUrl = styles['background-image'].slice(5, -2)
+ bgSize = if bgUrl.includes('@2x') then 32 else 16
+ bgPositions = styles['background-position'].split(' ')
+ bgX = parseInt(bgPositions[0].slice(0, -2))
+ bgY = parseInt(bgPositions[1].slice(0, -2))
+
+ img = new Image()
+ img.src = bgUrl
+ img.onload = () =>
+ canvas = document.createElement('canvas')
+
+ canvas.width = bgSize
+ canvas.height = bgSize
+ canvas.getContext('2d').drawImage(img, bgX, bgY)
+
+ $('link[rel="icon"]').href = canvas.toDataURL()
+ return
+ return
+
select: (model) ->
@listSelect.selectByHref model?.fullPath()
return
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]