]> git.gir.st - VimFx.git/blob - extension/bootstrap.coffee
Closes #9. Implemented localization, refactored bootstrap.coffee
[VimFx.git] / extension / bootstrap.coffee
1 "use strict"
2
3 { utils: Cu } = Components
4
5 Cu.import "resource://gre/modules/Services.jsm"
6 Cu.import "resource://gre/modules/AddonManager.jsm"
7
8 # Populate the global namespace with console, require, and include
9 do (global = this) ->
10 baseURI = Services.io.newURI __SCRIPT_URI_SPEC__, null, null
11 getResourceURI = (path) -> Services.io.newURI path, null, baseURI
12
13 include = (src, scope = {}) ->
14 try
15 uri = getResourceURI "packages/#{ src }.js"
16 Services.scriptloader.loadSubScript uri.spec, scope
17 catch error
18 uri = getResourceURI src
19 Services.scriptloader.loadSubScript uri.spec, scope
20
21 return scope
22
23
24 modules = {}
25 require = (src) ->
26 if modules[src]
27 return modules[src]
28 else
29 scope =
30 require: require
31 include: include
32 exports: {}
33
34 include src, scope
35
36 return modules[src] = scope.exports;
37
38 global.include = include
39 global.require = require
40 global.getResourceURI = getResourceURI
41
42 # Include into global scope
43 include("includes/#{ name }.js", global) for name in [
44 'chrome',
45 'console',
46 'unload',
47 'window-utils',
48 ]
49
50 # Init localization `underscore` method
51 { l10n } = require 'l10n'
52 global._ = l10n "vimfx.properties"
53
54 { loadCss } = require 'utils'
55 { addEventListeners } = require 'events'
56 { getPref
57 , installPrefObserver } = require 'prefs'
58 { setButtonInstallPosition
59 , addToolbarButton } = require 'button'
60
61 # Firefox will call this method on startup/enabling
62 global.startup = (data, reason) ->
63
64
65 if reason = ADDON_INSTALL
66 # Position the toolbar button right before the default Bookmarks button
67 # If Bookmarks button is hidden - then VimFx button will be appended to the toolbar
68 setButtonInstallPosition 'nav-bar', 'bookmarks-menu-button-container'
69
70 loadCss 'style'
71 watchWindows addEventListeners, 'navigator:browser'
72 watchWindows addToolbarButton, 'navigator:browser'
73 installPrefObserver()
74
75 # Firefox will call this method on shutdown/disabling
76 global.shutdown = (data, reason) ->
77 # Don't bother to clean up if the browser is shutting down
78 if reason != APP_SHUTDOWN
79 unload()
Imprint / Impressum