Skip to content

Commit 6e09f54

Browse files
committed
Upgrade to release v3.0.0
1 parent 32e388a commit 6e09f54

6 files changed

+91
-55
lines changed

Select2.php

+3-32
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ protected function renderInput()
176176
public function registerAssets()
177177
{
178178
$view = $this->getView();
179+
$id = $this->options['id'];
179180

180181
// set locale and language
181182
if (!empty($this->language) && substr($this->language, 0, 2) != 'en') {
@@ -188,41 +189,11 @@ public function registerAssets()
188189
$this->pluginOptions['width'] = 'resolve';
189190

190191
// validate bootstrap has-success & has-error states
191-
$js = <<< 'JS'
192-
function() {
193-
var $el = $(this), $drop = $("#select2-drop"), cssClasses;
194-
$drop.removeClass("has-success has-error has-warning");
195-
if ($el.parents("[class*='has-']").length) {
196-
cssClasses = $el.parents("[class*='has-']")[0].className.split(/\s+/);
197-
for (var i = 0; i < cssClasses.length; i++) {
198-
if (cssClasses[i].match("has-")) {
199-
$drop.addClass(cssClasses[i]);
200-
}
201-
}
202-
}
203-
}
204-
JS;
205-
$this->pluginEvents += ['select2-open' => $js];
192+
$this->pluginEvents += ['select2-open' => "function(){initSelect2DropStyle('{$id}')}"];
206193

207194
// register plugin
208195
if ($this->pluginLoading) {
209-
$id = $this->options['id'];
210-
$loading = "jQuery('.kv-plugin-loading.loading-{$id}')";
211-
$groupCss = "group-{$id}";
212-
$group = "jQuery('.kv-hide.{$groupCss}')";
213-
$el = "jQuery('#{$id}')";
214-
$callback = <<< JS
215-
function(){
216-
var \$container = {$el}.select2('container');
217-
{$el}.removeClass('kv-hide');
218-
\$container.removeClass('kv-hide');
219-
{$loading}.remove();
220-
if (Object.keys({$group}).length > 0) {
221-
{$group}.removeClass('kv-hide').removeClass('{$groupCss}');
222-
}
223-
}
224-
JS;
225-
$this->registerPlugin('select2', $el, $callback);
196+
$this->registerPlugin('select2', "jQuery('#{$id}')", "initSelect2Loading('{$id}')");
226197
} else {
227198
$this->registerPlugin('select2');
228199
}

Select2Asset.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2013
55
* @package yii2-widgets
6-
* @version 1.0.0
6+
* @version 3.0.0
77
*/
88

99
namespace kartik\widgets;
@@ -22,8 +22,8 @@ class Select2Asset extends AssetBundle
2222
public function init()
2323
{
2424
$this->setSourcePath(__DIR__ . '/lib/select2');
25-
$this->setupAssets('css', ['select2', 'select2-bootstrap3']);
26-
$this->setupAssets('js', ['select2']);
25+
$this->setupAssets('css', ['select2', 'select2-kv']);
26+
$this->setupAssets('js', ['select2', 'select2-kv']);
2727
parent::init();
2828
}
2929
}

lib/select2/select2-bootstrap3.css lib/select2/select2-kv.css

+39-20
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
padding: 0;
1818
}
1919

