opera.contexts.toolbar.createItem()
Description
This method creates a Button from a given property object. Note: The item can only be used within the ToolbarContext that it is created in.
Parameters:
properties: TheButtonPropertiesto use when creating theButton.
The available properties include:
Syntax:
Button createItem (<ButtonProperties> properties)
Example:
The below button would include a badge (saying '42') and display a popup window when clicked.
Note that buttons must be defined in the background process (e.g. in index.html) in order to work.
//
// The background process (e.g. index.html)
//
var i = 0; // count the number of times the button get clicked
// The button properties
var properties = {
disabled: false,
title: "My Extension",
icon: "icon.18x18.png",
onclick: function() {
i++; // counting how often the button is clicked
},
popup: {
href: 'popup.html',
width: 100,
height: 100
},
badge: {
display: 'block',
backgroundColor: '#5566ff',
color: '#ffffff',
textContent: '42'
}
};
// Create the button
var button = opera.contexts.toolbar.createItem(properties);
You can also define the properties on the fly when creating the button:
//
// The background process (e.g. index.html)
//
// Create a button
var button = opera.contexts.toolbar.createItem({
title: 'Weather Extension',
icon: 'yr.png'
});About this article
| Published in | Dev.Opera |
|---|---|
| Date | December 16, 2011 |
| Author | Opera Software |
| Tags | Button and Badge, extensions API, Toolbar |
| Original | Internet Archive |