0

I needed to overwrite the show function for specific elements. This works fine so far. But there is an evil side effect: My growl element stays visible after it shows. There is no log error in the console and the other stuff works fine. It also doesnt stuck anywhere. It just never hides again after it is shown.

Here my jQuery function:

jQuery(function($) {

            jQuery.fn.oldshow = jQuery.fn.show;

            jQuery.fn.show = function() {
                //Use old function
                return jQuery(this).oldshow();
            };
        });

Here the growl element:

  <p:growl id="growl" showDetail="true" />

without the jQuery function it works as expected and hides again.

It would be great to get some tipps or a solution.

I already tried to replace it with:

jQuery(function($) {

            var oldshow = $.fn.show;

            $.fn.show = function(args) {
                var t = $(this);
                return oldshow.apply(t, arguments);
            };
        });

it makes no difference

Lule
  • 68
  • 9
  • Possible duplicate of [Passing arguments forward to another javascript function](http://stackoverflow.com/questions/3914557/passing-arguments-forward-to-another-javascript-function) – freedomn-m Feb 09 '17 at 11:23
  • doesn't solve my problem. There are no arguments passed in this case. I just tried it. Makes no difference :( – Lule Feb 09 '17 at 11:36
  • Debug the growl js and check where the hide is called and what goes wrong. Errors on the console? Lots of things you can and should try/investigate yourself. – Kukeltje Feb 09 '17 at 11:49
  • not so easy to get the primefaces original sourcecode for debugging – Lule Feb 09 '17 at 13:06
  • It is not really that difficult and worth the investment of half a day. – Kukeltje Feb 09 '17 at 16:25

1 Answers1

0

Overwrite the primefaces function instead of the jquery function

PrimeFaces.widget.Growl.prototype.show = (function() {
 var oldFunction = PrimeFaces.widget.Growl.prototype.show;
 return function() {
    //some logic

    //use old function
    return oldFunction.apply(this, arguments);
 };
})();
David Florez
  • 1,460
  • 2
  • 13
  • 26
  • I think (think) that op wants to do something in the generic jquery show and that it breaks the Growl. But I might be wrong (and the question than was not clear) and then your answer is correct – Kukeltje Feb 09 '17 at 16:27
  • Kukeltje is right. I need the function of the overlayPanel and tried to override it in general. But I will try to do it only for primefaces overlayPanel show-function and give you a feedback then! – Lule Feb 10 '17 at 13:57
  • it worked like that. But if you want to override primefaces show - pay attention to the fact that the primefaces function is named "_show" and not "show". – Lule Feb 20 '17 at 16:42