psergus / ngWYSIWYG

true angular WYSIWYG
MIT License
63 stars 42 forks source link

How to change image width automatically? #5

Closed butaixianran closed 8 years ago

butaixianran commented 9 years ago

I konw Chome can't change image size in design mode. But, we can check all images' width, if any image's width > textarea's width, then set image's width to 100%.

This strategy is not perfect, but will be fine in most cases. With this, most people won't even try to modify image size in html source anymore.

butaixianran commented 9 years ago

I find a solution for this, by adding following code at the end of scope.$on('execCommand', function(e, cmd)

$body.html($body.html().replace(/<img src/g, "<img style='max-width:100%;' src"));

But that means this replace() will be checked, everytime clicking on any button.

I try to do this in scope.insertImage() function with scope.content , but what I get is the text before execCommand finished.

So, how should I get $body.html() in scope.insertImage() function ? Thanks.

psergus commented 9 years ago

what I would recommend in this case is to use scope.execCommand('insertHTML', '' ); instead of scope.execCommand('insertimage', val); inside wysiwygEdit directive. This will give you better flexibility. Actually I was thinking to replace it and probably will.

On Sat, Apr 25, 2015 at 6:11 PM, butaixianran notifications@github.com wrote:

I find a solution for this, by adding this at the end of scope.$on('execCommand', function(e, cmd)

$body.html($body.html().replace(/<img src/g, "<img style='max-width:100%;' src"));

But that means this replace() will be checked, everytime clicking on any button.

I try to do thi in scope.insertImage() function with scope.content , but what I get is the value before execCommand finished.

So, how should I get $body.html() scope.insertImage() function ? Thanks.

— Reply to this email directly or view it on GitHub https://github.com/psergus/ngWYSIWYG/issues/5#issuecomment-96299981.

Best regards, Sergey Petrenko

butaixianran commented 9 years ago

it's a great solution, much better than what I did, thanks