/**
* Sub-menu base widget.
* @typedef {Object} SubMenuWidget
*/
define('application/widgets/menu/sections/submenu/base', [
'rofl/widgets/container',
'antie/runtimecontext',
'antie/widgets/verticallist',
'rofl/lib/utils',
'application/formatters/menuitem',
'rofl/decorators/pointer'
], function (
Container,
RuntimeContext,
VerticalList,
Utils,
defaultMenuItemFormatter,
PointerDecorator
) {
'use strict';
var application = RuntimeContext.getCurrentApplication(),
DefaultConfig = {
WIDGET_CLASS: 'submenu-list',
VISIBLE_ITEMS: 8,
SCROLL_OFFSET: 3,
SCROLL_DURATION: 250
};
return VerticalList.extend({
_visibleItems: null,
_totalDataItems: null,
_scrollOffset: null,
/**
* Initializes the base menu widget.
*
* @param {Object} opts - The widget opts.
*/
init: function init (opts) {
var id = opts.id,
items = opts.items,
menuItemFormatter = opts.submenuItemFormatter || defaultMenuItemFormatter,
cssClass = opts.cssClass || 'submenu-list';
this._visibleItems = opts.visibleItems || DefaultConfig.VISIBLE_ITEMS;
this._scrollOffset = opts.scrollOffset || DefaultConfig.SCROLL_OFFSET;
this._scrollAnimationDuration = DefaultConfig.SCROLL_DURATION;
this._totalDataItems = items.length;
init.base.call(this, id, new menuItemFormatter(), items);
this.addClass(cssClass);
this.decorate([PointerDecorator]);
},
/**
* Returns if menu can be focused.
*
* @returns {boolean} - Is focusable.
*/
isFocusable: function () {
return Utils.isFunction(application.isMenuAllowed) && application.isMenuAllowed() || true;
},
/**
* Pointer handling needs to be inited after widget is rendered.
*
* @param {Device} device - The current device.
* @returns {Element} - The rendered element.
*/
render: function render (device) {
var outputElement = render.base.call(this, device);
this.initPointerHandlers();
return outputElement;
}
});
});