Skip to content

Commit 6bf5fcb

Browse files
authored
Merge pull request #65 from benjamin-albert/master
Allows the user to pass an empty i18n translation. I saw new unit tests # 25 and 26 for this. Great work. All tests pass in IE 8 - IE 11 as well as Edge.
2 parents 80494d6 + 80a2adc commit 6bf5fcb

File tree

5 files changed

+42
-18
lines changed

5 files changed

+42
-18
lines changed

demo/MonthPicker.min.js

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

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "jquery-ui-month-picker",
33
"description": "jQuery UI Month Picker Plugin",
4-
"version": "3.0.3",
4+
"version": "3.0.4",
55
"license": "GPL-3.0",
66
"repository": "https://github.com/KidSysco/jquery-ui-month-picker.git",
77
"scripts": {

src/MonthPicker.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
The jQuery UI Month Picker Version 3.0.3
2+
The jQuery UI Month Picker Version 3.0.4
33
https://github.com/KidSysco/jquery-ui-month-picker/
44
55
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>

src/MonthPicker.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
The jQuery UI Month Picker Version 3.0.3
2+
The jQuery UI Month Picker Version 3.0.4
33
https://github.com/KidSysco/jquery-ui-month-picker/
44
55
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
@@ -166,7 +166,7 @@ along with this program. If not, see
166166
}
167167

168168
$.MonthPicker = {
169-
VERSION: '3.0.3', // Added in version 2.4;
169+
VERSION: '3.0.4', // Added in version 2.4;
170170
i18n: {
171171
year: 'Year',
172172
prevYear: 'Previous Year',
@@ -667,7 +667,13 @@ along with this program. If not, see
667667
},
668668

669669
_i18n: function(str) {
670-
return this.options.i18n[str] || $.MonthPicker.i18n[str];
670+
var _trans = this.options.i18n[str];
671+
672+
if (typeof _trans === 'undefined') {
673+
return $.MonthPicker.i18n[str];
674+
} else {
675+
return _trans;
676+
}
671677
},
672678

673679
_parseMonth: function (str, format) {

test/test.js

+30-12
Original file line numberDiff line numberDiff line change
@@ -633,37 +633,37 @@ QUnit.test('AltField and AltFormat tests', function( assert ) {
633633
field.val('11/2015').trigger('change');
634634

635635
assert.equal( $(SecondaryAltField).val(), '11/2015', 'Triggering a change event on the main field updated the secondary field');
636-
636+
637637
field.MonthPicker('Clear');
638-
638+
639639
assert.equal(field.val(), '', "The main field was cleared.");
640-
640+
641641
assert.equal($(SecondaryAltField).val(), '', "The secondary field was cleared.");
642-
642+
643643
field.MonthPicker('option', 'SelectedMonth', '06/2016');
644-
644+
645645
assert.equal(field.val(), '06/2016', 'The main field was populated correctly using the SelectedMonth option.');
646646
assert.equal($(SecondaryAltField).val(), '06/2016', "The secondary field was populated correctly using the SelectedMonth option.");
647-
647+
648648
field.MonthPicker('option', 'SelectedMonth', null);
649-
649+
650650
assert.equal(field.val(), '', 'The main field was cleared by passing null to the SelectedMonth option.');
651651
assert.equal($(SecondaryAltField).val(), '', "The secondary field was cleared by passing null to the SelectedMonth option..");
652-
652+
653653
var selectedVal = field.MonthPicker('Validate');
654654

655655
assert.equal($('#MonthPicker_Validation_MainAltField').css('display'), 'inline', 'A Validate API call showed a validation message about a bad date on #MainAltField.');
656656

657657
assert.equal(selectedVal, null, 'Validate API call returned null when there was no date selected as expected.');
658658

659659
assert.equal(field.MonthPicker('GetSelectedMonthYear'), null, 'GetSelectedMonthYear API call returned null when there was no date selected as expected.');
660-
660+
661661
assert.equal($('#MonthPicker_Validation_MainAltField').css('display'), 'inline', '#MainAltField showed a validation message about a bad date.');
662-
662+
663663
field.MonthPicker('option', 'SelectedMonth', '06/2016');
664664

665665
assert.ok($('#MonthPicker_Validation_MainAltField').is(':hidden'), '#MainAltField cleared the validation error message by setting the SelectedMonth option.');
666-
666+
667667
});
668668

669669
QUnit.test('Right to left', function (assert) {
@@ -994,7 +994,9 @@ QUnit.test('ShowOn both', function (assert) {
994994
assert.notOk(menu.is(':visible'), 'The menu was closed by pressing tab');
995995
});
996996

997-
QUnit.test('i18n', function (assert) {
997+
QUnit.module("i18n");
998+
999+
QUnit.test('button', function (assert) {
9981000
assert.expect(2);
9991001

10001002
$("<input />").MonthPicker({
@@ -1005,6 +1007,22 @@ QUnit.test('i18n', function (assert) {
10051007
}).MonthPicker('destroy');
10061008
});
10071009

1010+
QUnit.test('empty text translation', function (assert) {
1011+
assert.expect(1);
1012+
1013+
var field = $("<input id='i18nField' />").MonthPicker({
1014+
i18n: { year: '' }
1015+
});
1016+
1017+
field.MonthPicker('Open');
1018+
1019+
var menu = $(MonthPicker_i18nField);
1020+
1021+
assert.equal(menu.find('.month-picker-title').text(), new Date().getFullYear(), 'We are NOT using the default text when passing in an empty string');
1022+
1023+
field.MonthPicker('destroy');
1024+
});
1025+
10081026
QUnit.module("Min/MaxMonth");
10091027

10101028
QUnit.test('Month buttons are disabled', function (assert) {

0 commit comments

Comments
 (0)