mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-11-28 00:01:05 +00:00
refactor: convert skin.citizen.scripts to packagedFiles
This commit is contained in:
parent
25822463a0
commit
56de894f6e
42
resources/skins.citizen.scripts/search.js
Normal file
42
resources/skins.citizen.scripts/search.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
var searchToggle = document.getElementById( 'search-checkbox' ),
|
||||
searchInput = document.getElementById( 'searchInput' ),
|
||||
pageReady = require( ( 'mediawiki.page.ready' ) );
|
||||
|
||||
/**
|
||||
* Focus in search box when search toggle checkbox is checked.
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function searchInputFocus() {
|
||||
if ( searchToggle.checked !== false ) {
|
||||
searchInput.focus();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check search toggle checkbox when search box is in focus.
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function searchToggleCheck() {
|
||||
if ( searchToggle.checked === false ) {
|
||||
searchToggle.checked = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {void}
|
||||
*/
|
||||
function init() {
|
||||
searchToggle.addEventListener( 'click', searchInputFocus );
|
||||
searchInput.addEventListener( 'focus', searchToggleCheck );
|
||||
pageReady.loadSearchModule(
|
||||
// Decide between new Citizen implementation or core
|
||||
mw.config.get( 'wgCitizenEnableSearch' ) ?
|
||||
'skins.citizen.scripts.search' : 'mediawiki.searchSuggest'
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: init
|
||||
};
|
12
resources/skins.citizen.scripts/skin.js
Normal file
12
resources/skins.citizen.scripts/skin.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
var themeToggle = require( './themeToggle.js' ),
|
||||
search = require( './search.js' );
|
||||
|
||||
/**
|
||||
* @return {void}
|
||||
*/
|
||||
function main() {
|
||||
themeToggle.init();
|
||||
search.init();
|
||||
}
|
||||
|
||||
main();
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* Citizen - Core JS
|
||||
* https://starcitizen.tools
|
||||
*/
|
||||
|
||||
var searchToggle = document.getElementById( 'search-checkbox' ),
|
||||
searchInput = document.getElementById( 'searchInput' ),
|
||||
pageReady = require( ( 'mediawiki.page.ready' ) );
|
||||
|
||||
/**
|
||||
* Focus in search box when search toggle checkbox is checked.
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function searchInputFocus() {
|
||||
if ( searchToggle.checked !== false ) {
|
||||
searchInput.focus();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check search toggle checkbox when search box is in focus.
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function searchToggleCheck() {
|
||||
if ( searchToggle.checked === false ) {
|
||||
searchToggle.checked = true;
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
searchToggle.addEventListener( 'click', searchInputFocus );
|
||||
searchInput.addEventListener( 'focus', searchToggleCheck );
|
||||
pageReady.loadSearchModule(
|
||||
// Decide between new Citizen implementation or core
|
||||
mw.config.get( 'wgCitizenEnableSearch' ) ?
|
||||
'skins.citizen.scripts.search' : 'mediawiki.searchSuggest'
|
||||
);
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
( function () {
|
||||
var theme = window.mw.cookie.get( 'skin-citizen-theme' );
|
||||
var toggleBtn = document.getElementById( 'theme-toggle' );
|
||||
|
||||
// * theme-toggle-light
|
||||
// * theme-toggle-dark
|
||||
toggleBtn.classList.add( 'theme-toggle-' + theme );
|
||||
|
||||
toggleBtn.addEventListener( 'click', function ( clickEvent ) {
|
||||
try {
|
||||
theme = theme === 'dark' ? 'light' : 'dark';
|
||||
|
||||
clickEvent.target.classList.remove( 'theme-toggle-light', 'theme-toggle-dark' );
|
||||
// * theme-toggle-light
|
||||
// * theme-toggle-dark
|
||||
clickEvent.target.classList.add( 'theme-toggle-' + theme );
|
||||
|
||||
try {
|
||||
window.mw.cookie.set( 'skin-citizen-theme', null );
|
||||
window.mw.cookie.set( 'skin-citizen-theme', theme );
|
||||
window.mw.cookie.set( 'skin-citizen-theme-override', '1' );
|
||||
} catch ( e ) {
|
||||
}
|
||||
|
||||
window.switchTheme();
|
||||
} catch ( e ) {
|
||||
}
|
||||
} );
|
||||
}() );
|
33
resources/skins.citizen.scripts/themeToggle.js
Normal file
33
resources/skins.citizen.scripts/themeToggle.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
function init() {
|
||||
var theme = window.mw.cookie.get( 'skin-citizen-theme' );
|
||||
var toggleBtn = document.getElementById( 'theme-toggle' );
|
||||
|
||||
// * theme-toggle-light
|
||||
// * theme-toggle-dark
|
||||
toggleBtn.classList.add( 'theme-toggle-' + theme );
|
||||
|
||||
toggleBtn.addEventListener( 'click', function ( clickEvent ) {
|
||||
try {
|
||||
theme = theme === 'dark' ? 'light' : 'dark';
|
||||
|
||||
clickEvent.target.classList.remove( 'theme-toggle-light', 'theme-toggle-dark' );
|
||||
// * theme-toggle-light
|
||||
// * theme-toggle-dark
|
||||
clickEvent.target.classList.add( 'theme-toggle-' + theme );
|
||||
|
||||
try {
|
||||
window.mw.cookie.set( 'skin-citizen-theme', null );
|
||||
window.mw.cookie.set( 'skin-citizen-theme', theme );
|
||||
window.mw.cookie.set( 'skin-citizen-theme-override', '1' );
|
||||
} catch ( e ) {
|
||||
}
|
||||
|
||||
window.switchTheme();
|
||||
} catch ( e ) {
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: init
|
||||
};
|
|
@ -127,8 +127,10 @@
|
|||
"styles": [ "resources/skins.citizen.styles.toc/skins.citizen.styles.toc.less" ]
|
||||
},
|
||||
"skins.citizen.scripts": {
|
||||
"scripts": [
|
||||
"resources/skins.citizen.scripts/skins.citizen.scripts.js"
|
||||
"packageFiles": [
|
||||
"resources/skins.citizen.scripts/skin.js",
|
||||
"resources/skins.citizen.scripts/themeToggle.js",
|
||||
"resources/skins.citizen.scripts/search.js"
|
||||
],
|
||||
"dependencies": [
|
||||
"mediawiki.page.ready",
|
||||
|
|
Loading…
Reference in a new issue