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
df025fc2
Commit
df025fc2
authored
May 24, 2013
by
Alexander Kochetov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jQuery Accordion rework
parent
b5812b58
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
33 deletions
+26
-33
Accordion.php
framework/yii/jui/Accordion.php
+26
-33
No files found.
framework/yii/jui/Accordion.php
View file @
df025fc2
...
@@ -19,13 +19,15 @@ use yii\helpers\Html;
...
@@ -19,13 +19,15 @@ use yii\helpers\Html;
* ```php
* ```php
* echo Accordion::widget(array(
* echo Accordion::widget(array(
* 'items' => array(
* 'items' => array(
* 'Section 1' => array(
* array(
* 'header' => 'Section 1',
* 'content' => 'Mauris mauris ante, blandit et, ultrices a, suscipit eget...',
* 'content' => 'Mauris mauris ante, blandit et, ultrices a, suscipit eget...',
* 'contentOptions' => array(...),
* ),
* ),
*
'Section 2' =>
array(
* array(
* '
content' => 'Sed non urna. Phasellus eu ligula. Vestibulum sit amet purus...
',
* '
header' => 'Section 2
',
* 'headerOptions' => array(...),
* 'headerOptions' => array(...),
* 'content' => 'Sed non urna. Phasellus eu ligula. Vestibulum sit amet purus...',
* 'options' => array(...),
* ),
* ),
* ),
* ),
* ));
* ));
...
@@ -42,12 +44,13 @@ class Accordion extends Widget
...
@@ -42,12 +44,13 @@ class Accordion extends Widget
* section with the following structure:
* section with the following structure:
*
*
* ```php
* ```php
* // item key is the actual section header
* array(
* 'Section' => array(
* // required, the header (HTML) of the section
* 'header' => 'Section label',
* // required, the content (HTML) of the section
* // required, the content (HTML) of the section
* 'content' => 'Mauris mauris ante, blandit et, ultrices a, suscipit eget...',
* 'content' => 'Mauris mauris ante, blandit et, ultrices a, suscipit eget...',
* // optional the HTML attributes of the content section
* // optional the HTML attributes of the content section
* '
contentO
ptions'=> array(...),
* '
o
ptions'=> array(...),
* // optional the HTML attributes of the header section
* // optional the HTML attributes of the header section
* 'headerOptions'=> array(...),
* 'headerOptions'=> array(...),
* )
* )
...
@@ -62,46 +65,36 @@ class Accordion extends Widget
...
@@ -62,46 +65,36 @@ class Accordion extends Widget
public
function
run
()
public
function
run
()
{
{
echo
Html
::
beginTag
(
'div'
,
$this
->
options
)
.
"
\n
"
;
echo
Html
::
beginTag
(
'div'
,
$this
->
options
)
.
"
\n
"
;
echo
$this
->
render
Item
s
()
.
"
\n
"
;
echo
$this
->
render
Section
s
()
.
"
\n
"
;
echo
Html
::
endTag
(
'div'
)
.
"
\n
"
;
echo
Html
::
endTag
(
'div'
)
.
"
\n
"
;
$this
->
registerWidget
(
'accordion'
);
$this
->
registerWidget
(
'accordion'
);
}
}
/**
/**
* Renders collapsible
item
s as specified on [[items]].
* Renders collapsible
section
s as specified on [[items]].
* @return string the rendering result.
* @return string the rendering result.
* @throws InvalidConfigException.
*/
*/
p
ublic
function
renderItem
s
()
p
rotected
function
renderSection
s
()
{
{
$items
=
array
();
$sections
=
array
();
foreach
(
$this
->
items
as
$header
=>
$item
)
{
foreach
(
$this
->
items
as
$item
)
{
$items
[]
=
$this
->
renderItem
(
$header
,
$item
);
if
(
!
isset
(
$item
[
'header'
]))
{
throw
new
InvalidConfigException
(
"The 'header' option is required."
);
}
}
return
implode
(
"
\n
"
,
$items
);
$headerOptions
=
ArrayHelper
::
getValue
(
$item
,
'headerOptions'
,
array
()
);
}
$sections
[]
=
Html
::
tag
(
'h3'
,
$item
[
'header'
],
$headerOptions
);
/**
if
(
!
isset
(
$item
[
'content'
]))
{
* Renders a single collapsible item section.
* @param string $header a label of the item section [[items]].
* @param array $item a single item from [[items]].
* @return string the rendering result.
* @throws InvalidConfigException.
*/
public
function
renderItem
(
$header
,
$item
)
{
if
(
isset
(
$item
[
'content'
]))
{
$contentOptions
=
ArrayHelper
::
getValue
(
$item
,
'contentOptions'
,
array
());
$content
=
Html
::
tag
(
'div'
,
$item
[
'content'
])
.
"
\n
"
;
}
else
{
throw
new
InvalidConfigException
(
"The 'content' option is required."
);
throw
new
InvalidConfigException
(
"The 'content' option is required."
);
}
}
$group
=
array
(
);
$options
=
ArrayHelper
::
getValue
(
$item
,
'options'
,
array
()
);
$headerOptions
=
ArrayHelper
::
getValue
(
$item
,
'headerOptions'
,
array
())
;
$sections
[]
=
Html
::
tag
(
'div'
,
$item
[
'content'
],
$options
);
;
$group
[]
=
Html
::
tag
(
'h3'
,
$header
,
$headerOptions
);
$group
[]
=
Html
::
tag
(
'div'
,
$content
,
$contentOptions
);
}
return
implode
(
"
\n
"
,
$
group
);
return
implode
(
"
\n
"
,
$
sections
);
}
}
}
}
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