kea-rails 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/lib/kea-rails/version.rb +1 -1
  3. data/vendor/assets/components/Keypress/LICENSE +191 -0
  4. data/vendor/assets/components/Keypress/README.md +78 -0
  5. data/vendor/assets/components/Keypress/bower.json +28 -0
  6. data/vendor/assets/components/Keypress/keypress-2.1.0.min.js +33 -0
  7. data/vendor/assets/components/Keypress/keypress.coffee +921 -0
  8. data/vendor/assets/components/Keypress/keypress.js +1132 -0
  9. data/vendor/assets/components/Keypress/package.json +15 -0
  10. data/vendor/assets/components/attachejs/attache-jquery.js +47 -0
  11. data/vendor/assets/components/attachejs/attache-knockout.js +56 -0
  12. data/vendor/assets/components/attachejs/attache.css +10 -0
  13. data/vendor/assets/components/attachejs/attache.js +589 -0
  14. data/vendor/assets/components/attachejs/bower.json +36 -0
  15. data/vendor/assets/components/humane-js/bower.json +8 -0
  16. data/vendor/assets/components/humane-js/changelog.md +165 -0
  17. data/vendor/assets/components/humane-js/humane.js +238 -0
  18. data/vendor/assets/components/humane-js/humane.min.js +11 -0
  19. data/vendor/assets/components/humane-js/index.html +190 -0
  20. data/vendor/assets/components/humane-js/package.json +25 -0
  21. data/vendor/assets/components/humane-js/readme.md +85 -0
  22. data/vendor/assets/components/humane-js/test/issue23.html +11 -0
  23. data/vendor/assets/components/humane-js/test/issue36.html +9 -0
  24. data/vendor/assets/components/humane-js/test/issue38.html +15 -0
  25. data/vendor/assets/components/humane-js/test/issue49.html +9 -0
  26. data/vendor/assets/components/humane-js/theme-src/bigbox.styl +65 -0
  27. data/vendor/assets/components/humane-js/theme-src/boldlight.styl +64 -0
  28. data/vendor/assets/components/humane-js/theme-src/jackedup.styl +69 -0
  29. data/vendor/assets/components/humane-js/theme-src/libnotify.styl +61 -0
  30. data/vendor/assets/components/humane-js/theme-src/original.styl +51 -0
  31. data/vendor/assets/components/humane-js/themes/bigbox.css +123 -0
  32. data/vendor/assets/components/humane-js/themes/boldlight.css +122 -0
  33. data/vendor/assets/components/humane-js/themes/flatty.css +94 -0
  34. data/vendor/assets/components/humane-js/themes/jackedup.css +123 -0
  35. data/vendor/assets/components/humane-js/themes/libnotify.css +115 -0
  36. data/vendor/assets/components/humane-js/themes/original.css +72 -0
  37. data/vendor/assets/components/knockout-sortable/README.md +129 -0
  38. data/vendor/assets/components/knockout-sortable/bower.json +15 -0
  39. data/vendor/assets/components/knockout-sortable/build/knockout-sortable.js +358 -0
  40. data/vendor/assets/components/knockout-sortable/build/knockout-sortable.min.js +2 -0
  41. data/vendor/assets/components/uri.js/README.md +437 -0
  42. data/vendor/assets/components/uri.js/URI.jquery.json +38 -0
  43. data/vendor/assets/components/uri.js/about-uris.html +156 -0
  44. data/vendor/assets/components/uri.js/build.html +66 -0
  45. data/vendor/assets/components/uri.js/build.js +78 -0
  46. data/vendor/assets/components/uri.js/component.json +15 -0
  47. data/vendor/assets/components/uri.js/contribute.md +11 -0
  48. data/vendor/assets/components/uri.js/docs.html +1280 -0
  49. data/vendor/assets/components/uri.js/index.html +173 -0
  50. data/vendor/assets/components/uri.js/jquery-1.10.2.min.js +6 -0
  51. data/vendor/assets/components/uri.js/jquery-1.7.2.min.js +4 -0
  52. data/vendor/assets/components/uri.js/jquery-1.8.2.min.js +2 -0
  53. data/vendor/assets/components/uri.js/jquery-1.9.1.min.js +5 -0
  54. data/vendor/assets/components/uri.js/jquery-uri-plugin.html +203 -0
  55. data/vendor/assets/components/uri.js/package.json +75 -0
  56. data/vendor/assets/components/uri.js/prettify/lang-apollo.js +2 -0
  57. data/vendor/assets/components/uri.js/prettify/lang-clj.js +18 -0
  58. data/vendor/assets/components/uri.js/prettify/lang-css.js +2 -0
  59. data/vendor/assets/components/uri.js/prettify/lang-go.js +1 -0
  60. data/vendor/assets/components/uri.js/prettify/lang-hs.js +2 -0
  61. data/vendor/assets/components/uri.js/prettify/lang-lisp.js +3 -0
  62. data/vendor/assets/components/uri.js/prettify/lang-lua.js +2 -0
  63. data/vendor/assets/components/uri.js/prettify/lang-ml.js +2 -0
  64. data/vendor/assets/components/uri.js/prettify/lang-n.js +4 -0
  65. data/vendor/assets/components/uri.js/prettify/lang-proto.js +1 -0
  66. data/vendor/assets/components/uri.js/prettify/lang-scala.js +2 -0
  67. data/vendor/assets/components/uri.js/prettify/lang-sql.js +2 -0
  68. data/vendor/assets/components/uri.js/prettify/lang-tex.js +1 -0
  69. data/vendor/assets/components/uri.js/prettify/lang-vb.js +2 -0
  70. data/vendor/assets/components/uri.js/prettify/lang-vhdl.js +3 -0
  71. data/vendor/assets/components/uri.js/prettify/lang-wiki.js +2 -0
  72. data/vendor/assets/components/uri.js/prettify/lang-xq.js +3 -0
  73. data/vendor/assets/components/uri.js/prettify/lang-yaml.js +2 -0
  74. data/vendor/assets/components/uri.js/prettify/prettify.css +1 -0
  75. data/vendor/assets/components/uri.js/prettify/prettify.js +28 -0
  76. data/vendor/assets/components/uri.js/prettify/prettify.sunburst.css +52 -0
  77. data/vendor/assets/components/uri.js/screen.css +167 -0
  78. data/vendor/assets/components/uri.js/screen.js +39 -0
  79. data/vendor/assets/components/uri.js/src/IPv6.js +185 -0
  80. data/vendor/assets/components/uri.js/src/SecondLevelDomains.js +220 -0
  81. data/vendor/assets/components/uri.js/src/URI.fragmentQuery.js +103 -0
  82. data/vendor/assets/components/uri.js/src/URI.fragmentURI.js +96 -0
  83. data/vendor/assets/components/uri.js/src/URI.js +1938 -0
  84. data/vendor/assets/components/uri.js/src/URI.min.js +81 -0
  85. data/vendor/assets/components/uri.js/src/URITemplate.js +494 -0
  86. data/vendor/assets/components/uri.js/src/jquery.URI.js +232 -0
  87. data/vendor/assets/components/uri.js/src/jquery.URI.min.js +7 -0
  88. data/vendor/assets/components/uri.js/src/punycode.js +508 -0
  89. data/vendor/assets/components/uri.js/test/index.html +26 -0
  90. data/vendor/assets/components/uri.js/test/pre_libs.js +4 -0
  91. data/vendor/assets/components/uri.js/test/qunit/qunit-composite.css +13 -0
  92. data/vendor/assets/components/uri.js/test/qunit/qunit-composite.js +167 -0
  93. data/vendor/assets/components/uri.js/test/qunit/qunit.css +244 -0
  94. data/vendor/assets/components/uri.js/test/qunit/qunit.js +2212 -0
  95. data/vendor/assets/components/uri.js/test/test.URI.html +26 -0
  96. data/vendor/assets/components/uri.js/test/test.fragmentQuery.html +31 -0
  97. data/vendor/assets/components/uri.js/test/test.fragmentURI.html +31 -0
  98. data/vendor/assets/components/uri.js/test/test.jQuery-1.10.html +31 -0
  99. data/vendor/assets/components/uri.js/test/test.jQuery-1.7.html +31 -0
  100. data/vendor/assets/components/uri.js/test/test.jQuery-1.8.html +31 -0
  101. data/vendor/assets/components/uri.js/test/test.jQuery-1.9.html +31 -0
  102. data/vendor/assets/components/uri.js/test/test.js +1409 -0
  103. data/vendor/assets/components/uri.js/test/test_fragmentQuery.js +57 -0
  104. data/vendor/assets/components/uri.js/test/test_fragmentURI.js +59 -0
  105. data/vendor/assets/components/uri.js/test/test_jim.js +143 -0
  106. data/vendor/assets/components/uri.js/test/test_jquery.js +138 -0
  107. data/vendor/assets/components/uri.js/test/test_template.js +385 -0
  108. data/vendor/assets/components/uri.js/test/urls.js +1236 -0
  109. data/vendor/assets/components/uri.js/uri-template.html +234 -0
  110. data/vendor/assets/components/uri.js/utils/SLDs.php +37 -0
  111. data/vendor/assets/components/uri.js/utils/sld.js +101 -0
  112. data/vendor/assets/components/veiljs/bower.json +36 -0
  113. data/vendor/assets/components/veiljs/veil-jquery.js +47 -0
  114. data/vendor/assets/components/veiljs/veil-knockout.js +55 -0
  115. data/vendor/assets/components/veiljs/veil.js +465 -0
  116. data/vendor/assets/javascripts/fuse.js +472 -0
  117. data/vendor/assets/javascripts/jquery-ui.js +3844 -0
  118. data/vendor/assets/javascripts/knockout-3.2.0-debug.js +5299 -0
  119. data/vendor/assets/javascripts/moment.js +1902 -0
  120. data/vendor/assets/javascripts/pikaday.js +896 -0
  121. data/vendor/assets/stylesheets/pikaday.css +171 -0
  122. metadata +120 -1
