Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 59de543

Browse files
committed
Bug 882407 - Uplift addon-sdk to firefox. r=me
1 parent 0242a75 commit 59de543

39 files changed

Lines changed: 294 additions & 106 deletions

File tree

addon-sdk/source/doc/module-source/sdk/event/target.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ Exceptions in the listeners can be handled via `'error'` event listeners:
104104
If there is no listener registered for `error` event or if it also throws
105105
exception then such exceptions are logged into a console.
106106

107+
## Chaining
108+
109+
Emitters can also have their methods chained:
110+
111+
target.on('message', handleMessage)
112+
.on('data', parseData)
113+
.on('error', handleError);
114+
107115
<api name="EventTarget">
108116
@class
109117
`EventTarget` is an exemplar for creating an objects that can be used to
@@ -131,6 +139,8 @@ specified `type` are emitted.
131139
The type of event.
132140
@param listener {Function}
133141
The listener function that processes the event.
142+
@returns {EventTarget}
143+
Returns the EventTarget instance
134144
</api>
135145

136146
<api name="once">
@@ -141,6 +151,8 @@ the next time an event of the specified `type` is emitted.
141151
The type of event.
142152
@param listener {Function}
143153
The listener function that processes the event.
154+
@returns {EventTarget}
155+
Returns the EventTarget instance
144156
</api>
145157

