-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1096 from julien/issue/1048
Fixes #1048 | Add button to remove images
- Loading branch information
Showing
7 changed files
with
107 additions
and
6 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
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,3 @@ | ||
import removeImageCommand from './remove-image'; | ||
|
||
export {removeImageCommand}; |
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,29 @@ | ||
const removeImageCommand = { | ||
exec: editor => { | ||
const selection = editor.getSelection(); | ||
|
||
if (selection) { | ||
const ranges = selection.getRanges(); | ||
const startContainer = ranges[0].startContainer; | ||
|
||
const nextRange = new CKEDITOR.dom.range(startContainer); | ||
nextRange.setStart(startContainer, 0); | ||
nextRange.setEnd(startContainer, 0); | ||
|
||
const selectedElement = selection.getSelectedElement(); | ||
|
||
if (selectedElement && selectedElement.getName() === 'img') { | ||
const native = selection.getNative(); | ||
if (native) { | ||
native.removeAllRanges(); | ||
} | ||
|
||
selection.selectRanges([nextRange]); | ||
|
||
selectedElement.remove(); | ||
} | ||
} | ||
}, | ||
}; | ||
|
||
export default removeImageCommand; |
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,37 @@ | ||
import ButtonCommand from '../base/button-command.js'; | ||
import ButtonIcon from './button-icon.jsx'; | ||
import ButtonStateClasses from '../base/button-state-classes.js'; | ||
import React from 'react'; | ||
|
||
/** | ||
* The ButtonRemoveImage class removes an image using a CKEDITOR.command. | ||
* | ||
* @class ButtonRemoveImage | ||
* @uses ButtonCommand | ||
*/ | ||
class ButtonRemoveImage extends React.Component { | ||
static defaultProps = { | ||
command: 'removeImage', | ||
}; | ||
|
||
static key = 'removeImage'; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
render() { | ||
const cssClass = `ae-button ${this.getStateClasses()}`; | ||
|
||
return ( | ||
<button | ||
aria-label={AlloyEditor.Strings.removeImage} | ||
aria-pressed={cssClass.indexOf('pressed') !== -1} | ||
className={cssClass} | ||
onClick={this.execCommand}> | ||
<ButtonIcon symbol="times-circle" /> | ||
</button> | ||
); | ||
} | ||
} | ||
|
||
export default ButtonCommand(ButtonStateClasses(ButtonRemoveImage)); |
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