codemirror-ui icon indicating copy to clipboard operation
codemirror-ui copied to clipboard

Inside editorChanged function need to check for existence of element before adding / removing class

Open kipwilliams opened this issue 12 years ago • 0 comments

Around line 335 in function editorChanged if the save or redo buttons are not used then "Uncaught TypeError: Cannot read property 'className' of undefined " in chrome will pop on the first line of the removeClass function.

The solution was to replace the code below

  var his = this.mirror.historySize();
    if (his['undo'] > 0) {
      this.removeClass(this.saveButton, 'inactive');
      this.removeClass(this.undoButton, 'inactive');
    } else {
      this.addClass(this.saveButton, 'inactive');
      this.addClass(this.undoButton, 'inactive');
    }
    if (his['redo'] > 0) {
      this.removeClass(this.redoButton, 'inactive');
    } else {
      this.addClass(this.redoButton, 'inactive');
    }

with this

var his = this.mirror.historySize();
    if (his['undo'] > 0) {
        if(this.saveButton !== null && this.saveButton !== undefined)
            this.removeClass(this.saveButton, 'inactive');
        if(this.undoButton !== null && this.undoButton !== undefined)
            this.removeClass(this.undoButton, 'inactive');
    } else {
        if(this.saveButton !== null && this.saveButton !== undefined)
            this.addClass(this.saveButton, 'inactive');

        if(this.undoButton !== null && this.undoButton !== undefined)
            this.addClass(this.undoButton, 'inactive');
    }
    if (his['redo'] > 0) {
        if(this.redoButton !== null && this.redoButton !== undefined)
            this.removeClass(this.redoButton, 'inactive');
    } else {
        if(this.redoButton !== null && this.redoButton !== undefined)
            this.addClass(this.redoButton, 'inactive');
    }

kipwilliams avatar Oct 14 '12 14:10 kipwilliams