Changes

Jump to: navigation, search

Labs/Ubiquity/Ubiquity 0.5 Author Tutorial

1,760 bytes added, 03:50, 30 August 2009
sample code for Bin
In the future, Ubiquity is also likely to have the ability to convert your Ubiquity commands into proper Firefox extensions. Look [http://labs.toolness.com/trac/ticket/3 here] to check on the progress of this functionality.
 
== Using Bin ==
Some commands may want to store data that persist even after closing Firefox.
Meet <code>Bin</code>:
<pre>
var gId = 42; // used for avoiding needless preview updates when typing
CmdUtils.CreateCommand({
name: "memo",
description: "Lets you jot a memo for the page.",
author: "satyr",
argument: noun_arb_text,
execute: function memo_execute({object: {html}}) {
var {href} = CmdUtils.getDocument().location;
var list = Bin[href]() || [];
list.push(html);
Bin[href](list);
gId = +new Date;
},
preview: function memo_preview(pb) {
var {href} = CmdUtils.getDocument().location;
var list = Bin[href]();
if (!list) {
pb.innerHTML =
<>No memos taken for: <small><code>{href}</code></small></>;
return;
}
if (pb.ownerDocument.getElementById(gId)) return;
var ol = CmdUtils.previewList(pb, list, function deleteMemo(i, ev) {
$(ev.target).closest("li").slideUp();
list.splice(i, 1);
Bin[href](list.length ? list : null);
gId = +new Date;
});
ol.id = gId;
},
});
 
CmdUtils.CreateCommand({
name: "list memos",
description: "Opens all memos you've taken in a new tab.",
author: "satyr",
execute: function list_memos_execute() {
var htm = +Bin + " page(s)<dl>", {escapeHtml} = Utils;
for (var [url, memos] in Bin) {
htm += "<dt>" + escapeHtml(url) + "</dt><dd><ol>";
for each (var memo in memos) htm += "<li>" + memo + "</li>";
htm += "</ol></dd>";
}
Utils.openUrlInBrowser("data:text/html," + encodeURI(htm + "</dl>"));
},
});
</pre>
For details, see the bottom of [https://ubiquity.mozilla.com/hg/ubiquity-firefox/raw-file/tip/ubiquity/index.html#modules/feedmanager.js FeedManager] documentation.
== Firebug ==
73
edits

Navigation menu