From c8a400ce937201bb8063eb3d4e22200f3042c4d8 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 21 Feb 2012 16:41:47 +0900 Subject: [PATCH] added a mechanism to specify a function to lazily render the menu --- .../main/resources/lib/layout/breadcrumbs.js | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/core/src/main/resources/lib/layout/breadcrumbs.js b/core/src/main/resources/lib/layout/breadcrumbs.js index fbedd31d02..b632ac935d 100644 --- a/core/src/main/resources/lib/layout/breadcrumbs.js +++ b/core/src/main/resources/lib/layout/breadcrumbs.js @@ -1,5 +1,9 @@ var breadcrumbs = (function() { - /** @type {YAHOO.widget.Menu} */ + /** + * This component actually renders the menu. + * + * @type {YAHOO.widget.Menu} + */ var menu; /** @@ -8,7 +12,7 @@ var breadcrumbs = (function() { var xhr; function makeMenuHtml(icon,displayName) { - return " "+displayName; + return (icon!=null ? " " : "")+displayName; } window.addEventListener("load",function(){ @@ -16,7 +20,7 @@ var breadcrumbs = (function() { }); jenkinsRules["#breadcrumbs LI"] = function (e) { - // when the moust hovers over LI, activate the menu + // when the mouse hovers over LI, activate the menu e.addEventListener("mouseover", function () { function showMenu(items) { menu.hide(); @@ -32,7 +36,7 @@ var breadcrumbs = (function() { }; // ignore the currently pending call if (e.items) {// use what's already loaded - showMenu(e.items); + showMenu(e.items()); } else {// fetch menu on demand xhr = new Ajax.Request(e.firstChild.getAttribute("href") + "contextMenu", { onComplete:function (x) { @@ -40,7 +44,7 @@ var breadcrumbs = (function() { a.each(function (e) { e.text = makeMenuHtml(e.icon, e.displayName); }); - e.items = a; + e.items = function() { return a }; showMenu(a); } }); @@ -76,10 +80,13 @@ var breadcrumbs = (function() { * * @param {String|HTMLElement} li * The LI tag to which you associate the menu (or its ID) - * @param {breadcrumbs.ContextMenu} + * @param {Function|breadcrumbs.ContextMenu} menu + * Pass in the configured menu object. If a function is given, this function + * is called each time a menu needs to be displayed. This is convenient for dynamically + * populating the content. */ "attachMenu" : function (li,menu) { - $(li).items = menu.items; + $(li).items = (typeof menu=="function") ? menu : function() { return menu.items }; }, "ContextMenu" : ContextMenu