Editor: manually trigger `change` event when text is modified from JS.

Props westonruter.
Fixes #40726.

git-svn-id: https://develop.svn.wordpress.org/trunk@40615 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2017-05-11 00:28:43 +00:00
parent ab5cd5011f
commit 0c63472b68
2 changed files with 20 additions and 2 deletions

View File

@ -406,7 +406,7 @@ function edButton(id, display, tagStart, tagEnd, access) {
};
qt.insertContent = function(content) {
var sel, startPos, endPos, scrollTop, text, canvas = document.getElementById(wpActiveEditor);
var sel, startPos, endPos, scrollTop, text, canvas = document.getElementById(wpActiveEditor), event;
if ( !canvas ) {
return false;
@ -433,6 +433,15 @@ function edButton(id, display, tagStart, tagEnd, access) {
canvas.value += content;
canvas.focus();
}
if ( document.createEvent ) {
event = document.createEvent( 'HTMLEvents' );
event.initEvent( 'change', false, true );
canvas.dispatchEvent( event );
} else if ( canvas.fireEvent ) {
canvas.fireEvent( 'onchange' );
}
return true;
};
@ -515,7 +524,7 @@ function edButton(id, display, tagStart, tagEnd, access) {
return ret;
};
qt.TagButton.prototype.callback = function(element, canvas, ed) {
var t = this, startPos, endPos, cursorPos, scrollTop, v = canvas.value, l, r, i, sel, endTag = v ? t.tagEnd : '';
var t = this, startPos, endPos, cursorPos, scrollTop, v = canvas.value, l, r, i, sel, endTag = v ? t.tagEnd : '', event;
if ( document.selection ) { // IE
canvas.focus();
@ -590,6 +599,14 @@ function edButton(id, display, tagStart, tagEnd, access) {
}
canvas.focus();
}
if ( document.createEvent ) {
event = document.createEvent( 'HTMLEvents' );
event.initEvent( 'change', false, true );
canvas.dispatchEvent( event );
} else if ( canvas.fireEvent ) {
canvas.fireEvent( 'onchange' );
}
};
// removed

View File

@ -380,6 +380,7 @@ var wpLink;
wpLink.close();
textarea.focus();
$( textarea ).trigger( 'change' );
// Audible confirmation message when a link has been inserted in the Editor.
wp.a11y.speak( wpLinkL10n.linkInserted );