Skip to content

Commit 7d80d6e

Browse files
committed
Fix #163: Enhancements to support Bootstrap v5.x
1 parent 66f9abb commit 7d80d6e

12 files changed

+62
-45
lines changed

CHANGE.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ Change Log: `yii2-date-range`
33

44
## Version 1.7.3
55

6-
**Date:** _under development_
6+
**Date:** 01-Sep-2021
77

8+
- (enh #163): Enhancements to support Bootstrap v5.x.
9+
- (enh #162): Update Uzbek Translations.
10+
- (enh #156): Update Greek Translations.
11+
- (enh #155): Update Indonesian Translations.
12+
- (enh #154): Update Kazakh Translations.
813
- (enh #150): Add following properties to DateRangePicker (applicable only when `presetDropdown` is `true`).
914
- `includeDaysFilter` : _bool_ defaults to `true`
1015
- `presetFilterDays` : _array_ defaults to `[7, 30]`

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2015 - 2020, Kartik Visweswaran
1+
Copyright (c) 2015 - 2021, Kartik Visweswaran
22
Krajee.com
33
All rights reserved.
44

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
}
2424
],
2525
"require": {
26-
"kartik-v/yii2-krajee-base": ">=2.0.0"
26+
"kartik-v/yii2-krajee-base": ">=3.0.0"
2727
},
2828
"autoload": {
2929
"psr-4": {

src/DateRangeBehavior.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2020
4+
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2021
55
* @package yii2-date-range
66
* @version 1.7.3
77
*/

src/DateRangePicker.php

+46-34
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
<?php
22

33
/**
4-
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2020
4+
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2021
55
* @package yii2-date-range
66
* @version 1.7.3
77
*/
88

99
namespace kartik\daterange;
1010

11+
use Exception;
1112
use kartik\base\InputWidget;
13+
use ReflectionException;
1214
use Yii;
1315
use yii\base\InvalidConfigException;
1416
use yii\helpers\ArrayHelper;
@@ -209,7 +211,7 @@ class DateRangePicker extends InputWidget
209211
* @see http://php.net/manual/en/function.date.php
210212
* @see http://momentjs.com/docs/#/parsing/string-format/
211213
*
212-
* @param string $format the PHP date format string
214+
* @param string $format the PHP date format string
213215
*
214216
* @return string
215217
*/
@@ -259,13 +261,14 @@ protected static function convertDateFormat($format)
259261
// unix timestamp
260262
'U' => 'X',
261263
];
264+
262265
return strtr($format, $conversions);
263266
}
264267

265268
/**
266269
* Parses and returns a JsExpression
267270
*
268-
* @param string|JsExpression $value
271+
* @param string|JsExpression $value
269272
*
270273
* @return JsExpression
271274
*/
@@ -277,7 +280,7 @@ protected static function parseJsExpr($value)
277280
/**
278281
* @inheritdoc
279282
* @throws InvalidConfigException
280-
* @throws \ReflectionException
283+
* @throws ReflectionException
281284
*/
282285
public function run()
283286
{
@@ -292,10 +295,10 @@ public function registerAssets()
292295
{
293296
$view = $this->getView();
294297
MomentAsset::register($view);
295-
$input = 'jQuery("#' . $this->options['id'] . '")';
298+
$input = 'jQuery("#'.$this->options['id'].'")';
296299
$id = $input;
297300
if ($this->hideInput) {
298-
$id = 'jQuery("#' . $this->containerOptions['id'] . '")';
301+
$id = 'jQuery("#'.$this->containerOptions['id'].'")';
299302
}
300303
if (!empty($this->_langFile)) {
301304
LanguageAsset::register($view)->js[] = $this->_langFile;
@@ -307,7 +310,7 @@ public function registerAssets()
307310
if (ArrayHelper::getValue($this->pluginOptions, 'singleDatePicker', false)) {
308311
$val = "start.format('{$this->_format}')";
309312
}
310-
$rangeJs = $this->getRangeJs('start') . $this->getRangeJs('end');
313+
$rangeJs = $this->getRangeJs('start').$this->getRangeJs('end');
311314
$change = "{$input}.val(val).trigger('change');{$rangeJs}";
312315
if ($this->presetDropdown) {
313316
$id = "{$id}.find('.kv-drp-dropdown')";
@@ -321,6 +324,7 @@ public function registerAssets()
321324
$script = "var val={$val};{$change}";
322325
} else {
323326
$this->registerPlugin($this->pluginName, $id);
327+
324328
return;
325329
}
326330
$this->callback = "function(start,end,label){{$script}}";
@@ -368,18 +372,18 @@ public function registerAssets()
368372
* Initializes widget settings
369373
*
370374
* @throws InvalidConfigException
371-
* @throws \ReflectionException
375+
* @throws ReflectionException
372376
*/
373377
protected function initSettings()
374378
{
375-
$isBs4 = $this->isBs4();
379+
$notBs3 = !$this->isBs(3);
376380
$this->_msgCat = 'kvdrp';
377381
if (!isset($this->pickerIcon)) {
378-
$iconCss = $isBs4 ? 'fas fa-calendar-alt' : 'glyphicon glyphicon-calendar';
382+
$iconCss = $notBs3 ? 'fas fa-calendar-alt' : 'glyphicon glyphicon-calendar';
379383
$this->pickerIcon = Html::tag('i', '', ['class' => $iconCss]);
380384
}
381385
if (!isset($this->pluginOptions['cancelButtonClasses'])) {
382-
$this->pluginOptions['cancelButtonClasses'] = $isBs4 ? 'btn-secondary' : 'btn-default';
386+
$this->pluginOptions['cancelButtonClasses'] = $notBs3 ? 'btn-secondary' : 'btn-default';
383387
}
384388
$this->initI18N(__DIR__);
385389
$this->initLocale();
@@ -405,7 +409,7 @@ protected function initSettings()
405409
if ($this->startAttribute && $this->endAttribute) {
406410
$start = $this->getRangeValue('start');
407411
$end = $this->getRangeValue('end');
408-
$this->value = $start . $this->_separator . $end;
412+
$this->value = $start.$this->_separator.$end;
409413
if ($this->hasModel()) {
410414
$attr = Html::getAttributeName($this->attribute);
411415
$this->model->$attr = $this->value;
@@ -415,7 +419,7 @@ protected function initSettings()
415419
}
416420
}
417421
$this->containerTemplate = strtr($this->containerTemplate, [
418-
'{value}' => isset($this->value) ? $this->value : '',
422+
'{value}' => $this->value ?? '',
419423
'{pickerIcon}' => $this->pickerIcon,
420424
]);
421425
// Set `autoUpdateInput` to false for certain settings
@@ -425,19 +429,19 @@ protected function initSettings()
425429
$this->_startInput = $this->getRangeInput('start');
426430
$this->_endInput = $this->getRangeInput('end');
427431
if (empty($this->containerOptions['id'])) {
428-
$this->containerOptions['id'] = $this->options['id'] . '-container';
432+
$this->containerOptions['id'] = $this->options['id'].'-container';
429433
}
430434
if (empty($this->containerOptions['class'])) {
431435
$css = $this->useWithAddon && !$this->presetDropdown && !$this->hideInput ? ' input-group' : '';
432-
$this->containerOptions['class'] = 'kv-drp-container' . $css;
436+
$this->containerOptions['class'] = 'kv-drp-container'.$css;
433437
}
434438
$this->initRange();
435439
$this->registerAssets();
436440
}
437441

438442
/**
439443
* Initialize locale settings
440-
* @throws \ReflectionException
444+
* @throws ReflectionException|Exception
441445
*/
442446
protected function initLocale()
443447
{
@@ -534,37 +538,39 @@ protected function initRange()
534538
*/
535539
protected function renderInput()
536540
{
537-
$append = $this->_startInput . $this->_endInput;
541+
$append = $this->_startInput.$this->_endInput;
538542
if (!$this->hideInput) {
539-
return $this->getInput('textInput') . $append;
543+
return $this->getInput('textInput').$append;
540544
}
541-
$content = str_replace('{input}', $this->getInput('hiddenInput') . $append, $this->containerTemplate);
545+
$content = str_replace('{input}', $this->getInput('hiddenInput').$append, $this->containerTemplate);
542546
$tag = ArrayHelper::remove($this->containerOptions, 'tag', 'div');
547+
543548
return Html::tag($tag, $content, $this->containerOptions);
544549
}
545550

546551
/**
547552
* Gets input options based on type
548553
*
549-
* @param string $type whether `start` or `end`
554+
* @param string $type whether `start` or `end`
550555
*
551556
* @return array|mixed
552557
*/
553558
protected function getInputOpts($type = '')
554559
{
555-
$opts = $type . 'InputOptions';
560+
$opts = $type.'InputOptions';
561+
556562
return isset($this->$opts) && is_array($this->$opts) ? $this->$opts : [];
557563
}
558564

559565
/**
560566
* Sets input options for a specific type
561567
*
562-
* @param string $type whether `start` or `end`
563-
* @param array $options the options to set
568+
* @param string $type whether `start` or `end`
569+
* @param array $options the options to set
564570
*/
565571
protected function setInputOpts($type = '', $options = [])
566572
{
567-
$opts = $type . 'InputOptions';
573+
$opts = $type.'InputOptions';
568574
if (property_exists($this, $opts)) {
569575
$this->$opts = $options;
570576
}
@@ -573,20 +579,21 @@ protected function setInputOpts($type = '', $options = [])
573579
/**
574580
* Gets the range attribute value based on type
575581
*
576-
* @param string $type whether `start` or `end`
582+
* @param string $type whether `start` or `end`
577583
*
578584
* @return mixed|string
579585
*/
580586
protected function getRangeAttr($type = '')
581587
{
582-
$attr = $type . 'Attribute';
588+
$attr = $type.'Attribute';
589+
583590
return $type && isset($this->$attr) ? $this->$attr : '';
584591
}
585592

586593
/**
587594
* Generates and returns the client script on date range change, when the start and end attributes are set
588595
*
589-
* @param string $type whether `start` or `end`
596+
* @param string $type whether `start` or `end`
590597
*
591598
* @return string
592599
*/
@@ -597,15 +604,16 @@ protected function getRangeJs($type = '')
597604
return '';
598605
}
599606
$options = $this->getInputOpts($type);
600-
$input = "jQuery('#" . $this->options['id'] . "')";
601-
return "var v={$input}.val() ? {$type}.format('{$this->_format}') : '';jQuery('#" . $options['id'] .
607+
$input = "jQuery('#".$this->options['id']."')";
608+
609+
return "var v={$input}.val() ? {$type}.format('{$this->_format}') : '';jQuery('#".$options['id'].
602610
"').val(v).trigger('change');";
603611
}
604612

605613
/**
606614
* Generates and returns the hidden input markup when one of start or end attributes are set.
607615
*
608-
* @param string $type whether `start` or `end`
616+
* @param string $type whether `start` or `end`
609617
*
610618
* @return string
611619
*/
@@ -617,23 +625,25 @@ protected function getRangeInput($type = '')
617625
}
618626
$options = $this->getInputOpts($type);
619627
if (empty($options['id'])) {
620-
$options['id'] = $this->options['id'] . '-' . $type;
628+
$options['id'] = $this->options['id'].'-'.$type;
621629
}
622630
if ($this->hasModel()) {
623631
$this->setInputOpts($type, $options);
632+
624633
return Html::activeHiddenInput($this->model, $attr, $options);
625634
}
626635
$options['type'] = 'hidden';
627636
$options['name'] = $attr;
628637
$this->setInputOpts($type, $options);
638+
629639
return Html::tag('input', '', $options);
630640
}
631641

632642
/**
633643
* Initializes the range values when one of start or end attributes are set.
634644
*
635-
* @param string $type whether `start` or `end`
636-
* @param string $value the value to set
645+
* @param string $type whether `start` or `end`
646+
* @param string $value the value to set
637647
*/
638648
protected function initRangeValue($type = '', $value = '')
639649
{
@@ -653,9 +663,10 @@ protected function initRangeValue($type = '', $value = '')
653663
/**
654664
* Generates and returns the hidden input markup when one of start or end attributes are set.
655665
*
656-
* @param string $type whether `start` or `end`
666+
* @param string $type whether `start` or `end`
657667
*
658668
* @return string
669+
* @throws Exception
659670
*/
660671
protected function getRangeValue($type = '')
661672
{
@@ -664,6 +675,7 @@ protected function getRangeValue($type = '')
664675
return '';
665676
}
666677
$options = $this->getInputOpts($type);
678+
667679
return $this->hasModel() ? Html::getAttributeValue($this->model, $attr) :
668680
ArrayHelper::getValue($options, 'value', '');
669681
}

src/DateRangePickerAsset.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2020
4+
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2021
55
* @package yii2-date-range
66
* @version 1.7.3
77
*/

src/LanguageAsset.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2020
4+
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2021
55
* @package yii2-date-range
66
* @version 1.7.3
77
*/

src/MomentAsset.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2020
4+
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2021
55
* @package yii2-date-range
66
* @version 1.7.3
77
*/

src/assets/css/daterangepicker-kv.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2020
2+
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2021
33
* @version 1.7.3
44
*
55
* Custom styling for DateRangePicker

src/assets/css/daterangepicker-kv.min.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2020
2+
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2021
33
* @version 1.7.3
44
*
55
* Custom styling for DateRangePicker

src/assets/css/daterangepicker.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2020
2+
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2021
33
* @version 1.7.3
44
*
55
* Modified Bootstrap 3.x & 4.x styling for DateRangePicker

src/assets/css/daterangepicker.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)