How to use the global.window.addEventListener function in global

To help you get started, we’ve selected a few global examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github storybookjs / SBNext / ui / pages / preview-1.js View on Github external
};
    this.postMessageListener = ({ data: { go, size } }) => {
      if (go) {
        this.go(go);
      }

      if (size) {
        this.resizeListener();
      }
    };

    window.addEventListener('message', this.postMessageListener, false);

    // listen for changes that might change the size of the window
    window.addEventListener('resize', this.resizeListener, false);
    window.addEventListener('scroll', this.resizeListener, false);

    this.performanceObserver = new PerformanceObserver(list => {
      if (list.getEntries().find(item => item.initiatorType.match(/(css|img)/))) {
        this.resizeListener();
      }
    });
    this.performanceObserver.observe({ entryTypes: ['resource'] });

    // pass the rendered window size up to parent
    this.resizeListener();
  }
  componentWillUnmount() {
github uber / manifold / bindings / jupyter / js / src / index.js View on Github external
import {window} from 'global';
import Jupyter from 'base/js/namespace';

// Frontend error handling
window.addEventListener('error', event => {
  const msgId = Jupyter.notebook.kernel.last_msg_id;
  const cell = Jupyter.notebook.get_msg_cell(msgId);
  if (cell) {
    const {error} = event;
    cell.output_area.append_output({
      output_type: 'error',
      ename: error.name,
      evalue: error.message,
      traceback: ['Javascript Error', error.stack],
    });
    cell.output_area.element
      .find('.output_subarea.output_error')
      .css({'background-color': '#ff9999'});
  }
});
github storybookjs / SBNext / ui / pages / preview-1.js View on Github external
window.parent.postMessage(
        { size: document.documentElement.getBoundingClientRect() },
        document.location.origin
      );
    };
    this.postMessageListener = ({ data: { go, size } }) => {
      if (go) {
        this.go(go);
      }

      if (size) {
        this.resizeListener();
      }
    };

    window.addEventListener('message', this.postMessageListener, false);

    // listen for changes that might change the size of the window
    window.addEventListener('resize', this.resizeListener, false);
    window.addEventListener('scroll', this.resizeListener, false);

    this.performanceObserver = new PerformanceObserver(list => {
      if (list.getEntries().find(item => item.initiatorType.match(/(css|img)/))) {
        this.resizeListener();
      }
    });
    this.performanceObserver.observe({ entryTypes: ['resource'] });

    // pass the rendered window size up to parent
    this.resizeListener();
  }
  componentWillUnmount() {
github jaegertracing / jaeger-ui / src / components / DependencyGraph / DependencyForceGraph.js View on Github external
componentDidMount() {
    this.onResize();
    this.debouncedResize = debounce((...args) => this.onResize(...args), 50);
    window.addEventListener('resize', this.debouncedResize);
  }
github jaegertracing / jaeger-ui / src / components / TracePage / TraceSpanGraph.js View on Github external
startDragging(boundName, { clientX }) {
    this.setState({ currentlyDragging: boundName, prevX: clientX });

    const mouseMoveHandler = (...args) => this.onMouseMove(...args);
    const mouseUpHandler = () => {
      this.stopDragging();
      window.removeEventListener('mouseup', mouseUpHandler);
      window.removeEventListener('mousemove', mouseMoveHandler);
    };

    window.addEventListener('mouseup', mouseUpHandler);
    window.addEventListener('mousemove', mouseMoveHandler);
  }
github jaegertracing / jaeger-ui / src / components / TracePage / TraceSpanGraph.js View on Github external
startDragging(boundName, { clientX }) {
    this.setState({ currentlyDragging: boundName, prevX: clientX });

    const mouseMoveHandler = (...args) => this.onMouseMove(...args);
    const mouseUpHandler = () => {
      this.stopDragging();
      window.removeEventListener('mouseup', mouseUpHandler);
      window.removeEventListener('mousemove', mouseMoveHandler);
    };

    window.addEventListener('mouseup', mouseUpHandler);
    window.addEventListener('mousemove', mouseMoveHandler);
  }
github uber-common / vis-academy / src / demos / marching-squares / 0-workflow-demo / src / container.js View on Github external
componentDidMount() {
    window.addEventListener('resize', this._handleResize.bind(this));
    this._handleResize();
  }
github storybookjs / SBNext / ui / components / preview / iframe.js View on Github external
componentDidMount() {
    this.postMessageListener = ({ source, data: { size } }) => {
      if (size && this.elements.iframe && this.elements.iframe.contentWindow === source) {
        this.setState({ height: size.height });
      }
    };

    if (this.props.publisher) {
      this.props.publisher.listen((command, ...args) => {
        if (command === 'zoom') {
          this.setState({ zoom: this.state.zoom + args[0] });
        }
      });
    }
    window.addEventListener('message', this.postMessageListener, false);
  }
  componentWillUnmount() {
github uber / streetscape.gl / website / src / components / home.js View on Github external
componentDidMount() {
    window.addEventListener('resize', this.resize);
    this.resize();
  }
github storybookjs / storybook / lib / components / src / layout / desktop.js View on Github external
componentDidMount() {
    window.addEventListener('resize', this.throttledUpdatePreviewPanelState);
  }