diff --git a/package.json b/package.json index 2ace33e465b..bd480f71abc 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "karma-commonjs": "^0.0.13", "karma-coverage": "^0.5.0", "karma-firefox-launcher": "^0.1.6", + "karma-ie-launcher": "^0.2.0", "karma-jasmine": "^0.3.6", "karma-phantomjs-launcher": "^0.2.1", "karma-safari-launcher": "^0.1.1", diff --git a/src/compiler/compile-props.js b/src/compiler/compile-props.js index 231c6c4b3e8..8173d2935b8 100644 --- a/src/compiler/compile-props.js +++ b/src/compiler/compile-props.js @@ -21,7 +21,7 @@ module.exports = function compileProps (el, propOptions) { var props = [] var names = Object.keys(propOptions) var i = names.length - var options, name, attr, value, path, parsed, prop, isTitleBinding + var options, name, attr, value, path, parsed, prop, hasBinding while (i--) { name = names[i] options = propOptions[name] || empty @@ -50,16 +50,12 @@ module.exports = function compileProps (el, propOptions) { mode: propBindingModes.ONE_WAY } - // IE title issues - isTitleBinding = false - if (name === 'title' && (el.getAttribute(':title') || el.getAttribute('v-bind:title'))) { - isTitleBinding = true - } + attr = _.hyphenate(name) + hasBinding = _.preferBinding && hasBindingAttr(el, attr) // first check literal version - attr = _.hyphenate(name) value = prop.raw = _.attr(el, attr) - if (value === null || isTitleBinding) { + if (value === null || hasBinding) { // then check dynamic version if ((value = _.getBindAttr(el, attr)) === null) { if ((value = _.getBindAttr(el, attr + '.sync')) !== null) { @@ -119,6 +115,24 @@ module.exports = function compileProps (el, propOptions) { return makePropsLinkFn(props) } +/** + * Check existance of an attribute with binding syntax. + * + * @param {Element} el + * @return {String} attr + */ + +function hasBindingAttr (el, attr) { + if (attr === 'class') { + return false + } + + return ( + el.hasAttribute(':' + attr) || + el.hasAttribute('v-bind:' + attr) + ) +} + /** * Build a function that applies props to a vm. * diff --git a/src/util/env.js b/src/util/env.js index 065ba465434..f804eadda25 100644 --- a/src/util/env.js +++ b/src/util/env.js @@ -83,3 +83,14 @@ exports.nextTick = (function () { timerFunc(nextTickHandler, 0) } })() + +// feature detect browsers (IE) that have trouble +// with binding syntax on certain attributes +var div +var preferBinding = false +if (inBrowser) { + div = document.createElement('div') + div.setAttribute(':title', '') + preferBinding = div.getAttribute('title') !== null +} +exports.preferBinding = preferBinding diff --git a/test/unit/specs/misc_spec.js b/test/unit/specs/misc_spec.js index dce78e904e3..46a401ce91d 100644 --- a/test/unit/specs/misc_spec.js +++ b/test/unit/specs/misc_spec.js @@ -270,7 +270,7 @@ describe('Misc', function () { expect(hasWarned(__, 'Unknown custom element')).toBe(true) }) - it('prefer bound title over static title', function (done) { + it('prefer bound attributes over static attributes', function (done) { var el = document.createElement('div') var count = 0 var expected = [ @@ -289,6 +289,13 @@ describe('Misc', function () { } document.body.appendChild(el) + + el.setAttribute(':title', '') + if(el.getAttribute('title') === null) { + // this browser does not need this test + done() + return + } new Vue({ el: el,