Badge.textContent

By Opera Software

Description:

The text that will be shown in the badge; this may overflow the visual space provided which is usually around four characters.

Example:

//
// The background process (e.g. index.html)
//

// Set the button's properties
var properties = {
  disabled: false,
  title: "My Test Extension",
  icon: "icon.18x18.png",
  badge: {
    backgroundColor: '#5566FF',
    color: 'white',
    textContent: '0'
  }
};	

// Add the button to the browser UI
var button = opera.contexts.toolbar.createItem(properties);
opera.contexts.toolbar.addItem(button);

// Set the button's click handler
var i = 1; 
button.addEventListener('click', handleClick, false);

function handleClick() {
  // If clicked more than five times, show '5+' in the badge
  var badgeText = (i > 5) ? '5+' : i;

  // Update the badge text
  button.badge.textContent = badgeText;

  // Update the button title
  button.title = "You've clicked the button " + i + " time(s)"; 

  i++;
}
// // The background process (e.g. index.html) // // Set the button's properties var properties = { disabled: false, title:

This article is licensed under a Creative Commons Attribution 3.0 Unported license.

Comments

No new comments accepted.