]> git.gir.st - VimFx.git/blob - extension/packages/hints.coffee
Fixed exception firing by marker enabled commands on XUL Documents
[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 # First remove previous hints container
17 removeHints document
18
19 # For now we aren't able to handle hint markers in XUL Documents :(
20 if document instanceof HTMLDocument# or document instanceof XULDocument
21 if document.documentElement
22 # Find and create markers
23 markers = Marker.createMarkers document
24
25 container = createHintsContainer document
26
27 # For performance use Document Fragment
28 fragment = document.createDocumentFragment()
29 for marker in markers
30 fragment.appendChild marker.markerElement
31
32 container.appendChild fragment
33 document.documentElement.appendChild container
34
35 return markers
36
37 # Remove previously injected hints from the DOM
38 removeHints = (document, markers) ->
39 if container = document.getElementById CONTAINER_ID
40 document.documentElement.removeChild container
41
42
43 exports.injectHints = injectHints
44 exports.removeHints = removeHints
Imprint / Impressum