From 0b8fddccda628c96f4ce5f4c3c310acbb728736b Mon Sep 17 00:00:00 2001 From: markusfluer Date: Mon, 15 Jan 2018 13:46:26 +0100 Subject: [PATCH] Fixed issue #13151: Display issue? - Survey theme editor Dev: fixed a few minor errors in fruity options js --- themes/survey/fruity/options/options.js | 81 ++++++++++++++--------- themes/survey/fruity/options/options.twig | 17 +++-- themes/survey/vanilla/config.xml | 2 +- 3 files changed, 60 insertions(+), 40 deletions(-) diff --git a/themes/survey/fruity/options/options.js b/themes/survey/fruity/options/options.js index ff2f45d3233..675c73c2f18 100644 --- a/themes/survey/fruity/options/options.js +++ b/themes/survey/fruity/options/options.js @@ -18,6 +18,13 @@ var prepare = function(){ $('#TemplateConfiguration_options').val(JSON.stringify(optionObject)); }); }; + var writeToOptionsField = function(newOptionObject){ + if($('#general_inherit_on').prop('checked')){ + $('#TemplateConfiguration_options').val('inherit'); + } else { + $('#TemplateConfiguration_options').val(JSON.stringify(newOptionObject)); + } + } //Un-/Hide everything on general inherit switch if(generalInherit()){ @@ -132,7 +139,7 @@ var prepare = function(){ newOptionObject[$(item).attr('name')] = $(item).val(); }); //now write the newly created object to the correspondent field as a json string - $('#TemplateConfiguration_options').val(JSON.stringify(newOptionObject)); + writeToOptionsField(newOptionObject); //and submit the form $('#template-options-form').find('button[type=submit]').trigger('click'); } @@ -142,7 +149,6 @@ var prepare = function(){ $('#general_inherit_on').on('change', function(evt){ $('#TemplateConfiguration_options').val('inherit'); $('.action_hide_on_inherit').addClass('hidden'); - updateFieldSettings(); }); $('#general_inherit_off').on('change', function(evt){ $('.action_hide_on_inherit').removeClass('hidden'); @@ -173,14 +179,14 @@ var prepare = function(){ optionObject[$(this).attr('name')] = $(this).prop('checked') ? 'on' : 'off'; } //write the option object to json string - $('#TemplateConfiguration_options').val(JSON.stringify(optionObject)); + writeToOptionsField(optionObject); }); //hotswapping the radio fields $('.action_update_options_string_form').find('.selector_option_radio_field').on('change', function(evt){ $(this).prop('checked',true); optionObject[$(this).attr('name')] = $(this).val(); - $('#TemplateConfiguration_options').val(JSON.stringify(optionObject)); + writeToOptionsField(optionObject); }); //hotswapping the colorpickers and adding the reset functionality @@ -197,9 +203,45 @@ var prepare = function(){ $(this).closest('.input-group').find('.selector__show-inherit-value').css('background-color', colorField.data('inheritvalue')); colorField.attr('type','text').val('inherit'); optionObject[colorField.attr('name')] = 'inherit'; - $('#TemplateConfiguration_options').val(JSON.stringify(optionObject)); + writeToOptionsField(optionObject); }); + // Fruity Fonts + if($('#simple_edit_font').length>0){ + optionObject.font = optionObject.font || 'inherit'; + + var currentPackageLoad = JSON.parse($('#TemplateConfiguration_packages_to_load').val()), + currentFontPackage = currentPackageLoad.add.reduce(function(coll, it){ + return coll = /^font-/.test(it) ? it : coll; + },'font-inherit'), + currentFont = optionObject.font; + + + if( currentFont !== 'inherit' ){ + $('#simple_edit_font').val(currentFont); + } + $('#simple_edit_font').on('change', function(evt){ + if($(this).val() === 'inherit'){ + currentPackageLoad.add = currentPackageLoad.add.filter(function(val,idx){ + return !(/^font-/.test(val)); + }); + optionObject.font = 'inherit'; + writeToOptionsField(optionObject); + } else { + currentPackageLoad.add = currentPackageLoad.add.filter(function(val,idx){ + return !(/^font-/.test(val)); + }); + var selectedFontPackage = $(this).find('option:selected').data('font-package'); + var formatedPackageName = "font-"+selectedFontPackage; + currentPackageLoad.add.push(formatedPackageName); + optionObject.font = $(this).val(); + writeToOptionsField(optionObject); + } + + $('#TemplateConfiguration_packages_to_load').val(JSON.stringify(currentPackageLoad)); + }); + console.ls.groupEnd('FontChangeTestsEnd'); + } // Fruity Theming if($('#simple_edit_add_css').length>0){ @@ -227,35 +269,8 @@ var prepare = function(){ } }) } - - - // Fruity Fonts - if($('#simple_edit_font').length>0){ - var currentFontObject = 'inherit'; - optionObject.font = optionObject.font || (inheritPossible ? 'inherit' : 'roboto'); - - if( optionObject.font !== 'inherit' ){ - $('#simple_edit_font').val(optionObject.font); - } - - $('#simple_edit_font').on('change', function(evt){ - if($('#simple_edit_font').val() === 'inherit'){ - $('#TemplateConfiguration_packages_to_load').val('inherit'); - } else { - - currentFontObject = {}; - var selectedFontPackage = $(this).find('option:selected'); - var packageName = selectedFontPackage.data('font-package'); - var formatedPackageName = "font-"+packageName; - - - currentFontObject.add = ["pjax", formatedPackageName ]; - - } - $('#TemplateConfiguration_packages_to_load').val(JSON.stringify(currentFontObject)); - }) - } } + setTimeout(function(){deferred.resolve()},650); return deferred.promise(); diff --git a/themes/survey/fruity/options/options.twig b/themes/survey/fruity/options/options.twig index af409cbc7a6..0473d899b6c 100644 --- a/themes/survey/fruity/options/options.twig +++ b/themes/survey/fruity/options/options.twig @@ -845,13 +845,11 @@ - -
+

- -
-
+
+
{{ "Fruity fonts" | t }}
@@ -866,7 +864,14 @@
-
+
+ +
+
+
+ +
+
{{ "Fruity variations" | t }}
diff --git a/themes/survey/vanilla/config.xml b/themes/survey/vanilla/config.xml index 5ac7faf2edf..7ad0da19447 100755 --- a/themes/survey/vanilla/config.xml +++ b/themes/survey/vanilla/config.xml @@ -75,8 +75,8 @@ pjax - font-noto moment + font-noto