define('application/widgets/pointerfocusableasset', [
'rofl/widgets/pointerfocusablebutton',
'rofl/lib/utils',
'rofl/devices/input/pointer',
'application/events/mousefocusevent'
], function (
Base,
Utils,
PointerManager,
MouseFocusEvent
) {
'use strict';
var pointerManager;
return Base.extend({
/**
* Removes the mouse leave handler.
*/
removeMouseLeaveHandler: function removeMouseLeaveHandlerFn () {
if (this.outputElement) {
this.outputElement.onmouseleave = null;
}
},
/**
* Handles the mouse over event.
*/
mouseOverHandler: function mouseOverHandlerFn () {
this._focusTimeout = setTimeout(Utils.bind(this._setFocus, this), 200);
},
/**
* Sets focus for an element and bubles MouseFocusEvent.
*/
_setFocus: function () {
if (pointerManager.pointerIsOn()) {
if (!this.isFocussed() && this.parentWidget) {
this.focus();
this.parentWidget.setActiveChildWidget(this);
this.bubbleEvent(new MouseFocusEvent(this));
}
}
},
/**
* Handles the mouse leave event.
*/
mouseLeaveHandler: function mouseLeaveHandlerFn () {
clearTimeout(this._focusTimeout);
},
/**
* Adds the mouse leave handler.
*/
addMouseLeaveHandler: function addMouseLeaveHandlerFn () {
if (this.outputElement) {
this.outputElement.onmouseleave = Utils
.bind(this.mouseLeaveHandler, this);
}
},
/** Renders the button.
*
* @param {Object} device - Device.
* @returns {Object} DOM node.
*/
render: function renderFn (device) {
var element = renderFn.base.call(this, device);
this.addMouseLeaveHandler();
return element;
},
/**
* Disposes of the button.
*/
dispose: function disposeFn () {
this.removeMouseLeaveHandler();
disposeFn.base.call(this);
},
/**
* Initializes the button.
*
* @param {string} id - Button id.
* @param {boolean} animationEnabled - Animations enabled or not.
*/
init: function initFn (id, animationEnabled) {
if (!pointerManager) {
pointerManager = PointerManager.getInstance();
}
initFn.base.call(this, id, animationEnabled);
}
});
});