Search code examples
javascriptsummernote

Override some functions in javascript file (summernote.js)


I am changing summernote-lite.js to extend it's functionality and now I'm facing an issue: new version lunches and what now? I have to change it again if I want to use it on my websites. I think the best for me is to override functions that are already in that file and store that in separate js file, but how to do it?

For example here is beginning of the summernote-lite.js file:

(function (global, factory) {
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('jquery')) :
    typeof define === 'function' && define.amd ? define(['jquery'], factory) :
      (factory(global.jQuery));
}(this, (function ($$1) {

then here are couple functions that I want to override:

var imageDialog = function (opt) {
....
}

Next:

var ImageDialog = /* @class */ (function () {
    ...

    ImageDialog.prototype.initialize = function () {
      ...
    }
    ImageDialog.prototype.show = function () {
      ...
    }
    ImageDialog.prototype.showImageDialog = function () {
      ...
    }
    ...
}());

I want to change those mentioned functions (in ImageDialog just mentioned ones).

How I can do it?

Thanks, Dejan


Solution

  • As far as I can tell, you can not overwrite them, since they are encapsulated in a function scope which tries to emulate private methods on a class.

    In any case, I would suggest you not to overwrite any code method, rather to extend the class.

    class MyCustomImageDialog extends ImageDialog {
      constructor() {
        super();
      }
    
      initialize() { … }
      show() { … }
      showImageDialog() { … }
    }