Sha256: 5a06fedc101c96931dc14adff0f7fdab419c5e8870b1d18c980abf0a7f43de1a

Contents?: true

Size: 1.73 KB

Versions: 7

Compression:

Stored size: 1.73 KB

Contents

(function() {
  var KEY_SHIFT = 16;
  var KEY_CTRL = 17;

  sitemap.ScrollPaneView = Backbone.Marionette.View.extend({
    className: 'scroll_pane',

    events: {
      mousedown: function(event) {
        this.scrolling = true;
        this.lastX = event.pageX;
        this.lastY = event.pageY;
      },

      mousemove: function(event) {
        if (!event.ctrlKey) {
          this.deactivate();
        }

        if (this.scrolling) {
          var diffX = event.pageX - this.lastX;
          var diffY = event.pageY - this.lastY;

          this.options.graphView.scrollBy(diffX, diffY);

          this.lastX = event.pageX;
          this.lastY = event.pageY;
        }
      },

      mouseup: function(event) {
        this.scrolling = false;
      },
    },

    initialize: function() {
      this.keydownHandler = _.bind(this.onKeydown, this);
      this.keyupHandler = _.bind(this.onKeyup, this);

      $(document).on('keydown', this.keydownHandler);
      $(document).on('keyup', this.keyupHandler);
    },

    onClose: function() {
      $(document).off('keydown', this.keydownHandler);
      $(document).off('keyup', this.keyupHandler);
    },

    onKeydown: function(event) {
      if ((event.which === KEY_CTRL && event.shiftKey) ||
          (event.which === KEY_SHIFT && event.ctrlKey)) {
        this.activate();
      }
    },

    onKeyup: function(event) {
      if (event.which === KEY_CTRL || event.which === KEY_SHIFT) {
        this.deactivate();
      }
    },

    activate: function() {
      this.$el.addClass('active');
      document.body.style.cursor = 'move';
    },

    deactivate: function() {
      this.scrolling = false;
      this.$el.removeClass('active');
      document.body.style.cursor = 'default';
    }
  });
}());

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pageflow-sitemap-1.5.0 app/assets/javascripts/pageflow/sitemap/editor/views/scroll_pane_view.js
pageflow-sitemap-1.4.0 app/assets/javascripts/pageflow/sitemap/editor/views/scroll_pane_view.js
pageflow-sitemap-1.3.0 app/assets/javascripts/pageflow/sitemap/editor/views/scroll_pane_view.js
pageflow-sitemap-1.2.0 app/assets/javascripts/pageflow/sitemap/editor/views/scroll_pane_view.js
pageflow-sitemap-1.1.0 app/assets/javascripts/pageflow/sitemap/editor/views/scroll_pane_view.js
pageflow-sitemap-1.0.0 app/assets/javascripts/pageflow/sitemap/editor/views/scroll_pane_view.js
pageflow-sitemap-0.1.0 app/assets/javascripts/pageflow/sitemap/editor/views/scroll_pane_view.js