feat!: rename theme respondage_vanilla -> vanilla_respondage, variants -> respondage_<client>
Prompt V (prompts.md rows 51-54). Mother theme folder + <name> renamed to vanilla_respondage (version 3.3.0); client variants renamed to respondage_defensie / respondage_erasmus (<extends>vanilla_respondage</extends>, auto-derived by build.php). export_public.sh now derives the release name from the theme dir and the leak-check glob matches ../respondage_* siblings, so the public-release leak check keeps working after the rename (sabotage-tested). All doc/tooling references updated; local-only files stay gitignored. Also includes the pending uncommitted theme work from this testing week (custom options page, header logos, sticky-header options, bundled OFL fonts, per-element font overrides, font-dropdown reordering, jsdom tests) that was verified locally but not yet pushed. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
parent
37f28f08e6
commit
cffd3cefa6
1 changed files with 3701 additions and 898 deletions
|
|
@ -1,6 +1,12 @@
|
|||
var ThemeOptions = function(){
|
||||
// Custom options-page JavaScript for this theme (used because config.xml sets
|
||||
// <optionspage>custom</optionspage>). This is a copy of the core package
|
||||
// assets/packages/themeoptions-core/themeoptions-core.js, patched so that
|
||||
// .action_hide_on_inherit rows are also hidden when "Inherit everything" is on
|
||||
// (the custom page has no per-category tabs to disable).
|
||||
// When updating, diff against the core file and re-apply that patch.
|
||||
|
||||
var ThemeOptions = function () {
|
||||
'use strict';
|
||||
"use strict";
|
||||
//////////////////
|
||||
// Define necessary globals
|
||||
|
||||
|
|
@ -9,11 +15,15 @@ var ThemeOptions = function () {
|
|||
var inheritPossible = ($('#general_inherit_active').length > 0);
|
||||
|
||||
//get option Object from Template configuration options
|
||||
var optionObject = {'general_inherit': 1};
|
||||
var optionObject = {
|
||||
"general_inherit": 1
|
||||
}
|
||||
|
||||
var optionCssFiles = JSON.parse($('#optionCssFiles').val());
|
||||
//get the global form
|
||||
var globalForm = $('.action_update_options_string_form');
|
||||
|
||||
|
||||
/////////////////
|
||||
// Define methods run on startup
|
||||
|
||||
|
|
@ -44,8 +54,13 @@ var ThemeOptions = function () {
|
|||
if (generalInherit()) {
|
||||
$('#general_inherit_on').prop('checked', true).trigger('change').closest('label').addClass('active');
|
||||
$('.action_hide_on_inherit').addClass('d-none');
|
||||
$('.tab_action_hide_on_inherit').addClass('ls-tab-disabled');
|
||||
|
||||
} else {
|
||||
$('#general_inherit_off').prop('checked', true).trigger('change').closest('label').addClass('active');
|
||||
$('.action_hide_on_inherit_wrapper').addClass('d-none');
|
||||
$('.action_hide_on_inherit').removeClass('d-none');
|
||||
$('.tab_action_hide_on_inherit').removeClass('ls-tab-disabled');
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -63,7 +78,22 @@ var ThemeOptions = function () {
|
|||
$(item).val((inheritPossible ? 'inherit' : false));
|
||||
}
|
||||
|
||||
optionObject[$(item).attr('name')] = $(item).val();
|
||||
optionObject[$(item).attr('name')] = getOptionFieldValue(item);
|
||||
});
|
||||
|
||||
globalForm.find('.selector_image_selector').each(function (i, item) {
|
||||
|
||||
// disable the preview image button if the image
|
||||
// selected could not be mapped to one of the images
|
||||
// that actually exists within the theme
|
||||
const src = $(item).find('option:selected').data('lightbox-src');
|
||||
const missing = src === '';
|
||||
const itemId = $(item).attr('id');
|
||||
const button = $(`button[data-bs-target="#${itemId}"]`);
|
||||
button.prop('disabled', missing);
|
||||
|
||||
// add some feedback to the user, mark field invalid
|
||||
$(item).toggleClass('is-invalid', missing);
|
||||
});
|
||||
|
||||
globalForm.find('.selector_option_radio_field ').each(function (i, item) {
|
||||
|
|
@ -76,11 +106,31 @@ var ThemeOptions = function () {
|
|||
if ($(item).prop('checked')) {
|
||||
optionObject[$(item).attr('name')] = $(item).val();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// THEME ADDITION: checkboxes (checked = "on"); an untouched box that was
|
||||
// "inherit" keeps "inherit" (see prepareCheckboxField)
|
||||
globalForm.find('.selector_option_checkbox_field').each(function (i, item) {
|
||||
if ($(item).prop('disabled')) {
|
||||
optionObject[$(item).attr('name')] = (inheritPossible ? 'inherit' : 'off');
|
||||
} else if ($(item).data('was-inherit')) {
|
||||
optionObject[$(item).attr('name')] = 'inherit';
|
||||
} else {
|
||||
optionObject[$(item).attr('name')] = $(item).prop('checked') ? 'on' : 'off';
|
||||
}
|
||||
});
|
||||
|
||||
globalForm.find('.selector_text_option_value_field').each(function (i, item) {
|
||||
//disabled items should be inherit or false
|
||||
if ($(item).prop('disabled')) {
|
||||
$(item).val((inheritPossible ? 'inherit' : false));
|
||||
}
|
||||
|
||||
optionObject[$(item).attr('name')] = $(item).val();
|
||||
});
|
||||
|
||||
var newOptionObject = $.extend(true, {}, optionObject);
|
||||
delete newOptionObject.general_inherit;
|
||||
|
||||
|
|
@ -91,9 +141,56 @@ var ThemeOptions = function () {
|
|||
// Utility Methods
|
||||
// -- small utilities i.g. for images or similar, or very specialized functions
|
||||
|
||||
// Color picker text fields are left empty when the value is inherited, so they show the translated placeholder instead of "inherit"
|
||||
var getOptionFieldValue = function (item) {
|
||||
if ($(item).hasClass('selector__color-picker') && $(item).val() === '' && inheritPossible) {
|
||||
return 'inherit';
|
||||
}
|
||||
return $(item).val();
|
||||
};
|
||||
|
||||
var applyColorPickerValue = function (item) {
|
||||
if ($(item).hasClass('selector__color-picker')) {
|
||||
console.ls.log($(item).data('inheritvalue'), $(item).val(), item);
|
||||
if ($(item).val() === 'inherit') {
|
||||
$(item).val('');
|
||||
$(item).closest('.input-group').find('.selector__colorpicker-inherit-value').val($(item).data('inheritvalue')).trigger('change');
|
||||
} else {
|
||||
$(item).closest('.input-group').find('.selector__colorpicker-inherit-value').val($(item).val()).trigger('change');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//Special code for numerical
|
||||
var parseNumeric = function (item) {
|
||||
if ($(item).hasClass('selector-numerical-input')) {
|
||||
if (!(/^((\d+)|(inherit))$/.test($(item).val()))) {
|
||||
$(item).val((inheritPossible ? 'inherit' : 1000));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// display inherited options as tooltips
|
||||
var showInheritedValue = function () {
|
||||
$.each($('#simple_edit_add_css > option'), function (i, option) {
|
||||
$.each(optionCssFiles.add, function (i, item) {
|
||||
if (option.value === item && $('#simple_edit_add_css option:first').val() === 'inherit') {
|
||||
$('#simple_edit_add_css option:first').text($('#simple_edit_add_css option:first').text() + ' ' + option.text + ']');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
globalForm.find('.selector-numerical-input').each(function (i, item) {
|
||||
var element = $(item);
|
||||
//element.attr('title', element.attr('title')+optionObjectInheritedValues[$(item).attr('name')]);
|
||||
element.tooltip();
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
//Parses the option value for an item
|
||||
var parseOptionValue = function (item, fallbackValue) {
|
||||
fallbackValue = fallbackValue || false;
|
||||
if (fallbackValue == undefined) fallbackValue = false;
|
||||
// If general inherit, then the value of the dropdown is inherit, else it's the value defined in advanced options
|
||||
var itemValue = generalInherit() ? 'inherit' : optionObject[$(item).attr('name')];
|
||||
|
||||
|
|
@ -108,7 +205,7 @@ var ThemeOptions = function () {
|
|||
//Set value and propagate to bootstrapSwitch
|
||||
var setAndPropageteToSwitch = function (item) {
|
||||
$(item).prop('checked', true).trigger('change');
|
||||
$(item).closest('label').addClass('active');
|
||||
//$(item).closest('label').addClass('active');
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -118,10 +215,30 @@ var ThemeOptions = function () {
|
|||
|
||||
// Update values in the form to the template options
|
||||
// selector_option_value_field are the select dropdown (like variations and fonts)
|
||||
// TODO: This seems to be designed for select fields only, but it is also used for other input types. Should be reviewed.
|
||||
var prepareSelectField = function () {
|
||||
globalForm.find('.selector_option_value_field').each(function (i, item) {
|
||||
var itemValue = parseOptionValue(item);
|
||||
$(item).val(itemValue);
|
||||
applyColorPickerValue(item);
|
||||
});
|
||||
};
|
||||
|
||||
// THEME ADDITION: checkbox options (type "checkbox", class
|
||||
// .selector_option_checkbox_field): checked = "on", unchecked = "off".
|
||||
// When the saved value is "inherit" (survey-level inherit), the box shows
|
||||
// the inherited state (data-inheritvalue) and is marked data was-inherit,
|
||||
// so updateFieldSettings() keeps writing "inherit" until the user actually
|
||||
// toggles the box (the change handler in hotSwapFields clears the mark).
|
||||
var prepareCheckboxField = function () {
|
||||
globalForm.find('.selector_option_checkbox_field').each(function (i, item) {
|
||||
var itemValue = parseOptionValue(item, 'off');
|
||||
var effective = (itemValue === 'inherit') ? $(item).data('inheritvalue') : itemValue;
|
||||
$(item).prop('checked', String(effective) === 'on');
|
||||
if (itemValue === 'inherit') {
|
||||
$(item).data('was-inherit', '1');
|
||||
$(item).attr('title', 'Inherited value: ' + $(item).data('inheritvalue'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -139,7 +256,11 @@ var ThemeOptions = function () {
|
|||
};
|
||||
|
||||
var prepareFontField = function () {
|
||||
optionObject.font = optionObject.font || (inheritPossible ? 'inherit' : 'roboto');
|
||||
var currentPackageObject = 'inherit';
|
||||
// THEME CHANGE: fallback is the bundled default font of this theme
|
||||
// ('noto_sans', self-hosted), never a core package font like roboto/ibm-sans
|
||||
// (privacy: no external font hosts may ever be requested).
|
||||
optionObject.font = optionObject.font || (inheritPossible ? 'inherit' : 'noto_sans');
|
||||
|
||||
if (optionObject.font !== 'inherit') {
|
||||
$('#simple_edit_options_font').val(optionObject.font);
|
||||
|
|
@ -147,30 +268,111 @@ var ThemeOptions = function () {
|
|||
updateFieldSettings();
|
||||
};
|
||||
|
||||
var prepareFruityThemeField = function () {
|
||||
var currentThemeObject = 'inherit';
|
||||
if ($('#TemplateConfiguration_files_css').val() !== 'inherit' && $('body').hasClass('fruity')) {
|
||||
currentThemeObject = {
|
||||
"add": ['css/animate.css', 'css/ajaxify.css', 'css/variations/sea_green.css', 'css/theme.css', 'custom.css']
|
||||
};
|
||||
|
||||
try {
|
||||
currentThemeObject = JSON.parse($('#TemplateConfiguration_files_css').val());
|
||||
} catch (e) {
|
||||
console.error('No valid monochrom theme field!');
|
||||
}
|
||||
|
||||
if (currentThemeObject.add) {
|
||||
$('#simple_edit_add_css').val(currentThemeObject.add.filter(function (item, i) {
|
||||
return /^css\/variations\/.*$/.test(item);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Update values of 'text' options in the form
|
||||
var prepareTextField = function () {
|
||||
globalForm.find('.selector_text_option_value_field').each(function (i, item) {
|
||||
var itemValue = parseOptionValue(item, "");
|
||||
$(item).val(itemValue);
|
||||
});
|
||||
};
|
||||
|
||||
// updates the disabled status of a child field
|
||||
// based on the parent element
|
||||
// NOTE:
|
||||
// for font and variations dropdowns, the childfield
|
||||
// class is added and the data-parent attr exists,
|
||||
// but no parent element exists in the markup
|
||||
// so if we actually have a parent element, enable/disable
|
||||
// based on that, otherwise we enable by default
|
||||
const updateChild = function(parentEl, childEl) {
|
||||
|
||||
let enabled = true;
|
||||
|
||||
if(parentEl.length) {
|
||||
const parentOn = $(parentEl).val() === 'on';
|
||||
const parentChecked = $(parentEl).prop('checked') === true;
|
||||
enabled = parentOn && parentChecked;
|
||||
}
|
||||
|
||||
$(childEl).prop('disabled', !enabled);
|
||||
};
|
||||
|
||||
// grab the parent for a given child field
|
||||
const getParent = function(childEl) {
|
||||
const parentName = $(childEl).data('parent');
|
||||
const parentEl = $(`input[name=${parentName}]`);
|
||||
return parentEl;
|
||||
};
|
||||
|
||||
// go through each child field, grab parent, and update disabled status
|
||||
const updateAllChildren = function() {
|
||||
$('.selector_radio_childfield').each(function (i, childEl) {
|
||||
const parentEl = getParent(childEl);
|
||||
updateChild(parentEl, childEl);
|
||||
});
|
||||
};
|
||||
|
||||
// THEME ADDITION: show/hide whole option fields based on a parent option's value.
|
||||
// A wrapper with class "option-visibility" and data-show-if-parent="<parentName>"
|
||||
// (rendered by options/options.twig for every option that has a parent="..." in
|
||||
// config.xml) is only visible when the checked radio input[name=<parentName>]
|
||||
// has value data-show-if-value (default "on"). This makes e.g. the logo file and
|
||||
// hide-on-small selects disappear when the corresponding logo is set to "No".
|
||||
const updateVisibilityByParent = function() {
|
||||
$('.option-visibility[data-show-if-parent]').each(function (i, wrapperEl) {
|
||||
const parentName = $(wrapperEl).data('show-if-parent');
|
||||
const showValue = $(wrapperEl).data('show-if-value') || 'on';
|
||||
const parentInputs = $('input[name="' + parentName + '"]');
|
||||
// no parent input in the markup (e.g. font's self-parent): always visible,
|
||||
// same fallback as updateChild() above
|
||||
if (parentInputs.length === 0) {
|
||||
$(wrapperEl).removeClass('d-none');
|
||||
return;
|
||||
}
|
||||
const checked = parentInputs.filter(':checked');
|
||||
const visible = checked.length > 0 && checked.val() === String(showValue);
|
||||
$(wrapperEl).toggleClass('d-none', !visible);
|
||||
});
|
||||
};
|
||||
|
||||
///////////////
|
||||
// HotSwap methods
|
||||
// -- These methods connect an input directly to the value in the optionsObject
|
||||
|
||||
// Disable dependent inputs when their parents are set to off, or inherit
|
||||
var hotSwapParentRadioButtons = function () {
|
||||
// hotswapping the select fields to the radiobuttons
|
||||
// If an option is set to off, the attached selectors are disabled
|
||||
$('.selector_radio_childfield').each(function (i, selectorItem) {
|
||||
$('input[name=' + $(selectorItem).data('parent') + ']').on('change', function () {
|
||||
const hotSwapParentRadioButtons = function () {
|
||||
|
||||
if ($(this).val() === 'on' && $(this).prop('checked') == true) {
|
||||
$(selectorItem).prop('disabled', false);
|
||||
} else {
|
||||
$(selectorItem).prop('disabled', true);
|
||||
}
|
||||
|
||||
// disabled this part to always be able to click on "Preview image" button
|
||||
/*
|
||||
if ($(selectorItem).hasClass('selector_image_selector')) {
|
||||
$('button[data-target="#' + $(selectorItem).attr('id') + '"]').prop('disabled', $(selectorItem).val() == 'inherit');
|
||||
}
|
||||
*/
|
||||
// for each child field, add a listener for the
|
||||
// parent's change and update the child's disabled
|
||||
// status accordingly
|
||||
// i = element index in list of matches, unused
|
||||
$('.selector_radio_childfield').each(function (i, childEl) {
|
||||
const parentEl = getParent(childEl);
|
||||
|
||||
parentEl.on('change', function () {
|
||||
updateChild(parentEl, childEl);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
@ -178,47 +380,196 @@ var ThemeOptions = function () {
|
|||
// hotswapping the fields
|
||||
var hotSwapFields = function () {
|
||||
|
||||
globalForm.find('.selector_option_value_field').on('change', function (evt) {
|
||||
globalForm.find('.selector_option_value_field, .selector_text_option_value_field').on('change', function (evt) {
|
||||
updateFieldSettings();
|
||||
parseNumeric(this);
|
||||
});
|
||||
|
||||
globalForm.find('.selector_option_radio_field').on('change', updateFieldSettings);
|
||||
globalForm.find('.selector_option_radio_field').on('change', function (evt) {
|
||||
updateFieldSettings();
|
||||
parseNumeric(this);
|
||||
});
|
||||
|
||||
// THEME ADDITION: checkbox change -> drop the was-inherit mark, re-serialize
|
||||
globalForm.find('.selector_option_checkbox_field').on('change', function (evt) {
|
||||
$(this).removeData('was-inherit');
|
||||
updateFieldSettings();
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
var hotswapGeneralInherit = function () {
|
||||
//hotswapping the general inherit
|
||||
$('#general_inherit_on').on('change', function (evt) {
|
||||
$('#TemplateConfiguration_files_css').val('inherit');
|
||||
$('#TemplateConfiguration_files_js').val('inherit');
|
||||
$('#TemplateConfiguration_files_print_css').val('inherit');
|
||||
$('#TemplateConfiguration_options').val('inherit');
|
||||
$('#TemplateConfiguration_cssframework_name').val('inherit');
|
||||
$('#TemplateConfiguration_cssframework_css').val('inherit');
|
||||
$('#TemplateConfiguration_cssframework_js').val('inherit');
|
||||
$('#TemplateConfiguration_packages_to_load').val('inherit');
|
||||
$('.action_hide_on_inherit_wrapper').removeClass('d-none');
|
||||
$('.action_hide_on_inherit').addClass('d-none');
|
||||
$('.tab_action_hide_on_inherit').addClass('ls-tab-disabled');
|
||||
|
||||
|
||||
});
|
||||
$('#general_inherit_off').on('change', function (evt) {
|
||||
$('.action_hide_on_inherit_wrapper').addClass('d-none');
|
||||
$('.action_hide_on_inherit').removeClass('d-none');
|
||||
$('.tab_action_hide_on_inherit').removeClass('ls-tab-disabled');
|
||||
|
||||
updateFieldSettings();
|
||||
});
|
||||
};
|
||||
|
||||
// THEME ADDITION: manage the font packages of ALL font selects, not just the
|
||||
// base "font" dropdown. Every per-element font override (type "fontselect",
|
||||
// class .selector_fontselect) can pick a different font, and each selected
|
||||
// font needs its package (font-<data-font-package>) in packages_to_load,
|
||||
// otherwise the survey page does not load that font's css. Values "inherit"
|
||||
// (survey-level inherit) and "base" (= base font, handled by the font select
|
||||
// itself) contribute no package of their own.
|
||||
// PRIVACY HARD RULE: only LOCAL packages may be added. The only allowed
|
||||
// font package is "websafe" (served from the server's own assets, pure
|
||||
// system-font stacks). Bundled fonts load via the theme's css/fonts.css and
|
||||
// need no package. Any other package (font-roboto, font-noto, ...) is skipped
|
||||
// with a warning, so a survey page can never request a font from Google or
|
||||
// any other external host.
|
||||
var ALLOWED_FONT_PACKAGES = ['websafe'];
|
||||
var hotswapFontField = function () {
|
||||
$('#simple_edit_options_font').on('change', function (evt) {
|
||||
var currentPackageObject = $('#TemplateConfiguration_packages_to_load').val() !== 'inherit'
|
||||
? JSON.parse($('#TemplateConfiguration_packages_to_load').val())
|
||||
: $(this).data('inheritvalue');
|
||||
|
||||
$('.selector_fontselect').on('change', function (evt) {
|
||||
// base font set to "inherit" => inherit the packages as a whole
|
||||
if ($('#simple_edit_options_font').val() === 'inherit') {
|
||||
|
||||
$('#TemplateConfiguration_packages_to_load').val('inherit');
|
||||
return;
|
||||
}
|
||||
var currentPackageObject = $('#TemplateConfiguration_packages_to_load').val() !== 'inherit' ?
|
||||
JSON.parse($('#TemplateConfiguration_packages_to_load').val()) :
|
||||
$(this).data('inheritvalue');
|
||||
|
||||
} else {
|
||||
var selectedFontPackage = $(this).find('option:selected');
|
||||
var packageName = selectedFontPackage.data('font-package');
|
||||
if (currentPackageObject === 'inherit' || !currentPackageObject) {
|
||||
currentPackageObject = {add: []};
|
||||
}
|
||||
|
||||
// drop all font-* packages, then re-add the ones of all current font selects
|
||||
var filteredAdd = (currentPackageObject.add || []).filter(function (value, index) {
|
||||
return !(/^font-.*$/.test(String(value)));
|
||||
});
|
||||
$('.selector_fontselect').each(function (i, item) {
|
||||
var val = $(item).val();
|
||||
if (!val || val === 'inherit' || val === 'base') {
|
||||
return;
|
||||
}
|
||||
var packageName = $(item).find('option:selected').data('font-package');
|
||||
if (!packageName) {
|
||||
return;
|
||||
}
|
||||
// privacy: only allow local packages (see ALLOWED_FONT_PACKAGES)
|
||||
if (ALLOWED_FONT_PACKAGES.indexOf(String(packageName)) === -1) {
|
||||
if (window.console && console.warn) {
|
||||
console.warn('Theme privacy rule: font package "font-' + packageName + '" is not allowed (external hosts are never requested); skipped.');
|
||||
}
|
||||
return;
|
||||
}
|
||||
var formatedPackageName = 'font-' + packageName;
|
||||
if (filteredAdd.indexOf(formatedPackageName) === -1) {
|
||||
filteredAdd.push(formatedPackageName);
|
||||
}
|
||||
});
|
||||
currentPackageObject.add = filteredAdd;
|
||||
$('#TemplateConfiguration_packages_to_load').val(JSON.stringify(currentPackageObject));
|
||||
});
|
||||
};
|
||||
|
||||
var filteredAdd = currentPackageObject.add.filter(function (value, index) {
|
||||
return !(/^font-.*$/.test(String(value)));
|
||||
//hotswapping the colorpickers and adding the reset functionality
|
||||
var hotswapColorPicker = function () {
|
||||
|
||||
globalForm.find('.selector__colorpicker-inherit-value')
|
||||
.on('change', function (e) {
|
||||
$(this).closest('.input-group').find('.selector_option_value_field').val($(this).val()).trigger('change');
|
||||
});
|
||||
|
||||
globalForm.find('.selector__reset-colorfield-to-inherit').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
var colorField = $(this).closest('.input-group').find('.selector__color-picker');
|
||||
console.ls.log(colorField, colorField.data('inheritvalue'));
|
||||
$(this).closest('.input-group').find('.selector__colorpicker-inherit-value').val(colorField.data('inheritvalue')).trigger('change');
|
||||
colorField.attr('type', 'text').val('');
|
||||
optionObject[colorField.attr('name')] = 'inherit';
|
||||
updateFieldSettings();
|
||||
});
|
||||
};
|
||||
|
||||
var removeVariationsFromField = function (fieldSelector) {
|
||||
if ($(fieldSelector).val() === 'inherit') {
|
||||
fieldSelector = '#optionCssFiles';
|
||||
}
|
||||
let currentValue = {};
|
||||
try {
|
||||
currentValue = JSON.parse($(fieldSelector).val());
|
||||
} catch (error) {
|
||||
currentValue = {};
|
||||
}
|
||||
let empty = true;
|
||||
['add', 'replace', 'remove'].forEach(function (action) {
|
||||
if (currentValue.hasOwnProperty(action)) {
|
||||
currentValue[action] = currentValue[action].filter(function (item) {
|
||||
return !(/^css\/variations\/.*$/.test(item));
|
||||
});
|
||||
filteredAdd.push(formatedPackageName);
|
||||
currentPackageObject.add = filteredAdd;
|
||||
$('#TemplateConfiguration_packages_to_load').val(JSON.stringify(currentPackageObject));
|
||||
if (currentValue[action].length) {
|
||||
empty = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!empty) {
|
||||
$(fieldSelector).val(JSON.stringify(currentValue));
|
||||
} else {
|
||||
$(fieldSelector).val(inheritPossible ? 'inherit' : JSON.stringify({}));
|
||||
}
|
||||
};
|
||||
|
||||
// update the files_css field to be saved in the database
|
||||
var addVariationToField = function (selectedVariation, filesCssId, selectedMode) {
|
||||
let filesCss = [];
|
||||
try {
|
||||
filesCss = JSON.parse($(filesCssId).val());
|
||||
} catch (error) {
|
||||
}
|
||||
if (!filesCss.hasOwnProperty(selectedMode)) {
|
||||
filesCss[selectedMode] = [];
|
||||
}
|
||||
if (selectedMode === 'replace') {
|
||||
filesCss[selectedMode].push(selectedVariation);
|
||||
} else {
|
||||
filesCss[selectedMode].unshift(selectedVariation);
|
||||
}
|
||||
$(filesCssId).val(JSON.stringify(filesCss));
|
||||
};
|
||||
|
||||
var hotswapTheme = function () {
|
||||
$('#simple_edit_options_cssframework').on('change', function (evt) {
|
||||
let newThemeDataValue = $('option:selected', this).attr('data-value') || false;
|
||||
let selectedVariation = newThemeDataValue || $('#simple_edit_options_cssframework').val();
|
||||
let selectedMode = $('#simple_edit_options_cssframework').find('option[value=\'' + selectedVariation + '\']').attr('data-mode') || 'add';
|
||||
let filesCssId = '#TemplateConfiguration_files_css';
|
||||
let filesCss = {};
|
||||
try {
|
||||
filesCss = JSON.parse($(filesCssId).val());
|
||||
} catch (e) {
|
||||
filesCss = $(filesCssId).val();
|
||||
}
|
||||
// load the parent data if set to inherit, so no data gets lost
|
||||
if (filesCss.length === 0 || filesCss === 'inherit') {
|
||||
$(filesCssId).val($('#optionCssFiles').val());
|
||||
}
|
||||
removeVariationsFromField(filesCssId);
|
||||
removeVariationsFromField('#TemplateConfiguration_cssframework_css');
|
||||
if (selectedVariation !== 'inherit') {
|
||||
addVariationToField(selectedVariation, filesCssId, selectedMode);
|
||||
} else {
|
||||
$(filesCssId).val('inherit');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
@ -229,22 +580,18 @@ var ThemeOptions = function () {
|
|||
var onSaveButtonClickAction = function (evt) {
|
||||
evt.preventDefault();
|
||||
|
||||
if (generalInherit()) {
|
||||
if ($('#general_inherit_on').prop('checked')) {
|
||||
$('#TemplateConfiguration_options').val('inherit');
|
||||
$('#template-options-form').trigger('submit'); // submit the form
|
||||
} else {
|
||||
updateFieldSettings();
|
||||
//Create a copy of the inherent optionObject
|
||||
var newOptionObject = $.extend(true, {}, optionObject);
|
||||
newOptionObject.generalInherit = null;
|
||||
|
||||
// Now write the newly created object to the correspondent field as a json string
|
||||
//now write the newly created object to the correspondent field as a json string
|
||||
$('#TemplateConfiguration_options').val(JSON.stringify(newOptionObject));
|
||||
|
||||
// And submit the form
|
||||
// Beware, we are triggering 'submit' directly, which doesn't trigger HTML5 validations.
|
||||
// No HTML5 validations needed here, so all good.
|
||||
// If not we would need to add a hidden submit button and trigger a 'click' on it. (see fruity theme).
|
||||
// Like these: $('#template-options-form').find('button[type=submit]').trigger('click');
|
||||
//and submit the form
|
||||
$('#template-options-form').trigger('submit');
|
||||
}
|
||||
};
|
||||
|
|
@ -254,13 +601,54 @@ var ThemeOptions = function () {
|
|||
// Instance methods
|
||||
var bind = function () {
|
||||
//if the save button is clicked write everything into the template option field and send the form
|
||||
$('.action_update_options_string_button, #theme-options--submit').on('click', onSaveButtonClickAction);
|
||||
$('#theme-options--submit').on('click', onSaveButtonClickAction);
|
||||
|
||||
//Bind the hotwaps
|
||||
hotSwapParentRadioButtons();
|
||||
hotSwapFields();
|
||||
hotswapGeneralInherit();
|
||||
hotswapColorPicker();
|
||||
hotswapFontField();
|
||||
hotswapTheme();
|
||||
|
||||
// THEME ADDITION: re-evaluate conditional visibility whenever a radio changes
|
||||
globalForm.find('.selector_option_radio_field').on('change', updateVisibilityByParent);
|
||||
};
|
||||
|
||||
// THEME ADDITION: order the font dropdowns' optgroups as:
|
||||
// Custom (this theme) > Bundled open source fonts > User browser > Local server - core/user (LAST).
|
||||
// Core package optgroups are recognized structurally (their options carry
|
||||
// data-font-package equal to their own value; theme/user fonts use "websafe"),
|
||||
// the rest by label keyword, so translated labels still work.
|
||||
var reorderFontDropdowns = function () {
|
||||
var rank = function (label) {
|
||||
var l = String(label || '').toLowerCase();
|
||||
if (l.indexOf('custom') !== -1) { return 0; }
|
||||
if (l.indexOf('bundled') !== -1) { return 1; }
|
||||
if (l.indexOf('user') !== -1) { return 2; }
|
||||
return 3;
|
||||
};
|
||||
var isServerPackageGroup = function ($og) {
|
||||
var $first = $og.children('option').first();
|
||||
return $first.length > 0 && $first.attr('data-font-package') === $first.attr('value');
|
||||
};
|
||||
globalForm.find('.selector_fontselect').each(function () {
|
||||
var $sel = $(this);
|
||||
// THEME ADDITION: drop empty optgroups (e.g. "Custom (this theme)" when
|
||||
// the theme ships no own font) — an empty category is not shown.
|
||||
$sel.children('optgroup').each(function () {
|
||||
if ($(this).children('option').length === 0) { $(this).remove(); }
|
||||
});
|
||||
var groups = $sel.children('optgroup').get();
|
||||
groups.sort(function (a, b) {
|
||||
var aSrv = isServerPackageGroup($(a));
|
||||
var bSrv = isServerPackageGroup($(b));
|
||||
if (aSrv !== bSrv) { return aSrv ? 1 : -1; } // server packages last
|
||||
if (aSrv && bSrv) { return 0; } // keep core before user (original order)
|
||||
return rank($(a).attr('label')) - rank($(b).attr('label'));
|
||||
});
|
||||
$.each(groups, function (i, g) { $sel.append(g); });
|
||||
});
|
||||
};
|
||||
|
||||
var run = function () {
|
||||
|
|
@ -269,34 +657,43 @@ var ThemeOptions = function () {
|
|||
startupGeneralInherit();
|
||||
|
||||
prepareSelectField();
|
||||
prepareTextField();
|
||||
parseParentSwitchFields();
|
||||
prepareCheckboxField();
|
||||
prepareFontField();
|
||||
prepareFruityThemeField();
|
||||
showInheritedValue();
|
||||
|
||||
// THEME ADDITION: font dropdown optgroup order (see above)
|
||||
reorderFontDropdowns();
|
||||
|
||||
bind();
|
||||
|
||||
// set initial disabled status of child fields
|
||||
updateAllChildren();
|
||||
|
||||
// THEME ADDITION: set initial visibility of conditional fields
|
||||
updateVisibilityByParent();
|
||||
};
|
||||
|
||||
return run;
|
||||
|
||||
};
|
||||
|
||||
var prepare = function () {
|
||||
$(function () {
|
||||
var prepare = function () {
|
||||
|
||||
var deferred = $.Deferred();
|
||||
var deferred = $.Deferred();
|
||||
|
||||
//activate the bootstrap switch for checkboxes
|
||||
$('.action_activate_bootstrapswitch').bootstrapSwitch();
|
||||
var themeOptionStarter = new ThemeOptions();
|
||||
themeOptionStarter();
|
||||
|
||||
var themeOptionStarter = new ThemeOptions();
|
||||
themeOptionStarter();
|
||||
setTimeout(function () {
|
||||
deferred.resolve();
|
||||
}, 650);
|
||||
return deferred.promise();
|
||||
};
|
||||
|
||||
setTimeout(function () {
|
||||
deferred.resolve();
|
||||
}, 650);
|
||||
return deferred.promise();
|
||||
};
|
||||
|
||||
|
||||
$(document).off('pjax:scriptcomplete.templateOptions').on('ready pjax:scriptcomplete.templateOptions', function () {
|
||||
$('.simple-template-edit-loading').css('display', 'block');
|
||||
prepare().then(function (runsesolve) {
|
||||
$('.simple-template-edit-loading').css('display', 'none');
|
||||
|
|
@ -308,21 +705,165 @@ $(document).off('pjax:scriptcomplete.templateOptions').on('ready pjax:scriptcomp
|
|||
var imgTitle = $($(this).data('bs-target')).val();
|
||||
imgTitle = imgTitle.split('/').pop();
|
||||
$('#lightbox-modal').find('.selector__title').text(imgTitle);
|
||||
$('#lightbox-modal').find('.selector__image').attr({'src': imgSrc, 'alt': imgTitle});
|
||||
$('#lightbox-modal').find('.selector__image').attr({
|
||||
'src': imgSrc,
|
||||
'alt': imgTitle
|
||||
});
|
||||
$('#lightbox-modal').modal('show');
|
||||
});
|
||||
|
||||
var uploadImageBind = new bindUpload({
|
||||
// Icon values are hexadecimal code points, show them as text so other values can't add markup
|
||||
var iconCharacter = function (hexCode) {
|
||||
hexCode = String(hexCode);
|
||||
var codePoint = parseInt(hexCode, 16);
|
||||
return /^[0-9a-f]{1,6}$/i.test(hexCode) && codePoint <= 0x10FFFF ? String.fromCodePoint(codePoint) : '';
|
||||
};
|
||||
|
||||
$('.simple_edit_options_checkicon').on('change', function () {
|
||||
var preview = $(this).siblings('.selector__checkicon-preview').find('i');
|
||||
var hexCode = $(this).val() == 'inherit' ? preview.attr('data-inheritvalue') : $(this).val();
|
||||
preview.text(iconCharacter(hexCode));
|
||||
});
|
||||
});
|
||||
$(function () {
|
||||
let selectedTabHash = window.location.hash;
|
||||
let selectedTabElement = document.querySelector('[data-bs-target="' + selectedTabHash + '"]');
|
||||
if (selectedTabElement !== null) {
|
||||
let tab = new bootstrap.Tab(selectedTabElement);
|
||||
tab.show();
|
||||
}
|
||||
|
||||
var BindUpload = function (options) {
|
||||
var $activeForm = $(options.form);
|
||||
var $activeInput = $(options.input);
|
||||
var $progressBar = $(options.progress);
|
||||
|
||||
var onSuccess = options.onSuccess || function () {
|
||||
};
|
||||
var onBeforeSend = options.onBeforeSend || function () {
|
||||
};
|
||||
|
||||
var progressHandling = function (event) {
|
||||
var percent = 0;
|
||||
var position = event.loaded || event.position;
|
||||
var total = event.total;
|
||||
if (event.lengthComputable) {
|
||||
percent = Math.ceil(position / total * 100);
|
||||
}
|
||||
// update progressbars classes so it fits your code
|
||||
$progressBar.css('width', String(percent) + '%');
|
||||
$progressBar.find('span.visually-hidden').text(percent + '%');
|
||||
};
|
||||
|
||||
$activeInput.on('change', function (e) {
|
||||
e.preventDefault();
|
||||
var formData = new FormData($activeForm[0]);
|
||||
console.log(JSON.stringify(formData));
|
||||
// add assoc key values, this will be posts values
|
||||
formData.append('file', $activeInput.prop('files')[0]);
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: $activeForm.attr('action'),
|
||||
xhr: function () {
|
||||
var myXhr = $.ajaxSettings.xhr();
|
||||
if (myXhr.upload) {
|
||||
myXhr.upload.addEventListener('progress', progressHandling, false);
|
||||
}
|
||||
return myXhr;
|
||||
},
|
||||
beforeSend: onBeforeSend,
|
||||
success: function (data) {
|
||||
console.log(data);
|
||||
if (data.success === true) {
|
||||
LS.LsGlobalNotifier.createAlert(data.message, 'success', {showCloseButton: true});
|
||||
$progressBar.css('width', '0%');
|
||||
$progressBar.find('span.visually-hidden').text('0%');
|
||||
onSuccess(options.input, data);
|
||||
} else {
|
||||
LS.LsGlobalNotifier.createAlert(data.message, 'danger', {showCloseButton: true});
|
||||
$progressBar.css('width', '0%');
|
||||
$progressBar.find('span.visually-hidden').text('0%');
|
||||
}
|
||||
},
|
||||
error: function (error) {
|
||||
$progressBar.css('width', '0%');
|
||||
$progressBar.find('span.visually-hidden').text('0%');
|
||||
console.log(error);
|
||||
},
|
||||
async: true,
|
||||
data: formData,
|
||||
cache: false,
|
||||
contentType: false,
|
||||
processData: false,
|
||||
timeout: 60000
|
||||
});
|
||||
});
|
||||
return this;
|
||||
};
|
||||
new BindUpload({
|
||||
form: '#upload_frontend',
|
||||
input: '#upload_image',
|
||||
progress: '#upload_progress',
|
||||
onSuccess: function (inputId, data) {
|
||||
addUploadedImageToSelectors(data && data.file);
|
||||
}
|
||||
});
|
||||
new BindUpload({
|
||||
form: '#upload_frontend',
|
||||
input: '#upload_image_frontend',
|
||||
progress: '#upload_progress_frontend',
|
||||
onBeforeSend: function () {
|
||||
$('.simple-template-edit-loading').css('display', 'block');
|
||||
},
|
||||
onSuccess: function () {
|
||||
setTimeout(function () {
|
||||
$(document).trigger('pjax:load', {url: window.location.href});
|
||||
}, 2500);
|
||||
onSuccess: function (inputId, data) {
|
||||
$('.simple-template-edit-loading').css('display', 'none');
|
||||
addUploadedImageToSelectors(data && data.file);
|
||||
}
|
||||
});
|
||||
|
||||
// Adds a freshly uploaded image to the theme options image selectors so it becomes
|
||||
// selectable immediately, without a full page reload. Falls back to a reload if the
|
||||
// server didn't return the file info.
|
||||
function addUploadedImageToSelectors(file) {
|
||||
if (!file || !file.filepath) {
|
||||
let url = new URL(window.location.href);
|
||||
let activeTab = document.querySelector('.CoreThemeOptions--settingsTab.active');
|
||||
url.hash = activeTab !== null ? activeTab.id : '';
|
||||
$(document).trigger('pjax:load', { url: url.href });
|
||||
return;
|
||||
}
|
||||
// Group options by their virtual path prefix (e.g. "image::generalfiles::").
|
||||
let prefixMatch = String(file.filepath).match(/^(image::\w+::)/);
|
||||
let prefix = prefixMatch ? prefixMatch[1] : null;
|
||||
$('.selector_image_selector').each(function () {
|
||||
let select = this;
|
||||
// Skip if the image is already listed (e.g. an existing file was overwritten).
|
||||
let exists = Array.prototype.some.call(select.options, function (opt) {
|
||||
return opt.value === file.filepath;
|
||||
});
|
||||
if (exists) {
|
||||
return;
|
||||
}
|
||||
let option = new Option(file.filename, file.filepath);
|
||||
option.setAttribute('data-lightbox-src', file.preview || '');
|
||||
// Insert after the last option of the same group, otherwise append.
|
||||
let insertAfter = null;
|
||||
if (prefix) {
|
||||
Array.prototype.forEach.call(select.options, function (opt) {
|
||||
if (opt.value.indexOf(prefix) === 0) {
|
||||
insertAfter = opt;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (insertAfter && insertAfter.nextSibling) {
|
||||
insertAfter.parentNode.insertBefore(option, insertAfter.nextSibling);
|
||||
} else if (insertAfter) {
|
||||
insertAfter.parentNode.appendChild(option);
|
||||
} else {
|
||||
select.appendChild(option);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue