@@ -714,6 +714,7 @@ $.extend(Datepicker.prototype, {
714
714
var borders = $ . datepicker . _getBorders ( inst . dpDiv ) ;
715
715
instActive = inst ; // for delegate hover events
716
716
inst . dpDiv . empty ( ) . append ( this . _generateHTML ( inst ) ) ;
717
+ this . _attachHandlers ( inst ) ;
717
718
var cover = inst . dpDiv . find ( 'iframe.ui-datepicker-cover' ) ; // IE6- only
718
719
if ( ! ! cover . length ) { //avoid call to outerXXXX() when not in IE6
719
720
cover . css ( { left : - borders [ 0 ] , top : - borders [ 1 ] , width : inst . dpDiv . outerWidth ( ) , height : inst . dpDiv . outerHeight ( ) } )
@@ -1402,6 +1403,43 @@ $.extend(Datepicker.prototype, {
1402
1403
return startDate ;
1403
1404
} ,
1404
1405
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
+
1405
1443
/* Generate the HTML for the current state of the date picker. */
1406
1444
_generateHTML : function ( inst ) {
1407
1445
var today = new Date ( ) ;
@@ -1444,28 +1482,25 @@ $.extend(Datepicker.prototype, {
1444
1482
this . _daylightSavingAdjust ( new Date ( drawYear , drawMonth - stepMonths , 1 ) ) ,
1445
1483
this . _getFormatConfig ( inst ) ) ) ;
1446
1484
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"' +
1449
1486
' title="' + prevText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'e' : 'w' ) + '">' + prevText + '</span></a>' :
1450
1487
( 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>' ) ) ;
1451
1488
var nextText = this . _get ( inst , 'nextText' ) ;
1452
1489
nextText = ( ! navigationAsDateFormat ? nextText : this . formatDate ( nextText ,
1453
1490
this . _daylightSavingAdjust ( new Date ( drawYear , drawMonth + stepMonths , 1 ) ) ,
1454
1491
this . _getFormatConfig ( inst ) ) ) ;
1455
1492
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"' +
1458
1494
' title="' + nextText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'w' : 'e' ) + '">' + nextText + '</span></a>' :
1459
1495
( 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>' ) ) ;
1460
1496
var currentText = this . _get ( inst , 'currentText' ) ;
1461
1497
var gotoDate = ( this . _get ( inst , 'gotoCurrent' ) && inst . currentDay ? currentDate : today ) ;
1462
1498
currentText = ( ! navigationAsDateFormat ? currentText :
1463
1499
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>' : '' ) ;
1466
1502
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"' +
1469
1504
'>' + currentText + '</button>' : '' ) + ( isRTL ? '' : controls ) + '</div>' : '' ;
1470
1505
var firstDay = parseInt ( this . _get ( inst , 'firstDay' ) , 10 ) ;
1471
1506
firstDay = ( isNaN ( firstDay ) ? 0 : firstDay ) ;
@@ -1544,8 +1579,7 @@ $.extend(Datepicker.prototype, {
1544
1579
( printDate . getTime ( ) == currentDate . getTime ( ) ? ' ' + this . _currentClass : '' ) + // highlight selected day
1545
1580
( printDate . getTime ( ) == today . getTime ( ) ? ' ui-datepicker-today' : '' ) ) + '"' + // highlight today (if different)
1546
1581
( ( ! 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
1549
1583
( otherMonth && ! showOtherMonths ? ' ' : // display for other months
1550
1584
( unselectable ? '<span class="ui-state-default">' + printDate . getDate ( ) + '</span>' : '<a class="ui-state-default' +
1551
1585
( printDate . getTime ( ) == today . getTime ( ) ? ' ui-state-highlight' : '' ) +
@@ -1588,9 +1622,7 @@ $.extend(Datepicker.prototype, {
1588
1622
else {
1589
1623
var inMinYear = ( minDate && minDate . getFullYear ( ) == drawYear ) ;
1590
1624
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">' ;
1594
1626
for ( var month = 0 ; month < 12 ; month ++ ) {
1595
1627
if ( ( ! inMinYear || month >= minDate . getMonth ( ) ) &&
1596
1628
( ! inMaxYear || month <= maxDate . getMonth ( ) ) )
@@ -1621,9 +1653,7 @@ $.extend(Datepicker.prototype, {
1621
1653
var endYear = Math . max ( year , determineYear ( years [ 1 ] || '' ) ) ;
1622
1654
year = ( minDate ? Math . max ( year , minDate . getFullYear ( ) ) : year ) ;
1623
1655
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">' ;
1627
1657
for ( ; year <= endYear ; year ++ ) {
1628
1658
inst . yearshtml += '<option value="' + year + '"' +
1629
1659
( year == drawYear ? ' selected="selected"' : '' ) +
0 commit comments