<commit_before>(function(ionic) {

ionic.controllers.NavController = function(opts) {
  var _this = this;

  this.navBar = opts.navBar;
  this.content = opts.content;
  this.controllers = opts.controllers || [];

  this._updateNavBar();

  // TODO: Is this the best way?
  this.navBar.shouldGoBack = function() {
    _this.pop();
  }
};

ionic.controllers.NavController.prototype = {
  getControllers: function() {
    return this.controllers;
  },
  getTopController: function() {
    return this.controllers[this.controllers.length-1];
  },
  push: function(controller) {
    var last = this.controllers[this.controllers.length - 1];

    this.controllers.push(controller);

    // Indicate we are switching controllers
    var shouldSwitch = this.switchingController && this.switchingController(controller) || true;

    // Return if navigation cancelled
    if(shouldSwitch === false)
      return;

    // Actually switch the active controllers

    // Remove the old one
    //last && last.detach();
    if(last) {
      last.isVisible = false;
      last.visibilityChanged && last.visibilityChanged();
    }

    // Grab the top controller on the stack
    var next = this.controllers[this.controllers.length - 1];

    // TODO: No DOM stuff here
    //this.content.el.appendChild(next.el);
    next.isVisible = true;
    next.visibilityChanged && next.visibilityChanged();

    this._updateNavBar();

    return controller;
  },

  pop: function() {
    var next, last;

    // Make sure we keep one on the stack at all times
    if(this.controllers.length < 2) {
      return;
    }

    // Grab the controller behind the top one on the stack
    last = this.controllers.pop();
    if(last) {
      last.isVisible = false;
      last.visibilityChanged && last.visibilityChanged();
    }
    
    // Remove the old one
    //last && last.detach();

    next = this.controllers[this.controllers.length - 1];

    // TODO: No DOM stuff here
    //this.content.el.appendChild(next.el);
    next.isVisible = true;
    next.visibilityChanged && next.visibilityChanged();

    // Switch to it (TODO: Animate or such things here)

    this._updateNavBar();

    return last;
  },

  _updateNavBar: function() {
    if(!this.getTopController()) {
      return;
    }

    this.navBar.setTitle(this.getTopController().title);

    if(this.controllers.length > 1) {
      this.navBar.showBackButton(true);
    } else {
      this.navBar.showBackButton(false);
    }
  },

};
})(window.ionic);<commit_msg>NavController comments<commit_after>(function(ionic) {

/**
 * The NavController makes it easy to have a stack
 * of views or screens that can be pushed and popped
 * for a dynamic navigation flow. This API is modelled
 * off of the UINavigationController in iOS.
 *
 * The NavController can drive a nav bar to show a back button
 * if the stack can be poppped to go back to the last view, and
 * it will handle updating the title of the nav bar and processing animations.
 */
ionic.controllers.NavController = function(opts) {
  var _this = this;

  this.navBar = opts.navBar;
  this.content = opts.content;
  this.controllers = opts.controllers || [];

  this._updateNavBar();

  // TODO: Is this the best way?
  this.navBar.shouldGoBack = function() {
    _this.pop();
  }
};

ionic.controllers.NavController.prototype = {
  /**
   * @return {array} the array of controllers on the stack.
   */
  getControllers: function() {
    return this.controllers;
  },

  /**
   * @return {object} the controller at the top of the stack.
   */
  getTopController: function() {
    return this.controllers[this.controllers.length-1];
  },

  /**
   * Push a new controller onto the navigation stack. The new controller
   * will automatically become the new visible view.
   *
   * @param {object} controller the controller to push on the stack.
   */
  push: function(controller) {
    var last = this.controllers[this.controllers.length - 1];

    this.controllers.push(controller);

    // Indicate we are switching controllers
    var shouldSwitch = this.switchingController && this.switchingController(controller) || true;

    // Return if navigation cancelled
    if(shouldSwitch === false)
      return;

    // Actually switch the active controllers

    // Remove the old one
    //last && last.detach();
    if(last) {
      last.isVisible = false;
      last.visibilityChanged && last.visibilityChanged();
    }

    // Grab the top controller on the stack
    var next = this.controllers[this.controllers.length - 1];

    // TODO: No DOM stuff here
    //this.content.el.appendChild(next.el);
    next.isVisible = true;
    next.visibilityChanged && next.visibilityChanged();

    this._updateNavBar();

    return controller;
  },

  /**
   * Pop the top controller off the stack, and show the last one. This is the
   * "back" operation.
   *
   * @return {object} the last popped controller
   */
  pop: function() {
    var next, last;

    // Make sure we keep one on the stack at all times
    if(this.controllers.length < 2) {
      return;
    }

    // Grab the controller behind the top one on the stack
    last = this.controllers.pop();
    if(last) {
      last.isVisible = false;
      last.visibilityChanged && last.visibilityChanged();
    }
    
    // Remove the old one
    //last && last.detach();

    next = this.controllers[this.controllers.length - 1];

    // TODO: No DOM stuff here
    //this.content.el.appendChild(next.el);
    next.isVisible = true;
    next.visibilityChanged && next.visibilityChanged();

    // Switch to it (TODO: Animate or such things here)

    this._updateNavBar();

    return last;
  },

  // Update the nav bar after a push or pop
  _updateNavBar: function() {
    if(!this.getTopController() || !this.navBar) {
      return;
    }

    this.navBar.setTitle(this.getTopController().title);

    if(this.controllers.length > 1) {
      this.navBar.showBackButton(true);
    } else {
      this.navBar.showBackButton(false);
    }
  }
};
})(window.ionic);
{'fraction_non_alphanumeric': 0.11895663731516863, 'fraction_numerical': 0.001993686658913441, 'mean_word_length': 2.7957124842370744, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4416880', 'n_tokens_mistral': 1843, 'n_tokens_neox': 1745, 'n_words': 499}