Skip to content

Commit

Permalink
Remove allowObjectResizing config adopt inline styles after resizing …
Browse files Browse the repository at this point in the history
…an <img> (fixes tiff#157)
  • Loading branch information
tiff committed Jul 23, 2012
1 parent e205dbd commit 9705b62
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
2 changes: 0 additions & 2 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
stylesheets: [],
// Placeholder text to use, defaults to the placeholder attribute on the textarea element
placeholderText: undef,
// Whether the composer should allow the user to manually resize images, tables etc.
allowObjectResizing: true,
// Whether the rich text editor should be rendered on touch devices (wysihtml5 >= 0.3.0 comes with basic support for iOS 5)
supportTouchDevices: true
};
Expand Down
38 changes: 20 additions & 18 deletions src/views/composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@

try {
this.element.innerHTML = html;
}
catch (e) {
} catch (e) {
this.element.innerText = html;
}
},
Expand Down Expand Up @@ -285,35 +284,38 @@
_initObjectResizing: function() {
var properties = ["width", "height"],
propertiesLength = properties.length,
element = this.element;

this.commands.exec("enableObjectResizing", this.config.allowObjectResizing);

if (this.config.allowObjectResizing) {
// IE sets inline styles after resizing objects
// The following lines make sure that the width/height css properties
// are copied over to the width/height attributes
if (browser.supportsEvent("resizeend")) {
dom.observe(element, "resizeend", function(event) {
element = this.element,
adoptStyles = function(event) {
var target = event.target || event.srcElement,
style = target.style,
i = 0,
property;
for(; i<propertiesLength; i++) {

if (target.nodeName !== "IMG") {
return;
}

for (; i<propertiesLength; i++) {
property = properties[i];
if (style[property]) {
target.setAttribute(property, parseInt(style[property], 10));
style[property] = "";
}
}

// After resizing IE sometimes forgets to remove the old resize handles
wysihtml5.quirks.redraw(element);
});
}
};

this.commands.exec("enableObjectResizing", true);

// IE sets inline styles after resizing objects
// The following lines make sure that the width/height css properties
// are copied over to the width/height attributes
if (browser.supportsEvent("resizeend")) {
dom.observe(element, "resizeend", adoptStyles);
} else {
if (browser.supportsEvent("resizestart")) {
dom.observe(element, "resizestart", function(event) { event.preventDefault(); });
}
dom.observe(element, "DOMAttrModified", adoptStyles);
}
},

Expand Down

0 comments on commit 9705b62

Please sign in to comment.