Hi all.

I've written a custom drop-down menu class that works great.  To add
more functionality, and the ability to dynamically manipulate
elements, I added an "onBeforeDrop" event ... but it won't fire.  I
placed an alert within the event just in case.  What am I doing wrong?

Here are the relevant portions of the script:

var Menu = new Class({
  Implements: [Options,Events],
  options: {
    minWidth: 150,
    wrapperClass: 'dropdownmenu',
    sizeToSender: false,
    showEvent: 'click',
    elements: {},
//    onBeforeDrop: $emptyFalse,
  },
  // Event/function happens onClick for the "item" argument.
  showMenu: function(event, item) {
    event.stop();
    //...
    this.fireEvent('beforedrop', [this.options.elements, item, this]);
    //...
  },
}

And in the <script> tags:
  window.addEvent('domready', function() {
    var links;
    var userMenu;
    if(links = $$('.userLink'))
      userMenu = new Menu({
        sizeToSender: true,
        elements: ['<a href="?cmd=user.view&amp;uid=0"><img src="img/
icons/icon_user.gif" alt="" /> <span>View Profile</span></a>',
          '<a href="?cmd=user.pm&amp;uid=0"><img src="img/icons/
icon_mail.gif" alt="" /> <span>Private Message</span></a>']
        // tried a onBeforeDrop event here, no good.
      }).attachTo(links)
      .addEvent('beforedrop', function(elements, link, sender) {
        alert('onBeforeDrop called!');
        var temp = (/uid=(\d+)$/).exec($(link).get('href'));
        var uid = temp[1].toInt();
        $A(elements).each(function(item, index) {
          elements[index] = item.replace(/uid=(\d+)$/,'uid='+uid);
        });
        sender.rebuildMenu();
      });
  })


Thanks for anything you might spot.  If need be I'll throw together
the full source plus an html test page.  I'm considering releasing
this to the community under an MIT license anyway. ;-)

Thanks,
Flea

Reply via email to