123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
"use strict";
modulum('FolderWidget', ['FolderWidgetBase'],
function(context, cls) {
cls.FolderWidget = context.oo.Class(cls.FolderWidgetBase, function($super) {
return {
__name: "FolderWidget",
_tabsTitlesHostElement: null,
_tabsTitlesElement: null,
_tabsPosition: "top",
_scroller: null,
_initLayout: function() {
this._layoutInformation = new cls.FolderLayoutInformation(this);
this._layoutEngine = new cls.FolderLayoutEngine(this);
$super._initLayout.call(this);
},
_initContainerElement: function() {
$super._initContainerElement.call(this);
this._tabsTitlesHostElement = this._element.getElementsByClassName("mt-tab-titles")[0];
this._tabsTitlesElement = this._element.getElementsByClassName("mt-tab-titles-container")[0];
this._scroller = new cls.ScrollTabDecorator(this);
},
destroy: function() {
if (this._scroller) {
this._scroller.destroy();
this._scroller = null;
}
if (this._tabsTitlesHostElement) {
this._tabsTitlesHostElement = null;
}
if (this._tabsTitlesElement) {
this._tabsTitlesElement = null;
}
$super.destroy.call(this);
},
addChildWidget: function(widget, options) {
var pageWidget = widget;
var titleWidget = pageWidget.getTitleWidget();
this._tabsTitlesElement.appendChild(titleWidget.getElement());
$super.addChildWidget.call(this, pageWidget, options);
},
setCurrentPage: function(page, executeAction) {
var modified = $super.setCurrentPage.call(this, page, executeAction);
if (modified) {
this.scrollTo(this._currentPage);
}
return modified;
},
getTabsTitlesHostElement: function() {
return this._tabsTitlesHostElement;
},
getTabsPosition: function() {
return this._tabsPosition;
},
setTabPosition: function(position) {
if (["top", "bottom", "left", "right"].indexOf(position) < 0) {
position = "top";
}
this._element.setAttribute("__FolderWidget", position);
this._scroller.updatePosition("__FolderWidget", position);
this._tabsPosition = position;
},
scrollTo: function(page) {
var title = page && page.getTitleWidget();
if (title) {
this._scroller.scrollTo(title.getElement());
}
this._scroller.refreshScrollers();
},
updateScrollersVisibility: function() {
var isVertical = ["left", "right"].indexOf(this._tabsPosition) >= 0;
var isHorizontal = ["top", "bottom"].indexOf(this._tabsPosition) >= 0;
var sizeAttr = isVertical ? "height" : isHorizontal ? "width" : false;
var info = this.getLayoutInformation();
if (sizeAttr && this._scroller) {
var tabsTitlesSize = this.getChildren().map(function(item) {
return item.isHidden() ? 0 :
item.getLayoutInformation()[isHorizontal ? "getTitleMeasureWidth" : "getTitleMeasureHeight"]();
}).reduce(function(next, prev) {
return next + prev;
}, 0);
var tabsTitlesHostSize = this._getAllocatedSize(isHorizontal) -
info[isHorizontal ? "getTitlesContainerDeltaWidth" : "getTitlesContainerDeltaHeight"]();
if (tabsTitlesHostSize <= tabsTitlesSize) {
this._scroller.showScroller(true);
} else {
this._scroller.showScroller(false);
}
}
},
_getAllocatedSize: function(isHorizontal) {
var info = this.getLayoutInformation();
return info.getAllocated()[isHorizontal ? "getWidth" : "getHeight"]();
}
};
});
cls.WidgetFactory.registerBuilder('Folder', cls.FolderWidget);
});