Labs/Jetpack/API: Difference between revisions

From MozillaWiki
< Labs‎ | Jetpack
Jump to navigation Jump to search
No edit summary
(Origination.)
Line 1: Line 1:
{{draft}}
{{draft}}
JetPack is a project to explore new and innovative approaches to extensibility of the browser.


'''WARNING''': This reference is extremely volatile and will change.
'''WARNING''': This reference is extremely volatile and will change.
Line 7: Line 5:
= JetPack API Reference =
= JetPack API Reference =


'''Logger'''
== The <code>jetpack</code> Namespace ==
Used to output debugging information, it appears in the Javascript Error Console. You can access it from the Tools menu.
* <code>log( message )</code>. Shows a log message in the Error Console.
* <code>debug( message )</code>. Shows a debug message in the Error Console.
* <code>info( message )</code>. Shows an info message in the Error Console.
* <code>warn( message )</code>. Shows a warning in the Error Console.
* <code>error( message )</code>. 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.
* <code>has(name)</code>. Checks whether a JetPack feature has stored a value.
* <code>get(name)</code>. Returns the value of a stored object by name.
* <code>set({name:string, value:string})</code>. 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.
 
*<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.Statusbars'''
Allows addition of icons to the status bar.
 
*<code>create({id: string, callback: func})</code>
** <code>id</code>: the identifier by which you can refer to the status bar later.
** <code>callback</code>: A function that details what to do upon creation of the status bar.
 
Example:
  Jetpack.UI.Statusbars.create({
    id: "sb-panel",
    callback: function(aPanel){
      aPanel.create({
        id: "amo-link",
        name: "AMO Link",
        icon: "icon.png",
        isLink: true,
        url: "http://addons.mozilla.org"
      });
      }
  });


The <code>jetpack</code> namespace is available to all Jetpack Features, and is the main point of contact for Features with the rest of Firefox. The API is intended as a lightweight backwards-compatible facade to the underlying Mozilla platform, which means that if you write a Feature using the Jetpack library, you shouldn't have to change your code as Firefox continues to evolve.


'''UI.Content'''
For now, it has the following properties:


* 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.
* <code>tabs</code> provides access to all open tabs (irrespective of window).
* <code>statusBar</code> lets you add or modify to Firefox's status bar at the bottom of Firefox browser windows.
* <code>lib</code> gives access to small libraries for the web, providing encapsulated and easy-to-use ways of accessing services like Twitter, Flickr, Delicious, and so forth. Eventually you'll be able to import libraries from anywhere, but the default ones will be code reviewed by Mozilla.

Revision as of 07:40, 20 May 2009

Draft-template-image.png THIS PAGE IS A WORKING DRAFT Pencil-emoji U270F-gray.png
The page may be difficult to navigate, and some information on its subject might be incomplete and/or evolving rapidly.
If you have any questions or ideas, please add them as a new topic on the discussion page.

WARNING: This reference is extremely volatile and will change.

JetPack API Reference

The jetpack Namespace

The jetpack namespace is available to all Jetpack Features, and is the main point of contact for Features with the rest of Firefox. The API is intended as a lightweight backwards-compatible facade to the underlying Mozilla platform, which means that if you write a Feature using the Jetpack library, you shouldn't have to change your code as Firefox continues to evolve.

For now, it has the following properties:

  • tabs provides access to all open tabs (irrespective of window).
  • statusBar lets you add or modify to Firefox's status bar at the bottom of Firefox browser windows.
  • lib gives access to small libraries for the web, providing encapsulated and easy-to-use ways of accessing services like Twitter, Flickr, Delicious, and so forth. Eventually you'll be able to import libraries from anywhere, but the default ones will be code reviewed by Mozilla.