Skip to content

Commit dbed18e

Browse files
committed
support colon shorthand syntax for bind-
1 parent 737a85d commit dbed18e

File tree

12 files changed

+61
-49
lines changed

12 files changed

+61
-49
lines changed

examples/commits/index.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ <h1>Latest Vue.js Commits</h1>
2626
<template v-for="branch in branches">
2727
<input type="radio"
2828
name="branch"
29-
bind-id="branch"
30-
bind-value="branch"
29+
:id="branch"
30+
:value="branch"
3131
v-model="currentBranch">
32-
<label bind-for="branch">{{branch}}</label>
32+
<label :for="branch">{{branch}}</label>
3333
</template>
3434
<p>yyx990803/vue@{{currentBranch}}</p>
3535
<ul>
3636
<li v-for="record in commits">
37-
<a bind-href="record.html_url" target="_blank" class="commit">{{record.sha.slice(0, 7)}}</a>
37+
<a :href="record.html_url" target="_blank" class="commit">{{record.sha.slice(0, 7)}}</a>
3838
- <span class="message">{{record.commit.message | truncate}}</span><br>
3939
by <span class="author">{{record.commit.author.name}}</span>
4040
at <span class="date">{{record.commit.author.date | formatDate}}</span>

examples/grid/index.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
<tr>
1616
<th v-for="key in columns"
1717
on-click="sortBy(key)"
18-
bind-class="{active: sortKey == key}">
18+
:class="{active: sortKey == key}">
1919
{{key | capitalize}}
2020
<span class="arrow"
21-
bind-class="reversed[key] ? 'dsc' : 'asc'">
21+
:class="reversed[key] ? 'dsc' : 'asc'">
2222
</span>
2323
</th>
2424
</tr>
@@ -42,9 +42,9 @@
4242
Search <input name="query" v-model="searchQuery">
4343
</form>
4444
<demo-grid
45-
bind-data="gridData"
46-
bind-columns="gridColumns"
47-
bind-filter-key="searchQuery">
45+
:data="gridData"
46+
:columns="gridColumns"
47+
:filter-key="searchQuery">
4848
</demo-grid>
4949
</div>
5050

examples/modal/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<div id="app">
5858
<button id="show-modal" on-click="showModal = true">Show Modal</button>
5959
<!-- use the modal component, pass in the prop -->
60-
<modal bind-show="@showModal">
60+
<modal :show="@showModal">
6161
<!--
6262
you can use custom content here to overwrite
6363
default content

examples/svg/index.html

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@
1111
<!-- template for the polygraph component. -->
1212
<script type="text/x-template" id="polygraph-template">
1313
<g>
14-
<polygon bind-points="points"></polygon>
14+
<polygon :points="points"></polygon>
1515
<circle cx="100" cy="100" r="80"></circle>
1616
<axis-label
1717
v-for="stat in stats"
18-
bind-stat="stat"
19-
bind-index="$index"
20-
bind-total="stats.length">
18+
:stat="stat"
19+
:index="$index"
20+
:total="stats.length">
2121
</axis-label>
2222
</g>
2323
</script>
2424

2525
<!-- template for the axis label component. -->
2626
<script type="text/x-template" id="axis-label-template">
27-
<text bind-x="point.x" bind-y="point.y">{{stat.label}}</text>
27+
<text :x="point.x" :y="point.y">{{stat.label}}</text>
2828
</script>
2929

3030
<!-- demo root element -->
3131
<div id="demo">
3232
<!-- Use the component -->
3333
<svg width="200" height="200">
34-
<polygraph bind-stats="stats"></polygraph>
34+
<polygraph :stats="stats"></polygraph>
3535
</svg>
3636
<!-- controls -->
3737
<div v-for="stat in stats">

examples/todomvc/index.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ <h1>todos</h1>
2121
<ul class="todo-list">
2222
<li class="todo"
2323
v-for="todo in filteredTodos"
24-
bind-class="{completed: todo.completed, editing: todo == editedTodo}">
24+
:class="{completed: todo.completed, editing: todo == editedTodo}">
2525
<div class="view">
2626
<input class="toggle" type="checkbox" v-model="todo.completed">
2727
<label on-dblclick="editTodo(todo)">{{todo.title}}</label>
@@ -41,9 +41,9 @@ <h1>todos</h1>
4141
<strong v-text="remaining"></strong> {{remaining | pluralize 'item'}} left
4242
</span>
4343
<ul class="filters">
44-
<li><a href="#/all" bind-class="{selected: visibility == 'all'}">All</a></li>
45-
<li><a href="#/active" bind-class="{selected: visibility == 'active'}">Active</a></li>
46-
<li><a href="#/completed" bind-class="{selected: visibility == 'completed'}">Completed</a></li>
44+
<li><a href="#/all" :class="{selected: visibility == 'all'}">All</a></li>
45+
<li><a href="#/active" :class="{selected: visibility == 'active'}">Active</a></li>
46+
<li><a href="#/completed" :class="{selected: visibility == 'completed'}">Completed</a></li>
4747
</ul>
4848
<button class="clear-completed" on-click="removeCompleted" v-show="todos.length > remaining">
4949
Clear completed

