Skip to content

Commit

Permalink
Upgrade to release v3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Oct 8, 2014
1 parent 32e388a commit 6e09f54
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 55 deletions.
35 changes: 3 additions & 32 deletions Select2.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ protected function renderInput()
public function registerAssets()
{
$view = $this->getView();
$id = $this->options['id'];

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

// validate bootstrap has-success & has-error states
$js = <<< 'JS'
function() {
var $el = $(this), $drop = $("#select2-drop"), cssClasses;
$drop.removeClass("has-success has-error has-warning");
if ($el.parents("[class*='has-']").length) {
cssClasses = $el.parents("[class*='has-']")[0].className.split(/\s+/);
for (var i = 0; i < cssClasses.length; i++) {
if (cssClasses[i].match("has-")) {
$drop.addClass(cssClasses[i]);
}
}
}
}
JS;
$this->pluginEvents += ['select2-open' => $js];
$this->pluginEvents += ['select2-open' => "function(){initSelect2DropStyle('{$id}')}"];

// register plugin
if ($this->pluginLoading) {
$id = $this->options['id'];
$loading = "jQuery('.kv-plugin-loading.loading-{$id}')";
$groupCss = "group-{$id}";
$group = "jQuery('.kv-hide.{$groupCss}')";
$el = "jQuery('#{$id}')";
$callback = <<< JS
function(){
var \$container = {$el}.select2('container');
{$el}.removeClass('kv-hide');
\$container.removeClass('kv-hide');
{$loading}.remove();
if (Object.keys({$group}).length > 0) {
{$group}.removeClass('kv-hide').removeClass('{$groupCss}');
}
}
JS;
$this->registerPlugin('select2', $el, $callback);
$this->registerPlugin('select2', "jQuery('#{$id}')", "initSelect2Loading('{$id}')");
} else {
$this->registerPlugin('select2');
}
Expand Down
6 changes: 3 additions & 3 deletions Select2Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2013
* @package yii2-widgets
* @version 1.0.0
* @version 3.0.0
*/

namespace kartik\widgets;
Expand All @@ -22,8 +22,8 @@ class Select2Asset extends AssetBundle
public function init()
{
$this->setSourcePath(__DIR__ . '/lib/select2');
$this->setupAssets('css', ['select2', 'select2-bootstrap3']);
$this->setupAssets('js', ['select2']);
$this->setupAssets('css', ['select2', 'select2-kv']);
$this->setupAssets('js', ['select2', 'select2-kv']);
parent::init();
}
}
59 changes: 39 additions & 20 deletions lib/select2/select2-bootstrap3.css → lib/select2/select2-kv.css
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
padding: 0;
}