20-
.select2-container .select2-choices .select2-search-field input, .select2-container .select2-choice, .select2-container .select2-choices {
20+
.select2-container .select2-choices .select2-search-field input,
21+
.select2-container .select2-choice,
22+
.select2-container .select2-choices {
2123
background: none repeat scroll 0 0 #FFFFFF;
2224
border-color: #CCCCCC;
2325
border-radius: 4px;
@@ -55,19 +57,21 @@
5557

5658
.select2-container-multi.input-sm .select2-choices .select2-search-field input,
5759
.input-group-sm .select2-container-multi .select2-choices .select2-search-field input {
58-
height: 28px;
60+
height: 28px;
5961
}
6062

6163
.select2-container-multi.input-lg .select2-choices .select2-search-field input,
6264
.input-group-lg .select2-container-multi .select2-choices .select2-search-field input {
63-
height: 44px;
65+
height: 44px;
6466
}
6567

6668
.select2-container-multi .select2-choices .select2-search-field input {
6769
margin: 0;
6870
}
6971

70-
.select2-chosen, .select2-choice > span:first-child, .select2-container .select2-choices .select2-search-field input {
72+
.select2-chosen,
73+
.select2-choice > span:first-child,
74+
.select2-container .select2-choices .select2-search-field input {
7175
padding: 6px 12px;
7276
}
7377

@@ -91,7 +95,8 @@
9195
padding-bottom: 4px;
9296
}
9397

94-
.select2-container-multi .select2-search-choice:hover, .select2-container .select2-search-choice:focus {
98+
.select2-container-multi .select2-search-choice:hover,
99+
.select2-container .select2-search-choice:focus {
95100
background-color: #f5f5f5;
96101
}
97102

@@ -100,7 +105,8 @@
100105
top: 50%;
101106
}
102107

103-
.select2-container.input-sm, .select2-container-multi.input-sm {
108+
.select2-container.input-sm,
109+
.select2-container-multi.input-sm {
104110
padding: 0;
105111
}
106112

@@ -114,7 +120,8 @@
114120
line-height: 1.5;
115121
}
116122

117-
.input-sm .select2-search-choice, .input-group-sm .select2-search-choice {
123+
.input-sm .select2-search-choice,
124+
.input-group-sm .select2-search-choice {
118125
margin: 4px !important;
119126
margin-right: 0 !important;
120127
padding-top: 2.5px !important;
@@ -135,11 +142,11 @@
135142
background-position: -18px 1px;
136143
}
137144

138-
.select2-container.input-lg, .select2-container-multi.input-lg {
145+
.select2-container.input-lg,
146+
.select2-container-multi.input-lg {
139147
padding: 0;
140148
}
141149

142-
143150
.select2-container.input-lg .select2-choice,
144151
.input-group-lg .select2-choice,
145152
.select2-container-multi.input-lg .select2-choices,
@@ -160,7 +167,8 @@
160167
line-height: 2.05;
161168
}
162169

163-
.input-lg .select2-search-choice, .input-group-lg .select2-search-choice {
170+
.input-lg .select2-search-choice,
171+
.input-group-lg .select2-search-choice {
164172
margin-top: 10px!important;
165173
}
166174

@@ -186,21 +194,25 @@
186194
margin-top: -5px;
187195
}
188196

189-
.select2-container .select2-choice .select2-arrow, .select2-container .select2-choice div {
197+
.select2-container .select2-choice .select2-arrow,
198+
.select2-container .select2-choice div {
190199
background: none repeat scroll 0 0 rgba(0, 0, 0, 0);
191200
border-left: 1px solid #CCCCCC;
192201
}
193202

194-
.select2-dropdown-open .select2-choice .select2-arrow, .select2-dropdown-open .select2-choice div {
203+
.select2-dropdown-open .select2-choice .select2-arrow,
204+
.select2-dropdown-open .select2-choice div {
195205
background: none repeat scroll 0 0 rgba(0, 0, 0, 0);
196206
border-left-color: rgba(0, 0, 0, 0);
197207
}
198208

199-
.select2-container .select2-choice .select2-arrow b, .select2-container .select2-choice div b {
209+
.select2-container .select2-choice .select2-arrow b,
210+
.select2-container .select2-choice div b {
200211
background-position: 0 3px;
201212
}
202213

203-
.select2-dropdown-open .select2-choice .select2-arrow b, .select2-dropdown-open .select2-choice div b {
214+
.select2-dropdown-open .select2-choice .select2-arrow b,
215+
.select2-dropdown-open .select2-choice div b {
204216
background-position: -18px 3px;
205217
}
206218

@@ -217,7 +229,8 @@
217229
border-color: #66AFE9;
218230
}
219231

220-
.select2-drop-auto-width, .select2-drop.select2-drop-above.select2-drop-active {
232+
.select2-drop-auto-width,
233+
.select2-drop.select2-drop-above.select2-drop-active {
221234
border-top-color: #66AFE9;
222235
}
223236

@@ -273,12 +286,15 @@
273286
top: 50%;
274287
}
275288

276-
.select2-results .select2-no-results, .select2-results .select2-searching, .select2-results .select2-selection-limit {
289+
.select2-results .select2-no-results,
290+
.select2-results .select2-searching,
291+
.select2-results .select2-selection-limit {
277292
background-color: #FCF8E3;
278293
color: #C09853;
279294
}
280295

281-
.select2-container.select2-container-disabled .select2-choice, .select2-container.select2-container-disabled .select2-choices {
296+
.select2-container.select2-container-disabled .select2-choice,
297+
.select2-container.select2-container-disabled .select2-choices {
282298
background-color: #EEEEEE;
283299
border-color: #CCCCCC;
284300
cursor: not-allowed;
@@ -298,7 +314,8 @@
298314
background-position: right 4px center;
299315
}
300316

301-
.has-warning .select2-choice, .has-warning .select2-choices {
317+
.has-warning .select2-choice,
318+
.has-warning .select2-choices {
302319
border-color: #8a6d3b;
303320
}
304321

@@ -316,7 +333,8 @@
316333
border-top-color: #66512c;
317334
}
318335

319-
.has-error .select2-choice, .has-error .select2-choices {
336+
.has-error .select2-choice,
337+
.has-error .select2-choices {
320338
border-color: #a94442;
321339
}
322340

@@ -334,7 +352,8 @@
334352
border-top-color: #843534;
335353
}
336354

337-
.has-success .select2-choice, .has-success .select2-choices {
355+
.has-success .select2-choice,
356+
.has-success .select2-choices {
338357
border-color: #3c763d;
339358
}
340359

lib/select2/select2-kv.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*!
2+
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014
3+
* @version 3.0.0
4+
*
5+
* Additional enhancements for Select2 widget extension for Yii 2.0.
6+
*
7+
* Author: Kartik Visweswaran
8+
* Copyright: 2014, Kartik Visweswaran, Krajee.com
9+
* For more JQuery plugins visit http://plugins.krajee.com
10+
* For more Yii related demos visit http://demos.krajee.com
11+
*/
12+
var initSelect2Loading = function (id) {
13+
var $el = $('#' + id), groupCss = 'group-' + id, $group = $('.kv-hide.' + groupCss),
14+
$container = $el.select2('container'),
15+
$loading = $('.kv-plugin-loading.loading-' + id);
16+
$el.removeClass('kv-hide');
17+
$container.removeClass('kv-hide');
18+
$loading.remove();
19+
if (Object.keys($group).length > 0) {
20+
$group.removeClass('kv-hide').removeClass(groupCss);
21+
}
22+
}
23+
24+
var initSelect2DropStyle = function (id) {
25+
var $el = $('#' + id), $drop = $("#select2-drop"), cssClasses, i;
26+
$drop.removeClass("has-success has-error has-warning");
27+
if ($el.parents("[class*='has-']").length) {
28+
cssClasses = $el.parents("[class*='has-']")[0].className.split(/\s+/);
29+
for (i = 0; i < cssClasses.length; i++) {
30+
if (cssClasses[i].match("has-")) {
31+
$drop.addClass(cssClasses[i]);
32+
}
33+
}
34+
}
35+
}
File renamed without changes.

lib/select2/select2-kv.min.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*!
2+
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014
3+
* @version 3.0.0
4+
*
5+
* Additional enhancements for Select2 widget extension for Yii 2.0.
6+
*
7+
* Author: Kartik Visweswaran
8+
* Copyright: 2014, Kartik Visweswaran, Krajee.com
9+
* For more JQuery plugins visit http://plugins.krajee.com
10+
* For more Yii related demos visit http://demos.krajee.com
11+
*/var initSelect2Loading=function(e){var s=$("#"+e),a="group-"+e,l=$(".kv-hide."+a),r=s.select2("container"),n=$(".kv-plugin-loading.loading-"+e);s.removeClass("kv-hide"),r.removeClass("kv-hide"),n.remove(),Object.keys(l).length>0&&l.removeClass("kv-hide").removeClass(a)},initSelect2DropStyle=function(e){var s,a,l=$("#"+e),r=$("#select2-drop");if(r.removeClass("has-success has-error has-warning"),l.parents("[class*='has-']").length)for(s=l.parents("[class*='has-']")[0].className.split(/\s+/),a=0;a<s.length;a++)s[a].match("has-")&&r.addClass(s[a])};

0 commit comments

Comments
 (0)