Skip to content

Commit

Permalink
Refactors first and last button method
Browse files Browse the repository at this point in the history
  • Loading branch information
Davi Ferreira committed Sep 24, 2013
1 parent b269a5c commit 465000d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
11 changes: 9 additions & 2 deletions dist/js/medium.editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ function MediumEditor(elements, options) {
this.selection = newSelection;
this.selectionRange = this.selection.getRangeAt(0);
this.toolbar.style.display = 'block';
this.setToolbarPosition()
.setToolbarButtonStates()
this.setToolbarButtonStates()
.setToolbarPosition()
.showToolbarActions();
}
}
Expand Down Expand Up @@ -257,6 +257,13 @@ function MediumEditor(elements, options) {
for (i = 0; i < buttons.length; i += 1) {
buttons[i].addEventListener('click', triggerAction);
}
this.setFirstAndLastItens(buttons);
return this;
},

setFirstAndLastItens: function (buttons) {
buttons[0].className += ' medium-editor-button-first';
buttons[buttons.length - 1].className += ' medium-editor-button-last';
return this;
},

Expand Down
2 changes: 1 addition & 1 deletion dist/js/medium.editor.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions spec/buttons.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,13 @@ describe('Buttons TestCase', function () {
});

});

describe('First and Last', function () {
it('should add a special class to the first and last buttons', function () {
var editor = new MediumEditor('.editor'),
buttons = editor.toolbar.querySelectorAll('button');
expect(buttons[0].className).toContain('medium-editor-button-first');
expect(buttons[buttons.length - 1].className).toContain('medium-editor-button-last');
});
});
});
Loading

0 comments on commit 465000d

Please sign in to comment.