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
a834e104
Commit
a834e104
authored
May 26, 2013
by
Alexander Kochetov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sortable rework
parent
c52d4a2e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
16 deletions
+44
-16
Sortable.php
framework/yii/jui/Sortable.php
+44
-16
No files found.
framework/yii/jui/Sortable.php
View file @
a834e104
...
...
@@ -7,6 +7,8 @@
namespace
yii\jui
;
use
yii\base\InvalidConfigException
;
use
yii\helpers\ArrayHelper
;
use
yii\helpers\Html
;
/**
...
...
@@ -17,9 +19,9 @@ use yii\helpers\Html;
* ```php
* echo Sortable::widget(array(
* 'items' => array(
* '
<li>Item 1</li>
',
* '
<li>Item 2</li>
',
* '
<li>Item 3</li>
',
* '
Item 1
',
* '
Item 2
',
* '
Item 3
',
* ),
* 'clientOptions' => array(
* 'cursor' => 'move',
...
...
@@ -32,17 +34,20 @@ use yii\helpers\Html;
*
* ```php
* Sortable::begin(array(
* 'clientOptions' => array(
* 'cursor' => 'move',
* ),
* 'options' => array(
* 'tag' => 'div',
* ),
* 'itemOptions' => array(
* 'tag' => 'div',
* ),
* 'clientOptions' => array(
* 'cursor' => 'move',
* ),
* ));
*
* echo '
<div>Item 1</div>
';
* echo '
<div>Item 2</div>
';
* echo '
<div>Item 3</div>
';
* echo '
Item 1
';
* echo '
Item 2
';
* echo '
Item 3
';
*
* Sortable::end();
* ```
...
...
@@ -54,10 +59,15 @@ use yii\helpers\Html;
class
Sortable
extends
Widget
{
/**
* @var array
list of sortable containers. Each array element represents a single
*
sortable container.
* @var array
.
*
@todo comments
*/
public
$items
=
array
();
/**
* @var array.
* @todo comments
*/
public
$itemOptions
=
array
();
/**
...
...
@@ -67,8 +77,7 @@ class Sortable extends Widget
{
parent
::
init
();
$options
=
$this
->
options
;
$tag
=
isset
(
$options
[
'tag'
])
?
$options
[
'tag'
]
:
'ul'
;
unset
(
$options
[
'tag'
]);
$tag
=
ArrayHelper
::
remove
(
$options
,
'tag'
,
'ul'
);
echo
Html
::
beginTag
(
$tag
,
$options
)
.
"
\n
"
;
}
...
...
@@ -78,16 +87,35 @@ class Sortable extends Widget
public
function
run
()
{
echo
$this
->
renderItems
()
.
"
\n
"
;
echo
Html
::
endTag
(
isset
(
$this
->
options
[
'tag'
])
?
$this
->
options
[
'tag'
]
:
'ul'
)
.
"
\n
"
;
$tag
=
ArrayHelper
::
getValue
(
$this
->
options
,
'tag'
,
'ul'
);
echo
Html
::
endTag
(
$tag
)
.
"
\n
"
;
$this
->
registerWidget
(
'sortable'
,
false
);
}
/**
* Renders sortable items as specified on [[items]].
* @return string the rendering result
* @return string the rendering result.
* @throws InvalidConfigException.
*/
public
function
renderItems
()
{
return
implode
(
"
\n
"
,
$this
->
items
);
$items
=
array
();
foreach
(
$this
->
items
as
$item
)
{
$options
=
$this
->
itemOptions
;
$tag
=
ArrayHelper
::
remove
(
$options
,
'tag'
,
'li'
);
if
(
is_array
(
$item
))
{
if
(
!
isset
(
$item
[
'content'
]))
{
throw
new
InvalidConfigException
(
"The 'content' option is required."
);
}
if
(
isset
(
$item
[
'options'
]))
{
$options
=
array_merge
(
$options
,
$item
[
'options'
]);
$tag
=
ArrayHelper
::
remove
(
$options
,
'tag'
,
$tag
);
}
$items
[]
=
Html
::
tag
(
$tag
,
$item
[
'content'
],
$options
);
}
else
{
$items
[]
=
Html
::
tag
(
$tag
,
$item
,
$options
);
}
}
return
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