From 6e09f54dbaa4a596c65ea1087a3484bf282d2387 Mon Sep 17 00:00:00 2001 From: Kartik Visweswaran Date: Wed, 8 Oct 2014 08:36:57 +0530 Subject: [PATCH] Upgrade to release v3.0.0 --- Select2.php | 35 +---------- Select2Asset.php | 6 +- ...{select2-bootstrap3.css => select2-kv.css} | 59 ++++++++++++------- lib/select2/select2-kv.js | 35 +++++++++++ ...-bootstrap3.min.css => select2-kv.min.css} | 0 lib/select2/select2-kv.min.js | 11 ++++ 6 files changed, 91 insertions(+), 55 deletions(-) rename lib/select2/{select2-bootstrap3.css => select2-kv.css} (85%) mode change 100755 => 100644 create mode 100644 lib/select2/select2-kv.js rename lib/select2/{select2-bootstrap3.min.css => select2-kv.min.css} (100%) mode change 100755 => 100644 create mode 100644 lib/select2/select2-kv.min.js diff --git a/Select2.php b/Select2.php index b85e002..1a9a255 100644 --- a/Select2.php +++ b/Select2.php @@ -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') { @@ -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'); } diff --git a/Select2Asset.php b/Select2Asset.php index 7bb836f..b63d684 100644 --- a/Select2Asset.php +++ b/Select2Asset.php @@ -3,7 +3,7 @@ /** * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2013 * @package yii2-widgets - * @version 1.0.0 + * @version 3.0.0 */ namespace kartik\widgets; @@ -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(); } } diff --git a/lib/select2/select2-bootstrap3.css b/lib/select2/select2-kv.css old mode 100755 new mode 100644 similarity index 85% rename from lib/select2/select2-bootstrap3.css rename to lib/select2/select2-kv.css index 6bb53ec..8a98c48 --- a/lib/select2/select2-bootstrap3.css +++ b/lib/select2/select2-kv.css @@ -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; @@ -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; } @@ -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; } @@ -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; } @@ -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; @@ -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, @@ -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; } @@ -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; } @@ -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; } @@ -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; @@ -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; } @@ -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; } @@ -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; } diff --git a/lib/select2/select2-kv.js b/lib/select2/select2-kv.js new file mode 100644 index 0000000..6d628e4 --- /dev/null +++ b/lib/select2/select2-kv.js @@ -0,0 +1,35 @@ +/*! + * @copyright Copyright © 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]); + } + } + } +} \ No newline at end of file diff --git a/lib/select2/select2-bootstrap3.min.css b/lib/select2/select2-kv.min.css old mode 100755 new mode 100644 similarity index 100% rename from lib/select2/select2-bootstrap3.min.css rename to lib/select2/select2-kv.min.css diff --git a/lib/select2/select2-kv.min.js b/lib/select2/select2-kv.min.js new file mode 100644 index 0000000..b62fe4f --- /dev/null +++ b/lib/select2/select2-kv.min.js @@ -0,0 +1,11 @@ +/*! + * @copyright Copyright © 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