all files / directives/duplex/ option.js

100% Statements 30/30
90.91% Branches 20/22
100% Functions 7/7
100% Lines 30/30
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 471× 125× 188× 85×   103×         1× 85× 85× 85× 85× 85× 83×         1× 92× 8×   84× 84× 84× 83× 1× 1×     84×     1× 30× 89× 39× 6× 50× 20×     30×  
export function lookupOption(vdom, values) {
   vdom.children && vdom.children.forEach(function (el) {
        if (el.nodeName === 'option') {
            setOption(el, values)
        } else {
            lookupOption(el, values)
        } 
    })
}
 
function setOption(vdom, values) {
    var props = vdom.props
    Eif (!('disabled' in props)) {
        var value = getOptionValue(vdom, props).trim()
        props.selected = values.indexOf(value) !== -1
        if (vdom.dom) {
            vdom.dom.selected = props.selected
        }
    }
}
 
function getOptionValue(vdom, props) {
    if (props && 'value' in props) {
        return props.value
    }
    var arr = []
    vdom.children.forEach(function (el) {
        if (el.nodeName === '#text') {
            arr.push(el.nodeValue)
        } else Eif (el.nodeName === '#document-fragment') {
            arr.push(getOptionValue(el))
        }
    })
    return arr.join('')
}
 
export function getSelectedValue(vdom, arr) {
    vdom.children.forEach(function (el) {
        if (el.nodeName === 'option') {
            if(el.props.selected === true)
               arr.push(getOptionValue(el, el.props))
        } else if (el.children) {
            getSelectedValue(el,arr)
        }
    })
    return arr
}