Sha256: 593bf836b873bec00801994384b83638b44a6fa93d56954c192394c08bc16e8e

Contents?: true

Size: 1.97 KB

Versions: 12

Compression:

Stored size: 1.97 KB

Contents

import Component from "@ember/component";
const MOVE_EVENTS = ["touchmove", "mousemove"];
const UP_EVENTS = ["touchend", "mouseup"];
const DOWN_EVENTS = ["touchstart", "mousedown"];

export default Component.extend({
  classNames: ["divider"],

  divideView(fromTop, win) {
    const $win = win || Em.$(window);
    const height = $win.height();
    const fromBottom = $win.height() - fromTop;

    if (fromTop < 100 || fromTop + 170 > height) {
      return;
    }

    this.divider.css("bottom", fromBottom - 5);
    this.events.trigger("panelResized", fromBottom);
  },

  didInsertElement() {
    // inspired by http://plugins.jquery.com/misc/textarea.js
    this.divider = Em.$(".divider");

    const $win = Em.$(window);
    let resizing = false;

    const performDrag = e => {
      if (resizing) {
        this.divideView(
          e.clientY || (e.touches && e.touches[0] && e.touches[0].clientY),
          $win
        );
      }
    };

    const endDrag = () => {
      Em.$("#overlay").remove();
      resizing = false;

      if (localStorage) {
        localStorage.logster_divider_bottom = parseInt(
          this.divider.css("bottom"),
          10
        );
      }

      const $document = Em.$(document);
      MOVE_EVENTS.forEach(e => $document.unbind(e, performDrag));
      UP_EVENTS.forEach(e => $document.unbind(e, endDrag));
    };

    this.divider.on(DOWN_EVENTS.join(" "), e => {
      e.preventDefault(); // for disabling pull-down-to-refresh on mobile
      Em.$("<div id='overlay'></div>").appendTo(Em.$("body"));
      resizing = true;
      Em.$(document)
        .on(MOVE_EVENTS.join(" "), _.throttle(performDrag, 25))
        .on(UP_EVENTS.join(" "), endDrag);
    });

    Em.run.next(() => {
      const amount =
        (localStorage && localStorage.logster_divider_bottom) || 300;
      const fromTop = $win.height() - parseInt(amount, 10);
      this.divideView(fromTop, $win);
    });
  },

  willDestroyElement() {
    Em.$(".divider").off(DOWN_EVENTS.join(" "));
  }
});

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
logster-2.5.1 client-app/app/components/panel-resizer.js
logster-2.5.0 client-app/app/components/panel-resizer.js
logster-2.4.2 client-app/app/components/panel-resizer.js
logster-2.4.1 client-app/app/components/panel-resizer.js
logster-2.4.0 client-app/app/components/panel-resizer.js
logster-2.3.3 client-app/app/components/panel-resizer.js
logster-2.3.2 client-app/app/components/panel-resizer.js
logster-2.3.1 client-app/app/components/panel-resizer.js
logster-2.3.0 client-app/app/components/panel-resizer.js
logster-2.2.0 client-app/app/components/panel-resizer.js
logster-2.1.2 client-app/app/components/panel-resizer.js
logster-2.1.1 client-app/app/components/panel-resizer.js