openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

widgets.min.js (1050B)


      1 import { contains, elt, removeChildrenAndAdd } from "../util/dom.js"
      2 import { e_target } from "../util/event.js"
      3 
      4 export function widgetHeight(widget) {
      5   if (widget.height != null) return widget.height
      6   let cm = widget.doc.cm
      7   if (!cm) return 0
      8   if (!contains(document.body, widget.node)) {
      9     let parentStyle = "position: relative;"
     10     if (widget.coverGutter)
     11       parentStyle += "margin-left: -" + cm.display.gutters.offsetWidth + "px;"
     12     if (widget.noHScroll)
     13       parentStyle += "width: " + cm.display.wrapper.clientWidth + "px;"
     14     removeChildrenAndAdd(cm.display.measure, elt("div", [widget.node], null, parentStyle))
     15   }
     16   return widget.height = widget.node.parentNode.offsetHeight
     17 }
     18 
     19 // Return true when the given mouse event happened in a widget
     20 export function eventInWidget(display, e) {
     21   for (let n = e_target(e); n != display.wrapper; n = n.parentNode) {
     22     if (!n || (n.nodeType == 1 && n.getAttribute("cm-ignore-events") == "true") ||
     23         (n.parentNode == display.sizer && n != display.mover))
     24       return true
     25   }
     26 }