jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/367874 )
Change subject: Disable prefs in GlobalPreferences unless they're
globally-enabled
......................................................................
Disable prefs in GlobalPreferences unless they're globally-enabled
Also highlight the relevant preference labels on hover over
the global checkbox.
Adds ESlint and stylelint configuration.
Bug: T68869
Change-Id: Icde9ffbda6209fd866415b29774247396119166f
---
A .eslintrc.json
A .gitignore
A .stylelintrc
M Gruntfile.js
M SpecialGlobalPreferences.php
M extension.json
M package.json
M resources/ext.GlobalPreferences.special.css
A resources/ext.GlobalPreferences.special.js
A resources/ext.GlobalPreferences.special.nojs.css
10 files changed, 122 insertions(+), 14 deletions(-)
Approvals:
MaxSem: Looks good to me, approved
jenkins-bot: Verified
diff --git a/.eslintrc.json b/.eslintrc.json
new file mode 100644
index 0000000..4843240
--- /dev/null
+++ b/.eslintrc.json
@@ -0,0 +1,10 @@
+{
+ "extends": "wikimedia",
+ "env": {
+ "browser": true,
+ "jquery": true
+ },
+ "globals": {
+ "mediaWiki": false
+ }
+}
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
diff --git a/.stylelintrc b/.stylelintrc
new file mode 100644
index 0000000..2c90730
--- /dev/null
+++ b/.stylelintrc
@@ -0,0 +1,3 @@
+{
+ "extends": "stylelint-config-wikimedia"
+}
diff --git a/Gruntfile.js b/Gruntfile.js
index 7756e75..b6d397f 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -1,9 +1,30 @@
-/*jshint node:true */
+/* eslint-env node */
module.exports = function ( grunt ) {
- grunt.loadNpmTasks( 'grunt-jsonlint' );
grunt.loadNpmTasks( 'grunt-banana-checker' );
+ grunt.loadNpmTasks( 'grunt-eslint' );
+ grunt.loadNpmTasks( 'grunt-jsonlint' );
+ grunt.loadNpmTasks( 'grunt-stylelint' );
grunt.initConfig( {
+ eslint: {
+ src: [
+ '**/*.js',
+ '!node_modules/**',
+ '!vendor/**',
+ '!tests/externals/**',
+ '!docs/**'
+ ]
+ },
+ // Lint – Styling
+ stylelint: {
+ options: {
+ syntax: 'less'
+ },
+ all: [
+ 'resources/**/*.css',
+ 'resources/**/*.less'
+ ]
+ },
banana: {
all: 'i18n/'
},
@@ -15,6 +36,7 @@
}
} );
- grunt.registerTask( 'test', [ 'jsonlint', 'banana' ] );
+ grunt.registerTask( 'lint', [ 'eslint', 'stylelint', 'jsonlint',
'banana' ] );
+ grunt.registerTask( 'test', 'lint' );
grunt.registerTask( 'default', 'test' );
};
diff --git a/SpecialGlobalPreferences.php b/SpecialGlobalPreferences.php
index 9d317e0..ac0ab5e 100644
--- a/SpecialGlobalPreferences.php
+++ b/SpecialGlobalPreferences.php
@@ -16,7 +16,10 @@
$this->setHeaders();
throw new ErrorPageError( 'globalprefs-error-header',
'globalprefs-notglobal' );
}
- $this->getOutput()->addModuleStyles(
'ext.GlobalPreferences.special' );
+ // Add module styles and scripts separately
+ // so non-JS users get the styles quicker and to avoid a FOUC.
+ $this->getOutput()->addModuleStyles(
'ext.GlobalPreferences.special.nojs' );
+ $this->getOutput()->addModules( 'ext.GlobalPreferences.special'
);
parent::execute( $par );
}
diff --git a/extension.json b/extension.json
index 58a4dd7..2bc56f7 100644
--- a/extension.json
+++ b/extension.json
@@ -50,7 +50,11 @@
},
"ResourceModules": {
"ext.GlobalPreferences.special": {
- "styles": "ext.GlobalPreferences.special.css"
+ "styles": "ext.GlobalPreferences.special.css",
+ "scripts": "ext.GlobalPreferences.special.js"
+ },
+ "ext.GlobalPreferences.special.nojs": {
+ "styles": "ext.GlobalPreferences.special.nojs.css"
}
},
"manifest_version": 1
diff --git a/package.json b/package.json
index c68038a..11b436c 100644
--- a/package.json
+++ b/package.json
@@ -4,10 +4,12 @@
"test": "grunt test"
},
"devDependencies": {
- "grunt": "0.4.5",
- "grunt-banana-checker": "0.4.0",
- "grunt-cli": "0.1.13",
- "grunt-jsonlint": "1.0.7",
- "stylelint": "7.8.0"
+ "grunt": "1.0.1",
+ "grunt-banana-checker": "0.5.0",
+ "grunt-eslint": "19.0.0",
+ "grunt-jsonlint": "1.0.8",
+ "grunt-stylelint": "0.7.0",
+ "eslint-config-wikimedia": "0.4.0",
+ "stylelint-config-wikimedia": "0.4.1"
}
}
diff --git a/resources/ext.GlobalPreferences.special.css
b/resources/ext.GlobalPreferences.special.css
index 7510123..ef5a087 100644
--- a/resources/ext.GlobalPreferences.special.css
+++ b/resources/ext.GlobalPreferences.special.css
@@ -1,6 +1,9 @@
-input.mw-globalprefs-global-check {
- margin-left: 20px;
+.globalprefs-disabled {
+ opacity: 0.5;
}
-tr.mw-globalprefs-global-check {
- font-size: 13px;
+.globalprefs-hover {
+ background-color: rgba( 255, 224, 97, 0.4 );
+}
+.mw-special-GlobalPreferences form.mw-htmlform table {
+ border-collapse: collapse;
}
diff --git a/resources/ext.GlobalPreferences.special.js
b/resources/ext.GlobalPreferences.special.js
new file mode 100644
index 0000000..59658de
--- /dev/null
+++ b/resources/ext.GlobalPreferences.special.js
@@ -0,0 +1,54 @@
+( function ( mw, $ ) {
+ 'use strict';
+
+ $( 'input.mw-globalprefs-global-check' ).on( 'change', function () {
+ var $labels,
+
+ // Find the name (without the '-global' suffix, but
with the 'wp' prefix).
+ fullName = $( this ).attr( 'name' ),
+ name = fullName.substr( 0, fullName.length -
'-global'.length ),
+
+ // Is this preference enabled globally?
+ enabled = $( this ).prop( 'checked' ),
+
+ // The table rows relating to this preference
+ // (two or three rows, depending on whether there's a
help row).
+ $globalCheckRow,
+ $labelRow,
+ $rows;
+
+ // All the labels for this preference (not all have for='').
+ $labels = $( 'label[for^=\'mw-input-' + name + '\']' )
+ .closest( 'tr' )
+ .find( 'label' )
+ .not( '[for$=\'-global\']' );
+
+ // Disable or enable the related preferences inputs.
+ $( ':input[name=\'' + name + '\']' ).prop( 'disabled', !enabled
);
+ if ( enabled ) {
+ $labels.removeClass( 'globalprefs-disabled' );
+ } else {
+ $labels.addClass( 'globalprefs-disabled' );
+ }
+
+ // Collect the related rows. The latter two in the $rows array
will often be the same element.
+ $globalCheckRow = $( this ).closest( 'tr' );
+ $labelRow = $labels.closest( 'tr' );
+ $rows = $( [
+ $labelRow[ 0 ],
+ $labelRow.next()[ 0 ],
+ $globalCheckRow[ 0 ]
+ ] );
+
+ // Add a class on hover, to highlight the related rows.
+ $( this ).add( 'label[for=\'' + $( this ).attr( 'id' ) + '\']'
).hover( function () {
+ // Hover on.
+ $rows.addClass( 'globalprefs-hover' );
+ }, function () {
+ // Hover off.
+ $rows.removeClass( 'globalprefs-hover' );
+ } );
+
+ } ).change();
+
+}( mediaWiki, jQuery ) );
diff --git a/resources/ext.GlobalPreferences.special.nojs.css
b/resources/ext.GlobalPreferences.special.nojs.css
new file mode 100644
index 0000000..71deae3
--- /dev/null
+++ b/resources/ext.GlobalPreferences.special.nojs.css
@@ -0,0 +1,6 @@
+input.mw-globalprefs-global-check {
+ margin-left: 2em;
+}
+tr.mw-globalprefs-global-check {
+ font-size: smaller;
+}
--
To view, visit https://gerrit.wikimedia.org/r/367874
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Icde9ffbda6209fd866415b29774247396119166f
Gerrit-PatchSet: 13
Gerrit-Project: mediawiki/extensions/GlobalPreferences
Gerrit-Branch: master
Gerrit-Owner: Samwilson <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: Samwilson <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits