Skip to content
Snippets Groups Projects
divtools.js 1.57 KiB
Newer Older
  • Learn to ignore specific revisions
  • function writeStateRep(container, rep, key){
        var variable = rep.state[key]
        if(typeof variable == 'string'){
    
    Jake Read's avatar
    Jake Read committed
            var li  = document.createElement('li')
            li.appendChild(document.createTextNode(key))
    
            var input = document.createElement('input')
            input.type = 'text'
            input.size = 24
            input.value = variable
            input.addEventListener('change', function(){
                rep.state[key] = input.value
                putState(rep)
            })
    
    Jake Read's avatar
    Jake Read committed
            li.appendChild(input)
            container.appendChild(li)
    
            return input
        } else if (typeof variable == 'number'){
            console.log('NUM')
    
    Jake Read's avatar
    Jake Read committed
            var li = document.createElement('li')
            li.appendChild(document.createTextNode(key))
            var input = document.createElement('input')
            input.type = 'text'
            input.size = 24
            input.value = variable.toString()
            input.addEventListener('change', function(){
                rep.state[key] = parseFloat(input.value)
                putState(rep)
            })
            li.appendChild(input)
            container.appendChild(li)
            return input
    
        } else {
            console.log("unui'd type:", typeof variable)
        }
    }
    
    function writeEventRep(rep, type, key) {
        var li = document.createElement('li')
        li.innerHTML = key.toString()
        li.id = rep.id + ' ' + type + ' ' + key
        li.addEventListener('click', (evt) => {
            var ipclk = {
                rep: rep,
                type: type,
                name: key,
                evt: evt
            }
            console.log('clicked', key)
            evtConnectHandler(ipclk)
        })
        return li
    
    Jake Read's avatar
    Jake Read committed
    }