<commit_before>import Ember from 'ember';

export default Ember.Component.extend({
  spotlightCSS: '',
  started: false,
  firstTourStep: 0,
  currentStopStep: null,
  transitioning: false,

  startTour: (function(){
    if(this.get('started')){
      this.setProperties({
        transitionStop: null,
        currentStop: null
      });
      var startingStep = this.get('firstTourStep') || 0;

      this.set('currentStopStep', startingStep);
      this.notifyPropertyChange('currentStopStep');
    }
  }).observes('started'),

  moreForwardSteps: Ember.computed('currentStopStep', 'sortedTourStops',
    function(){
      return this.get('currentStopStep') + 1 < this.get('sortedTourStops.length');
    }
  ),

  moreBackwardSteps: Ember.computed('currentStopStep',
    function(){
      return this.get('currentStopStep') > 0;
    }
  ),

  currentStopNumber: Ember.computed('currentStopStep', function(){
    return this.get('currentStopNumber') + 1;
  }),

  previousStopStep: null,
  previousStop: null,
  transitionStop: null,
  windowWidth: null,
  windowHeight: null,

  tourStops: Ember.computed.alias('model.tourStops'),
  currentPath: Ember.computed.alias('parentView.controller.currentPath'),

  _routeChange: (function(){
    if(this.get('currentStop') && this.get('started')) {
      Ember.run.scheduleOnce('afterRender', this, this._checkForUserInitiatedTransition);
    }
  }).observes('currentPath'),

  _checkForUserInitiatedTransition: (function(){
    var transitioning = this.get('transitioning');
    var element = this.get('currentStop.element');
    var elementOnPage = $(element);
    if (!transitioning && Ember.isBlank(elementOnPage)) {
      this.exitTour();
    }
  }),

  sortedTourStops: Ember.computed('model',
    function(){
      var model = this.get('model');
      if(model && model.get('tourStops')){
        return model.get('tourStops').sortBy('step');
      }
    }
  ),

  _setTransitionStop: (function(){
    var step = this.get('currentStopStep');
    var transitionStop = this.get('sortedTourStops').objectAt(step);
    this.set('transitionStop', transitionStop);
  }
  ).observes('currentStopStep'),

  _startTourStopTransition: (function(){
    var transitionStop = this.get('transitionStop'),
      currentStop = this.get('currentStop');

    if(currentStop){
      currentStop.set('active', false);
    }

    if(transitionStop) {
      this.set('transitioning', true);

      var previousStop = this.get('previousStop'),
        targetRoute = transitionStop.get('targetRoute'),
        router = this.container.lookup('router:main').router,
        renderedProperty = 'lastRenderedTemplate',
        targetElement = transitionStop.get('element'),
        route;

      var allRoutes = Ember.keys(router.recognizer.names);
      var routeExists = allRoutes.indexOf(targetRoute) !== -1;

      if (routeExists) {
        route = this.container.lookup('route:' + targetRoute);
      }

      var currentRouteDifferent = !previousStop || previousStop.get('targetRoute') !== targetRoute;
      var routePresent = routeExists && route.get(renderedProperty);

      if (routeExists && (!routePresent || currentRouteDifferent)) {
        route.transitionTo(targetRoute);
        if (targetElement) {
          this._finishWhenElementInPage(targetElement);
        } else {
          this._finishTransition();
        }
      } else {
        this._finishTransition();
      }
    }
  }).observes('transitionStop'),

  _finishWhenElementInPage: function(element, waitTime) {
    var component = this;
    if(!(typeof waitTime === "number")){
      waitTime = 5000
    }
    if(!Ember.isBlank($(element))){
      this._finishTransition();
    } else if(waitTime > 0) {
      Ember.run.later(function () {
        component._finishWhenElementInPage(element, waitTime - 20);
      },20);
    } else {
      this.incrementProperty('currentStopStep');
    }
  },

  _finishTransition: function() {
    var transitionStop = this.get('transitionStop'),
      currentStop = this.get('currentStop');

    transitionStop.set('active', true);
    this.setProperties({
      currentStop: transitionStop,
      previousStop: currentStop
    });

    Ember.run.scheduleOnce('afterRender', this, function(){this.set('transitioning', false)});
  },

  currentProgress: Ember.computed('tourStops', 'currentStep', function(){
    return ((this.get('currentStep') + 1) / this.get('tourStops.length')) * 100;
  }),

  /**
   * Initializes a listener to set window height and width;
   *
   * @api private
   * @method _getWinSize
   */

  _windowSize: (function(){
    var component = this;

    component.setProperties({<commit_msg>some documentation for tour<commit_after>import Ember from 'ember';

export default Ember.Component.extend({

  /**
   The CSS properties for the 'spotlight' element over the current target element

   @property spotlightCSS
   @type String
   */

  spotlightCSS: '',

  /**
   Set to true if the tour is running

   @property started
   @type Boolean
   @default false
   */

  started: false,

  /**
   The point at which the tour will start

   @property firstTourStep
   @type Integer
   @default 0
   */

  firstTourStep: 0,

  /**
   The number of the active stop stop

   @property currentStopStep
   @type Integer
   @default null
   */

  currentStopStep: null,

  /**
   Set to true if the tour is between stops

   @property transitioning
   @type Integer
   @default false
   */

  transitioning: false,

  /**
   The previous tour stop

   @property previousStop
   @type previousStop
   @default null
   */

  previousStop: null,

  /**
   When in transition, the stop to which the tour is transitioning

   @property transitionStop
   @type Object
   @default null
   */

  transitionStop: null,

  /**
   The height of the window

   @property windowHeight
   @type Integer
   */

  windowHeight: null,

  /**
   The width of the window

   @property windowWidth
   @type Integer
   */

  windowWidth: null,

  /**
   @property tourStops
   @type Object
   */

  tourStops: Ember.computed.alias('model.tourStops'),

  /**
   The Ember currentPath

   @property currentPath
   @type String
   */

  currentPath: Ember.computed.alias('parentView.controller.currentPath'),

  /**
   Starts the tour when `started` is changed to true
   @private
   @method _startTour
   */

  _startTour: (function(){
    if(this.get('started')){
      this.setProperties({
        transitionStop: null,
        currentStop: null
      });
      var startingStep = this.get('firstTourStep') || 0;

      this.set('currentStopStep', startingStep);
      this.notifyPropertyChange('currentStopStep');
    }
  }).observes('started'),

  /**
   Set to true if there are stops after the `currentStop` in `tourStops`

   @property moreForwardSteps
   @type Boolean
   */

  moreForwardSteps: Ember.computed('currentStopStep', 'sortedTourStops',
    function(){
      return this.get('currentStopStep') + 1 < this.get('sortedTourStops.length');
    }
  ),

  /**
   Set to true if there are stops before the `currentStop` in `tourStops`

   @property moreBackwardStops
   @type Boolean
   */

  moreBackwardSteps: Ember.computed('currentStopStep',
    function(){
      return this.get('currentStopStep') > 0;
    }
  ),

  /**
   When the current path changes, call a check to see if the user changed the path

   @method pathChange
   */

  pathChange: (function(){
    if(this.get('currentStop') && this.get('started')) {
      Ember.run.scheduleOnce('afterRender', this, this._checkForUserInitiatedTransition);
    }
  }).observes('currentPath'),


  /**
   Exits the tour if the user initiated a route change, instead of the tour. Checks to see
   if the target element is still in the page after the transition; if not the tour ends.

   @method checkForUserInitiatedTransition
   */

  checkForUserInitiatedTransition: (function(){
    var transitioning = this.get('transitioning');
    var element = this.get('currentStop.element');
    var elementOnPage = $(element);
    if (!transitioning && Ember.isBlank(elementOnPage)) {
      this.exitTour();
    }
  }),

  /**
   The tour's stops, sorted by the step number

   @property sortedTourStops
   @type Object
   */

  sortedTourStops: Ember.computed('tourStops',
    function(){
      var tourStops = this.get('tourStops');
      if(tourStops && tourStops.get('length')){
        return tourStops.sortBy('step');
      }
    }
  ),

  /**
   When the `currentStopStep` changes, the transitionStop is set to the object at that position.

   @private
   @method _setTransitionStop
   */

  _setTransitionStop: (function(){
      var step = this.get('currentStopStep');
      var transitionStop = this.get('sortedTourStops').objectAt(step);
      this.set('transitionStop', transitionStop);
    }
  ).observes('currentStopStep'),

  _startTourStopTransition: (function(){
    var transitionStop = this.get('transitionStop'),
      currentStop = this.get('currentStop');

    if(currentStop){
      currentStop.set('active', false);
    }

    if(transitionStop) {
      this.set('transitioning', true);

      var previousStop = this.get('previousStop'),
        targetRoute = transitionStop.get('targetRoute'),
        router = this.container.lookup('router:main').router,
        renderedProperty = 'lastRenderedTemplate',
        targetElement = transitionStop.get('element'),
        route;

      var allRoutes = Ember.keys(router.recognizer.names);
      var routeExists = allRoutes.indexOf(targetRoute) !== -1;

      if (routeExists) {
        route = this.container.lookup('route:' + targetRoute);
      }

      var currentRouteDifferent = !previousStop || previousStop.get('targetRoute') !== targetRoute;
      var routePresent = routeExists && route.get(renderedProperty);

      if (routeExists && (!routePresent || currentRouteDifferent)) {
        route.transitionTo(targetRoute);
        if (targetElement) {
          this._finishWhenElementInPage(targetElement);
        } else {
          this._finishTransition();
        }
      } else {
        this._finishTransition();
      }
    }
  }).observes('transitionStop'),

  _finishWhenElementInPage: function(element, waitTime) {
    var component = this;
    if(!(typeof waitTime === "number")){
      waitTime = 5000
    }
    if(!Ember.isBlank($(element))){
      this._finishTransition();
    } else if(waitTime > 0) {
      Ember.run.later(function () {
        component._finishWhenElementInPage(element, waitTime - 20);
      },20);
    } else {
      this.incrementProperty('currentStopStep');
    }
  },

  _finishTransition: function() {
    var transitionStop = this.get('transitionStop'),
      currentStop = this.get('currentStop');

    transitionStop.set('active', true);
    this.setProperties({
      currentStop: transitionStop,
      previousStop: currentStop
    });

    Ember.run.scheduleOnce('afterRender', this, function(){this.set('transitioning', false)});
  },

  currentProgress: Ember.computed('tourStops', 'currentStep', function(){
    return ((this.get('currentStep') + 1) / this.get('tourStops.length')) * 100;
  }),

  /**
   Initializes a listener to track window height and width;

   @private
   @method _windowSize
   */

  _windowSize: (function(){
    var component = this;

    component.setProperties({
{'fraction_non_alphanumeric': 0.1306115235065394, 'fraction_numerical': 0.00335807705903146, 'mean_word_length': 3.2023765317489787, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5188704', 'n_tokens_mistral': 3421, 'n_tokens_neox': 3239, 'n_words': 724}