繁体   English   中英

如何从同一链接打开和关闭rich:popupPanel

[英]How to open and close rich:popupPanel from the same link

我从展示柜中遵循以下示例: http ://showcase.richfaces.org/richfaces/component-sample.jsf?demo=popup&sample=login&skin=blueSky它展示了如何单击链接以打开popupPanel并附加该面板到该链接的相同位置。 但是我希望这样,如果我再次单击,它将关闭面板。 有人知道如何实现吗? 这是我的代码

    <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原型,如下所示:

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();" )。

不太了解richfaces 4,但是modalpanel渲染了div,它的可见性可以用简单的js控制:

var isShown = false;
function onlinkclick() {
  if(isShown) {
      hideElement();
  } else {
      showElement();
  }
  isShown = !isShown;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM