123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
"use strict";
modulum('PageWidget', ['WidgetGroupBase'],
function(context, cls) {
cls.PageWidget = context.oo.Class(cls.WidgetGroupBase, function($super) {
return {
__name: "PageWidget",
_title: null,
_clickHandler: null,
_onActivationHandler: null,
_pageActivateHandler: null,
_pageDisableHandler: null,
_initElement: function() {
$super._initElement.call(this);
this._title = cls.WidgetFactory.createWidget("PageTitle", this.getBuildParameters());
this._clickHandler = this._title.when(context.constants.widgetEvents.click, function(event) {
var folderWidget = this.getParentWidget();
if (folderWidget) {
folderWidget.onTitleClick(this);
this.emit(context.constants.widgetEvents.click, event);
}
}.bind(this));
this._onActivationHandler = this.when(context.constants.widgetEvents.ready, this._onActivation.bind(this));
this.setAriaAttribute("labelledby", this._title.getRootClassName());
},
_initLayout: function() {
this._layoutInformation = new cls.PageLayoutInformation(this);
this._layoutEngine = new cls.PageLayoutEngine(this);
},
destroy: function() {
if (this._pageActivateHandler) {
this._pageActivateHandler();
this._pageActivateHandler = null;
}
if (this._pageDisableHandler) {
this._pageDisableHandler();
this._pageDisableHandler = null;
}
if (this._onActivationHandler) {
this._onActivationHandler();
this._onActivationHandler = null;
}
if (this._clickHandler) {
this._clickHandler();
this._clickHandler = null;
}
this._title.destroy();
this._title = null;
$super.destroy.call(this);
},
activate: function() {
this.emit(context.constants.widgetEvents.activate, this);
},
onActivate: function(hook) {
return this.when(context.constants.widgetEvents.activate, hook);
},
disable: function() {
this.emit(context.constants.widgetEvents.disable);
},
onDisable: function(hook) {
return this.when(context.constants.widgetEvents.disable, hook);
},
_onActivation: function(event, widget, parentPageWidget) {
if (parentPageWidget) {
this._pageActivateHandler = parentPageWidget.onActivate(this.activate.bind(this));
this._pageDisableHandler = parentPageWidget.onDisable(this.disable.bind(this));
}
},
getPageIndex: function() {
var parent = this.getParentWidget();
if (parent) {
return parent.getChildren().indexOf(this);
}
return -1;
},
getTitleWidget: function() {
return this._title;
},
addChildWidget: function(widget, options) {
if (this._children.length !== 0) {
throw "A page can only contain a single child";
}
$super.addChildWidget.call(this, widget, options);
},
setText: function(text) {
this._title.setText(text);
},
getText: function() {
return this._title.getText();
},
setTitle: function(title) {
this._title.setTitle(title);
},
getTitle: function() {
return this._title.getTitle();
},
setImage: function(image) {
this._title.setImage(image);
},
getImage: function() {
return this._title.getImage();
},
setHidden: function(hidden) {
var folderWidget = this.getParentWidget();
if (this._hidden !== hidden) {
folderWidget.emit(context.constants.widgetEvents.pageVisibility);
}
var visiblePageCount = folderWidget.getVisiblePageCount();
$super.setHidden.call(this, hidden);
this._title.setHidden(hidden);
if (folderWidget.getCurrentPage() === this && this.isHidden()) {
folderWidget.updateCurrentPage();
} else if (visiblePageCount === 0 && !hidden) {
folderWidget.setCurrentPage(this);
}
},
addPageInDom: function() {
if (this._replacerElement && this._replacerElement.parentNode) {
this._replacerElement.parentNode.replaceChild(this.getElement(), this._replacerElement);
}
},
removePageFromDom: function() {
if (!this._replacerElement) {
this._replacerElement = document.createElement("div");
this._replacerElement.setAttribute("tabindex", "0");
}
if (this.getElement() && this.getElement().parentNode) {
this.getElement().parentNode.replaceChild(this._replacerElement, this.getElement());
}
},
isVisible: function() {
return this.getParentWidget().getCurrentPage() === this && !this.isHidden();
},
isLayoutMeasureable: function(deep) {
return true;
}
};
});
cls.WidgetFactory.registerBuilder('Page', cls.PageWidget);
});