146158
<api name="removeListener">
@@ -150,6 +162,13 @@ Removes an event `listener` for the given event `type`.
150162
The type of event.
151163
@param listener {Function}
152164
The listener function that processes the event.
165+
@returns {EventTarget}
166+
Returns the EventTarget instance
167+
</api>
168+
169+
<api name="off">
170+
@method
171+
An alias for [removeListener](modules/sdk/event/target.html#removeListener(type, listener)).
153172
</api>
154173

155174
</api>

addon-sdk/source/doc/module-source/sdk/lang/functional.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,31 @@ of having to set a boolean flag and checking it later.
286286
The wrapped `fn` that can only be executed once.
287287
</api>
288288

289+
<api name="chain">
290+
@function
291+
Creates a version of the input function that will return `this`.
292+
293+
let { chain } = require("sdk/lang/functional");
294+
295+
function Person (age) { this.age = age; }
296+
Person.prototype.happyBirthday = chain(function () this.age++);
297+
298+
let person = new Person(30);
299+
300+
person
301+
.happyBirthday()
302+
.happyBirthday()
303+
.happyBirthday()
304+
305+
console.log(person.age); // 33
306+
307+
@param fn {function}
308+
The function that will be wrapped by the chain function.
309+
310+
@returns {function}
311+
The wrapped function that executes `fn` and returns `this`.
312+
</api>
313+
289314
<api name="cache">
290315
@function
291316
An alias for [once](modules/sdk/lang/functional.html#once(fn)).

addon-sdk/source/doc/module-source/sdk/panel.md

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ method exported by the
7070

7171
panel.show();
7272

73+
## Panel Positioning ##
74+
75+
By default the panel appears in the center of the currently active browser window.
76+
You can position the panel by passing a `position` to the panel's
77+
[constructor](modules/sdk/panel.html#Panel(options)) or to
78+
its [`show()`](modules/sdk/panel.html#show(options)) method.
79+
7380
## Updating Panel Content ##
7481

7582
You can update the panel's content simply by setting the panel's `contentURL`
@@ -425,23 +432,23 @@ Creates a panel.
425432
The position of the panel.
426433
Ignored if the panel is opened by a widget.
427434

428-
You can set as value an object that has one or more of the following
429-
properites: `top`, `right`, `bottom` and `left`. Their values are expressed
435+
This is an object that has one or more of the following
436+
properties: `top`, `right`, `bottom` and `left`. Their values are expressed
430437
in pixels. Any other properties will be ignored.
431438

432-
The default alignment is centered, so for example panel can be displayed in
433-
the center of the bottom corner by leaving off vertical axis:
439+
The default alignment along each axis is centered: so to display a panel centred
440+
along the vertical or horizontal axis, just omit that axis:
434441

435-
// Show the panel to the centered horizontally and aligned to the bottom
436-
// of the content area
442+
// Show the panel centered horizontally and
443+
// aligned to the bottom of the content area
437444
require("sdk/panel").Panel({
438445
position: {
439446
bottom: 0
440447
}
441448
}).show();
442449

443-
// Show the panel to the centered vertically and aligned to the left o
444-
// the content area
450+
// Show the panel centered vertically and
451+
// aligned to the left of the content area
445452
require("sdk/panel").Panel({
446453
position: {
447454
left: 0
@@ -451,23 +458,27 @@ Creates a panel.
451458
// Centered panel, default behavior
452459
require("sdk/panel").Panel({}).show();
453460

454-
In the same way of their CSS counterpart, setting both `top` and `bottom`,
455-
or `left` and `right`, will results in calculated the `height` and `width`:
461+
As with the CSS `top`, `bottom`, `left`, and `right` properties, setting
462+
both `top` and `bottom` or both `left` and `right` will implicitly set the
463+
panel's `height` or `width` relative to the content window:
456464

457-
// Show the panel centered horizontally, that is distant 40px
458-
// from the top and 100px from the bottom.
465+
// Show the panel centered horizontally, with:
466+
// - the top edge 40px from the top of the content window
467+
// - the bottom edge 100px from the bottom of the content window
459468
require("sdk/panel").Panel({
460469
position: {
461470
top: 40,
462471
bottom: 100
463472
}
464473
}).show();
465474

466-
Set implicitly `height` in this example, will makes the panel ignore the
467-
`bottom` property, as the CSS homonym properties does:
475+
If you set both `top` and `bottom`, but also set the panel's height
476+
explicitly using the `height` property, then the panel will ignore
477+
`bottom`, just as CSS does for its properties with the same name:
468478

469-
// Show the panel centered horizontally, that is distant 40px from the top
470-
// and has 400px as height
479+
// Show the panel centered horizontally, with:
480+
// - the top edge 40px from the top of the content window
481+
// - a height of 400px
471482
require("sdk/panel").Panel({
472483
position: {
473484
top: 40,
@@ -485,7 +496,8 @@ Creates a panel.
485496
height: 400
486497
}).show();
487498

488-
The same principle is applied for `width`, `left` and `right`.
499+
The same principle is applied in the horizontal axis with
500+
`width`, `left` and `right`.
489501

490502
@prop [focus=true] {boolean}
491503
Set to `false` to prevent taking the focus away when the panel is shown.
@@ -644,8 +656,10 @@ Displays the panel.
644656

645657
If the `options` argument is given, it will be shallow merged with the options
646658
provided in the constructor: the `options` passed in the `show` method takes
647-
the precedence.
648-
It's useful for temporary changes, without touching the default values.
659+
precedence.
660+
661+
Passing options here is useful for making temporary changes without touching
662+
the default values.
649663

650664
@param options {object}
651665
Showing options for the panel, with the following keys:

addon-sdk/source/examples/annotator/lib/main.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
var widgets = require('widget');
6-
var pageMod = require('page-mod');
7-
var data = require('self').data;
8-
var panels = require('panel');
9-
var simpleStorage = require('simple-storage');
10-
var notifications = require("notifications");
5+
var widgets = require('sdk/widget');
6+
var pageMod = require('sdk/page-mod');
7+
var data = require('sdk/self').data;
8+
var panels = require('sdk/panel');
9+
var simpleStorage = require('sdk/simple-storage');
10+
var notifications = require("sdk/notifications");
1111

1212
/*
1313
Global variables
@@ -188,7 +188,7 @@ in the browser.
188188
this.postMessage(simpleStorage.storage.annotations);
189189
},
190190
onMessage: function(message) {
191-
require('tabs').open(message);
191+
require('sdk/tabs').open(message);
192192
}
193193
});
194194

addon-sdk/source/examples/library-detector/lib/main.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
const tabs = require('tabs');
6-
const widgets = require('widget');
7-
const data = require('self').data;
8-
const pageMod = require('page-mod');
9-
const panel = require('panel');
5+
const tabs = require('sdk/tabs');
6+
const widgets = require('sdk/widget');
7+
const data = require('sdk/self').data;
8+
const pageMod = require('sdk/page-mod');
9+
const panel = require('sdk/panel');
1010

1111
const ICON_WIDTH = 16;
1212

addon-sdk/source/examples/reading-data/lib/main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
var self = require("self");
6-
var panels = require("addon-kit/panel");
7-
var widgets = require("addon-kit/widget");
5+
var self = require("sdk/self");
6+
var panels = require("sdk/panel");
7+
var widgets = require("sdk/widget");
88

99
function replaceMom(html) {
1010
return html.replace("World", "Mom");

addon-sdk/source/examples/reading-data/tests/test-main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
var m = require("main");
6-
var self = require("self");
6+
var self = require("sdk/self");
77

88
exports.testReplace = function(test) {
99
var input = "Hello World";

addon-sdk/source/examples/reddit-panel/lib/main.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
var data = require("self").data;
5+
var data = require("sdk/self").data;
66

7-
var reddit_panel = require("panel").Panel({
7+
var reddit_panel = require("sdk/panel").Panel({
88
width: 240,
99
height: 320,
1010
contentURL: "http://www.reddit.com/.mobile?keep_extension=True",
@@ -13,10 +13,10 @@ var reddit_panel = require("panel").Panel({
1313
});
1414

1515
reddit_panel.port.on("click", function(url) {
16-
require("tabs").open(url);
16+
require("sdk/tabs").open(url);
1717
});
1818

19-
require("widget").Widget({
19+
require("sdk/widget").Widget({
2020
id: "open-reddit-btn",
2121
label: "Reddit",
2222
contentURL: "http://www.reddit.com/static/favicon.ico",

addon-sdk/source/examples/reddit-panel/tests/test-main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
var m = require("main");
6-
var self = require("self");
6+
var self = require("sdk/self");
77

88
exports.testMain = function(test) {
99
var callbacks = { quit: function() {

addon-sdk/source/lib/sdk/deprecated/window-utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,17 @@ Object.defineProperties(exports, {
205205
*/
206206
exports.getInnerId = deprecateFunction(getInnerId,
207207
'require("window-utils").getInnerId is deprecated, ' +
208-
'please use require("window/utils").getInnerId instead'
208+
'please use require("sdk/window/utils").getInnerId instead'
209209
);
210210

211211
exports.getOuterId = deprecateFunction(getOuterId,
212212
'require("window-utils").getOuterId is deprecated, ' +
213-
'please use require("window/utils").getOuterId instead'
213+
'please use require("sdk/window/utils").getOuterId instead'
214214
);
215215

216216
exports.isBrowser = deprecateFunction(isBrowser,
217217
'require("window-utils").isBrowser is deprecated, ' +
218-
'please use require("window/utils").isBrowser instead'
218+
'please use require("sdk/window/utils").isBrowser instead'
219219
);
220220

221221
exports.hiddenWindow = appShellService.hiddenDOMWindow;

0 commit comments

Comments
 (0)