Last active
April 12, 2022 11:11
-
-
Save petersjoo/e1049f2f543895520e36acca3a3f787f to your computer and use it in GitHub Desktop.
Modified /js/create/editor.php to output img width, height and align attributes instead of style for Outlook compatibility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
$(document).ready(function() { | |
ckEditor = CKEDITOR.replace('html', { | |
fullPage: true, | |
allowedContent: true, | |
filebrowserUploadUrl: 'includes/create/upload.php?app=<?php echo get_app_info('app'); ?>', | |
height: '570px', | |
extraPlugins: 'codemirror,dragresize' | |
<?php if ($dark_mode) : ?>, | |
skin: 'moono-dark' | |
<?php else : ?>, | |
uiColor: '#FFFFFF' | |
<?php endif; ?> | |
}); | |
// wait until the editor is done initializing | |
ckEditor.on("instanceReady", function(ev) { | |
ev.editor.dataProcessor.htmlFilter.addRules({ | |
elements: { | |
$: function(element) { | |
// Output dimensions of images as width and height | |
if (element.name == 'img') { | |
var style = element.attributes.style; | |
if (style) { | |
// Get the width from the style. | |
var match = /(?:^|\s)width\s*:\s*(\d+)px/i.exec(style), | |
width = match && match[1]; | |
// Get the height from the style. | |
match = /(?:^|\s)height\s*:\s*(\d+)px/i.exec(style); | |
var height = match && match[1]; | |
// Get the float from the style. | |
match = /(?:^|\s)float\s*:\s*(\w+)/i.exec(style); | |
var float = match && match[1]; | |
if (width) { | |
element.attributes.style = element.attributes.style.replace(/(?:^|\s)width\s*:\s*(\d+)px;?/i, ''); | |
element.attributes.width = width; | |
} | |
if (height) { | |
element.attributes.style = element.attributes.style.replace(/(?:^|\s)height\s*:\s*(\d+)px;?/i, ''); | |
element.attributes.height = height; | |
} | |
if (float) { | |
element.attributes.style = element.attributes.style.replace(/(?:^|\s)float\s*:\s*(\w+)/i, ''); | |
element.attributes.align = float; | |
} | |
} | |
} | |
if (!element.attributes.style) delete element.attributes.style; | |
return element; | |
} | |
} | |
}); | |
// overwrite the default save function | |
ckEditor.addCommand("save", { | |
modes: { | |
wysiwyg: 1, | |
source: 1 | |
}, | |
exec: function() { | |
// get the editor content | |
var theData = ckEditor.getData(); | |
$('<input>').attr({ | |
type: 'hidden', | |
id: 'save-only', | |
name: 'save-only', | |
value: 1 | |
}).appendTo('form'); | |
$("#campaign-save-only-btn, #autoresponder-save-only-btn, #save-button").click(); | |
} | |
}); | |
}); | |
//Save campaign only | |
$("#campaign-save-only-btn, #autoresponder-save-only-btn").click(function(e) { | |
e.preventDefault(); | |
$('<input>').attr({ | |
type: 'hidden', | |
id: 'save-only', | |
name: 'save-only', | |
value: 1 | |
}).appendTo('form'); | |
$("#edit-form").submit(); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment