8
0
Просмотр исходного кода

Renamed FocusManager to FocusTracker.

Oskar Wróbel 9 лет назад
Родитель
Сommit
1e5393e06e

+ 11 - 11
packages/ckeditor5-utils/src/focusmanager.js

@@ -24,14 +24,14 @@ import mix from './mix.js';
  * @mixes utils.DOMEmitterMixin
  * @mixes utils.ObservableMixin
  */
-export default class FocusManager {
+export default class FocusTracker {
 	constructor() {
 		/**
 		 * True when one of the registered elements is focused.
 		 *
 		 * @readonly
 		 * @observable
-		 * @member {Boolean} utils.FocusManager#isFocused
+		 * @member {Boolean} utils.FocusTracker#isFocused
 		 */
 		this.set( 'isFocused', false );
 
@@ -39,7 +39,7 @@ export default class FocusManager {
 		 * List of registered elements.
 		 *
 		 * @private
-		 * @member {Array<HTMLElement>} utils.FocusManager#_elements
+		 * @member {Array<HTMLElement>} utils.FocusTracker#_elements
 		 */
 		this._elements = [];
 
@@ -47,7 +47,7 @@ export default class FocusManager {
 		 * Event loop timeout.
 		 *
 		 * @private
-		 * @member {Number} utils.FocusManager#_nextEventLoopTimeout
+		 * @member {Number} utils.FocusTracker#_nextEventLoopTimeout
 		 */
 		this._nextEventLoopTimeout = null;
 
@@ -55,7 +55,7 @@ export default class FocusManager {
 		 * Currently focused element.
 		 *
 		 * @private
-		 * @member {HTMLElement} utils.FocusManager#_focusedElement
+		 * @member {HTMLElement} utils.FocusTracker#_focusedElement
 		 */
 		this._focusedElement = null;
 	}
@@ -67,7 +67,7 @@ export default class FocusManager {
 	 */
 	add( element ) {
 		if ( this._elements.indexOf( element ) >= 0 ) {
-			throw new CKEditorError( 'focusManager-add-element-already-exist' );
+			throw new CKEditorError( 'focusTracker-add-element-already-exist' );
 		}
 
 		this.listenTo( element, 'focus', () => this._focus( element ), { useCapture: true } );
@@ -94,7 +94,7 @@ export default class FocusManager {
 	}
 
 	/**
-	 * Stores currently focused element and set {utils.FocusManager#isFocused} as `true`.
+	 * Stores currently focused element and set {utils.FocusTracker#isFocused} as `true`.
 	 *
 	 * @private
 	 * @param {HTMLElement} element Element which has been focused.
@@ -107,11 +107,11 @@ export default class FocusManager {
 	}
 
 	/**
-	 * Clears currently focused element and set {utils.FocusManager#isFocused} as `false`.
+	 * Clears currently focused element and set {utils.FocusTracker#isFocused} as `false`.
 	 * This method uses `setTimeout` to change order of fires `blur` and `focus` events.
 	 *
 	 * @private
-	 * @fires utils.FocusManager#blur
+	 * @fires utils.FocusTracker#blur
 	 */
 	_blur() {
 		this._nextEventLoopTimeout = setTimeout( () => {
@@ -121,5 +121,5 @@ export default class FocusManager {
 	}
 }
 
-mix( FocusManager, DOMEmitterMixin );
-mix( FocusManager, ObservableMixin );
+mix( FocusTracker, DOMEmitterMixin );
+mix( FocusTracker, ObservableMixin );

+ 34 - 34
packages/ckeditor5-utils/tests/focusmanager.js

@@ -5,14 +5,14 @@
 
 /* global document */
 
-import FocusManager from '/ckeditor5/utils/focusmanager.js';
+import FocusTracker from '/ckeditor5/utils/focustracker.js';
 import CKEditorError from '/ckeditor5/utils/ckeditorerror.js';
 import testUtils from '/tests/core/_utils/utils.js';
 
 testUtils.createSinonSandbox();
 
-describe( 'FocusManager', () => {
-	let focusManager, container, containerFirstInput, containerSecondInput, inputOuOfContainer;
+describe( 'FocusTracker', () => {
+	let focusTracker, container, containerFirstInput, containerSecondInput, inputOuOfContainer;
 
 	beforeEach( () => {
 		container = document.createElement( 'div' );
@@ -27,7 +27,7 @@ describe( 'FocusManager', () => {
 
 		testUtils.sinon.useFakeTimers();
 
-		focusManager = new FocusManager();
+		focusTracker = new FocusTracker();
 	} );
 
 	afterEach( () => {
@@ -38,15 +38,15 @@ describe( 'FocusManager', () => {
 	describe( 'constructor', () => {
 		describe( 'isFocused', () => {
 			it( 'should be false at default', () => {
-				expect( focusManager.isFocused ).to.false;
+				expect( focusTracker.isFocused ).to.false;
 			} );
 
 			it( 'should be observable', () => {
 				const observableSpy = testUtils.sinon.spy();
 
-				focusManager.listenTo( focusManager, 'change:isFocused', observableSpy );
+				focusTracker.listenTo( focusTracker, 'change:isFocused', observableSpy );
 
-				focusManager.isFocused = true;
+				focusTracker.isFocused = true;
 
 				expect( observableSpy.calledOnce ).to.true;
 			} );
@@ -55,77 +55,77 @@ describe( 'FocusManager', () => {
 
 	describe( 'add', () => {
 		it( 'should throw an error when element has been already added', () => {
-			focusManager.add( containerFirstInput );
+			focusTracker.add( containerFirstInput );
 
 			expect( () => {
-				focusManager.add( containerFirstInput );
-			} ).to.throw( CKEditorError, /focusManager-add-element-already-exist/ );
+				focusTracker.add( containerFirstInput );
+			} ).to.throw( CKEditorError, /focusTracker-add-element-already-exist/ );
 		} );
 
 		describe( 'single element', () => {
 			it( 'should start listening on element focus and update `isFocused` property', () => {
-				focusManager.add( containerFirstInput );
+				focusTracker.add( containerFirstInput );
 
-				expect( focusManager.isFocused ).to.false;
+				expect( focusTracker.isFocused ).to.false;
 
 				containerFirstInput.focus();
 
-				expect( focusManager.isFocused ).to.true;
+				expect( focusTracker.isFocused ).to.true;
 			} );
 
 			it( 'should start listening on element blur and update `isFocused` property', () => {
-				focusManager.add( containerFirstInput );
+				focusTracker.add( containerFirstInput );
 
 				containerFirstInput.focus();
 
-				expect( focusManager.isFocused ).to.true;
+				expect( focusTracker.isFocused ).to.true;
 
 				containerSecondInput.focus();
 				testUtils.sinon.clock.tick( 0 );
 
-				expect( focusManager.isFocused ).to.false;
+				expect( focusTracker.isFocused ).to.false;
 			} );
 		} );
 
 		describe( 'container element', () => {
 			it( 'should start listening on element focus using event capturing and update `isFocused` property', () => {
-				focusManager.add( container );
+				focusTracker.add( container );
 
-				expect( focusManager.isFocused ).to.false;
+				expect( focusTracker.isFocused ).to.false;
 
 				containerFirstInput.focus();
 
-				expect( focusManager.isFocused ).to.true;
+				expect( focusTracker.isFocused ).to.true;
 			} );
 
 			it( 'should start listening on element blur using event capturing and update `isFocused` property', () => {
-				focusManager.add( container );
+				focusTracker.add( container );
 
 				containerFirstInput.focus();
 
-				expect( focusManager.isFocused ).to.true;
+				expect( focusTracker.isFocused ).to.true;
 
 				inputOuOfContainer.focus();
 				testUtils.sinon.clock.tick( 0 );
 
-				expect( focusManager.isFocused ).to.false;
+				expect( focusTracker.isFocused ).to.false;
 			} );
 
 			it( 'should not change `isFocused` property when focus is going between child elements', () => {
 				const changeSpy = testUtils.sinon.spy();
 
-				focusManager.add( container );
+				focusTracker.add( container );
 
 				containerFirstInput.focus();
 
-				focusManager.listenTo( focusManager, 'change:isFocused', changeSpy );
+				focusTracker.listenTo( focusTracker, 'change:isFocused', changeSpy );
 
-				expect( focusManager.isFocused ).to.true;
+				expect( focusTracker.isFocused ).to.true;
 
 				containerSecondInput.focus();
 				testUtils.sinon.clock.tick( 0 );
 
-				expect( focusManager.isFocused ).to.true;
+				expect( focusTracker.isFocused ).to.true;
 				expect( changeSpy.notCalled ).to.true;
 			} );
 		} );
@@ -134,29 +134,29 @@ describe( 'FocusManager', () => {
 	describe( 'remove', () => {
 		it( 'should do nothing when element was not added', () => {
 			expect( () => {
-				focusManager.remove( container );
+				focusTracker.remove( container );
 			} ).to.not.throw();
 		} );
 
 		it( 'should stop listening on element focus and update `isFocused` property', () => {
-			focusManager.add( containerFirstInput );
-			focusManager.remove( containerFirstInput );
+			focusTracker.add( containerFirstInput );
+			focusTracker.remove( containerFirstInput );
 
 			containerFirstInput.focus();
 
-			expect( focusManager.isFocused ).to.false;
+			expect( focusTracker.isFocused ).to.false;
 		} );
 
 		it( 'should blur element before removing when is focused', () => {
-			focusManager.add( containerFirstInput );
+			focusTracker.add( containerFirstInput );
 			containerFirstInput.focus();
 
-			expect( focusManager.isFocused ).to.true;
+			expect( focusTracker.isFocused ).to.true;
 
-			focusManager.remove( containerFirstInput );
+			focusTracker.remove( containerFirstInput );
 			testUtils.sinon.clock.tick( 0 );
 
-			expect( focusManager.isFocused ).to.false;
+			expect( focusTracker.isFocused ).to.false;
 		} );
 	} );
 } );