Labs/Jetpack/API: Difference between revisions

From MozillaWiki
< Labs‎ | Jetpack
Jump to navigation Jump to search
Line 33: Line 33:
Allows JetPack features to manipulate Firefox sidebars.
Allows JetPack features to manipulate Firefox sidebars.


* <code>create({id: string, name: string, content: element})</code>. Creates a sidebar with a given name. The <code>id</code> is the identifier by which you can refer to the sidebar later in your code. The <code>name</code> will appear in the View>Sidebar menu. Finally, <code>content</code>
* <code>create({id: string, name: string, content: element})</code>. Creates a sidebar with a given name.
** <code>id</code>: the identifier by which you can refer to the sidebar later in your code.
** <code>name</code> will be the text that appears in the View>Sidebar menu.
** <code>content</code> is a DOM element. You can supply one using the <code>$</code> function, which works just like the jQuery selector. For example, $("#sidebar-content").
 
 
'''UI.Content'''
 
* '''addLoadHandler({patterns: arrayOfRegexps, filter: function}). Adds a global page load handler. The patterns are matched against the page URL, and in case of a match, the filter method is called in the context of the page.

Revision as of 09:11, 27 April 2009

JetPack is a project to explore new and innovative approaches to extensibility of the browser.

WARNING: This reference is extremely volatile and will change.

JetPack API Reference

Logger Used to output debugging information, it appears in the Javascript Error Console. You can access it from the Tools menu.

  • log( message ). Shows a log message in the Error Console.
  • debug( message ). Shows a debug message in the Error Console.
  • info( message ). Shows an info message in the Error Console.
  • warn( message ). Shows a warning in the Error Console.
  • error( message ). Shows an error message in the Error Console.

Example:

 JetPack.Logger.warn( "1+1 != 3, except for values of 1 sufficiently large.");

Storage Persistent storage for your feature. The storage is sandboxed per feature, so data stored by one JetPack feature cannot be accessed by another JetPack feature.

  • has(name). Checks whether a JetPack feature has stored a value.
  • get(name). Returns the value of a stored object by name.
  • set({name:string, value:string}). Sets the value of an object by name. Use .toSource() to store Javascript objects. In the future, serialization will be performed automatically.

Example:

 if( !JetPack.Storage.has("cheese") )
   JetPack.Storage.set({name: "cheese", value: "Delicious!"});


UI Interacting with the user interface of the browser is done through this component.

UI.Sidebars Allows JetPack features to manipulate Firefox sidebars.

  • create({id: string, name: string, content: element}). Creates a sidebar with a given name.
    • id: the identifier by which you can refer to the sidebar later in your code.
    • name will be the text that appears in the View>Sidebar menu.
    • content is a DOM element. You can supply one using the $ function, which works just like the jQuery selector. For example, $("#sidebar-content").


UI.Content

  • addLoadHandler({patterns: arrayOfRegexps, filter: function}). Adds a global page load handler. The patterns are matched against the page URL, and in case of a match, the filter method is called in the context of the page.