mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Add once option to css().
The default value is false for backwards compatibility. In 3.0, the default will be made consistent with script(). Refs #1973 Refs #3628
This commit is contained in:
parent
92eeef8ae0
commit
758599e6f4
2 changed files with 44 additions and 5 deletions
|
@ -695,6 +695,31 @@ class HtmlHelperTest extends CakeTestCase {
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test css() with once option.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCssLinkOnce() {
|
||||||
|
Configure::write('Asset.filter.css', false);
|
||||||
|
|
||||||
|
$result = $this->Html->css('screen', array('once' => true));
|
||||||
|
$expected = array(
|
||||||
|
'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/.*css\/screen\.css/')
|
||||||
|
);
|
||||||
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
|
$result = $this->Html->css('screen', array('once' => true));
|
||||||
|
$this->assertEquals('', $result);
|
||||||
|
|
||||||
|
// Default is once=false
|
||||||
|
$result = $this->Html->css('screen');
|
||||||
|
$expected = array(
|
||||||
|
'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/.*css\/screen\.css/')
|
||||||
|
);
|
||||||
|
$this->assertTags($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test css link BC usage
|
* Test css link BC usage
|
||||||
*
|
*
|
||||||
|
|
|
@ -112,11 +112,11 @@ class HtmlHelper extends AppHelper {
|
||||||
protected $_crumbs = array();
|
protected $_crumbs = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Names of script files that have been included once
|
* Names of script & css files that have been included once
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $_includedScripts = array();
|
protected $_includedAssets = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Options for the currently opened script block buffer if any.
|
* Options for the currently opened script block buffer if any.
|
||||||
|
@ -397,6 +397,9 @@ class HtmlHelper extends AppHelper {
|
||||||
*
|
*
|
||||||
* - `inline` If set to false, the generated tag will be appended to the 'css' block,
|
* - `inline` If set to false, the generated tag will be appended to the 'css' block,
|
||||||
* and included in the `$scripts_for_layout` layout variable. Defaults to true.
|
* and included in the `$scripts_for_layout` layout variable. Defaults to true.
|
||||||
|
* - `once` Whether or not the css file should be checked for uniqueness. If true css
|
||||||
|
* files will only be included once, use false to allow the same
|
||||||
|
* css to be included more than once per request.
|
||||||
* - `block` Set the name of the block link/style tag will be appended to.
|
* - `block` Set the name of the block link/style tag will be appended to.
|
||||||
* This overrides the `inline` option.
|
* This overrides the `inline` option.
|
||||||
* - `plugin` False value will prevent parsing path as a plugin
|
* - `plugin` False value will prevent parsing path as a plugin
|
||||||
|
@ -423,7 +426,12 @@ class HtmlHelper extends AppHelper {
|
||||||
unset($rel);
|
unset($rel);
|
||||||
}
|
}
|
||||||
|
|
||||||
$options += array('block' => null, 'inline' => true, 'rel' => 'stylesheet');
|
$options += array(
|
||||||
|
'block' => null,
|
||||||
|
'inline' => true,
|
||||||
|
'once' => false,
|
||||||
|
'rel' => 'stylesheet'
|
||||||
|
);
|
||||||
if (!$options['inline'] && empty($options['block'])) {
|
if (!$options['inline'] && empty($options['block'])) {
|
||||||
$options['block'] = __FUNCTION__;
|
$options['block'] = __FUNCTION__;
|
||||||
}
|
}
|
||||||
|
@ -440,6 +448,12 @@ class HtmlHelper extends AppHelper {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($options['once'] && isset($this->_includedAssets[$path])) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
unset($options['once']);
|
||||||
|
$this->_includedAssets[$path] = true;
|
||||||
|
|
||||||
if (strpos($path, '//') !== false) {
|
if (strpos($path, '//') !== false) {
|
||||||
$url = $path;
|
$url = $path;
|
||||||
} else {
|
} else {
|
||||||
|
@ -538,10 +552,10 @@ class HtmlHelper extends AppHelper {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if ($options['once'] && isset($this->_includedScripts[$url])) {
|
if ($options['once'] && isset($this->_includedAssets[$url])) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$this->_includedScripts[$url] = true;
|
$this->_includedAssets[$url] = true;
|
||||||
|
|
||||||
if (strpos($url, '//') === false) {
|
if (strpos($url, '//') === false) {
|
||||||
$url = $this->assetUrl($url, $options + array('pathPrefix' => Configure::read('App.jsBaseUrl'), 'ext' => '.js'));
|
$url = $this->assetUrl($url, $options + array('pathPrefix' => Configure::read('App.jsBaseUrl'), 'ext' => '.js'));
|
||||||
|
|
Loading…
Add table
Reference in a new issue