@@ -715,6 +715,7 @@ $.extend(Datepicker.prototype, {
715
715
var borders = $ . datepicker . _getBorders ( inst . dpDiv ) ;
716
716
instActive = inst ; // for delegate hover events
717
717
inst . dpDiv . empty ( ) . append ( this . _generateHTML ( inst ) ) ;
718
+ this . _attachHandlers ( inst ) ;
718
719
var cover = inst . dpDiv . find ( 'iframe.ui-datepicker-cover' ) ; // IE6- only
719
720
if ( ! ! cover . length ) { //avoid call to outerXXXX() when not in IE6
720
721
cover . css ( { left : - borders [ 0 ] , top : - borders [ 1 ] , width : inst . dpDiv . outerWidth ( ) , height : inst . dpDiv . outerHeight ( ) } )
@@ -1408,6 +1409,43 @@ $.extend(Datepicker.prototype, {
1408
1409
return startDate ;
1409
1410
} ,
1410
1411
1412
+ /* Attach the onxxx handlers. These are declared statically so
1413
+ * they work with static code transformers like Caja.
1414
+ */
1415
+ _attachHandlers : function ( inst ) {
1416
+ var stepMonths = this . _get ( inst , 'stepMonths' ) ;
1417
+ var id = '#' + inst . id ;
1418
+ inst . dpDiv . find ( '[data-handler]' ) . map ( function ( ) {
1419
+ var handler = {
1420
+ prev : function ( ) {
1421
+ window [ 'DP_jQuery_' + dpuuid ] . datepicker . _adjustDate ( id , - stepMonths , 'M' ) ;
1422
+ } ,
1423
+ next : function ( ) {
1424
+ window [ 'DP_jQuery_' + dpuuid ] . datepicker . _adjustDate ( id , + stepMonths , 'M' ) ;
1425
+ } ,
1426
+ hide : function ( ) {
1427
+ window [ 'DP_jQuery_' + dpuuid ] . datepicker . _hideDatepicker ( ) ;
1428
+ } ,
1429
+ today : function ( ) {
1430
+ window [ 'DP_jQuery_' + dpuuid ] . datepicker . _gotoToday ( id ) ;
1431
+ } ,
1432
+ selectDay : function ( ) {
1433
+ window [ 'DP_jQuery_' + dpuuid ] . datepicker . _selectDay ( id , + this . getAttribute ( 'data-month' ) , + this . getAttribute ( 'data-year' ) , this ) ;
1434
+ return false ;
1435
+ } ,
1436
+ selectMonth : function ( ) {
1437
+ window [ 'DP_jQuery_' + dpuuid ] . datepicker . _selectMonthYear ( id , this , 'M' ) ;
1438
+ return false ;
1439
+ } ,
1440
+ selectYear : function ( ) {
1441
+ window [ 'DP_jQuery_' + dpuuid ] . datepicker . _selectMonthYear ( id , this , 'Y' ) ;
1442
+ return false ;
1443
+ }
1444
+ } ;
1445
+ $ ( this ) . bind ( this . getAttribute ( 'data-event' ) , handler [ this . getAttribute ( 'data-handler' ) ] ) ;
1446
+ } ) ;
1447
+ } ,
1448
+
1411
1449
/* Generate the HTML for the current state of the date picker. */
1412
1450
_generateHTML : function ( inst ) {
1413
1451
var today = new Date ( ) ;
@@ -1450,28 +1488,25 @@ $.extend(Datepicker.prototype, {
1450
1488
this . _daylightSavingAdjust ( new Date ( drawYear , drawMonth - stepMonths , 1 ) ) ,
1451
1489
this . _getFormatConfig ( inst ) ) ) ;
1452
1490
var prev = ( this . _canAdjustMonth ( inst , - 1 , drawYear , drawMonth ) ?
1453
- '<a class="ui-datepicker-prev ui-corner-all" onclick="DP_jQuery_' + dpuuid +
1454
- '.datepicker._adjustDate(\'#' + inst . id + '\', -' + stepMonths + ', \'M\');"' +
1491
+ '<a class="ui-datepicker-prev ui-corner-all" data-handler="prev" data-event="click"' +
1455
1492
' title="' + prevText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'e' : 'w' ) + '">' + prevText + '</span></a>' :
1456
1493
( 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>' ) ) ;
1457
1494
var nextText = this . _get ( inst , 'nextText' ) ;
1458
1495
nextText = ( ! navigationAsDateFormat ? nextText : this . formatDate ( nextText ,
1459
1496
this . _daylightSavingAdjust ( new Date ( drawYear , drawMonth + stepMonths , 1 ) ) ,
1460
1497
this . _getFormatConfig ( inst ) ) ) ;
1461
1498
var next = ( this . _canAdjustMonth ( inst , + 1 , drawYear , drawMonth ) ?
1462
- '<a class="ui-datepicker-next ui-corner-all" onclick="DP_jQuery_' + dpuuid +
1463
- '.datepicker._adjustDate(\'#' + inst . id + '\', +' + stepMonths + ', \'M\');"' +
1499
+ '<a class="ui-datepicker-next ui-corner-all" data-handler="next" data-event="click"' +
1464
1500
' title="' + nextText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'w' : 'e' ) + '">' + nextText + '</span></a>' :
1465
1501
( 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>' ) ) ;
1466
1502
var currentText = this . _get ( inst , 'currentText' ) ;
1467
1503
var gotoDate = ( this . _get ( inst , 'gotoCurrent' ) && inst . currentDay ? currentDate : today ) ;
1468
1504
currentText = ( ! navigationAsDateFormat ? currentText :
1469
1505
this . formatDate ( currentText , gotoDate , this . _getFormatConfig ( inst ) ) ) ;
1470
- var controls = ( ! inst . inline ? '<button type="button" class="ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all" onclick="DP_jQuery_' + dpuuid +
1471
- '.datepicker._hideDatepicker();">' + this . _get ( inst , 'closeText' ) + '</button>' : '' ) ;
1506
+ 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">' +
1507
+ this . _get ( inst , 'closeText' ) + '</button>' : '' ) ;
1472
1508
var buttonPanel = ( showButtonPanel ) ? '<div class="ui-datepicker-buttonpane ui-widget-content">' + ( isRTL ? controls : '' ) +
1473
- ( this . _isInRange ( inst , gotoDate ) ? '<button type="button" class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" onclick="DP_jQuery_' + dpuuid +
1474
- '.datepicker._gotoToday(\'#' + inst . id + '\');"' +
1509
+ ( 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"' +
1475
1510
'>' + currentText + '</button>' : '' ) + ( isRTL ? '' : controls ) + '</div>' : '' ;
1476
1511
var firstDay = parseInt ( this . _get ( inst , 'firstDay' ) , 10 ) ;
1477
1512
firstDay = ( isNaN ( firstDay ) ? 0 : firstDay ) ;
@@ -1550,8 +1585,7 @@ $.extend(Datepicker.prototype, {
1550
1585
( printDate . getTime ( ) == currentDate . getTime ( ) ? ' ' + this . _currentClass : '' ) + // highlight selected day
1551
1586
( printDate . getTime ( ) == today . getTime ( ) ? ' ui-datepicker-today' : '' ) ) + '"' + // highlight today (if different)
1552
1587
( ( ! otherMonth || showOtherMonths ) && daySettings [ 2 ] ? ' title="' + daySettings [ 2 ] + '"' : '' ) + // cell title
1553
- ( unselectable ? '' : ' onclick="DP_jQuery_' + dpuuid + '.datepicker._selectDay(\'#' +
1554
- inst . id + '\',' + printDate . getMonth ( ) + ',' + printDate . getFullYear ( ) + ', this);return false;"' ) + '>' + // actions
1588
+ ( unselectable ? '' : ' data-handler="selectDay" data-event="click" data-month="' + printDate . getMonth ( ) + '" data-year="' + printDate . getFullYear ( ) + '"' ) + '>' + // actions
1555
1589
( otherMonth && ! showOtherMonths ? ' ' : // display for other months
1556
1590
( unselectable ? '<span class="ui-state-default">' + printDate . getDate ( ) + '</span>' : '<a class="ui-state-default' +
1557
1591
( printDate . getTime ( ) == today . getTime ( ) ? ' ui-state-highlight' : '' ) +
@@ -1594,9 +1628,7 @@ $.extend(Datepicker.prototype, {
1594
1628
else {
1595
1629
var inMinYear = ( minDate && minDate . getFullYear ( ) == drawYear ) ;
1596
1630
var inMaxYear = ( maxDate && maxDate . getFullYear ( ) == drawYear ) ;
1597
- monthHtml += '<select class="ui-datepicker-month" ' +
1598
- 'onchange="DP_jQuery_' + dpuuid + '.datepicker._selectMonthYear(\'#' + inst . id + '\', this, \'M\');" ' +
1599
- '>' ;
1631
+ monthHtml += '<select class="ui-datepicker-month" data-handler="selectMonth" data-event="change">' ;
1600
1632
for ( var month = 0 ; month < 12 ; month ++ ) {
1601
1633
if ( ( ! inMinYear || month >= minDate . getMonth ( ) ) &&
1602
1634
( ! inMaxYear || month <= maxDate . getMonth ( ) ) )
@@ -1627,9 +1659,7 @@ $.extend(Datepicker.prototype, {
1627
1659
var endYear = Math . max ( year , determineYear ( years [ 1 ] || '' ) ) ;
1628
1660
year = ( minDate ? Math . max ( year , minDate . getFullYear ( ) ) : year ) ;
1629
1661
endYear = ( maxDate ? Math . min ( endYear , maxDate . getFullYear ( ) ) : endYear ) ;
1630
- inst . yearshtml += '<select class="ui-datepicker-year" ' +
1631
- 'onchange="DP_jQuery_' + dpuuid + '.datepicker._selectMonthYear(\'#' + inst . id + '\', this, \'Y\');" ' +
1632
- '>' ;
1662
+ inst . yearshtml += '<select class="ui-datepicker-year" data-handler="selectYear" data-event="change">' ;
1633
1663
for ( ; year <= endYear ; year ++ ) {
1634
1664
inst . yearshtml += '<option value="' + year + '"' +
1635
1665
( year == drawYear ? ' selected="selected"' : '' ) +
0 commit comments