History

Set favicon to the icon of the currently shown docs

Jasper van Merle committed 7 years ago

Commit c36478c1 parent d640a8e5 files · +58 −25Browse files

Showing the changes to assets/javascripts/views (4 of 5 files). Show all

Unified · Split

4 files
  1. assets/javascripts/views/content/content.coffee +3 −0
  2. assets/javascripts/views/content/entry_page.coffee +1 −0
  3. assets/javascripts/views/content/type_page.coffee +1 −0
  4. assets/javascripts/views/sidebar/doc_list.coffee +0 −25
assets/javascripts/views/content/content.coffee+3−0
@@ -153,6 +153,9 @@ class app.views.Content extends app.View · 152 unmodified lines
153 return153 return
154 154
155 afterRoute: (route, context) =>155 afterRoute: (route, context) =>
156 if route != 'entry' and route != 'type'
157 resetFavicon()
158
156 switch route159 switch route
157 when 'root'160 when 'root'
158 @show @rootPage161 @show @rootPage
assets/javascripts/views/content/entry_page.coffee+1−0
@@ -40,6 +40,7 @@ class app.views.EntryPage extends app.View · 39 unmodified lines
40 if app.disabledDocs.findBy 'slug', @entry.doc.slug40 if app.disabledDocs.findBy 'slug', @entry.doc.slug
41 @hiddenView = new app.views.HiddenPage @el, @entry41 @hiddenView = new app.views.HiddenPage @el, @entry
42 42
43 setFaviconForDoc(@entry.doc)
43 @delay @polyfillMathML44 @delay @polyfillMathML
44 @trigger 'loaded'45 @trigger 'loaded'
45 return46 return
assets/javascripts/views/content/type_page.coffee+1−0
@@ -9,6 +9,7 @@ class app.views.TypePage extends app.View · 8 unmodified lines
9 9
10 render: (@type) ->10 render: (@type) ->
11 @html @tmpl('typePage', @type)11 @html @tmpl('typePage', @type)
12 setFaviconForDoc(@type.doc)
12 return13 return
13 14
14 getTitle: ->15 getTitle: ->
assets/javascripts/views/sidebar/doc_list.coffee+0−25
@@ -94,8 +94,6 @@ class app.views.DocList extends app.View · 93 unmodified lines
94 $.stopEvent(event)94 $.stopEvent(event)
95 doc = app.docs.findBy 'slug', event.target.getAttribute('data-slug')95 doc = app.docs.findBy 'slug', event.target.getAttribute('data-slug')
96 96
97 @setFaviconForDoc(doc)
98
99 if doc and not @lists[doc.slug]97 if doc and not @lists[doc.slug]
100 @lists[doc.slug] = if doc.types.isEmpty()98 @lists[doc.slug] = if doc.types.isEmpty()
101 new app.views.EntryList doc.entries.all()99 new app.views.EntryList doc.entries.all()
@@ -113,29 +111,6 @@ class app.views.DocList extends app.View · 11 unmodified lines
113 delete @lists[doc.slug]111 delete @lists[doc.slug]
114 return112 return
115 113
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
139 select: (model) ->114 select: (model) ->
140 @listSelect.selectByHref model?.fullPath()115 @listSelect.selectByHref model?.fullPath()
141 return116 return