mirror of
https://github.com/e107inc/e107.git
synced 2025-07-29 19:00:26 +02:00
e107::link() now supports a plain HTML string. Useful for font preloading.
eg. e107::link('rel="preload" href="{THEME}fonts/fontawesome-webfont.woff2?v=4.7.0" as="font" type="font/woff2" crossorigin'); Bootstrap automatic font preload added.
This commit is contained in:
@@ -2157,7 +2157,9 @@ class e107
|
||||
return null;
|
||||
}
|
||||
|
||||
$libraryPath = self::getParser()->replaceConstants($info['library_path'].'/'.$info['path'], 'abs').'/';
|
||||
$tp = self::getParser();
|
||||
|
||||
$libraryPath = $tp->replaceConstants($info['library_path'].'/'.$info['path'], 'abs').'/';
|
||||
|
||||
foreach($info['preload'] as $pre)
|
||||
{
|
||||
@@ -2290,18 +2292,17 @@ class e107
|
||||
|
||||
/**
|
||||
* Add a <link> tag to the head of the html document.
|
||||
* @param array $attributes
|
||||
* @param bool $browserCache set to true to add the cacheId to the href.
|
||||
* @param array|string $attributes
|
||||
* @param bool $browserCache set to true to add the cacheId to the href. (when an array is used)
|
||||
* @example e107::link(array('rel'=>"dns-prefetch", "href" => "http://example-domain.com/"));
|
||||
* @example e107::link('rel="preload" href="{THEME}assets/fonts/fontawesome-webfont.woff2?v=4.7.0" as="font" type="font/woff2" crossorigin');
|
||||
*/
|
||||
public static function link($attributes=array(), $browserCache = false)
|
||||
public static function link($attributes, $browserCache = false)
|
||||
{
|
||||
self::getJs()->addLink($attributes, $browserCache);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* CSS Common Public Function. Prefered is shortcode script path
|
||||
* @param string $type core|theme|footer|inline|footer-inline|url or any existing plugin_name
|
||||
|
@@ -2718,6 +2718,8 @@ class e_parse extends e_parser
|
||||
*/
|
||||
public function staticUrl($path=null, $opts=array())
|
||||
{
|
||||
$path = $this->replaceConstants($path,'abs');
|
||||
|
||||
if(!defined('e_HTTP_STATIC') || deftrue('e_ADMIN_AREA'))
|
||||
{
|
||||
// e107::getDebug()->log("e_HTTP_STATIC not defined");
|
||||
|
@@ -772,17 +772,23 @@ class e_jsmanager
|
||||
|
||||
/**
|
||||
* Add a <link> tag to the head.
|
||||
* @param array $attributes key>value pairs
|
||||
* @param array|string $attributes key>value pairs or html attributes string
|
||||
* @param bool $browserCache - set to true to add the cacheId to the href.
|
||||
* @example addLink(array('rel'=>'prefetch', 'href'=>THEME.'images/browsers.png'));
|
||||
* @example addLink('rel="preload" href="{THEME}assets/fonts/fontawesome-webfont.woff2?v=4.7.0" as="font" type="font/woff2" crossorigin');
|
||||
*/
|
||||
public function addLink($attributes=array(), $browserCache=false)
|
||||
public function addLink($attributes, $browserCache=false)
|
||||
{
|
||||
if(!empty($attributes['href']) && $browserCache === true)
|
||||
if(is_array($attributes) && !empty($attributes['href']))
|
||||
{
|
||||
$attributes['href'] .= "?".$this->getCacheId();
|
||||
$attributes['href'] .= ($browserCache === true) ? "?".$this->getCacheId() : '';
|
||||
$attributes['href'] = e107::getParser()->staticUrl($attributes['href']);
|
||||
}
|
||||
|
||||
if(is_string($attributes))
|
||||
{
|
||||
$attributes = e107::getParser()->staticUrl($attributes);
|
||||
}
|
||||
|
||||
if(!empty($attributes))
|
||||
{
|
||||
@@ -806,10 +812,24 @@ class e_jsmanager
|
||||
|
||||
foreach($this->_e_link as $v)
|
||||
{
|
||||
if(is_string($v))
|
||||
{
|
||||
if(strpos($v, "text/css") !== false)
|
||||
{
|
||||
e107::getDebug()->log("e107::link(".$v.") ignored. Use e107::css() instead for css stylesheets");
|
||||
continue;
|
||||
}
|
||||
|
||||
$text .= "\n<link ".$v." />";
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if(!empty($v['type']))
|
||||
{
|
||||
if($v['type'] == 'text/css' || $v['rel'] == 'stylesheet') // not for this purpose. use e107::css();
|
||||
{
|
||||
e107::getDebug()->log("e107::link(".$v['href'].") ignored. Use e107::css() instead for css stylesheets");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@@ -469,6 +469,16 @@ class core_library
|
||||
),
|
||||
'library_path' => '{e_WEB}lib/bootstrap',
|
||||
'path' => '3',
|
||||
'preload' => array(
|
||||
0 => array(
|
||||
'as' => 'font',
|
||||
'type' => 'font/woff2',
|
||||
'path' => 'fonts/glyphicons-halflings-regular.woff2',
|
||||
'crossorigin' => true,
|
||||
'browsercache' => false,
|
||||
),
|
||||
|
||||
),
|
||||
);
|
||||
|
||||
// Bootstrap Editable (CDN).
|
||||
@@ -855,6 +865,7 @@ class core_library
|
||||
|
||||
/**
|
||||
* Alters library information before detection and caching takes place.
|
||||
* @param array $libraries
|
||||
*/
|
||||
function config_alter(&$libraries)
|
||||
{
|
||||
|
Reference in New Issue
Block a user