File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -94,6 +94,8 @@ class app.views.DocList extends app.View
94
94
$ .stopEvent (event)
95
95
doc = app .docs .findBy ' slug' , event .target .getAttribute (' data-slug' )
96
96
97
+ @ setFaviconForDoc (doc)
98
+
97
99
if doc and not @lists [doc .slug ]
98
100
@lists [doc .slug ] = if doc .types .isEmpty ()
99
101
new app.views.EntryList doc .entries .all ()
@@ -111,6 +113,29 @@ class app.views.DocList extends app.View
111
113
delete @lists [doc .slug ]
112
114
return
113
115
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
+
114
139
select : (model ) ->
115
140
@listSelect .selectByHref model ? .fullPath ()
116
141
return
You can’t perform that action at this time.
0 commit comments