Skip to content
This repository was archived by the owner on Mar 8, 2019. It is now read-only.

Commit 80b3544

Browse files
committed
Fix resizing in Firefox (fixes #208)
1 parent 4c18401 commit 80b3544

File tree

1 file changed

+39
-41
lines changed

1 file changed

+39
-41
lines changed

src/views/composer.js

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -141,33 +141,34 @@
141141
this.element = this.doc.body;
142142
this.textarea = this.parent.textarea;
143143
this.element.innerHTML = this.textarea.getValue(true);
144-
this.enable();
145144

146145
// Make sure our selection handler is ready
147146
this.selection = new wysihtml5.Selection(this.parent);
148147

149148
// Make sure commands dispatcher is ready
150149
this.commands = new wysihtml5.Commands(this.parent);
151-
150+
152151
dom.copyAttributes([
153152
"className", "spellcheck", "title", "lang", "dir", "accessKey"
154153
]).from(this.textarea.element).to(this.element);
155154

156155
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
159158
if (this.config.style) {
160159
this.style();
161160
}
162-
161+
163162
this.observe();
164-
163+
165164
var name = this.config.name;
166165
if (name) {
167166
dom.addClass(this.element, name);
168167
dom.addClass(this.iframe, name);
169168
}
170169

170+
this.enable();
171+
171172
if (this.textarea.element.disabled) {
172173
this.disable();
173174
}
@@ -182,33 +183,33 @@
182183

183184
// Make sure that the browser avoids using inline styles whenever possible
184185
this.commands.exec("styleWithCSS", false);
185-
186+
186187
this._initAutoLinking();
187188
this._initObjectResizing();
188189
this._initUndoManager();
189-
190+
190191
// Simulate html5 autofocus on contentEditable element
191192
// This doesn't work on IOS (5.1.1)
192193
if ((this.textarea.element.hasAttribute("autofocus") || document.querySelector(":focus") == this.textarea.element) && !browser.isIos()) {
193194
setTimeout(function() { that.focus(true); }, 100);
194195
}
195-
196+
196197
wysihtml5.quirks.insertLineBreakOnReturn(this);
197-
198+
198199
// IE sometimes leaves a single paragraph, which can't be removed by the user
199200
if (!browser.clearsContentEditableCorrectly()) {
200201
wysihtml5.quirks.ensureProperClearing(this);
201202
}
202-
203+
203204
if (!browser.clearsListsInContentEditableCorrectly()) {
204205
wysihtml5.quirks.ensureProperClearingOfLists(this);
205206
}
206-
207+
207208
// Set up a sync that makes sure that textarea and editor have the same content
208209
if (this.initSync && this.config.sync) {
209210
this.initSync();
210211
}
211-
212+
212213
// Okay hide the textarea, we are ready to go
213214
this.textarea.hide();
214215

@@ -289,40 +290,37 @@
289290
},
290291

291292
_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-
317293
this.commands.exec("enableObjectResizing", true);
318294

319295
// IE sets inline styles after resizing objects
320296
// The following lines make sure that the width/height css properties
321297
// are copied over to the width/height attributes
322298
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+
});
326324
}
327325
},
328326

0 commit comments

Comments
 (0)