How to use the pscript.window.document function in pscript

To help you get started, we’ve selected a few pscript 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 flexxui / flexx / flexx / ui / _widget.py View on Github external
def __render_resolve(self, vnode, node=None):
        """ Given a DOM node and its virtual representation,
        update or create a new DOM node as necessary.
        """

        # Check vnode (we check vnode.children further down)
        if vnode and vnode.nodeName:  # is DOM node
            return vnode
        elif isinstance(vnode, str):
            return window.document.createTextNode(vnode)
        elif not isinstance(vnode, dict):
            raise TypeError('Widget._render_dom() needs virtual nodes '
                            'to be dicts, not ' + vnode)
        if not isinstance(vnode.type, str):
            raise TypeError('Widget._render_dom() needs virtual node '
                            'type to be str, not ' + vnode.type)
        if not isinstance(vnode.props, dict):
            raise TypeError('Widget._render_dom() needs virtual node '
                            'props as dict, not ' + vnode.props)

        # Resolve the node itself
        if node is None or node.nodeName.toLowerCase() != vnode.type.toLowerCase():
            node = window.document.createElement(vnode.type)

        # Resolve props (i.e. attributes)
        map = {'css_class': 'className', 'class': 'className'}
github flexxui / flexx / flexx / ui / widgets / _dropdown.py View on Github external
def _expand(self):
        # Expand
        self.node.classList.add('expanded')
        # Collapse when the node changes position (e.g. scroll or layout change)
        rect = self.node.getBoundingClientRect()
        self._rect_to_check = rect
        window.setTimeout(self._check_expanded_pos, 100)
        # Collapse when the mouse is used outside the combobox (or its children)
        self._addEventListener(window.document, 'mousedown', self._collapse_maybe, 1)
        # Return rect so subclasses can use it
        return rect
github flexxui / flexx / flexx / ui / _widget.py View on Github external
def mdown(e):
            # Start emitting move events, maybe follow the mouse outside widget bounds
            if self.capture_mouse == 0:
                self._capture_flag = 1
            else:
                self._capture_flag = 2
                window.document.addEventListener("mousemove", mmove_outside, True)
                window.document.addEventListener("mouseup", mup_outside, True)
                # Explicit caputuring is not necessary, and even causes problems on IE