提交 38532186 编写于 作者: K Kohsuke Kawaguchi

properly scoping names in the JavaScript to avoid leakage

上级 a0a14c25
...@@ -55,7 +55,7 @@ THE SOFTWARE. ...@@ -55,7 +55,7 @@ THE SOFTWARE.
<ul id="breadcrumbs"> <ul id="breadcrumbs">
<j:forEach var="anc" items="${request.ancestors}"> <j:forEach var="anc" items="${request.ancestors}">
<j:if test="${h.isModel(anc.object) and anc.prev.url!=anc.url}"> <j:if test="${h.isModel(anc.object) and anc.prev.url!=anc.url}">
<li onmouseover="return foo(this)"> <li onmouseover="return breadcrumb.activate(this)">
<a href="${anc.url}/"> <a href="${anc.url}/">
${anc.object.displayName} ${anc.object.displayName}
</a> </a>
...@@ -63,7 +63,7 @@ THE SOFTWARE. ...@@ -63,7 +63,7 @@ THE SOFTWARE.
</j:if> </j:if>
</j:forEach> </j:forEach>
</ul> </ul>
<div id="rendertarget"/> <div id="breadcrumb-menu-target"/>
</div> </div>
</div> </div>
</td> </td>
......
/** @type {YAHOO.widget.Menu} */ var breadcrumb = (function() {
var oMenu; /** @type {YAHOO.widget.Menu} */
var menu;
var xhr; /**
* Used for fetching the content of the menu asynchronously from the server
*/
var xhr;
/** /**
* @param {HTMLElement} e * Activates the context menu for the specified breadcrumb element.
* The LI tag that the mouse has wondered into. *
*/ * @param {HTMLElement} e
function foo(e) { * The LI tag that the mouse has wondered into.
function showMenu(items) { */
oMenu.hide(); function activate(e) {
oMenu.cfg.setProperty("context",[e,"tl","bl"]); function showMenu(items) {
oMenu.clearContent(); menu.hide();
oMenu.addItems(items); menu.cfg.setProperty("context",[e,"tl","bl"]);
oMenu.render("rendertarget"); menu.clearContent();
oMenu.show(); menu.addItems(items);
} menu.render("breadcrumb-menu-target");
menu.show();
}
if (xhr) if (xhr)
xhr.options.onComplete = function() {}; // ignore the currently pending call xhr.options.onComplete = function() {}; // ignore the currently pending call
if (e.items) {// use what's already loaded if (e.items) {// use what's already loaded
showMenu(e.items); showMenu(e.items);
} else {// fetch menu on demand } else {// fetch menu on demand
xhr = new Ajax.Request(e.firstChild.getAttribute("href")+"contextMenu", { xhr = new Ajax.Request(e.firstChild.getAttribute("href")+"contextMenu", {
onComplete : function (x) { onComplete : function (x) {
var a = x.responseText.evalJSON().items; var a = x.responseText.evalJSON().items;
a.each(function(e) { a.each(function(e) {
e.text = "<img src='"+e.icon+"' width=24 height=24 style='margin: 2px;' alt=''> "+e.displayName; e.text = "<img src='"+e.icon+"' width=24 height=24 style='margin: 2px;' alt=''> "+e.displayName;
});
e.items = a;
showMenu(a);
}
}); });
e.items = a;
showMenu(a);
} }
return false;
}
window.addEventListener("load",function(){
menu = new YAHOO.widget.Menu("breadcrumb-menu", {position:"dynamic", hidedelay:1000});
}); });
}
return false; return { activate : activate };
} })();
window.addEventListener("load",function(){
oMenu = new YAHOO.widget.Menu("breadcrumb-menu", {position:"dynamic", hidedelay:1000});
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册