Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1809)

Unified Diff: chrome/browser/resources/shared/js/cr/ui/menu.js

Issue 10377169: Added menuItem icon support, and little API for menu modification. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added separator API. Simplified code. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/shared/js/cr/ui/menu.js
diff --git a/chrome/browser/resources/shared/js/cr/ui/menu.js b/chrome/browser/resources/shared/js/cr/ui/menu.js
index 94fea75c43948b6ca41197ff1a7ec6a92e7725b4..1928293c60406441e95f1c5a3f450ed4d1b438cd 100644
--- a/chrome/browser/resources/shared/js/cr/ui/menu.js
+++ b/chrome/browser/resources/shared/js/cr/ui/menu.js
@@ -34,6 +34,41 @@ cr.define('cr.ui', function() {
},
/**
+ * Adds menu item at the end of the list.
+ * @param {Object} item Menu item properties.
+ * @return {cr.ui.MenuItem} The created menu item.
+ */
+ addMenuItem: function(item) {
+ var menuItem = this.ownerDocument.createElement('menuitem');
+ this.appendChild(menuItem);
+
+ cr.ui.decorate(menuItem, MenuItem);
+
+ if (item.label)
+ menuItem.label = item.label;
+
+ if (item.iconUrl)
+ menuItem.iconUrl = item.iconUrl;
+
+ return menuItem;
+ },
+
+ /**
+ * Adds separator at the end of the list.
+ */
+ addSeparator: function() {
+ var separator = this.ownerDocument.createElement('hr');
+ this.appendChild(separator);
+ },
+
+ /**
+ * Clears menu.
+ */
+ clear: function() {
+ this.textContent = '';
+ },
+
+ /**
* Walks up the ancestors of |el| until a menu item belonging to this menu
* is found.
* @param {Element} el The element to start searching from.
@@ -79,6 +114,13 @@ cr.define('cr.ui', function() {
},
/**
+ * Menu length
+ */
+ get length() {
+ return this.children.length;
+ },
+
+ /**
* This is the function that handles keyboard navigation. This is usually
* called by the element responsible for managing the menu.
* @param {Event} e The keydown event object.

Powered by Google App Engine
This is Rietveld 408576698