Skip to content

Instantly share code, notes, and snippets.

@awolfey
Last active August 29, 2015 14:13
Show Gist options
  • Save awolfey/fc63365cb18f1a9f051e to your computer and use it in GitHub Desktop.
Save awolfey/fc63365cb18f1a9f051e to your computer and use it in GitHub Desktop.
Set Value of alt text if empty in CKEditor

#In CKEditor, set the alt text value in the image dialog

It may not be a great idea to set the alt value to the image file name, but this can be modified to use some other value.

CKEDITOR.on('dialogDefinition', function(ev) {
var dialogName = ev.data.name;
var dialog = ev.data.definition.dialog;
switch (dialogName) {
case 'image': //Image Properties dialog
// Set the alt value to the image file name if it's left blank.
var urlField = infoTab.get('txtUrl');
dialog.on('ok', function () {
var altField = dialog.getContentElement('info', 'txtAlt');
if (altField.getValue() == '') {
var url = dialog.getContentElement('info', 'txtUrl').getValue()
altField.setValue(url.substring(url.lastIndexOf('/')+1));
}
});
break;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment