data-api.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. module('DATA-API');
  2. test('DATA-API: data-provide="datepicker" on input; focus', function(){
  3. var input = $('<input data-provide="datepicker" />')
  4. .appendTo('#qunit-fixture');
  5. input.focus();
  6. ok(input.data('datepicker'), 'datepicker is initialized by "focus" event');
  7. });
  8. test('DATA-API: data-provide="datepicker" on input; click', function(){
  9. var input = $('<input data-provide="datepicker" />')
  10. .appendTo('#qunit-fixture');
  11. input.click();
  12. ok(input.data('datepicker'), 'datepicker is initialized by "focus" event');
  13. });
  14. test('DATA-API: data-provide="datepicker" on component', function(){
  15. var html, comp;
  16. html = '<div class="input-append date" data-provide="datepicker">'+
  17. '<input><span class="add-on"><i class="icon-th"></i></span>'+
  18. '</div>';
  19. comp = $(html).appendTo('#qunit-fixture');
  20. comp.find('input').focus();
  21. ok(comp.data('datepicker'), 'append component initialized by "focus" event on input');
  22. comp.remove();
  23. comp = $(html).appendTo('#qunit-fixture');
  24. comp.find('input').click();
  25. ok(comp.data('datepicker'), 'append component initialized by "click" event on input');
  26. comp.remove();
  27. comp = $(html).appendTo('#qunit-fixture');
  28. comp.find('.add-on').focus();
  29. ok(comp.data('datepicker'), 'append component initialized by "focus" event on add-on');
  30. comp.remove();
  31. comp = $(html).appendTo('#qunit-fixture');
  32. comp.find('.add-on').click();
  33. ok(comp.data('datepicker'), 'append component initialized by "click" event on add-on');
  34. comp.remove();
  35. html = '<div class="input-prepend date" data-provide="datepicker">'+
  36. '<span class="add-on"><i class="icon-th"></i></span><input>'+
  37. '</div>';
  38. comp = $(html).prependTo('#qunit-fixture');
  39. comp.find('input').focus();
  40. ok(comp.data('datepicker'), 'prepend component initialized by "focus" event on input');
  41. comp.remove();
  42. comp = $(html).prependTo('#qunit-fixture');
  43. comp.find('input').click();
  44. ok(comp.data('datepicker'), 'prepend component initialized by "click" event on input');
  45. comp.remove();
  46. comp = $(html).prependTo('#qunit-fixture');
  47. comp.find('.add-on').focus();
  48. ok(comp.data('datepicker'), 'prepend component initialized by "focus" event on add-on');
  49. comp.remove();
  50. comp = $(html).prependTo('#qunit-fixture');
  51. comp.find('.add-on').click();
  52. ok(comp.data('datepicker'), 'prepend component initialized by "click" event on add-on');
  53. comp.remove();
  54. });
  55. test('DATA-API: data-provide="datepicker" on button', function(){
  56. var html, comp;
  57. html = '<button data-provide="datepicker">';
  58. comp = $(html).appendTo('#qunit-fixture');
  59. comp.focus();
  60. ok(comp.data('datepicker'), 'button initialized by "focus" event on input');
  61. comp.remove();
  62. comp = $(html).appendTo('#qunit-fixture');
  63. comp.click();
  64. ok(comp.data('datepicker'), 'button initialized by "click" event on input');
  65. comp.remove();
  66. });
  67. test('DATA-API: data-provide="datepicker" on rangepicker', function(){
  68. var html, comp;
  69. html = '<div class="input-daterange" data-provide="datepicker">'+
  70. '<input class="datepicker">'+
  71. '<span class="add-on">to</span>'+
  72. '<input class="datepicker">'+
  73. '</div>';
  74. comp = $(html).appendTo('#qunit-fixture');
  75. comp.find('input:first').focus();
  76. ok(comp.data('datepicker'), 'range initialized by "focus" event on first input');
  77. comp.remove();
  78. comp = $(html).appendTo('#qunit-fixture');
  79. comp.find('input:first').click();
  80. ok(comp.data('datepicker'), 'range initialized by "click" event on first input');
  81. comp.remove();
  82. comp = $(html).appendTo('#qunit-fixture');
  83. comp.find('input:last').focus();
  84. ok(comp.data('datepicker'), 'range initialized by "focus" event on last input');
  85. comp.remove();
  86. comp = $(html).appendTo('#qunit-fixture');
  87. comp.find('input:last').click();
  88. ok(comp.data('datepicker'), 'range initialized by "click" event on last input');
  89. comp.remove();
  90. });