examples/tree/index.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<script type="text/x-template" id="item-template">
2929
<li>
3030
<div
31-
bind-class="{bold: isFolder}"
31+
:class="{bold: isFolder}"
3232
on-click="toggle"
3333
on-dblclick="changeType">
3434
{{model.name}}
@@ -38,7 +38,7 @@
3838
<item
3939
class="item"
4040
v-for="model in model.children"
41-
bind-model="model">
41+
:model="model">
4242
</item>
4343
<li on-click="addChild">+</li>
4444
</ul>
@@ -51,7 +51,7 @@
5151
<ul id="demo">
5252
<item
5353
class="item"
54-
bind-model="treeData">
54+
:model="treeData">
5555
</item>
5656
</ul>
5757

src/compiler/compile-props.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ module.exports = function compileProps (el, propOptions) {
5858
el.removeAttribute(attr)
5959
} else {
6060
// then check dynamic version
61-
attr = 'bind-' + attr
62-
value = prop.raw = el.getAttribute(attr)
61+
value = prop.raw = _.getBindAttr(el, attr)
6362
if (value !== null) {
64-
el.removeAttribute(attr)
6563
parsed = dirParser.parse(value)
6664
value = parsed.expression
6765
prop.filters = parsed.filters

src/compiler/compile.js

+13-18
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var resolveAsset = _.resolveAsset
1111
// special binding prefixes
1212
var bindRE = /^bind-|^:/
1313
var onRE = /^on-/
14+
var specialAttrRE = /^(bind-|:)?(el|transition)$/
1415

1516
// terminal directives
1617
var terminalDirectives = [
@@ -565,37 +566,31 @@ function compileDirectives (attrs, options) {
565566
}
566567
} else
567568

568-
// special case for el
569-
if (name === 'el' || name === 'bind-el') {
570-
pushDir('el', internalDirectives.el, {
571-
literal: !bindRE.test(name)
569+
// event handlers
570+
if (onRE.test(name)) {
571+
pushDir('on', internalDirectives.on, {
572+
arg: name.replace(onRE, '')
572573
})
573574
} else
574575

575-
// special case for transition
576-
if (name === 'transition' || name === 'bind-transition') {
577-
pushDir('transition', internalDirectives.transition, {
576+
// special attribtues: transition & el
577+
if (specialAttrRE.test(name)) {
578+
dirName = name.replace(bindRE, '')
579+
pushDir(dirName, internalDirectives[dirName], {
578580
literal: !bindRE.test(name)
579581
})
580582
} else
581583

582584
// attribute bindings
583585
if (bindRE.test(name)) {
584-
var attributeName = name.replace(bindRE, '')
585-
if (attributeName === 'style' || attributeName === 'class') {
586-
pushDir(attributeName, internalDirectives[attributeName])
586+
dirName = name.replace(bindRE, '')
587+
if (dirName === 'style' || dirName === 'class') {
588+
pushDir(dirName, internalDirectives[dirName])
587589
} else {
588590
pushDir('attr', internalDirectives.attr, {
589-
arg: attributeName
591+
arg: dirName
590592
})
591593
}
592-
} else
593-
594-
// event handlers
595-
if (onRE.test(name)) {
596-
pushDir('on', internalDirectives.on, {
597-
arg: name.replace(onRE, '')
598-
})
599594
}
600595
}
601596

src/directive.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,8 @@ Directive.prototype.param = function (name) {
165165
this.el.removeAttribute(name)
166166
param = (this._scope || this.vm).$interpolate(param)
167167
} else {
168-
param = this.el.getAttribute('bind-' + name)
168+
param = _.getBindAttr(this.el, name)
169169
if (param != null) {
170-
this.el.removeAttribute('bind-' + name)
171170
param = (this._scope || this.vm).$eval(param)
172171
process.env.NODE_ENV !== 'production' && _.log(
173172
'You are using bind- syntax on "' + name + '", which ' +

src/directives/element/partial.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = {
1515
// static partial
1616
this.insert(id)
1717
} else {
18-
id = el.getAttribute('bind-name')
18+
id = _.getBindAttr(el, 'name')
1919
if (id) {
2020
this.setupDynamic(id)
2121
}

src/util/component.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ exports.checkComponent = function (el, options) {
1919
el.removeAttribute('is')
2020
return { id: exp }
2121
} else {
22-
exp = el.getAttribute('bind-is')
22+
exp = _.getBindAttr(el, 'is')
2323
if (exp != null) {
24-
el.removeAttribute('bind-is')
2524
return { id: exp, dynamic: true }
2625
}
2726
}

src/util/dom.js

+21
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,27 @@ exports.attr = function (node, attr) {
5757
return val
5858
}
5959

60+
/**
61+
* Get an attribute with colon or bind- prefix.
62+
*
63+
* @param {Node} node
64+
* @param {String} name
65+
* @return {String|null}
66+
*/
67+
68+
exports.getBindAttr = function (node, name) {
69+
var attr = ':' + name
70+
var val = node.getAttribute(attr)
71+
if (val === null) {
72+
attr = 'bind-' + name
73+
val = node.getAttribute(attr)
74+
}
75+
if (val !== null) {
76+
node.removeAttribute(attr)
77+
}
78+
return val
79+
}
80+
6081
/**
6182
* Insert el before target
6283
*

0 commit comments

Comments
 (0)