2 var isReady
, toolbar
, currentFocused
;
10 * If you want to add buttons, use
11 * mw.toolbar.addButton( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText );
13 addButton: function () {
15 toolbar
.insertButton
.apply( toolbar
, arguments
);
17 toolbar
.buttons
.push( [].slice
.call( arguments
) );
20 insertButton: function ( imageFile
, speedTip
, tagOpen
, tagClose
, sampleText
, imageId
, selectText
) {
21 var image
= $('<img>', {
28 'class': 'mw-toolbar-editbutton'
29 } ).click( function () {
30 mw
.toolbar
.insertTags( tagOpen
, tagClose
, sampleText
, selectText
);
34 toolbar
.$toolbar
.append( image
);
39 * apply tagOpen/tagClose to selection in textarea,
40 * use sampleText instead of selection if there is none.
42 insertTags: function ( tagOpen
, tagClose
, sampleText
, selectText
) {
43 if ( currentFocused
&& currentFocused
.length
) {
44 currentFocused
.textSelection(
45 'encapsulateSelection', {
54 // For backwards compatibility
58 // Legacy (for compatibility with the code previously in skins/common.edit.js)
59 window
.addButton
= toolbar
.addButton
;
60 window
.insertTags
= toolbar
.insertTags
;
65 $( document
).ready( function () {
66 var buttons
, i
, c
, iframe
;
68 // currentFocus is used to determine where to insert tags
69 currentFocused
= $( '#wpTextbox1' );
71 // Populate the selector cache for $toolbar
72 toolbar
.$toolbar
= $( '#toolbar' );
74 // Legacy: Merge buttons from mwCustomEditButtons
75 buttons
= [].concat( toolbar
.buttons
, window
.mwCustomEditButtons
);
76 for ( i
= 0; i
< buttons
.length
; i
++ ) {
77 if ( $.isArray( buttons
[i
] ) ) {
78 // Passes our button array as arguments
79 toolbar
.insertButton
.apply( toolbar
, buttons
[i
] );
81 // Legacy mwCustomEditButtons is an object
83 toolbar
.insertButton( c
.imageFile
, c
.speedTip
, c
.tagOpen
,
84 c
.tagClose
, c
.sampleText
, c
.imageId
, c
.selectText
);
88 // This causes further calls to addButton to go to insertion directly
89 // instead of to the toolbar.buttons queue.
90 // It is important that this is after the one and only loop through
91 // the the toolbar.buttons queue
94 // Make sure edit summary does not exceed byte limit
95 $( '#wpSummary' ).byteLimit( 255 );
98 * Restore the edit box scroll state following a preview operation,
99 * and set up a form submission handler to remember this state
101 ( function scrollEditBox() {
102 var editBox
, scrollTop
, $editForm
;
104 editBox
= document
.getElementById( 'wpTextbox1' );
105 scrollTop
= document
.getElementById( 'wpScrolltop' );
106 $editForm
= $( '#editform' );
107 if ( $editForm
.length
&& editBox
&& scrollTop
) {
108 if ( scrollTop
.value
) {
109 editBox
.scrollTop
= scrollTop
.value
;
111 $editForm
.submit( function () {
112 scrollTop
.value
= editBox
.scrollTop
;
117 $( 'textarea, input:text' ).focus( function () {
118 currentFocused
= $(this);
121 // HACK: make currentFocused work with the usability iframe
122 // With proper focus detection support (HTML 5!) this'll be much cleaner
123 iframe
= $( '.wikiEditor-ui-text iframe' );
124 if ( iframe
.length
> 0 ) {
125 $( iframe
.get( 0 ).contentWindow
.document
)
127 .add( iframe
.get( 0 ).contentWindow
.document
.body
)
128 .focus( function () {
129 currentFocused
= iframe
;
134 }( jQuery
, mediaWiki
) );