File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -94,6 +94,8 @@ class app.views.DocList extends app.View
9494 $ .stopEvent (event)
9595 doc = app .docs .findBy ' slug' , event .target .getAttribute (' data-slug' )
9696
97+ @ setFaviconForDoc (doc)
98+
9799 if doc and not @lists [doc .slug ]
98100 @lists [doc .slug ] = if doc .types .isEmpty ()
99101 new app.views.EntryList doc .entries .all ()
@@ -111,6 +113,29 @@ class app.views.DocList extends app.View
111113 delete @lists [doc .slug ]
112114 return
113115
116+ setFaviconForDoc : (doc ) ->
117+ link = $ (" a._list-item[data-slug='#{ doc .slug } ']" )
118+ styles = window .getComputedStyle (link, ' :before' )
119+
120+ bgUrl = styles[' background-image' ].slice (5 , - 2 )
121+ bgSize = if bgUrl .includes (' @2x' ) then 32 else 16
122+ bgPositions = styles[' background-position' ].split (' ' )
123+ bgX = parseInt (bgPositions[0 ].slice (0 , - 2 ))
124+ bgY = parseInt (bgPositions[1 ].slice (0 , - 2 ))
125+
126+ img = new Image ()
127+ img .src = bgUrl
128+ img .onload = () =>
129+ canvas = document .createElement (' canvas' )
130+
131+ canvas .width = bgSize
132+ canvas .height = bgSize
133+ canvas .getContext (' 2d' ).drawImage (img, bgX, bgY)
134+
135+ $ (' link[rel="icon"]' ).href = canvas .toDataURL ()
136+ return
137+ return
138+
114139 select : (model ) ->
115140 @listSelect .selectByHref model ? .fullPath ()
116141 return
You can’t perform that action at this time.
0 commit comments