<commit_before>;'use strict';

// The base Pushpop object.
var Pushpop = window['Pushpop'] || {};

/**
  Creates a new ModalViewStack.
  @param {HTMLDivElement} element The DIV element to initialize as a new ModalViewStack.
  @constructor
  @extends Pushpop.ViewStack
*/
Pushpop.ModalViewStack = function ModalViewStack(element) {
  
  // Call the "super" constructor.
  Pushpop.ViewStack.prototype.constructor.apply(this, arguments);
  
  var $element = this.$element;
  
  // Insert the backdrop element after the modal view stack element.
  var $backdrop = $('<div class="pp-modal-view-stack-backdrop"/>').insertAfter($element);
  
  // Initialize the modal view stack's presentation style based on the element's CSS classes.
  var presentationStyles = Pushpop.ModalViewStack.PresentationStyleType, didInitPresentationStyle = false;
  for (var presentationStyle in presentationStyles) {
    if ($element.hasClass('pp-modal-presentation-style-' + presentationStyles[presentationStyle])) {
      this.setPresentationStyle(presentationStyles[presentationStyle]);
      didInitPresentationStyle = true;
      break;
    }
  }
  
  // Set the modal view stack's presentation style to the default if one was not specified.
  if (!didInitPresentationStyle) this.setPresentationStyle(this.constructor.prototype._presentationStyle);
  
  // Initialize the modal view stack's transition style based on the element's CSS classes.
  var transitionStyles = Pushpop.ModalViewStack.TransitionStyleType, didInitTransitionStyle = false;
  for (var transitionStyle in transitionStyles) {
    if ($element.hasClass('pp-modal-transition-style-' + transitionStyles[transitionStyle])) {
      this.setTransitionStyle(transitionStyles[transitionStyle]);
      didInitTransitionStyle = true;
      break;
    }
  }
  
  // Set the modal view stack's transition style to the default if one was not specified.
  if (!didInitTransitionStyle) this.setTransitionStyle(this.constructor.prototype._transitionStyle);
  
  // Make the modal view stack visible if it is initialized with the .pp-active CSS class.
  this.setHidden(!$element.hasClass('pp-active'));
};

/**
  Presentation styles available when presenting a Pushpop.ModalViewStack.
*/
Pushpop.ModalViewStack.PresentationStyleType = {
  FullScreen: 'full-screen',  // 100% x 100%
  PageSheet: 'page-sheet',    // 768px x 100%
  FormSheet: 'form-sheet'     // 540px x 620px
};

/**
  Transition styles available when presenting a Pushpop.ModalViewStack.
*/
Pushpop.ModalViewStack.TransitionStyleType = {
  CoverVertical: 'cover-vertical'
};

// Create the prototype for the Pushpop.ModalViewStack as a "sub-class" of Pushpop.ViewStack.
Pushpop.ModalViewStack.prototype = new Pushpop.ViewStack();
Pushpop.ModalViewStack.prototype.constructor = Pushpop.ModalViewStack;

/**
  Pushes the specified view to the view stack using the optionally specified transition. If a
  transition is not specified, the default will be used. A callback may optionally be provided
  to be called after the transition completes. In the case of a Pushpop.ModalViewStack, the
  modal view stack will first be presented if it is currently hidden.
  @description This method overrides the default implementation of Pushpop.ViewStack to present
  the modal view stack if it is hidden. After presenting the modal view stack (if needed), the
  "super" implementation of this method is then executed.
  @param {Pushpop.View} view The view to be pushed to the view stack.
  @param {String|Function} [transitionOrCallback] Either the name of the transition to use when
  pushing the view or a callback function to be executed upon completion of the default transition.
  If this parameter is omitted, the default transition is used.
  @param {Function} [callback] A callback function to be executed upon completion of the specified
  transition.
*/
Pushpop.ModalViewStack.prototype.push = function(view, transitionOrCallback, callback) {
  if (this.getHidden()) this.present();
  
  // Call the "super" method.
  Pushpop.ViewStack.prototype.push.apply(this, arguments);
};

