Skip to content

Commit 1d85fcb

Browse files
committed
IE should prefer all bound props other than class
1 parent d2821b0 commit 1d85fcb

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-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: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ var empty = {}
88
var identRE = require('../parsers/path').identRE
99
var settablePathRE = /^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*|\[[^\[\]]+\])*$/
1010

11+
// feature detect browsers (IE) that have trouble
12+
// with binding syntax on certain attributes
13+
var div, preferBinding
14+
if (_.inBrowser) {
15+
div = document.createElement('div')
16+
div.setAttribute(':title', '')
17+
preferBinding = div.getAttribute('title') !== null
18+
}
19+
1120
/**
1221
* Compile props on a root element and return
1322
* a props link function.
@@ -21,7 +30,7 @@ module.exports = function compileProps (el, propOptions) {
2130
var props = []
2231
var names = Object.keys(propOptions)
2332
var i = names.length
24-
var options, name, attr, value, path, parsed, prop, isTitleBinding
33+
var options, name, attr, value, path, parsed, prop, hasBinding
2534
while (i--) {
2635
name = names[i]
2736
options = propOptions[name] || empty
@@ -50,16 +59,12 @@ module.exports = function compileProps (el, propOptions) {
5059
mode: propBindingModes.ONE_WAY
5160
}
5261

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

5965
// first check literal version
60-
attr = _.hyphenate(name)
6166
value = prop.raw = _.attr(el, attr)
62-
if (value === null || isTitleBinding) {
67+
if (value === null || hasBinding) {
6368
// then check dynamic version
6469
if ((value = _.getBindAttr(el, attr)) === null) {
6570
if ((value = _.getBindAttr(el, attr + '.sync')) !== null) {
@@ -119,6 +124,28 @@ module.exports = function compileProps (el, propOptions) {
119124
return makePropsLinkFn(props)
120125
}
121126

127+
/**
128+
* Check existance of an attribute with binding syntax.
129+
*
130+
* @param {Element} el
131+
* @return {String} attr
132+
*/
133+
134+
function checkBindingAttr (el, attr) {
135+
if (attr === 'class') {
136+
return null
137+
}
138+
139+
return (
140+
el.getAttribute(':' + attr) ||
141+
el.getAttribute(':' + attr + '.once') ||
142+
el.getAttribute(':' + attr + '.sync') ||
143+
el.getAttribute('v-bind:' + attr) ||
144+
el.getAttribute('v-bind:' + attr + '.once') ||
145+
el.getAttribute('v-bind:' + attr + '.sync')
146+
)
147+
}
148+
122149
/**
123150
* Build a function that applies props to a vm.
124151
*

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)