diff options
author | Jon Reid | 2012-06-26 14:58:10 -0700 |
---|---|---|
committer | Jon Reid | 2012-06-26 14:58:10 -0700 |
commit | 2599f74d72293b809929d8a0b36fb8e721f194cd (patch) | |
tree | ca4cd45b23b8debea32f95d7dea807c77b6633b2 /js/components/editable.reel | |
parent | ab9d14780eed98f39786fae4518e69861b34bad7 (diff) | |
parent | e4304b9ac6c58802de4dd334be1f5802533f5160 (diff) | |
download | ninja-2599f74d72293b809929d8a0b36fb8e721f194cd.tar.gz |
Merge remote-tracking branch 'ninja-jduran/TimelineUber' into timeline-local
Diffstat (limited to 'js/components/editable.reel')
-rw-r--r-- | js/components/editable.reel/editable.js | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/js/components/editable.reel/editable.js b/js/components/editable.reel/editable.js index 103e418f..88b93b2c 100644 --- a/js/components/editable.reel/editable.js +++ b/js/components/editable.reel/editable.js | |||
@@ -93,12 +93,43 @@ exports.Editable = Montage.create(Component, { | |||
93 | } | 93 | } |
94 | } | 94 | } |
95 | }, | 95 | }, |
96 | |||
97 | _value : { value: null }, | ||
96 | value : { | 98 | value : { |
97 | get: function() { | 99 | get : function() { return this._value; }, |
98 | return this._element.textContent; | 100 | set : function(value) { |
99 | }, | 101 | if(value === this._value) { return; } |
100 | set: function(str) { | 102 | |
101 | this._element.textContent = str; | 103 | var node = this._getFirstTextNode(); |
104 | node.textContent = value; | ||
105 | |||
106 | this._value = value; | ||
107 | } | ||
108 | }, | ||
109 | _getFirstTextNode : { | ||
110 | value : function(el) { | ||
111 | ///// optional el argument specified container element | ||
112 | var e = el || this._element, | ||
113 | nodes = e.childNodes, node; | ||
114 | |||
115 | if(nodes.length) { | ||
116 | for(var i=0; i<nodes.length; i++) { | ||
117 | if(nodes[i].nodeType === 3) { | ||
118 | ///// found the first text node | ||
119 | node = nodes[i]; | ||
120 | break; | ||
121 | } | ||
122 | } | ||
123 | } | ||
124 | |||
125 | ///// Text node not found | ||
126 | if(!node) { | ||
127 | node = document.createTextNode(''); | ||
128 | e.appendChild(node); | ||
129 | } | ||
130 | |||
131 | |||
132 | return node; | ||
102 | } | 133 | } |
103 | }, | 134 | }, |
104 | 135 | ||
@@ -207,6 +238,8 @@ exports.Editable = Montage.create(Component, { | |||
207 | ///// Text input has changed values | 238 | ///// Text input has changed values |
208 | handleInput : { | 239 | handleInput : { |
209 | value : function(e) { | 240 | value : function(e) { |
241 | this.value = this._getFirstTextNode().textContent; | ||
242 | |||
210 | if(!this.isDirty) { | 243 | if(!this.isDirty) { |
211 | this.isDirty = true; | 244 | this.isDirty = true; |
212 | } | 245 | } |
@@ -230,6 +263,8 @@ exports.Editable = Montage.create(Component, { | |||
230 | value: function(e) { | 263 | value: function(e) { |
231 | e.preventDefault(); | 264 | e.preventDefault(); |
232 | document.execCommand('insertHTML', null, e._event.clipboardData.getData("Text")); | 265 | document.execCommand('insertHTML', null, e._event.clipboardData.getData("Text")); |
266 | this.value = this._element.textContent; | ||
267 | |||
233 | this._sendEvent('paste', e); | 268 | this._sendEvent('paste', e); |
234 | } | 269 | } |
235 | }, | 270 | }, |