Tim Starling has submitted this change and it was merged.
Change subject: Make CodeEditor cooperate with the experimental live preview
......................................................................
Make CodeEditor cooperate with the experimental live preview
LivePreview takes the text from the textarea and sends it to the server
via an Ajax call to handle preview and diff. But CodeEditor hides that
textarea, and only updates it when the form is submitted or the "disable
CodeEditor" button is used.
Fortunately, LivePreview already provides a custom JavaScript event to
indicate when it is about to pull the textarea contents. So all we have
to do is listen for that and update it.
Bug: 47235
Change-Id: Iba1b727c55aabcd31afc06cec99618fcdce207d8
---
M modules/jquery.codeEditor.js
1 file changed, 14 insertions(+), 0 deletions(-)
Approvals:
Tim Starling: Verified; Looks good to me, approved
diff --git a/modules/jquery.codeEditor.js b/modules/jquery.codeEditor.js
index 2f62cf8..fccc850 100644
--- a/modules/jquery.codeEditor.js
+++ b/modules/jquery.codeEditor.js
@@ -165,6 +165,16 @@
box.closest('form').submit(
context.evt.codeEditorSubmit );
var session = context.codeEditor.getSession();
+ // Bug 47235: Update text field for LivePreview
+ if ( mw.hook ) {
+ // New style hook
+ mw.hook( 'LivePreviewPrepare' ).add(
context.evt.codeEditorSubmit );
+ }
+ // Old, deprecated style for backwards compat
+ // Do this even if mw.hook exists, because the caller
wasn't
+ // updated right away to actually use the new style.
+ $( mw ).bind( 'LivePreviewPrepare',
context.evt.codeEditorSubmit );
+
// Disable code-linting in the background using
JavaScript WebWorkers.
// Currently broken due to require() / ResourceLoader
mismatch.
session.setUseWorker(false);
@@ -197,6 +207,10 @@
'disableCodeEditor': function() {
// Kills it!
context.$textarea.closest('form').unbind('submit',
context.evt.codeEditorSubmit );
+ if ( mw.hook ) {
+ mw.hook( 'LivePreviewPrepare' ).remove(
context.evt.codeEditorSubmit );
+ }
+ $( mw ).unbind( 'LivePreviewPrepare',
context.evt.codeEditorSubmit ); // deprecated
// Save contents
context.$textarea.val(context.fn.getContents());
--
To view, visit https://gerrit.wikimedia.org/r/62612
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iba1b727c55aabcd31afc06cec99618fcdce207d8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CodeEditor
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: Victor Vasiliev <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits