<commit_before>;(function($) {
  var pluginName = 'carousel';

  var defaults = {};

  function Carousel(element, options) {
    this.options = $.extend({}, defaults, options);
    this._defaults = defaults;
    this._name = pluginName;

    this.element = element;
    this.$element = $(element);

    this.$container = this.$element;
    this.$panes = this.$container.find(".carousel-item");

    this.pane_width = 0;
    this.pane_count = this.$panes.length;

    this.current_pane = 0;
    this.init();

    this.$element.hammer({ drag_lock_to_axis: true })
      .on("release dragleft dragright swipeleft swiperight", $.proxy(this.handleHammer, this));


    // hammerjs tap with jquery mobile tap
    // control btn mainly for mouse usage
    // $('.carousel-control').hammer().on('tap', function(e) {
    var self = this;
    $('.carousel-control').on('click', function(e) {

      var $this = $(this);
      var control = $this.attr('data-carousel');

      if(control === 'prev') {
        self.prev();
      } else if(control === 'next') {
        self.next();
      }
      return false;
    });
  }


  Carousel.prototype.init = function() {
    var self = this;
    this.$panes.first().addClass('carousel-active');
    this.setPaneDimensions();
    this.updateControl();

    $(window).on("load resize orientationchange", function() {
      self.setPaneDimensions();
      //updateOffset();
    });
  };


  Carousel.prototype.setPaneDimensions = function() {
    this.pane_width = this.$element.width();
    this.$panes.each(function() {
      $(this).width(self.pane_width);
    });
    this.$container.width(this.pane_width*this.pane_count);
  };

  Carousel.prototype.updateControl = function() {
    var $left = $('.left.carousel-control').show();
    var $right = $('.right.carousel-control').show();
    if(this.current_pane ===  0) {
      $left.hide();
    }
    if(this.current_pane === this.pane_count - 1) {
      $right.hide();
    }
  };


  Carousel.prototype.showPane = function(index) {
    // between the bounds
    index = Math.max(0, Math.min(index, self.pane_count-1));
    this.current_pane = index;

    var offset = -((100/self.pane_count)*self.current_pane);
    this.setContainerOffset(offset, true);
    this.updateControl();

    this.$container.find('.carousel-active').removeClass('carousel-active');
    $(this.$panes.get(index)).addClass('carousel-active');
  };


  Carousel.prototype.setContainerOffset = function(percent, animate) {
    this.$container.removeClass("animate");

    if(animate) {
     this.$container.addClass("animate");
    }

    if(Modernizr.csstransforms3d) {
      this.$container.css("transform", "translate3d("+ percent +"%,0,0) scale3d(1,1,1)");
    } else if(Modernizr.csstransforms) {
      this.$container.css("transform", "translate("+ percent +"%,0)");
    } else {
      var px = ((this.pane_width*this.pane_count) / 100) * percent;
      this.$container.css("left", px+"px");
    }
  };

  Carousel.prototype.next = function() {
    return this.showPane(this.current_pane+1, true);
  };

  Carousel.prototype.prev = function() {
    return this.showPane(this.current_pane-1, true);
  };


  Carousel.prototype.handleHammer = function(ev) {
    var self = this;
    // disable browser scrolling
    ev.gesture.preventDefault();

    switch(ev.type) {
      case 'dragright':
      case 'dragleft':
        // stick to the finger
        var pane_offset = -(100/self.pane_count)*self.current_pane;
        var drag_offset = ((100/self.pane_width)*ev.gesture.deltaX) / self.pane_count;

        // slow down at the first and last pane
        if((self.current_pane === 0 && ev.gesture.direction == Hammer.DIRECTION_RIGHT) ||
          (self.current_pane == self.pane_count-1 && ev.gesture.direction == Hammer.DIRECTION_LEFT)) {
          drag_offset *= 0.4;
        }

        self.setContainerOffset(drag_offset + pane_offset);
        break;

      case 'swipeleft':
        self.next();
        ev.gesture.stopDetect();
        break;

      case 'swiperight':
        self.prev();<commit_msg>remove carousel.init<commit_after>;(function($) {
  var pluginName = 'carousel';

  var defaults = {};

  function Carousel(element, options) {
    this.options = $.extend({}, defaults, options);
    this._defaults = defaults;
    this._name = pluginName;

    this.element = element;
    this.$element = $(element);

    this.$container = this.$element.find('.carousel-inner');
    this.$panes = this.$container.find(".carousel-item");

    this.pane_width = 0;
    this.pane_count = this.$panes.length;

    this.current_pane = 0;

    this.$element.hammer({ drag_lock_to_axis: true })
      .on("release dragleft dragright swipeleft swiperight", $.proxy(this.handleHammer, this));

    var self = this;

    this.$panes.first().addClass('carousel-active');
    // this.setPaneDimensions();
    this.updateControl();

    $(window).on("load resize orientationchange", function() {
      self.setPaneDimensions();
      //updateOffset();
    });

    // hammerjs tap with jquery mobile tap
    // control btn mainly for mouse usage
    // $('.carousel-control').hammer().on('tap', function(e) {
    // var self = this;
    // $('.carousel-control').on('click', function(e) {

    //   var $this = $(this);
    //   var control = $this.attr('data-carousel');

    //   if(control === 'prev') {
    //     self.prev();
    //   } else if(control === 'next') {
    //     self.next();
    //   }
    //   return false;
    // });
  }

  Carousel.prototype.setPaneDimensions = function() {
    this.pane_width = this.$element.width();

    console.log('%c this.pane_width = ' + this.pane_width, 'color: green');
    var self = this;
    this.$panes.each(function() {
      $(this).width(self.pane_width);
    });
    this.$container.width(this.pane_width*this.pane_count);
  };

  Carousel.prototype.updateControl = function() {
    var $left = $('.left.carousel-control').show();
    var $right = $('.right.carousel-control').show();
    if(this.current_pane ===  0) {
      $left.hide();
    }
    if(this.current_pane === this.pane_count - 1) {
      $right.hide();
    }
  };


  Carousel.prototype.showPane = function(index) {
    console.log('%c show pane ' + index, 'color: green');


    // between the bounds
    index = Math.max(0, Math.min(index, this.pane_count-1));
    this.current_pane = index;

    var offset = -((100/this.pane_count)*this.current_pane);
    this.setContainerOffset(offset, true);
    this.updateControl();

    this.$container.find('.carousel-active').removeClass('carousel-active');
    $(this.$panes.get(index)).addClass('carousel-active');
  };


  Carousel.prototype.setContainerOffset = function(percent, animate) {
    this.$container.removeClass("animate");

    if(animate) {
     this.$container.addClass("animate");
    }

    if(Modernizr.csstransforms3d) {
      this.$container.css("transform", "translate3d("+ percent +"%,0,0) scale3d(1,1,1)");
    } else if(Modernizr.csstransforms) {
      this.$container.css("transform", "translate("+ percent +"%,0)");
    } else {
      var px = ((this.pane_width*this.pane_count) / 100) * percent;
      this.$container.css("left", px+"px");
    }
  };

  Carousel.prototype.next = function() {
    console.log('%c next', 'color: green');

    console.log(this.current_pane);

    return this.showPane(this.current_pane+1, true);
  };

  Carousel.prototype.prev = function() {
    console.log('%c prev', 'color: green');

    return this.showPane(this.current_pane-1, true);
  };


  Carousel.prototype.handleHammer = function(ev) {
    var self = this;
    // disable browser scrolling
    ev.gesture.preventDefault();

    console.log(ev);

    switch(ev.type) {
      case 'dragright':
      case 'dragleft':
        // stick to the finger
        var pane_offset = -(100/self.pane_count)*self.current_pane;
        var drag_offset = ((100/self.pane_width)*ev.gesture.deltaX) / self.pane_count;

        // slow down at the first and last pane
        if((self.current_pane === 0 && ev.gesture.direction == Hammer.DIRECTION_RIGHT) ||
          (self.current_pane == self.pane_count-1 && ev.gesture.direction == Hammer.DIRECTION_LEFT)) {
          drag_offset *= 0.4;
        }

        self.setContainerOffset(drag_offset + pane_offset);
        break;

      case 'swipeleft':
        self.next();
        ev.gesture.stopDetect();
        break;

      case 'swiperight':
        self.prev();
{'fraction_non_alphanumeric': 0.16984033116499114, 'fraction_numerical': 0.007806031933767002, 'mean_word_length': 2.8700228832951944, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3334155', 'n_tokens_mistral': 2839, 'n_tokens_neox': 2701, 'n_words': 463}