|
8 | 8 | * License: GNU/GPLv2 |
9 | 9 | * @see LICENSE.txt |
10 | 10 | * |
11 | | - * This file: Front-end handler (last modified: 2022.10.25). |
| 11 | + * This file: Front-end handler (last modified: 2022.10.28). |
12 | 12 | */ |
13 | 13 |
|
14 | 14 | namespace phpMussel\FrontEnd; |
@@ -1132,33 +1132,9 @@ public function view(string $Page = ''): void |
1132 | 1132 | } |
1133 | 1133 | } |
1134 | 1134 | if (isset($DirValue['preview'])) { |
1135 | | - $ThisDir['Preview'] = ($DirValue['preview'] === 'allow_other') ? '' : sprintf( |
1136 | | - $DirValue['preview_default_fill'] ?? ' = <span id="%s_preview"></span>', |
1137 | | - $ThisDir['DirLangKey'] |
1138 | | - ); |
| 1135 | + $ThisDir['Preview'] = ($DirValue['preview'] === 'allow_other') ? '' : sprintf(' = <span id="%s_preview"></span>', $ThisDir['DirLangKey']); |
1139 | 1136 | $ThisDir['Trigger'] = ' onchange="javascript:' . $ThisDir['DirLangKey'] . '_function();" onkeyup="javascript:' . $ThisDir['DirLangKey'] . '_function();"'; |
1140 | | - if ($DirValue['preview'] === 'kb') { |
1141 | | - $ThisDir['Preview'] .= sprintf( |
1142 | | - '<script type="text/javascript">function %1$s_function(){var e=%7$s?%7$s(' . |
1143 | | - '\'%1$s_field\').value:%8$s&&!%7$s?%8$s.%1$s_field.value:\'\',z=e.replace' . |
1144 | | - '(/o$/i,\'b\').substr(-2).toLowerCase(),y=\'kb\'==z?1:\'mb\'==z?1024:\'gb' . |
1145 | | - '\'==z?1048576:\'tb\'==z?1073741824:\'b\'==e.substr(-1)?.0009765625:1,e=e' . |
1146 | | - '.replace(/[^0-9]*$/i,\'\'),e=isNaN(e)?0:e*y,t=0>e?\'0 %2$s\':1>e?nft((10' . |
1147 | | - '24*e).toFixed(0))+\' %2$s\':1024>e?nft((1*e).toFixed(2))+\' %3$s\':10485' . |
1148 | | - '76>e?nft((e/1024).toFixed(2))+\' %4$s\':1073741824>e?nft((e/1048576).toF' . |
1149 | | - 'ixed(2))+\' %5$s\':nft((e/1073741824).toFixed(2))+\' %6$s\';%7$s?%7$s(\'' . |
1150 | | - '%1$s_preview\').innerHTML=t:%8$s&&!%7$s?%8$s.%1$s_preview.innerHTML=t:\'' . |
1151 | | - '\'};%1$s_function();</script>', |
1152 | | - $ThisDir['DirLangKey'], |
1153 | | - $this->Loader->L10N->getPlural(0, 'field_size_bytes'), |
1154 | | - $this->Loader->L10N->getString('field_size_KB'), |
1155 | | - $this->Loader->L10N->getString('field_size_MB'), |
1156 | | - $this->Loader->L10N->getString('field_size_GB'), |
1157 | | - $this->Loader->L10N->getString('field_size_TB'), |
1158 | | - 'document.getElementById', |
1159 | | - 'document.all' |
1160 | | - ); |
1161 | | - } elseif ($DirValue['preview'] === 'seconds') { |
| 1137 | + if ($DirValue['preview'] === 'seconds') { |
1162 | 1138 | $ThisDir['Preview'] .= sprintf( |
1163 | 1139 | '<script type="text/javascript">function %1$s_function(){var t=%9$s?%9$s(' . |
1164 | 1140 | '\'%1$s_field\').value:%10$s&&!%9$s?%10$s.%1$s_field.value:\'\',e=isNaN(t' . |
@@ -1245,6 +1221,35 @@ public function view(string $Page = ''): void |
1245 | 1221 | $ThisDir['DirLangKey'] |
1246 | 1222 | ) . '</script>'; |
1247 | 1223 | } |
| 1224 | + } elseif ($DirValue['type'] === 'kb') { |
| 1225 | + $ThisDir['Preview'] = sprintf(' = <span id="%s_preview"></span>', $ThisDir['DirLangKey']); |
| 1226 | + $ThisDir['Trigger'] = ' onchange="javascript:' . $ThisDir['DirLangKey'] . '_function();" onkeyup="javascript:' . $ThisDir['DirLangKey'] . '_function();"'; |
| 1227 | + $ThisDir['Preview'] .= sprintf( |
| 1228 | + '<script type="text/javascript">function %1$s_function(){const bytesPerUnit={' . |
| 1229 | + 'B:1,K:1024,M:1048576,G:1073741824,T:1099511627776,P:1125899906842620},unitNa' . |
| 1230 | + 'mes=["%2$s","%3$s","%4$s","%5$s","%6$s","%7$s"];var e=%8$s?%8$s(\'%1$s_field' . |
| 1231 | + '\').value:%9$s&&!%8$s?%9$s.%1$s_field.value:\'\';if((Unit=e.match(/(?<Unit>[' . |
| 1232 | + 'KkMmGgTtPpOoBb]|К|к|М|м|Г|г|Т|т|П|п|K|k|M|m|G|g|T|t|P|p|Б|б|B|b)(?:[OoBb]|Б|' . |
| 1233 | + 'б|B|b)?$/))&&void 0!==Unit.groups.Unit)if((Unit=Unit.groups.Unit).match(/^(?' . |
| 1234 | + ':[OoBb]|Б|б|B|b)$/))var Unit=\'B\';else if(Unit.match(/^(?:[Mm]|М|м)$/))Unit' . |
| 1235 | + '=\'M\';else if(Unit.match(/^(?:[Gg]|Г|г)$/))Unit=\'G\';else if(Unit.match(/^' . |
| 1236 | + '(?:[Tt]|Т|т)$/))Unit=\'T\';else if(Unit.match(/^(?:[Pp]|П|п)$/))Unit=\'P\';e' . |
| 1237 | + 'lse Unit=\'K\';else Unit=\'K\';var e=parseFloat(e);if(isNaN(e))var fixed=0;e' . |
| 1238 | + 'lse{if(void 0!==bytesPerUnit[Unit])fixed=e*bytesPerUnit[Unit];else fixed=e;f' . |
| 1239 | + 'ixed=Math.floor(fixed)}for(var i=0,p=unitNames[i];fixed>=1024;){fixed=fixed/' . |
| 1240 | + '1024;i++;p=unitNames[i];if(i>=5)break}t=nft(fixed.toFixed(i===0?0:2))+\' \'+' . |
| 1241 | + 'p;%8$s?%8$s(\'%1$s_preview\').innerHTML=t:%9$s&&!%8$s?%9$s.%1$s_preview.inne' . |
| 1242 | + 'rHTML=t:\'\';};%1$s_function();</script>', |
| 1243 | + $ThisDir['DirLangKey'], |
| 1244 | + $this->Loader->L10N->getPlural(0, 'field_size_bytes'), |
| 1245 | + $this->Loader->L10N->getString('field_size_KB'), |
| 1246 | + $this->Loader->L10N->getString('field_size_MB'), |
| 1247 | + $this->Loader->L10N->getString('field_size_GB'), |
| 1248 | + $this->Loader->L10N->getString('field_size_TB'), |
| 1249 | + $this->Loader->L10N->getString('field_size_PB'), |
| 1250 | + 'document.getElementById', |
| 1251 | + 'document.all' |
| 1252 | + ); |
1248 | 1253 | } |
1249 | 1254 | if ($DirValue['type'] === 'timezone') { |
1250 | 1255 | $DirValue['choices'] = ['SYSTEM' => $this->Loader->L10N->getString('field_system_timezone')]; |
@@ -1491,6 +1496,8 @@ public function view(string $Page = ''): void |
1491 | 1496 | $ThisDir['FieldAppend'] = $ThisDir['autocomplete'] . $ThisDir['Trigger']; |
1492 | 1497 | if (isset($DirValue['pattern'])) { |
1493 | 1498 | $ThisDir['FieldAppend'] .= ' pattern="' . $DirValue['pattern'] . '"'; |
| 1499 | + } elseif ($DirValue['type'] === 'kb') { |
| 1500 | + $ThisDir['FieldAppend'] .= ' pattern="^\d+(\.\d+)?\s*(?:[KkMmGgTtPpOoBb]|К|к|М|м|Г|г|Т|т|П|п|K|k|M|m|G|g|T|t|P|p|Б|б|B|b)(?:[OoBb]|Б|б|B|b)?$"'; |
1494 | 1501 | } |
1495 | 1502 | $ThisDir['FieldOut'] = sprintf( |
1496 | 1503 | '<input type="text" name="%1$s" id="%1$s_field" value="%2$s"%3$s />', |
|
0 commit comments