Sha256: 5287bfab5c8dd5bb721debb3e68115ea58ba0902123e57701cd5765a4b9cf789

Contents?: true

Size: 900 Bytes

Versions: 4

Compression:

Stored size: 900 Bytes

Contents

{getDOMRange, setDOMRange} = Trix

class Trix.PointMapper
  createDOMRangeFromPoint: ({x, y}) ->
    if document.caretPositionFromPoint
      {offsetNode, offset} = document.caretPositionFromPoint(x, y)
      domRange = document.createRange()
      domRange.setStart(offsetNode, offset)
      domRange

    else if document.caretRangeFromPoint
      document.caretRangeFromPoint(x, y)

    else if document.body.createTextRange
      originalDOMRange = getDOMRange()
      try
        # IE 11 throws "Unspecified error" when using moveToPoint
        # during a drag-and-drop operation.
        textRange = document.body.createTextRange()
        textRange.moveToPoint(x, y)
        textRange.select()
      domRange = getDOMRange()
      setDOMRange(originalDOMRange)
      domRange

  getClientRectsForDOMRange: (domRange) ->
    [start, ..., end] = [domRange.getClientRects()...]
    [start, end]

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vapid-0.1.3 lib/vapid/vendor/trix/src/trix/models/point_mapper.coffee
vapid-0.1.2 lib/vapid/vendor/trix/src/trix/models/point_mapper.coffee
vapid-0.1.1 lib/vapid/vendor/trix/src/trix/models/point_mapper.coffee
vapid-0.1.0 lib/vapid/vendor/trix/src/trix/models/point_mapper.coffee