Skip to content

Commit 73d1c87

Browse files
first commit
0 parents  commit 73d1c87

File tree

9 files changed

+870
-0
lines changed

9 files changed

+870
-0
lines changed

MultiSelect.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
namespace muhiddin\select;
3+
4+
use yii\bootstrap\InputWidget;
5+
use yii\bootstrap\Html;
6+
use yii\helpers\Json;
7+
use yii\web\View;
8+
use muhiddin\select\MultiSelectAsset;
9+
10+
class MultiSelect extends InputWidget
11+
{
12+
public $data;
13+
public $id = 'multi-select';
14+
public $pluginOptions = '';
15+
public $selectAll = false;
16+
public $deselectAll = false;
17+
18+
public function run()
19+
{
20+
if (!isset($this->options['css'])) {
21+
$this->options['id'] = $this->id;
22+
}
23+
if ($this->selectAll)
24+
echo Html::a(\Yii::t('backend', 'select all'), '#', ['id' => $this->id . '-select-all']);
25+
26+
if ($this->deselectAll)
27+
echo Html::a(\Yii::t('backend', 'deselect all'), '#', ['id' => $this->id . '-deselect-all']);
28+
29+
MultiSelectAsset::register($this->getView());
30+
if (isset($this->model)) {
31+
$this->pluginOptions[] = $this->model->{$this->attribute};
32+
echo Html::activeDropDownList($this->model, $this->attribute, $this->data, $this->options);
33+
echo Html::error($this->model, $this->attribute);
34+
} else {
35+
$this->pluginOptions[] = $this->value;
36+
echo Html::dropDownList($this->name, $this->value, $this->data, $this->options);
37+
}
38+
39+
$this->registerJsScript();
40+
}
41+
42+
public function registerJsScript()
43+
{
44+
$this->pluginOptions[] = 'array';
45+
$pluginOptions = Json::encode($this->pluginOptions);
46+
$addJsScript = "";
47+
if ($this->selectAll)
48+
$addJsScript .= "
49+
$('#" . $this->id . "-select-all').click(function(){
50+
$('#" . $this->id . "').multiSelect('select_all');
51+
return false;
52+
});";
53+
if ($this->deselectAll)
54+
$addJsScript .= "
55+
$('#" . $this->id . "-deselect-all').click(function(){
56+
$('#" . $this->id . "').multiSelect('deselect_all');
57+
return false;
58+
});";
59+
60+
\Yii::$app->view->registerJs("
61+
$('#" . $this->id . "').multiSelect({$pluginOptions});
62+
" . $addJsScript, View::POS_END);
63+
}
64+
}

MultiSelectAsset.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* @link http://www.yiiframework.com/
4+
* @copyright Copyright (c) 2008 Yii Software LLC
5+
* @license http://www.yiiframework.com/license/
6+
*/
7+
8+
namespace muhiddin\select;
9+
10+
use yii\web\AssetBundle;
11+
12+
/**
13+
* @author Muhiddin Jumaniyazov <[email protected]>
14+
* @since 1.0
15+
*/
16+
class MultiSelectAsset extends AssetBundle
17+
{
18+
public $sourcePath = '@muhiddin/select/assets';
19+
20+
public $css = [
21+
'css/multi-select.css',
22+
];
23+
public $js = [
24+
'js/jquery.multi-select.js',
25+
];
26+
27+
public function init()
28+
{
29+
parent::init();
30+
$this->jsOptions['position'] = \yii\web\View::POS_END;
31+
}
32+
33+
}

assets/css/multi-select.css

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
.ms-container {
2+
background: transparent url('../img/switch.png') no-repeat 50% 50%;
3+
width: 80%;
4+
}
5+
6+
.ms-container:after {
7+
content: ".";
8+
display: block;
9+
height: 0;
10+
line-height: 0;
11+
font-size: 0;
12+
clear: both;
13+
min-height: 0;
14+
visibility: hidden;
15+
}
16+
17+
.ms-container .ms-selectable, .ms-container .ms-selection {
18+
background: #fff;
19+
color: #555555;
20+
float: left;
21+
width: 45%;
22+
}
23+
24+
.ms-container .ms-selection {
25+
float: right;
26+
}
27+
28+
.ms-container .ms-list {
29+
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
30+
-moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
31+
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
32+
-webkit-transition: border linear 0.2s, box-shadow linear 0.2s;
33+
-moz-transition: border linear 0.2s, box-shadow linear 0.2s;
34+
-ms-transition: border linear 0.2s, box-shadow linear 0.2s;
35+
-o-transition: border linear 0.2s, box-shadow linear 0.2s;
36+
transition: border linear 0.2s, box-shadow linear 0.2s;
37+
border: 1px solid #ccc;
38+
-webkit-border-radius: 3px;
39+
-moz-border-radius: 3px;
40+
border-radius: 3px;
41+
position: relative;
42+
height: 200px;
43+
padding: 0;
44+
overflow-y: auto;
45+
}
46+
47+
.ms-container .ms-list.ms-focus {
48+
border-color: rgba(82, 168, 236, 0.8);
49+
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(82, 168, 236, 0.6);
50+
-moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(82, 168, 236, 0.6);
51+
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(82, 168, 236, 0.6);
52+
outline: 0;
53+
outline: thin dotted \9;
54+
}
55+
56+
.ms-container ul {
57+
margin: 0;
58+
list-style-type: none;
59+
padding: 0;
60+
}
61+
62+
.ms-container .ms-optgroup-container {
63+
width: 100%;
64+
}
65+
66+
.ms-container .ms-optgroup-label {
67+
margin: 0;
68+
padding: 5px 0px 0px 5px;
69+
cursor: pointer;
70+
color: #999;
71+
}
72+
73+
.ms-container .ms-selectable li.ms-elem-selectable,
74+
.ms-container .ms-selection li.ms-elem-selection {
75+
border-bottom: 1px #eee solid;
76+
padding: 2px 10px;
77+
color: #555;
78+
font-size: 14px;
79+
}
80+
81+
.ms-container .ms-selectable li.ms-hover,
82+
.ms-container .ms-selection li.ms-hover {
83+
cursor: pointer;
84+
color: #fff;
85+
text-decoration: none;
86+
background-color: #08c;
87+
}
88+
89+
.ms-container .ms-selectable li.disabled,
90+
.ms-container .ms-selection li.disabled {
91+
background-color: #eee;
92+
color: #aaa;
93+
cursor: text;
94+
}

assets/css/multi-select.dev.css

Lines changed: 108 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/css/multi-select.dev.css.map

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/css/multi-select.dist.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/img/switch.png

540 Bytes
Loading

0 commit comments

Comments
 (0)