Move edit.js stuff to mediawiki.action.edit.js, and remove wikibits dependency. Wrap...
authorLeo Koppelkamm <diebuche@users.mediawiki.org>
Thu, 21 Apr 2011 08:19:24 +0000 (08:19 +0000)
committerLeo Koppelkamm <diebuche@users.mediawiki.org>
Thu, 21 Apr 2011 08:19:24 +0000 (08:19 +0000)
includes/EditPage.php
resources/Resources.php
resources/jquery/jquery.textSelection.js
resources/mediawiki.action/mediawiki.action.edit.js
skins/common/edit.js
skins/common/shared.css

index 9b6f6a0..5e69bb5 100644 (file)
@@ -373,7 +373,7 @@ class EditPage {
                        $this->preview = true;
                }
 
-               $wgOut->addModules( array( 'mediawiki.legacy.edit', 'mediawiki.action.edit' ) );
+               $wgOut->addModules( array( 'mediawiki.action.edit' ) );
 
                if ( $wgUser->getOption( 'uselivepreview', false ) ) {
                        $wgOut->addModules( 'mediawiki.legacy.preview' );
@@ -2410,9 +2410,9 @@ HTML
 
                        $paramList = implode( ',',
                                array_map( array( 'Xml', 'encodeJsVar' ), $params ) );
-                       $script .= "addButton($paramList);\n";
+                       $script .= "mw.toolbar.addButton($paramList);\n";
                }
-
+               $script .= "mw.toolbar.init();\n";
                $wgOut->addScript( Html::inlineScript(
                        "if ( window.mediaWiki ) { jQuery(function(){{$script}}); }"
                ) );
index 7ae0d22..adf4513 100644 (file)
@@ -412,6 +412,7 @@ return array(
        ),
        'mediawiki.action.edit' => array(
                'scripts' => 'resources/mediawiki.action/mediawiki.action.edit.js',
+               'dependencies' => 'jquery.textSelection',
        ),
        'mediawiki.action.view.rightClickEdit' => array(
                'scripts' => 'resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js',
index 22ee092..530485e 100644 (file)
@@ -62,10 +62,17 @@ encapsulateSelection: function( options ) {
                                isSample = true;
                        } else if ( options.replace ) {
                                selText = options.peri;
-                       } else if ( selText.charAt( selText.length - 1 ) == ' ' ) {
-                               // Exclude ending space char
-                               selText = selText.substring(0, selText.length - 1);
-                               options.post += ' ';
+                       } else {
+                               while ( selText.charAt( selText.length - 1 ) == ' ' ) {
+                                       // Exclude ending space char
+                                       selText = selText.substring(0, selText.length - 1);
+                                       options.post += ' ';
+                               }
+                               while ( selText.charAt( 0 ) == ' ' ) {
+                                       // Exclude prepending space char
+                                       selText = selText.substring(1, selText.length);
+                                       options.pre = ' ' + options.pre;
+                               }
                        }
                }
                var isSample = false;
