From 0347920cb81607f506e207653caedb696435b1f3 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Sun, 11 Dec 2016 11:14:45 +0100 Subject: [PATCH] Added support for 'rem' --- .../install/files/acp/templates/styleAdd.tpl | 6 ++++-- .../files/lib/acp/form/StyleAddForm.class.php | 17 ++++------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/wcfsetup/install/files/acp/templates/styleAdd.tpl b/wcfsetup/install/files/acp/templates/styleAdd.tpl index 76e747fa5b..0cccdddc53 100644 --- a/wcfsetup/install/files/acp/templates/styleAdd.tpl +++ b/wcfsetup/install/files/acp/templates/styleAdd.tpl @@ -42,7 +42,7 @@ $('.jsUnitSelect').change(function(event) { var $target = $(event.currentTarget); - $target.prev().attr('step', ($target.val() == 'em' ? '0.01' : '1')); + $target.prev().attr('step', (($target.val() == 'em' || $target.val() == 'rem') ? '0.01' : '1')); }).trigger('change'); }); @@ -396,7 +396,9 @@ diff --git a/wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php b/wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php index 969cc9a4f3..eaacd517ff 100644 --- a/wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php @@ -73,7 +73,7 @@ class StyleAddForm extends AbstractForm { * list of available units * @var string[] */ - public $availableUnits = ['px', 'em', '%', 'pt']; + public $availableUnits = ['px', 'pt', 'rem', 'em', '%']; /** * @var array @@ -396,18 +396,9 @@ class StyleAddForm extends AbstractForm { // parse global (unit) variables foreach ($this->globals as $variableName) { - $unit = ''; - $value = $this->variables[$variableName]; - $i = strlen($value) - 1; - while ($i >= 0) { - $unit = $value[$i] . $unit; - if (in_array($unit, $this->availableUnits)) { - $this->variables[$variableName] = str_replace($unit, '', $value); - $this->variables[$variableName.'_unit'] = $unit; - break; - } - - $i--; + if (preg_match('/(.*?)(' . implode('|', $this->availableUnits) . ')$/', $this->variables[$variableName], $match)) { + $this->variables[$variableName] = $match[1]; + $this->variables[$variableName.'_unit'] = $match[2]; } } -- 2.20.1