1

I'm using the Adobe Accessible Mega Menu plugin and am looking to extend this, (basically add a function that can be called from another script).

I've looked into extending jquery plugins, javascript closures and various other threads on the subject and I can see how this works

I can also see a bunch of public attributes and methods (ln 695 on) however attempting to call these merely returns the jquery object?

Equally adding a function and attempting to call that doesn't seem to work?

I've added a function called testFunction which fires an alert and should (i think) be called :

$("nav:first").accessibleMegaMenu("testFunction");

but no luck far..

Does anyone know how I can add a function to the above script, that can be called from another script?

https://codepen.io/anon/pen/VjzkqE

edit: solved - functions need to be accessed through the prototype obj as in :

nav.accessibleMegaMenu.AccessibleMegaMenu.prototype.customFunction(param);
Community
  • 1
  • 1
dg85
  • 490
  • 2
  • 7
  • 21
  • 1
    While you could do this, I would advise against it. If the plugin is updated in the future it could easily break your extended functionality and you would be left having to use an outdated version or spend time refactoring your extension, neither of which is ideal. I would suggest using a plugin which matches all your requirements, if you can find one. – Rory McCrossan Jul 06 '16 at 10:01
  • @RoryMcCrossan, i was planning on simply moving this out to another script so it is insulated from updates. – dg85 Jul 06 '16 at 10:09

1 Answers1

1

I have implemented this approach on a project by using extend function from jquery and prototype to extend infinitescroll plugin you can take this approach and implement it to your plugin I hope this would be useful for you as well

$.extend($.infinitescroll.prototype, {
    fucntion1: function() {
      //function implementation    
    },
    fucntion2: function() {
       //function implementaion
    }    
});

take a look for the question Best Way to Extend a jQuery Plugin

Community
  • 1
  • 1
Alaa M. Tekleh
  • 6,938
  • 4
  • 16
  • 29
  • Thanks, it was accessing the function through the prototype obj that was the trick. – dg85 Jul 06 '16 at 12:54