This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
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 #250 from ckeditor/t/245
Feature: Introduced the `'imageInsert'` command. Closes #245. Closes #251. BREAKING CHANGE: The `'imageUpload'` command's `files` parameter was renamed to `file`. It still can accept an array of files.
- Loading branch information
Showing
14 changed files
with
532 additions
and
91 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,61 @@ | ||
/** | ||
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
import Command from '@ckeditor/ckeditor5-core/src/command'; | ||
import { insertImage, isImageAllowed } from './utils'; | ||
|
||
/** | ||
* @module image/image/imageinsertcommand | ||
*/ | ||
|
||
/** | ||
* Insert image command. | ||
* | ||
* The command is registered by the {@link module:image/image/imageediting~ImageEditing} plugin as `'imageInsert'`. | ||
* | ||
* In order to insert an image at the current selection position | ||
* (according to the {@link module:widget/utils~findOptimalInsertionPosition} algorithm), | ||
* execute the command and specify the image source: | ||
* | ||
* editor.execute( 'imageInsert', { source: 'http://url.to.the/image' } ); | ||
* | ||
* It is also possible to insert multiple images at once: | ||
* | ||
* editor.execute( 'imageInsert', { | ||
* source: [ | ||
* 'path/to/image.jpg', | ||
* 'path/to/other-image.jpg' | ||
* ] | ||
* } ); | ||
* | ||
* @extends module:core/command~Command | ||
*/ | ||
export default class ImageInsertCommand extends Command { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
refresh() { | ||
this.isEnabled = isImageAllowed( this.editor.model ); | ||
} | ||
|
||
/** | ||
* Executes the command. | ||
* | ||
* @fires execute | ||
* @param {Object} options Options for the executed command. | ||
* @param {String|Array.<String>} options.source The image source or an array of image sources to insert. | ||
*/ | ||
execute( options ) { | ||
const model = this.editor.model; | ||
|
||
model.change( writer => { | ||
const sources = Array.isArray( options.source ) ? options.source : [ options.source ]; | ||
|
||
for ( const src of sources ) { | ||
insertImage( writer, model, { src } ); | ||
} | ||
} ); | ||
} | ||
} |
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
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
Oops, something went wrong.