Hello again !

I'm trying to setup a function call on this event because I have to manipulate some markup at menu display time.

I tried this code :

     Drupal.behaviors.MyBehaviour = {
        attach: function(context, settings) {
            $('#superfish-1').superfish('onBeforeShow', function() {
              alert('onBeforeShow ok');              
            });
        }
     }  

... which works but seems to mess up the other init options (drop shadows back despite the fact they are disabled in config). I suspect it resets everything to default.

So my quesiton is : is there a way to add or change an option after the menu has been initialized, or should I setup my own intialisation functionwith all the options I need ?

The first solution would be a lot more convenient, but I couldn't find any working example on the net, so I'm asking the local expert ;-).

Comments

Countzero’s picture

Spoke too soon : in fact it doesn't work at all.

mehrpadin’s picture

Bonjour,

You can use the "supposition.js" as a reference:

(function($){
  $.fn.myfunction = function(){
    var onBeforeShow = function(){
      alert('Hello there!');
    };

    return this.each(function() {
      var o = $.fn.superfish.o[this.serial];

      var _onBeforeShow = o.onBeforeShow;

      $.extend($.fn.superfish.o[this.serial],{
        onBeforeShow: function() {
          onBeforeShow.call(this);
          _onBeforeShow.call(this);
        };
      });
    });
  };
})(jQuery);
Countzero’s picture

Thank you but I don't get it. How am I supposed to call this code afterwards ?

OnBeforeShow is a standard superfish option, supposed to fire a callback before showing any ul element in the menu.

I don't see why it should be necessary to extend the existing plugin to handle this.

Countzero’s picture

I ran this on a non superfish block menu and it behaves as expected.

            $('#block-system-main-menu .content > ul.menu').superfish({
              dropShadows:false,
              animation:     {opacity:'show'},
              pathClass:'active-trail',
              autoArrows:false,
              onBeforeShow: function() {
                    // Do stuff here
                  }
            });

I guess what I'd need is a setter function for the superfish options, but there are not, right ?

As my menu won't change a lot once configured, I'll stick with this mildly satisfying solution.

I don't know if it's of any use for you to leave this issue open.

As far as I'm concerned, and except if you come up with a cleaner way to do it (mean : not bypassing your module's great functionalities), we can close this.

Thanks

mehrpadin’s picture

Mon ami, I think I've an idea, added to my to-do list for the next version.

sagannotcarl’s picture

Title: OnBeforeShow » onBeforeShow, onShow, and onHide
Category: support » feature
StatusFileSize
new3.86 KB

Here is a patch that provides fields on the block settings form to add custom onBeforeShow, onShow, and an onHide functions.

You can put whatever javascript you want in those fields. It solves a short-term need I have but I'm sure this is a security problem if you have untrusted users with administer block permissions.

Any thoughts on how to allow this kind of thing to happen without running javascript directly from a user?

mehrpadin’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

The patch - or the feature - cannot be added due to security & stability issue, those requiring this feature can add sub-plugins like advised above :)