Index: trunk/phase3/skins/common/shared.css |
— | — | @@ -40,7 +40,9 @@ |
41 | 41 | #editform, #toolbar, #wpTextbox1 { |
42 | 42 | clear: both; |
43 | 43 | } |
44 | | - |
| 44 | +#toolbar img { |
| 45 | + cursor: pointer; |
| 46 | +} |
45 | 47 | div#mw-js-message { |
46 | 48 | margin: 1em 5%; |
47 | 49 | padding: 0.5em 2.5%; |
Index: trunk/phase3/skins/common/edit.js |
— | — | @@ -1,3 +1,7 @@ |
| 2 | +// This file is still referenced from |
| 3 | +// tests/selenium/data/SimpleSeleniumTestDB.sql |
| 4 | +// includes/specials/SpecialUpload.php |
| 5 | +// /extensions/SemanticForms/specials/SF_UploadWindow2.php |
2 | 6 | window.currentFocused = undefined; |
3 | 7 | |
4 | 8 | // this function adds a toolbar button to the mwEditButtons list |
Index: trunk/phase3/includes/EditPage.php |
— | — | @@ -373,7 +373,7 @@ |
374 | 374 | $this->preview = true; |
375 | 375 | } |
376 | 376 | |
377 | | - $wgOut->addModules( array( 'mediawiki.legacy.edit', 'mediawiki.action.edit' ) ); |
| 377 | + $wgOut->addModules( array( 'mediawiki.action.edit' ) ); |
378 | 378 | |
379 | 379 | if ( $wgUser->getOption( 'uselivepreview', false ) ) { |
380 | 380 | $wgOut->addModules( 'mediawiki.legacy.preview' ); |
— | — | @@ -2410,9 +2410,9 @@ |
2411 | 2411 | |
2412 | 2412 | $paramList = implode( ',', |
2413 | 2413 | array_map( array( 'Xml', 'encodeJsVar' ), $params ) ); |
2414 | | - $script .= "addButton($paramList);\n"; |
| 2414 | + $script .= "mw.toolbar.addButton($paramList);\n"; |
2415 | 2415 | } |
2416 | | - |
| 2416 | + $script .= "mw.toolbar.init();\n"; |
2417 | 2417 | $wgOut->addScript( Html::inlineScript( |
2418 | 2418 | "if ( window.mediaWiki ) { jQuery(function(){{$script}}); }" |
2419 | 2419 | ) ); |
Index: trunk/phase3/resources/jquery/jquery.textSelection.js |
— | — | @@ -62,10 +62,17 @@ |
63 | 63 | isSample = true; |
64 | 64 | } else if ( options.replace ) { |
65 | 65 | selText = options.peri; |
66 | | - } else if ( selText.charAt( selText.length - 1 ) == ' ' ) { |
67 | | - // Exclude ending space char |
68 | | - selText = selText.substring(0, selText.length - 1); |
69 | | - options.post += ' '; |
| 66 | + } else { |
| 67 | + while ( selText.charAt( selText.length - 1 ) == ' ' ) { |
| 68 | + // Exclude ending space char |
| 69 | + selText = selText.substring(0, selText.length - 1); |
| 70 | + options.post += ' '; |
| 71 | + } |
| 72 | + while ( selText.charAt( 0 ) == ' ' ) { |
| 73 | + // Exclude prepending space char |
| 74 | + selText = selText.substring(1, selText.length); |
| 75 | + options.pre = ' ' + options.pre; |
| 76 | + } |
70 | 77 | } |
71 | 78 | } |
72 | 79 | var isSample = false; |
Index: trunk/phase3/resources/mediawiki.action/mediawiki.action.edit.js |
— | — | @@ -1,14 +1,61 @@ |
2 | | -/* Note, there is still stuff in skins/common/edit.js that |
3 | | - * has not been jQuery-ized. |
4 | | - */ |
| 2 | +(function( $ ) { |
| 3 | + // currentFocus is used to determine where to insert tags |
| 4 | + var currentFocused = $( '#wpTextbox1' ); |
| 5 | + |
| 6 | + mw.toolbar = { |
| 7 | + $toolbar : $( '#toolbar' ), |
| 8 | + addButton : function( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ) { |
| 9 | + var image = $('<img>', { |
| 10 | + width : 23, |
| 11 | + height : 23, |
| 12 | + src : imageFile, |
| 13 | + alt : speedTip, |
| 14 | + title : speedTip, |
| 15 | + id : imageId || '', |
| 16 | + 'class': 'mw-toolbar-editbutton' |
| 17 | + } ).click( function() { |
| 18 | + mw.toolbar.insertTags( tagOpen, tagClose, sampleText, selectText ); |
| 19 | + return false; |
| 20 | + } ); |
5 | 21 | |
6 | | -(function( $ ) { |
| 22 | + this.$toolbar.append( image ); |
| 23 | + return true; |
| 24 | + }, |
| 25 | + |
| 26 | + // apply tagOpen/tagClose to selection in textarea, |
| 27 | + // use sampleText instead of selection if there is none |
| 28 | + insertTags : function( tagOpen, tagClose, sampleText, selectText) { |
| 29 | + if ( currentFocused.length ) { |
| 30 | + currentFocused.textSelection( |
| 31 | + 'encapsulateSelection', { 'pre': tagOpen, 'peri': sampleText, 'post': tagClose } |
| 32 | + ); |
| 33 | + return; |
| 34 | + } |
| 35 | + }, |
| 36 | + init : function() { |
| 37 | + // Legacy |
| 38 | + // Print out buttons from mwCustomEditButtons |
| 39 | + // If you want to add buttons, use |
| 40 | + // $( document ).ready( function () { mw.toolbar.addButton( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ) } ); |
| 41 | + var c; |
| 42 | + for ( i = 0; i < window.mwCustomEditButtons.length; i++ ) { |
| 43 | + c = window.mwCustomEditButtons[i]; |
| 44 | + mw.toolbar.addButton( c.imageFile, c.speedTip, c.tagOpen, c.tagClose, c.sampleText, c.imageId, c.selectText ); |
| 45 | + } |
| 46 | + return true; |
| 47 | + } |
| 48 | + }; |
| 49 | + |
| 50 | + //Legacy |
| 51 | + window.addButton = mw.toolbar.addButton; |
| 52 | + window.insertTags = mw.toolbar.insertTags; |
| 53 | + |
7 | 54 | //make sure edit summary does not exceed byte limit |
8 | 55 | $( '#wpSummary' ).attr( 'maxLength', 250 ).keypress( function( e ) { |
9 | 56 | // first check to see if this is actually a character key |
10 | 57 | // being pressed. |
11 | 58 | // Based on key-event info from http://unixpapa.com/js/key.html |
12 | | - // JQuery should also normalize e.which to be consistent cross-browser, |
| 59 | + // jQuery should also normalize e.which to be consistent cross-browser, |
13 | 60 | // however the same check is still needed regardless of jQuery. |
14 | 61 | |
15 | 62 | // Note: At the moment, for some older opera versions (~< 10.5) |
— | — | @@ -33,4 +80,39 @@ |
34 | 81 | e.preventDefault(); |
35 | 82 | } |
36 | 83 | }); |
| 84 | + |
| 85 | + |
| 86 | + $( document ).ready( function() { |
| 87 | + /** |
| 88 | + * Restore the edit box scroll state following a preview operation, |
| 89 | + * and set up a form submission handler to remember this state |
| 90 | + */ |
| 91 | + var scrollEditBox = function() { |
| 92 | + var editBox = document.getElementById( 'wpTextbox1' ); |
| 93 | + var scrollTop = document.getElementById( 'wpScrolltop' ); |
| 94 | + var $editForm = $( '#editform' ); |
| 95 | + if( $editForm.length && editBox && scrollTop ) { |
| 96 | + if( scrollTop.value ) { |
| 97 | + editBox.scrollTop = scrollTop.value; |
| 98 | + } |
| 99 | + $editForm.submit( function() { |
| 100 | + scrollTop.value = editBox.scrollTop; |
| 101 | + }); |
| 102 | + } |
| 103 | + }; |
| 104 | + scrollEditBox(); |
| 105 | + |
| 106 | + $( '#wpSummary, #wpTextbox1' ).focus( function() { |
| 107 | + currentFocused = $(this); |
| 108 | + }); |
| 109 | + |
| 110 | + // HACK: make currentFocused work with the usability iframe |
| 111 | + // With proper focus detection support (HTML 5!) this'll be much cleaner |
| 112 | + var iframe = $( '.wikiEditor-ui-text iframe' ); |
| 113 | + if ( iframe.length > 0 ) { |
| 114 | + $( iframe.get( 0 ).contentWindow.document ) |
| 115 | + .add( iframe.get( 0 ).contentWindow.document.body ) // for IE |
| 116 | + .focus( function() { currentFocused = iframe; } ); |
| 117 | + } |
| 118 | + }); |
37 | 119 | })(jQuery); |
Index: trunk/phase3/resources/Resources.php |
— | — | @@ -412,6 +412,7 @@ |
413 | 413 | ), |
414 | 414 | 'mediawiki.action.edit' => array( |
415 | 415 | 'scripts' => 'resources/mediawiki.action/mediawiki.action.edit.js', |
| 416 | + 'dependencies' => 'jquery.textSelection', |
416 | 417 | ), |
417 | 418 | 'mediawiki.action.view.rightClickEdit' => array( |
418 | 419 | 'scripts' => 'resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js', |