Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IE should prefer bound props over static props other than class #1703

Merged
merged 3 commits into from
Nov 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 22 additions & 8 deletions src/compiler/compile-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
*
Expand Down
11 changes: 11 additions & 0 deletions src/util/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 8 additions & 1 deletion test/unit/specs/misc_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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,
Expand Down