2 // currentFocus is used to determine where to insert tags
3 var currentFocused = $( '#wpTextbox1' );
6 $toolbar : $( '#toolbar' ),
8 // If you want to add buttons, use
9 // mw.toolbar.addButton( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText );
10 addButton : function() {
11 this.buttons.push( [].slice.call( arguments ) );
13 insertButton : function( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ) {
14 var image = $('<img>', {
21 'class': 'mw-toolbar-editbutton'
22 } ).click( function() {
23 mw.toolbar.insertTags( tagOpen, tagClose, sampleText, selectText );
27 this.$toolbar.append( image );
31 // apply tagOpen/tagClose to selection in textarea,
32 // use sampleText instead of selection if there is none
33 insertTags : function( tagOpen, tagClose, sampleText, selectText) {
34 if ( currentFocused.length ) {
35 currentFocused.textSelection(
36 'encapsulateSelection', { 'pre': tagOpen, 'peri': sampleText, 'post': tagClose }
42 // Merge buttons from mwCustomEditButtons
43 var buttons = [].concat( this.buttons, window.mwCustomEditButtons );
44 for ( var i = 0; i < buttons.length; i++ ) {
45 if ( $.isArray( buttons[i] ) ) {
46 // Passes our button array as arguments
47 mw.toolbar.insertButton.apply( this, buttons[i] );
49 // Legacy mwCustomEditButtons is an object
51 mw.toolbar.insertButton( c.imageFile, c.speedTip, c.tagOpen, c.tagClose, c.sampleText, c.imageId, c.selectText );
59 window.addButton = mw.toolbar.addButton;
60 window.insertTags = mw.toolbar.insertTags;
62 //make sure edit summary does not exceed byte limit
63 $( '#wpSummary' ).byteLimit( 250 );
65 $( document ).ready( function() {
67 * Restore the edit box scroll state following a preview operation,
68 * and set up a form submission handler to remember this state
70 var scrollEditBox = function() {
71 var editBox = document.getElementById( 'wpTextbox1' );
72 var scrollTop = document.getElementById( 'wpScrolltop' );
73 var $editForm = $( '#editform' );
74 if( $editForm.length && editBox && scrollTop ) {
75 if( scrollTop.value ) {
76 editBox.scrollTop = scrollTop.value;
78 $editForm.submit( function() {
79 scrollTop.value = editBox.scrollTop;
88 $( '#wpSummary, #wpTextbox1' ).focus( function() {
89 currentFocused = $(this);
92 // HACK: make currentFocused work with the usability iframe
93 // With proper focus detection support (HTML 5!) this'll be much cleaner
94 var iframe = $( '.wikiEditor-ui-text iframe' );
95 if ( iframe.length > 0 ) {
96 $( iframe.get( 0 ).contentWindow.document )
97 .add( iframe.get( 0 ).contentWindow.document.body ) // for IE
98 .focus( function() { currentFocused = iframe; } );