]> git.gir.st - VimFx.git/blob - extension/packages/hints.coffee
Consistent use of parenthesis
[VimFx.git] / extension / packages / hints.coffee
1 { Marker } = require 'marker'
2
3 { interfaces: Ci } = Components
4
5 HTMLDocument = Ci.nsIDOMHTMLDocument
6 XULDocument = Ci.nsIDOMXULDocument
7
8 CONTAINER_ID = 'VimFxHintMarkerContainer'
9
10 createHintsContainer = (document) ->
11 container = document.createElement('div')
12 container.id = CONTAINER_ID
13 container.className = 'VimFxReset'
14 return container
15
16 # Creates and injects hint markers into the DOM
17 injectHints = (document) ->
18
19 inner = (document, startIndex = 1) ->
20 # First remove previous hints container
21 removeHints(document)
22
23 # For now we aren't able to handle hint markers in XUL Documents :(
24 if document instanceof HTMLDocument# or document instanceof XULDocument
25 if document.documentElement
26 # Find and create markers
27 markers = Marker.createMarkers(document, startIndex)
28
29 container = createHintsContainer(document)
30
31 # For performance use Document Fragment
32 fragment = document.createDocumentFragment()
33 for marker in markers
34 fragment.appendChild(marker.markerElement)
35
36 container.appendChild(fragment)
37 document.documentElement.appendChild(container)
38
39 for frame in document.defaultView.frames
40 markers = markers.concat(inner(frame.document, markers.length+1))
41
42 return markers
43
44 return inner(document)
45
46 # Remove previously injected hints from the DOM
47 removeHints = (document) ->
48 if container = document.getElementById(CONTAINER_ID)
49 document.documentElement.removeChild(container)
50
51 for frame in document.defaultView.frames
52 removeHints(frame.document)
53
54
55 exports.injectHints = injectHints
56 exports.removeHints = removeHints
Imprint / Impressum