User:Thehayro/JavaScript Addons: Difference between revisions
(Created page with 'Category:Plasma, JavaScript = Introduction = This is a tutorial on how to write a JavaScript Addon for Plasma. Since it is possible to write Plasmoids in JavaScript (and o...') |
No edit summary |
||
Line 8: | Line 8: | ||
= Setting up = | = Setting up = | ||
== metadata.desktop == | |||
= A very simple Addon = | = A very simple Addon = | ||
Line 33: | Line 35: | ||
</code> | </code> | ||
In this part, the actual method is called echo, however having MyJavaScriptAddon.prototype prefixed is important for JavaScript to make sure that echo is a member of the class MyJavaScriptAddon | In this part, the actual method is called echo, however having MyJavaScriptAddon.prototype prefixed is important for JavaScript to make sure that echo is a member of this class. | ||
At the end of your Addon it is also important that you "publish" your class for other instances that would like to use it. | |||
<code javascript="javascript"> | |||
registerAddon(MyJavaScriptAddon) </code> |
Revision as of 16:29, 10 September 2010
Introduction
This is a tutorial on how to write a JavaScript Addon for Plasma. Since it is possible to write Plasmoids in JavaScript (and other languages), you are able to extend your Plasmoid with Addons. This tutorial goes through basic steps you need to do to get your Addon running.
Setting up
metadata.desktop
A very simple Addon
Our Addon will be a simple JavaScript class that prints out "Hello World" when it gets loaded. Furthermore we will provide one method that prints out an entered text.
First of all we will define a constructor. In this case we name it MyJavaScriptAddon
function MyJavaScriptAddon()
{
print("Hello World");
}
This constructor gets called, when this addon is loaded by another JavaScript instance. In there we will get a console output with "Hello World".
The next step is to provide our Addon a method, which print out our input.
MyJavaScriptAddon.prototype.echo = function(text)
{
print(text);
}
In this part, the actual method is called echo, however having MyJavaScriptAddon.prototype prefixed is important for JavaScript to make sure that echo is a member of this class.
At the end of your Addon it is also important that you "publish" your class for other instances that would like to use it.
registerAddon(MyJavaScriptAddon)