<commit_before>/*global angular, Swiper */
'use strict';

function emSwiper($rootScope, emLocation, userPrefix) {
  var initialSlideIndex, initialSubPath, slides, swiper, swipers;
  slides = [];
  swipers = {};

  var slideX, slideY;
  var sw = {};

  return {
    initSwiper: function(container, params) {
      // http://www.idangero.us/sliders/swiper/api.php
      swiper = new Swiper(container, params);
      swipers[swiper.params.mode] = swiper;
      return swiper;
    },
    changePath: function(swiper) {
      var activeSlide, slidePath, slideSubPath;
      activeSlide = swiper.getSlide(swiper.activeIndex);

      if (swiper.params.mode === 'horizontal') {
        if (activeSlide.getData('path')) {
          slidePath = '/' + userPrefix.getPrefix() + '/' + activeSlide.getData('path');
        } else {
          slidePath = '/' + userPrefix.getPrefix();
        }
      } else { // vertical
        slideSubPath = activeSlide.getData('path');
        slidePath = '/' + userPrefix.getPrefix() + '/' + this.getSwiper('horizontal').getSlide(this.getSwiper('horizontal').activeIndex).getData('path') + '/' + slideSubPath;
      }
      emLocation.skipReload().path(slidePath);
      $rootScope.$apply();
    },
    getSwiper: function(mode) {
      return swipers[mode];
    },
    setSlides: function(initialIndex, subPath) {
      initialSubPath = subPath;
      slides = ['inbox', '', 'tasks/dates', 'tasks/projects', 'tasks'];
      initialSlideIndex = initialIndex;
    },
    getSlides: function() {
      return slides;
    },
    setSlideIndex: function(coordX, coordY) {
      swipers.horizontal.swipeTo(coordX);

      sw[coordX].swipeTo(coordY);
    },
    setInitialSlideIndex: function(initialIndex) {
      initialSlideIndex = initialIndex;
    },
    getInitiaSlideIndex: function() {
      return initialSlideIndex;
    },
    setVerticalSwiper: function(coordX) {
      sw[coordX] = swiper;
    },
    getSlideX: function() {
      return slideX;
    },
    setSlideY: function(coordY) {
      slideY = coordY;
    },
    getSlideY: function() {
      return slideY;
    },
    getInitialSubPath: function() {
      return initialSubPath;
    }
  };
}
angular.module('em.services').factory('emSwiper', emSwiper);
emSwiper.$inject = ['$rootScope', 'emLocation', 'userPrefix'];

function swiperSlide(emSwiper) {
  return {
    restrict: 'A',
    require: '^emSwiperSlider',
    scope: true,
    compile: function compile() {
      var slidePathData = [];

      return {
        pre: function preLink(scope, element, attrs, ctrl) {
          ctrl.scrollVerticalSlide(element[0]);
          slidePathData.push(attrs.swiperSlide);
        },
        post: function postLink(scope, element, attrs, ctrl) {
          // http://stackoverflow.com/a/18757437
          if (scope.$last) {
            var i = 0;

            if (emSwiper.getInitialSubPath()) {
              while (slidePathData[i]) {
                if (slidePathData[i] === emSwiper.getInitialSubPath()) {
                  emSwiper.setInitialSlideIndex(i);
                }
                i++;
              }
            }
            ctrl.slidesReady(slidePathData);
          }
        }
      };
    }
  };
}
angular.module('em.directives').directive('swiperSlide', swiperSlide);
swiperSlide.$inject = ['emSwiper'];

