bootstrap-datepicker 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. data/.gitignore +7 -0
  2. data/.hgignore +3 -0
  3. data/.hgtags +9 -0
  4. data/.travis.yml +4 -0
  5. data/CHANGELOG.md +89 -0
  6. data/CONTRIBUTING.md +40 -0
  7. data/Gemfile +4 -0
  8. data/Gruntfile.js +165 -0
  9. data/LICENSE +202 -0
  10. data/README.md +24 -0
  11. data/Rakefile +1 -0
  12. data/bootstrap-datepicker.gemspec +26 -0
  13. data/bower.json +9 -0
  14. data/build/build.less +67 -0
  15. data/build/build3.less +71 -0
  16. data/build/build_standalone.less +61 -0
  17. data/build/build_standalone3.less +63 -0
  18. data/composer.json +19 -0
  19. data/css/datepicker.css +509 -0
  20. data/css/datepicker3.css +790 -0
  21. data/docs/Makefile +153 -0
  22. data/docs/REAME.md +8 -0
  23. data/docs/_static/demo_head.png +0 -0
  24. data/docs/conf.py +248 -0
  25. data/docs/events.rst +48 -0
  26. data/docs/i18n.rst +28 -0
  27. data/docs/index.rst +122 -0
  28. data/docs/keyboard.rst +30 -0
  29. data/docs/make.bat +190 -0
  30. data/docs/markup.rst +50 -0
  31. data/docs/methods.rst +156 -0
  32. data/docs/options.rst +191 -0
  33. data/js/bootstrap-datepicker.js +1609 -0
  34. data/js/locales/bootstrap-datepicker.ar.js +15 -0
  35. data/js/locales/bootstrap-datepicker.bg.js +14 -0
  36. data/js/locales/bootstrap-datepicker.ca.js +14 -0
  37. data/js/locales/bootstrap-datepicker.cs.js +15 -0
  38. data/js/locales/bootstrap-datepicker.cy.js +14 -0
  39. data/js/locales/bootstrap-datepicker.da.js +15 -0
  40. data/js/locales/bootstrap-datepicker.de.js +17 -0
  41. data/js/locales/bootstrap-datepicker.el.js +13 -0
  42. data/js/locales/bootstrap-datepicker.es.js +14 -0
  43. data/js/locales/bootstrap-datepicker.et.js +18 -0
  44. data/js/locales/bootstrap-datepicker.fa.js +17 -0
  45. data/js/locales/bootstrap-datepicker.fi.js +16 -0
  46. data/js/locales/bootstrap-datepicker.fr.js +17 -0
  47. data/js/locales/bootstrap-datepicker.gl.js +11 -0
  48. data/js/locales/bootstrap-datepicker.he.js +15 -0
  49. data/js/locales/bootstrap-datepicker.hr.js +13 -0
  50. data/js/locales/bootstrap-datepicker.hu.js +16 -0
  51. data/js/locales/bootstrap-datepicker.id.js +15 -0
  52. data/js/locales/bootstrap-datepicker.is.js +14 -0
  53. data/js/locales/bootstrap-datepicker.it.js +16 -0
  54. data/js/locales/bootstrap-datepicker.ja.js +15 -0
  55. data/js/locales/bootstrap-datepicker.ka.js +17 -0
  56. data/js/locales/bootstrap-datepicker.kk.js +15 -0
  57. data/js/locales/bootstrap-datepicker.kr.js +13 -0
  58. data/js/locales/bootstrap-datepicker.lt.js +16 -0
  59. data/js/locales/bootstrap-datepicker.lv.js +16 -0
  60. data/js/locales/bootstrap-datepicker.mk.js +15 -0
  61. data/js/locales/bootstrap-datepicker.ms.js +14 -0
  62. data/js/locales/bootstrap-datepicker.nb.js +14 -0
  63. data/js/locales/bootstrap-datepicker.nl-BE.js +17 -0
  64. data/js/locales/bootstrap-datepicker.nl.js +14 -0
  65. data/js/locales/bootstrap-datepicker.no.js +16 -0
  66. data/js/locales/bootstrap-datepicker.pl.js +15 -0
  67. data/js/locales/bootstrap-datepicker.pt-BR.js +15 -0
  68. data/js/locales/bootstrap-datepicker.pt.js +16 -0
  69. data/js/locales/bootstrap-datepicker.ro.js +15 -0
  70. data/js/locales/bootstrap-datepicker.rs-latin.js +14 -0
  71. data/js/locales/bootstrap-datepicker.rs.js +14 -0
  72. data/js/locales/bootstrap-datepicker.ru.js +15 -0
  73. data/js/locales/bootstrap-datepicker.sk.js +15 -0
  74. data/js/locales/bootstrap-datepicker.sl.js +14 -0
  75. data/js/locales/bootstrap-datepicker.sq.js +15 -0
  76. data/js/locales/bootstrap-datepicker.sv.js +16 -0
  77. data/js/locales/bootstrap-datepicker.sw.js +15 -0
  78. data/js/locales/bootstrap-datepicker.th.js +14 -0
  79. data/js/locales/bootstrap-datepicker.tr.js +16 -0
  80. data/js/locales/bootstrap-datepicker.ua.js +15 -0
  81. data/js/locales/bootstrap-datepicker.uk.js +14 -0
  82. data/js/locales/bootstrap-datepicker.vi.js +16 -0
  83. data/js/locales/bootstrap-datepicker.zh-CN.js +16 -0
  84. data/js/locales/bootstrap-datepicker.zh-TW.js +17 -0
  85. data/less/datepicker.less +265 -0
  86. data/less/datepicker3.less +252 -0
  87. data/lib/bootstrap-datepicker.rb +11 -0
  88. data/lib/bootstrap-datepicker/version.rb +9 -0
  89. data/package.json +32 -0
  90. data/sass/build_standalone-sass.scss +70 -0
  91. data/sass/datepicker.scss +270 -0
  92. data/test/Readme.md +9 -0
  93. data/test/less_test.js +19 -0
  94. data/test/scss_test.js +19 -0
  95. data/test/support/less.patch +4 -0
  96. data/test/support/scss.patch +493 -0
  97. data/tests/README.md +55 -0
  98. data/tests/_coverage.html +26 -0
  99. data/tests/assets/coverage.js +48 -0
  100. data/tests/assets/jquery-1.7.1.min.js +4 -0
  101. data/tests/assets/mock.js +26 -0
  102. data/tests/assets/qunit-logging.js +29 -0
  103. data/tests/assets/qunit.css +235 -0
  104. data/tests/assets/qunit.js +1669 -0
  105. data/tests/assets/utils.js +21 -0
  106. data/tests/run-qunit.js +157 -0
  107. data/tests/suites/calendar-weeks.js +48 -0
  108. data/tests/suites/component.js +202 -0
  109. data/tests/suites/data-api.js +114 -0
  110. data/tests/suites/events.js +306 -0
  111. data/tests/suites/formats.js +235 -0
  112. data/tests/suites/inline.js +28 -0
  113. data/tests/suites/keyboard_navigation/2011.js +92 -0
  114. data/tests/suites/keyboard_navigation/2012.js +468 -0
  115. data/tests/suites/keyboard_navigation/all.js +26 -0
  116. data/tests/suites/methods.js +78 -0
  117. data/tests/suites/mouse_navigation/2011.js +66 -0
  118. data/tests/suites/mouse_navigation/2012.js +251 -0
  119. data/tests/suites/mouse_navigation/all.js +33 -0
  120. data/tests/suites/noconflict.js +20 -0
  121. data/tests/suites/options.js +648 -0
  122. data/tests/tests.html +50 -0
  123. metadata +240 -0
