From 7f39d4e75d2dcec7a80ccd25ca88fa8b3e0803f8 Mon Sep 17 00:00:00 2001 From: Alex Monk Date: Wed, 22 Jun 2016 00:18:09 +0100 Subject: [PATCH] Use .textSelection( 'getContents' ) instead of .val() to get the value of #wpTextbox1 To allow gadgets like wikEd to use textSelection to return the latest value. Bug: T135747 Change-Id: Ie353cf547dea6c100c5f01ab56c9b415be1ffdb8 --- .../targets/ve.init.mw.DesktopArticleTarget.init.js | 10 ++++++---- modules/ve-mw/init/ve.init.mw.ArticleTargetLoader.js | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js index 06cbf5fec5..002ae5a872 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js +++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js @@ -550,8 +550,7 @@ }, activateVe: function () { - var wikitext = $( '#wpTextbox1' ).val(), - wikitextModified = wikitext !== initialWikitext; + var wikitext = $( '#wpTextbox1' ).textSelection( 'getContents' ); // Close any open jQuery.UI dialogs (e.g. WikiEditor's find and replace) if ( $.fn.dialog ) { @@ -560,7 +559,10 @@ if ( mw.config.get( 'wgAction' ) === 'submit' || - ( mw.config.get( 'wgAction' ) === 'edit' && wikitextModified ) || + ( + mw.config.get( 'wgAction' ) === 'edit' && + wikitext !== initialWikitext + ) || // switching from section editing must prompt because we can't // keep changes from that (yet?) $( 'input[name=wpSection]' ).val() @@ -718,7 +720,7 @@ urlSaysHideWelcome = 'hidewelcomedialog' in new mw.Uri( location.href ).query; if ( uri.query.action === 'edit' && $( '#wpTextbox1' ).length ) { - initialWikitext = $( '#wpTextbox1' ).val(); + initialWikitext = $( '#wpTextbox1' ).textSelection( 'getContents' ); } if ( init.isAvailable ) { diff --git a/modules/ve-mw/init/ve.init.mw.ArticleTargetLoader.js b/modules/ve-mw/init/ve.init.mw.ArticleTargetLoader.js index c0d04a8c8c..4c9db9ae8c 100644 --- a/modules/ve-mw/init/ve.init.mw.ArticleTargetLoader.js +++ b/modules/ve-mw/init/ve.init.mw.ArticleTargetLoader.js @@ -138,7 +138,7 @@ ve.track( 'trace.restbaseLoad.enter' ); if ( conf.fullRestbaseUrl && - $( '#wpTextbox1' ).val() && + $( '#wpTextbox1' ).textSelection( 'getContents' ) && !$( '[name=wpSection]' ).val() ) { switched = true; @@ -153,7 +153,7 @@ data: { title: pageName, oldid: oldid, - wikitext: $( '#wpTextbox1' ).val(), + wikitext: $( '#wpTextbox1' ).textSelection( 'getContents' ), stash: 'true' }, // Should be synchronised with ApiVisualEditor.php