Final clean version
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* Minimal Profile - Show fields based on config
|
||||||
|
*/
|
||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
console.log('MinimalProfile: Loading...');
|
|
||||||
|
|
||||||
var fieldSelectors = {
|
var fieldSelectors = {
|
||||||
'pronouns': '#account-property-pronouns',
|
'pronouns': '#account-property-pronouns',
|
||||||
'role': '#account-property-role',
|
'role': '#account-property-role',
|
||||||
'headline': '#account-property-headline',
|
'headline': '#account-property-headline',
|
||||||
'biography': '#account-property-biography',
|
'biography': '#account-property-biography',
|
||||||
'organisation': '#account-property-organisation',
|
'organisation': '#account-property-organisation',
|
||||||
@@ -17,48 +19,39 @@
|
|||||||
'location': '#account-property-location'
|
'location': '#account-property-location'
|
||||||
};
|
};
|
||||||
|
|
||||||
function updateCss(hiddenFields) {
|
function showFields(hiddenFields) {
|
||||||
if (!hiddenFields || hiddenFields.length === 0) {
|
var allFields = Object.keys(fieldSelectors);
|
||||||
console.log('MinimalProfile: No hidden fields');
|
allFields.forEach(function(field) {
|
||||||
return;
|
if (!hiddenFields.includes(field)) {
|
||||||
}
|
var selector = fieldSelectors[field];
|
||||||
var css = '';
|
var el = document.querySelector(selector);
|
||||||
hiddenFields.forEach(function(field) {
|
if (el) {
|
||||||
var selector = fieldSelectors[field];
|
var box = el.closest('.personal-settings-setting-box');
|
||||||
if (selector) {
|
if (box) {
|
||||||
css += selector + ' { display: none !important; } ';
|
box.style.display = '';
|
||||||
console.log('MinimalProfile: Hiding', field, selector);
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
|
|
||||||
var style = document.createElement('style');
|
|
||||||
style.id = 'minimalprofile-style';
|
|
||||||
style.textContent = css;
|
|
||||||
document.head.appendChild(style);
|
|
||||||
console.log('MinimalProfile: CSS applied', css);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var req = new XMLHttpRequest();
|
function init() {
|
||||||
req.onload = function() {
|
var req = new XMLHttpRequest();
|
||||||
console.log('MinimalProfile: Response status', req.status);
|
req.onload = function() {
|
||||||
if (req.status === 200) {
|
if (req.status === 200) {
|
||||||
try {
|
try {
|
||||||
var data = JSON.parse(req.responseText);
|
var data = JSON.parse(req.responseText);
|
||||||
console.log('MinimalProfile: Data', data);
|
showFields(data.hiddenFields || []);
|
||||||
updateCss(data.hiddenFields);
|
} catch (e) {}
|
||||||
} catch (e) {
|
|
||||||
console.error('MinimalProfile: Error', e);
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
req.open('GET', OC.generateUrl('/apps/minimalprofile/api/v1/hidden-fields'));
|
||||||
req.onerror = function() {
|
req.send();
|
||||||
console.error('MinimalProfile: Request failed');
|
}
|
||||||
};
|
|
||||||
req.open('GET', OC.generateUrl('/apps/minimalprofile/api/v1/hidden-fields'));
|
|
||||||
req.send();
|
|
||||||
|
|
||||||
setTimeout(function() {
|
if (document.readyState === 'loading') {
|
||||||
var el = document.querySelector('#account-property-pronouns');
|
document.addEventListener('DOMContentLoaded', init);
|
||||||
console.log('MinimalProfile: Pronouns element found?', !!el);
|
} else {
|
||||||
}, 3000);
|
init();
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
Reference in New Issue
Block a user