Skip to content

Commit

Permalink
Merge pull request #65 from benjamin-albert/master
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
KidSysco committed Oct 7, 2016
2 parents 80494d6 + 80a2adc commit 6bf5fcb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 18 deletions.
2 changes: 1 addition & 1 deletion demo/MonthPicker.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jquery-ui-month-picker",
"description": "jQuery UI Month Picker Plugin",
"version": "3.0.3",
"version": "3.0.4",
"license": "GPL-3.0",
"repository": "https://github.com/KidSysco/jquery-ui-month-picker.git",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/MonthPicker.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
The jQuery UI Month Picker Version 3.0.3
The jQuery UI Month Picker Version 3.0.4
https://github.com/KidSysco/jquery-ui-month-picker/
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Expand Down
12 changes: 9 additions & 3 deletions src/MonthPicker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
The jQuery UI Month Picker Version 3.0.3
The jQuery UI Month Picker Version 3.0.4
https://github.com/KidSysco/jquery-ui-month-picker/
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Expand Down Expand Up @@ -166,7 +166,7 @@ along with this program. If not, see
}

$.MonthPicker = {
VERSION: '3.0.3', // Added in version 2.4;
VERSION: '3.0.4', // Added in version 2.4;
i18n: {
year: 'Year',
prevYear: 'Previous Year',
Expand Down Expand Up @@ -667,7 +667,13 @@ along with this program. If not, see
},

_i18n: function(str) {
return this.options.i18n[str] || $.MonthPicker.i18n[str];
var _trans = this.options.i18n[str];

if (typeof _trans === 'undefined') {
return $.MonthPicker.i18n[str];
} else {
return _trans;
}
},

_parseMonth: function (str, format) {
Expand Down
42 changes: 30 additions & 12 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,37 +633,37 @@ QUnit.test('AltField and AltFormat tests', function( assert ) {
field.val('11/2015').trigger('change');

assert.equal( $(SecondaryAltField).val(), '11/2015', 'Triggering a change event on the main field updated the secondary field');

field.MonthPicker('Clear');

assert.equal(field.val(), '', "The main field was cleared.");

assert.equal($(SecondaryAltField).val(), '', "The secondary field was cleared.");

field.MonthPicker('option', 'SelectedMonth', '06/2016');

assert.equal(field.val(), '06/2016', 'The main field was populated correctly using the SelectedMonth option.');
assert.equal($(SecondaryAltField).val(), '06/2016', "The secondary field was populated correctly using the SelectedMonth option.");

field.MonthPicker('option', 'SelectedMonth', null);

assert.equal(field.val(), '', 'The main field was cleared by passing null to the SelectedMonth option.');
assert.equal($(SecondaryAltField).val(), '', "The secondary field was cleared by passing null to the SelectedMonth option..");

var selectedVal = field.MonthPicker('Validate');

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

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

assert.equal(field.MonthPicker('GetSelectedMonthYear'), null, 'GetSelectedMonthYear API call returned null when there was no date selected as expected.');

assert.equal($('#MonthPicker_Validation_MainAltField').css('display'), 'inline', '#MainAltField showed a validation message about a bad date.');

field.MonthPicker('option', 'SelectedMonth', '06/2016');

assert.ok($('#MonthPicker_Validation_MainAltField').is(':hidden'), '#MainAltField cleared the validation error message by setting the SelectedMonth option.');

});

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

QUnit.test('i18n', function (assert) {
QUnit.module("i18n");

QUnit.test('button', function (assert) {
assert.expect(2);

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

QUnit.test('empty text translation', function (assert) {
assert.expect(1);

var field = $("<input id='i18nField' />").MonthPicker({
i18n: { year: '' }
});

field.MonthPicker('Open');

var menu = $(MonthPicker_i18nField);

assert.equal(menu.find('.month-picker-title').text(), new Date().getFullYear(), 'We are NOT using the default text when passing in an empty string');

field.MonthPicker('destroy');
});

QUnit.module("Min/MaxMonth");

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

0 comments on commit 6bf5fcb

Please sign in to comment.