Skip to content

Commit

Permalink
Remove extraneous arguments in toolbar/view logic
Browse files Browse the repository at this point in the history
  • Loading branch information
bantic committed Sep 3, 2015
1 parent a2a9969 commit f5871fc
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
6 changes: 1 addition & 5 deletions src/js/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class Editor {

this.element = element;

this.applyClassName(EDITOR_ELEMENT_CLASS_NAME);
addClassName(this.element, EDITOR_ELEMENT_CLASS_NAME);
this.applyPlaceholder();

element.spellcheck = this.spellcheck;
Expand Down Expand Up @@ -388,10 +388,6 @@ class Editor {
return new Cursor(this);
}

applyClassName(className) {
addClassName(this.element, className);
}

applyPlaceholder() {
const placeholder = this.placeholder;
const existingPlaceholder = getData(this.element, 'placeholder');
Expand Down
2 changes: 2 additions & 0 deletions src/js/models/markup-section.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const MarkupSection = class MarkupSection extends Markerable {
splitAtMarker(marker, offset=0) {
let [beforeSection, afterSection] = [
this.builder.createMarkupSection(this.tagName, []),
// FIXME we probably want to make it so that we create a new default markup
// section instead of copying the same tagname to the section below
this.builder.createMarkupSection(this.tagName, [])
];

Expand Down
6 changes: 6 additions & 0 deletions src/js/utils/dom-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ function addClassName(element, className) {
element.classList.add(className);
}

function removeClassName(element, className) {
// FIXME-IE IE10+
element.classList.remove(className);
}

function normalizeTagName(tagName) {
return tagName.toLowerCase();
}
Expand All @@ -136,6 +141,7 @@ export {
walkDOM,
walkTextNodes,
addClassName,
removeClassName,
normalizeTagName,
isTextNode,
parseHTML
Expand Down
9 changes: 4 additions & 5 deletions src/js/views/reversible-toolbar-button.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import mixin from '../utils/mixin';
import EventListenerMixin from '../utils/event-listener';
import { addClassName, removeClassName } from '../utils/dom-utils';

const ELEMENT_TYPE = 'button';
const BUTTON_CLASS_NAME = 'ck-toolbar-btn';
const ACTIVE_CLASS_NAME = 'active';

class ReversibleToolbarButton {
constructor(command, editor) {
Expand Down Expand Up @@ -53,11 +55,8 @@ class ReversibleToolbarButton {

set active(val) {
this._active = val;
if (this._active) {
this.element.className = BUTTON_CLASS_NAME + ' active';
} else {
this.element.className = BUTTON_CLASS_NAME;
}
let method = this._active ? addClassName : removeClassName;
method(this.element, ACTIVE_CLASS_NAME);
}

get active() {
Expand Down
5 changes: 2 additions & 3 deletions src/js/views/text-format-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ export default class TextFormatToolbar extends Toolbar {

handleResize() {
if (this.isShowing) {
const activePromptRange = this.activePrompt && this.activePrompt.range;
this.positionToContent(activePromptRange ? activePromptRange : window.getSelection().getRangeAt(0));
this.positionToContent();
}
}

handleSelection() {
this.show();
this.updateForSelection(window.getSelection());
this.updateForSelection();
}

handleSelectionEnded() {
Expand Down
10 changes: 6 additions & 4 deletions src/js/views/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,16 @@ class Toolbar extends View {
this.updateForSelection();
}

updateForSelection(selection=window.getSelection()) {
updateForSelection() {
if (!this.isShowing) { return; }
if (!selection.isCollapsed) {
this.positionToContent(selection.getRangeAt(0));
const selection = window.getSelection(),
range = selection && selection.getRangeAt(0);
if (!range.collapsed) {
this.positionToContent(range);
}
}

positionToContent(content) {
positionToContent(content=window.getSelection().getRangeAt(0)) {
var directions = ToolbarDirection;
var positioningMethod, position, sideEdgeOffset;
switch(this.direction) {
Expand Down

0 comments on commit f5871fc

Please sign in to comment.