Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Polyfill js for legacy browsers (adds events and classlist polyfills) #11686

42 changes: 42 additions & 0 deletions libraries/cms/html/behavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -960,4 +960,46 @@ public static function tabstate()
JHtml::_('script', 'system/tabs-state.js', false, true);
self::$loaded[__METHOD__] = true;
}

/**
* Add javascript polyfills.
*
* @param string|array $polyfillTypes The polyfill type(s). Examples: event, array('event', 'classlist').
* @param array $conditionalBrowser A IE conditional expression. Example: lt IE 9 (lower than IE 9).
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public static function polyfill($polyfillTypes = null, $conditionalBrowser = null)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm how about lt IE 11 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

classList partial implementation in IE 10-9

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i actually think it's better to leave the parameters empty by default (add if you want when calling)
i will remove the default values.

if (is_null($polyfillTypes))
{
return false;
}

if (!is_array($polyfillTypes))
{
$polyfillTypes = array($polyfillTypes);
}

foreach ($polyfillTypes as $polyfillType)
{
$sig = md5(serialize(array($polyfillType, $conditionalBrowser)));

// Only load once
if (isset(static::$loaded[__METHOD__][$sig]))
{
continue;
}

// If include according to browser.
$scriptOptions = !is_null($conditionalBrowser) ? array('relative' => true, 'conditional' => $conditionalBrowser) : array('relative' => true);

JHtml::_('script', 'system/polyfill.' . $polyfillType . '.js', $scriptOptions);

// Set static array
static::$loaded[__METHOD__][$sig] = true;
}
}
}
Loading