/**
  Pops the current or specified view off the view stack using the optionally specified transition.
  If a view is not specified, the current view will be popped (unless it is the root view). If a 
  transition is not specified, the default will be used. A callback may optionally be provided to
  be called after the transition completes. In the case of a Pushpop.ModalViewStack, the modal
  view stack will be dismissed if this method is called when there is only one remaining view on
  the view stack (e.g.: the "root" view) and no view is specified.
  @description This method overrides the default implementation of Pushpop.ViewStack to dismiss
  the modal view stack if there is only one remaining view on the view stack and no view is
  specified. After dismissing the modal view stack (if needed), the "super" implementation of this
  method is then executed.
  @param {Pushpop.View|String} viewOrTransition Either the view to be popped to on the view stack
  or the name of the transition to use when popping the view. If this parameter is omitted or if
  it specifies a transition name, the current view will be assumed to be popped.
  @param {String|Function} [transitionOrCallback] Either the name of the transition to use when
  popping the view or a callback function to be executed upon completion of the default transition.
  If this parameter is omitted, the default transition is used.
  @param {Function} [callback] A callback function to be executed upon completion of the specified
  transition.
*/
Pushpop.ModalViewStack.prototype.pop = function(viewOrTransition, transitionOrCallback, callback) {
  if (this.views.length <= 1) this.dismiss();
  
  // Call the "super" method.
  Pushpop.ViewStack.prototype.pop.apply(this, arguments);
};

Pushpop.ModalViewStack.prototype._hidden = true;

/**
  Returns a flag indicating if this modal view stack is hidden.
  @type Boolean
*/
Pushpop.ModalViewStack.prototype.getHidden = function() { return this._hidden; };

/**
  Sets a flag indicating if this modal view stack should be hidden.
  @param {Boolean} hidden A flag indicating if this modal view stack should be hidden.
*/
Pushpop.ModalViewStack.prototype.setHidden = function(hidden) { if (hidden) this.dismiss(); else this.present(); };

/**
  Presents this modal view stack and transitions it to a visible state.
*/
Pushpop.ModalViewStack.prototype.present = function() { this._hidden = false; this.$element.addClass('pp-active'); };

/**
  Dismisses this modal view stack and transitions it to a hidden state.
*/
Pushpop.ModalViewStack.prototype.dismiss = function() { this._hidden = true; this.$element.removeClass('pp-active'); };

Pushpop.ModalViewStack.prototype._presentationStyle = Pushpop.ModalViewStack.PresentationStyleType.FormSheet;<commit_msg>Fixed bug where present/dismiss events were not fired for the last active view when presenting/dismissing a modal.<commit_after>;'use strict';

// The base Pushpop object.
var Pushpop = window['Pushpop'] || {};

/**
  Creates a new ModalViewStack.
  @param {HTMLDivElement} element The DIV element to initialize as a new ModalViewStack.
  @constructor
  @extends Pushpop.ViewStack
*/
Pushpop.ModalViewStack = function ModalViewStack(element) {
  
  // Call the "super" constructor.
  Pushpop.ViewStack.prototype.constructor.apply(this, arguments);
  
  var $element = this.$element;
  
  // Insert the backdrop element after the modal view stack element.
  var $backdrop = $('<div class="pp-modal-view-stack-backdrop"/>').insertAfter($element);
  
  // Initialize the modal view stack's presentation style based on the element's CSS classes.
  var presentationStyles = Pushpop.ModalViewStack.PresentationStyleType, didInitPresentationStyle = false;
  for (var presentationStyle in presentationStyles) {
    if ($element.hasClass('pp-modal-presentation-style-' + presentationStyles[presentationStyle])) {
      this.setPresentationStyle(presentationStyles[presentationStyle]);
      didInitPresentationStyle = true;
      break;
    }
  }
  
  // Set the modal view stack's presentation style to the default if one was not specified.
  if (!didInitPresentationStyle) this.setPresentationStyle(this.constructor.prototype._presentationStyle);
  
  // Initialize the modal view stack's transition style based on the element's CSS classes.
  var transitionStyles = Pushpop.ModalViewStack.TransitionStyleType, didInitTransitionStyle = false;
  for (var transitionStyle in transitionStyles) {
    if ($element.hasClass('pp-modal-transition-style-' + transitionStyles[transitionStyle])) {
      this.setTransitionStyle(transitionStyles[transitionStyle]);
      didInitTransitionStyle = true;
      break;
    }
  }
  
  // Set the modal view stack's transition style to the default if one was not specified.
  if (!didInitTransitionStyle) this.setTransitionStyle(this.constructor.prototype._transitionStyle);
  
  // Make the modal view stack visible if it is initialized with the .pp-active CSS class.
  this.setHidden(!$element.hasClass('pp-active'));
};

/**
  Presentation styles available when presenting a Pushpop.ModalViewStack.
*/
Pushpop.ModalViewStack.PresentationStyleType = {
  FullScreen: 'full-screen',  // 100% x 100%
  PageSheet: 'page-sheet',    // 768px x 100%
  FormSheet: 'form-sheet'     // 540px x 620px
};

/**
  Transition styles available when presenting a Pushpop.ModalViewStack.
*/
Pushpop.ModalViewStack.TransitionStyleType = {
  CoverVertical: 'cover-vertical'
};