.select2-container .select2-choices .select2-search-field input, .select2-container .select2-choice, .select2-container .select2-choices {
.select2-container .select2-choices .select2-search-field input,
.select2-container .select2-choice,
.select2-container .select2-choices {
background: none repeat scroll 0 0 #FFFFFF;
border-color: #CCCCCC;
border-radius: 4px;
Expand Down Expand Up @@ -55,19 +57,21 @@

.select2-container-multi.input-sm .select2-choices .select2-search-field input,
.input-group-sm .select2-container-multi .select2-choices .select2-search-field input {
height: 28px;
height: 28px;
}

.select2-container-multi.input-lg .select2-choices .select2-search-field input,
.input-group-lg .select2-container-multi .select2-choices .select2-search-field input {
height: 44px;
height: 44px;
}

.select2-container-multi .select2-choices .select2-search-field input {
margin: 0;
}

.select2-chosen, .select2-choice > span:first-child, .select2-container .select2-choices .select2-search-field input {
.select2-chosen,
.select2-choice > span:first-child,
.select2-container .select2-choices .select2-search-field input {
padding: 6px 12px;
}

Expand All @@ -91,7 +95,8 @@
padding-bottom: 4px;
}

.select2-container-multi .select2-search-choice:hover, .select2-container .select2-search-choice:focus {
.select2-container-multi .select2-search-choice:hover,
.select2-container .select2-search-choice:focus {
background-color: #f5f5f5;
}

Expand All @@ -100,7 +105,8 @@
top: 50%;
}

.select2-container.input-sm, .select2-container-multi.input-sm {
.select2-container.input-sm,
.select2-container-multi.input-sm {
padding: 0;
}

Expand All @@ -114,7 +120,8 @@
line-height: 1.5;
}

.input-sm .select2-search-choice, .input-group-sm .select2-search-choice {
.input-sm .select2-search-choice,
.input-group-sm .select2-search-choice {
margin: 4px !important;
margin-right: 0 !important;
padding-top: 2.5px !important;
Expand All @@ -135,11 +142,11 @@
background-position: -18px 1px;
}

.select2-container.input-lg, .select2-container-multi.input-lg {
.select2-container.input-lg,
.select2-container-multi.input-lg {
padding: 0;
}


.select2-container.input-lg .select2-choice,
.input-group-lg .select2-choice,
.select2-container-multi.input-lg .select2-choices,
Expand All @@ -160,7 +167,8 @@
line-height: 2.05;
}

.input-lg .select2-search-choice, .input-group-lg .select2-search-choice {
.input-lg .select2-search-choice,
.input-group-lg .select2-search-choice {
margin-top: 10px!important;
}

Expand All @@ -186,21 +194,25 @@
margin-top: -5px;
}

.select2-container .select2-choice .select2-arrow, .select2-container .select2-choice div {
.select2-container .select2-choice .select2-arrow,
.select2-container .select2-choice div {
background: none repeat scroll 0 0 rgba(0, 0, 0, 0);
border-left: 1px solid #CCCCCC;
}

.select2-dropdown-open .select2-choice .select2-arrow, .select2-dropdown-open .select2-choice div {
.select2-dropdown-open .select2-choice .select2-arrow,
.select2-dropdown-open .select2-choice div {
background: none repeat scroll 0 0 rgba(0, 0, 0, 0);
border-left-color: rgba(0, 0, 0, 0);
}

.select2-container .select2-choice .select2-arrow b, .select2-container .select2-choice div b {
.select2-container .select2-choice .select2-arrow b,
.select2-container .select2-choice div b {
background-position: 0 3px;
}

.select2-dropdown-open .select2-choice .select2-arrow b, .select2-dropdown-open .select2-choice div b {
.select2-dropdown-open .select2-choice .select2-arrow b,
.select2-dropdown-open .select2-choice div b {
background-position: -18px 3px;
}

Expand All @@ -217,7 +229,8 @@
border-color: #66AFE9;
}

.select2-drop-auto-width, .select2-drop.select2-drop-above.select2-drop-active {
.select2-drop-auto-width,
.select2-drop.select2-drop-above.select2-drop-active {
border-top-color: #66AFE9;
}

Expand Down Expand Up @@ -273,12 +286,15 @@
top: 50%;
}

.select2-results .select2-no-results, .select2-results .select2-searching, .select2-results .select2-selection-limit {
.select2-results .select2-no-results,
.select2-results .select2-searching,
.select2-results .select2-selection-limit {
background-color: #FCF8E3;
color: #C09853;
}

.select2-container.select2-container-disabled .select2-choice, .select2-container.select2-container-disabled .select2-choices {
.select2-container.select2-container-disabled .select2-choice,
.select2-container.select2-container-disabled .select2-choices {
background-color: #EEEEEE;
border-color: #CCCCCC;
cursor: not-allowed;
Expand All @@ -298,7 +314,8 @@
background-position: right 4px center;
}

.has-warning .select2-choice, .has-warning .select2-choices {
.has-warning .select2-choice,
.has-warning .select2-choices {
border-color: #8a6d3b;
}

Expand All @@ -316,7 +333,8 @@
border-top-color: #66512c;
}

.has-error .select2-choice, .has-error .select2-choices {
.has-error .select2-choice,
.has-error .select2-choices {
border-color: #a94442;
}

Expand All @@ -334,7 +352,8 @@
border-top-color: #843534;
}

.has-success .select2-choice, .has-success .select2-choices {
.has-success .select2-choice,
.has-success .select2-choices {
border-color: #3c763d;
}

Expand Down
35 changes: 35 additions & 0 deletions lib/select2/select2-kv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*!
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014
* @version 3.0.0
*
* Additional enhancements for Select2 widget extension for Yii 2.0.
*
* Author: Kartik Visweswaran
* Copyright: 2014, Kartik Visweswaran, Krajee.com
* For more JQuery plugins visit http://plugins.krajee.com
* For more Yii related demos visit http://demos.krajee.com
*/
var initSelect2Loading = function (id) {
var $el = $('#' + id), groupCss = 'group-' + id, $group = $('.kv-hide.' + groupCss),
$container = $el.select2('container'),
$loading = $('.kv-plugin-loading.loading-' + id);
$el.removeClass('kv-hide');
$container.removeClass('kv-hide');
$loading.remove();
if (Object.keys($group).length > 0) {
$group.removeClass('kv-hide').removeClass(groupCss);
}
}

var initSelect2DropStyle = function (id) {
var $el = $('#' + id), $drop = $("#select2-drop"), cssClasses, i;
$drop.removeClass("has-success has-error has-warning");
if ($el.parents("[class*='has-']").length) {
cssClasses = $el.parents("[class*='has-']")[0].className.split(/\s+/);
for (i = 0; i < cssClasses.length; i++) {
if (cssClasses[i].match("has-")) {
$drop.addClass(cssClasses[i]);
}
}
}
}
File renamed without changes.
11 changes: 11 additions & 0 deletions lib/select2/select2-kv.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*!
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014
* @version 3.0.0
*
* Additional enhancements for Select2 widget extension for Yii 2.0.
*
* Author: Kartik Visweswaran
* Copyright: 2014, Kartik Visweswaran, Krajee.com
* For more JQuery plugins visit http://plugins.krajee.com
* For more Yii related demos visit http://demos.krajee.com
*/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 comments on commit 6e09f54

Please sign in to comment.