Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
5f8e6d37
Commit
5f8e6d37
authored
Dec 30, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #1706: Added support for registering a single JS/CSS file with dependency
parent
b83414f6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
9 deletions
+28
-9
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
AssetBundle.php
framework/yii/web/AssetBundle.php
+2
-4
View.php
framework/yii/web/View.php
+25
-5
No files found.
framework/CHANGELOG.md
View file @
5f8e6d37
...
@@ -44,6 +44,7 @@ Yii Framework 2 Change Log
...
@@ -44,6 +44,7 @@ Yii Framework 2 Change Log
-
Enh #1646: Added postgresql
`QueryBuilder::checkIntegrity`
and
`QueryBuilder::resetSequence`
(Ragazzo)
-
Enh #1646: Added postgresql
`QueryBuilder::checkIntegrity`
and
`QueryBuilder::resetSequence`
(Ragazzo)
-
Enh #1645: Added
`Connection::$pdoClass`
property (Ragazzo)
-
Enh #1645: Added
`Connection::$pdoClass`
property (Ragazzo)
-
Enh #1681: Added support for automatically adjusting the "for" attribute of label generated by
`ActiveField::label()`
(qiangxue)
-
Enh #1681: Added support for automatically adjusting the "for" attribute of label generated by
`ActiveField::label()`
(qiangxue)
-
Enh #1706: Added support for registering a single JS/CSS file with dependency (qiangxue)
-
Enh: Added
`favicon.ico`
and
`robots.txt`
to default application templates (samdark)
-
Enh: Added
`favicon.ico`
and
`robots.txt`
to default application templates (samdark)
-
Enh: Added
`Widget::autoIdPrefix`
to support prefixing automatically generated widget IDs (qiangxue)
-
Enh: Added
`Widget::autoIdPrefix`
to support prefixing automatically generated widget IDs (qiangxue)
-
Enh: Support for file aliases in console command 'message' (omnilight)
-
Enh: Support for file aliases in console command 'message' (omnilight)
...
...
framework/yii/web/AssetBundle.php
View file @
5f8e6d37
...
@@ -165,8 +165,6 @@ class AssetBundle extends Object
...
@@ -165,8 +165,6 @@ class AssetBundle extends Object
* It will also try to convert non-CSS or JS files (e.g. LESS, Sass) into the corresponding
* It will also try to convert non-CSS or JS files (e.g. LESS, Sass) into the corresponding
* CSS or JS files using [[AssetManager::converter|asset converter]].
* CSS or JS files using [[AssetManager::converter|asset converter]].
* @param AssetManager $am the asset manager to perform the asset publishing
* @param AssetManager $am the asset manager to perform the asset publishing
* @throws InvalidConfigException if [[baseUrl]] or [[basePath]] is not set when the bundle
* contains internal CSS or JS files.
*/
*/
public
function
publish
(
$am
)
public
function
publish
(
$am
)
{
{
...
@@ -179,7 +177,7 @@ class AssetBundle extends Object
...
@@ -179,7 +177,7 @@ class AssetBundle extends Object
if
(
isset
(
$this
->
basePath
,
$this
->
baseUrl
))
{
if
(
isset
(
$this
->
basePath
,
$this
->
baseUrl
))
{
$this
->
js
[
$i
]
=
$converter
->
convert
(
$js
,
$this
->
basePath
,
$this
->
baseUrl
);
$this
->
js
[
$i
]
=
$converter
->
convert
(
$js
,
$this
->
basePath
,
$this
->
baseUrl
);
}
else
{
}
else
{
throw
new
InvalidConfigException
(
'Both of the "baseUrl" and "basePath" properties must be set.'
)
;
$this
->
js
[
$i
]
=
'/'
.
$js
;
}
}
}
}
}
}
...
@@ -188,7 +186,7 @@ class AssetBundle extends Object
...
@@ -188,7 +186,7 @@ class AssetBundle extends Object
if
(
isset
(
$this
->
basePath
,
$this
->
baseUrl
))
{
if
(
isset
(
$this
->
basePath
,
$this
->
baseUrl
))
{
$this
->
css
[
$i
]
=
$converter
->
convert
(
$css
,
$this
->
basePath
,
$this
->
baseUrl
);
$this
->
css
[
$i
]
=
$converter
->
convert
(
$css
,
$this
->
basePath
,
$this
->
baseUrl
);
}
else
{
}
else
{
throw
new
InvalidConfigException
(
'Both of the "baseUrl" and "basePath" properties must be set.'
)
;
$this
->
css
[
$i
]
=
'/'
.
$css
;
}
}
}
}
}
}
...
...
framework/yii/web/View.php
View file @
5f8e6d37
...
@@ -312,15 +312,26 @@ class View extends \yii\base\View
...
@@ -312,15 +312,26 @@ class View extends \yii\base\View
/**
/**
* Registers a CSS file.
* Registers a CSS file.
* @param string $url the CSS file to be registered.
* @param string $url the CSS file to be registered.
* @param array $depends the names of the asset bundles that this CSS file depends on
* @param array $options the HTML attributes for the link tag.
* @param array $options the HTML attributes for the link tag.
* @param string $key the key that identifies the CSS script file. If null, it will use
* @param string $key the key that identifies the CSS script file. If null, it will use
* $url as the key. If two CSS files are registered with the same key, the latter
* $url as the key. If two CSS files are registered with the same key, the latter
* will overwrite the former.
* will overwrite the former.
*/
*/
public
function
registerCssFile
(
$url
,
$options
=
[],
$key
=
null
)
public
function
registerCssFile
(
$url
,
$
depends
=
[],
$
options
=
[],
$key
=
null
)
{
{
$key
=
$key
?:
$url
;
$key
=
$key
?:
$url
;
if
(
empty
(
$depends
))
{
$this
->
cssFiles
[
$key
]
=
Html
::
cssFile
(
$url
,
$options
);
$this
->
cssFiles
[
$key
]
=
Html
::
cssFile
(
$url
,
$options
);
}
else
{
$am
=
Yii
::
$app
->
getAssetManager
();
$am
->
bundles
[
$key
]
=
new
AssetBundle
([
'css'
=>
[
$url
],
'cssOptions'
=>
$options
,
'depends'
=>
(
array
)
$depends
,
]);
$this
->
registerAssetBundle
(
$key
);
}
}
}
/**
/**
...
@@ -350,9 +361,8 @@ class View extends \yii\base\View
...
@@ -350,9 +361,8 @@ class View extends \yii\base\View
/**
/**
* Registers a JS file.
* Registers a JS file.
* Please note that when this file depends on other JS files to be registered before,
* for example jQuery, you should use [[registerAssetBundle]] instead.
* @param string $url the JS file to be registered.
* @param string $url the JS file to be registered.
* @param array $depends the names of the asset bundles that this JS file depends on
* @param array $options the HTML attributes for the script tag. A special option
* @param array $options the HTML attributes for the script tag. A special option
* named "position" is supported which specifies where the JS script tag should be inserted
* named "position" is supported which specifies where the JS script tag should be inserted
* in a page. The possible values of "position" are:
* in a page. The possible values of "position" are:
...
@@ -365,12 +375,22 @@ class View extends \yii\base\View
...
@@ -365,12 +375,22 @@ class View extends \yii\base\View
* $url as the key. If two JS files are registered with the same key, the latter
* $url as the key. If two JS files are registered with the same key, the latter
* will overwrite the former.
* will overwrite the former.
*/
*/
public
function
registerJsFile
(
$url
,
$options
=
[],
$key
=
null
)
public
function
registerJsFile
(
$url
,
$
depends
=
[],
$
options
=
[],
$key
=
null
)
{
{
$key
=
$key
?:
$url
;
if
(
empty
(
$depends
))
{
$position
=
isset
(
$options
[
'position'
])
?
$options
[
'position'
]
:
self
::
POS_END
;
$position
=
isset
(
$options
[
'position'
])
?
$options
[
'position'
]
:
self
::
POS_END
;
unset
(
$options
[
'position'
]);
unset
(
$options
[
'position'
]);
$key
=
$key
?:
$url
;
$this
->
jsFiles
[
$position
][
$key
]
=
Html
::
jsFile
(
$url
,
$options
);
$this
->
jsFiles
[
$position
][
$key
]
=
Html
::
jsFile
(
$url
,
$options
);
}
else
{
$am
=
Yii
::
$app
->
getAssetManager
();
$am
->
bundles
[
$key
]
=
new
AssetBundle
([
'js'
=>
[
$url
],
'jsOptions'
=>
$options
,
'depends'
=>
(
array
)
$depends
,
]);
$this
->
registerAssetBundle
(
$key
);
}
}
}
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment