1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
/*
* Sample extension
*
*/
// Information about the extension, will be used by dwbem to get information
// about the extension, the <INFO comments are mandatory
/*<INFO
Sample extension
INFO>*/
// Default configuration of the extension, will be used by dwbem.
// The //<DEFAULT_CONFIG and //>DEFAULT_CONFIG comments are mandatory
var defaultConfig = {
//<DEFAULT_CONFIG
// Sample configuration option
myConfigOption : "foo",
// Sample default shortcut
myShortcut : "Control m"
//>DEFAULT_CONFIG
};
// Some implementation
var myConfig = {};
function myAction() {
// some implementation
}
function mySignalCallback() {
// some signal callback
}
/*
* An object that must be returned by the extension.
*/
var myExtension = {
// Minimum api version required by the extension, optional
apiVersion : 1.6,
// The default configuration, will be first passed to util.mixin and then to
// the init function of this object, optional
defaultConfig : defaultConfig,
// An object that can be imported by userscripts, e.g. if the extension is
// called "myExtension", the exports object can be imported with
//
// require(["myExtension"], function(myExtension) {
// ...
// });
//
// Optional.
exports : {
action : myAction
},
// Initialization function, will be called after the the extension has been
// loaded. The initialization function must either return true if
// initialization was successful or false if it failed. If the
// initialization is asynchronous, e.g. if system.spawn is used, the function
// can also return a Deferred and call resolve(true)/resolve(false) or reject(reason)
// on the Deferred if initialization was successful/failed respectively.
//
// Synchronous initialization
init : function(config) {
myConfig = config;
this.exports.config = config;
script.own(
bind(config.myShortcut, myAction),
Signal.connect("onNavigation", mySignalCallback)
);
return true;
},
// Asynchronous initialization
/*
init : function(config) {
myConfig = config;
this.exports.config = config;
var deferred = new Deferred();
system.spawn("some command", {
onFinished : function(result) {
if (result.status == 0) {
script.own(
bind(config.myShortcut, myAction),
Signal.connect("onNavigation", mySignalCallback),
);
deferred.resolve(true);
}
else {
deferred.reject("Spawning some command failed");
}
}
});
return deferred;
},
*/
// Cleanup function that will be called when the extension is disabled. Should be
// defined if some commands were bound in init or some signals were
// connected. Must return true if deinitialization was successful.
end : function() {
script.removeHandles();
return true;
}
};
// The defined object must be returned by the extension. Every extension is
// encapsulated in a function, so it is possible to return an object directly
// from the extension.
return myExtension;
// vim:set ft=javascript:
|