From 7d80d6e2598e252487fe1acf911b8cb43f45e3b1 Mon Sep 17 00:00:00 2001 From: Kartik Visweswaran Date: Wed, 1 Sep 2021 17:46:39 +0530 Subject: [PATCH] Fix #163: Enhancements to support Bootstrap v5.x --- CHANGE.md | 7 +- LICENSE.md | 2 +- composer.json | 2 +- src/DateRangeBehavior.php | 2 +- src/DateRangePicker.php | 80 +++++++++++++---------- src/DateRangePickerAsset.php | 2 +- src/LanguageAsset.php | 2 +- src/MomentAsset.php | 2 +- src/assets/css/daterangepicker-kv.css | 2 +- src/assets/css/daterangepicker-kv.min.css | 2 +- src/assets/css/daterangepicker.css | 2 +- src/assets/css/daterangepicker.min.css | 2 +- 12 files changed, 62 insertions(+), 45 deletions(-) diff --git a/CHANGE.md b/CHANGE.md index 9bb8a2e..8b48377 100644 --- a/CHANGE.md +++ b/CHANGE.md @@ -3,8 +3,13 @@ Change Log: `yii2-date-range` ## Version 1.7.3 -**Date:** _under development_ +**Date:** 01-Sep-2021 +- (enh #163): Enhancements to support Bootstrap v5.x. +- (enh #162): Update Uzbek Translations. +- (enh #156): Update Greek Translations. +- (enh #155): Update Indonesian Translations. +- (enh #154): Update Kazakh Translations. - (enh #150): Add following properties to DateRangePicker (applicable only when `presetDropdown` is `true`). - `includeDaysFilter` : _bool_ defaults to `true` - `presetFilterDays` : _array_ defaults to `[7, 30]` diff --git a/LICENSE.md b/LICENSE.md index a0accb3..8de2366 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2015 - 2020, Kartik Visweswaran +Copyright (c) 2015 - 2021, Kartik Visweswaran Krajee.com All rights reserved. diff --git a/composer.json b/composer.json index cc169ad..8267f93 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ } ], "require": { - "kartik-v/yii2-krajee-base": ">=2.0.0" + "kartik-v/yii2-krajee-base": ">=3.0.0" }, "autoload": { "psr-4": { diff --git a/src/DateRangeBehavior.php b/src/DateRangeBehavior.php index bb1f0bc..01fe4b5 100644 --- a/src/DateRangeBehavior.php +++ b/src/DateRangeBehavior.php @@ -1,7 +1,7 @@ 'X', ]; + return strtr($format, $conversions); } /** * Parses and returns a JsExpression * - * @param string|JsExpression $value + * @param string|JsExpression $value * * @return JsExpression */ @@ -277,7 +280,7 @@ protected static function parseJsExpr($value) /** * @inheritdoc * @throws InvalidConfigException - * @throws \ReflectionException + * @throws ReflectionException */ public function run() { @@ -292,10 +295,10 @@ public function registerAssets() { $view = $this->getView(); MomentAsset::register($view); - $input = 'jQuery("#' . $this->options['id'] . '")'; + $input = 'jQuery("#'.$this->options['id'].'")'; $id = $input; if ($this->hideInput) { - $id = 'jQuery("#' . $this->containerOptions['id'] . '")'; + $id = 'jQuery("#'.$this->containerOptions['id'].'")'; } if (!empty($this->_langFile)) { LanguageAsset::register($view)->js[] = $this->_langFile; @@ -307,7 +310,7 @@ public function registerAssets() if (ArrayHelper::getValue($this->pluginOptions, 'singleDatePicker', false)) { $val = "start.format('{$this->_format}')"; } - $rangeJs = $this->getRangeJs('start') . $this->getRangeJs('end'); + $rangeJs = $this->getRangeJs('start').$this->getRangeJs('end'); $change = "{$input}.val(val).trigger('change');{$rangeJs}"; if ($this->presetDropdown) { $id = "{$id}.find('.kv-drp-dropdown')"; @@ -321,6 +324,7 @@ public function registerAssets() $script = "var val={$val};{$change}"; } else { $this->registerPlugin($this->pluginName, $id); + return; } $this->callback = "function(start,end,label){{$script}}"; @@ -368,18 +372,18 @@ public function registerAssets() * Initializes widget settings * * @throws InvalidConfigException - * @throws \ReflectionException + * @throws ReflectionException */ protected function initSettings() { - $isBs4 = $this->isBs4(); + $notBs3 = !$this->isBs(3); $this->_msgCat = 'kvdrp'; if (!isset($this->pickerIcon)) { - $iconCss = $isBs4 ? 'fas fa-calendar-alt' : 'glyphicon glyphicon-calendar'; + $iconCss = $notBs3 ? 'fas fa-calendar-alt' : 'glyphicon glyphicon-calendar'; $this->pickerIcon = Html::tag('i', '', ['class' => $iconCss]); } if (!isset($this->pluginOptions['cancelButtonClasses'])) { - $this->pluginOptions['cancelButtonClasses'] = $isBs4 ? 'btn-secondary' : 'btn-default'; + $this->pluginOptions['cancelButtonClasses'] = $notBs3 ? 'btn-secondary' : 'btn-default'; } $this->initI18N(__DIR__); $this->initLocale(); @@ -405,7 +409,7 @@ protected function initSettings() if ($this->startAttribute && $this->endAttribute) { $start = $this->getRangeValue('start'); $end = $this->getRangeValue('end'); - $this->value = $start . $this->_separator . $end; + $this->value = $start.$this->_separator.$end; if ($this->hasModel()) { $attr = Html::getAttributeName($this->attribute); $this->model->$attr = $this->value; @@ -415,7 +419,7 @@ protected function initSettings() } } $this->containerTemplate = strtr($this->containerTemplate, [ - '{value}' => isset($this->value) ? $this->value : '', + '{value}' => $this->value ?? '', '{pickerIcon}' => $this->pickerIcon, ]); // Set `autoUpdateInput` to false for certain settings @@ -425,11 +429,11 @@ protected function initSettings() $this->_startInput = $this->getRangeInput('start'); $this->_endInput = $this->getRangeInput('end'); if (empty($this->containerOptions['id'])) { - $this->containerOptions['id'] = $this->options['id'] . '-container'; + $this->containerOptions['id'] = $this->options['id'].'-container'; } if (empty($this->containerOptions['class'])) { $css = $this->useWithAddon && !$this->presetDropdown && !$this->hideInput ? ' input-group' : ''; - $this->containerOptions['class'] = 'kv-drp-container' . $css; + $this->containerOptions['class'] = 'kv-drp-container'.$css; } $this->initRange(); $this->registerAssets(); @@ -437,7 +441,7 @@ protected function initSettings() /** * Initialize locale settings - * @throws \ReflectionException + * @throws ReflectionException|Exception */ protected function initLocale() { @@ -534,37 +538,39 @@ protected function initRange() */ protected function renderInput() { - $append = $this->_startInput . $this->_endInput; + $append = $this->_startInput.$this->_endInput; if (!$this->hideInput) { - return $this->getInput('textInput') . $append; + return $this->getInput('textInput').$append; } - $content = str_replace('{input}', $this->getInput('hiddenInput') . $append, $this->containerTemplate); + $content = str_replace('{input}', $this->getInput('hiddenInput').$append, $this->containerTemplate); $tag = ArrayHelper::remove($this->containerOptions, 'tag', 'div'); + return Html::tag($tag, $content, $this->containerOptions); } /** * Gets input options based on type * - * @param string $type whether `start` or `end` + * @param string $type whether `start` or `end` * * @return array|mixed */ protected function getInputOpts($type = '') { - $opts = $type . 'InputOptions'; + $opts = $type.'InputOptions'; + return isset($this->$opts) && is_array($this->$opts) ? $this->$opts : []; } /** * Sets input options for a specific type * - * @param string $type whether `start` or `end` - * @param array $options the options to set + * @param string $type whether `start` or `end` + * @param array $options the options to set */ protected function setInputOpts($type = '', $options = []) { - $opts = $type . 'InputOptions'; + $opts = $type.'InputOptions'; if (property_exists($this, $opts)) { $this->$opts = $options; } @@ -573,20 +579,21 @@ protected function setInputOpts($type = '', $options = []) /** * Gets the range attribute value based on type * - * @param string $type whether `start` or `end` + * @param string $type whether `start` or `end` * * @return mixed|string */ protected function getRangeAttr($type = '') { - $attr = $type . 'Attribute'; + $attr = $type.'Attribute'; + return $type && isset($this->$attr) ? $this->$attr : ''; } /** * Generates and returns the client script on date range change, when the start and end attributes are set * - * @param string $type whether `start` or `end` + * @param string $type whether `start` or `end` * * @return string */ @@ -597,15 +604,16 @@ protected function getRangeJs($type = '') return ''; } $options = $this->getInputOpts($type); - $input = "jQuery('#" . $this->options['id'] . "')"; - return "var v={$input}.val() ? {$type}.format('{$this->_format}') : '';jQuery('#" . $options['id'] . + $input = "jQuery('#".$this->options['id']."')"; + + return "var v={$input}.val() ? {$type}.format('{$this->_format}') : '';jQuery('#".$options['id']. "').val(v).trigger('change');"; } /** * Generates and returns the hidden input markup when one of start or end attributes are set. * - * @param string $type whether `start` or `end` + * @param string $type whether `start` or `end` * * @return string */ @@ -617,23 +625,25 @@ protected function getRangeInput($type = '') } $options = $this->getInputOpts($type); if (empty($options['id'])) { - $options['id'] = $this->options['id'] . '-' . $type; + $options['id'] = $this->options['id'].'-'.$type; } if ($this->hasModel()) { $this->setInputOpts($type, $options); + return Html::activeHiddenInput($this->model, $attr, $options); } $options['type'] = 'hidden'; $options['name'] = $attr; $this->setInputOpts($type, $options); + return Html::tag('input', '', $options); } /** * Initializes the range values when one of start or end attributes are set. * - * @param string $type whether `start` or `end` - * @param string $value the value to set + * @param string $type whether `start` or `end` + * @param string $value the value to set */ protected function initRangeValue($type = '', $value = '') { @@ -653,9 +663,10 @@ protected function initRangeValue($type = '', $value = '') /** * Generates and returns the hidden input markup when one of start or end attributes are set. * - * @param string $type whether `start` or `end` + * @param string $type whether `start` or `end` * * @return string + * @throws Exception */ protected function getRangeValue($type = '') { @@ -664,6 +675,7 @@ protected function getRangeValue($type = '') return ''; } $options = $this->getInputOpts($type); + return $this->hasModel() ? Html::getAttributeValue($this->model, $attr) : ArrayHelper::getValue($options, 'value', ''); } diff --git a/src/DateRangePickerAsset.php b/src/DateRangePickerAsset.php index 0234c41..bdc4bfe 100644 --- a/src/DateRangePickerAsset.php +++ b/src/DateRangePickerAsset.php @@ -1,7 +1,7 @@