PageSliderController.js
Summary
No overview generated for 'PageSliderController.js'
const TKPageSliderControllerContainerCSSClass = 'tk-page-slider-controller-view';
TKPageSliderController.inherits = TKController;
TKPageSliderController.synthetizes = ['slidingViewData', 'pageControlData', 'sliderHasHighlight'];
function TKPageSliderController (data) {
this.previousPageButton = null;
this.nextPageButton = null;
this.slidingView = new TKSlidingView();
this.slidingView.delegate = this;
this.pageControl = new TKPageControl();
this.pageControl.delegate = this;
this._previousPageButton = null;
this._nextPageButton = null;
this.callSuper(data);
};
TKPageSliderController.prototype.processView = function () {
this.callSuper();
if (this.previousPageButton !== null) {
this._previousPageButton = this.view.querySelector(this.previousPageButton);
if (this._previousPageButton !== null) {
this._previousPageButton.addEventListener('click', this, false);
}
}
if (this.nextPageButton !== null) {
this._nextPageButton = this.view.querySelector(this.nextPageButton);
if (this._nextPageButton !== null) {
this._nextPageButton.addEventListener('click', this, false);
}
}
this.container = this._view.appendChild(document.createElement('div'));
this.container.addClassName(TKPageSliderControllerContainerCSSClass);
this.container.appendChild(this.slidingView.element);
this.container.appendChild(this.pageControl.element);
this.container.addEventListener('highlight', this, false);
this.highlightedElement = this.container;
this.addKeyboardElement(this.container);
this.pageWasHighlighted(0);
this.syncPageButtons();
};
TKPageSliderController.prototype.setSlidingViewData = function (data) {
if (!TKUtils.objectIsUndefined(data.elements)) {
this.slidingView.dataSource = new TKSlidingViewDataSourceHelper(data.elements);
delete data.element;
}
TKUtils.copyPropertiesFromSourceToTarget(data, this.slidingView);
this.slidingView.init();
this.syncPageButtons();
};
TKPageSliderController.prototype.setPageControlData = function (data) {
this.pageControl.dataSource = new TKPageControlDataSourceHelper(data);
TKUtils.copyPropertiesFromSourceToTarget(data, this.pageControl);
this.pageControl.init();
};
TKPageSliderController.prototype.getSliderHasHighlight = function () {
return (this.highlightedElement === this.container);
};
TKPageSliderController.prototype.metricsForElement = function (element) {
if (element !== this.container) {
return this.callSuper(element);
}
var view_metrics = this._view.getBounds();
var union = TKRect.rectFromUnionOfRects([
this.slidingView.element.getBounds(),
this.pageControl.element.getBounds()
]);
union.width = Math.min(union.width, view_metrics.width);
union.height = Math.min(union.width, view_metrics.height);
return union;
};
TKPageSliderController.prototype.wantsToHandleKeyboardEvent = function (event) {
return (this.wantsCustomHandlingOfKeyboardEvent(event) || this.callSuper(event));
};
TKPageSliderController.prototype.wantsCustomHandlingOfKeyboardEvent = function (event) {
var key = event.keyCode;
return (
(key == KEYBOARD_LEFT && (this.slidingView.activeElementIndex > 0 || this.slidingView.loops)) ||
(key == KEYBOARD_RIGHT && (this.slidingView.activeElementIndex < this.slidingView.numberOfElements || this.slidingView.loops)) ||
(key == KEYBOARD_RETURN)
);
};
TKPageSliderController.prototype.handleKeydown = function (event) {
if (!this.wantsCustomHandlingOfKeyboardEvent(event) || !this.sliderHasHighlight) {
this.callSuper(event);
return;
}
switch (event.keyCode) {
case KEYBOARD_RIGHT:
this.slidingView.activeElementIndex++;
break;
case KEYBOARD_LEFT:
this.slidingView.activeElementIndex--;
break;
case KEYBOARD_RETURN:
this.pageWasSelected(this.slidingView.activeElementIndex);
break;
}
};
TKPageSliderController.prototype.handleEvent = function (event) {
this.callSuper(event);
if (event.currentTarget === this._previousPageButton) {
this.slidingView.activeElementIndex--;
}
else if (event.currentTarget === this._nextPageButton) {
this.slidingView.activeElementIndex++;
}
};
TKPageSliderController.prototype.syncPageButtons = function () {
if (this.slidingView.loops) {
return;
}
if (this._previousPageButton !== null) {
this._previousPageButton[(this.slidingView.activeElementIndex <= 0 ? 'add' : 'remove') + 'ClassName']('inactive');
}
if (this._nextPageButton !== null) {
this._nextPageButton[(this.slidingView.activeElementIndex >= this.slidingView.numberOfElements - 1 ? 'add' : 'remove') + 'ClassName']('inactive');
}
};
TKPageSliderController.prototype.slidingViewDidFocusElementAtIndex = function (view, index) {
this.pageControl.currentPage = index;
this.pageWasHighlighted(index);
this.syncPageButtons();
};
TKPageSliderController.prototype.slidingViewDidBlurElementAtIndex = function (view, index) {};
TKPageSliderController.prototype.slidingViewDidSelectActiveElement = function (view, index) {
this.pageWasSelected(index);
};
TKPageSliderController.prototype.slidingViewStyleForItemAtIndex = function (view, index) {
return this.styleForPageAtIndex(index);
};
TKPageSliderController.prototype.slidingViewDidHoverElementAtIndex = function (view, index) {
this.pageWasHovered(index);
};
TKPageSliderController.prototype.slidingViewDidUnhoverElementAtIndex = function (view, index) {
this.pageWasUnhovered(index);
};
TKPageSliderController.prototype.pageWasHighlighted = function (index) {};
TKPageSliderController.prototype.pageWasSelected = function (index) {};
TKPageSliderController.prototype.pageWasHovered = function (index) {};
TKPageSliderController.prototype.pageWasUnhovered = function (index) {};
TKPageSliderController.prototype.styleForPageAtIndex = function (index) {
return [];
};
TKPageSliderController.prototype.pageControlDidUpdateCurrentPage = function (control, newPageIndex) {
this.slidingView.activeElementIndex = newPageIndex;
this.pageControl.updateCurrentPageDisplay();
};
TKClass(TKPageSliderController);
Documentation generated by
JSDoc on Tue Sep 15 21:24:36 2009