FUEL/0.2/Plan: Difference between revisions
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:''' | '''Due Date:''' May 25, 2007<br/> | ||
'''Deliverable:''' [[FUEL/0.2/API|Complete API]] | '''Deliverable:''' [[FUEL/0.2/API|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 === | === Bookmarks === | ||
Line 12: | Line 67: | ||
'''Example:''' | '''Example:''' | ||
Log the title of all top-level bookmarks: | |||
Application.bookmarks.all.forEach(function(cur){ | |||
console.log( "title", cur.title ); | 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(); | |||
}); | |||
} | |||
Application. | 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 ); |
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 );