disabled: false,
title: "Button Example",
icon: "icons / button.png"
}
After initializing the property in ToolbarUIItemProperties , the next thing to do is create the actual function with the createItem syntax:
var theButton = opera.contexts.toolbar.createItem (ToolbarUIItemProperties);
There are 5 properties we can pass to ToolbarUIItemProperties , including:
theButton.disabled = true;
theButton.title = "This is a tooltip";
theButton.icon = "icons / beautiful-toobar-icon.png";
theButton.onclick = function () {/ * do something * /};
theButton.onremove = function () {/ * do something * /};
To assign a button to the toolbar , we will have to use the addItem method with the following general syntax:
opera.contexts.toolbar.addItem (theButton)
You can run the test with the button example here or download via MediaFire.
And once you have a button, our next step here is to create a popup - which happens when a user clicks a certain function button. Specifically, this is a predefined type of overlay window with a predefined width and height, users can point to a web page or software package, application with extension to display within the popup window. .
To create a popup window, we need to initialize the properties of the Popup object in the ToolbarUIItemProperties object:
var ToolbarUIItemProperties = {
disabled: false,
title: "Button Example",
icon: "icons / button.png",
popup: {
href: "popup.html",
width: 400,
height: 200
}
}
Note that by default, the width and height of the popup window is 300 x 300 . To change, you need to clearly define the parameters width , height as the example above.
To connect to the content of the popup window, you must use the attribute href :
theButton.popup.href = http://www.opera.com/ ";
Besides, we can also access the website stored on the local address:
theButton.popup.href = "popup.html";
These websites may be just normal HTML pages. Note that if you change the href attribute when the popup is dim, then the popup window will close. Technically, the size of the popup window will be determined in pixels by the width and height attribute:
And then, the popup window will be initialized with the button when the system calls the createItem method. You can experiment with the sample popup example here or download via MediaFire.
The badge concept here can be interpreted as a content layer that overlaps the icon with a certain text. They are often used to display the number of counts of certain components, such as the number of emails that have or have not been read. To create badges, we need to initialize the Badge object within the ToolbarUIItemProperties object:
var ToolbarUIItemProperties = {
disabled: false,
title: "Button Example",
icon: "icons / button.png",
badge: {
display: "block",
textContent: "12",
color: "white",
backgroundColor: "rgba (211, 0, 4, 1)"
}
}
Typical 1 badge will have 4 customizable attributes. And to display the badge you must use the display attribute. The values are block and none , the default value is none . And 1 badge will be set to display in the following syntax:
theButton.badge.display = "block";
Besides, the textContent attribute will be applied to display the label, and of course badge will limit the text displayed on the outside:
theButton.badge.textContent = "12";
Finally, the color and backgroundColor properties will set badge color and background color. Supports hexadecimal , RGBA and color coded modes:
theButton.badge.color = "white";
theButton.badge.backgroundColor: = "rgba (211, 0, 4, 1)";
You can test the extension button with badge here or via MediaFire. Good luck!