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
60c351ea
Commit
60c351ea
authored
May 30, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored Tabs.
parent
79aaf1fb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
52 deletions
+21
-52
Tabs.php
framework/yii/bootstrap/Tabs.php
+21
-52
No files found.
framework/yii/bootstrap/Tabs.php
View file @
60c351ea
...
...
@@ -26,8 +26,8 @@ use yii\helpers\Html;
* ),
* array(
* 'label' => 'Two',
* 'headerOptions' => array(...),
* 'content' => 'Anim pariatur cliche...',
* 'headerOptions' => array(...),
* 'options' => array('id'=>'myveryownID'),
* ),
* array(
...
...
@@ -61,12 +61,12 @@ class Tabs extends Widget
* - headerOptions: array, optional, the HTML attributes of the tab header.
* - content: array, required if `items` is not set. The content (HTML) of the tab pane.
* - options: array, optional, the HTML attributes of the tab pane container.
* - active: boolean, optional, whether the item tab header and pane should be visible
s
or not.
* - active: boolean, optional, whether the item tab header and pane should be visible or not.
* - items: array, optional, if not set then `content` will be required. The `items` specify a dropdown items
* configuration array. Items can also hold two extra keys:
*
- active: boolean, optional, whether the item tab header and pane should be visibles
or not.
*
-
content: string, required if `items` is not set. The content (HTML) of the tab pane.
*
-
contentOptions: optional, array, the HTML attributes of the tab content container.
*
* active: boolean, optional, whether the item tab header and pane should be visible
or not.
*
*
content: string, required if `items` is not set. The content (HTML) of the tab pane.
*
*
contentOptions: optional, array, the HTML attributes of the tab content container.
*/
public
$items
=
array
();
/**
...
...
@@ -94,7 +94,6 @@ class Tabs extends Widget
{
parent
::
init
();
$this
->
addCssClass
(
$this
->
options
,
'nav nav-tabs'
);
}
/**
...
...
@@ -119,25 +118,21 @@ class Tabs extends Widget
if
(
!
isset
(
$item
[
'label'
]))
{
throw
new
InvalidConfigException
(
"The 'label' option is required."
);
}
if
(
!
isset
(
$item
[
'content'
])
&&
!
isset
(
$item
[
'items'
]))
{
throw
new
InvalidConfigException
(
"The 'content' option is required."
);
}
$label
=
$this
->
label
(
$item
[
'label'
]);
$headerOptions
=
$this
->
mergedOptions
(
$item
,
'headerOptions'
);
$label
=
$this
->
encodeLabels
?
Html
::
encode
(
$item
[
'label'
])
:
$item
[
'label'
];
$headerOptions
=
array_merge
(
$this
->
headerOptions
,
ArrayHelper
::
getValue
(
$item
,
'headerOptions'
,
array
()));
if
(
isset
(
$item
[
'items'
]))
{
$label
.=
' <b class="caret"></b>'
;
$this
->
addCssClass
(
$headerOptions
,
'dropdown'
);
if
(
$this
->
normalizeItems
(
$item
[
'items'
],
$panes
))
{
if
(
$this
->
renderDropdown
(
$item
[
'items'
],
$panes
))
{
$this
->
addCssClass
(
$headerOptions
,
'active'
);
}
$header
=
Html
::
a
(
$label
,
"#"
,
array
(
'class'
=>
'dropdown-toggle'
,
'data-toggle'
=>
'dropdown'
))
.
"
\n
"
;
$header
.=
Dropdown
::
widget
(
array
(
'items'
=>
$item
[
'items'
],
'clientOptions'
=>
false
));
}
else
{
$options
=
$this
->
mergedOptions
(
$item
,
'itemOptions'
,
'options'
);
$header
=
Html
::
a
(
$label
,
"#"
,
array
(
'class'
=>
'dropdown-toggle'
,
'data-toggle'
=>
'dropdown'
))
.
"
\n
"
.
Dropdown
::
widget
(
array
(
'items'
=>
$item
[
'items'
],
'clientOptions'
=>
false
));
}
elseif
(
isset
(
$item
[
'content'
]))
{
$options
=
array_merge
(
$this
->
itemOptions
,
ArrayHelper
::
getValue
(
$item
,
'options'
));
$options
[
'id'
]
=
ArrayHelper
::
getValue
(
$options
,
'id'
,
$this
->
options
[
'id'
]
.
'-tab'
.
$n
);
$this
->
addCssClass
(
$options
,
'tab-pane'
);
...
...
@@ -147,40 +142,15 @@ class Tabs extends Widget
}
$header
=
Html
::
a
(
$label
,
'#'
.
$options
[
'id'
],
array
(
'data-toggle'
=>
'tab'
,
'tabindex'
=>
'-1'
));
$panes
[]
=
Html
::
tag
(
'div'
,
$item
[
'content'
],
$options
);
}
else
{
throw
new
InvalidConfigException
(
"Either the 'content' or 'items' option must be set."
);
}
$headers
[]
=
Html
::
tag
(
'li'
,
$header
,
array_merge
(
$this
->
headerOptions
,
$headerOptions
));
}
return
Html
::
tag
(
'ul'
,
implode
(
"
\n
"
,
$headers
),
$this
->
options
)
.
"
\n
"
.
Html
::
tag
(
'div'
,
implode
(
"
\n
"
,
$panes
),
array
(
'class'
=>
'tab-content'
));
}
/**
* Returns encoded if specified on [[encodeLabels]], original string otherwise.
* @param string $content the label text to encode or return
* @return string the resulting label.
*/
protected
function
label
(
$content
)
{
return
$this
->
encodeLabels
?
Html
::
encode
(
$content
)
:
$content
;
}
/**
* Returns array of options merged with specified attribute array. The availabel options are:
* - [[itemOptions]]
* - [[headerOptions]]
* @param array $item the item to merge the options with
* @param string $name the property name.
* @param string $key the key to extract. If null, it is assumed to be the same as `$name`.
* @return array the merged array options.
*/
protected
function
mergedOptions
(
$item
,
$name
,
$key
=
null
)
{
if
(
$key
===
null
)
{
$key
=
$name
;
$headers
[]
=
Html
::
tag
(
'li'
,
$header
,
$headerOptions
);
}
return
array_merge
(
$this
->
{
$name
},
ArrayHelper
::
getValue
(
$item
,
$key
,
array
()));
return
Html
::
tag
(
'ul'
,
implode
(
"
\n
"
,
$headers
),
$this
->
options
)
.
"
\n
"
.
Html
::
tag
(
'div'
,
implode
(
"
\n
"
,
$panes
),
array
(
'class'
=>
'tab-content'
));
}
/**
...
...
@@ -191,7 +161,7 @@ class Tabs extends Widget
* @return boolean whether any of the dropdown items is `active` or not.
* @throws InvalidConfigException
*/
protected
function
normalizeItems
(
&
$items
,
&
$panes
)
protected
function
renderDropdown
(
&
$items
,
&
$panes
)
{
$itemActive
=
false
;
...
...
@@ -199,7 +169,7 @@ class Tabs extends Widget
if
(
is_string
(
$item
))
{
continue
;
}
if
(
!
isset
(
$item
[
'content'
])
&&
!
isset
(
$item
[
'items'
])
)
{
if
(
!
isset
(
$item
[
'content'
]))
{
throw
new
InvalidConfigException
(
"The 'content' option is required."
);
}
...
...
@@ -222,4 +192,4 @@ class Tabs extends Widget
}
return
$itemActive
;
}
}
\ No newline at end of file
}
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