<commit_before>
(function() {
  'use strict';
  var pluginName = 'offcanvas',
    defaults = {
      toggle: '.toggle-canvas',
      canvas: ['main'],
      open: function(){},
      close: function(){},
      resize: function(){},
      init: function(){},
      debug: false
    };


  $[pluginName] = function (element, options) {
    this.element = element;
    this.$offcanvas = $(element);

    this.options = $.extend({}, defaults, options);
    this.debug = this.options.debug;

    this._defaults = defaults;
    this._name = pluginName;

    var initCB = $.Callbacks('stopOnFalse');
    initCB.add($.proxy(this.initialize,this));
    if (typeof this.options.init === 'function') {
      initCB.add($.proxy(this.options.init,this));
    }
    initCB.fire();
  };

  $[pluginName].prototype = {
    initialize: function() {
      if (this.debug) console.log('init offcanvas', this);

      this.$offcanvas.attr('alive',true);
      this.processSelectors();
      this.attachEvents();
      this.setSizes();
    },

    toggle: function(event) {
      if (event) {
        event.preventDefault();
        event.stopPropagation();
      }
      if (this.state.open) {
        return this.close();
      } else {
        return this.open();
      }
    },

    open: function() {
      if (this.debug) console.log('open offcanvas', this);
      var openCB = $.Callbacks('stopOnFalse');

      openCB.add($.proxy(function() {
        this.state.open = true;

        this.setBodyPosition(this.$offcanvas.data('width'));
        this.state.position = this.$offcanvas.data('width');

        this.$offcanvas.css({'-webkit-overflow-scrolling': 'touch'});
        this.$offcanvas.attr('active',true);

        this.el.toggle.attr('active',true);
        this.el.toggle.attr('moving',true);

        setTimeout($.proxy(function() {
          this.el.toggle.attr('moving',false);
          this.el.toggle.attr('open',true);
        }, this), 250);
      },this));
      if (typeof this.options.open === 'function') {
        openCB.add($.proxy(this.options.open,this));
      }
      openCB.fire();
    },

    close: function() {
      if (this.debug) console.log('close offcanvas', this);
      var closeCB = $.Callbacks('stopOnFalse');

      closeCB.add($.proxy(function() {
        this.state.open = false;

        this.setBodyPosition(0);
        this.state.position = 0;

        this.$offcanvas.css({'-webkit-overflow-scrolling': ''});
        this.$offcanvas.attr('active',false);

        this.el.toggle.attr('active',false);
        this.el.toggle.attr('moving',true);

        setTimeout($.proxy(function() {
          this.el.toggle.attr('moving',false);
          this.el.toggle.attr('open',false);
        }, this), 250);
      },this));
      if (typeof this.options.close === 'function') {
        closeCB.add($.proxy(this.options.close,this));
      }
      closeCB.fire();
    },

    setBodyPosition: function(num) {
      $.each(this.el.canvas, $.proxy(function(index, el) {
        $(el).css(this.css.translate(num));
        if (num !== 0) {
          $('html,body').addClass('noscroll');
        }
        if (num === 0) {
          $('html,body').removeClass('noscroll');
        }
      }, this));

    },

    processSelectors: function() {
      this.el = {};

      this.el.toggle = this.options.toggle;
      if (typeof this.el.toggle === 'string') {
        this.el.toggle = $(this.el.toggle);
      }

      if (typeof this.options.canvas === 'object' && typeof this.options.canvas[0] === 'string') {
        this.el.canvas = [];
        $.each(this.options.canvas, $.proxy(function(index, el) {
          this.el.canvas.push($(el));
          $(el).attr('canvas',true);
        }, this));
      } else {
        this.el.canvas = false;
      }
    },

    attachEvents: function() {
      $(window).on('toggleCanvas', $.proxy(this.toggle,this));

      this.el.toggle.on('click', function(event) {
        event.preventDefault();
        event.stopPropagation();
        $(window).trigger('toggleCanvas');
      });

      this.resizeTimeout = 0;
      $(window).on('offCanvasResize', $.proxy(this.onResize, this));
      $(window).on('resize scroll', function() {
        $(window).trigger('offCanvasResize');
      }).trigger('resize');
    },

    onResize: function() {
      clearTimeout(this.resizeTimeout);
      this.resizeTimeout = setTimeout($.proxy(function() {
        this.setSizes();
        if (typeof this.options.resize === 'function') {
          this.options.resize();
        }
        if (this.el.toggle.css('display') === 'none' && this.state.open) {
          return this.close();
        }
      }, this, 100));
    },

    setSizes: function() {
      if (window.innerHeight) {
        this.$offcanvas.css('height',window.innerHeight);
        this.el.canvas[0].css('min-height', window.innerHeight);
      } else {
        this.$offcanvas.css('height',$(window).height());
        this.el.canvas[0].css('min-height', $(window).height());
      }
      if (this.$offcanvas.css('left') === '0px') {<commit_msg>Implement uniqueID to allow for multiple offcanvas sidebars on same page + implement usage of event namespacing<commit_after>
(function() {
  'use strict';
  var pluginName = 'offcanvas',
    defaults = {
      toggle: '.toggle-canvas',
      canvas: ['main'],
      open: function(){},
      close: function(){},
      resize: function(){},
      init: function(){},
      debug: false
    };


  $[pluginName] = function (element, options) {
    this.element = element;
    this.$offcanvas = $(element);

    this.options = $.extend({}, defaults, options);
    this.debug = this.options.debug;

    this._defaults = defaults;
    this._name = pluginName;

    var initCB = $.Callbacks('stopOnFalse');
    initCB.add($.proxy(this.initialize,this));
    if (typeof this.options.init === 'function') {
      initCB.add($.proxy(this.options.init,this));
    }
    initCB.fire();
  };

  $[pluginName].prototype = {
    initialize: function() {
      if (this.debug) console.log('init offcanvas', this);

      this.$offcanvas.attr('alive',true);

      this.uniqueID = new Date().getTime();
      this.$offcanvas.data('uniqueID',this.uniqueID);

      this.processSelectors();
      this.attachEvents();
      this.setSizes();
    },

    toggle: function(event) {
      if (event) {
        event.preventDefault();
        event.stopPropagation();
      }
      if (this.state.open) {
        return this.close();
      } else {
        return this.open();
      }
    },

    open: function() {
      if (this.debug) console.log('open offcanvas', this);
      var openCB = $.Callbacks('stopOnFalse');

      openCB.add($.proxy(function() {
        this.state.open = true;

        this.setBodyPosition(this.$offcanvas.data('width'));
        this.state.position = this.$offcanvas.data('width');

        this.$offcanvas.css({'-webkit-overflow-scrolling': 'touch'});
        this.$offcanvas.attr('active',true);

        this.el.toggle.attr('active',true);
        this.el.toggle.attr('moving',true);

        setTimeout($.proxy(function() {
          this.el.toggle.attr('moving',false);
          this.el.toggle.attr('open',true);
        }, this), 250);
      },this));
      openCB.add($.proxy(function() {
        this.resizeTimeout = 0;
        $(window).on('resize.offCanvasResize_' + this.uniqueID, $.proxy(this.onResize, this));
      },this));
      if (typeof this.options.open === 'function') {
        openCB.add($.proxy(this.options.open,this));
      }
      openCB.fire();
    },

    close: function() {
      if (this.debug) console.log('close offcanvas', this);
      var closeCB = $.Callbacks('stopOnFalse');

      closeCB.add($.proxy(function() {
        this.state.open = false;

        this.setBodyPosition(0);
        this.state.position = 0;

        this.$offcanvas.css({'-webkit-overflow-scrolling': ''});
        this.$offcanvas.attr('active',false);

        this.el.toggle.attr('active',false);
        this.el.toggle.attr('moving',true);

        setTimeout($.proxy(function() {
          this.el.toggle.attr('moving',false);
          this.el.toggle.attr('open',false);
        }, this), 250);
      },this));
      closeCB.add($.proxy(function() {
        $(window).off('resize.offCanvasResize_' + this.uniqueID);
      },this));
      if (typeof this.options.close === 'function') {
        closeCB.add($.proxy(this.options.close,this));
      }
      closeCB.fire();
    },

    setBodyPosition: function(num) {
      $.each(this.el.canvas, $.proxy(function(index, el) {
        $(el).css(this.css.translate(num));
        if (num !== 0) {
          $('html,body').addClass('noscroll');
        }
        if (num === 0) {
          $('html,body').removeClass('noscroll');
        }
      }, this));

    },

    processSelectors: function() {
      this.el = {};

      this.el.toggle = this.options.toggle;
      if (typeof this.el.toggle === 'string') {
        this.el.toggle = $(this.el.toggle);
      }

      if (typeof this.options.canvas === 'object' && typeof this.options.canvas[0] === 'string') {
        this.el.canvas = [];
        $.each(this.options.canvas, $.proxy(function(index, el) {
          this.el.canvas.push($(el));
          $(el).attr('canvas',true);
        }, this));
      } else {
        this.el.canvas = false;
      }
    },

    attachEvents: function() {
      this.el.toggle.on(
        'click.toggleCanvas_' + this.uniqueID,
        $.proxy(function(event) {
          event.preventDefault();
          event.stopPropagation();
          this.toggle();
        },this)
      );
    },

    onResize: function() {
      clearTimeout(this.resizeTimeout);
      this.resizeTimeout = setTimeout($.proxy(function() {
        this.setSizes();
        if (typeof this.options.resize === 'function') {
          this.options.resize();
        }
        if (this.el.toggle.css('display') === 'none' && this.state.open) {
          return this.close();
        }
      }, this, 100));
    },

    setSizes: function() {
      if (window.innerHeight) {
        this.$offcanvas.css('height',window.innerHeight);
        this.el.canvas[0].css('min-height', window.innerHeight);
      } else {
        this.$offcanvas.css('height',$(window).height());
        this.el.canvas[0].css('min-height', $(window).height());
      }
      if (this.$offcanvas.css('left') === '0px') {
{'fraction_non_alphanumeric': 0.18661667147389674, 'fraction_numerical': 0.003461205653302567, 'mean_word_length': 2.3468468468468466, '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': '1321609', 'n_tokens_mistral': 3230, 'n_tokens_neox': 3160, 'n_words': 492}