TabNavigationController.js

Summary

No overview generated for 'TabNavigationController.js'


Class Summary
TKTabNavigationController  

/**
 *  Copyright © 2009 Apple Inc.  All rights reserved.
 *
 *  @class
 **/
 
 
const TKTabNavigationControllerDidSelectTab = 'tabNavigationControllerDidSelectTab';  

TKTabNavigationController.inherits = TKController;
TKTabNavigationController.synthetizes = ['selectedIndex'];

function TKTabNavigationController (data) {
  this.delegate = null;
  this.tabs = null;
  this._selectedIndex = -1;
  this.callSuper(data);
};

/* ==================== Additional View Processing ==================== */

TKTabNavigationController.prototype.processView = function () {
  this.callSuper();
  // process tabs and add to navigation list
  for (var i = 0; i < this.tabs.length; i++) {
    var tab = this.tabs[i];
    tab._tabIndex = i;
    tab.addEventListener('highlight', this, false);
    tab.addEventListener('unhighlight', this, false);
    tab.addEventListener('click', this, false);
    this.addKeyboardElement(tab);
  }
  this.selectedIndex = 0;
};

/* ==================== Keyboard Handling ==================== */

TKTabNavigationController.prototype.handleEvent = function (event) {
  this.callSuper(event);
  //
  if (event.currentTarget._tabIndex !== undefined) {
    if (event.type == 'highlight') {
      this.selectedIndex = event.currentTarget._tabIndex;
      if (!SUPPORTS_KEYBOARD_NAVIGATION) {
        event.currentTarget.addClassName(TKControllerHighlightCSSClass);
      }
    }
    else if (event.type == 'unhighlight') {
      if (!SUPPORTS_KEYBOARD_NAVIGATION) {
        event.currentTarget.removeClassName(TKControllerHighlightCSSClass);
      }
    }
  }
};

TKTabNavigationController.prototype.elementWasActivated = function (element) {
  this.callSuper(element);
  if (event.currentTarget._tabIndex !== undefined) {
    this.highlightElement(element);
  }
};

/* ==================== Controllers ==================== */

TKTabNavigationController.prototype.setSelectedIndex = function (index) {
  if (this._selectedIndex == index) {
    return;
  }
  //
  if (index >= 0 && index < this.tabs.length) {
    this._selectedIndex = index;
    this.highlightElement(this.tabs[index]);
    if (TKUtils.objectHasMethod(this.delegate, TKTabNavigationControllerDidSelectTab)) {
      this.delegate[TKTabNavigationControllerDidSelectTab](this, index);
    }
  }
};

TKClass(TKTabNavigationController);


Documentation generated by JSDoc on Tue Sep 15 21:24:36 2009