Remove support for targetie attribute on assets

This commit is contained in:
Kijin Sung 2022-12-28 00:35:57 +09:00
parent d34d08438f
commit 9e9adcdb43
8 changed files with 95 additions and 193 deletions

View file

@ -496,25 +496,15 @@ class Formatter
foreach ($source_filename as $filename)
{
// Get the IE condition.
if (is_array($filename) && count($filename) >= 2)
// Handle the array format, previously used for the targetIE attribute.
if (is_array($filename) && count($filename) >= 1)
{
list($filename, $targetie) = $filename;
}
else
{
$targetie = null;
$filename = reset($filename);
}
// Clean the content.
$content = utf8_clean(file_get_contents($filename));
// Wrap the content in an IE condition if there is one.
if ($targetie !== null)
{
$content = 'if (' . self::convertIECondition($targetie) . ') {' . "\n\n" . trim($content) . ";\n\n" . '}';
}
// Append to the result string.
$original_filename = starts_with(\RX_BASEDIR, $filename) ? substr($filename, strlen(\RX_BASEDIR)) : $filename;
$result .= '/* Original file: ' . $original_filename . ' */' . "\n\n" . trim($content) . ";\n\n";
@ -526,62 +516,12 @@ class Formatter
/**
* Convert IE conditional comments to JS conditions.
*
* @deprecated
* @param string $condition
* @return string
*/
public static function convertIECondition($condition)
{
$conversions = array(
'/^true$/i' => 'true',
'/^false$/i' => 'false',
'/^IE$/i' => 'window.navigator.userAgent.match(/MSIE\s/)',
'/^IE\s*(\d+)$/i' => '(/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] == %d)',
'/^gt IE\s*(\d+)$/i' => '(/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] > %d)',
'/^gte IE\s*(\d+)$/i' => '(/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] >= %d)',
'/^lt IE\s*(\d+)$/i' => '(/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] < %d)',
'/^lte IE\s*(\d+)$/i' => '(/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] <= %d)',
);
$result = array();
$conditions = preg_split('/([\&\|])/', $condition, -1, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE);
foreach ($conditions as $condition)
{
$condition = trim(preg_replace('/[\(\)]/', '', $condition));
if ($condition === '')
{
continue;
}
if ($condition === '&' || $condition === '|')
{
$result[] = $condition . $condition;
continue;
}
$negation = $condition[0] === '!';
if ($negation)
{
$condition = trim(substr($condition, 1));
}
foreach ($conversions as $regexp => $replacement)
{
if (preg_match($regexp, $condition, $matches))
{
if (count($matches) > 1)
{
array_shift($matches);
$result[] = ($negation ? '!' : '') . vsprintf($replacement, $matches);
}
else
{
$result[] = ($negation ? '!' : '') . $replacement;
}
break;
}
}
}
return count($result) ? implode(' ', $result) : 'false';
throw new Exceptions\FeatureDisabled;
}
}

View file

@ -17,16 +17,12 @@
<!-- CSS -->
<block loop="Context::getCssFile(true) => $key, $css_file">
<block cond="$css_file['targetie']"><!--[if {$css_file['targetie']}]><block cond="stripos($css_file['targetie'], 'gt') === 0"><!--></block></block>
<link rel="stylesheet" href="{$css_file['file']}" media="{$css_file['media']}"|cond="$css_file['media'] != 'all'" />
<block cond="$css_file['targetie']"><block cond="stripos($css_file['targetie'], 'gt') === 0"><!--</block><![endif]-->{"\n"}</block>
</block>
<!-- JS -->
<block loop="Context::getJsFile('head', true) => $key, $js_file">
<block cond="$js_file['targetie']"><!--[if {$js_file['targetie']}]><block cond="stripos($js_file['targetie'], 'gt') === 0"><!--></block></block>
<script src="{$js_file['file']}"></script>
<block cond="$js_file['targetie']"><block cond="stripos($js_file['targetie'], 'gt') === 0"><!--</block><![endif]-->{"\n"}</block>
</block>
<!-- RSS -->