Sha256: a02e0cfd0b727fdde400d277f98a1e0fb401fe9ee608bc39db93369c06429d80

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

// xlink
var xlinkNS = 'http://www.w3.org/1999/xlink'
var xlinkRE = /^xlink:/

module.exports = {

  priority: 850,

  update: function (value) {
    if (this.arg) {
      this.setAttr(this.arg, value)
    } else if (typeof value === 'object') {
      this.objectHandler(value)
    }
  },

  objectHandler: function (value) {
    // cache object attrs so that only changed attrs
    // are actually updated.
    var cache = this.cache || (this.cache = {})
    var attr, val
    for (attr in cache) {
      if (!(attr in value)) {
        this.setAttr(attr, null)
        delete cache[attr]
      }
    }
    for (attr in value) {
      val = value[attr]
      if (val !== cache[attr]) {
        cache[attr] = val
        this.setAttr(attr, val)
      }
    }
  },

  setAttr: function (attr, value) {
    if (value != null && value !== false) {
      if (xlinkRE.test(attr)) {
        this.el.setAttributeNS(xlinkNS, attr, value)
      } else {
        this.el.setAttribute(attr, value)
      }
    } else {
      this.el.removeAttribute(attr)
    }
    if (attr === 'value' && 'value' in this.el) {
      this.el.value = value
    }
  }
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
plate-lang-0.1.2 skeleton/vendor/vue/src/directives/attr.js
plate-lang-0.1.1 skeleton/vendor/vue/src/directives/attr.js
plate-lang-0.1.0 skeleton/vendor/vue/src/directives/attr.js