%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /www/varak.net/wiki.varak.net/extensions/VisualEditor/lib/ve/src/ce/
Upload File :
Create Path :
Current File : /www/varak.net/wiki.varak.net/extensions/VisualEditor/lib/ve/src/ce/ve.ce.KeyDownHandlerFactory.js

/*!
 * VisualEditor KeyDownHandlerFactory class.
 *
 * @copyright 2011-2016 VisualEditor Team and others; see http://ve.mit-license.org
 */

/**
 * Key down handler factory.
 *
 * @class
 * @extends OO.Factory
 * @constructor
 */
ve.ce.KeyDownHandlerFactory = function VeCeKeyDownHandlerFactory() {
	// Parent constructor
	ve.ce.KeyDownHandlerFactory.super.apply( this, arguments );

	// Handlers which match all kinds and a specific type
	this.handlerNamesByKeys = {};
};

/* Inheritance */

OO.inheritClass( ve.ce.KeyDownHandlerFactory, OO.Factory );

/* Methods */

/**
 * @inheritdoc
 */
ve.ce.KeyDownHandlerFactory.prototype.register = function ( constructor ) {
	var i, ilen, keys, name;

	// Parent method
	ve.ce.KeyDownHandlerFactory.super.prototype.register.call( this, constructor );

	keys = constructor.static.keys;
	name = constructor.static.name;

	// TODO: Clean up handlerNamesByKeys in unregister
	for ( i = 0, ilen = keys.length; i < ilen; i++ ) {
		this.handlerNamesByKeys[ keys[ i ] ] = this.handlerNamesByKeys[ keys[ i ] ] || [];
		if ( this.handlerNamesByKeys[ keys[ i ] ].indexOf( name ) === -1 ) {
			this.handlerNamesByKeys[ keys[ i ] ].push( name );
		}
	}
};

/**
 * Get the handler for a specific key
 *
 * @param {number} key Key code
 * @param {string} selectionName Selection type name
 * @return {Function[]} Matched handlers
 */
ve.ce.KeyDownHandlerFactory.prototype.lookupHandlersForKey = function ( key, selectionName ) {
	var i, constructor, supportedSelections,
		constructors = [],
		names = this.handlerNamesByKeys[ key ] || [];

	// Length is likely to be 1 or 0 so don't cache
	for ( i = 0; i < names.length; i++ ) {
		constructor = this.registry[ names[ i ] ];
		supportedSelections = constructor.static.supportedSelections;
		if ( !supportedSelections || supportedSelections.indexOf( selectionName ) !== -1 ) {
			constructors.push( constructor );
		}
	}

	return constructors;
};

/**
 * Execute the handlers for a specific key
 *
 * @param {number} key Key code
 * @param {string} selectionName Selection type name
 * @param {ve.ce.Surface} surface Surface
 * @param {jQuery} e Key down event
 * @return {boolean} Some handlers acted
 */
ve.ce.KeyDownHandlerFactory.prototype.executeHandlersForKey = function ( key, selectionName, surface, e ) {
	var i, acted,
		handlers = this.lookupHandlersForKey( key, selectionName );

	// Length is likely to be 1 or 0 so don't cache
	for ( i = 0; i < handlers.length; i++ ) {
		if ( handlers[ i ].static.execute( surface, e ) ) {
			acted = true;
		}
	}

	return acted;
};

/* Initialization */

ve.ce.keyDownHandlerFactory = new ve.ce.KeyDownHandlerFactory();

Zerion Mini Shell 1.0