Skip to content

Commit 474da3d

Browse files
committed
Merge pull request #1703 from fergaldoyle/dev
IE should prefer bound props over static props other than class
2 parents 7244c69 + ccec915 commit 474da3d

File tree

4 files changed

+42
-9
lines changed

4 files changed

+42
-9
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"karma-commonjs": "^0.0.13",
4343
"karma-coverage": "^0.5.0",
4444
"karma-firefox-launcher": "^0.1.6",
45+
"karma-ie-launcher": "^0.2.0",
4546
"karma-jasmine": "^0.3.6",
4647
"karma-phantomjs-launcher": "^0.2.1",
4748
"karma-safari-launcher": "^0.1.1",

src/compiler/compile-props.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = function compileProps (el, propOptions) {
2121
var props = []
2222
var names = Object.keys(propOptions)
2323
var i = names.length
24-
var options, name, attr, value, path, parsed, prop, isTitleBinding
24+
var options, name, attr, value, path, parsed, prop, hasBinding
2525
while (i--) {
2626
name = names[i]
2727
options = propOptions[name] || empty
@@ -50,16 +50,12 @@ module.exports = function compileProps (el, propOptions) {
5050
mode: propBindingModes.ONE_WAY
5151
}
5252

53-
// IE title issues
54-
isTitleBinding = false
55-
if (name === 'title' && (el.getAttribute(':title') || el.getAttribute('v-bind:title'))) {
56-
isTitleBinding = true
57-
}
53+
attr = _.hyphenate(name)
54+
hasBinding = _.preferBinding && hasBindingAttr(el, attr)
5855

5956
// first check literal version
60-
attr = _.hyphenate(name)
6157
value = prop.raw = _.attr(el, attr)
62-
if (value === null || isTitleBinding) {
58+
if (value === null || hasBinding) {
6359
// then check dynamic version
6460
if ((value = _.getBindAttr(el, attr)) === null) {
6561
if ((value = _.getBindAttr(el, attr + '.sync')) !== null) {
@@ -119,6 +115,24 @@ module.exports = function compileProps (el, propOptions) {
119115
return makePropsLinkFn(props)
120116
}
121117

118+
/**
119+
* Check existance of an attribute with binding syntax.
120+
*
121+
* @param {Element} el
122+
* @return {String} attr
123+
*/
124+
125+
function hasBindingAttr (el, attr) {
126+
if (attr === 'class') {
127+
return false
128+
}
129+
130+
return (
131+
el.hasAttribute(':' + attr) ||
132+
el.hasAttribute('v-bind:' + attr)
133+
)
134+
}
135+
122136
/**
123137
* Build a function that applies props to a vm.
124138
*

src/util/env.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,14 @@ exports.nextTick = (function () {
8383
timerFunc(nextTickHandler, 0)
8484
}
8585
})()
86+
87+
// feature detect browsers (IE) that have trouble
88+
// with binding syntax on certain attributes
89+
var div
90+
var preferBinding = false
91+
if (inBrowser) {
92+
div = document.createElement('div')
93+
div.setAttribute(':title', '')
94+
preferBinding = div.getAttribute('title') !== null
95+
}
96+
exports.preferBinding = preferBinding

test/unit/specs/misc_spec.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ describe('Misc', function () {
270270
expect(hasWarned(__, 'Unknown custom element')).toBe(true)
271271
})
272272

273-
it('prefer bound title over static title', function (done) {
273+
it('prefer bound attributes over static attributes', function (done) {
274274
var el = document.createElement('div')
275275
var count = 0
276276
var expected = [
@@ -289,6 +289,13 @@ describe('Misc', function () {
289289
}
290290

291291
document.body.appendChild(el)
292+
293+
el.setAttribute(':title', '')
294+
if(el.getAttribute('title') === null) {
295+
// this browser does not need this test
296+
done()
297+
return
298+
}
292299

293300
new Vue({
294301
el: el,

0 commit comments

Comments
 (0)