CSS hides all, JS shows unhidden fields via API
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Hide profile fields */
|
||||
/* Hide all profile fields by default */
|
||||
.personal-settings-setting-box:has(#account-property-pronouns) { display: none !important; }
|
||||
.personal-settings-setting-box:has(#account-property-role) { display: none !important; }
|
||||
.personal-settings-setting-box:has(#account-property-headline) { display: none !important; }
|
||||
@@ -11,3 +11,6 @@
|
||||
.personal-settings-setting-box:has(#account-property-twitter) { display: none !important; }
|
||||
.personal-settings-setting-box:has(#account-property-fediverse) { display: none !important; }
|
||||
.personal-settings-setting-box:has(#account-property-location) { display: none !important; }
|
||||
|
||||
/* Show fields in this list */
|
||||
.show-field { display: block !important; }
|
||||
@@ -21,59 +21,16 @@ class Application extends App implements IBootstrap {
|
||||
}
|
||||
|
||||
public function register(IRegistrationContext $context): void {
|
||||
$context->registerService(IConfig::class, function($c) {
|
||||
return $c->get(IConfig::class);
|
||||
});
|
||||
|
||||
// Load CSS - hides all by default
|
||||
$context->registerEventListener(
|
||||
TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS,
|
||||
LoadStylesListener::class
|
||||
function() {
|
||||
Util::addStyle('minimalprofile', 'minimalprofile');
|
||||
Util::addScript('minimalprofile', 'minimalprofile');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function boot(IBootContext $context): void {
|
||||
}
|
||||
}
|
||||
|
||||
class LoadStylesListener {
|
||||
private IConfig $config;
|
||||
|
||||
public function __construct(IConfig $config) {
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function __invoke(): void {
|
||||
$value = $this->config->getAppValue('minimalprofile', 'hidden_fields', '');
|
||||
$hidden = ($value !== '') ? json_decode($value, true) ?? [] : [];
|
||||
|
||||
if (empty($hidden)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$selectors = [
|
||||
'pronouns' => '#account-property-pronouns',
|
||||
'role' => '#account-property-role',
|
||||
'headline' => '#account-property-headline',
|
||||
'biography' => '#account-property-biography',
|
||||
'organisation' => '#account-property-organisation',
|
||||
'phone' => '#account-property-phone',
|
||||
'address' => '#account-property-address',
|
||||
'birthdate' => '#account-property-birthdate',
|
||||
'website' => '#account-property-website',
|
||||
'twitter' => '#account-property-twitter',
|
||||
'fediverse' => '#account-property-fediverse',
|
||||
'location' => '#account-property-location',
|
||||
];
|
||||
|
||||
$css = '';
|
||||
foreach ($hidden as $field) {
|
||||
if (isset($selectors[$field])) {
|
||||
$css .= '.personal-settings-setting-box:has(' . $selectors[$field] . ') { display: none !important; }' . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
if ($css) {
|
||||
Util::addInlineStyle($css);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user