steveathon / bootstrap-wysiwyg

Tiny bootstrap-compatible WYSIWYG rich text editor
MIT License
661 stars 1.71k forks source link

.bindToolbar bug #119

Open spreadred opened 7 years ago

spreadred commented 7 years ago

So in the .bindToolbar function there is a piece of code here:

        toolbar.find( toolbarBtnSelector ).click( function() {
            self.restoreSelection(  );
            editor.focus();

            if ( editor.data( options.commandRole ) === "html" ) {
                self.toggleHtmlEdit( editor );
            }

What this appears to be accomplishing is finding the toolbar and binding a .click handler to it. From inside the click handler, this is where we handle the the commands associated with the particular toolbar button which has been clicked.

For all cases except the "html button" we extract the command from the button's data-edit attribute using $( this ).data and pass that to execCommand. Following that logic, shouldn't the initial check for an HTML toggle button be:

if ( $( this ).data( options.commandRole ) === "html" )

The way it is now, it is trying to retrieve the data-edit value from the editor element, in this case a div which has no data-edit attribute, so it always fails spectacularly.