Skip to content

Commit 707539f

Browse files
committed
Datepicker - Fixed #4704 - Datepicker global variable isn't unique
1 parent d33c2de commit 707539f

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

ui/jquery.ui.datepicker.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
$.extend($.ui, { datepicker: { version: "@VERSION" } });
1717

1818
var PROP_NAME = 'datepicker';
19+
var dpuuid = new Date().getTime();
1920

2021
/* Date picker manager.
2122
Use the singleton instance of this class, $.datepicker, to interact with the date picker.
@@ -1357,24 +1358,28 @@ $.extend(Datepicker.prototype, {
13571358
this._daylightSavingAdjust(new Date(drawYear, drawMonth - stepMonths, 1)),
13581359
this._getFormatConfig(inst)));
13591360
var prev = (this._canAdjustMonth(inst, -1, drawYear, drawMonth) ?
1360-
'<a class="ui-datepicker-prev ui-corner-all" onclick="DP_jQuery.datepicker._adjustDate(\'#' + inst.id + '\', -' + stepMonths + ', \'M\');"' +
1361+
'<a class="ui-datepicker-prev ui-corner-all" onclick="DP_jQuery_' + dpuuid +
1362+
'.datepicker._adjustDate(\'#' + inst.id + '\', -' + stepMonths + ', \'M\');"' +
13611363
' title="' + prevText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'e' : 'w') + '">' + prevText + '</span></a>' :
13621364
(hideIfNoPrevNext ? '' : '<a class="ui-datepicker-prev ui-corner-all ui-state-disabled" title="'+ prevText +'"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'e' : 'w') + '">' + prevText + '</span></a>'));
13631365
var nextText = this._get(inst, 'nextText');
13641366
nextText = (!navigationAsDateFormat ? nextText : this.formatDate(nextText,
13651367
this._daylightSavingAdjust(new Date(drawYear, drawMonth + stepMonths, 1)),
13661368
this._getFormatConfig(inst)));
13671369
var next = (this._canAdjustMonth(inst, +1, drawYear, drawMonth) ?
1368-
'<a class="ui-datepicker-next ui-corner-all" onclick="DP_jQuery.datepicker._adjustDate(\'#' + inst.id + '\', +' + stepMonths + ', \'M\');"' +
1370+
'<a class="ui-datepicker-next ui-corner-all" onclick="DP_jQuery_' + dpuuid +
1371+
'.datepicker._adjustDate(\'#' + inst.id + '\', +' + stepMonths + ', \'M\');"' +
13691372
' title="' + nextText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'w' : 'e') + '">' + nextText + '</span></a>' :
13701373
(hideIfNoPrevNext ? '' : '<a class="ui-datepicker-next ui-corner-all ui-state-disabled" title="'+ nextText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'w' : 'e') + '">' + nextText + '</span></a>'));
13711374
var currentText = this._get(inst, 'currentText');
13721375
var gotoDate = (this._get(inst, 'gotoCurrent') && inst.currentDay ? currentDate : today);
13731376
currentText = (!navigationAsDateFormat ? currentText :
13741377
this.formatDate(currentText, gotoDate, this._getFormatConfig(inst)));
1375-
var controls = (!inst.inline ? '<button type="button" class="ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all" onclick="DP_jQuery.datepicker._hideDatepicker();">' + this._get(inst, 'closeText') + '</button>' : '');
1378+
var controls = (!inst.inline ? '<button type="button" class="ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all" onclick="DP_jQuery_' + dpuuid +
1379+
'.datepicker._hideDatepicker();">' + this._get(inst, 'closeText') + '</button>' : '');
13761380
var buttonPanel = (showButtonPanel) ? '<div class="ui-datepicker-buttonpane ui-widget-content">' + (isRTL ? controls : '') +
1377-
(this._isInRange(inst, gotoDate) ? '<button type="button" class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" onclick="DP_jQuery.datepicker._gotoToday(\'#' + inst.id + '\');"' +
1381+
(this._isInRange(inst, gotoDate) ? '<button type="button" class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" onclick="DP_jQuery_' + dpuuid +
1382+
'.datepicker._gotoToday(\'#' + inst.id + '\');"' +
13781383
'>' + currentText + '</button>' : '') + (isRTL ? '' : controls) + '</div>' : '';
13791384
var firstDay = parseInt(this._get(inst, 'firstDay'),10);
13801385
firstDay = (isNaN(firstDay) ? 0 : firstDay);
@@ -1447,7 +1452,7 @@ $.extend(Datepicker.prototype, {
14471452
(printDate.getTime() == currentDate.getTime() ? ' ' + this._currentClass : '') + // highlight selected day
14481453
(printDate.getTime() == today.getTime() ? ' ui-datepicker-today' : '')) + '"' + // highlight today (if different)
14491454
((!otherMonth || showOtherMonths) && daySettings[2] ? ' title="' + daySettings[2] + '"' : '') + // cell title
1450-
(unselectable ? '' : ' onclick="DP_jQuery.datepicker._selectDay(\'#' +
1455+
(unselectable ? '' : ' onclick="DP_jQuery_' + dpuuid + '.datepicker._selectDay(\'#' +
14511456
inst.id + '\',' + printDate.getMonth() + ',' + printDate.getFullYear() + ', this);return false;"') + '>' + // actions
14521457
(otherMonth && !showOtherMonths ? '&#xa0;' : // display for other months
14531458
(unselectable ? '<span class="ui-state-default">' + printDate.getDate() + '</span>' : '<a class="ui-state-default' +
@@ -1492,8 +1497,8 @@ $.extend(Datepicker.prototype, {
14921497
var inMinYear = (minDate && minDate.getFullYear() == drawYear);
14931498
var inMaxYear = (maxDate && maxDate.getFullYear() == drawYear);
14941499
monthHtml += '<select class="ui-datepicker-month" ' +
1495-
'onchange="DP_jQuery.datepicker._selectMonthYear(\'#' + inst.id + '\', this, \'M\');" ' +
1496-
'onclick="DP_jQuery.datepicker._clickMonthYear(\'#' + inst.id + '\');"' +
1500+
'onchange="DP_jQuery_' + dpuuid + '.datepicker._selectMonthYear(\'#' + inst.id + '\', this, \'M\');" ' +
1501+
'onclick="DP_jQuery_' + dpuuid + '.datepicker._clickMonthYear(\'#' + inst.id + '\');"' +
14971502
'>';
14981503
for (var month = 0; month < 12; month++) {
14991504
if ((!inMinYear || month >= minDate.getMonth()) &&
@@ -1524,8 +1529,8 @@ $.extend(Datepicker.prototype, {
15241529
year = (minDate ? Math.max(year, minDate.getFullYear()) : year);
15251530
endYear = (maxDate ? Math.min(endYear, maxDate.getFullYear()) : endYear);
15261531
html += '<select class="ui-datepicker-year" ' +
1527-
'onchange="DP_jQuery.datepicker._selectMonthYear(\'#' + inst.id + '\', this, \'Y\');" ' +
1528-
'onclick="DP_jQuery.datepicker._clickMonthYear(\'#' + inst.id + '\');"' +
1532+
'onchange="DP_jQuery_' + dpuuid + '.datepicker._selectMonthYear(\'#' + inst.id + '\', this, \'Y\');" ' +
1533+
'onclick="DP_jQuery_' + dpuuid + '.datepicker._clickMonthYear(\'#' + inst.id + '\');"' +
15291534
'>';
15301535
for (; year <= endYear; year++) {
15311536
html += '<option value="' + year + '"' +
@@ -1685,6 +1690,6 @@ $.datepicker.version = "@VERSION";
16851690

16861691
// Workaround for #4055
16871692
// Add another global to avoid noConflict issues with inline event handlers
1688-
window.DP_jQuery = $;
1693+
window['DP_jQuery_' + dpuuid] = $;
16891694

16901695
})(jQuery);

0 commit comments

Comments
 (0)