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