medium-editor-insert-plugin icon indicating copy to clipboard operation
medium-editor-insert-plugin copied to clipboard

Simplify custom modifications

Open linkesch opened this issue 9 years ago • 2 comments

I've monkey-patched the addImage routine, also to pick from an internal image list, with our own custom handlers. So I've removed all the blueimp dependencies from my application, but only by duplicating a bunch of plugin code in my app.

$editor.data('plugin_mediumInsertImages').add = myAddImageCode;

Gross. Extension should be supported by the plugin, since applications will differ so widely...

@jbellsey in #177

linkesch avatar Apr 17 '15 15:04 linkesch

@jbellsey I started working on simplifying custom modifications. What are your requirements?

I have this API in mind:

// Initializition stays the same
$('.editable').mediumInsert({ editor: editor });

// Overriding core function
$('.editable').mediumInsert('deprecated', function (oldName, newName, version, since) {
    // Your custom content. You could even add new arguments if you need, just make sure the rest of the arguments remains backwards compatible
});

// Calling core function with arguments
$('.editable').mediumInsert('deprecated', 'old()', 'new()', '2.0', '1.7');

// Overriding addon function just by prepending addon name separated with colon
$('.editable').mediumInsert('images:addToolbar', function () {
    // Your custom content
});

// Calling addon function
$('.editable').mediumInsert('images:addToolbar');

What do you think? Would this help you with customizing? Or do you need something more than this?

linkesch avatar Apr 18 '15 12:04 linkesch

Why not add callback functions to the options object?

var options = {
  addons: {
    images: {
      callbacks: {
          newImage: function(opts) { return {url, width, height, title}; },
          // etc
      }
    }
  }

You could also let the user add callbacks individually, as you suggested. Perhaps by giving the user an API when they instantiate:

var MI = $obj.mediumInsert(options);
MI.addCallback('newImage', fnc);

jbellsey avatar Apr 20 '15 15:04 jbellsey