How to use the @instructure/ui-dom-utils.ownerDocument function in @instructure/ui-dom-utils

To help you get started, we’ve selected a few @instructure/ui-dom-utils 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 instructure / instructure-ui / packages / ui-layout / src / calculateElementPosition.js View on Github external
normalizeScrollTop (element) {
    // Account for cross browser differences with scrollTop attribute on the
    // body element https://bugs.chromium.org/p/chromium/issues/detail?id=766938
    return ownerDocument(this.node).body === element ? 0 : element.scrollTop
  }
}
github instructure / instructure-ui / packages / ui-layout / src / calculateElementPosition.js View on Github external
get positionedParentsOffset () {
    // If the element container is within a positioned
    // element, it will position absolutely with respect to that
    // ancestor. We calculate the offset between the child and
    // positioned parent so we can negate that distance
    const parents = getOffsetParents(this.node)
    const doc = ownerDocument(this.node)

    // If there is more than one parent, the offset on the
    // documentElement should be calculated appropriately.
    // Otherwise we need to explictly account for that offset
    let offsetY = parents.length > 1 ? 0 : doc.documentElement.offsetTop
    let offsetX = 0
    let scrollY = 0

    for (let i = 1; i < parents.length; i++) {
      const parent = getBoundingClientRect(parents[i])
      const child = getBoundingClientRect(parents[i - 1])

      offsetY = offsetY + (child.top - parent.top)
      offsetX = offsetX + (child.left - parent.left)

      if (parents[i] === doc.body) {
github instructure / instructure-ui / packages / ui-a11y / src / FocusRegion.js View on Github external
activate () {
    if (!this._active) {
      const doc = ownerDocument(this._contextElement)

      this._keyboardFocusRegion.activate()
      this._screenReaderFocusRegion.activate()

      if (this._options.shouldCloseOnDocumentClick) {
        this._listeners.push(addEventListener(doc, 'click', this.captureDocumentClick, true))
        this._listeners.push(addEventListener(doc, 'click', this.handleDocumentClick))

        Array.from(doc.getElementsByTagName('iframe'))
          .forEach((el) => {
            // listen for mouseup events on any iframes in the document
            const frameDoc = getFrameDocumentSafe(el)

            if(frameDoc) {
              this._listeners.push(addEventListener(frameDoc, 'mouseup', (event) => {
                this.handleFrameClick(event, el)
github instructure / instructure-ui / packages / ui-layout / src / calculateElementPosition.js View on Github external
constructor (element, target, options) {
    this.options = options || {}

    const { container, constrain, placement, over } = this.options

    if (!element || placement === 'offscreen') return

    this.container = container || ownerDocument(element).body

    this.element = new PositionedElement(element, placement, { top: this.options.offsetY, left: this.options.offsetX })

    this.target = new PositionedElement(
      target || this.container,
      over ? this.element.placement : this.element.mirroredPlacement
    )

    if (constrain === 'window') {
      this.constrainTo(ownerWindow(element))
    } else if (constrain === 'scroll-parent') {
      this.constrainTo(getScrollParents(this.target.node)[0])
    } else if (constrain === 'parent') {
      this.constrainTo(this.container)
    } else if (typeof constrain === 'function') {
      this.constrainTo(findDOMNode(constrain.call(null)))