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
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;
...
@@ -26,8 +26,8 @@ use yii\helpers\Html;
* ),
* ),
* array(
* array(
* 'label' => 'Two',
* 'label' => 'Two',
* 'headerOptions' => array(...),
* 'content' => 'Anim pariatur cliche...',
* 'content' => 'Anim pariatur cliche...',
* 'headerOptions' => array(...),
* 'options' => array('id'=>'myveryownID'),
* 'options' => array('id'=>'myveryownID'),
* ),
* ),
* array(
* array(
...
@@ -61,12 +61,12 @@ class Tabs extends Widget
...
@@ -61,12 +61,12 @@ class Tabs extends Widget
* - headerOptions: array, optional, the HTML attributes of the tab header.
* - 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.
* - 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.
* - 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
* - 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:
* configuration array. Items can also hold two extra keys:
*
- active: boolean, optional, whether the item tab header and pane should be visibles
or not.
*
* 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.
*
*
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.
*
*
contentOptions: optional, array, the HTML attributes of the tab content container.
*/
*/
public
$items
=
array
();
public
$items
=
array
();
/**
/**
...
@@ -94,7 +94,6 @@ class Tabs extends Widget
...
@@ -94,7 +94,6 @@ class Tabs extends Widget
{
{
parent
::
init
();
parent
::
init
();
$this
->
addCssClass
(
$this
->
options
,
'nav nav-tabs'
);
$this
->
addCssClass
(
$this
->
options
,
'nav nav-tabs'
);
}
}
/**
/**
...
@@ -119,25 +118,21 @@ class Tabs extends Widget
...
@@ -119,25 +118,21 @@ class Tabs extends Widget
if
(
!
isset
(
$item
[
'label'
]))
{
if
(
!
isset
(
$item
[
'label'
]))
{
throw
new
InvalidConfigException
(
"The 'label' option is required."
);
throw
new
InvalidConfigException
(
"The 'label' option is required."
);
}
}
if
(
!
isset
(
$item
[
'content'
])
&&
!
isset
(
$item
[
'items'
]))
{
$label
=
$this
->
encodeLabels
?
Html
::
encode
(
$item
[
'label'
])
:
$item
[
'label'
];
throw
new
InvalidConfigException
(
"The 'content' option is required."
);
$headerOptions
=
array_merge
(
$this
->
headerOptions
,
ArrayHelper
::
getValue
(
$item
,
'headerOptions'
,
array
()));
}
$label
=
$this
->
label
(
$item
[
'label'
]);
$headerOptions
=
$this
->
mergedOptions
(
$item
,
'headerOptions'
);
if
(
isset
(
$item
[
'items'
]))
{
if
(
isset
(
$item
[
'items'
]))
{
$label
.=
' <b class="caret"></b>'
;
$label
.=
' <b class="caret"></b>'
;
$this
->
addCssClass
(
$headerOptions
,
'dropdown'
);
$this
->
addCssClass
(
$headerOptions
,
'dropdown'
);
if
(
$this
->
normalizeItems
(
$item
[
'items'
],
$panes
))
{
if
(
$this
->
renderDropdown
(
$item
[
'items'
],
$panes
))
{
$this
->
addCssClass
(
$headerOptions
,
'active'
);
$this
->
addCssClass
(
$headerOptions
,
'active'
);
}
}
$header
=
Html
::
a
(
$label
,
"#"
,
array
(
'class'
=>
'dropdown-toggle'
,
'data-toggle'
=>
'dropdown'
))
.
"
\n
"
;
$header
=
Html
::
a
(
$label
,
"#"
,
array
(
'class'
=>
'dropdown-toggle'
,
'data-toggle'
=>
'dropdown'
))
.
"
\n
"
$header
.=
Dropdown
::
widget
(
array
(
'items'
=>
$item
[
'items'
],
'clientOptions'
=>
false
));
.
Dropdown
::
widget
(
array
(
'items'
=>
$item
[
'items'
],
'clientOptions'
=>
false
));
}
elseif
(
isset
(
$item
[
'content'
]))
{
}
else
{
$options
=
array_merge
(
$this
->
itemOptions
,
ArrayHelper
::
getValue
(
$item
,
'options'
));
$options
=
$this
->
mergedOptions
(
$item
,
'itemOptions'
,
'options'
);
$options
[
'id'
]
=
ArrayHelper
::
getValue
(
$options
,
'id'
,
$this
->
options
[
'id'
]
.
'-tab'
.
$n
);
$options
[
'id'
]
=
ArrayHelper
::
getValue
(
$options
,
'id'
,
$this
->
options
[
'id'
]
.
'-tab'
.
$n
);
$this
->
addCssClass
(
$options
,
'tab-pane'
);
$this
->
addCssClass
(
$options
,
'tab-pane'
);
...
@@ -147,40 +142,15 @@ class Tabs extends Widget
...
@@ -147,40 +142,15 @@ class Tabs extends Widget
}
}
$header
=
Html
::
a
(
$label
,
'#'
.
$options
[
'id'
],
array
(
'data-toggle'
=>
'tab'
,
'tabindex'
=>
'-1'
));
$header
=
Html
::
a
(
$label
,
'#'
.
$options
[
'id'
],
array
(
'data-toggle'
=>
'tab'
,
'tabindex'
=>
'-1'
));
$panes
[]
=
Html
::
tag
(
'div'
,
$item
[
'content'
],
$options
);
$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
"
.
$headers
[]
=
Html
::
tag
(
'li'
,
$header
,
$headerOptions
);
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
;
}
}
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
...
@@ -191,7 +161,7 @@ class Tabs extends Widget
* @return boolean whether any of the dropdown items is `active` or not.
* @return boolean whether any of the dropdown items is `active` or not.
* @throws InvalidConfigException
* @throws InvalidConfigException
*/
*/
protected
function
normalizeItems
(
&
$items
,
&
$panes
)
protected
function
renderDropdown
(
&
$items
,
&
$panes
)
{
{
$itemActive
=
false
;
$itemActive
=
false
;
...
@@ -199,7 +169,7 @@ class Tabs extends Widget
...
@@ -199,7 +169,7 @@ class Tabs extends Widget
if
(
is_string
(
$item
))
{
if
(
is_string
(
$item
))
{
continue
;
continue
;
}
}
if
(
!
isset
(
$item
[
'content'
])
&&
!
isset
(
$item
[
'items'
])
)
{
if
(
!
isset
(
$item
[
'content'
]))
{
throw
new
InvalidConfigException
(
"The 'content' option is required."
);
throw
new
InvalidConfigException
(
"The 'content' option is required."
);
}
}
...
@@ -222,4 +192,4 @@ class Tabs extends Widget
...
@@ -222,4 +192,4 @@ class Tabs extends Widget
}
}
return
$itemActive
;
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