function emSwiperSlider(emSwiper) {
  return {
    restrict: 'A',
    scope: {
      mode: '@emSwiperSlider'
    },
    controller: function($scope, $element) {
      var swiper;

      this.slidesReady = function(pathData) {
        var i, slide;
        swiper.reInit();

        if (pathData) {
          for (i = 0; i < swiper.slides.length; i++) {
            slide = swiper.getSlide(i);
            slide.setData('path', pathData[i]);
          }
          swiper.swipeTo(emSwiper.getInitiaSlideIndex(), 0, false);
        }
      };

      this.scrollVerticalSlide = function(elem) {
        elem.addEventListener('touchstart', slideTouchStart, false);
        elem.addEventListener('touchmove', slideTouchMove, false);
      };

      function emOnSlideChangeEnd() {
        emSwiper.changePath(swiper);
      }

      var swiperParams = {
        mode: $scope.mode,
        noSwiping: true,
        queueStartCallbacks: true,
        queueEndCallbacks: true,
        simulateTouch: true,
        initialSlide: emSwiper.getInitiaSlideIndex(),
        onSlideChangeEnd: emOnSlideChangeEnd
      };

      swiper = emSwiper.initSwiper($element[0], swiperParams);

      if (swiper.params.mode === 'horizontal') {
        var i, slide, slides;
        i = 0;
        slides = emSwiper.getSlides();

        while (swiper.slides[i]) {
          slide = swiper.slides[i];
          slide.setData('path', slides[i]);
          i++;
        }
      }

      var top = false;
      var bottom = false;
      var up = false;
      var down = false;<commit_msg>Return vertical swiper's active subpath to horizontal swiper.<commit_after>/*global angular, Swiper */
'use strict';

function emSwiper($rootScope, emLocation, userPrefix) {
  var initialSlideX, initialSlideY, initialSubPath, slides, swiper, swipers;
  slides = [];
  swipers = {};

  var slideX, slideY;
  var sw = {};

  return {
    initSwiper: function(container, params) {
      // http://www.idangero.us/sliders/swiper/api.php
      swiper = new Swiper(container, params);
      swipers[swiper.params.mode] = swiper;
      return swiper;
    },
    changePath: function(activeSwiper) {
      var activeSlide, activeSlideY, slidePath, slideSubPath;
      activeSlide = activeSwiper.getSlide(activeSwiper.activeIndex);

      if (activeSwiper.params.mode === 'horizontal') {
        if (activeSlide.getData('path')) {
          slidePath = '/' + userPrefix.getPrefix() + '/' + activeSlide.getData('path');
        } else {
          slidePath = '/' + userPrefix.getPrefix();
        }
        if (sw[activeSwiper.activeIndex]) {
          if (isNaN(sw[activeSwiper.activeIndex].activeIndex)) {
            activeSlideY = 0;
          } else {
            activeSlideY = sw[activeSwiper.activeIndex].activeIndex;
          }
          slideSubPath = sw[activeSwiper.activeIndex].getSlide(activeSlideY).getData('path');
          slidePath += '/' + slideSubPath;
        }
      } else { // vertical
        slideSubPath = activeSlide.getData('path');
        slidePath = '/' + userPrefix.getPrefix() + '/' + this.getSwiper('horizontal').getSlide(this.getSwiper('horizontal').activeIndex).getData('path') + '/' + slideSubPath;
      }
      emLocation.skipReload().path(slidePath);
      $rootScope.$apply();
    },
    getSwiper: function(mode) {
      return swipers[mode];
    },
    setSlides: function(slideX, subPath) {
      initialSubPath = subPath;
      slides = ['inbox', '', 'tasks/dates', 'tasks/projects', 'tasks'];
      initialSlideX = slideX;
    },
    getSlides: function() {
      return slides;
    },
    setSlideIndex: function(coordX, coordY) {
      swipers.horizontal.swipeTo(coordX);
      sw[coordX].swipeTo(coordY);
    },
    setInitialSlideY: function(slideY) {
      initialSlideY = slideY;
    },
    getInitiaSlideIndex: function(mode) {
      if (mode === 'horizontal') {
        return initialSlideX;
      }
      return initialSlideY;
    },
    setVerticalSwiper: function(coordX) {
      sw[coordX] = swiper;
    },
    getSlideX: function() {
      return slideX;
    },
    setSlideY: function(coordY) {
      slideY = coordY;
    },
    getSlideY: function() {
      return slideY;
    },
    getInitialSubPath: function() {
      return initialSubPath;
    }
  };
}
angular.module('em.services').factory('emSwiper', emSwiper);
emSwiper.$inject = ['$rootScope', 'emLocation', 'userPrefix'];

function swiperSlide(emSwiper) {
  return {
    restrict: 'A',
    require: '^emSwiperSlider',
    scope: true,
    compile: function compile() {
      var slidePathData = [];

      return {
        pre: function preLink(scope, element, attrs, ctrl) {
          ctrl.scrollVerticalSlide(element[0]);
          slidePathData.push(attrs.swiperSlide);
        },
        post: function postLink(scope, element, attrs, ctrl) {
          // http://stackoverflow.com/a/18757437
          if (scope.$last) {
            var i = 0;

            if (emSwiper.getInitialSubPath()) {
              while (slidePathData[i]) {
                if (slidePathData[i] === emSwiper.getInitialSubPath()) {
                  emSwiper.setInitialSlideY(i);
                }
                i++;
              }
            }
            ctrl.slidesReady(slidePathData);
          }
        }
      };
    }
  };
}
angular.module('em.directives').directive('swiperSlide', swiperSlide);
swiperSlide.$inject = ['emSwiper'];

function emSwiperSlider(emSwiper) {
  return {
    restrict: 'A',
    scope: {
      mode: '@emSwiperSlider'
    },
    controller: function($scope, $element) {
      var swiper;

      this.slidesReady = function(pathData) {
        var i, slide;
        swiper.reInit();

        if (pathData) {
          for (i = 0; i < swiper.slides.length; i++) {
            slide = swiper.getSlide(i);
            slide.setData('path', pathData[i]);
          }
          swiper.swipeTo(emSwiper.getInitiaSlideIndex($scope.mode), 0, false);
        }
      };

      this.scrollVerticalSlide = function(elem) {
        elem.addEventListener('touchstart', slideTouchStart, false);
        elem.addEventListener('touchmove', slideTouchMove, false);
      };

      function emOnSlideChangeEnd() {
        emSwiper.changePath(swiper);
      }

      var swiperParams = {
        mode: $scope.mode,
        noSwiping: true,
        queueStartCallbacks: true,
        queueEndCallbacks: true,
        simulateTouch: true,
        initialSlide: emSwiper.getInitiaSlideIndex($scope.mode),
        onSlideChangeEnd: emOnSlideChangeEnd
      };

      swiper = emSwiper.initSwiper($element[0], swiperParams);

      if (swiper.params.mode === 'horizontal') {
        var i, slide, slides;
        i = 0;
        slides = emSwiper.getSlides();

        while (swiper.slides[i]) {
          slide = swiper.slides[i];
          slide.setData('path', slides[i]);
          i++;
        }
      }

      var top = false;
      var bottom = false;
      var up = false;
      var down = false;
{'fraction_non_alphanumeric': 0.13571359081622725, 'fraction_numerical': 0.0028212861173265882, 'mean_word_length': 2.3290155440414506, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3225734', 'n_tokens_mistral': 3295, 'n_tokens_neox': 3201, 'n_words': 558}