Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement updated design notification banners #7

Merged
merged 13 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": [
"wikimedia/mediawiki",
"wikimedia/client/common",
"wikimedia/language/es2020"
],
"globals": {
"require": "readonly",
"module": "readonly",
"OO": "readonly"
},
"rules": {
"space-before-function-paren": "off",
"no-jquery/no-global-selector": "off",
"vars-on-top": "off",
"one-var": "off",
"no-use-before-define": "off",
"mediawiki/class-doc": "off",
"mediawiki/no-nodelist-unsupported-methods": "off",
"jsdoc/require-param-type": "off"
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/node_modules/
composer.lock
package-lock.json
.idea/
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,10 @@
"minus-x fix .",
"phpcbf"
]
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
9 changes: 8 additions & 1 deletion extension.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "NetworkNotice",
"version": "3.2.1",
"version": "3.3.0",
"author": [
"Tephus",
"[https://fo-nttax.de Alex Winkler]"
Expand All @@ -26,10 +26,14 @@
"HookHandlers": {
"Main": {
"class": "\\Liquipedia\\Extension\\NetworkNotice\\Hooks\\MainHookHandler"
},
"Schema": {
"class": "\\Liquipedia\\Extension\\NetworkNotice\\Hooks\\SchemaHookHandler"
}
},
"Hooks": {
"BeforePageDisplay": "Main",
"LoadExtensionSchemaUpdates": "Schema",
"LPExtensionMenu": [
"Liquipedia\\Extension\\NetworkNotice\\Hooks\\LegacyHooks::onLPExtensionMenu"
],
Expand All @@ -48,6 +52,9 @@
"styles": [
"styles/ext.networknotice.Notice.less"
],
"scripts": [
"scripts/ext.networknotice.Notice.js"
],
"position": "bottom"
}
},
Expand Down
5 changes: 3 additions & 2 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"networknotice-delete-network-notice-heading": "Delete network notice",
"networknotice-preview-heading": "Preview",
"networknotice-delete-network-notice-deletion-heading": "Confirm deletion",
"networknotice-close-button": "Close notification",

"networknotice-create-notice-desc": "Creates network notices (site notices) that can be displayed network wide, with more features than standard site notices.",
"networknotice-create-notice-label-label": "Label:",
Expand Down Expand Up @@ -56,9 +57,9 @@
"networknotice-button-delete-label": "delete",
"networknotice-text-false-label": "false",
"networknotice-text-true-label": "true",

"networknotice-success-updated": "Network notice successfully updated!",
"networknotice-success-created": "Network notice successfully created!",

"lpextmenu-networknotice": "Network Notice"
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"license": "MIT",
"private": true,
"devDependencies": {
"eslint-config-wikimedia": "*",
"stylelint-config-wikimedia": "*"
},
"scripts": {
Expand Down
59 changes: 59 additions & 0 deletions resources/scripts/ext.networknotice.Notice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
( function ( window, document ) {
'use strict';

const LOCAL_STORAGE_KEY = 'networknotice';

function init() {
if ( 'localStorage' in window ) {
document.querySelectorAll( '[data-component="network-notice"]' ).forEach( function( notice ) {
const key = notice.dataset.id;
if ( isInStorage( key ) ) {
notice.classList.add( 'd-none' );
} else {
const closeButton = notice.querySelector(
'[data-component="network-notice-close-button"]'
);
closeButton.onclick = function() {
notice.classList.add( 'd-none' );
putIntoStorage( key );
};
}
} );
}
}

function getItemsFromStorage() {
const items = localStorage.getItem( LOCAL_STORAGE_KEY );
try {
return items ? JSON.parse( items ) : [];
} catch ( e ) {
return [ ];
}
}

function putIntoStorage( key ) {
const items = getItemsFromStorage();
if ( !items.includes( key ) ) {
items.push( key );
localStorage.setItem( LOCAL_STORAGE_KEY, JSON.stringify( items ) );
}
}

function isInStorage( key ) {
const items = getItemsFromStorage();
return items.includes( key );
}

/**
* Check on document readyState
*/
if ( document.readyState === 'complete' ) {
init();
} else {
document.addEventListener( 'readystatechange', () => {
if ( document.readyState === 'complete' ) {
init();
}
} );
}
}( window, document ) );
Loading
Loading