[MediaWiki-commits] [Gerrit] Split jquery.textSelection and WikiEditor api overrides - change (mediawiki...CodeEditor)

2014-10-22 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Split jquery.textSelection and WikiEditor api overrides
..


Split jquery.textSelection and WikiEditor api overrides

Split context.evt up into 2 objects
- context.fn, where WikiEditor API functions are defined
- textSelectionFn, where all textSelection API function are defined.

- scrollToTop() is moved to the WikiEditor API block
- getElementAtCursor() is removed. It is no longer in use by the
WikiEditor API or the textSelection API.

This depends on MediaWiki core change I14492572

Bug: 29328
Change-Id: I57bc7791dc61b7edcf258e6c16445d5a4a8783cf
---
M modules/jquery.codeEditor.js
1 file changed, 24 insertions(+), 33 deletions(-)

Approvals:
  Krinkle: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/jquery.codeEditor.js b/modules/jquery.codeEditor.js
index 6b8f91d..4d074b5 100644
--- a/modules/jquery.codeEditor.js
+++ b/modules/jquery.codeEditor.js
@@ -40,6 +40,7 @@
 
$.wikiEditor.extensions.codeEditor = function ( context ) {
var saveAndExtend,
+   textSelectionFn,
returnFalse = function () { return false; };
 
/*
@@ -182,6 +183,7 @@
// Load the editor now
context.codeEditor = ace.edit( 
editdiv[0] );

context.codeEditor.getSession().setValue( box.val() );
+   box.textSelection( 'register', 
textSelectionFn );
 
// Disable some annoying commands

context.codeEditor.commands.removeCommand( 'replace' );  // ctrl+R
@@ -196,16 +198,6 @@
enableSnippets: true
} );
 
-   // fakeout for bug 29328
-   context.$iframe = [
-   {
-   contentWindow: {
-   focus: function 
() {
-   
context.codeEditor.focus();
-   }
-   }
-   }
-   ];
box.closest( 'form' ).submit( 
context.evt.codeEditorSubmit );
session = 
context.codeEditor.getSession();
 
@@ -257,7 +249,8 @@
$( mw ).unbind( 'LivePreviewPrepare', 
context.evt.codeEditorSubmit ); // deprecated
 
// Save contents
-   context.$textarea.val( context.fn.getContents() 
);
+   context.$textarea.textSelection( 'unregister' );
+   context.$textarea.val( 
textSelectionFn.getContents() );
 
// @todo fetch cursor, scroll position
 
@@ -265,7 +258,6 @@
context.fn.removeStatusBar();
context.$codeEditorContainer.remove();
context.$codeEditorContainer = undefined;
-   context.$iframe = undefined;
context.codeEditor = undefined;
 
// Restore textarea
@@ -526,18 +518,26 @@
mw.log( 'codeEditor stub function 
restoreSelection called' );
},
 
+   /**
+* Scroll an element to the top of the iframe
+*
+* @param $element jQuery object containing an element 
in the iframe
+* @param force If true, scroll the element even if 
it's already visible
+*/
+   'scrollToTop': function () {
+   mw.log( 'codeEditor stub function scrollToTop 
called' );
+   }
+   } );
+
+   /**
+* Compatibility with the $.textSelection jQuery plug-in. When 
the iframe is in use, these functions provide
+* equivalant functionality to the otherwise textarea-based 
functionality.
+*/
+   textSelectionFn = {
+
/* Needed for search/replace */
'getContents': function () {
return 
context.codeEditor.getSession().getValue();
-   },
-
-   /**
-* 

[MediaWiki-commits] [Gerrit] Split jquery.textSelection and WikiEditor api overrides - change (mediawiki...CodeEditor)

2014-07-28 Thread TheDJ (Code Review)
TheDJ has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/150037

Change subject: Split jquery.textSelection and WikiEditor api overrides
..

Split jquery.textSelection and WikiEditor api overrides

This depends on MediaWiki core change I14492572

Bug: 29328
Change-Id: I57bc7791dc61b7edcf258e6c16445d5a4a8783cf
---
M modules/jquery.codeEditor.js
1 file changed, 25 insertions(+), 34 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CodeEditor 
refs/changes/37/150037/1

diff --git a/modules/jquery.codeEditor.js b/modules/jquery.codeEditor.js
index c7f46df..9cf7f70 100644
--- a/modules/jquery.codeEditor.js
+++ b/modules/jquery.codeEditor.js
@@ -39,7 +39,8 @@
};
 
$.wikiEditor.extensions.codeEditor = function ( context ) {
-   var saveAndExtend;
+   var saveAndExtend,
+   textSelectionFn;
 
/*
 * Event Handlers
@@ -189,6 +190,7 @@
// Load the editor now
context.codeEditor = ace.edit( 
editdiv[0] );

context.codeEditor.getSession().setValue( box.val() );
+   box.textSelection( 'register', 
textSelectionFn );
 
// Disable some annoying commands

context.codeEditor.commands.removeCommand( 'replace' );  // ctrl+R
@@ -203,16 +205,6 @@
enableSnippets: true
} );
 
-   // fakeout for bug 29328
-   context.$iframe = [
-   {
-   contentWindow: {
-   focus: function 
() {
-   
context.codeEditor.focus();
-   }
-   }
-   }
-   ];
box.closest( 'form' ).submit( 
context.evt.codeEditorSubmit );
session = 
context.codeEditor.getSession();
 
@@ -265,7 +257,8 @@
$( mw ).unbind( 'LivePreviewPrepare', 
context.evt.codeEditorSubmit ); // deprecated
 
// Save contents
-   context.$textarea.val( context.fn.getContents() 
);
+   context.$textarea.textSelection( 'unregister' );
+   context.$textarea.val( 
textSelectionFn.getContents() );
 
// @todo fetch cursor, scroll position
 
@@ -273,7 +266,6 @@
context.fn.removeStatusBar();
context.$codeEditorContainer.remove();
context.$codeEditorContainer = undefined;
-   context.$iframe = undefined;
context.codeEditor = undefined;
 
// Restore textarea
@@ -535,18 +527,26 @@
mw.log( 'codeEditor stub function 
restoreSelection called' );
},
 
+   /**
+* Scroll an element to the top of the iframe
+*
+* @param $element jQuery object containing an element 
in the iframe
+* @param force If true, scroll the element even if 
it's already visible
+*/
+   'scrollToTop': function () {
+   mw.log( 'codeEditor stub function scrollToTop 
called' );
+   }
+   } );
+
+   /**
+* Compatibility with the $.textSelection jQuery plug-in. When 
the iframe is in use, these functions provide
+* equivalant functionality to the otherwise textarea-based 
functionality.
+*/
+   textSelectionFn = {
+
/* Needed for search/replace */
'getContents': function () {
return 
context.codeEditor.getSession().getValue();
-   },
-
-   /**
-* Compatibility with the $.textSelection jQuery 
plug-in. When the iframe is in use, these functions provide
-* equivilant functionality to the otherwise 
textarea-based functionality.
-*/
-
-