7

Hi I am trying to extend this jQuery plugin but it seems I can't seem to find a way to do it like the other plugins. I've tried:

$.fn.picEdit.somefunction = function() {

But it seems that the plugin functions is encapsulated.

Does anyone know how to override this specific plugin(not editing/hacking any on the inside of the JS plugin)? I just want to know if it can be extended or not. Thanks.

Cedric
  • 1,236
  • 2
  • 18
  • 35
  • please explain what you would like to achieve – mylee Feb 16 '16 at 03:43
  • I didn't know about _picEdit_'s existence... it looks a very nice plugin, if you explain us what function are you trying to extend, and what might be your expected result, I'll gladly try to help you. –  Feb 16 '16 at 15:24
  • picEdit looks like an awesome jQuery Plug-In. –  Feb 17 '16 at 15:38
  • Hi [mylee](http://stackoverflow.com/users/5417823/mylee), I am trying to extend it to have some option that can handle my error scenarios such as 404 or 400 because there's no currently implemented error option in the said plugin only a generic error message. – Cedric Feb 22 '16 at 00:10
  • Hi [Washington Guedes](http://stackoverflow.com/users/4227915/washington-guedes), like I said to mylee I want to add some options like error option, and also edit some functions like `_template` function to edit the html template of the picEdit plugin. – Cedric Feb 22 '16 at 00:15

1 Answers1

1

You could create a duplicate of the picEdit object, extend that object and set jQuery.fn.picEdit to the copy.

Code:

(function(window, document, $, undefined) {
  // your methods
  var methods = {
    sayHi: function(name) {
      alert("Hello " + name);
    }
  };
  // duplicate of the extended picEdit
  var newPicEdit = $.extend($.fn.picEdit, methods)
  // set jQuery.fn.picEdit 
  $.fn.picEdit = newPicEdit;
})(this, this.document, jQuery);

Good luck, hope it helps.

  • @Cedric Have you found the answer yet, if so would you mind sharing it? I'm just curious as this is a problem I've not seen before. –  Feb 24 '16 at 13:27
  • because of the time constraint in our project, I have no choice but to hack the current plugin, and edit it to meet our requirements, but I've tried you're answer and it's not working. Still haven't find the right way to extend it. – Cedric Mar 02 '16 at 01:08