How to use the pscript.window.document.createElement 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
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'}
        for key, val in vnode.props.items():
            ob = node
            parts = key.replace('__', '.').split('.')
            for i in range(len(parts)-1):
                ob = ob[parts[i]]
            key = parts[len(parts)-1]
            ob[map.get(key, key)] = val

        # Resolve content
        if vnode.children is None:
            pass  # dont touch it
        elif isinstance(vnode.children, list):
            # Truncate children
github flexxui / flexx / flexx / ui / widgets / _dropdown.py View on Github external
def _create_dom(self):
        return window.document.createElement('span')
github flexxui / flexx / flexx / ui / _widget.py View on Github external
def __icon_changed(self, *events):
        if self.parent is None and self.container == 'body':
            window.document.title = self.title or 'Flexx app'

            link = window.document.createElement('link')
            oldLink = window.document.getElementById('flexx-favicon')
            link.id = 'flexx-favicon'
            link.rel = 'shortcut icon'
            link.href = events[-1].new_value
            if oldLink:
                window.document.head.removeChild(oldLink)
            window.document.head.appendChild(link)
github flexxui / flexx / flexx / ui / layouts / _form.py View on Github external
def _create_dom(self):
        return window.document.createElement('div')
github flexxui / flexx / flexx / ui / layouts / _tabs.py View on Github external
def __update_tabs(self):
        children = self.children
        current = self.current

        # Add items to tabbar as needed
        while len(self._tabbar.children) < len(children):
            node = window.document.createElement('p')
            node.classList.add('flx-tab-item')
            node.index = len(self._tabbar.children)
            self._tabbar.appendChild(node)

        # Remove items from tabbar as needed
        while len(self._tabbar.children) > len(children):
            c = self._tabbar.children[len(self._tabbar.children) - 1]
            self._tabbar.removeChild(c)

        # Update titles
        for i in range(len(children)):
            widget = children[i]
            node = self._tabbar.children[i]
            node.textContent = widget.title
            if widget is current:
                node.classList.add('flx-current')
github flexxui / flexx / flexx / ui / layouts / _tabs.py View on Github external
def _create_dom(self):
        outernode = window.document.createElement('div')
        self._tabbar = window.document.createElement('div')
        self._tabbar.classList.add('flx-tabbar')
        self._addEventListener(self._tabbar, 'mousedown',  # also works for touch
                               self._tabbar_click)
        outernode.appendChild(self._tabbar)
        return outernode
github flexxui / flexx / flexx / ui / layouts / _tabs.py View on Github external
def _create_dom(self):
        outernode = window.document.createElement('div')
        self._tabbar = window.document.createElement('div')
        self._tabbar.classList.add('flx-tabbar')
        self._addEventListener(self._tabbar, 'mousedown',  # also works for touch
                               self._tabbar_click)
        outernode.appendChild(self._tabbar)
        return outernode