MediaWiki

Difference between revisions of "Common.js"

m
m
Line 53: Line 53:
 
(works from the second step onwards) */
 
(works from the second step onwards) */
 
$(function() {
 
$(function() {
  if (mw.config.get('wgPageName') !== 'Special:RecordWizard') {
 
    return;
 
  }
 
  window.onbeforeunload = function() {
 
      console.log('Window out 1');
 
    return "Do you want to leave the page? All your unsaved changes will be lost.";
 
  };
 
 
 
 
if (mw.config.get('wgPageName') === 'Special:RecordWizard') {
 
if (mw.config.get('wgPageName') === 'Special:RecordWizard') {
 
     window.onbeforeunload = function() {
 
     window.onbeforeunload = function() {
Line 68: Line 59:
 
     };
 
     };
 
}
 
}
 
 
});
 
});

Revision as of 21:37, 28 May 2022

// Page-specific scripts modules and conditional loading
// General sugar
// RecordWizard sugar

/* *************************************************************** */
/* PAGE-SPECIFIC SCRIPTS LOADINGS ******************************** */
// Documentation: https://m.mediawiki.org/wiki/ResourceLoader/Architecture#Resource:_Scripts
// Documentation: https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.loader
//🎷🥁🎸🐣📔🗻🌏
// LastAudiosBoxes
if (/^LinguaLibre:Main/.test(mw.config.get('wgPageName'))) {
  console.log('🎸 Last Audios');
  mw.loader.load('/index.php?title=MediaWiki:LastAudios.js&action=raw&ctype=text/javascript');
}
// SoundLibrary
if (/^LinguaLibre:Explore_the_sound_library(\/[a-z_-]+)?$/.test(mw.config.get('wgPageName'))) {
  console.log('🥁 Sound library');
  mw.loader.load('/index.php?title=MediaWiki:SoundLibrary.js&action=raw&ctype=text/javascript');
}
// Item pages additional sugar
if (/^(Q|Property:P)[0-9]+$/.test(mw.config.get('wgPageName'))) {
  console.log('🍭 ItemsSugar ');
  mw.loader.load('/index.php?title=MediaWiki:ItemsSugar.js&action=raw&ctype=text/javascript');
}
// Lexeme Queries Generator (OOUI)
if (/^Template:LexemeQueriesGenerator$/.test(mw.config.get('wgPageName')) || /^Help:SPARQL_2$/.test(mw.config.get('wgPageName'))) {
  console.log('📔 Lexeme Queries Generator');
  mw.loader.load('/index.php?title=MediaWiki:LexemeQueriesGenerator.js&action=raw&ctype=text/javascript');
}
// SPARQL to data (OOUI)
if (/SPARQL/.test(mw.config.get('wgPageName')) || /parql/.test(mw.config.get('wgPageName'))) {
  console.log('🚀 SPARQL to data');
  mw.loader.load('/index.php?title=MediaWiki:Sparql2data.js&action=raw&ctype=text/javascript');
}

/* *************************************************************** */
/* In development *************************************** */
// User:Yug: Language overview
if (/Languages/.test(mw.config.get('wgPageName'))) {
  console.log('🌏 Languages gallery');
  mw.loader.load('/index.php?title=MediaWiki:LanguagesGallery.js&action=raw&ctype=text/javascript');
}
// User:Yug: Search by words, see https://jsfiddle.net/hugolpz/ecpzy0fo/89/
if (/^LinguaLibre:Search_by(\/[a-z_-]+)?$/.test(mw.config.get('wgPageName'))) {
  console.log('🐣 Search by word');
  mw.loader.load('/index.php?title=MediaWiki:SearchBy.js&action=raw&ctype=text/javascript');
}
// Minorities languages statistics

/* *************************************************************** */
/* RECORD WIZARD SUGAR ******************************************* */
/*Confirmation message when users try to leave the Record Wizard
(works from the second step onwards) */
$(function() {
if (mw.config.get('wgPageName') === 'Special:RecordWizard') {
    window.onbeforeunload = function() {
    	console.log('Window out 2');
    	return "Do you want to leave the page? All your unsaved changes will be lost.";
    };
}
});