MonkeyPatching: PrimeFaces widgets extend/override

前端 未结 2 568
無奈伤痛
無奈伤痛 2021-01-06 07:21

I\'m currently using (it\'s working fine)

PrimeFaces.widget.OverlayPanel.prototype._old_init = PrimeFaces.widget.OverlayPanel.prototype.init;
PrimeFaces.widg         


        
2条回答
  •  悲哀的现实
    2021-01-06 08:12

    I had the same problem, but you're solution was not 100% efficient to my problem (See here https://github.com/primefaces/primefaces/issues/1928)) since you're willing to call _super() from OverlayPanel, and I'm trying to avoid it (it does few things I did not want to). So what I did is this:

    /* Quick fix so layout might be handled in dialog component PF #1928 */
    if(PrimeFaces.widget.Layout) {
        PrimeFaces.widget.Layout.prototype.init = function(cfg) {
            // skip calling PrimeFaces.widget.Layout.init() on purpose
            PrimeFaces.widget.DeferredWidget.prototype.init.call(this, cfg);
    
            this.cfg = cfg;
            this.id = this.cfg.id;
            this.jqId = PrimeFaces.escapeClientId(this.id);
    
            if(this.cfg.full) {          //full
                var dialog = $(this.cfg.center.paneSelector).parents('.ui-dialog-content');
                if(dialog) {             // full + dialog
                    this.jq = dialog;
                } else {
                    this.jq = $('body');
                }
            } else if(this.cfg.parent) { //nested
                this.jq = $(PrimeFaces.escapeClientId(this.cfg.parent));
            } else {                     //element
                this.jq = $(this.jqId);
            }
    
            this.renderDeferred();
        }
    }
    

    That way init() is completely overrided. I hope it will help few folks out there in this atypical case ;)

提交回复
热议问题