angular-summernote icon indicating copy to clipboard operation
angular-summernote copied to clipboard

options.callbacks being overwritten

Open shadybones opened this issue 10 years ago • 5 comments

So, now one has to add callbacks to all summernote elements instead of just one global location like a shared summernote options object.

Why not keep reference to the original callbacks object, and call those functions if they exist? Like this:

    var callbacks = {}, originalCallbacks = summernoteConfig.callbacks||{};
    callbacks.onEnter = function(evt) { 
        $scope.enter({evt:evt});
        !evt.defaultPrevented && angular.isFunction(originalCallbacks.onEnter) && originalCallbacks.onEnter(evt)
    };

shadybones avatar Jan 28 '16 21:01 shadybones

Geez, an even worse issue is that you're modifying the config object and you're not even making a copy of it first! Bad form ;) If you're going to muck with my configs, have the decency to not do it to the original object. This prevents one from having a global config.

shadybones avatar Jan 28 '16 21:01 shadybones

I didn't understand why !evt.defaultPrevented && angular.isFunction(originalCallbacks.onEnter) && originalCallbacks.onEnter(evt) parts are needed?

But I agree with you for making a copy of the config object.

outsideris avatar Feb 01 '16 18:02 outsideris

well, !evt.defaultPrevented isn't really needed I suppose

shadybones avatar Feb 04 '16 02:02 shadybones

I don't understand originalCallbacks.onEnter(evt) part, too. $scope.enter({evt:evt}); call a function which a user bind it to callback. Why it invoke callbacks again?

outsideris avatar Feb 05 '16 12:02 outsideris

Ok, try re-reading the opening issue (making a copy of the config object is just a side issue). Basically, I want to be able to have a globally shared config object for all my summernotes, which contains these event callbacks. Currently, you overwrite these values on the config object, forcing one to add "on-event" attributes in the HTML, to each of the (possibly) dozens of summernote forms. This is a hassle. If summernote would just check for these event handlers on the config object, as well as accepting "on-event" attributes, then I wouldn't need to add event listeners to each instance.

Basically you accept a summernote config object, and then overwrite some pretty important things, before passing it to summernote. It'd be better if you didn't do that.

shadybones avatar Feb 07 '16 19:02 shadybones