11var utils = require ( '../utils' ) ,
22 config = require ( '../config' ) ,
3- transition = require ( '../transition' )
3+ transition = require ( '../transition' ) ,
4+ directives = module . exports = utils . hash ( )
45
5- module . exports = {
6-
7- on : require ( './on' ) ,
8- repeat : require ( './repeat' ) ,
9- model : require ( './model' ) ,
10- 'if' : require ( './if' ) ,
11- 'with' : require ( './with' ) ,
12- html : require ( './html' ) ,
13- style : require ( './style' ) ,
14- partial : require ( './partial' ) ,
15- view : require ( './view' ) ,
16-
17- component : {
18- isLiteral : true ,
19- bind : function ( ) {
20- if ( ! this . el . vue_vm ) {
21- this . childVM = new this . Ctor ( {
22- el : this . el ,
23- parent : this . vm
24- } )
25- }
26- } ,
27- unbind : function ( ) {
28- if ( this . childVM ) {
29- this . childVM . $destroy ( )
30- }
6+ /**
7+ * Nest and manage a Child VM
8+ */
9+ directives . component = {
10+ isLiteral : true ,
11+ bind : function ( ) {
12+ if ( ! this . el . vue_vm ) {
13+ this . childVM = new this . Ctor ( {
14+ el : this . el ,
15+ parent : this . vm
16+ } )
3117 }
3218 } ,
33-
34- attr : {
35- bind : function ( ) {
36- var params = this . vm . $options . paramAttributes
37- this . isParam = params && params . indexOf ( this . arg ) > - 1
38- } ,
39- update : function ( value ) {
40- if ( value || value === 0 ) {
41- this . el . setAttribute ( this . arg , value )
42- } else {
43- this . el . removeAttribute ( this . arg )
44- }
45- if ( this . isParam ) {
46- this . vm [ this . arg ] = utils . checkNumber ( value )
47- }
19+ unbind : function ( ) {
20+ if ( this . childVM ) {
21+ this . childVM . $destroy ( )
4822 }
49- } ,
23+ }
24+ }
5025
51- text : {
52- bind : function ( ) {
53- this . attr = this . el . nodeType === 3
54- ? 'nodeValue'
55- : 'textContent'
56- } ,
57- update : function ( value ) {
58- this . el [ this . attr ] = utils . guard ( value )
59- }
26+ /**
27+ * Binding HTML attributes
28+ */
29+ directives . attr = {
30+ bind : function ( ) {
31+ var params = this . vm . $options . paramAttributes
32+ this . isParam = params && params . indexOf ( this . arg ) > - 1
6033 } ,
34+ update : function ( value ) {
35+ if ( value || value === 0 ) {
36+ this . el . setAttribute ( this . arg , value )
37+ } else {
38+ this . el . removeAttribute ( this . arg )
39+ }
40+ if ( this . isParam ) {
41+ this . vm [ this . arg ] = utils . checkNumber ( value )
42+ }
43+ }
44+ }
6145
62- show : function ( value ) {
63- var el = this . el ,
64- target = value ? '' : 'none' ,
65- change = function ( ) {
66- el . style . display = target
67- }
68- transition ( el , value ? 1 : - 1 , change , this . compiler )
46+ /**
47+ * Binding textContent
48+ */
49+ directives . text = {
50+ bind : function ( ) {
51+ this . attr = this . el . nodeType === 3
52+ ? 'nodeValue'
53+ : 'textContent'
6954 } ,
55+ update : function ( value ) {
56+ this . el [ this . attr ] = utils . guard ( value )
57+ }
58+ }
7059
71- 'class' : function ( value ) {
72- if ( this . arg ) {
73- utils [ value ? 'addClass' : 'removeClass' ] ( this . el , this . arg )
74- } else {
75- if ( this . lastVal ) {
76- utils . removeClass ( this . el , this . lastVal )
77- }
78- if ( value ) {
79- utils . addClass ( this . el , value )
80- this . lastVal = value
81- }
60+ /**
61+ * Binding CSS display property
62+ */
63+ directives . show = function ( value ) {
64+ var el = this . el ,
65+ target = value ? '' : 'none' ,
66+ change = function ( ) {
67+ el . style . display = target
8268 }
83- } ,
69+ transition ( el , value ? 1 : - 1 , change , this . compiler )
70+ }
8471
85- cloak : {
86- isEmpty : true ,
87- bind : function ( ) {
88- var el = this . el
89- this . compiler . observer . once ( 'hook:ready' , function ( ) {
90- el . removeAttribute ( config . prefix + '-cloak' )
91- } )
72+ /**
73+ * Binding CSS classes
74+ */
75+ directives [ 'class' ] = function ( value ) {
76+ if ( this . arg ) {
77+ utils [ value ? 'addClass' : 'removeClass' ] ( this . el , this . arg )
78+ } else {
79+ if ( this . lastVal ) {
80+ utils . removeClass ( this . el , this . lastVal )
9281 }
93- } ,
82+ if ( value ) {
83+ utils . addClass ( this . el , value )
84+ this . lastVal = value
85+ }
86+ }
87+ }
88+
89+ /**
90+ * Only removed after the owner VM is ready
91+ */
92+ directives . cloak = {
93+ isEmpty : true ,
94+ bind : function ( ) {
95+ var el = this . el
96+ this . compiler . observer . once ( 'hook:ready' , function ( ) {
97+ el . removeAttribute ( config . prefix + '-cloak' )
98+ } )
99+ }
100+ }
94101
95- ref : {
96- isLiteral : true ,
97- bind : function ( ) {
98- var id = this . expression
99- if ( id ) {
100- this . vm . $parent . $ [ id ] = this . vm
101- }
102- } ,
103- unbind : function ( ) {
104- var id = this . expression
105- if ( id ) {
106- delete this . vm . $parent . $ [ id ]
107- }
102+ /**
103+ * Store a reference to self in parent VM's $
104+ */
105+ directives . ref = {
106+ isLiteral : true ,
107+ bind : function ( ) {
108+ var id = this . expression
109+ if ( id ) {
110+ this . vm . $parent . $ [ id ] = this . vm
111+ }
112+ } ,
113+ unbind : function ( ) {
114+ var id = this . expression
115+ if ( id ) {
116+ delete this . vm . $parent . $ [ id ]
108117 }
109118 }
119+ }
110120
111- }
121+ directives . on = require ( './on' )
122+ directives . repeat = require ( './repeat' )
123+ directives . model = require ( './model' )
124+ directives [ 'if' ] = require ( './if' )
125+ directives [ 'with' ] = require ( './with' )
126+ directives . html = require ( './html' )
127+ directives . style = require ( './style' )
128+ directives . partial = require ( './partial' )
129+ directives . view = require ( './view' )
0 commit comments