MediaWiki:Common.js: различия между версиями
Материал из melioration.space
Sonys (обсуждение | вклад) |
Sonys (обсуждение | вклад) |
||
| Строка 1: | Строка 1: | ||
| − | + | function setup() { | |
| − | + | var mathUpdater = new $.Deferred(); | |
| − | + | if ( mathUpdaterLs ) { | |
| − | function | + | mathUpdater.resolve(); |
| − | + | } else { | |
| − | + | mw.loader.using(['wikibase.api.RepoApi', 'wikibase.client.getMwApiForRepo'], function(){ | |
| − | + | var repoApi = new wikibase.api.RepoApi(wikibase.client.getMwApiForRepo()); | |
| − | + | repoApi.getEntities( wbSpellCheck, 'sitelinks').done( function( data ) { | |
| − | + | var currSite = mw.config.get( 'wgDBname' ); | |
| − | + | if ( data.entities && data.entities.hasOwnProperty( wbSpellCheck ) && data.entities[wbSpellCheck].sitelinks && data.entities[wbSpellCheck].sitelinks.hasOwnProperty( currSite ) ) { | |
| − | + | mispellsList = data.entities[wbSpellCheck].sitelinks[currSite].title; | |
| − | var | + | try { |
| − | + | localStorage.mathUpdaterLs = mathUpdaterLs; | |
| − | + | } catch(e) { | |
| − | + | $.cookie( 'mispellsList', mathUpdaterLs ); | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
} | } | ||
| − | } ); | + | mathUpdater.resolve(); |
| + | } else { | ||
| + | mw.notify( $( errors.installError.replace('{0}', wbSpellCheck) ) ); | ||
| + | mathUpdater.reject(); | ||
| + | } | ||
} ); | } ); | ||
| − | } | + | } ); |
| − | |||
} | } | ||
| − | + | return mathUpdater; | |
| − | function | + | }; |
| − | + | mw.hook( 've.activationComplete' ).add( function() { | |
| − | + | setup().then( function(){ | |
| − | + | var view =ve.init.target.getSurface().getView(); | |
| − | + | var doc = view.getDocument(); | |
| − | + | var model = ve.init.target.getSurface().getModel(); | |
| − | + | //while editing - only on current node | |
| − | + | model.on( 'documentUpdate', function () { | |
| − | + | try | |
| − | + | { | |
| − | + | var selection = model.getSelection().getRange(), | |
| − | + | node = selection && doc.getBranchNodeFromOffset( selection.start ), | |
| + | originalSelection; | ||
| + | if ( !( node instanceof ve.ce.ContentBranchNode ) ) { | ||
| + | return; | ||
| + | } | ||
| + | //remove spell errors from current node | ||
| + | $( node.$element[0] ).find('.spellError').contents().unwrap(); | ||
| + | //view.surfaceObserver.disable(); | ||
| + | checkSpells( $( node.$element[0] ) ); | ||
| + | //reset selection | ||
| + | selection = model.getSelection().getRange(); | ||
| + | originalSelection = view.getSelectionState( new ve.Range(selection.to, selection.to) ); | ||
| + | |||
| + | setTimeout( function () { | ||
| + | view.showSelectionState( originalSelection ); | ||
| + | } ); | ||
| + | } catch(err){ | ||
| + | console.log('Error in Gadget-Rechtschreibpruefung.js:documentUpdate'); | ||
| + | console.log(err); | ||
} | } | ||
| − | } | + | } ); |
| − | + | } ); | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
}); | }); | ||
Версия 19:10, 25 декабря 2020
function setup() {
var mathUpdater = new $.Deferred();
if ( mathUpdaterLs ) {
mathUpdater.resolve();
} else {
mw.loader.using(['wikibase.api.RepoApi', 'wikibase.client.getMwApiForRepo'], function(){
var repoApi = new wikibase.api.RepoApi(wikibase.client.getMwApiForRepo());
repoApi.getEntities( wbSpellCheck, 'sitelinks').done( function( data ) {
var currSite = mw.config.get( 'wgDBname' );
if ( data.entities && data.entities.hasOwnProperty( wbSpellCheck ) && data.entities[wbSpellCheck].sitelinks && data.entities[wbSpellCheck].sitelinks.hasOwnProperty( currSite ) ) {
mispellsList = data.entities[wbSpellCheck].sitelinks[currSite].title;
try {
localStorage.mathUpdaterLs = mathUpdaterLs;
} catch(e) {
$.cookie( 'mispellsList', mathUpdaterLs );
}
mathUpdater.resolve();
} else {
mw.notify( $( errors.installError.replace('{0}', wbSpellCheck) ) );
mathUpdater.reject();
}
} );
} );
}
return mathUpdater;
};
mw.hook( 've.activationComplete' ).add( function() {
setup().then( function(){
var view =ve.init.target.getSurface().getView();
var doc = view.getDocument();
var model = ve.init.target.getSurface().getModel();
//while editing - only on current node
model.on( 'documentUpdate', function () {
try
{
var selection = model.getSelection().getRange(),
node = selection && doc.getBranchNodeFromOffset( selection.start ),
originalSelection;
if ( !( node instanceof ve.ce.ContentBranchNode ) ) {
return;
}
//remove spell errors from current node
$( node.$element[0] ).find('.spellError').contents().unwrap();
//view.surfaceObserver.disable();
checkSpells( $( node.$element[0] ) );
//reset selection
selection = model.getSelection().getRange();
originalSelection = view.getSelectionState( new ve.Range(selection.to, selection.to) );
setTimeout( function () {
view.showSelectionState( originalSelection );
} );
} catch(err){
console.log('Error in Gadget-Rechtschreibpruefung.js:documentUpdate');
console.log(err);
}
} );
} );
});