Skip to content

Commit 5771894

Browse files
committed
Update to release v1.3.3
1 parent dba217f commit 5771894

13 files changed

+95
-33
lines changed

CHANGE.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
version 1.3.3
22
=============
3-
**Date:** 15-Jun-2015
3+
**Date:** 27-Jun-2015
44

55
- (enh #27): Enhance plugin to use no conflict approach.
66
- (enh #28): Update to latest version of bootstrap-datepicker.
7-
- (enh #29): Fix locale js files to use the new noconflict kvDatepicker function.
7+
- (enh #29): Fix locale js files to use the new noconflict `kvDatepicker` function.
88
- (enh #30): Add Ukranian translations.
9+
- (bug #35): Parse `title` correctly for calendar/remove button addon.
10+
- (enh #36): Configure addon for prepend, append, and range.
911
- (enh #39): Add Spanish translations.
1012

1113
version 1.3.2

DatePicker.php

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class DatePicker extends \kartik\base\InputWidget
6666
* - if this is passed as an array (this is the DEFAULT) it will treat this as HTML attributes
6767
* for the button (to be displayed as a Bootstrap addon). The following special keys are recognized;
6868
* - icon - string, the bootstrap glyphicon name/suffix. Defaults to 'calendar'.
69-
* - title - string, the title to be displayed on hover. Defaults to 'Select date & time'.
69+
* - title - string|bool, the title to be displayed on hover. Defaults to 'Select date & time'. To disable,
70+
* set it to `false`.
7071
*/
7172
public $pickerButton = [];
7273

@@ -78,7 +79,8 @@ class DatePicker extends \kartik\base\InputWidget
7879
* - if this is passed as an array (this is the DEFAULT) it will treat this as HTML attributes
7980
* for the button (to be displayed as a Bootstrap addon). The following special keys are recognized;
8081
* - icon - string, the bootstrap glyphicon name/suffix. Defaults to 'remove'.
81-
* - title - string, the title to be displayed on hover. Defaults to 'Clear field'.
82+
* - title - string, the title to be displayed on hover. Defaults to 'Clear field'. To disable,
83+
* set it to `false`.
8284
*/
8385
public $removeButton = [];
8486

@@ -88,10 +90,18 @@ class DatePicker extends \kartik\base\InputWidget
8890
public $options = [];
8991

9092
/**
91-
* @var string The addon that will be prepended/appended for a
92-
* [[TYPE_COMPONENT_PREPEND]] and [[TYPE_COMPONENT_APPEND]]
93+
* @var array The addon that will be prepended/appended for a [[TYPE_COMPONENT_PREPEND]] and
94+
* [[TYPE_COMPONENT_APPEND]]. You can set the following array keys:
95+
* - part1: string, the content to prepend before the [[TYPE_COMPONENT_PREPEND]] OR
96+
* before input # 1 for [[TYPE_RANGE]].
97+
* - part2: string, the content to prepend after the [[TYPE_COMPONENT_PREPEND]] OR
98+
* after input # 1 for [[TYPE_RANGE]].
99+
* - part3: string, the content to append before the [[TYPE_COMPONENT_APPEND]] OR
100+
* before input # 2 for [[TYPE_RANGE]].
101+
* - part4: string, the content to append after the [[TYPE_COMPONENT_APPEND]] OR
102+
* after input # 2 for [[TYPE_RANGE]].
93103
*/
94-
public $addon = self::CALENDAR_ICON;
104+
public $addon = [];
95105

96106
/**
97107
* @var string the model attribute 2 if you are using [[TYPE_RANGE]]
@@ -168,6 +178,9 @@ public function init()
168178
if (isset($this->form) && ($this->type === self::TYPE_RANGE) && (!isset($this->attribute2))) {
169179
throw new InvalidConfigException("The 'attribute2' property must be set for a 'range' type markup and a defined 'form' property.");
170180
}
181+
if (isset($this->addon) && !is_array($this->addon)) {
182+
throw new InvalidConfigException("The 'addon' property must be setup as an array with 'part1', 'part2', 'part3', and/or 'part4' keys.");
183+
}
171184
$s = DIRECTORY_SEPARATOR;
172185
$this->initI18N(__DIR__);
173186
$this->setLanguage('bootstrap-datepicker.', __DIR__ . "{$s}assets{$s}", null, '.min.js');
@@ -222,11 +235,9 @@ protected function renderAddon(&$options, $type = 'picker')
222235
$icon = ($type === 'picker') ? 'calendar' : 'remove';
223236
Html::addCssClass($options, 'input-group-addon kv-date-' . $icon);
224237
$icon = '<i class="glyphicon glyphicon-' . ArrayHelper::remove($options, 'icon', $icon) . '"></i>';
225-
if (empty($options['title'])) {
226-
$title = ($type === 'picker') ? Yii::t('kvdate', 'Select date') : Yii::t('kvdate', 'Clear field');
227-
if ($title != false) {
228-
$options['title'] = $title;
229-
}
238+
$title = ArrayHelper::getValue($options, 'title', '');
239+
if ($title !== false && empty($title)) {
240+
$options['title'] = ($type === 'picker') ? Yii::t('kvdate', 'Select date') : Yii::t('kvdate', 'Clear field');
230241
}
231242
return Html::tag('span', $icon, $options);
232243
}
@@ -252,13 +263,21 @@ protected function parseMarkup($input)
252263
if ($this->type == self::TYPE_INPUT) {
253264
return $input;
254265
}
266+
$part1 = $part2 = $part3 = $part4 = '';
267+
if (!empty($this->addon) && ($this->_hasAddon || $this->type == self::TYPE_RANGE)) {
268+
$part1 = ArrayHelper::getValue($this->addon, 'part1', '');
269+
$part2 = ArrayHelper::getValue($this->addon, 'part2', '');
270+
$part3 = ArrayHelper::getValue($this->addon, 'part3', '');
271+
$part4 = ArrayHelper::getValue($this->addon, 'part4', '');
272+
}
255273
if ($this->_hasAddon) {
256274
Html::addCssClass($this->_container, 'date');
257275
$picker = $this->renderAddon($this->pickerButton);
258276
$remove = $this->renderAddon($this->removeButton, 'remove');
259-
$content = $picker . $remove . $input;
260277
if ($this->type == self::TYPE_COMPONENT_APPEND) {
261-
$content = $input . $remove . $picker;
278+
$content = $part1 . $part2 . $input . $part3 . $remove . $picker . $part4;
279+
} else {
280+
$content = $part1 . $picker . $remove . $part2 . $input . $part3 . $part4;
262281
}
263282
return Html::tag('div', $content, $this->_container);
264283
}
@@ -297,7 +316,9 @@ protected function parseMarkup($input)
297316
Html::activeTextInput($this->model, $this->attribute2, $this->options2) :
298317
Html::textInput($this->name2, $this->value2, $this->options2);
299318
}
300-
return Html::tag('div', "{$input}<span class='input-group-addon kv-field-separator'>{$this->separator}</span>{$input2}", $this->_container);
319+
$content = $part1 . $input . $part2 . "<span class='input-group-addon kv-field-separator'>{$this->separator}</span>" .
320+
$part3 . $input2 . $part4;
321+
return Html::tag('div', $content, $this->_container);
301322
}
302323
if ($this->type == self::TYPE_INLINE) {
303324
$this->_id = $this->options['id'] . '-inline';
@@ -332,13 +353,15 @@ public function registerAssets()
332353
} else {
333354
$this->registerPlugin($this->pluginName, "{$id}.parent()");
334355
}
335-
if ($this->removeButton !== false && $this->_hasAddon) {
336-
$view->registerJs("{$id}.parent().find('.kv-date-remove').on('click', function() {
337-
{$id}.parent().{$this->pluginName}('clearDates');
338-
});");
356+
if ($this->_hasAddon && $this->removeButton !== false) {
357+
$view->registerJs("initDPRemove('" . $this->options['id'] . "');");
358+
}
359+
if ($this->_hasAddon && !empty($this->addon)) {
360+
$view->registerJs("initDPAddon('" . $this->options['id'] . "');");
339361
}
340362
if ($this->type === self::TYPE_RANGE) {
341363
\kartik\field\FieldRangeAsset::register($view);
364+
$view->registerJs("initDPRemove('" . $this->options['id'] . "', true);");
342365
}
343366
}
344367
}

DatePickerAsset.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
class DatePickerAsset extends \kartik\base\AssetBundle
1919
{
20-
2120
public function init()
2221
{
2322
$this->setSourcePath(__DIR__ . '/assets');

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2525
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
2626
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2727
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ The preferred way to install this extension is through [composer](http://getcomp
2525
To install, either run
2626

2727
```
28-
$ php composer.phar require kartik-v/yii2-widget-datepicker "*"
28+
$ php composer.phar require kartik-v/yii2-widget-datepicker "@dev"
2929
```
3030

3131
or add
3232

3333
```
34-
"kartik-v/yii2-widget-datepicker": "*"
34+
"kartik-v/yii2-widget-datepicker": "@dev"
3535
```
3636

3737
to the ```require``` section of your `composer.json` file.

assets/css/datepicker-kv.css

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@
2222
opacity: .65;
2323
}
2424

25-
.input-group.date .input-group-addon span {
26-
cursor: pointer;
25+
.input-group.date .input-group-addon {
26+
cursor: default;
2727
}
28+
29+
.input-group.date .kv-date-remove, .input-group.date .kv-date-calendar,
30+
.input-group.date .kv-date-remove, .input-group.date .kv-date-calendar,
31+
.input-group.input-daterange .kv-date-remove, .input-group.input-daterange .kv-date-calendar,
32+
.input-group.input-daterange .kv-date-remove, .input-group.input-daterange .kv-date-calendar {
33+
cursor: pointer;
34+
}
35+
36+
.input-group.input-daterange .input-group-addon {
37+
border-left: 1px solid #ccc;
38+
}
39+
40+
.input-group.input-daterange .input-group-addon:last-child {
41+
border-right: 1px solid #ccc;
42+
}

assets/css/datepicker-kv.min.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
* Author: Kartik Visweswaran
1010
* Year: 2015
1111
* For more Yii related demos visit http://demos.krajee.com
12-
*/.datepicker{z-index:1151!important}.input-group.date.disabled .input-group-addon .glyphicon{cursor:not-allowed;filter:alpha(opacity=65);-webkit-box-shadow:none;box-shadow:none;opacity:.65}.input-group.date .input-group-addon span{cursor:pointer}
12+
*/.datepicker{z-index:1151!important}.input-group.date.disabled .input-group-addon .glyphicon{cursor:not-allowed;filter:alpha(opacity=65);-webkit-box-shadow:none;box-shadow:none;opacity:.65}.input-group.date .input-group-addon{cursor:default}.input-group.date .kv-date-calendar,.input-group.date .kv-date-remove,.input-group.input-daterange .kv-date-calendar,.input-group.input-daterange .kv-date-remove{cursor:pointer}.input-group.input-daterange .input-group-addon{border-left:1px solid #ccc}.input-group.input-daterange .input-group-addon:last-child{border-right:1px solid #ccc}

assets/js/datepicker-kv.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,30 @@
1313
* Year: 2015
1414
* For more Yii related demos visit http://demos.krajee.com
1515
*/
16+
var initDPRemove = function() {
17+
}, initDPAddon = function() {
18+
};
1619
(function ($) {
1720
$.fn.kvDatepicker = $.fn.datepicker.noConflict();
21+
initDPRemove = function(id, range) {
22+
var $id = $('#' + id), $el = $id.parent();
23+
$el.find('.kv-date-remove').on('click.kvdatepicker', function() {
24+
if (range) {
25+
$el.find('input[type="text"]').each(function() {
26+
$(this).kvDatepicker('clearDates');
27+
});
28+
} else {
29+
$el.kvDatepicker('clearDates');
30+
}
31+
});
32+
};
33+
initDPAddon = function(id) {
34+
var $id = $('#' + id), $el = $id.parent();
35+
$el.find('.input-group-addon:not(.kv-date-calendar):not(.kv-date-remove)').each(function() {
36+
var $addon = $(this);
37+
$addon.on('click.kvdatepicker', function(e) {
38+
$el.kvDatepicker('hide');
39+
});
40+
});
41+
};
1842
})(window.jQuery);

assets/js/datepicker-kv.min.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
* Author: Kartik Visweswaran
1313
* Year: 2015
1414
* For more Yii related demos visit http://demos.krajee.com
15-
*/!function(n){n.fn.kvDatepicker=n.fn.datepicker.noConflict()}(window.jQuery);
15+
*/var initDPRemove=function(){},initDPAddon=function(){};!function(n){n.fn.kvDatepicker=n.fn.datepicker.noConflict(),initDPRemove=function(e,t){var i=n("#"+e),c=i.parent();c.find(".kv-date-remove").on("click.kvdatepicker",function(){t?c.find('input[type="text"]').each(function(){n(this).kvDatepicker("clearDates")}):c.kvDatepicker("clearDates")})},initDPAddon=function(e){var t=n("#"+e),i=t.parent();i.find(".input-group-addon:not(.kv-date-calendar):not(.kv-date-remove)").each(function(){var e=n(this);e.on("click.kvdatepicker",function(n){i.kvDatepicker("hide")})})}}(window.jQuery);

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212
"homepage": "http://www.krajee.com/"
1313
}
1414
],
15-
"minimum-stability": "stable",
1615
"require": {
17-
"kartik-v/yii2-krajee-base": "*"
16+
"kartik-v/yii2-krajee-base": "~1.7"
1817
},
1918
"autoload": {
2019
"psr-4": {
2120
"kartik\\date\\": ""
2221
}
2322
}
24-
}
23+
}

messages/config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@
4949
// When format is "db", you may specify the following two options
5050
//'db' => 'db',
5151
//'sourceMessageTable' => '{{%source_message}}',
52-
];
52+
];

messages/en/kvdate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
return [
2020
'Clear field' => '',
2121
'Select date' => '',
22-
];
22+
];

messages/es/kvdate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
return [
2020
'Clear field' => 'Limpiar campo',
2121
'Select date' => 'Seleccionar fecha',
22-
];
22+
];

0 commit comments

Comments
 (0)