jquery.wikiEditor.preview: Clean up

* Rename 'collection' to 'loadmodules'.
* Consistently close parentheses and brackets at the same
  indentation level as they were opened.
* Use $.ajax directly instead of $.post, especially the fourth
  argument to $.post makes it hard to read.
* Use promise interface of $.ajax and $.post instead of the
  (deprecated) callback parameter.

Change-Id: I48924c9a1ce29829f8994be05c46d5563b2c25d6
This commit is contained in:
Timo Tijhof 2014-05-04 15:50:52 +02:00
parent 0be6642d42
commit d0ebd8f812

View file

@ -53,37 +53,37 @@ fn: {
}
context.modules.preview.$preview.find( '.wikiEditor-preview-contents' ).empty();
context.modules.preview.$preview.find( '.wikiEditor-preview-loading' ).show();
$.post(
mw.util.wikiScript( 'api' ),
{
$.ajax( {
url: mw.util.wikiScript( 'api' ),
type: 'POST',
dataType: 'json',
data: {
format: 'json',
action: 'parse',
title: mw.config.get( 'wgPageName' ),
text: wikitext,
prop: 'text|modules',
pst: ''
},
function ( data ) {
if (
typeof data.parse === 'undefined' ||
typeof data.parse.text === 'undefined' ||
typeof data.parse.text['*'] === 'undefined'
) {
return;
}
context.modules.preview.previewText = wikitext;
context.modules.preview.$preview.find( '.wikiEditor-preview-loading' ).hide();
context.modules.preview.$preview.find( '.wikiEditor-preview-contents' )
.html( data.parse.text['*'] )
.find( 'a:not([href^=#])' ).click( false );
var collection = data.parse.modules.concat(
data.parse.modulescripts,
data.parse.modulestyles,
data.parse.modulemessages );
mw.loader.load( collection );
},
'json'
);
}
} ).done( function ( data ) {
if ( !data.parse || !data.parse.text || data.parse.text['*'] === undefined ) {
return;
}
context.modules.preview.previewText = wikitext;
context.modules.preview.$preview.find( '.wikiEditor-preview-loading' ).hide();
context.modules.preview.$preview.find( '.wikiEditor-preview-contents' )
.html( data.parse.text['*'] )
.find( 'a:not([href^=#])' )
.click( false );
var loadmodules = data.parse.modules.concat(
data.parse.modulescripts,
data.parse.modulestyles,
data.parse.modulemessages
);
mw.loader.load( loadmodules );
} );
}
} );
@ -101,15 +101,18 @@ fn: {
context.$changesTab.find( '.wikiEditor-preview-loading' ).show();
// Call the API. First PST the input, then diff it
var postdata = {
format: 'json',
action: 'parse',
title: mw.config.get( 'wgPageName' ),
onlypst: '',
text: wikitext
};
$.post( mw.util.wikiScript( 'api' ), postdata, function ( data ) {
$.ajax( {
url: mw.util.wikiScript( 'api' ),
type: 'POST',
dataType: 'json',
data: {
format: 'json',
action: 'parse',
title: mw.config.get( 'wgPageName' ),
onlypst: '',
text: wikitext
}
} ).done( function ( data ) {
try {
var postdata2 = {
format: 'json',
@ -125,22 +128,29 @@ fn: {
postdata2.rvsection = section;
}
$.post( mw.util.wikiScript( 'api' ), postdata2, function ( data ) {
// Add diff CSS
mw.loader.load( 'mediawiki.action.history.diff' );
try {
var diff = data.query.pages[data.query.pageids[0]]
.revisions[0].diff['*'];
context.$changesTab.find( 'table.diff tbody' )
.html( diff );
context.modules.preview.changesText = wikitext;
} catch ( e ) { } // "blah is undefined" error, ignore
context.$changesTab
.find( '.wikiEditor-preview-loading' ).hide();
}, 'json'
);
} catch ( e ) { } // "blah is undefined" error, ignore
}, 'json' );
$.ajax( {
url: mw.util.wikiScript( 'api' ),
type: 'POST',
dataType: 'json',
data: postdata2
} ).done( function ( data ) {
// Add diff CSS
mw.loader.load( 'mediawiki.action.history.diff' );
try {
var diff = data.query.pages[data.query.pageids[0]]
.revisions[0].diff['*'];
context.$changesTab.find( 'table.diff tbody' ).html( diff );
context.modules.preview.changesText = wikitext;
} catch ( e ) {
// "data.blah is undefined" error, ignore
}
context.$changesTab.find( '.wikiEditor-preview-loading' ).hide();
} );
} catch ( e ) {
// "data.blah is undefined" error, ignore
}
} );
}
} );