b2eb4729 by Paul Jones

Support passing multiple elements to Rivets.View

1 parent 3e37aba8
...@@ -90,6 +90,16 @@ describe('Functional', function() { ...@@ -90,6 +90,16 @@ describe('Functional', function() {
90 expect(input.value).toBe(data.get('foo')); 90 expect(input.value).toBe(data.get('foo'));
91 }); 91 });
92 }); 92 });
93
94 describe('Multiple', function() {
95 it('should bind a list of multiple elements', function() {
96 el.setAttribute('data-html', 'data.foo');
97 input.setAttribute('data-value', 'data.foo');
98 rivets.bind([el, input], bindData);
99 expect(el).toHaveTheTextContent(data.get('foo'));
100 expect(input.value).toBe(data.get('foo'));
101 });
102 });
93 }); 103 });
94 104
95 describe('Updates', function() { 105 describe('Updates', function() {
......
...@@ -69,8 +69,8 @@ class Rivets.Binding ...@@ -69,8 +69,8 @@ class Rivets.Binding
69 class Rivets.View 69 class Rivets.View
70 # The parent DOM element and the model objects for binding are passed into the 70 # The parent DOM element and the model objects for binding are passed into the
71 # constructor. 71 # constructor.
72 constructor: (@el, @models) -> 72 constructor: (@els, @models) ->
73 @el = @el.get(0) if @el.jquery 73 @els = [@els] unless (@els.jquery || @els instanceof Array)
74 @build() 74 @build()
75 75
76 # Regular expression used to match binding attributes. 76 # Regular expression used to match binding attributes.
...@@ -102,8 +102,9 @@ class Rivets.View ...@@ -102,8 +102,9 @@ class Rivets.View
102 102
103 @bindings.push new Rivets.Binding node, type, bindType, model, keypath, pipes 103 @bindings.push new Rivets.Binding node, type, bindType, model, keypath, pipes
104 104
105 parseNode @el 105 for el in @els
106 parseNode node for node in @el.getElementsByTagName '*' 106 parseNode el
107 parseNode node for node in el.getElementsByTagName '*'
107 108
108 # Binds all of the current bindings for this view. 109 # Binds all of the current bindings for this view.
109 bind: => 110 bind: =>
......