FUEL/0.2/Plan: Difference between revisions

From MozillaWiki
< FUEL‎ | 0.2
Jump to navigation Jump to search
mNo edit summary
(Added bookmarks examples, fixed up the browser examples, removed the database examples.)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
< [[FUEL/0.2]]<br/>
< [[FUEL/0.2]]<br/>
'''Due Date:''' Feb 28, 2007<br/>
'''Due Date:''' May 25, 2007<br/>
'''Deliverable:''' [[FUEL/0.2/API|Complete API]]
'''Deliverable:''' [[FUEL/0.2/API|Complete API]]


=== File I/0 ===
=== Browser ===
TBD
* Access browser tabs
* Access web content in a tab
* Handle tab-related events
 
'''Example:'''
 
Open, and activate, a new tab
  Application.browser.open("http://google.com/").active = true;
 
Open, and activate, a tab just after the current tab
  var tab = Application.browser.open("http://google.com/");
  Application.browser.insertBefore( tab, Application.browser.activeTab.next );
  tab.active = true;
 
or:
  var tab = Application.browser.open("http://google.com/");
  tab.index = Application.browser.activeTab + 1;
  tab.active = true;
 
Move the active tab to be the first tab
  Application.browser.insertBefore(
    Application.browser.activeTab,
    Application.browser.tabs[0]
  );
 
or:
  Application.browser.activeTab.index = 0;
 
Close the active tab
  Application.browser.activeTab.close();
 
Do something when the active tab loads
  Application.browser.activeTab.events.addListener( "load", function(){
    this.query("#foo div")
  });
 
Change the URL in the active tab
  Application.browser.activeTab.url = "http://mozilla.org/";
 
Close all Google-related tabs
  Application.browser.tabs.forEach(function(tab){
    if ( tab.url.match(/google/) )
      tab.remove();
  });
 
Re-use a tab, or open a new one
  var url = "http://google.com/";
  Application.browser.tabs.some(function(tab){
    if ( tab.url == url )
      return tab.active = true;
  }) || Application.browser.open( url ).active = true;
 
Stop the user from opening any new tabs
  Application.browser.events.addListener( "TabOpen", function(e){
    e.target.close();
  });


=== Bookmarks ===
=== Bookmarks ===
Line 12: Line 67:
'''Example:'''
'''Example:'''


   var b = Bookmarks.getAll();
Log the title of all top-level bookmarks:
 
   Application.bookmarks.all.forEach(function(cur){
  while ( b.hasNext() ) {
  var cur = b.next();
   console.log( "title", cur.title );
   console.log( "title", cur.title );
  }
 
  Bookmarks.add({
    title: "Foo Bar",
    url: "http://mozilla.org/"
   });
   });


=== Storage (SQLite) ===
Add a new bookmark:
* Attach to an existing SQLite DB
  Application.bookmarks.add("Mozilla", "http://mozilla.org/");
* Create DB
* Perform a basic query
* Get JS-object results back


'''Example:'''
Remove all bookmarks that point to Google:
 
   Application.bookmarks.all.forEach(function(cur){
   var db = new Storage("myfile.db");
     if ( cur.url.match(/google.com/) )
 
      cur.remove();
  var q = db.prepare("SELECT * FROM foo WHERE foo = ?;");
   });
  q.execute( "bar" );
 
  while ( q.hasNext() ) {
     var row = q.next();
    console.log( "foo", row.foo );
    console.log( "username", row.username );
   }
 
=== Application Storage ===
see: http://www.xulplanet.com/ndeakin/article/359/
* Allows extensions to store state during lifetime of application
* Model on DOM:Storage API
 
'''Example:'''


   Application.storage.set("password", "jimmy01");
Add a new bookmark, if one doesn't already exist:
    
  var url = "http://google.com/";
  Extension.storage.set("blockedpagecount", "20");
   Application.bookmarks.all.some(function(cur){
    if ( cur.url == url )
      return true;
   }) || Application.bookmarks.add( "Google", url );

Latest revision as of 00:25, 11 May 2007

< FUEL/0.2
Due Date: May 25, 2007
Deliverable: Complete API

Browser

  • Access browser tabs
  • Access web content in a tab
  • Handle tab-related events

Example:

Open, and activate, a new tab

 Application.browser.open("http://google.com/").active = true;

Open, and activate, a tab just after the current tab

 var tab = Application.browser.open("http://google.com/");
 Application.browser.insertBefore( tab, Application.browser.activeTab.next );
 tab.active = true;

or:

 var tab = Application.browser.open("http://google.com/");
 tab.index = Application.browser.activeTab + 1;
 tab.active = true;

Move the active tab to be the first tab

 Application.browser.insertBefore(
   Application.browser.activeTab,
   Application.browser.tabs[0]
 );

or:

 Application.browser.activeTab.index = 0;

Close the active tab

 Application.browser.activeTab.close();

Do something when the active tab loads

 Application.browser.activeTab.events.addListener( "load", function(){
   this.query("#foo div")
 });

Change the URL in the active tab

 Application.browser.activeTab.url = "http://mozilla.org/";

Close all Google-related tabs

 Application.browser.tabs.forEach(function(tab){
   if ( tab.url.match(/google/) )
     tab.remove();
 });

Re-use a tab, or open a new one

 var url = "http://google.com/";
 Application.browser.tabs.some(function(tab){
   if ( tab.url == url )
     return tab.active = true;
 }) || Application.browser.open( url ).active = true;

Stop the user from opening any new tabs

 Application.browser.events.addListener( "TabOpen", function(e){
   e.target.close();
 });

Bookmarks

  • Add A Bookmark
  • Browse Bookmarks

Example:

Log the title of all top-level bookmarks:

 Application.bookmarks.all.forEach(function(cur){
 	console.log( "title", cur.title );
 });

Add a new bookmark:

 Application.bookmarks.add("Mozilla", "http://mozilla.org/");

Remove all bookmarks that point to Google:

 Application.bookmarks.all.forEach(function(cur){
   if ( cur.url.match(/google.com/) )
     cur.remove();
 });

Add a new bookmark, if one doesn't already exist:

 var url = "http://google.com/";
 Application.bookmarks.all.some(function(cur){
   if ( cur.url == url )
     return true;
 }) || Application.bookmarks.add( "Google", url );