Confirmed users
161
edits
(move jquery from 'other issues' to TODO) |
(mark parts of the JEP that are likely to change (model "B"/"C")) |
||
Line 1: | Line 1: | ||
This is an alternative version of [[Labs/Jetpack/Reboot/JEP/107]] ('''page mods'''). | This is an alternative version of [[Labs/Jetpack/Reboot/JEP/107]] ('''page mods'''). | ||
Here's [http://bitbucket.org/nickolay/jetpack-packages/src/tip/packages/page-mods/ in progress implementation] (currently | Here's [http://bitbucket.org/nickolay/jetpack-packages/src/tip/packages/page-mods/ in progress implementation] (currently 'Model "B"'). | ||
---- | ---- | ||
Line 15: | Line 15: | ||
Introduce an API allowing jetpacks to run script whenever a content page the jetpack is interested in loads. | Introduce an API allowing jetpacks to run script whenever a content page the jetpack is interested in loads. | ||
This way of enhancing functionality of web sites was popularized by the [https://addons.mozilla.org/en-US/firefox/addon/748 Greasemonkey extension]. Unlike Greasemonkey scripts, in this proposal the pagemod's scripts all share the same Jetpack context and have the same privileges as the jetpack itself (but see [[#Discussion - e10s]] below). | This way of enhancing functionality of web sites was popularized by the [https://addons.mozilla.org/en-US/firefox/addon/748 Greasemonkey extension]. | ||
{{Note|Some parts of this API are generally agreed on (<code>include</code>, global <code>add()</code>/<code>remove()</code> methods), but there are two execution models under consideration for the scripts actually working with the page (see [[#Discussion - e10s]]). | |||
<p>The initial proposal described a model (called "B" in the e10s discussion), but current thinking is that another model, "C" is overall better. The difference between the two models are noted throughout the rest of this proposal.</p>}} | |||
<span style="background-color: yellow">[Model "B"]</span> Unlike Greasemonkey scripts, in this proposal the pagemod's scripts all share the same Jetpack context and have the same privileges as the jetpack itself (but see [[#Discussion - e10s]] below). | |||
=== Use Cases === | === Use Cases === | ||
Line 38: | Line 44: | ||
"http://example.org/a/specific/url", | "http://example.org/a/specific/url", | ||
"http://example.info/*"], | "http://example.info/*"], | ||
// [Model "B"] The callbacks are specified in the jetpack context: | |||
onWindowCreate: function(wrappedWindow) { | onWindowCreate: function(wrappedWindow) { | ||
// this runs each time a new content document starts loading, but | // this runs each time a new content document starts loading, but | ||
Line 67: | Line 75: | ||
**# <code><nowiki>http://example.com/*</nowiki></code> - any URLs with the specified prefix. | **# <code><nowiki>http://example.com/*</nowiki></code> - any URLs with the specified prefix. | ||
**# <code><nowiki>http://example.com/test</nowiki></code> - the single specified URL | **# <code><nowiki>http://example.com/test</nowiki></code> - the single specified URL | ||
* <code>onWindowCreate</code>, <code>onDOMReady</code>: optional parameters specifying the code to run on the matched pages. | * <span style="background-color: yellow">[Model "B"]</span> <code>onWindowCreate</code>, <code>onDOMReady</code>: optional parameters specifying the code to run on the matched pages. | ||
** No code is run if these parameters are not specified. | ** No code is run if these parameters are not specified. | ||
** Providing a single function <code>func</code> is equivalent to providing a single-item array <code>[func]</code> | ** Providing a single function <code>func</code> is equivalent to providing a single-item array <code>[func]</code> | ||
Line 168: | Line 176: | ||
*#* [docs] encourage addon developers to clean up after their page mods via the unload module. (The clean up actions should also run when the script mod is removed). | *#* [docs] encourage addon developers to clean up after their page mods via the unload module. (The clean up actions should also run when the script mod is removed). | ||
*#* [docs] Should provide an example of using jQuery in a script mod. | *#* [docs] Should provide an example of using jQuery in a script mod. | ||
*#* If we keep model "B"'s APIs make sure to implement the latest naming changes suggested by Myk. | |||
* Post-0.5: | * Post-0.5: | ||
*# Possible API enhancements: | *# Possible API enhancements: |