Skip to content

Commit bdbee90

Browse files
author
Eonasdan
committed
Merge pull request Eonasdan#1201 from liamsmith57/development
Added tooltips to options for localization.
2 parents d7ba83c + 18a150e commit bdbee90

File tree

1 file changed

+46
-14
lines changed

1 file changed

+46
-14
lines changed

src/js/bootstrap-datetimepicker.js

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,16 @@
285285
getToolbar = function () {
286286
var row = [];
287287
if (options.showTodayButton) {
288-
row.push($('<td>').append($('<a>').attr({'data-action':'today', 'title':'Go to today'}).append($('<span>').addClass(options.icons.today))));
288+
row.push($('<td>').append($('<a>').attr({'data-action':'today', 'title': options.tooltips.today}).append($('<span>').addClass(options.icons.today))));
289289
}
290290
if (!options.sideBySide && hasDate() && hasTime()) {
291291
row.push($('<td>').append($('<a>').attr({'data-action':'togglePicker', 'title':'Select Time'}).append($('<span>').addClass(options.icons.time))));
292292
}
293293
if (options.showClear) {
294-
row.push($('<td>').append($('<a>').attr({'data-action':'clear', 'title':'Clear selection'}).append($('<span>').addClass(options.icons.clear))));
294+
row.push($('<td>').append($('<a>').attr({'data-action':'clear', 'title': options.tooltips.clear}).append($('<span>').addClass(options.icons.clear))));
295295
}
296296
if (options.showClose) {
297-
row.push($('<td>').append($('<a>').attr({'data-action':'close', 'title':'Close the picker'}).append($('<span>').addClass(options.icons.close))));
297+
row.push($('<td>').append($('<a>').attr({'data-action':'close', 'title': options.tooltips.close}).append($('<span>').addClass(options.icons.close))));
298298
}
299299
return $('<table>').addClass('table-condensed').append($('<tbody>').append($('<tr>').append(row)));
300300
},
@@ -558,9 +558,9 @@
558558
monthsViewHeader = monthsView.find('th'),
559559
months = monthsView.find('tbody').find('span');
560560

561-
monthsViewHeader.eq(0).find('span').attr('title', 'Previous Year');
562-
monthsViewHeader.eq(1).attr('title', 'Select Year');
563-
monthsViewHeader.eq(2).find('span').attr('title', 'Next Year');
561+
monthsViewHeader.eq(0).find('span').attr('title', options.tooltips.prevYear);
562+
monthsViewHeader.eq(1).attr('title', options.tooltips.selectYear);
563+
monthsViewHeader.eq(2).find('span').attr('title', options.tooltips.nextYear);
564564

565565
monthsView.find('.disabled').removeClass('disabled');
566566

@@ -593,9 +593,9 @@
593593
endYear = viewDate.clone().add(6, 'y'),
594594
html = '';
595595

596-
yearsViewHeader.eq(0).find('span').attr('title', 'Previous Decade');
597-
yearsViewHeader.eq(1).attr('title', 'Select Decade');
598-
yearsViewHeader.eq(2).find('span').attr('title', 'Next Decade');
596+
yearsViewHeader.eq(0).find('span').attr('title', options.tooltips.nextDecade);
597+
yearsViewHeader.eq(1).attr('title', options.tooltips.selectDecade);
598+
yearsViewHeader.eq(2).find('span').attr('title', options.tooltips.prevDecade);
599599

600600
yearsView.find('.disabled').removeClass('disabled');
601601

@@ -624,8 +624,8 @@
624624
endDecade = startDecade.clone().add(100, 'y'),
625625
html = '';
626626

627-
decadesViewHeader.eq(0).find('span').attr('title', 'Previous Century');
628-
decadesViewHeader.eq(2).find('span').attr('title', 'Next Century');
627+
decadesViewHeader.eq(0).find('span').attr('title', options.tooltips.prevCentury);
628+
decadesViewHeader.eq(2).find('span').attr('title', options.tooltips.nextCentury);
629629

630630
decadesView.find('.disabled').removeClass('disabled');
631631

@@ -662,9 +662,9 @@
662662
return;
663663
}
664664

665-
daysViewHeader.eq(0).find('span').attr('title', 'Previous Month');
666-
daysViewHeader.eq(1).attr('title', 'Select Month');
667-
daysViewHeader.eq(2).find('span').attr('title', 'Next Month');
665+
daysViewHeader.eq(0).find('span').attr('title', options.tooltips.prevMonth);
666+
daysViewHeader.eq(1).attr('title', options.tooltips.selectMonth);
667+
daysViewHeader.eq(2).find('span').attr('title', options.tooltips.nextMonth);
668668

669669
daysView.find('.disabled').removeClass('disabled');
670670
daysViewHeader.eq(1).text(viewDate.format(options.dayViewHeaderFormat));
@@ -1807,6 +1807,22 @@
18071807
return picker;
18081808
};
18091809

1810+
picker.tooltips = function (tooltips) {
1811+
if (arguments.length === 0) {
1812+
return $.extend({}, options.tooltips);
1813+
}
1814+
1815+
if (!(tooltips instanceof Object)) {
1816+
throw new TypeError('tooltips() expects parameter to be an Object');
1817+
}
1818+
$.extend(options.tooltips, tooltips);
1819+
if (widget) {
1820+
hide();
1821+
show();
1822+
}
1823+
return picker;
1824+
};
1825+
18101826
picker.useStrict = function (useStrict) {
18111827
if (arguments.length === 0) {
18121828
return options.useStrict;
@@ -2319,6 +2335,22 @@
23192335
clear: 'glyphicon glyphicon-trash',
23202336
close: 'glyphicon glyphicon-remove'
23212337
},
2338+
tooltips: {
2339+
today: 'Go to today',
2340+
clear: 'Clear selection',
2341+
close: 'Close the picker',
2342+
selectMonth: 'Select Month',
2343+
prevMonth: 'Previous Month',
2344+
nextMonth: 'Next Month',
2345+
selectYear: 'Select Year',
2346+
prevYear: 'Previous Year',
2347+
nextYear: 'Next Year',
2348+
selectDecade: 'Select Decade',
2349+
prevDecade: 'Previous Decade',
2350+
nextDecade: 'Next Decade',
2351+
prevCentury: 'Previous Century',
2352+
nextCentury: 'Next Century'
2353+
},
23222354
useStrict: false,
23232355
sideBySide: false,
23242356
daysOfWeekDisabled: false,

0 commit comments

Comments
 (0)