@@ -0,0 +1,21 @@
1
+ function UTCDate(){
2
+ return new Date(Date.UTC.apply(Date, arguments));
3
+ }
4
+
5
+
6
+ function format_date(date){
7
+ var y = date.getUTCFullYear(),
8
+ m = date.getUTCMonth() + 1,
9
+ d = date.getUTCDate(),
10
+ h = date.getUTCHours(),
11
+ i = date.getUTCMinutes(),
12
+ s = date.getUTCSeconds(),
13
+ l = date.getUTCMilliseconds();
14
+ function z(i){return (i <= 9 ? '0'+i : i);}
15
+ return y+'-'+z(m)+'-'+z(d)+' '+z(h)+':'+z(i)+':'+z(s)+'.'+z(l);
16
+ }
17
+
18
+
19
+ function datesEqual(actual, expected, message){
20
+ QUnit.push(QUnit.equiv(actual, expected), format_date(actual), format_date(expected), message);
21
+ }
@@ -0,0 +1,157 @@
1
+ var system = require('system');
2
+
3
+ /**
4
+ * Wait until the test condition is true or a timeout occurs. Useful for waiting
5
+ * on a server response or for a ui change (fadeIn, etc.) to occur.
6
+ *
7
+ * @param testFx javascript condition that evaluates to a boolean,
8
+ * it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
9
+ * as a callback function.
10
+ * @param onReady what to do when testFx condition is fulfilled,
11
+ * it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
12
+ * as a callback function.
13
+ * @param timeOutMillis the max amount of time to wait. If not specified, 3 sec is used.
14
+ */
15
+ function waitFor(testFx, onReady, timeOutMillis) {
16
+ var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 10001, //< Default Max Timout is 3s
17
+ start = new Date().getTime(),
18
+ condition = false,
19
+ interval = setInterval(function() {
20
+ if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) {
21
+ // If not time-out yet and condition not yet fulfilled
22
+ condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()); //< defensive code
23
+ } else {
24
+ if(!condition) {
25
+ // If condition still not fulfilled (timeout but condition is 'false')
26
+ console.log("'waitFor()' timeout");
27
+ phantom.exit(1);
28
+ } else {
29
+ // Condition fulfilled (timeout and/or condition is 'true')
30
+ //console.log("'waitFor()' finished in " + (new Date().getTime() - start) + "ms.");
31
+ typeof(onReady) === "string" ? eval(onReady) : onReady(); //< Do what it's supposed to do once the condition is fulfilled
32
+ clearInterval(interval); //< Stop this interval
33
+ }
34
+ }
35
+ }, 100); //< repeat check every 100ms
36
+ };
37
+
38
+ if (system.args.length !== 2) {
39
+ console.log('Usage: run-qunit.js URL');
40
+ phantom.exit(1);
41
+ }
42
+
43
+ var fs = require('fs');
44
+ var page = require('webpage').create();
45
+
46
+ // Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
47
+ page.onConsoleMessage = function(msg) {
48
+ console.log(msg);
49
+ };
50
+ page.onError = function (msg, trace) {
51
+ console.log(msg);
52
+ trace.forEach(function(item) {
53
+ console.log(' ', item.file, ':', item.line);
54
+ })
55
+ }
56
+
57
+ var _openPath = phantom.args[0].replace(/^.*(\\|\/)/, '');
58
+ var openPath = _openPath;
59
+ var origdir = '../js/';
60
+ var basedir = '../instrumented/';
61
+ var coverageBase = fs.read('_coverage.html');
62
+
63
+ if (fs.exists(basedir)){
64
+ var script = /<script.*><\/script>/g,
65
+ src = /src=(["'])(.*?)\1/,
66
+ contents = fs.read(openPath),
67
+ _contents = contents,
68
+ srcs = [],
69
+ s;
70
+ while (script.exec(contents)){
71
+ s = src.exec(RegExp.lastMatch)[2];
72
+ if (s && s.indexOf(origdir) != -1)
73
+ _contents = _contents.replace(s, s.replace(origdir, basedir))
74
+ }
75
+ if (_contents != contents){
76
+ openPath += '.cov.html';
77
+ fs.write(openPath, _contents);
78
+ }
79
+ }
80
+
81
+ page.open(openPath, function(status){
82
+ if (status !== "success") {
83
+ console.log("Unable to access network");
84
+ phantom.exit(1);
85
+ } else {
86
+ // Inject instrumented sources if they exist
87
+ if (fs.exists(basedir))
88
+ for (var i=0; i<srcs.length; i++)
89
+ page.includeJs(srcs[i]);
90
+ waitFor(function(){
91
+ return page.evaluate(function(){
92
+ var el = document.getElementById('qunit-testresult');
93
+ if (el && el.innerText.match('completed')) {
94
+ return true;
95
+ }
96
+ return false;
97
+ });
98
+ }, function(){
99
+ // output colorized code coverage
100
+ // reach into page context and pull out coverage info. stringify to pass context boundaries.
101
+ var coverageInfo = JSON.parse(page.evaluate(function() { return JSON.stringify(getCoverageByLine()); }));
102
+ if (coverageInfo.key){
103
+ var lineCoverage = coverageInfo.lines;
104
+ var originalFile = origdir + fs.separator + coverageInfo.key;
105
+ var source = coverageInfo.source;
106
+ var fileLines = readFileLines(originalFile);
107
+
108
+ var colorized = '';
109
+
110
+ for (var idx=0; idx < lineCoverage.length; idx++) {
111
+ //+1: coverage lines count from 1.
112
+ var cvg = lineCoverage[idx + 1];
113
+ var hitmiss = '';
114
+ if (typeof cvg === 'number') {
115
+ hitmiss = ' ' + (cvg>0 ? 'hit' : 'miss');
116
+ } else {
117
+ hitmiss = ' ' + 'undef';
118
+ }
119
+ var htmlLine = fileLines[idx]
120
+ if (!source)
121
+ htmlLine = htmlLine.replace('<', '&lt;').replace('>', '&gt;');
122
+ colorized += '<div class="code' + hitmiss + '">' + htmlLine + '</div>\n';
123
+ };
124
+ colorized = coverageBase.replace('COLORIZED_LINE_HTML', colorized);
125
+
126
+ fs.write('coverage.html', colorized, 'w');
127
+
128
+ console.log('Coverage for ' + coverageInfo.key + ' in coverage.html');
129
+ }
130
+ if (_openPath != openPath)
131
+ fs.remove(openPath);
132
+
133
+ var failedNum = page.evaluate(function(){
134
+ var el = document.getElementById('qunit-testresult');
135
+ console.log(el.innerText);
136
+ try {
137
+ return el.getElementsByClassName('failed')[0].innerHTML;
138
+ } catch (e) { }
139
+ return 10000;
140
+ });
141
+ phantom.exit((parseInt(failedNum, 10) > 0) ? 1 : 0);
142
+ });
143
+ }
144
+ });
145
+
146
+ function readFileLines(filename) {
147
+ var stream = fs.open(filename, 'r');
148
+ var lines = [];
149
+ var line;
150
+ while (!stream.atEnd()) {
151
+ lines.push(stream.readLine());
152
+ }
153
+ stream.close();
154
+
155
+ return lines;
156
+ }
157
+
@@ -0,0 +1,48 @@
1
+ module('Calendar Weeks', {
2
+ setup: function(){
3
+ this.input = $('<input type="text">')
4
+ .appendTo('#qunit-fixture')
5
+ .val('2013-01-14')
6
+ .datepicker({
7
+ format: 'yyyy-mm-dd',
8
+ calendarWeeks: true
9
+ })
10
+ .focus(); // Activate for visibility checks
11
+ this.dp = this.input.data('datepicker')
12
+ this.picker = this.dp.picker;
13
+ },
14
+ teardown: function(){
15
+ this.picker.remove();
16
+ }
17
+ });
18
+
19
+ test('adds cw header column', function(){
20
+ var target = this.picker.find('.datepicker-days thead th:first-child');
21
+ ok(target.hasClass('cw'), 'First column heading is from cw column');
22
+ });
23
+
24
+ test('adds calendar week cells to each day row', function(){
25
+ var target = this.picker.find('.datepicker-days tbody tr');
26
+
27
+ expect(target.length);
28
+ target.each(function(i){
29
+ var t = $(this).children().first();
30
+ ok(t.hasClass('cw'), "First column is cw column");
31
+ });
32
+ });
33
+
34
+ test('displays correct calendar week', function(){
35
+ var target = this.picker.find('.datepicker-days tbody tr');
36
+
37
+ expect(target.length);
38
+ target.each(function(i){
39
+ var t = $(this).children().first();
40
+ equal(t.text(), i+1, "Displays correct calendar weeks");
41
+ });
42
+ });
43
+
44
+ test('it prepends column to switcher thead row', function(){
45
+ var target = this.picker.find('.datepicker-days thead tr:first-child');
46
+ equal(target.children().length, 4, 'first row has 4 columns');
47
+ ok(target.children().first().hasClass('cw'), 'cw column is prepended');
48
+ });
@@ -0,0 +1,202 @@
1
+ module('Component', {
2
+ setup: function(){
3
+ this.component = $('<div class="input-append date" id="datepicker">'+
4
+ '<input size="16" type="text" value="12-02-2012" readonly>'+
5
+ '<span class="add-on"><i class="icon-th"></i></span>'+
6
+ '</div>')
7
+ .appendTo('#qunit-fixture')
8
+ .datepicker({format: "dd-mm-yyyy"});
9
+ this.input = this.component.find('input');
10
+ this.addon = this.component.find('.add-on');
11
+ this.dp = this.component.data('datepicker')
12
+ this.picker = this.dp.picker;
13
+ },
14
+ teardown: function(){
15
+ this.picker.remove();
16
+ }
17
+ });
18
+
19
+
20
+ test('Component gets date/viewDate from input value', function(){
21
+ datesEqual(this.dp.getUTCDate(), UTCDate(2012, 1, 12));
22
+ datesEqual(this.dp.viewDate, UTCDate(2012, 1, 12));
23
+ });
24
+
25
+ test('Activation by component', function(){
26
+ ok(!this.picker.is(':visible'));
27
+ this.addon.click();
28
+ ok(this.picker.is(':visible'));
29
+ });
30
+
31
+ test('simple keyboard nav test', function(){
32
+ var target;
33
+
34
+ // Keyboard nav only works with non-readonly inputs
35
+ this.input.removeAttr('readonly');
36
+
37
+ equal(this.dp.viewMode, 0);
38
+ target = this.picker.find('.datepicker-days thead th.datepicker-switch');
39
+ equal(target.text(), 'February 2012', 'Title is "February 2012"');
40
+ datesEqual(this.dp.getUTCDate(), UTCDate(2012, 1, 12));
41
+ datesEqual(this.dp.viewDate, UTCDate(2012, 1, 12));
42
+
43
+ // Focus/open
44
+ this.addon.click();
45
+
46
+ // Navigation: -1 day, left arrow key
47
+ this.input.trigger({
48
+ type: 'keydown',
49
+ keyCode: 37
50
+ });
51
+ datesEqual(this.dp.viewDate, UTCDate(2012, 1, 11));
52
+ datesEqual(this.dp.getUTCDate(), UTCDate(2012, 1, 12));
53
+ datesEqual(this.dp.focusDate, UTCDate(2012, 1, 11));
54
+ // Month not changed
55
+ target = this.picker.find('.datepicker-days thead th.datepicker-switch');
56
+ equal(target.text(), 'February 2012', 'Title is "February 2012"');
57
+
58
+ // Navigation: +1 month, shift + right arrow key
59
+ this.input.trigger({
60
+ type: 'keydown',
61
+ keyCode: 39,
62
+ shiftKey: true
63
+ });
64
+ datesEqual(this.dp.viewDate, UTCDate(2012, 2, 11));
65
+ datesEqual(this.dp.getUTCDate(), UTCDate(2012, 1, 12));
66
+ datesEqual(this.dp.focusDate, UTCDate(2012, 2, 11));
67
+ target = this.picker.find('.datepicker-days thead th.datepicker-switch');
68
+ equal(target.text(), 'March 2012', 'Title is "March 2012"');
69
+
70
+ // Navigation: -1 year, ctrl + left arrow key
71
+ this.input.trigger({
72
+ type: 'keydown',
73
+ keyCode: 37,
74
+ ctrlKey: true
75
+ });
76
+ datesEqual(this.dp.viewDate, UTCDate(2011, 2, 11));
77
+ datesEqual(this.dp.getUTCDate(), UTCDate(2012, 1, 12));
78
+ datesEqual(this.dp.focusDate, UTCDate(2011, 2, 11));
79
+ target = this.picker.find('.datepicker-days thead th.datepicker-switch');
80
+ equal(target.text(), 'March 2011', 'Title is "March 2011"');
81
+ });
82
+
83
+ test('setValue', function(){
84
+ this.dp.dates.replace(UTCDate(2012, 2, 13));
85
+ this.dp.setValue();
86
+ datesEqual(this.dp.dates[0], UTCDate(2012, 2, 13));
87
+ equal(this.input.val(), '13-03-2012');
88
+ });
89
+
90
+ test('update', function(){
91
+ this.input.val('13-03-2012');
92
+ this.dp.update();
93
+ equal(this.dp.dates.length, 1);
94
+ datesEqual(this.dp.dates[0], UTCDate(2012, 2, 13));
95
+ });
96
+
97
+ test('Navigating to/from decade view', function(){
98
+ var target;
99
+
100
+ this.addon.click();
101
+ this.input.val('31-03-2012');
102
+ this.dp.update();
103
+
104
+ equal(this.dp.viewMode, 0);
105
+ target = this.picker.find('.datepicker-days thead th.datepicker-switch');
106
+ ok(target.is(':visible'), 'View switcher is visible');
107
+
108
+ target.click();
109
+ ok(this.picker.find('.datepicker-months').is(':visible'), 'Month picker is visible');
110
+ equal(this.dp.viewMode, 1);
111
+ // Not modified when switching modes
112
+ datesEqual(this.dp.viewDate, UTCDate(2012, 2, 31));
113
+ datesEqual(this.dp.dates[0], UTCDate(2012, 2, 31));
114
+
115
+ target = this.picker.find('.datepicker-months thead th.datepicker-switch');
116
+ ok(target.is(':visible'), 'View switcher is visible');
117
+
118
+ target.click();
119
+ ok(this.picker.find('.datepicker-years').is(':visible'), 'Year picker is visible');
120
+ equal(this.dp.viewMode, 2);
121
+ // Not modified when switching modes
122
+ datesEqual(this.dp.viewDate, UTCDate(2012, 2, 31));
123
+ datesEqual(this.dp.dates[0], UTCDate(2012, 2, 31));
124
+
125
+ // Change years to test internal state changes
126
+ target = this.picker.find('.datepicker-years tbody span:contains(2011)');
127
+ target.click();
128
+ equal(this.dp.viewMode, 1);
129
+ // Only viewDate modified
130
+ datesEqual(this.dp.viewDate, UTCDate(2011, 2, 1));
131
+ datesEqual(this.dp.dates[0], UTCDate(2012, 2, 31));
132
+
133
+ target = this.picker.find('.datepicker-months tbody span:contains(Apr)');
134
+ target.click();
135
+ equal(this.dp.viewMode, 0);
136
+ // Only viewDate modified
137
+ datesEqual(this.dp.viewDate, UTCDate(2011, 3, 1));
138
+ datesEqual(this.dp.dates[0], UTCDate(2012, 2, 31));
139
+ });
140
+
141
+ test('Selecting date resets viewDate and date', function(){
142
+ var target;
143
+
144
+ this.addon.click();
145
+ this.input.val('31-03-2012');
146
+ this.dp.update();
147
+
148
+ // Rendered correctly
149
+ equal(this.dp.viewMode, 0);
150
+ target = this.picker.find('.datepicker-days tbody td:first');
151
+ equal(target.text(), '26'); // Should be Feb 26
152
+
153
+ // Updated internally on click
154
+ target.click();
155
+ datesEqual(this.dp.viewDate, UTCDate(2012, 1, 26))
156
+ datesEqual(this.dp.dates[0], UTCDate(2012, 1, 26))
157
+
158
+ // Re-rendered on click
159
+ target = this.picker.find('.datepicker-days tbody td:first');
160
+ equal(target.text(), '29'); // Should be Jan 29
161
+ });
162
+
163
+ test('"remove" removes associated HTML', function(){
164
+ var datepickerDivSelector = '.datepicker';
165
+
166
+ $('#datepicker').datepicker('show');
167
+
168
+ //there should be one datepicker initiated so that means one hidden .datepicker div
169
+ equal($(datepickerDivSelector).length, 1);
170
+ this.component.datepicker('remove');
171
+ equal($(datepickerDivSelector).length, 0);//hidden HTML should be gone
172
+ });
173
+
174
+ test('Does not block events', function(){
175
+ var clicks = 0;
176
+ function handler(){
177
+ clicks++;
178
+ }
179
+ $('#qunit-fixture').on('click', '.add-on', handler);
180
+ this.addon.click();
181
+ equal(clicks, 1);
182
+ $('#qunit-fixture').off('click', '.add-on', handler);
183
+ });
184
+
185
+
186
+ test('date and viewDate must be between startDate and endDate when setStartDate called', function() {
187
+ this.dp.setDate(new Date(2013, 1, 1));
188
+ datesEqual(this.dp.dates[0], UTCDate(2013, 1, 1));
189
+ datesEqual(this.dp.viewDate, UTCDate(2013, 1, 1));
190
+ this.dp.setStartDate(new Date(2013, 5, 6));
191
+ datesEqual(this.dp.viewDate, UTCDate(2013, 5, 6));
192
+ equal(this.dp.dates.length, 0);
193
+ });
194
+
195
+ test('date and viewDate must be between startDate and endDate when setEndDate called', function() {
196
+ this.dp.setDate(new Date(2013, 11, 1));
197
+ datesEqual(this.dp.dates[0], UTCDate(2013, 11, 1));
198
+ datesEqual(this.dp.viewDate, UTCDate(2013, 11, 1));
199
+ this.dp.setEndDate(new Date(2013, 5, 6));
200
+ datesEqual(this.dp.viewDate, UTCDate(2013, 5, 6));
201
+ equal(this.dp.dates.length, 0);
202
+ });
@@ -0,0 +1,114 @@
1
+ module('DATA-API');
2
+
3
+ test('DATA-API: data-provide="datepicker" on input; focus', function(){
4
+ var input = $('<input data-provide="datepicker" />')
5
+ .appendTo('#qunit-fixture');
6
+ input.focus();
7
+ ok(input.data('datepicker'), 'datepicker is initialized by "focus" event');
8
+ });
9
+
10
+ test('DATA-API: data-provide="datepicker" on input; click', function(){
11
+ var input = $('<input data-provide="datepicker" />')
12
+ .appendTo('#qunit-fixture');
13
+ input.click();
14
+ ok(input.data('datepicker'), 'datepicker is initialized by "focus" event');
15
+ });
16
+
17
+ test('DATA-API: data-provide="datepicker" on component', function(){
18
+ var html, comp;
19
+
20
+ html = '<div class="input-append date" data-provide="datepicker">'+
21
+ '<input><span class="add-on"><i class="icon-th"></i></span>'+
22
+ '</div>';
23
+
24
+ comp = $(html).appendTo('#qunit-fixture');
25
+ comp.find('input').focus();
26
+ ok(comp.data('datepicker'), 'append component initialized by "focus" event on input');
27
+ comp.remove();
28
+
29
+ comp = $(html).appendTo('#qunit-fixture');
30
+ comp.find('input').click();
31
+ ok(comp.data('datepicker'), 'append component initialized by "click" event on input');
32
+ comp.remove();
33
+
34
+ comp = $(html).appendTo('#qunit-fixture');
35
+ comp.find('.add-on').focus();
36
+ ok(comp.data('datepicker'), 'append component initialized by "focus" event on add-on');
37
+ comp.remove();
38
+
39
+ comp = $(html).appendTo('#qunit-fixture');
40
+ comp.find('.add-on').click();
41
+ ok(comp.data('datepicker'), 'append component initialized by "click" event on add-on');
42
+ comp.remove();
43
+
44
+
45
+ html = '<div class="input-prepend date" data-provide="datepicker">'+
46
+ '<span class="add-on"><i class="icon-th"></i></span><input>'+
47
+ '</div>';
48
+
49
+ comp = $(html).prependTo('#qunit-fixture');
50
+ comp.find('input').focus();
51
+ ok(comp.data('datepicker'), 'prepend component initialized by "focus" event on input');
52
+ comp.remove();
53
+
54
+ comp = $(html).prependTo('#qunit-fixture');
55
+ comp.find('input').click();
56
+ ok(comp.data('datepicker'), 'prepend component initialized by "click" event on input');
57
+ comp.remove();
58
+
59
+ comp = $(html).prependTo('#qunit-fixture');
60
+ comp.find('.add-on').focus();
61
+ ok(comp.data('datepicker'), 'prepend component initialized by "focus" event on add-on');
62
+ comp.remove();
63
+
64
+ comp = $(html).prependTo('#qunit-fixture');
65
+ comp.find('.add-on').click();
66
+ ok(comp.data('datepicker'), 'prepend component initialized by "click" event on add-on');
67
+ comp.remove();
68
+ });
69
+
70
+ test('DATA-API: data-provide="datepicker" on button', function(){
71
+ var html, comp;
72
+
73
+ html = '<button data-provide="datepicker">';
74
+
75
+ comp = $(html).appendTo('#qunit-fixture');
76
+ comp.focus();
77
+ ok(comp.data('datepicker'), 'button initialized by "focus" event on input');
78
+ comp.remove();
79
+
80
+ comp = $(html).appendTo('#qunit-fixture');
81
+ comp.click();
82
+ ok(comp.data('datepicker'), 'button initialized by "click" event on input');
83
+ comp.remove();
84
+ });
85
+
86
+ test('DATA-API: data-provide="datepicker" on rangepicker', function(){
87
+ var html, comp;
88
+
89
+ html = '<div class="input-daterange" data-provide="datepicker">'+
90
+ '<input class="datepicker">'+
91
+ '<span class="add-on">to</span>'+
92
+ '<input class="datepicker">'+
93
+ '</div>';
94
+
95
+ comp = $(html).appendTo('#qunit-fixture');
96
+ comp.find('input:first').focus();
97
+ ok(comp.data('datepicker'), 'range initialized by "focus" event on first input');
98
+ comp.remove();
99
+
100
+ comp = $(html).appendTo('#qunit-fixture');
101
+ comp.find('input:first').click();
102
+ ok(comp.data('datepicker'), 'range initialized by "click" event on first input');
103
+ comp.remove();
104
+
105
+ comp = $(html).appendTo('#qunit-fixture');
106
+ comp.find('input:last').focus();
107
+ ok(comp.data('datepicker'), 'range initialized by "focus" event on last input');
108
+ comp.remove();
109
+
110
+ comp = $(html).appendTo('#qunit-fixture');
111
+ comp.find('input:last').click();
112
+ ok(comp.data('datepicker'), 'range initialized by "click" event on last input');
113
+ comp.remove();
114
+ });