Skip to content

Commit

Permalink
Add Polyfill js for legacy browsers (adds events and classlist polyfi…
Browse files Browse the repository at this point in the history
…lls). Fixes #11686
  • Loading branch information
andrepereiradasilva authored and wilsonge committed Sep 4, 2016
1 parent 7602661 commit 075a14b
Show file tree
Hide file tree
Showing 5 changed files with 903 additions and 0 deletions.
42 changes: 42 additions & 0 deletions libraries/cms/html/behavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -973,4 +973,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)
{
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

0 comments on commit 075a14b

Please sign in to comment.