2 // currentFocus is used to determine where to insert tags
3 var currentFocused
= $( '#wpTextbox1' );
9 // If you want to add buttons, use
10 // mw.toolbar.addButton( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText );
11 addButton : function() {
13 this.insertButton
.apply( this, arguments
);
15 this.buttons
.push( [].slice
.call( arguments
) );
18 insertButton : function( imageFile
, speedTip
, tagOpen
, tagClose
, sampleText
, imageId
, selectText
) {
19 var image
= $('<img>', {
26 'class': 'mw-toolbar-editbutton'
27 } ).click( function() {
28 mw
.toolbar
.insertTags( tagOpen
, tagClose
, sampleText
, selectText
);
32 this.$toolbar
.append( image
);
36 // apply tagOpen/tagClose to selection in textarea,
37 // use sampleText instead of selection if there is none
38 insertTags : function( tagOpen
, tagClose
, sampleText
, selectText
) {
39 if ( currentFocused
.length
) {
40 currentFocused
.textSelection(
41 'encapsulateSelection', { 'pre': tagOpen
, 'peri': sampleText
, 'post': tagClose
}
46 // For backwards compatibility
49 onReady : function() {
50 this.$toolbar
= $( '#toolbar' );
53 // Merge buttons from mwCustomEditButtons
54 var buttons
= [].concat( this.buttons
, window
.mwCustomEditButtons
);
55 for ( var i
= 0; i
< buttons
.length
; i
++ ) {
56 if ( $.isArray( buttons
[i
] ) ) {
57 // Passes our button array as arguments
58 this.insertButton
.apply( this, buttons
[i
] );
60 // Legacy mwCustomEditButtons is an object
62 this.insertButton( c
.imageFile
, c
.speedTip
, c
.tagOpen
,
63 c
.tagClose
, c
.sampleText
, c
.imageId
, c
.selectText
);
71 window
.addButton
= mw
.toolbar
.addButton
;
72 window
.insertTags
= mw
.toolbar
.insertTags
;
74 $( document
).ready( function() {
77 // Make sure edit summary does not exceed byte limit
78 $( '#wpSummary' ).byteLimit( 250 );
81 * Restore the edit box scroll state following a preview operation,
82 * and set up a form submission handler to remember this state
84 var scrollEditBox = function() {
85 var editBox
= document
.getElementById( 'wpTextbox1' );
86 var scrollTop
= document
.getElementById( 'wpScrolltop' );
87 var $editForm
= $( '#editform' );
88 if( $editForm
.length
&& editBox
&& scrollTop
) {
89 if( scrollTop
.value
) {
90 editBox
.scrollTop
= scrollTop
.value
;
92 $editForm
.submit( function() {
93 scrollTop
.value
= editBox
.scrollTop
;
99 $( 'textarea, input:text' ).focus( function() {
100 currentFocused
= $(this);
103 // HACK: make currentFocused work with the usability iframe
104 // With proper focus detection support (HTML 5!) this'll be much cleaner
105 var iframe
= $( '.wikiEditor-ui-text iframe' );
106 if ( iframe
.length
> 0 ) {
107 $( iframe
.get( 0 ).contentWindow
.document
)
108 .add( iframe
.get( 0 ).contentWindow
.document
.body
) // for IE
109 .focus( function() { currentFocused
= iframe
; } );