$('.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>
* list of available units
* @var string[]
*/
- public $availableUnits = ['px', 'em', '%', 'pt'];
+ public $availableUnits = ['px', 'pt', 'rem', 'em', '%'];
/**
* @var array
// 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];
}
}