NavigationController.js
Summary
No overview generated for 'NavigationController.js'
const TKNavigationControllerWillShowController = 'navigationControllerWillShowController';
const TKNavigationControllerDidShowController = 'navigationControllerDidShowController';
TKNavigationController.inherits = TKController;
TKNavigationController.includes = [TKEventTriage];
TKNavigationController.synthetizes = ['topController'];
TKNavigationController.sharedNavigation = null;
function TKNavigationController (data) {
this.controllers = [];
this.delegate = null;
this.rootController = null;
this.previousController = null;
this.busy = false;
this.callSuper(data);
if (this.rootController !== null) {
this.pushController(this.rootController);
}
if (SUPPORTS_KEYBOARD_NAVIGATION) {
window.addEventListener('keydown', this, true);
}
TKNavigationController.sharedNavigation = this;
};
TKNavigationController.prototype.handleKeydown = function (event) {
if (event.keyCode == KEYBOARD_BACKSPACE) {
this.popController();
event.preventDefault();
return;
}
var top_controller = this.topController;
if (TKUtils.objectHasMethod(top_controller, 'handleKeydown')) {
top_controller.handleKeydown(event);
}
};
TKNavigationController.prototype.getTopController = function () {
return (this.controllers.length > 0) ? this.controllers[this.controllers.length - 1] : null;
};
TKNavigationController.prototype.pushController = function (controller) {
if (this.busy) {
return;
}
TKTransaction.begin();
var previous_controller = this.topController;
var next_view = controller.view;
if (TKUtils.objectHasMethod(this.delegate, TKNavigationControllerWillShowController)) {
this.delegate[TKNavigationControllerWillShowController](this, controller);
}
this.controllers.push(controller);
if (previous_controller !== null) {
previous_controller.viewWillDisappear();
}
controller.viewWillAppear();
this.view.appendChild(controller.view);
if (previous_controller !== null) {
this.transitionToController(previous_controller, controller);
}
else {
this.busy = true;
this.transitionDidComplete();
}
TKTransaction.commit();
};
TKNavigationController.prototype.popController = function () {
if (this.busy || this.controllers.length < 2) {
return;
}
TKTransaction.begin();
if (TKUtils.objectHasMethod(this.delegate, TKNavigationControllerWillShowController)) {
this.delegate[TKNavigationControllerWillShowController](this, this.controllers[this.controllers.length - 2]);
}
var previous_controller = this.controllers.pop();
var top_controller = this.topController;
previous_controller.viewWillDisappear();
top_controller.viewWillAppear();
this.view.appendChild(top_controller.view);
this.transitionToController(previous_controller, top_controller);
TKTransaction.commit();
};
TKNavigationController.prototype.transitionToController = function (previous_controller, top_controller) {
this.busy = true;
this.previousController = previous_controller;
if (previous_controller !== null) {
previous_controller.view.applyTransition(previous_controller.becomesInactiveTransition, false);
}
var top_controller_transition = top_controller.becomesActiveTransition;
top_controller_transition.delegate = this;
top_controller.view.applyTransition(top_controller_transition, false);
};
TKNavigationController.prototype.transitionDidComplete = function (transition) {
if (!this.busy) {
return;
}
if (this.previousController !== null) {
this.view.removeChild(this.previousController.view);
this.previousController.viewDidDisappear();
}
this.topController.viewDidAppear();
if (TKUtils.objectHasMethod(this.delegate, TKNavigationControllerDidShowController)) {
this.delegate[TKNavigationControllerDidShowController](this, this.topController);
}
this.busy = false;
var controller = this.topController;
setTimeout(function () {
TKFocusManager.focusElement(controller.highlightedElement);
}, 0);
};
TKClass(TKNavigationController);
Documentation generated by
JSDoc on Tue Sep 15 21:24:36 2009