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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
861c2b2f
Commit
861c2b2f
authored
Jan 28, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added `yii\web\View::POS_LOAD`
parent
7924e6d1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
2 deletions
+15
-2
view.md
docs/guide/view.md
+2
-1
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
View.php
framework/web/View.php
+12
-1
No files found.
docs/guide/view.md
View file @
861c2b2f
...
...
@@ -236,7 +236,8 @@ determines where script should be inserted into the page. Possible values are:
-
`View::POS_HEAD`
for head section.
-
`View::POS_BEGIN`
for right after opening
`<body>`
.
-
`View::POS_END`
for right before closing
`</body>`
.
-
`View::POS_READY`
for executing code on document
`ready`
event. This one registers jQuery automatically.
-
`View::POS_READY`
for executing code on document
`ready`
event. This will register jQuery automatically.
-
`View::POS_LOAD`
for executing code on document
`load`
event. This will register jQuery automatically.
The last argument is a unique script ID that is used to identify code block and replace existing one with the same ID
instead of adding a new one. If you don't provide it, the JS code itself will be used as the ID.
...
...
framework/CHANGELOG.md
View file @
861c2b2f
...
...
@@ -108,6 +108,7 @@ Yii Framework 2 Change Log
-
Enh: Added ability to get incoming headers (dizews)
-
Enh: Added
`beforeRun()`
and
`afterRun()`
to
`yii\base\Action`
(qiangxue)
-
Enh: Added support for using timeZone with
`yii\base\Formatter`
(dizews)
-
Enh: Added
`yii\web\View::POS_LOAD`
(qiangxue)
-
Chg #1519:
`yii\web\User::loginRequired()`
now returns the
`Response`
object instead of exiting the application (qiangxue)
-
Chg #1586:
`QueryBuilder::buildLikeCondition()`
will now escape special characters and use percentage characters by default (qiangxue)
-
Chg #1610:
`Html::activeCheckboxList()`
and
`Html::activeRadioList()`
will submit an empty string if no checkbox/radio is selected (qiangxue)
...
...
framework/web/View.php
View file @
861c2b2f
...
...
@@ -67,6 +67,11 @@ class View extends \yii\base\View
*/
const
POS_READY
=
4
;
/**
* The location of registered JavaScript code block.
* This means the JavaScript code block will be enclosed within `jQuery(window).load()`.
*/
const
POS_LOAD
=
5
;
/**
* This is internally used as the placeholder for receiving the content registered for the head section.
*/
const
PH_HEAD
=
'<![CDATA[YII-BLOCK-HEAD]]>'
;
...
...
@@ -336,6 +341,8 @@ class View extends \yii\base\View
* - [[POS_HEAD]]: in the head section
* - [[POS_BEGIN]]: at the beginning of the body section
* - [[POS_END]]: at the end of the body section
* - [[POS_LOAD]]: enclosed within jQuery(window).load().
* Note that by using this position, the method will automatically register the jQuery js file.
* - [[POS_READY]]: enclosed within jQuery(document).ready(). This is the default value.
* Note that by using this position, the method will automatically register the jQuery js file.
*
...
...
@@ -347,7 +354,7 @@ class View extends \yii\base\View
{
$key
=
$key
?:
md5
(
$js
);
$this
->
js
[
$position
][
$key
]
=
$js
;
if
(
$position
===
self
::
POS_READY
)
{
if
(
$position
===
self
::
POS_READY
||
$position
===
self
::
POS_LOAD
)
{
JqueryAsset
::
register
(
$this
);
}
}
...
...
@@ -458,6 +465,10 @@ class View extends \yii\base\View
$js
=
"jQuery(document).ready(function(){\n"
.
implode
(
"
\n
"
,
$this
->
js
[
self
::
POS_READY
])
.
"
\n
});"
;
$lines
[]
=
Html
::
script
(
$js
,
[
'type'
=>
'text/javascript'
]);
}
if
(
!
empty
(
$this
->
js
[
self
::
POS_LOAD
]))
{
$js
=
"jQuery(window).load(function(){\n"
.
implode
(
"
\n
"
,
$this
->
js
[
self
::
POS_LOAD
])
.
"
\n
});"
;
$lines
[]
=
Html
::
script
(
$js
,
[
'type'
=>
'text/javascript'
]);
}
return
empty
(
$lines
)
?
''
:
implode
(
"
\n
"
,
$lines
);
}
}
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