Merge branch 'ie-polyfills-and-fixes'
Showing
2 changed files
with
32 additions
and
7 deletions
... | @@ -6,6 +6,12 @@ | ... | @@ -6,6 +6,12 @@ |
6 | 6 | ||
7 | Rivets = {}; | 7 | Rivets = {}; |
8 | 8 | ||
9 | if (!String.prototype.trim) { | ||
10 | String.prototype.trim = function() { | ||
11 | return this.replace(/^\s+|\s+$/g, ""); | ||
12 | }; | ||
13 | } | ||
14 | |||
9 | Rivets.Binding = (function() { | 15 | Rivets.Binding = (function() { |
10 | 16 | ||
11 | function Binding(el, type, model, keypath, formatters) { | 17 | function Binding(el, type, model, keypath, formatters) { |
... | @@ -40,7 +46,11 @@ | ... | @@ -40,7 +46,11 @@ |
40 | this.set(Rivets.config.adapter.read(this.model, this.keypath)); | 46 | this.set(Rivets.config.adapter.read(this.model, this.keypath)); |
41 | } | 47 | } |
42 | if (_ref = this.type, __indexOf.call(bidirectionals, _ref) >= 0) { | 48 | if (_ref = this.type, __indexOf.call(bidirectionals, _ref) >= 0) { |
43 | return this.el.addEventListener('change', this.publish); | 49 | if (window.addEventListener) { |
50 | return this.el.addEventListener('change', this.publish); | ||
51 | } else { | ||
52 | return this.el.attachEvent('change', this.publish); | ||
53 | } | ||
44 | } | 54 | } |
45 | }; | 55 | }; |
46 | 56 | ||
... | @@ -79,7 +89,7 @@ | ... | @@ -79,7 +89,7 @@ |
79 | }; | 89 | }; |
80 | 90 | ||
81 | View.prototype.build = function() { | 91 | View.prototype.build = function() { |
82 | var attribute, bindingRegExp, keypath, model, node, path, pipes, type, _i, _len, _ref, _results; | 92 | var attribute, bindingRegExp, keypath, model, node, path, pipe, pipes, type, _i, _len, _ref, _results; |
83 | this.bindings = []; | 93 | this.bindings = []; |
84 | bindingRegExp = this.bindingRegExp(); | 94 | bindingRegExp = this.bindingRegExp(); |
85 | _ref = this.el.getElementsByTagName('*'); | 95 | _ref = this.el.getElementsByTagName('*'); |
... | @@ -94,9 +104,16 @@ | ... | @@ -94,9 +104,16 @@ |
94 | attribute = _ref1[_j]; | 104 | attribute = _ref1[_j]; |
95 | if (bindingRegExp.test(attribute.name)) { | 105 | if (bindingRegExp.test(attribute.name)) { |
96 | type = attribute.name.replace(bindingRegExp, ''); | 106 | type = attribute.name.replace(bindingRegExp, ''); |
97 | pipes = attribute.value.split('|').map(function(pipe) { | 107 | pipes = (function() { |
98 | return pipe.trim(); | 108 | var _k, _len2, _ref2, _results2; |
99 | }); | 109 | _ref2 = attribute.value.split('|'); |
110 | _results2 = []; | ||
111 | for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { | ||
112 | pipe = _ref2[_k]; | ||
113 | _results2.push(pipe.trim()); | ||
114 | } | ||
115 | return _results2; | ||
116 | })(); | ||
100 | path = pipes.shift().split('.'); | 117 | path = pipes.shift().split('.'); |
101 | model = this.models[path.shift()]; | 118 | model = this.models[path.shift()]; |
102 | keypath = path.join('.'); | 119 | keypath = path.join('.'); | ... | ... |
... | @@ -6,6 +6,9 @@ | ... | @@ -6,6 +6,9 @@ |
6 | # The Rivets namespace. | 6 | # The Rivets namespace. |
7 | Rivets = {} | 7 | Rivets = {} |
8 | 8 | ||
9 | # Polyfill For String::trim. | ||
10 | unless String::trim then String::trim = -> @replace /^\s+|\s+$/g, "" | ||
11 | |||
9 | # A single binding between a model attribute and a DOM element. | 12 | # A single binding between a model attribute and a DOM element. |
10 | class Rivets.Binding | 13 | class Rivets.Binding |
11 | # All information about the binding is passed into the constructor; the DOM | 14 | # All information about the binding is passed into the constructor; the DOM |
... | @@ -32,7 +35,12 @@ class Rivets.Binding | ... | @@ -32,7 +35,12 @@ class Rivets.Binding |
32 | @set Rivets.config.adapter.read @model, @keypath | 35 | @set Rivets.config.adapter.read @model, @keypath |
33 | 36 | ||
34 | if @type in bidirectionals | 37 | if @type in bidirectionals |
35 | @el.addEventListener 'change', @publish | 38 | # Check to see if addEventListener is available. |
39 | if window.addEventListener | ||
40 | @el.addEventListener 'change', @publish | ||
41 | else | ||
42 | # Assume we are in IE and use attachEvent. | ||
43 | @el.attachEvent 'change', @publish | ||
36 | 44 | ||
37 | # Publishes the value currently set on the input element back to the model. | 45 | # Publishes the value currently set on the input element back to the model. |
38 | publish: (e) => | 46 | publish: (e) => |
... | @@ -60,7 +68,7 @@ class Rivets.View | ... | @@ -60,7 +68,7 @@ class Rivets.View |
60 | for attribute in node.attributes | 68 | for attribute in node.attributes |
61 | if bindingRegExp.test attribute.name | 69 | if bindingRegExp.test attribute.name |
62 | type = attribute.name.replace bindingRegExp, '' | 70 | type = attribute.name.replace bindingRegExp, '' |
63 | pipes = attribute.value.split('|').map (pipe) -> pipe.trim() | 71 | pipes = (pipe.trim() for pipe in attribute.value.split '|') |
64 | path = pipes.shift().split '.' | 72 | path = pipes.shift().split '.' |
65 | model = @models[path.shift()] | 73 | model = @models[path.shift()] |
66 | keypath = path.join '.' | 74 | keypath = path.join '.' | ... | ... |
-
Please register or sign in to post a comment