Added support for 'rem'
authorMarcel Werk <burntime@woltlab.com>
Sun, 11 Dec 2016 10:14:45 +0000 (11:14 +0100)
committerMarcel Werk <burntime@woltlab.com>
Sun, 11 Dec 2016 10:14:45 +0000 (11:14 +0100)
wcfsetup/install/files/acp/templates/styleAdd.tpl
wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php

index 76e747fa5b014d65020e6dedb240ed2f9d00d307..0cccdddc53d7df2efdf0f81e942c4263df99c8ac 100644 (file)
@@ -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');
        });
 </script>
                                                <input type="number" id="wcfFontSizeDefault" name="wcfFontSizeDefault" value="{@$variables[wcfFontSizeDefault]}" class="tiny">
                                                <select name="wcfFontSizeDefault_unit" class="jsUnitSelect">
                                                        {foreach from=$availableUnits item=unit}
-                                                               <option value="{@$unit}"{if $variables[wcfFontSizeDefault_unit] == $unit} selected{/if}>{@$unit}</option>
+                                                               {if $unit == 'px' || $unit == 'pt'}
+                                                                       <option value="{@$unit}"{if $variables[wcfFontSizeDefault_unit] == $unit} selected{/if}>{@$unit}</option>
+                                                               {/if}
                                                        {/foreach}
                                                </select>
                                        </dd>
index 969cc9a4f3a11d1662a7d852e94c4a2740d192a8..eaacd517fff246a931b522bcb7b5235cbf04079c 100644 (file)
@@ -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];
                        }
                }