166
edits
(2 intermediate revisions by the same user not shown) | |||
Line 821: | Line 821: | ||
Du solltest Chrome Fehler und Warnungen aktivieren wenn Du möchtest, dass die Fehler Deines Codes in der FireBug-Konsole angezeigt werden. Benutze CmdUtils.log() anstatt console.log() ''Hinweis: Derzeit ist lediglich die Übergabe eines Arguments an log() möglich.'' | Du solltest Chrome Fehler und Warnungen aktivieren wenn Du möchtest, dass die Fehler Deines Codes in der FireBug-Konsole angezeigt werden. Benutze CmdUtils.log() anstatt console.log() ''Hinweis: Derzeit ist lediglich die Übergabe eines Arguments an log() möglich.'' | ||
== Programmatisches hinzufügen von Kommandos == | |||
Hier ist ein Stückchen Code das Dir zeigt, wie ein Entwickler ein Kommando programmatisch in einer FireFox-Extension registrieren kann. | |||
<pre> | |||
// Helper function used to determine the local directory where the | |||
// extension which contains the command is installed. This is used | |||
// to create the URL of the js file which includes the implementation | |||
// of the list of commands you want to add. | |||
function getExtensionDir() { | |||
var extMgr = Components.classes["@mozilla.org/extensions/manager;1"] | |||
.getService(Components.interfaces.nsIExtensionManager); | |||
return extMgr.getInstallLocation( "feedly@devhd" ).getItemLocation( "feedly@devhd" ); | |||
} | |||
function getBaseUri() { | |||
var ioSvc = Components.classes["@mozilla.org/network/io-service;1"] | |||
.getService(Components.interfaces.nsIIOService); | |||
var extDir = getExtensionDir(); | |||
var baseUri = ioSvc.newFileURI(extDir).spec; | |||
return baseUri; | |||
} | |||
// your extension needs to call the addUbiquity command each time a new browser | |||
// session is create and your extension is loaded. | |||
function addUbiquityCommands(){ | |||
// url of the file which contains the implementation of the commands | |||
// we want to add. | |||
var url = getBaseUri() + "content/app/ubiquity/commands.js" | |||
// link to the ubiquity setup module. | |||
var jsm = {}; | |||
Components.utils.import("resource://ubiquity/modules/setup.js", jsm); | |||
// look up the feed manager and add a new command. Note: we are using the | |||
// isBuiltIn=true option so that the command is only added for the duration | |||
// of the browser session. This simplifies the overall lifecycle: if the | |||
// extension is disabled or un-installed, it will be automatically | |||
// "removed" from ubiquity. | |||
jsm.UbiquitySetup.createServices().feedManager.addSubscribedFeed( { | |||
url: url, | |||
sourceUrl: url, | |||
canAutoUpdate: true, | |||
isBuiltIn: true | |||
}); | |||
} | |||
</pre> | |||
Innerhalb Deiner Kommando-Implementierung kannst Du Import-Module benutzen oder in einer Singleton XPCOM Komponente nachschlagen, um Dein Kommando zu der Funktionalität zurück zu verlinken, die in Deiner Extension eingekapselt ist. | |||
Hier ein Beispiel-Kommando, das genau dies tut: | |||
<pre> | |||
var StreetsUtils = function(){ | |||
var that = {}; | |||
that.lookupCore = function(){ | |||
return Components.classes["@devhd.com/feedly-boot;1"] | |||
.getService(Components.interfaces.nsIFeedlyBoot) | |||
.wrappedJSObject | |||
.lookupCore(); | |||
}; | |||
return that; | |||
}(); | |||
CmdUtils.CreateCommand({ | |||
name: "my-extension-test", | |||
takes: {"message": noun_arb_text}, | |||
icon: "chrome://my-extension-test/skin/icon-16x16.png", | |||
modifiers: {to: noun_type_contact}, | |||
description:"Testing the feedly+ubiquity integration", | |||
help:"This is a test help message", | |||
preview: function(pblock, directObj, modifiers) { | |||
var html = "Testing my-extension-test "; | |||
if (modifiers.to) { | |||
html += "to " + modifiers.to.text + " "; | |||
} | |||
if (directObj.html) { | |||
html += "with these contents:" + directObj.html; | |||
} else { | |||
html += "with a link to the current page."; | |||
} | |||
pblock.innerHTML = html; | |||
}, | |||
execute: function(directObj, headers) { | |||
CmdUtils.log( ">>> my-extension core? " + ( StreetsUtils.lookupCore() != null ) ); | |||
} | |||
}); | |||
</pre> | |||
Beachte: Wenn Dein Kommando andere JS-Dateien in die Extension einbinden oder laden muss, kannst Du dafür das folgende Code-Stückchen an den Anfang der entsprechenden Kommando-JS-Datei setzen, welche Du zu Ubiquity hinzufügst. | |||
<pre> | |||
function include( partialURI ) | |||
{ | |||
// Load JS libraries | |||
var u = "chrome://feedly/content/app/" + partialURI; | |||
var jsl = Cc["@mozilla.org/moz/jssubscript-loader;1"] | |||
.getService(Ci.mozIJSSubScriptLoader); | |||
jsl.loadSubScript( u ); | |||
} | |||
include( "ubiquity/templates.ubiquity.js" ); | |||
</pre> | |||
== Ubiquity programmatisch schliessen == | |||
Hier ist die Zeile Code, die Entwickler benutzen können, um Ubiquity programmatisch zu schliessen (z.B. von preview ): | |||
<pre> | |||
context.chromeWindow.gUbiquity.closeWindow(); | |||
</pre> | |||
= Zusammenfassung = | |||
Um nochmals einen Punkt zu wiederholen, den ich bereits zuvor schon einmal angeführt habe: Ubiquity erhöht das Innovationspotential des Browsers um ein Vielfaches dadurch, dass es jeden ,der einigermassen mit JavaScript umgehen kann, dazu in die Lage versetzt, sich an der Verbesserung des Browsers und des offenen Web persönlich zu beteiligen. Du bist einer dieser Menschen. | |||
Ziehe jetzt also dahin und verbessere. |
edits