Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
( function () {
// integration with VE and the cite dialog
mw.hook( 've.startup' ).add( function () {
mw.hook( 've.ui.MWCitationDialog.dialogReady' ).add( function ( dialog ) {
var surfaceModel = dialog.getSurface().getModel();
var store = dialog.getModel();
if ( store.get( 'schema' ) !== 'Cite book' ) return;
// Prevent default content panel
dialog.content.clear();
// Build OOUI form
var bookSelect = new OO.ui.DropdownInputWidget( {
options: mw.config.get( 'wgWingsofFireBooks' ).map( function ( b ) {
return { data: b, label: b.replace( /_/g, ' ' ) };
} ),
required: true
} );
var chapterSelect = new OO.ui.DropdownInputWidget( {
required: true
} );
var quoteInput = new OO.ui.MultilineTextInputWidget( {
placeholder: 'Paste the full paragraph here',
required: true
} );
var findBtn = new OO.ui.ButtonWidget( {
label: 'Find paragraph',
flags: [ 'primary' ]
} );
// When book changes, load chapters
bookSelect.on( 'change', function ( val ) {
if ( val ) {
mw.loader.using( 'mediawiki.api' ).done( function () {
( new mw.Api() ).get( {
action: 'json',
format: 'json',
url: mw.config.get( 'wgScriptPath' ) + '/find_paragraph/books/' + encodeURIComponent( val ) + '/chapters'
} ).done( function ( res ) {
var chapters = res.available_chapters || [];
chapterSelect.clearOptions();
chapters.forEach( function ( c ) {
chapterSelect.addOptions( [ { data: c, label: c } ] );
} );
} );
} );
}
} );
findBtn.on( 'click', function () {
var book = bookSelect.getValue(),
chapter = chapterSelect.getValue(),
quote = quoteInput.getValue();
if ( !book || !chapter || !quote ) {
alert( 'Please select a book, chapter and paste the full paragraph.' );
return;
}
findBtn.setDisabled( true );
new mw.Api().post( {
url: mw.config.get( 'wgScriptPath' ) + '/find_paragraph',
method: 'POST',
data: JSON.stringify( { book_name: book, chapter: chapter, paragraph: quote } ),
contentType: 'application/json'
} ).done( function ( data ) {
dialog.close(); // close mini form
// Open normal cite dialog
var citationDialog = new ve.ui.MWCitationDialog();
citationDialog.open();
// Pre-fill on open
citationDialog.getModel().once( 'change:paragraph', function () {
var model = citationDialog.getModel();
model.set( {
book: book,
chapter: chapter,
paragraph: String( data.index ),
quote: data.match
} );
} );
} ).fail( function ( xhr ) {
alert( xhr.responseJSON && xhr.responseJSON.reason || 'No match found.' );
} ).always( function () {
findBtn.setDisabled( false );
} );
} );
// Assemble and display the form
var panel = new OO.ui.PanelLayout( {
expanded: false,
padded: true,
framed: true
} );
panel.$element.append(
new OO.ui.FieldLayout( bookSelect, { label: 'Book', align: 'top' } ).$element,
new OO.ui.FieldLayout( chapterSelect, { label: 'Chapter', align: 'top' } ).$element,
new OO.ui.FieldLayout( quoteInput, { label: 'Paragraph text', align: 'top' } ).$element,
findBtn.$element
);
dialog.content.add( panel );
bookSelect.focus();
} );
} );
// Preload book list on page load
mw.loader.using( 'mediawiki.api' ).then( function () {
new mw.Api().get( {
url: mw.config.get( 'wgScriptPath' ) + '/find_paragraph/books'
} ).done( function ( res ) {
mw.config.set( 'wgWingsofFireBooks', res.available_books );
} );
} );
}() );