TheDJ has uploaded a new change for review.

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

Change subject: jquery.textSelection: register an alt implementation
......................................................................

jquery.textSelection: register an alt implementation

At times we replace the textarea with a different implementation, for
instance in the former iframe code of WikiEditor and now in CodeEditor.

Obviously only one implementation of this API can be in control at a
time, but in order to disable/enable which one exactly is currently
determined by the existence of function in the core WikiEditor
context. This is a remnant of when this code was still in WikiEditor.

I added two commands, register and unregister that can take an object
that has alternative function implementations for the commands.

This also requires changes in the CodeEditor plugin.

Bug: 29328
Change-Id: I14492572f7eb9bbd1af68872dbfef5159126f107
---
M resources/src/jquery/jquery.textSelection.js
1 file changed, 17 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/32/150032/1

diff --git a/resources/src/jquery/jquery.textSelection.js 
b/resources/src/jquery/jquery.textSelection.js
index e5444eb..e9185bf 100644
--- a/resources/src/jquery/jquery.textSelection.js
+++ b/resources/src/jquery/jquery.textSelection.js
@@ -24,8 +24,9 @@
 
        $.fn.textSelection = function ( command, options ) {
                var fn,
+                       alternateFn,
                        context,
-                       hasWikiEditorSurface, // The alt edit surface needs to 
implement the WikiEditor API
+                       hasWikiEditor,
                        needSave,
                        retval;
 
@@ -507,6 +508,8 @@
                        }
                };
 
+               alternateFn = $( this ).data( 'jquery.textSelection' );
+
                // Apply defaults
                switch ( command ) {
                        //case 'getContents': // no params
@@ -550,19 +553,28 @@
                                        force: false // Force a scroll even if 
the caret position is already visible
                                }, options );
                                break;
+                       case 'register':
+                               if ( alternateFn ) {
+                                       throw new Error( 'jquery.textSelection: 
Another implementation of the textSelection API is already in use' );
+                               }
+                               $( this ).data( 'jquery.textSelection', options 
);
+                               return;
+                       case 'unregister':
+                               $( this ).removeData( 'jquery.textSelection' );
+                               return;
                }
 
                context = $( this ).data( 'wikiEditor-context' );
-               hasWikiEditorSurface = ( context !== undefined );
+               hasWikiEditor = ( context !== undefined );
 
                // IE selection restore voodoo
                needSave = false;
-               if ( hasWikiEditorSurface && context.savedSelection !== null ) {
+               if ( hasWikiEditor && context.savedSelection !== null ) {
                        context.fn.restoreSelection();
                        needSave = true;
                }
-               retval = ( hasWikiEditorSurface && context.fn[command] !== 
undefined ? context.fn : fn )[command].call( this, options );
-               if ( hasWikiEditorSurface && needSave ) {
+               retval = ( alternateFn !== undefined && alternateFn[command] 
!== undefined ? alternateFn : fn )[command].call( this, options );
+               if ( hasWikiEditor && needSave ) {
                        context.fn.saveSelection();
                }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/150032
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I14492572f7eb9bbd1af68872dbfef5159126f107
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: TheDJ <hartman.w...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to