jquery - 如何打开和关闭丰富的:popupPanel from the same link

标签 jquery jsf jsf-2 richfaces

我按照展示中的这个例子:http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=popup&sample=login&skin=blueSky 它显示了如何单击链接来打开弹出面板并将该面板附加到该链接的相同位置。但我希望如果我再次单击,它将关闭面板。有人知道如何实现这一目标吗?这是我的代码

    <h:outputLink value="#" id="sb-dd-ol" >
        <rich:componentControl event="click" operation="show" target="sb-dd-pp">
            <a4j:param noEscape="true" value="event"/>
            <rich:hashParam>
                <a4j:param noEscape="true" name="top"
                           value="jQuery(#{rich:element('sb-dd-ol')}.parentNode).offset().top + 
                                  jQuery(#{rich:element('sb-dd-ol')}.parentNode).height()" />
                <a4j:param noEscape="true" name="left" 
                           value="jQuery(#{rich:element('sb-dd-ol')}.parentNode).offset().left" />
            </rich:hashParam>
        </rich:componentControl>
        Test
    </h:outputLink>
    <rich:popupPanel id="sb-dd-pp" autosized="true" modal="false" 
                     moveable="false" resizeable="false" followByScroll="false">
        This is a test
    </rich:popupPanel>

最佳答案

您可以扩展 PopupPanel 原型(prototype),如下所示:

jQuery.extend(RichFaces.ui.PopupPanel.prototype, {
    toggle: function(event, opts) {
        if (this.shown) {
            this.hide(event, opts);
        } else {
            this.show(event, opts);
        }
    }
}

之后,您可以在 componentControl 中使用 operation="toggle" (或者添加 onclick="#{rich:component('sb-dd-pp')}.toggle ();" 在链接上)。

关于jquery - 如何打开和关闭丰富的:popupPanel from the same link,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12736793/

相关文章:

javascript - 如何在图像悬停中显示文本

java - 似乎无法弄清楚如何使用 primefaces 重定向到 .xhtml

jsf - <h :head> and <head> in Java Facelets? 和有什么区别

java - 单击电子邮件激活链接时如何登录用户?(JSF 2.0)

javascript - Jquery 如果在列表中选中了两个复选框之一。

JQuery Double 每个函数

ajax - 在 ajax 表单提交后保留 bean 属性

JSF 2.0 注入(inject)不同范围的托管 bean

jsf - 是否可以拦截来自@ManagedBean 的方法?如果没有,有替代方案吗?

javascript - 如何添加悬停事件监听器来触发事件监听器