|
141 | 141 | this.element = this.doc.body; |
142 | 142 | this.textarea = this.parent.textarea; |
143 | 143 | this.element.innerHTML = this.textarea.getValue(true); |
144 | | - this.enable(); |
145 | 144 |
|
146 | 145 | // Make sure our selection handler is ready |
147 | 146 | this.selection = new wysihtml5.Selection(this.parent); |
148 | 147 |
|
149 | 148 | // Make sure commands dispatcher is ready |
150 | 149 | this.commands = new wysihtml5.Commands(this.parent); |
151 | | - |
| 150 | + |
152 | 151 | dom.copyAttributes([ |
153 | 152 | "className", "spellcheck", "title", "lang", "dir", "accessKey" |
154 | 153 | ]).from(this.textarea.element).to(this.element); |
155 | 154 |
|
156 | 155 | dom.addClass(this.element, this.config.composerClassName); |
157 | | - |
158 | | - // Make the editor look like the original textarea, by syncing styles |
| 156 | + // |
| 157 | + // // Make the editor look like the original textarea, by syncing styles |
159 | 158 | if (this.config.style) { |
160 | 159 | this.style(); |
161 | 160 | } |
162 | | - |
| 161 | + |
163 | 162 | this.observe(); |
164 | | - |
| 163 | + |
165 | 164 | var name = this.config.name; |
166 | 165 | if (name) { |
167 | 166 | dom.addClass(this.element, name); |
168 | 167 | dom.addClass(this.iframe, name); |
169 | 168 | } |
170 | 169 |
|
| 170 | + this.enable(); |
| 171 | + |
171 | 172 | if (this.textarea.element.disabled) { |
172 | 173 | this.disable(); |
173 | 174 | } |
|
182 | 183 |
|
183 | 184 | // Make sure that the browser avoids using inline styles whenever possible |
184 | 185 | this.commands.exec("styleWithCSS", false); |
185 | | - |
| 186 | + |
186 | 187 | this._initAutoLinking(); |
187 | 188 | this._initObjectResizing(); |
188 | 189 | this._initUndoManager(); |
189 | | - |
| 190 | + |
190 | 191 | // Simulate html5 autofocus on contentEditable element |
191 | 192 | // This doesn't work on IOS (5.1.1) |
192 | 193 | if ((this.textarea.element.hasAttribute("autofocus") || document.querySelector(":focus") == this.textarea.element) && !browser.isIos()) { |
193 | 194 | setTimeout(function() { that.focus(true); }, 100); |
194 | 195 | } |
195 | | - |
| 196 | + |
196 | 197 | wysihtml5.quirks.insertLineBreakOnReturn(this); |
197 | | - |
| 198 | + |
198 | 199 | // IE sometimes leaves a single paragraph, which can't be removed by the user |
199 | 200 | if (!browser.clearsContentEditableCorrectly()) { |
200 | 201 | wysihtml5.quirks.ensureProperClearing(this); |
201 | 202 | } |
202 | | - |
| 203 | + |
203 | 204 | if (!browser.clearsListsInContentEditableCorrectly()) { |
204 | 205 | wysihtml5.quirks.ensureProperClearingOfLists(this); |
205 | 206 | } |
206 | | - |
| 207 | + |
207 | 208 | // Set up a sync that makes sure that textarea and editor have the same content |
208 | 209 | if (this.initSync && this.config.sync) { |
209 | 210 | this.initSync(); |
210 | 211 | } |
211 | | - |
| 212 | + |
212 | 213 | // Okay hide the textarea, we are ready to go |
213 | 214 | this.textarea.hide(); |
214 | 215 |
|
|
289 | 290 | }, |
290 | 291 |
|
291 | 292 | _initObjectResizing: function() { |
292 | | - var properties = ["width", "height"], |
293 | | - propertiesLength = properties.length, |
294 | | - element = this.element, |
295 | | - adoptStyles = function(event) { |
296 | | - var target = event.target || event.srcElement, |
297 | | - style = target.style, |
298 | | - i = 0, |
299 | | - property; |
300 | | - |
301 | | - if (target.nodeName !== "IMG") { |
302 | | - return; |
303 | | - } |
304 | | - |
305 | | - for (; i<propertiesLength; i++) { |
306 | | - property = properties[i]; |
307 | | - if (style[property]) { |
308 | | - target.setAttribute(property, parseInt(style[property], 10)); |
309 | | - style[property] = ""; |
310 | | - } |
311 | | - } |
312 | | - |
313 | | - // After resizing IE sometimes forgets to remove the old resize handles |
314 | | - wysihtml5.quirks.redraw(element); |
315 | | - }; |
316 | | - |
317 | 293 | this.commands.exec("enableObjectResizing", true); |
318 | 294 |
|
319 | 295 | // IE sets inline styles after resizing objects |
320 | 296 | // The following lines make sure that the width/height css properties |
321 | 297 | // are copied over to the width/height attributes |
322 | 298 | if (browser.supportsEvent("resizeend")) { |
323 | | - dom.observe(element, "resizeend", adoptStyles); |
324 | | - } else { |
325 | | - dom.observe(element, "DOMAttrModified", adoptStyles); |
| 299 | + var properties = ["width", "height"], |
| 300 | + propertiesLength = properties.length, |
| 301 | + element = this.element; |
| 302 | + |
| 303 | + dom.observe(element, "resizeend", function(event) { |
| 304 | + var target = event.target || event.srcElement, |
| 305 | + style = target.style, |
| 306 | + i = 0, |
| 307 | + property; |
| 308 | + |
| 309 | + if (target.nodeName !== "IMG") { |
| 310 | + return; |
| 311 | + } |
| 312 | + |
| 313 | + for (; i<propertiesLength; i++) { |
| 314 | + property = properties[i]; |
| 315 | + if (style[property]) { |
| 316 | + target.setAttribute(property, parseInt(style[property], 10)); |
| 317 | + style[property] = ""; |
| 318 | + } |
| 319 | + } |
| 320 | + |
| 321 | + // After resizing IE sometimes forgets to remove the old resize handles |
| 322 | + wysihtml5.quirks.redraw(element); |
| 323 | + }); |
326 | 324 | } |
327 | 325 | }, |
328 | 326 |
|
|
0 commit comments