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 40
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 #1753 from ckeditor/t/ckeditor5-typing/167
Feature: Added `view.Document#event:beforeinput`.
- Loading branch information
Showing
5 changed files
with
90 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/** | ||
* @module engine/view/observer/inputobserver | ||
*/ | ||
|
||
import DomEventObserver from './domeventobserver'; | ||
|
||
/** | ||
* Observer for events connected with data input. | ||
* | ||
* Note that this observer is attached by the {@link module:engine/view/view~View} and is available by default. | ||
* | ||
* @extends module:engine/view/observer/domeventobserver~DomEventObserver | ||
*/ | ||
export default class InputObserver extends DomEventObserver { | ||
constructor( view ) { | ||
super( view ); | ||
|
||
this.domEventType = [ 'beforeinput' ]; | ||
} | ||
|
||
onDomEvent( domEvent ) { | ||
this.fire( domEvent.type, domEvent ); | ||
} | ||
} | ||
|
||
/** | ||
* Fired before browser inputs (or deletes) some data. | ||
* | ||
* This event is available only on browsers which support DOM `beforeinput` event. | ||
* | ||
* Introduced by {@link module:engine/view/observer/inputobserver~InputObserver}. | ||
* | ||
* Note that because {@link module:engine/view/observer/inputobserver~InputObserver} is attached by the | ||
* {@link module:engine/view/view~View} this event is available by default. | ||
* | ||
* @see module:engine/view/observer/inputobserver~InputObserver | ||
* @event module:engine/view/document~Document#event:beforeinput | ||
* @param {module:engine/view/observer/domeventdata~DomEventData} data Event data. | ||
*/ |
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,40 @@ | ||
/** | ||
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license | ||
*/ | ||
|
||
import InputObserver from '../../../src/view/observer/inputobserver'; | ||
import View from '../../../src/view/view'; | ||
|
||
describe( 'InputObserver', () => { | ||
let view, viewDocument, observer; | ||
|
||
beforeEach( () => { | ||
view = new View(); | ||
viewDocument = view.document; | ||
observer = view.getObserver( InputObserver ); | ||
} ); | ||
|
||
afterEach( () => { | ||
view.destroy(); | ||
} ); | ||
|
||
it( 'should define domEventType', () => { | ||
expect( observer.domEventType ).to.contains( 'beforeinput' ); | ||
} ); | ||
|
||
it( 'should fire beforeinput with dom event data', () => { | ||
const spy = sinon.spy(); | ||
|
||
viewDocument.on( 'beforeinput', spy ); | ||
|
||
const domEvtData = { | ||
type: 'beforeinput' | ||
}; | ||
|
||
observer.onDomEvent( domEvtData ); | ||
|
||
expect( spy.calledOnce ).to.be.true; | ||
expect( spy.args[ 0 ][ 1 ].domEvent ).to.equal( domEvtData ); | ||
} ); | ||
} ); |
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