1 utils = require 'utils'
2 { Marker } = require 'marker'
3 { addHuffmanCodeWordsTo } = require 'huffman'
5 { interfaces: Ci } = Components
7 HTMLDocument = Ci.nsIDOMHTMLDocument
8 XULDocument = Ci.nsIDOMXULDocument
10 CONTAINER_ID = 'VimFxHintMarkerContainer'
12 createHintsContainer = (document) ->
13 container = document.createElement('div')
14 container.id = CONTAINER_ID
15 container.className = 'VimFxReset'
18 # Creates and injects hint markers into the DOM
19 injectHints = (document) ->
20 markers = getMarkers(document)
21 hintChars = utils.getHintChars()
23 addHuffmanCodeWordsTo markers,
25 setCodeWord: (marker, hint, index) -> marker.setHint(hint)
29 getMarkers = (document) ->
30 # First remove previous hints container
33 # For now we aren't able to handle hint markers in XUL Documents :(
34 if document instanceof HTMLDocument# or document instanceof XULDocument
35 if document.documentElement
36 # Find and create markers
37 markers = Marker.createMarkers(document)
39 container = createHintsContainer(document)
41 # For performance use Document Fragment
42 fragment = document.createDocumentFragment()
44 fragment.appendChild(marker.markerElement)
46 container.appendChild(fragment)
47 document.documentElement.appendChild(container)
49 for frame in document.defaultView.frames
50 markers = markers.concat(getMarkers(frame.document))
54 # Remove previously injected hints from the DOM
55 removeHints = (document) ->
56 if container = document.getElementById(CONTAINER_ID)
57 document.documentElement.removeChild(container)
59 for frame in document.defaultView.frames
60 removeHints(frame.document)
63 exports.injectHints = injectHints
64 exports.removeHints = removeHints