index 8a785e6..6d93e9c 100644 (file)
@@ -1,14 +1,61 @@
-/* Note, there is still stuff in skins/common/edit.js that
- * has not been jQuery-ized.
- */
-
 (function( $ ) {
+       // currentFocus is used to determine where to insert tags
+       var currentFocused = $( '#wpTextbox1' );
+       
+       mw.toolbar = {
+               $toolbar : $( '#toolbar' ),
+               addButton : function( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ) {
+                       var image = $('<img>', {
+                               width  : 23,
+                               height : 23,
+                               src    : imageFile,
+                               alt    : speedTip,
+                               title  : speedTip,
+                               id     : imageId || '',
+                               'class': 'mw-toolbar-editbutton'
+                       } ).click( function() {
+                               mw.toolbar.insertTags( tagOpen, tagClose, sampleText, selectText );
+                               return false;
+                       } );
+
+                       this.$toolbar.append( image );
+                       return true;
+               },
+
+               // apply tagOpen/tagClose to selection in textarea,
+               // use sampleText instead of selection if there is none
+               insertTags : function( tagOpen, tagClose, sampleText, selectText) {
+                       if ( currentFocused.length ) {
+                               currentFocused.textSelection(
+                                       'encapsulateSelection', { 'pre': tagOpen, 'peri': sampleText, 'post': tagClose }
+                               );
+                               return;
+                       }
+               }, 
+               init : function() {
+                       // Legacy
+                       // Print out buttons from mwCustomEditButtons
+                       // If you want to add buttons, use 
+                       // $( document ).ready( function () { mw.toolbar.addButton( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ) } );
+                       var c;
+                       for ( i = 0; i < window.mwCustomEditButtons.length; i++ ) {
+                               c = window.mwCustomEditButtons[i];
+                               mw.toolbar.addButton( c.imageFile, c.speedTip, c.tagOpen, c.tagClose, c.sampleText, c.imageId, c.selectText );
+                       }
+                       return true;
+               }
+       };
+
+       //Legacy
+       window.addButton =  mw.toolbar.addButton;
+       window.insertTags = mw.toolbar.insertTags;
+
        //make sure edit summary does not exceed byte limit
        $( '#wpSummary' ).attr( 'maxLength', 250 ).keypress( function( e ) {
                // first check to see if this is actually a character key
                // being pressed.
                // Based on key-event info from http://unixpapa.com/js/key.html
-               // JQuery should also normalize e.which to be consistent cross-browser,
+               // jQuery should also normalize e.which to be consistent cross-browser,
                // however the same check is still needed regardless of jQuery.
 
                // Note: At the moment, for some older opera versions (~< 10.5)
                        e.preventDefault();
                }
        });
+       
+       
+       $( document ).ready( function() {
+               /**
+                * Restore the edit box scroll state following a preview operation,
+                * and set up a form submission handler to remember this state
+                */
+               var scrollEditBox = function() {
+                       var editBox = document.getElementById( 'wpTextbox1' );
+                       var scrollTop = document.getElementById( 'wpScrolltop' );
+                       var $editForm = $( '#editform' );
+                       if( $editForm.length && editBox && scrollTop ) {
+                               if( scrollTop.value ) {
+                                       editBox.scrollTop = scrollTop.value;
+                               }
+                               $editForm.submit( function() {
+                                       scrollTop.value = editBox.scrollTop;
+                               });
+                       }
+               };
+               scrollEditBox();
+
+               $( '#wpSummary, #wpTextbox1' ).focus( function() {
+                       currentFocused = $(this);
+               });
+
+               // HACK: make currentFocused work with the usability iframe
+               // With proper focus detection support (HTML 5!) this'll be much cleaner
+               var iframe = $( '.wikiEditor-ui-text iframe' );
+               if ( iframe.length > 0 ) {
+                       $( iframe.get( 0 ).contentWindow.document )
+                               .add( iframe.get( 0 ).contentWindow.document.body ) // for IE
+                               .focus( function() { currentFocused = iframe; } );
+               }
+       });
 })(jQuery);
index 35505f4..732aa92 100644 (file)
@@ -1,3 +1,7 @@
+// This file is still referenced from
+//  tests/selenium/data/SimpleSeleniumTestDB.sql
+//  includes/specials/SpecialUpload.php
+//  /extensions/SemanticForms/specials/SF_UploadWindow2.php
 window.currentFocused = undefined;
 
 // this function adds a toolbar button to the mwEditButtons list
index c9a3bd3..bbb8552 100644 (file)
@@ -40,7 +40,9 @@ span.texhtml { font-family: serif; }
 #editform, #toolbar, #wpTextbox1 {
        clear: both;
 }
-
+#toolbar img {
+       cursor: pointer;
+}
 div#mw-js-message {
        margin: 1em 5%;
        padding: 0.5em 2.5%;