Skip to content

Commit 831333a

Browse files
metawetascottgonzalez
authored andcommitted
Datepicker: Pulled event handlers into static code. Fixed #3945 - DatePicker does not respond to any click events in AIR, Google Sites, Windows Metro.
(cherry picked from commit 6dcc5c1)
1 parent 800ceb3 commit 831333a

File tree

1 file changed

+46
-16
lines changed

1 file changed

+46
-16
lines changed

ui/jquery.ui.datepicker.js

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ $.extend(Datepicker.prototype, {
714714
var borders = $.datepicker._getBorders(inst.dpDiv);
715715
instActive = inst; // for delegate hover events
716716
inst.dpDiv.empty().append(this._generateHTML(inst));
717+
this._attachHandlers(inst);
717718
var cover = inst.dpDiv.find('iframe.ui-datepicker-cover'); // IE6- only
718719
if( !!cover.length ){ //avoid call to outerXXXX() when not in IE6
719720
cover.css({left: -borders[0], top: -borders[1], width: inst.dpDiv.outerWidth(), height: inst.dpDiv.outerHeight()})
@@ -1402,6 +1403,43 @@ $.extend(Datepicker.prototype, {
14021403
return startDate;
14031404
},
14041405

1406+
/* Attach the onxxx handlers. These are declared statically so
1407+
* they work with static code transformers like Caja.
1408+
*/
1409+
_attachHandlers: function(inst) {
1410+
var stepMonths = this._get(inst, 'stepMonths');
1411+
var id = '#' + inst.id;
1412+
inst.dpDiv.find('[data-handler]').map(function () {
1413+
var handler = {
1414+
prev: function () {
1415+
window['DP_jQuery_' + dpuuid].datepicker._adjustDate(id, -stepMonths, 'M');
1416+
},
1417+
next: function () {
1418+
window['DP_jQuery_' + dpuuid].datepicker._adjustDate(id, +stepMonths, 'M');
1419+
},
1420+
hide: function () {
1421+
window['DP_jQuery_' + dpuuid].datepicker._hideDatepicker();
1422+
},
1423+
today: function () {
1424+
window['DP_jQuery_' + dpuuid].datepicker._gotoToday(id);
1425+
},
1426+
selectDay: function () {
1427+
window['DP_jQuery_' + dpuuid].datepicker._selectDay(id, +this.getAttribute('data-month'), +this.getAttribute('data-year'), this);
1428+
return false;
1429+
},
1430+
selectMonth: function () {
1431+
window['DP_jQuery_' + dpuuid].datepicker._selectMonthYear(id, this, 'M');
1432+
return false;
1433+
},
1434+
selectYear: function () {
1435+
window['DP_jQuery_' + dpuuid].datepicker._selectMonthYear(id, this, 'Y');
1436+
return false;
1437+
}
1438+
};
1439+
$(this).bind(this.getAttribute('data-event'), handler[this.getAttribute('data-handler')]);
1440+
});
1441+
},
1442+
14051443
/* Generate the HTML for the current state of the date picker. */
14061444
_generateHTML: function(inst) {
14071445
var today = new Date();
@@ -1444,28 +1482,25 @@ $.extend(Datepicker.prototype, {
14441482
this._daylightSavingAdjust(new Date(drawYear, drawMonth - stepMonths, 1)),
14451483
this._getFormatConfig(inst)));
14461484
var prev = (this._canAdjustMonth(inst, -1, drawYear, drawMonth) ?
1447-
'<a class="ui-datepicker-prev ui-corner-all" onclick="DP_jQuery_' + dpuuid +
1448-
'.datepicker._adjustDate(\'#' + inst.id + '\', -' + stepMonths + ', \'M\');"' +
1485+
'<a class="ui-datepicker-prev ui-corner-all" data-handler="prev" data-event="click"' +
14491486
' title="' + prevText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'e' : 'w') + '">' + prevText + '</span></a>' :
14501487
(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>'));
14511488
var nextText = this._get(inst, 'nextText');
14521489
nextText = (!navigationAsDateFormat ? nextText : this.formatDate(nextText,
14531490
this._daylightSavingAdjust(new Date(drawYear, drawMonth + stepMonths, 1)),
14541491
this._getFormatConfig(inst)));
14551492
var next = (this._canAdjustMonth(inst, +1, drawYear, drawMonth) ?
1456-
'<a class="ui-datepicker-next ui-corner-all" onclick="DP_jQuery_' + dpuuid +
1457-
'.datepicker._adjustDate(\'#' + inst.id + '\', +' + stepMonths + ', \'M\');"' +
1493+
'<a class="ui-datepicker-next ui-corner-all" data-handler="next" data-event="click"' +
14581494
' title="' + nextText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'w' : 'e') + '">' + nextText + '</span></a>' :
14591495
(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>'));
14601496
var currentText = this._get(inst, 'currentText');
14611497
var gotoDate = (this._get(inst, 'gotoCurrent') && inst.currentDay ? currentDate : today);
14621498
currentText = (!navigationAsDateFormat ? currentText :
14631499
this.formatDate(currentText, gotoDate, this._getFormatConfig(inst)));
1464-
var controls = (!inst.inline ? '<button type="button" class="ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all" onclick="DP_jQuery_' + dpuuid +
1465-
'.datepicker._hideDatepicker();">' + this._get(inst, 'closeText') + '</button>' : '');
1500+
var controls = (!inst.inline ? '<button type="button" class="ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all" data-handler="hide" data-event="click">' +
1501+
this._get(inst, 'closeText') + '</button>' : '');
14661502
var buttonPanel = (showButtonPanel) ? '<div class="ui-datepicker-buttonpane ui-widget-content">' + (isRTL ? controls : '') +
1467-
(this._isInRange(inst, gotoDate) ? '<button type="button" class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" onclick="DP_jQuery_' + dpuuid +
1468-
'.datepicker._gotoToday(\'#' + inst.id + '\');"' +
1503+
(this._isInRange(inst, gotoDate) ? '<button type="button" class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" data-handler="today" data-event="click"' +
14691504
'>' + currentText + '</button>' : '') + (isRTL ? '' : controls) + '</div>' : '';
14701505
var firstDay = parseInt(this._get(inst, 'firstDay'),10);
14711506
firstDay = (isNaN(firstDay) ? 0 : firstDay);
@@ -1544,8 +1579,7 @@ $.extend(Datepicker.prototype, {
15441579
(printDate.getTime() == currentDate.getTime() ? ' ' + this._currentClass : '') + // highlight selected day
15451580
(printDate.getTime() == today.getTime() ? ' ui-datepicker-today' : '')) + '"' + // highlight today (if different)
15461581
((!otherMonth || showOtherMonths) && daySettings[2] ? ' title="' + daySettings[2] + '"' : '') + // cell title
1547-
(unselectable ? '' : ' onclick="DP_jQuery_' + dpuuid + '.datepicker._selectDay(\'#' +
1548-
inst.id + '\',' + printDate.getMonth() + ',' + printDate.getFullYear() + ', this);return false;"') + '>' + // actions
1582+
(unselectable ? '' : ' data-handler="selectDay" data-event="click" data-month="' + printDate.getMonth() + '" data-year="' + printDate.getFullYear() + '"') + '>' + // actions
15491583
(otherMonth && !showOtherMonths ? '&#xa0;' : // display for other months
15501584
(unselectable ? '<span class="ui-state-default">' + printDate.getDate() + '</span>' : '<a class="ui-state-default' +
15511585
(printDate.getTime() == today.getTime() ? ' ui-state-highlight' : '') +
@@ -1588,9 +1622,7 @@ $.extend(Datepicker.prototype, {
15881622
else {
15891623
var inMinYear = (minDate && minDate.getFullYear() == drawYear);
15901624
var inMaxYear = (maxDate && maxDate.getFullYear() == drawYear);
1591-
monthHtml += '<select class="ui-datepicker-month" ' +
1592-
'onchange="DP_jQuery_' + dpuuid + '.datepicker._selectMonthYear(\'#' + inst.id + '\', this, \'M\');" ' +
1593-
'>';
1625+
monthHtml += '<select class="ui-datepicker-month" data-handler="selectMonth" data-event="change">';
15941626
for (var month = 0; month < 12; month++) {
15951627
if ((!inMinYear || month >= minDate.getMonth()) &&
15961628
(!inMaxYear || month <= maxDate.getMonth()))
@@ -1621,9 +1653,7 @@ $.extend(Datepicker.prototype, {
16211653
var endYear = Math.max(year, determineYear(years[1] || ''));
16221654
year = (minDate ? Math.max(year, minDate.getFullYear()) : year);
16231655
endYear = (maxDate ? Math.min(endYear, maxDate.getFullYear()) : endYear);
1624-
inst.yearshtml += '<select class="ui-datepicker-year" ' +
1625-
'onchange="DP_jQuery_' + dpuuid + '.datepicker._selectMonthYear(\'#' + inst.id + '\', this, \'Y\');" ' +
1626-
'>';
1656+
inst.yearshtml += '<select class="ui-datepicker-year" data-handler="selectYear" data-event="change">';
16271657
for (; year <= endYear; year++) {
16281658
inst.yearshtml += '<option value="' + year + '"' +
16291659
(year == drawYear ? ' selected="selected"' : '') +

0 commit comments

Comments
 (0)