@@ -0,0 +1,896 @@
1
+ /*!
2
+ * Pikaday
3
+ *
4
+ * Copyright © 2013 David Bushell | BSD & MIT license | https://github.com/dbushell/Pikaday
5
+ */
6
+
7
+ (function (root, factory)
8
+ {
9
+ 'use strict';
10
+
11
+ if (typeof define === 'function' && define.amd) {
12
+ // AMD. Register as an anonymous module.
13
+ define(function (req)
14
+ {
15
+ // Load moment.js as an optional dependency
16
+ var id = 'moment';
17
+ var moment = req.defined && req.defined(id) ? req(id) : undefined;
18
+ return factory(moment || root.moment);
19
+ });
20
+ } else {
21
+ // Browser global
22
+ root.Pikaday = factory(root.moment);
23
+ }
24
+ }(this, function (moment)
25
+ {
26
+ 'use strict';
27
+
28
+ /**
29
+ * feature detection and helper functions
30
+ */
31
+ var hasMoment = typeof moment === 'function',
32
+
33
+ hasEventListeners = !!window.addEventListener,
34
+
35
+ document = window.document,
36
+
37
+ sto = window.setTimeout,
38
+
39
+ addEvent = function(el, e, callback, capture)
40
+ {
41
+ if (hasEventListeners) {
42
+ el.addEventListener(e, callback, !!capture);
43
+ } else {
44
+ el.attachEvent('on' + e, callback);
45
+ }
46
+ },
47
+
48
+ removeEvent = function(el, e, callback, capture)
49
+ {
50
+ if (hasEventListeners) {
51
+ el.removeEventListener(e, callback, !!capture);
52
+ } else {
53
+ el.detachEvent('on' + e, callback);
54
+ }
55
+ },
56
+
57
+ fireEvent = function(el, eventName, data)
58
+ {
59
+ var ev;
60
+
61
+ if (document.createEvent) {
62
+ ev = document.createEvent('HTMLEvents');
63
+ ev.initEvent(eventName, true, false);
64
+ ev = extend(ev, data);
65
+ el.dispatchEvent(ev);
66
+ } else if (document.createEventObject) {
67
+ ev = document.createEventObject();
68
+ ev = extend(ev, data);
69
+ el.fireEvent('on' + eventName, ev);
70
+ }
71
+ },
72
+
73
+ trim = function(str)
74
+ {
75
+ return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g,'');
76
+ },
77
+
78
+ hasClass = function(el, cn)
79
+ {
80
+ return (' ' + el.className + ' ').indexOf(' ' + cn + ' ') !== -1;
81
+ },
82
+
83
+ addClass = function(el, cn)
84
+ {
85
+ if (!hasClass(el, cn)) {
86
+ el.className = (el.className === '') ? cn : el.className + ' ' + cn;
87
+ }
88
+ },
89
+
90
+ removeClass = function(el, cn)
91
+ {
92
+ el.className = trim((' ' + el.className + ' ').replace(' ' + cn + ' ', ' '));
93
+ },
94
+
95
+ isArray = function(obj)
96
+ {
97
+ return (/Array/).test(Object.prototype.toString.call(obj));
98
+ },
99
+
100
+ isDate = function(obj)
101
+ {
102
+ return (/Date/).test(Object.prototype.toString.call(obj)) && !isNaN(obj.getTime());
103
+ },
104
+
105
+ isLeapYear = function(year)
106
+ {
107
+ // solution by Matti Virkkunen: http://stackoverflow.com/a/4881951
108
+ return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
109
+ },
110
+
111
+ getDaysInMonth = function(year, month)
112
+ {
113
+ return [31, isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
114
+ },
115
+
116
+ setToStartOfDay = function(date)
117
+ {
118
+ if (isDate(date)) date.setHours(0,0,0,0);
119
+ },
120
+
121
+ compareDates = function(a,b)
122
+ {
123
+ // weak date comparison (use setToStartOfDay(date) to ensure correct result)
124
+ return a.getTime() === b.getTime();
125
+ },
126
+
127
+ extend = function(to, from, overwrite)
128
+ {
129
+ var prop, hasProp;
130
+ for (prop in from) {
131
+ hasProp = to[prop] !== undefined;
132
+ if (hasProp && typeof from[prop] === 'object' && from[prop].nodeName === undefined) {
133
+ if (isDate(from[prop])) {
134
+ if (overwrite) {
135
+ to[prop] = new Date(from[prop].getTime());
136
+ }
137
+ }
138
+ else if (isArray(from[prop])) {
139
+ if (overwrite) {
140
+ to[prop] = from[prop].slice(0);
141
+ }
142
+ } else {
143
+ to[prop] = extend({}, from[prop], overwrite);
144
+ }
145
+ } else if (overwrite || !hasProp) {
146
+ to[prop] = from[prop];
147
+ }
148
+ }
149
+ return to;
150
+ },
151
+
152
+
153
+ /**
154
+ * defaults and localisation
155
+ */
156
+ defaults = {
157
+
158
+ // bind the picker to a form field
159
+ field: null,
160
+
161
+ // automatically show/hide the picker on `field` focus (default `true` if `field` is set)
162
+ bound: undefined,
163
+
164
+ // the default output format for `.toString()` and `field` value
165
+ format: 'YYYY-MM-DD',
166
+
167
+ // the initial date to view when first opened
168
+ defaultDate: null,
169
+
170
+ // make the `defaultDate` the initial selected value
171
+ setDefaultDate: false,
172
+
173
+ // first day of week (0: Sunday, 1: Monday etc)
174
+ firstDay: 0,
175
+
176
+ // the minimum/earliest date that can be selected
177
+ minDate: null,
178
+ // the maximum/latest date that can be selected
179
+ maxDate: null,
180
+
181
+ // number of years either side, or array of upper/lower range
182
+ yearRange: 10,
183
+
184
+ // used internally (don't config outside)
185
+ minYear: 0,
186
+ maxYear: 9999,
187
+ minMonth: undefined,
188
+ maxMonth: undefined,
189
+
190
+ isRTL: false,
191
+
192
+ // Additional text to append to the year in the calendar title
193
+ yearSuffix: '',
194
+
195
+ // Render the month after year in the calendar title
196
+ showMonthAfterYear: false,
197
+
198
+ // how many months are visible (not implemented yet)
199
+ numberOfMonths: 1,
200
+
201
+ // internationalization
202
+ i18n: {
203
+ previousMonth : 'Previous Month',
204
+ nextMonth : 'Next Month',
205
+ months : ['January','February','March','April','May','June','July','August','September','October','November','December'],
206
+ weekdays : ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
207
+ weekdaysShort : ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
208
+ },
209
+
210
+ // callback function
211
+ onSelect: null,
212
+ onOpen: null,
213
+ onClose: null,
214
+ onDraw: null
215
+ },
216
+
217
+
218
+ /**
219
+ * templating functions to abstract HTML rendering
220
+ */
221
+ renderDayName = function(opts, day, abbr)
222
+ {
223
+ day += opts.firstDay;
224
+ while (day >= 7) {
225
+ day -= 7;
226
+ }
227
+ return abbr ? opts.i18n.weekdaysShort[day] : opts.i18n.weekdays[day];
228
+ },
229
+
230
+ renderDay = function(i, isSelected, isToday, isDisabled, isEmpty)
231
+ {
232
+ if (isEmpty) {
233
+ return '<td class="is-empty"></td>';
234
+ }
235
+ var arr = [];
236
+ if (isDisabled) {
237
+ arr.push('is-disabled');
238
+ }
239
+ if (isToday) {
240
+ arr.push('is-today');
241
+ }
242
+ if (isSelected) {
243
+ arr.push('is-selected');
244
+ }
245
+ return '<td data-day="' + i + '" class="' + arr.join(' ') + '"><button class="pika-button" type="button">' + i + '</button>' + '</td>';
246
+ },
247
+
248
+ renderRow = function(days, isRTL)
249
+ {
250
+ return '<tr>' + (isRTL ? days.reverse() : days).join('') + '</tr>';
251
+ },
252
+
253
+ renderBody = function(rows)
254
+ {
255
+ return '<tbody>' + rows.join('') + '</tbody>';
256
+ },
257
+
258
+ renderHead = function(opts)
259
+ {
260
+ var i, arr = [];
261
+ for (i = 0; i < 7; i++) {
262
+ arr.push('<th scope="col"><abbr title="' + renderDayName(opts, i) + '">' + renderDayName(opts, i, true) + '</abbr></th>');
263
+ }
264
+ return '<thead>' + (opts.isRTL ? arr.reverse() : arr).join('') + '</thead>';
265
+ },
266
+
267
+ renderTitle = function(instance)
268
+ {
269
+ var i, j, arr,
270
+ opts = instance._o,
271
+ month = instance._m,
272
+ year = instance._y,
273
+ isMinYear = year === opts.minYear,
274
+ isMaxYear = year === opts.maxYear,
275
+ html = '<div class="pika-title">',
276
+ monthHtml,
277
+ yearHtml,
278
+ prev = true,
279
+ next = true;
280
+
281
+ for (arr = [], i = 0; i < 12; i++) {
282
+ arr.push('<option value="' + i + '"' +
283
+ (i === month ? ' selected': '') +
284
+ ((isMinYear && i < opts.minMonth) || (isMaxYear && i > opts.maxMonth) ? 'disabled' : '') + '>' +
285
+ opts.i18n.months[i] + '</option>');
286
+ }
287
+ monthHtml = '<div class="pika-label">' + opts.i18n.months[month] + '<select class="pika-select pika-select-month">' + arr.join('') + '</select></div>';
288
+
289
+ if (isArray(opts.yearRange)) {
290
+ i = opts.yearRange[0];
291
+ j = opts.yearRange[1] + 1;
292
+ } else {
293
+ i = year - opts.yearRange;
294
+ j = 1 + year + opts.yearRange;
295
+ }
296
+
297
+ for (arr = []; i < j && i <= opts.maxYear; i++) {
298
+ if (i >= opts.minYear) {
299
+ arr.push('<option value="' + i + '"' + (i === year ? ' selected': '') + '>' + (i) + '</option>');
300
+ }
301
+ }
302
+ yearHtml = '<div class="pika-label">' + year + opts.yearSuffix + '<select class="pika-select pika-select-year">' + arr.join('') + '</select></div>';
303
+
304
+ if (opts.showMonthAfterYear) {
305
+ html += yearHtml + monthHtml;
306
+ } else {
307
+ html += monthHtml + yearHtml;
308
+ }
309
+
310
+ if (isMinYear && (month === 0 || opts.minMonth >= month)) {
311
+ prev = false;
312
+ }
313
+
314
+ if (isMaxYear && (month === 11 || opts.maxMonth <= month)) {
315
+ next = false;
316
+ }
317
+
318
+ html += '<button class="pika-prev' + (prev ? '' : ' is-disabled') + '" type="button">' + opts.i18n.previousMonth + '</button>';
319
+ html += '<button class="pika-next' + (next ? '' : ' is-disabled') + '" type="button">' + opts.i18n.nextMonth + '</button>';
320
+
321
+ return html += '</div>';
322
+ },
323
+
324
+ renderTable = function(opts, data)
325
+ {
326
+ return '<table cellpadding="0" cellspacing="0" class="pika-table">' + renderHead(opts) + renderBody(data) + '</table>';
327
+ },
328
+
329
+
330
+ /**
331
+ * Pikaday constructor
332
+ */
333
+ Pikaday = function(options)
334
+ {
335
+ var self = this,
336
+ opts = self.config(options);
337
+
338
+ self._onMouseDown = function(e)
339
+ {
340
+ if (!self._v) {
341
+ return;
342
+ }
343
+ e = e || window.event;
344
+ var target = e.target || e.srcElement;
345
+ if (!target) {
346
+ return;
347
+ }
348
+
349
+ if (!hasClass(target, 'is-disabled')) {
350
+ if (hasClass(target, 'pika-button') && !hasClass(target, 'is-empty')) {
351
+ self.setDate(new Date(self._y, self._m, parseInt(target.innerHTML, 10)));
352
+ if (opts.bound) {
353
+ sto(function() {
354
+ self.hide();
355
+ }, 100);
356
+ }
357
+ return;
358
+ }
359
+ else if (hasClass(target, 'pika-prev')) {
360
+ self.prevMonth();
361
+ }
362
+ else if (hasClass(target, 'pika-next')) {
363
+ self.nextMonth();
364
+ }
365
+ }
366
+ if (!hasClass(target, 'pika-select')) {
367
+ if (e.preventDefault) {
368
+ e.preventDefault();
369
+ } else {
370
+ e.returnValue = false;
371
+ return false;
372
+ }
373
+ } else {
374
+ self._c = true;
375
+ }
376
+ };
377
+
378
+ self._onChange = function(e)
379
+ {
380
+ e = e || window.event;
381
+ var target = e.target || e.srcElement;
382
+ if (!target) {
383
+ return;
384
+ }
385
+ if (hasClass(target, 'pika-select-month')) {
386
+ self.gotoMonth(target.value);
387
+ }
388
+ else if (hasClass(target, 'pika-select-year')) {
389
+ self.gotoYear(target.value);
390
+ }
391
+ };
392
+
393
+ self._onInputChange = function(e)
394
+ {
395
+ var date;
396
+
397
+ if (e.firedBy === self) {
398
+ return;
399
+ }
400
+ if (hasMoment) {
401
+ date = moment(opts.field.value, opts.format);
402
+ date = (date && date.isValid()) ? date.toDate() : null;
403
+ }
404
+ else {
405
+ date = new Date(Date.parse(opts.field.value));
406
+ }
407
+ self.setDate(isDate(date) ? date : null);
408
+ if (!self._v) {
409
+ self.show();
410
+ }
411
+ };
412
+
413
+ self._onInputFocus = function()
414
+ {
415
+ self.show();
416
+ };
417
+
418
+ self._onInputClick = function()
419
+ {
420
+ self.show();
421
+ };
422
+
423
+ self._onInputBlur = function()
424
+ {
425
+ if (!self._c) {
426
+ self._b = sto(function() {
427
+ self.hide();
428
+ }, 50);
429
+ }
430
+ self._c = false;
431
+ };
432
+
433
+ self._onClick = function(e)
434
+ {
435
+ e = e || window.event;
436
+ var target = e.target || e.srcElement,
437
+ pEl = target;
438
+ if (!target) {
439
+ return;
440
+ }
441
+ if (!hasEventListeners && hasClass(target, 'pika-select')) {
442
+ if (!target.onchange) {
443
+ target.setAttribute('onchange', 'return;');
444
+ addEvent(target, 'change', self._onChange);
445
+ }
446
+ }
447
+ do {
448
+ if (hasClass(pEl, 'pika-single')) {
449
+ return;
450
+ }
451
+ }
452
+ while ((pEl = pEl.parentNode));
453
+ if (self._v && target !== opts.trigger) {
454
+ self.hide();
455
+ }
456
+ };
457
+
458
+ self.el = document.createElement('div');
459
+ self.el.className = 'pika-single' + (opts.isRTL ? ' is-rtl' : '');
460
+
461
+ addEvent(self.el, 'mousedown', self._onMouseDown, true);
462
+ addEvent(self.el, 'change', self._onChange);
463
+
464
+ if (opts.field) {
465
+ if (opts.bound) {
466
+ document.body.appendChild(self.el);
467
+ } else {
468
+ opts.field.parentNode.insertBefore(self.el, opts.field.nextSibling);
469
+ }
470
+ addEvent(opts.field, 'change', self._onInputChange);
471
+
472
+ if (!opts.defaultDate) {
473
+ if (hasMoment && opts.field.value) {
474
+ opts.defaultDate = moment(opts.field.value, opts.format).toDate();
475
+ } else {
476
+ opts.defaultDate = new Date(Date.parse(opts.field.value));
477
+ }
478
+ opts.setDefaultDate = true;
479
+ }
480
+ }
481
+
482
+ var defDate = opts.defaultDate;
483
+
484
+ if (isDate(defDate)) {
485
+ if (opts.setDefaultDate) {
486
+ self.setDate(defDate, true);
487
+ } else {
488
+ self.gotoDate(defDate);
489
+ }
490
+ } else {
491
+ self.gotoDate(new Date());
492
+ }
493
+
494
+ if (opts.bound) {
495
+ this.hide();
496
+ self.el.className += ' is-bound';
497
+ addEvent(opts.trigger, 'click', self._onInputClick);
498
+ addEvent(opts.trigger, 'focus', self._onInputFocus);
499
+ addEvent(opts.trigger, 'blur', self._onInputBlur);
500
+ } else {
501
+ this.show();
502
+ }
503
+
504
+ };
505
+
506
+
507
+ /**
508
+ * public Pikaday API
509
+ */
510
+ Pikaday.prototype = {
511
+
512
+
513
+ /**
514
+ * configure functionality
515
+ */
516
+ config: function(options)
517
+ {
518
+ if (!this._o) {
519
+ this._o = extend({}, defaults, true);
520
+ }
521
+
522
+ var opts = extend(this._o, options, true);
523
+
524
+ opts.isRTL = !!opts.isRTL;
525
+
526
+ opts.field = (opts.field && opts.field.nodeName) ? opts.field : null;
527
+
528
+ opts.bound = !!(opts.bound !== undefined ? opts.field && opts.bound : opts.field);
529
+
530
+ opts.trigger = (opts.trigger && opts.trigger.nodeName) ? opts.trigger : opts.field;
531
+
532
+ var nom = parseInt(opts.numberOfMonths, 10) || 1;
533
+ opts.numberOfMonths = nom > 4 ? 4 : nom;
534
+
535
+ if (!isDate(opts.minDate)) {
536
+ opts.minDate = false;
537
+ }
538
+ if (!isDate(opts.maxDate)) {
539
+ opts.maxDate = false;
540
+ }
541
+ if ((opts.minDate && opts.maxDate) && opts.maxDate < opts.minDate) {
542
+ opts.maxDate = opts.minDate = false;
543
+ }
544
+ if (opts.minDate) {
545
+ setToStartOfDay(opts.minDate);
546
+ opts.minYear = opts.minDate.getFullYear();
547
+ opts.minMonth = opts.minDate.getMonth();
548
+ }
549
+ if (opts.maxDate) {
550
+ setToStartOfDay(opts.maxDate);
551
+ opts.maxYear = opts.maxDate.getFullYear();
552
+ opts.maxMonth = opts.maxDate.getMonth();
553
+ }
554
+
555
+ if (isArray(opts.yearRange)) {
556
+ var fallback = new Date().getFullYear() - 10;
557
+ opts.yearRange[0] = parseInt(opts.yearRange[0], 10) || fallback;
558
+ opts.yearRange[1] = parseInt(opts.yearRange[1], 10) || fallback;
559
+ } else {
560
+ opts.yearRange = Math.abs(parseInt(opts.yearRange, 10)) || defaults.yearRange;
561
+ if (opts.yearRange > 100) {
562
+ opts.yearRange = 100;
563
+ }
564
+ }
565
+
566
+ return opts;
567
+ },
568
+
569
+ /**
570
+ * return a formatted string of the current selection (using Moment.js if available)
571
+ */
572
+ toString: function(format)
573
+ {
574
+ return !isDate(this._d) ? '' : hasMoment ? moment(this._d).format(format || this._o.format) : this._d.toDateString();
575
+ },
576
+
577
+ /**
578
+ * return a Moment.js object of the current selection (if available)
579
+ */
580
+ getMoment: function()
581
+ {
582
+ return hasMoment ? moment(this._d) : null;
583
+ },
584
+
585
+ /**
586
+ * set the current selection from a Moment.js object (if available)
587
+ */
588
+ setMoment: function(date)
589
+ {
590
+ if (hasMoment && moment.isMoment(date)) {
591
+ this.setDate(date.toDate());
592
+ }
593
+ },
594
+
595
+ /**
596
+ * return a Date object of the current selection
597
+ */
598
+ getDate: function()
599
+ {
600
+ return isDate(this._d) ? new Date(this._d.getTime()) : null;
601
+ },
602
+
603
+ /**
604
+ * set the current selection
605
+ */
606
+ setDate: function(date, preventOnSelect)
607
+ {
608
+ if (!date) {
609
+ this._d = null;
610
+ return this.draw();
611
+ }
612
+ if (typeof date === 'string') {
613
+ date = new Date(Date.parse(date));
614
+ }
615
+ if (!isDate(date)) {
616
+ return;
617
+ }
618
+
619
+ var min = this._o.minDate,
620
+ max = this._o.maxDate;
621
+
622
+ if (isDate(min) && date < min) {
623
+ date = min;
624
+ } else if (isDate(max) && date > max) {
625
+ date = max;
626
+ }
627
+
628
+ this._d = new Date(date.getTime());
629
+ setToStartOfDay(this._d);
630
+ this.gotoDate(this._d);
631
+
632
+ if (this._o.field) {
633
+ this._o.field.value = this.toString();
634
+ fireEvent(this._o.field, 'change', { firedBy: this });
635
+ }
636
+ if (!preventOnSelect && typeof this._o.onSelect === 'function') {
637
+ this._o.onSelect.call(this, this.getDate());
638
+ }
639
+ },
640
+
641
+ /**
642
+ * change view to a specific date
643
+ */
644
+ gotoDate: function(date)
645
+ {
646
+ if (!isDate(date)) {
647
+ return;
648
+ }
649
+ this._y = date.getFullYear();
650
+ this._m = date.getMonth();
651
+ this.draw();
652
+ },
653
+
654
+ gotoToday: function()
655
+ {
656
+ this.gotoDate(new Date());
657
+ },
658
+
659
+ /**
660
+ * change view to a specific month (zero-index, e.g. 0: January)
661
+ */
662
+ gotoMonth: function(month)
663
+ {
664
+ if (!isNaN( (month = parseInt(month, 10)) )) {
665
+ this._m = month < 0 ? 0 : month > 11 ? 11 : month;
666
+ this.draw();
667
+ }
668
+ },
669
+
670
+ nextMonth: function()
671
+ {
672
+ if (++this._m > 11) {
673
+ this._m = 0;
674
+ this._y++;
675
+ }
676
+ this.draw();
677
+ },
678
+
679
+ prevMonth: function()
680
+ {
681
+ if (--this._m < 0) {
682
+ this._m = 11;
683
+ this._y--;
684
+ }
685
+ this.draw();
686
+ },
687
+
688
+ /**
689
+ * change view to a specific full year (e.g. "2012")
690
+ */
691
+ gotoYear: function(year)
692
+ {
693
+ if (!isNaN(year)) {
694
+ this._y = parseInt(year, 10);
695
+ this.draw();
696
+ }
697
+ },
698
+
699
+ /**
700
+ * change the minDate
701
+ */
702
+ setMinDate: function(value)
703
+ {
704
+ this._o.minDate = value;
705
+ },
706
+
707
+ /**
708
+ * change the maxDate
709
+ */
710
+ setMaxDate: function(value)
711
+ {
712
+ this._o.maxDate = value;
713
+ },
714
+
715
+ /**
716
+ * refresh the HTML
717
+ */
718
+ draw: function(force)
719
+ {
720
+ if (!this._v && !force) {
721
+ return;
722
+ }
723
+ var opts = this._o,
724
+ minYear = opts.minYear,
725
+ maxYear = opts.maxYear,
726
+ minMonth = opts.minMonth,
727
+ maxMonth = opts.maxMonth;
728
+
729
+ if (this._y <= minYear) {
730
+ this._y = minYear;
731
+ if (!isNaN(minMonth) && this._m < minMonth) {
732
+ this._m = minMonth;
733
+ }
734
+ }
735
+ if (this._y >= maxYear) {
736
+ this._y = maxYear;
737
+ if (!isNaN(maxMonth) && this._m > maxMonth) {
738
+ this._m = maxMonth;
739
+ }
740
+ }
741
+
742
+ this.el.innerHTML = renderTitle(this) + this.render(this._y, this._m);
743
+
744
+ if (opts.bound) {
745
+ this.adjustPosition();
746
+ if(opts.field.type !== 'hidden') {
747
+ sto(function() {
748
+ opts.trigger.focus();
749
+ }, 1);
750
+ }
751
+ }
752
+
753
+ if (typeof this._o.onDraw === 'function') {
754
+ var self = this;
755
+ sto(function() {
756
+ self._o.onDraw.call(self);
757
+ }, 0);
758
+ }
759
+ },
760
+
761
+ adjustPosition: function()
762
+ {
763
+ var field = this._o.trigger, pEl = field,
764
+ width = this.el.offsetWidth, height = this.el.offsetHeight,
765
+ viewportWidth = window.innerWidth || document.documentElement.clientWidth,
766
+ viewportHeight = window.innerHeight || document.documentElement.clientHeight,
767
+ scrollTop = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop,
768
+ left, top, clientRect;
769
+
770
+ if (typeof field.getBoundingClientRect === 'function') {
771
+ clientRect = field.getBoundingClientRect();
772
+ left = clientRect.left + window.pageXOffset;
773
+ top = clientRect.bottom + window.pageYOffset;
774
+ } else {
775
+ left = pEl.offsetLeft;
776
+ top = pEl.offsetTop + pEl.offsetHeight;
777
+ while((pEl = pEl.offsetParent)) {
778
+ left += pEl.offsetLeft;
779
+ top += pEl.offsetTop;
780
+ }
781
+ }
782
+
783
+ if (left + width > viewportWidth) {
784
+ left = left - width + field.offsetWidth;
785
+ }
786
+ if (top + height > viewportHeight + scrollTop) {
787
+ top = top - height - field.offsetHeight;
788
+ }
789
+ this.el.style.cssText = 'position:absolute;left:' + left + 'px;top:' + top + 'px;';
790
+ },
791
+
792
+ /**
793
+ * render HTML for a particular month
794
+ */
795
+ render: function(year, month)
796
+ {
797
+ var opts = this._o,
798
+ now = new Date(),
799
+ days = getDaysInMonth(year, month),
800
+ before = new Date(year, month, 1).getDay(),
801
+ data = [],
802
+ row = [];
803
+ setToStartOfDay(now);
804
+ if (opts.firstDay > 0) {
805
+ before -= opts.firstDay;
806
+ if (before < 0) {
807
+ before += 7;
808
+ }
809
+ }
810
+ var cells = days + before,
811
+ after = cells;
812
+ while(after > 7) {
813
+ after -= 7;
814
+ }
815
+ cells += 7 - after;
816
+ for (var i = 0, r = 0; i < cells; i++)
817
+ {
818
+ var day = new Date(year, month, 1 + (i - before)),
819
+ isDisabled = (opts.minDate && day < opts.minDate) || (opts.maxDate && day > opts.maxDate),
820
+ isSelected = isDate(this._d) ? compareDates(day, this._d) : false,
821
+ isToday = compareDates(day, now),
822
+ isEmpty = i < before || i >= (days + before);
823
+
824
+ row.push(renderDay(1 + (i - before), isSelected, isToday, isDisabled, isEmpty));
825
+
826
+ if (++r === 7) {
827
+ data.push(renderRow(row, opts.isRTL));
828
+ row = [];
829
+ r = 0;
830
+ }
831
+ }
832
+ return renderTable(opts, data);
833
+ },
834
+
835
+ isVisible: function()
836
+ {
837
+ return this._v;
838
+ },
839
+
840
+ show: function()
841
+ {
842
+ if (!this._v) {
843
+ if (this._o.bound) {
844
+ addEvent(document, 'click', this._onClick);
845
+ }
846
+ removeClass(this.el, 'is-hidden');
847
+ this._v = true;
848
+ this.draw();
849
+ if (typeof this._o.onOpen === 'function') {
850
+ this._o.onOpen.call(this);
851
+ }
852
+ }
853
+ },
854
+
855
+ hide: function()
856
+ {
857
+ var v = this._v;
858
+ if (v !== false) {
859
+ if (this._o.bound) {
860
+ removeEvent(document, 'click', this._onClick);
861
+ }
862
+ this.el.style.cssText = '';
863
+ addClass(this.el, 'is-hidden');
864
+ this._v = false;
865
+ if (v !== undefined && typeof this._o.onClose === 'function') {
866
+ this._o.onClose.call(this);
867
+ }
868
+ }
869
+ },
870
+
871
+ /**
872
+ * GAME OVER
873
+ */
874
+ destroy: function()
875
+ {
876
+ this.hide();
877
+ removeEvent(this.el, 'mousedown', this._onMouseDown, true);
878
+ removeEvent(this.el, 'change', this._onChange);
879
+ if (this._o.field) {
880
+ removeEvent(this._o.field, 'change', this._onInputChange);
881
+ if (this._o.bound) {
882
+ removeEvent(this._o.trigger, 'click', this._onInputClick);
883
+ removeEvent(this._o.trigger, 'focus', this._onInputFocus);
884
+ removeEvent(this._o.trigger, 'blur', this._onInputBlur);
885
+ }
886
+ }
887
+ if (this.el.parentNode) {
888
+ this.el.parentNode.removeChild(this.el);
889
+ }
890
+ }
891
+
892
+ };
893
+
894
+ return Pikaday;
895
+
896
+ }));