Skip to content

Instantly share code, notes, and snippets.

@simshaun
Created November 22, 2013 00:37
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save simshaun/7592631 to your computer and use it in GitHub Desktop.
Save simshaun/7592631 to your computer and use it in GitHub Desktop.
TinyMCE 4.0.11 - Automatically remove width and height attributes from img elements inserted via the img plugin
setup: function (editor) {
editor.on('init', function(args) {
editor = args.target;
editor.on('NodeChange', function(e) {
if (e && e.element.nodeName.toLowerCase() == 'img') {
tinyMCE.DOM.setAttribs(e.element, {'width': null, 'height': null});
}
});
}
}
@RobertMischke
Copy link

Great snipptet! Thx. There is missing a "});" around line 9.

setup: function (editor) {
    editor.on('init', function(args) {
        editor = args.target;

        editor.on('NodeChange', function(e) {
            if (e && e.element.nodeName.toLowerCase() == 'img') {
                tinyMCE.DOM.setAttribs(e.element, {'width': null, 'height': null});
            }
        });
    });
}

@Snorvarg
Copy link

Great snippet, I tried adding the widht and height as css, it worked in my environment. :)

setup: function (editor) {
    editor.on('init', function(args) {
        editor = args.target;

        editor.on('NodeChange', function(e) {
            if (e && e.element.nodeName.toLowerCase() == 'img') {
                width = e.element.width;
                height = e.element.height;
                tinyMCE.DOM.setAttribs(e.element, {'width': null, 'height': null});
                tinyMCE.DOM.setAttribs(e.element, 
                    {'style': 'width:' + width + 'px; height:' + height + 'px;'});
            }
        });
    });
}  

@MGHollander
Copy link

This code blocks all functionality. There is a configuration option to disable the image dimension input fields in the image modal. Now resizing images from the editor is still possible.

Source: http://www.tinymce.com/wiki.php/Configuration:image_dimensions

@RanaZubair
Copy link

Guys i load an HTML in tinymce 4 and i successfully integrate https://github.com/vikdiesel/justboil.me plugin with tinymce. My html has many divs i want to the picture exactly as the size of div. can you guys help me about it..?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment