return inp;\r
}\r
\r
+var PROP_NAME = 'datepicker';\r
+\r
test('setDefaults', function() {\r
var inp = init('#inp');\r
+ var dp = $('#ui-datepicker-div');\r
+ ok(!dp.is(':visible'), 'Initially invisible');\r
ok(inp.is('.hasDatepicker'), 'Marker class set');\r
- ok($($.datepicker._datepickerDiv).html() == '', 'Content empty');\r
+ ok($($.datepicker.dpDiv).html() == '', 'Content empty');\r
inp.datepicker('show');\r
- ok($($.datepicker._datepickerDiv).html() != '', 'Content present');\r
+ ok($($.datepicker.dpDiv).html() != '', 'Content present');\r
inp.datepicker('hide');\r
equals($.datepicker._defaults.showOn, 'focus', 'Initial showOn');\r
$.datepicker.setDefaults({showOn: 'button'});\r
test('remove', function() {\r
var rem = init('#rem');\r
ok(rem.is('.hasDatepicker'), 'Marker class set');\r
- ok(rem[0]._calId, 'Datepicker ID present');\r
+ ok($.data(rem[0], PROP_NAME), 'Datepicker instance present');\r
rem.datepicker('destroy');\r
rem = $('#rem');\r
ok(!rem.is('.hasDatepicker'), 'Marker class cleared');\r
- ok(!rem[0]._calId, 'Datepicker ID absent');\r
+ ok(!$.data(rem[0], PROP_NAME), 'Datepicker instance absent');\r
rem.datepicker({showOn: 'both', buttonImage: 'img/calendar.gif'});\r
ok(rem.is('.hasDatepicker'), 'Marker class set');\r
- ok(rem[0]._calId, 'Datepicker ID present');\r
- ok(rem.parent('.ui-datepicker-wrap').length != 0, 'Wrapper present');\r
+ ok($.data(rem[0], PROP_NAME), 'Datepicker instance present');\r
rem.datepicker('destroy');\r
rem = $('#rem');\r
ok(!rem.is('.hasDatepicker'), 'Marker class cleared');\r
- ok(!rem[0]._calId, 'Datepicker ID absent');\r
- ok(rem.parent('.ui-datepicker-wrap').length == 0, 'Wrapper absent');\r
+ ok(!$.data(rem[0], PROP_NAME), 'Datepicker instance absent');\r
});\r
\r
test('change', function() {\r
var inp = init('#inp');\r
- var inst = $.datepicker._inst[inp[0]._calId];\r
- equals(inst._settings.showOn, null, 'Initial setting showOn');\r
- equals(inst._get('showOn'), 'focus', 'Initial instance showOn');\r
+ var inst = $.data(inp[0], PROP_NAME);\r
+ equals(inst.settings.showOn, null, 'Initial setting showOn');\r
+ equals($.datepicker._get(inst, 'showOn'), 'focus', 'Initial instance showOn');\r
equals($.datepicker._defaults.showOn, 'focus', 'Initial default showOn');\r
inp.datepicker('change', 'showOn', 'button');\r
- equals(inst._settings.showOn, 'button', 'Change setting showOn');\r
- equals(inst._get('showOn'), 'button', 'Change instance showOn');\r
+ equals(inst.settings.showOn, 'button', 'Change setting showOn');\r
+ equals($.datepicker._get(inst, 'showOn'), 'button', 'Change instance showOn');\r
equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn');\r
inp.datepicker('change', {showOn: 'both'});\r
- equals(inst._settings.showOn, 'both', 'Change setting showOn');\r
- equals(inst._get('showOn'), 'both', 'Change instance showOn');\r
+ equals(inst.settings.showOn, 'both', 'Change setting showOn');\r
+ equals($.datepicker._get(inst, 'showOn'), 'both', 'Change instance showOn');\r
equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn');\r
inp.datepicker('change', 'showOn', undefined);\r
- equals(inst._settings.showOn, null, 'Clear setting showOn');\r
- equals(inst._get('showOn'), 'focus', 'Restore instance showOn');\r
+ equals(inst.settings.showOn, null, 'Clear setting showOn');\r
+ equals($.datepicker._get(inst, 'showOn'), 'focus', 'Restore instance showOn');\r
equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn');\r
});\r
\r
var dp = $('#ui-datepicker-div');\r
var body = $('body');\r
// On focus\r
- ok(!dp.is(':visible'), 'Focus - initially invisible');\r
- ok(inp.parent('.ui-datepicker-wrap').length == 0, 'Focus - wrapper absent');\r
var button = inp.siblings('button');\r
ok(button.length == 0, 'Focus - button absent');\r
var image = inp.siblings('img');\r
inp.datepicker({speed: '', showOn: 'button', buttonText: 'Popup'});\r
ok(!dp.is(':visible'), 'Button - initially hidden');\r
button = inp.siblings('button');\r
- ok(inp.parent('.ui-datepicker-wrap').length != 0, 'Button - wrapper present');\r
image = inp.siblings('img');\r
ok(button.length == 1, 'Button - button present');\r
ok(image.length == 0, 'Button - image absent');\r
inp.datepicker({speed: '', showOn: 'button', buttonImageOnly: true,\r
buttonImage: 'img/calendar.gif', buttonText: 'Cal'});\r
ok(!dp.is(':visible'), 'Image button - initially hidden');\r
- ok(inp.parent('.ui-datepicker-wrap').length != 0, 'Image button - wrapper present');\r
button = inp.siblings('button');\r
ok(button.length == 0, 'Image button - button absent');\r
image = inp.siblings('img');\r
inp = $('#inp');\r
inp.datepicker({speed: '', showOn: 'both', buttonImage: 'img/calendar.gif'});\r
ok(!dp.is(':visible'), 'Both - initially hidden');\r
- ok(inp.parent('.ui-datepicker-wrap').length != 0, 'Both - wrapper present');\r
button = inp.siblings('button');\r
ok(button.length == 1, 'Both - button present');\r
image = inp.siblings('img');\r
equalsDate(inp.datepicker('getDate'), date, 'Min/max - -1w, +1 M +10 D - ctrl+pgdn');\r
});\r
\r
+test('setDate', function() {\r
+ var inp = init('#inp');\r
+ var date1 = new Date(2008, 6 - 1, 4);\r
+ var date2 = new Date();\r
+ inp.datepicker('setDate', date1);\r
+ equalsDate(inp.datepicker('getDate'), date1, 'Set date - 2008-06-04');\r
+ date1 = new Date();\r
+ date1.setDate(date1.getDate() + 7);\r
+ inp.datepicker('setDate', +7);\r
+ equalsDate(inp.datepicker('getDate'), date1, 'Set date - +7');\r
+ date2.setFullYear(date2.getFullYear() + 2);\r
+ inp.datepicker('setDate', '+2y');\r
+ equalsDate(inp.datepicker('getDate'), date2, 'Set date - +2y');\r
+ inp.datepicker('setDate', date1, date2);\r
+ equalsDate(inp.datepicker('getDate'), date1, 'Set date - two dates');\r
+ inp.datepicker('setDate');\r
+ ok(inp.datepicker('getDate') == null, 'Set date - null');\r
+ // Ranges\r
+ date1 = new Date(2008, 6 - 1, 4);\r
+ date2 = new Date(2009, 7 - 1, 5);\r
+ inp.datepicker('change', {rangeSelect: true});\r
+ inp.datepicker('setDate', date1, date2);\r
+ equalsDateArray(inp.datepicker('getDate'), [date1, date2], 'Set date range - 2008-06-04 - 2009-07-05');\r
+ inp.datepicker('setDate', date1);\r
+ equalsDateArray(inp.datepicker('getDate'), [date1, date1], 'Set date range - 2008-06-04');\r
+ date1 = new Date();\r
+ date1.setDate(date1.getDate() - 10);\r
+ date2 = new Date();\r
+ date2.setDate(date2.getDate() + 10);\r
+ inp.datepicker('setDate', -10, +10);\r
+ equalsDateArray(inp.datepicker('getDate'), [date1, date2], 'Set date range - -10 - +10');\r
+ inp.datepicker('setDate', -10);\r
+ equalsDateArray(inp.datepicker('getDate'), [date1, date1], 'Set date range - -10');\r
+ date1 = new Date();\r
+ date1.setDate(date1.getDate() - 14);\r
+ date2 = new Date();\r
+ date2.setFullYear(date2.getFullYear() + 1);\r
+ inp.datepicker('setDate', '-2w', '+1Y');\r
+ equalsDateArray(inp.datepicker('getDate'), [date1, date2], 'Set date range - -2w - +1Y');\r
+ inp.datepicker('setDate', '-2w');\r
+ equalsDateArray(inp.datepicker('getDate'), [date1, date1], 'Set date range - -2w');\r
+ inp.datepicker('setDate');\r
+ isObj(inp.datepicker('getDate'), [null, null], 'Set date range - null');\r
+});\r
+\r
test('ranges', function() {\r
var inp = init('#inp', {rangeSelect: true});\r
var d1 = new Date();\r
inp.val('').datepicker('show');\r
inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER});\r
equals(selectedThis, inp[0], 'Callback selected this');\r
- equals(selectedInst, $.datepicker._getInst(inp[0]._calId), 'Callback selected inst');\r
+ equals(selectedInst, $.data(inp[0], PROP_NAME), 'Callback selected inst');\r
equals(selectedDate, $.datepicker.formatDate('mm/dd/yy', date), 'Callback selected date');\r
inp.val('').datepicker('show');\r
inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_DOWN}).\r
inp.simulate('keydown', {keyCode: $.simulate.VK_PGUP});\r
date.setMonth(date.getMonth() - 1);\r
equals(selectedThis, inp[0], 'Callback change month/year this');\r
- equals(selectedInst, $.datepicker._getInst(inp[0]._calId), 'Callback change month/year inst');\r
+ equals(selectedInst, $.data(inp[0], PROP_NAME), 'Callback change month/year inst');\r
equalsDate(selectedDate, date, 'Callback change month/year date - pgup');\r
inp.simulate('keydown', {keyCode: $.simulate.VK_PGDN});\r
date.setMonth(date.getMonth() + 1);\r
val('').datepicker('show');\r
inp.simulate('keydown', {keyCode: $.simulate.VK_ESC});\r
equals(selectedThis, inp[0], 'Callback close this');\r
- equals(selectedInst, $.datepicker._getInst(inp[0]._calId), 'Callback close inst');\r
+ equals(selectedInst, $.data(inp[0], PROP_NAME), 'Callback close inst');\r
ok(selectedDate == null, 'Callback close date - esc');\r
inp.val('').datepicker('show');\r
inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER});\r