// Create the prototype for the Pushpop.ModalViewStack as a "sub-class" of Pushpop.ViewStack.
Pushpop.ModalViewStack.prototype = new Pushpop.ViewStack();
Pushpop.ModalViewStack.prototype.constructor = Pushpop.ModalViewStack;

/**
  Pushes the specified view to the view stack using the optionally specified transition. If a
  transition is not specified, the default will be used. A callback may optionally be provided
  to be called after the transition completes. In the case of a Pushpop.ModalViewStack, the
  modal view stack will first be presented if it is currently hidden.
  @description This method overrides the default implementation of Pushpop.ViewStack to present
  the modal view stack if it is hidden. After presenting the modal view stack (if needed), the
  "super" implementation of this method is then executed.
  @param {Pushpop.View} view The view to be pushed to the view stack.
  @param {String|Function} [transitionOrCallback] Either the name of the transition to use when
  pushing the view or a callback function to be executed upon completion of the default transition.
  If this parameter is omitted, the default transition is used.
  @param {Function} [callback] A callback function to be executed upon completion of the specified
  transition.
*/
Pushpop.ModalViewStack.prototype.push = function(view, transitionOrCallback, callback) {
  if (this.getHidden()) {
    var activeView = this.getActiveView();
    activeView.$trigger($.Event(Pushpop.EventType.WillPresentView, {
      view: activeView,
      action: 'modal-push'
    }));
    
    this.present();
    
    activeView.$trigger($.Event(Pushpop.EventType.DidPresentView, {
      view: activeView,
      action: 'modal-push'
    }));
  }
  
  // Call the "super" method.
  Pushpop.ViewStack.prototype.push.apply(this, arguments);
};

/**
  Pops the current or specified view off the view stack using the optionally specified transition.
  If a view is not specified, the current view will be popped (unless it is the root view). If a 
  transition is not specified, the default will be used. A callback may optionally be provided to
  be called after the transition completes. In the case of a Pushpop.ModalViewStack, the modal
  view stack will be dismissed if this method is called when there is only one remaining view on
  the view stack (e.g.: the "root" view) and no view is specified.
  @description This method overrides the default implementation of Pushpop.ViewStack to dismiss
  the modal view stack if there is only one remaining view on the view stack and no view is
  specified. After dismissing the modal view stack (if needed), the "super" implementation of this
  method is then executed.
  @param {Pushpop.View|String} viewOrTransition Either the view to be popped to on the view stack
  or the name of the transition to use when popping the view. If this parameter is omitted or if
  it specifies a transition name, the current view will be assumed to be popped.
  @param {String|Function} [transitionOrCallback] Either the name of the transition to use when
  popping the view or a callback function to be executed upon completion of the default transition.
  If this parameter is omitted, the default transition is used.
  @param {Function} [callback] A callback function to be executed upon completion of the specified
  transition.
*/
Pushpop.ModalViewStack.prototype.pop = function(viewOrTransition, transitionOrCallback, callback) {
  if (this.views.length <= 1) {
    var activeView = this.getActiveView();
    activeView.$trigger($.Event(Pushpop.EventType.WillDismissView, {
      view: activeView,
      action: 'modal-push'
    }));
    
    this.dismiss();
    
    activeView.$trigger($.Event(Pushpop.EventType.DidDismissView, {
      view: activeView,
      action: 'modal-push'
    }));
  }
  
  // Call the "super" method.
  Pushpop.ViewStack.prototype.pop.apply(this, arguments);
};

Pushpop.ModalViewStack.prototype._hidden = true;

/**
  Returns a flag indicating if this modal view stack is hidden.
  @type Boolean
*/
Pushpop.ModalViewStack.prototype.getHidden = function() { return this._hidden; };

/**
  Sets a flag indicating if this modal view stack should be hidden.
  @param {Boolean} hidden A flag indicating if this modal view stack should be hidden.
*/
Pushpop.ModalViewStack.prototype.setHidden = function(hidden) { if (hidden) this.dismiss(); else this.present(); };

/**
  Presents this modal view stack and transitions it to a visible state.
*/
Pushpop.ModalViewStack.prototype.present = function() { this._hidden = false; this.$element.addClass('pp-active'); };

/**
  Dismisses this modal view stack and transitions it to a hidden state.
*/
Pushpop.ModalViewStack.prototype.dismiss = function() { this._hidden = true; this.$element.removeClass('pp-active'); };

Pushpop.ModalViewStack.prototype._presentationStyle = Pushpop.ModalViewStack.PresentationStyleType.FormSheet;
{'fraction_non_alphanumeric': 0.08433068142511242, 'fraction_numerical': 0.0026288481494292633, 'mean_word_length': 4.260553129548763, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5708026', 'n_tokens_mistral': 3882, 'n_tokens_neox': 3760, 'n_words': 1501}