pad.libre-service.eu-etherpad/src/static/js/skin_variants.js

56 lines
2 KiB
JavaScript
Raw Normal View History

// Specific hash to display the skin variants builder popup
2020-11-23 19:24:19 +01:00
if (window.location.hash.toLowerCase() == '#skinvariantsbuilder') {
$('#skin-variants').addClass('popup-show');
2020-11-23 19:24:19 +01:00
$('.skin-variant').change(() => {
updateSkinVariantsClasses();
});
2020-11-23 19:24:19 +01:00
const containers = ['editor', 'background', 'toolbar'];
const colors = ['super-light', 'light', 'dark', 'super-dark'];
updateCheckboxFromSkinClasses();
updateSkinVariantsClasses();
// add corresponding classes when config change
function updateSkinVariantsClasses() {
2020-11-23 19:24:19 +01:00
const domsToUpdate = [
$('html'),
$('iframe[name=ace_outer]').contents().find('html'),
2020-11-23 19:24:19 +01:00
$('iframe[name=ace_outer]').contents().find('iframe[name=ace_inner]').contents().find('html'),
];
2020-11-23 19:24:19 +01:00
colors.forEach((color) => {
containers.forEach((container) => {
domsToUpdate.forEach((el) => { el.removeClass(`${color}-${container}`); });
});
});
2020-11-23 19:24:19 +01:00
domsToUpdate.forEach((el) => { el.removeClass('full-width-editor'); });
2020-11-23 19:24:19 +01:00
const new_classes = [];
$('select.skin-variant-color').each(function () {
new_classes.push(`${$(this).val()}-${$(this).data('container')}`);
});
if ($('#skin-variant-full-width').is(':checked')) new_classes.push('full-width-editor');
2020-11-23 19:24:19 +01:00
domsToUpdate.forEach((el) => { el.addClass(new_classes.join(' ')); });
2020-11-23 19:24:19 +01:00
$('#skin-variants-result').val(`"skinVariants": "${new_classes.join(' ')}",`);
}
// run on init
function updateCheckboxFromSkinClasses() {
2020-11-23 19:24:19 +01:00
$('html').attr('class').split(' ').forEach((classItem) => {
var container = classItem.split('-').slice(-1);
2020-11-23 19:24:19 +01:00
var container = classItem.substring(classItem.lastIndexOf('-') + 1, classItem.length);
if (containers.indexOf(container) > -1) {
2020-11-23 19:24:19 +01:00
const color = classItem.substring(0, classItem.lastIndexOf('-'));
$(`.skin-variant-color[data-container="${container}"`).val(color);
}
2020-11-23 19:24:19 +01:00
});
$('#skin-variant-full-width').prop('checked', $('html').hasClass('full-width-editor'));
}
}