-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change block commands to operate semantically, add ReversibleToolbarB…
…utton * Test that clicking multiple heading keeps correct active buttons
- Loading branch information
Showing
9 changed files
with
154 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import FormatBlockCommand from './format-block'; | ||
|
||
export default class HeadingCommand extends FormatBlockCommand { | ||
constructor() { | ||
constructor(editor) { | ||
const options = { | ||
name: 'heading', | ||
tag: 'h2', | ||
button: '<i class="ck-icon-heading"></i>1' | ||
}; | ||
super(options); | ||
super(editor, options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
import FormatBlockCommand from './format-block'; | ||
import { inherit } from 'content-kit-utils'; | ||
|
||
function QuoteCommand() { | ||
FormatBlockCommand.call(this, { | ||
name: 'quote', | ||
tag: 'blockquote', | ||
button: '<i class="ck-icon-quote"></i>' | ||
}); | ||
export default class QuoteCommand extends FormatBlockCommand { | ||
constructor(editor) { | ||
super(editor, { | ||
name: 'quote', | ||
tag: 'blockquote', | ||
button: '<i class="ck-icon-quote"></i>' | ||
}); | ||
} | ||
} | ||
inherit(QuoteCommand, FormatBlockCommand); | ||
|
||
export default QuoteCommand; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
import FormatBlockCommand from './format-block'; | ||
import { inherit } from 'content-kit-utils'; | ||
|
||
function SubheadingCommand() { | ||
FormatBlockCommand.call(this, { | ||
name: 'subheading', | ||
tag: 'h3', | ||
button: '<i class="ck-icon-heading"></i>2' | ||
}); | ||
export default class SubheadingCommand extends FormatBlockCommand { | ||
constructor(editor) { | ||
super(editor, { | ||
name: 'subheading', | ||
tag: 'h3', | ||
button: '<i class="ck-icon-heading"></i>2' | ||
}); | ||
} | ||
} | ||
inherit(SubheadingCommand, FormatBlockCommand); | ||
|
||
export default SubheadingCommand; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import mixin from '../utils/mixin'; | ||
import EventListenerMixin from '../utils/event-listener'; | ||
|
||
const ELEMENT_TYPE = 'button'; | ||
const BUTTON_CLASS_NAME = 'ck-toolbar-btn'; | ||
|
||
class ReversibleToolbarButton { | ||
constructor(command, editor) { | ||
this.command = command; | ||
this.editor = editor; | ||
this.element = this.createElement(); | ||
this.active = false; | ||
|
||
this.addEventListener(this.element, 'mouseup', e => this.handleClick(e)); | ||
this.editor.on('selection', () => this.updateActiveState()); | ||
this.editor.on('selectionUpdated', () => this.updateActiveState()); | ||
this.editor.on('selectionEnded', () => this.updateActiveState()); | ||
} | ||
|
||
// These are here to match the API of the ToolbarButton class | ||
setInactive() {} | ||
setActive() {} | ||
|
||
handleClick(e) { | ||
e.stopPropagation(); | ||
|
||
if (this.active) { | ||
this.command.unexec(); | ||
} else { | ||
this.command.exec(); | ||
} | ||
} | ||
|
||
updateActiveState() { | ||
this.active = this.command.isActive(); | ||
} | ||
|
||
createElement() { | ||
const element = document.createElement(ELEMENT_TYPE); | ||
element.className = BUTTON_CLASS_NAME; | ||
element.innerHTML = this.command.button; | ||
element.title = this.command.name; | ||
return element; | ||
} | ||
|
||
set active(val) { | ||
this._active = val; | ||
if (this._active) { | ||
this.element.className = BUTTON_CLASS_NAME + ' active'; | ||
} else { | ||
this.element.className = BUTTON_CLASS_NAME; | ||
} | ||
} | ||
|
||
get active() { | ||
return this._active; | ||
} | ||
} | ||
|
||
mixin(ReversibleToolbarButton, EventListenerMixin); | ||
|
||
export default ReversibleToolbarButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters