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
e84f5649
Commit
e84f5649
authored
May 27, 2013
by
Alexander Kochetov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jQuery UI tabs full rework
parent
73900b4b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
13 deletions
+72
-13
Tabs.php
framework/yii/jui/Tabs.php
+72
-13
No files found.
framework/yii/jui/Tabs.php
View file @
e84f5649
...
@@ -29,17 +29,20 @@ use yii\helpers\Html;
...
@@ -29,17 +29,20 @@ use yii\helpers\Html;
* 'options' => array(
* 'options' => array(
* 'tag' => 'div',
* 'tag' => 'div',
* ),
* ),
* 'headerOptions' => array(
* 'class' => 'my-class',
* ),
* ),
* ),
* array(
* array(
* 'label' => 'Tab
three
',
* 'label' => 'Tab
with custom id
',
* 'content' => '
Specific conten
t...',
* 'content' => '
Morbi tincidunt, dui sit amet facilisis feugia
t...',
* 'options' => array(
* 'options' => array(
* 'id' => 'my-tab',
* 'id' => 'my-tab',
* ),
* ),
* ),
* ),
* array(
* array(
* 'label' => 'Ajax tab',
* 'label' => 'Ajax tab',
* '
url' => 'http://www.yiiframework.com'
,
* '
ajax' => array('ajax/content')
,
* ),
* ),
* ),
* ),
* 'options' => array(
* 'options' => array(
...
@@ -48,6 +51,9 @@ use yii\helpers\Html;
...
@@ -48,6 +51,9 @@ use yii\helpers\Html;
* 'itemOptions' => array(
* 'itemOptions' => array(
* 'tag' => 'div',
* 'tag' => 'div',
* ),
* ),
* 'headerOptions' => array(
* 'class' => 'my-class',
* ),
* 'clientOptions' => array(
* 'clientOptions' => array(
* 'collapsible' => false,
* 'collapsible' => false,
* ),
* ),
...
@@ -60,10 +66,52 @@ use yii\helpers\Html;
...
@@ -60,10 +66,52 @@ use yii\helpers\Html;
*/
*/
class
Tabs
extends
Widget
class
Tabs
extends
Widget
{
{
/**
* @var array the HTML attributes for the widget container tag. The following special options are recognized:
*
* - tag: string, defaults to "div", the tag name of the container tag of this widget
*/
public
$options
=
array
();
public
$options
=
array
();
/**
* @var array list of tab items. Each item can be an array of the following structure:
*
* ~~~
* array(
* 'label' => 'Tab header label',
* 'content' => 'Tab item content',
* 'ajax' => 'http://www.yiiframework.com', //or array('ajax/action'),
* // the HTML attributes of the item container tag. This will overwrite "itemOptions".
* 'options' => array(),
* // the HTML attributes of the header container tag. This will overwrite "headerOptions".
* 'headerOptions' = array(),
* // @todo comment.
* 'template'
* )
* ~~~
*/
public
$items
=
array
();
public
$items
=
array
();
/**
* @var array list of HTML attributes for the item container tags. This will be overwritten
* by the "options" set in individual [[items]]. The following special options are recognized:
*
* - tag: string, defaults to "div", the tag name of the item container tags.
*/
public
$itemOptions
=
array
();
public
$itemOptions
=
array
();
public
$headerTemplate
=
'<li><a href="{url}">{label}</a></li>'
;
/**
* @var array list of HTML attributes for the header container tags. This will be overwritten
* by the "headerOptions" set in individual [[items]].
*/
public
$headerOptions
=
array
();
/**
* @var string
* @todo comment.
*/
public
$linkTemplate
=
'<a href="{url}">{label}</a>'
;
/**
* @var boolean
* @todo comment.
*/
public
$encodeLabels
=
true
;
/**
/**
...
@@ -71,9 +119,11 @@ class Tabs extends Widget
...
@@ -71,9 +119,11 @@ class Tabs extends Widget
*/
*/
public
function
run
()
public
function
run
()
{
{
echo
Html
::
beginTag
(
'div'
,
$this
->
options
)
.
"
\n
"
;
$options
=
$this
->
options
;
$tag
=
ArrayHelper
::
remove
(
$options
,
'tag'
,
'div'
);
echo
Html
::
beginTag
(
$tag
,
$options
)
.
"
\n
"
;
echo
$this
->
renderItems
()
.
"
\n
"
;
echo
$this
->
renderItems
()
.
"
\n
"
;
echo
Html
::
endTag
(
'div'
)
.
"
\n
"
;
echo
Html
::
endTag
(
$tag
)
.
"
\n
"
;
$this
->
registerWidget
(
'tabs'
);
$this
->
registerWidget
(
'tabs'
);
}
}
...
@@ -81,26 +131,35 @@ class Tabs extends Widget
...
@@ -81,26 +131,35 @@ class Tabs extends Widget
* Renders tab items as specified on [[items]].
* Renders tab items as specified on [[items]].
* @return string the rendering result.
* @return string the rendering result.
* @throws InvalidConfigException.
* @throws InvalidConfigException.
* @todo rework
*/
*/
protected
function
renderItems
()
protected
function
renderItems
()
{
{
$headers
=
array
();
$headers
=
array
();
$items
=
array
();
$items
=
array
();
foreach
(
$this
->
items
as
$n
=>
$item
)
{
foreach
(
$this
->
items
as
$n
=>
$item
)
{
if
(
!
isset
(
$item
[
'
header
'
]))
{
if
(
!
isset
(
$item
[
'
label
'
]))
{
throw
new
InvalidConfigException
(
"The '
header
' option is required."
);
throw
new
InvalidConfigException
(
"The '
label
' option is required."
);
}
}
if
(
isset
(
$item
[
'ajax'
]))
{
$url
=
$item
[
'ajax'
];
}
else
{
if
(
!
isset
(
$item
[
'content'
]))
{
if
(
!
isset
(
$item
[
'content'
]))
{
throw
new
InvalidConfigException
(
"The 'content
' option is required."
);
throw
new
InvalidConfigException
(
"The 'content' or 'ajax
' option is required."
);
}
}
$options
=
ArrayHelper
::
getValue
(
$item
,
'options'
,
array
());
$options
=
array_merge
(
$this
->
itemOptions
,
ArrayHelper
::
getValue
(
$item
,
'options'
,
array
()));
$tag
=
ArrayHelper
::
remove
(
$options
,
'tag'
,
'div'
);
if
(
!
isset
(
$options
[
'id'
]))
{
if
(
!
isset
(
$options
[
'id'
]))
{
$options
[
'id'
]
=
$this
->
options
[
'id'
]
.
'-tab'
.
$n
;
$options
[
'id'
]
=
$this
->
options
[
'id'
]
.
'-tab'
.
$n
;
}
}
$url
=
'#'
.
$options
[
'id'
];
$items
[]
=
Html
::
tag
(
$tag
,
$item
[
'content'
],
$options
);
}
$headerOptions
=
ArrayHelper
::
getValue
(
$item
,
'headerOptions'
,
array
());
$headerOptions
=
ArrayHelper
::
getValue
(
$item
,
'headerOptions'
,
array
());
$headers
[]
=
Html
::
tag
(
'li'
,
Html
::
a
(
$item
[
'header'
],
'#'
.
$options
[
'id'
]),
$headerOptions
);
$template
=
ArrayHelper
::
getValue
(
$item
,
'template'
,
$this
->
linkTemplate
);
$items
[]
=
Html
::
tag
(
'div'
,
$item
[
'content'
],
$options
);
$headers
[]
=
Html
::
tag
(
'li'
,
strtr
(
$template
,
array
(
'{label}'
=>
$this
->
encodeLabels
?
Html
::
encode
(
$item
[
'label'
])
:
$item
[
'label'
],
'{url}'
=>
Html
::
url
(
$url
),
)),
$headerOptions
);
}
}
return
Html
::
tag
(
'ul'
,
implode
(
"
\n
"
,
$headers
))
.
"
\n
"
.
implode
(
"
\n
"
,
$items
);
return
Html
::
tag
(
'ul'
,
implode
(
"
\n
"
,
$headers
))
.
"
\n
"
.
implode
(
"
\n
"
,
$items
);
}
}
...
...
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