aureus 1.3.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -1
  3. data/Gemfile +9 -8
  4. data/Gemfile.lock +105 -104
  5. data/README.md +80 -0
  6. data/Rakefile +3 -16
  7. data/app/assets/javascripts/aureus/index.js +78 -20
  8. data/app/assets/stylesheets/aureus/index.scss +3 -35
  9. data/app/assets/stylesheets/aureus/skin/default.scss +52 -0
  10. data/app/assets/stylesheets/aureus/theme.scss +7 -0
  11. data/app/assets/stylesheets/aureus/theme/base.scss +19 -0
  12. data/app/assets/stylesheets/aureus/theme/content.scss +65 -0
  13. data/app/assets/stylesheets/aureus/{form.scss → theme/form.scss} +27 -27
  14. data/app/assets/stylesheets/aureus/theme/messages.scss +16 -0
  15. data/app/assets/stylesheets/aureus/theme/navigation.scss +42 -0
  16. data/app/assets/stylesheets/aureus/theme/table.scss +121 -0
  17. data/app/assets/stylesheets/aureus/theme/toolbar.scss +80 -0
  18. data/aureus.gemspec +21 -12
  19. data/config.ru +10 -0
  20. data/lib/aureus.rb +22 -18
  21. data/lib/aureus/components/box.rb +58 -0
  22. data/lib/aureus/components/content.rb +19 -0
  23. data/lib/aureus/components/data_table.rb +169 -0
  24. data/lib/aureus/components/listing.rb +43 -0
  25. data/lib/aureus/components/messages.rb +27 -0
  26. data/lib/aureus/components/navigation.rb +48 -0
  27. data/lib/aureus/components/row.rb +69 -0
  28. data/lib/aureus/components/simple_map.rb +21 -0
  29. data/lib/aureus/components/toolbar.rb +124 -0
  30. data/lib/aureus/engine.rb +8 -2
  31. data/lib/aureus/helper.rb +56 -55
  32. data/lib/aureus/renderable.rb +4 -12
  33. data/lib/aureus/version.rb +2 -2
  34. data/lib/generators/aureus/devise_i18n/devise_i18n_generator.rb +17 -12
  35. data/{config → lib/generators/aureus/devise_i18n}/locales/devise_base.de.yml +0 -0
  36. data/{config → lib/generators/aureus/devise_i18n}/locales/devise_base.en.yml +1 -1
  37. data/{config → lib/generators/aureus/devise_i18n}/locales/devise_mail.de.yml +1 -1
  38. data/{config → lib/generators/aureus/devise_i18n}/locales/devise_mail.en.yml +1 -1
  39. data/{config → lib/generators/aureus/devise_i18n}/locales/devise_ui.de.yml +0 -0
  40. data/{config → lib/generators/aureus/devise_i18n}/locales/devise_ui.en.yml +0 -0
  41. data/lib/generators/aureus/devise_invitable_i18n/devise_invitable_i18n_generator.rb +25 -0
  42. data/lib/generators/aureus/devise_invitable_i18n/locales/devise_invitable_base.de.yml +11 -0
  43. data/lib/generators/aureus/devise_invitable_i18n/locales/devise_invitable_base.en.yml +11 -0
  44. data/lib/generators/aureus/devise_invitable_i18n/locales/devise_invitable_mail.de.yml +9 -0
  45. data/lib/generators/aureus/devise_invitable_i18n/locales/devise_invitable_mail.en.yml +9 -0
  46. data/lib/generators/aureus/devise_invitable_i18n/locales/devise_invitable_ui.de.yml +12 -0
  47. data/lib/generators/aureus/devise_invitable_i18n/locales/devise_invitable_ui.en.yml +12 -0
  48. data/lib/generators/aureus/devise_invitable_views/devise_invitable_views_generator.rb +23 -0
  49. data/lib/generators/aureus/devise_invitable_views/templates/devise/invitations/edit.html.haml +9 -0
  50. data/lib/generators/aureus/devise_invitable_views/templates/devise/invitations/new.html.haml +8 -0
  51. data/lib/generators/aureus/devise_invitable_views/templates/devise/mailer/invitation_instructions.html.haml +5 -0
  52. data/lib/generators/aureus/devise_views/devise_views_generator.rb +17 -15
  53. data/lib/generators/aureus/devise_views/templates/devise/confirmations/new.html.haml +5 -5
  54. data/lib/generators/aureus/devise_views/templates/devise/mailer/confirmation_instructions.html.haml +3 -3
  55. data/lib/generators/aureus/devise_views/templates/devise/mailer/reset_password_instructions.html.haml +5 -5
  56. data/lib/generators/aureus/devise_views/templates/devise/mailer/unlock_instructions.html.haml +4 -4
  57. data/lib/generators/aureus/devise_views/templates/devise/passwords/edit.html.haml +7 -7
  58. data/lib/generators/aureus/devise_views/templates/devise/passwords/new.html.haml +5 -5
  59. data/lib/generators/aureus/devise_views/templates/devise/registrations/edit.html.haml +9 -9
  60. data/lib/generators/aureus/devise_views/templates/devise/registrations/new.html.haml +7 -7
  61. data/lib/generators/aureus/devise_views/templates/devise/sessions/new.html.haml +7 -7
  62. data/lib/generators/aureus/devise_views/templates/devise/shared/_links.html.haml +6 -6
  63. data/lib/generators/aureus/devise_views/templates/devise/unlocks/new.html.haml +5 -5
  64. data/lib/generators/aureus/layout/layout_generator.rb +10 -10
  65. data/lib/generators/aureus/layout/templates/layout.html.haml +8 -8
  66. data/lib/generators/aureus/views/templates/views/_form.html.haml +3 -3
  67. data/lib/generators/aureus/views/templates/views/_item.html.haml +2 -2
  68. data/lib/generators/aureus/views/templates/views/_list.html.haml +8 -8
  69. data/lib/generators/aureus/views/templates/views/edit.html.haml +4 -4
  70. data/lib/generators/aureus/views/templates/views/index.html.haml +3 -3
  71. data/lib/generators/aureus/views/templates/views/new.html.haml +4 -4
  72. data/lib/generators/aureus/views/templates/views/show.html.haml +4 -4
  73. data/lib/generators/aureus/views/views_generator.rb +70 -68
  74. data/spec/controllers/all_spec.rb +19 -0
  75. data/spec/internal/app/assets/javascripts/application.js +9 -0
  76. data/spec/internal/app/assets/stylesheets/application.scss +5 -0
  77. data/spec/internal/app/controllers/all_controller.rb +14 -0
  78. data/spec/internal/app/controllers/resources_controller.rb +2 -0
  79. data/spec/{lib/helper → internal/app/models}/resource.rb +0 -0
  80. data/spec/internal/app/views/all/centered.html.haml +5 -0
  81. data/spec/internal/app/views/all/index.html.haml +39 -0
  82. data/spec/internal/app/views/layouts/application.html.haml +24 -0
  83. data/spec/internal/app/views/layouts/naked.html.haml +10 -0
  84. data/spec/internal/config/database.yml +3 -0
  85. data/spec/internal/config/routes.rb +5 -0
  86. data/spec/internal/db/schema.rb +10 -0
  87. data/spec/internal/log/.gitignore +1 -0
  88. data/spec/internal/public/favicon.ico +0 -0
  89. data/spec/lib/generators/devise_i18n_spec.rb +19 -0
  90. data/spec/lib/generators/devise_invitable_i18n_spec.rb +19 -0
  91. data/spec/lib/generators/devise_invitable_views_spec.rb +19 -0
  92. data/spec/lib/generators/devise_views_spec.rb +25 -0
  93. data/spec/lib/generators/layout_spec.rb +17 -0
  94. data/spec/lib/generators/views_spec.rb +26 -0
  95. data/spec/requests/all_spec.rb +12 -0
  96. data/spec/spec_helper.rb +15 -0
  97. metadata +219 -78
  98. data/.rspec +0 -2
  99. data/Guardfile +0 -4
  100. data/Readme.md +0 -370
  101. data/TODO.md +0 -11
  102. data/app/assets/images/aureus/background.png +0 -0
  103. data/app/assets/images/aureus/topbar.png +0 -0
  104. data/app/assets/javascripts/aureus/defaults.js +0 -30
  105. data/app/assets/javascripts/aureus/extensions.js +0 -42
  106. data/app/assets/javascripts/aureus/functions.js +0 -67
  107. data/app/assets/javascripts/aureus/plugins/jquery-calendrical.js +0 -508
  108. data/app/assets/javascripts/aureus/plugins/jquery-datatables.js +0 -11838
  109. data/app/assets/javascripts/aureus/plugins/jquery-qtip.js +0 -15
  110. data/app/assets/stylesheets/aureus/base.scss +0 -48
  111. data/app/assets/stylesheets/aureus/content.scss +0 -100
  112. data/app/assets/stylesheets/aureus/mixins.scss +0 -43
  113. data/app/assets/stylesheets/aureus/navigation.scss +0 -43
  114. data/app/assets/stylesheets/aureus/reset.scss +0 -50
  115. data/app/assets/stylesheets/aureus/table.scss +0 -153
  116. data/app/assets/stylesheets/aureus/topbar.scss +0 -89
  117. data/app/assets/stylesheets/aureus/ui.scss +0 -98
  118. data/lib/aureus/box.rb +0 -54
  119. data/lib/aureus/content.rb +0 -15
  120. data/lib/aureus/data_table.rb +0 -148
  121. data/lib/aureus/listing.rb +0 -39
  122. data/lib/aureus/map.rb +0 -17
  123. data/lib/aureus/messages.rb +0 -23
  124. data/lib/aureus/navigation.rb +0 -42
  125. data/lib/aureus/row.rb +0 -65
  126. data/lib/aureus/toolbar.rb +0 -99
  127. data/spec/lib/helper/schema.rb +0 -6
  128. data/spec/lib/render_spec.rb +0 -16
  129. data/spec/lib/spec_helper.rb +0 -21
  130. data/spec/lib/views/box.haml +0 -14
  131. data/spec/lib/views/content.haml +0 -2
  132. data/spec/lib/views/datatable.haml +0 -11
  133. data/spec/lib/views/listing.haml +0 -5
  134. data/spec/lib/views/messages.haml +0 -2
  135. data/spec/lib/views/navigation.haml +0 -4
  136. data/spec/lib/views/row.haml +0 -28
  137. data/spec/lib/views/toolbar.haml +0 -11
@@ -1,67 +0,0 @@
1
- function aureus_remove_messages_after(seconds) {
2
- setTimeout(function() {
3
- $("#messages p").fadeOut();
4
- }, seconds*1000);
5
- }
6
-
7
- function aureus_setup_i18n(default_locale, current_locale) {
8
- I18n.defaultLocale = default_locale;
9
- I18n.locale = current_locale;
10
- }
11
-
12
- function aureus_datatables_decorate() {
13
- $.fn.dataTableExt.oStdClasses.sWrapper = "datatable-wrapper";
14
- $.fn.dataTableExt.oStdClasses.sLength = "datatable-length";
15
- $.fn.dataTableExt.oStdClasses.sFilter = "datatable-filter";
16
- $.fn.dataTableExt.oStdClasses.sInfo = "datatable-info";
17
- $.fn.dataTableExt.oStdClasses.sPaging = "datatable-paging";
18
-
19
- $(".datatable").each(function(){
20
- $(this).dataTable({
21
- sDom: "<'toolbar'fi>t",
22
- oLanguage: aureus_datatable_language_config,
23
- bPaginate: false,
24
- aoColumns: aureus_datatables_column_configurator($(this))
25
- });
26
- });
27
-
28
- $(".datatable-no-toolbar").each(function(){
29
- $(this).dataTable({
30
- sDom: "t",
31
- oLanguage: aureus_datatable_language_config,
32
- bPaginate: false,
33
- aoColumns: aureus_datatables_column_configurator($(this))
34
- });
35
- });
36
- }
37
-
38
- function aureus_trigger_form(selector) {
39
- $(selector).submit();
40
- }
41
-
42
- function aureus_datatables_translate() {
43
- aureus_datatable_language_config = {
44
- sSearch : I18n.t("aureus.datatables.search"),
45
- sLengthMenu: I18n.t("aureus.datatables.lenght_menu"),
46
- sZeroRecords: I18n.t("aureus.datatables.zero_records"),
47
- sInfo: I18n.t("aureus.datatables.info"),
48
- sInfoEmpty: I18n.t("aureus.datatables.info_empty"),
49
- sInfoFiltered: I18n.t("aureus.datatables.info_filtered")
50
- };
51
- }
52
-
53
- /* private */
54
-
55
- function aureus_datatables_column_configurator(table) {
56
- var ret = Array();
57
- table.children("thead").children("tr").children("th").each(function(){
58
- if($(this).hasClass("no-sorting")) {
59
- ret.push({ bSortable: false });
60
- } else if($(this).hasClass("date-sorting")) {
61
- ret.push({ sType: "date-eu" });
62
- } else {
63
- ret.push(null);
64
- }
65
- });
66
- return ret;
67
- }
@@ -1,508 +0,0 @@
1
- (function($) {
2
- var monthNames = ['January', 'February', 'March', 'April', 'May', 'June',
3
- 'July', 'August', 'September', 'October', 'November', 'December'];
4
-
5
- function getToday()
6
- {
7
- var date = new Date();
8
- return new Date(date.getFullYear(), date.getMonth(), date.getDate());
9
- }
10
-
11
- function areDatesEqual(date1, date2)
12
- {
13
- return String(date1) == String(date2);
14
- }
15
-
16
- function daysInMonth(year, month)
17
- {
18
- if (year instanceof Date) return daysInMonth(year.getFullYear(), year.getMonth());
19
- if (month == 1) {
20
- var leapYear = (year % 4 == 0) &&
21
- (!(year % 100 == 0) || (year % 400 == 0));
22
- return leapYear ? 29 : 28;
23
- } else if (month == 3 || month == 5 || month == 8 || month == 10) {
24
- return 30;
25
- } else {
26
- return 31;
27
- }
28
- }
29
-
30
- function dayAfter(date)
31
- {
32
- var year = date.getFullYear();
33
- var month = date.getMonth();
34
- var day = date.getDate();
35
- var lastDay = daysInMonth(date);
36
- return (day == lastDay) ?
37
- ((month == 11) ?
38
- new Date(year + 1, 0, 1) :
39
- new Date(year, month + 1, 1)
40
- ) :
41
- new Date(year, month, day + 1);
42
- }
43
-
44
- function dayBefore(date)
45
- {
46
- var year = date.getFullYear();
47
- var month = date.getMonth();
48
- var day = date.getDate();
49
- return (day == 1) ?
50
- ((month == 0) ?
51
- new Date(year - 1, 11, daysInMonth(year - 1, 11)) :
52
- new Date(year, month - 1, daysInMonth(year, month - 1))
53
- ) :
54
- new Date(year, month, day - 1);
55
- }
56
-
57
- function monthAfter(year, month)
58
- {
59
- return (month == 11) ?
60
- new Date(year + 1, 0, 1) :
61
- new Date(year, month + 1, 1);
62
- }
63
-
64
- function formatDate(date, usa)
65
- {
66
- return (usa ?
67
- ((date.getMonth() + 1) + '/' + date.getDate()) :
68
- (date.getDate() + '/' + (date.getMonth() + 1))
69
- ) + '/' + date.getFullYear();
70
- }
71
-
72
- function parseDate(date, usa)
73
- {
74
- if (usa) return new Date(date);
75
- a = date.split(/[\.\-\/]/);
76
- var day = a.shift();
77
- var month = a.shift();
78
- a.unshift(day);
79
- a.unshift(month);
80
- return new Date(a.join('/'));
81
- }
82
-
83
- function formatTime(hour, minute, options)
84
- {
85
- var printMinute = minute;
86
- if (minute < 10) printMinute = '0' + minute;
87
-
88
- if (options.isoTime) {
89
- var printHour = hour
90
- if (printHour < 10) printHour = '0' + hour;
91
- return printHour + ':' + printMinute;
92
- } else {
93
- var printHour = hour % 12;
94
- if (printHour == 0) printHour = 12;
95
-
96
- if (options.meridiemUpperCase) {
97
- var half = (hour < 12) ? 'AM' : 'PM';
98
- } else {
99
- var half = (hour < 12) ? 'am' : 'pm';
100
- }
101
-
102
- return printHour + ':' + printMinute + half;
103
- }
104
- }
105
-
106
- function parseTime(text)
107
- {
108
- var match = match = /(\d+)\s*[:\-\.,]\s*(\d+)\s*(am|pm)?/i.exec(text);
109
- if (match && match.length >= 3) {
110
- var hour = Number(match[1]);
111
- var minute = Number(match[2])
112
- if (hour == 12 && match[3]) hour -= 12;
113
- if (match[3] && match[3].toLowerCase() == 'pm') hour += 12;
114
- return {
115
- hour: hour,
116
- minute: minute
117
- };
118
- } else {
119
- return null;
120
- }
121
- }
122
-
123
- function timeToMinutes(time)
124
- {
125
- return time && (time.hour * 60 + time.minute);
126
- }
127
-
128
- /**
129
- * Generates calendar header, with month name, << and >> controls, and
130
- * initials for days of the week.
131
- */
132
- function renderCalendarHeader(element, year, month, options)
133
- {
134
- //Prepare thead element
135
- var thead = $('<thead />');
136
- var titleRow = $('<tr />').appendTo(thead);
137
-
138
- //Generate << (back a month) link
139
- $('<th />').addClass('monthCell').append(
140
- $('<a href="javascript:;">&laquo;</a>')
141
- .addClass('prevMonth')
142
- .mousedown(function(e) {
143
- renderCalendarPage(element,
144
- month == 0 ? (year - 1) : year,
145
- month == 0 ? 11 : (month - 1), options
146
- );
147
- e.preventDefault();
148
- })
149
- ).appendTo(titleRow);
150
-
151
- //Generate month title
152
- $('<th />').addClass('monthCell').attr('colSpan', 5).append(
153
- $('<a href="javascript:;">' + monthNames[month] + ' ' +
154
- year + '</a>').addClass('monthName')
155
- ).appendTo(titleRow);
156
-
157
- //Generate >> (forward a month) link
158
- $('<th />').addClass('monthCell').append(
159
- $('<a href="javascript:;">&raquo;</a>')
160
- .addClass('nextMonth')
161
- .mousedown(function() {
162
- renderCalendarPage(element,
163
- month == 11 ? (year + 1) : year,
164
- month == 11 ? 0 : (month + 1), options
165
- );
166
- })
167
- ).appendTo(titleRow);
168
-
169
- //Generate weekday initials row
170
- var dayNames = $('<tr />').appendTo(thead);
171
- $.each(String('SMTWTFS').split(''), function(k, v) {
172
- $('<td />').addClass('dayName').append(v).appendTo(dayNames);
173
- });
174
-
175
- return thead;
176
- }
177
-
178
- function renderCalendarPage(element, year, month, options)
179
- {
180
- options = options || {};
181
-
182
- var today = getToday();
183
-
184
- var date = new Date(year, month, 1);
185
-
186
- //Wind end date forward to saturday week after month
187
- var endDate = monthAfter(year, month);
188
- var ff = 6 - endDate.getDay();
189
- if (ff < 6) ff += 7;
190
- for (var i = 0; i < ff; i++) endDate = dayAfter(endDate);
191
-
192
- var table = $('<table />');
193
- renderCalendarHeader(element, year, month, options).appendTo(table);
194
-
195
- var tbody = $('<tbody />').appendTo(table);
196
- var row = $('<tr />');
197
-
198
- //Rewind date to monday week before month
199
- var rewind = date.getDay() + 7;
200
- for (var i = 0; i < rewind; i++) date = dayBefore(date);
201
-
202
- while (date <= endDate) {
203
- var td = $('<td />')
204
- .addClass('day')
205
- .append(
206
- $('<a href="javascript:;">' +
207
- date.getDate() + '</a>'
208
- ).click((function() {
209
- var thisDate = date;
210
-
211
- return function() {
212
- if (options && options.selectDate) {
213
- options.selectDate(thisDate);
214
- }
215
- }
216
- }()))
217
- )
218
- .appendTo(row);
219
-
220
- var isToday = areDatesEqual(date, today);
221
- var isSelected = options.selected &&
222
- areDatesEqual(options.selected, date);
223
-
224
- if (isToday) td.addClass('today');
225
- if (isSelected) td.addClass('selected');
226
- if (isToday && isSelected) td.addClass('today_selected');
227
- if (date.getMonth() != month) td.addClass('nonMonth');
228
-
229
- dow = date.getDay();
230
- if (dow == 6) {
231
- tbody.append(row);
232
- row = $('<tr />');
233
- }
234
- date = dayAfter(date);
235
- }
236
- if (row.children().length) {
237
- tbody.append(row);
238
- } else {
239
- row.remove();
240
- }
241
-
242
- element.empty().append(table);
243
- }
244
-
245
- function renderTimeSelect(element, options)
246
- {
247
- var minTime = timeToMinutes(options.minTime);
248
- var maxTime = timeToMinutes(options.maxTime);
249
- var defaultTime = timeToMinutes(options.defaultTime);
250
- var selection = options.selection && timeToMinutes(parseTime(options.selection));
251
-
252
- //Round selection to nearest time interval so that it matches a list item
253
- selection = selection && (
254
- (
255
- Math.floor((selection - minTime) / options.timeInterval) *
256
- options.timeInterval
257
- ) + minTime
258
- );
259
-
260
- var scrollTo; //Element to scroll the dropdown box to when shown
261
- var ul = $('<ul />');
262
-
263
- for (var time = minTime; time <= maxTime; time += options.timeInterval) {
264
- (function(time) {
265
- var hour = Math.floor(time / 60);
266
- var minute = time % 60;
267
- var timeText = formatTime(hour, minute, options);
268
- var fullText = timeText;
269
- if (options.showDuration) {
270
- var duration = time - minTime;
271
- if (duration < 60) {
272
- fullText += ' (' + duration + ' mins)';
273
- } else if (duration == 60) {
274
- fullText += ' (1 hr)';
275
- } else {
276
- //Round partial hours to 1 decimal place
277
- fullText += ' (' + (Math.round(duration / 60.0 * 10.0) / 10.0) + ' hrs)';
278
- }
279
- }
280
- var li = $('<li />').append(
281
- $('<a href="javascript:;">' + fullText + '</a>')
282
- .click(function() {
283
- if (options && options.selectTime) {
284
- options.selectTime(timeText);
285
- }
286
- }).mousemove(function() {
287
- $('li.selected', ul).removeClass('selected');
288
- })
289
- ).appendTo(ul);
290
-
291
- //Set to scroll to the default hour, unless already set
292
- if (!scrollTo && time == defaultTime) scrollTo = li;
293
-
294
- if (selection == time) {
295
- //Highlight selected item
296
- li.addClass('selected');
297
-
298
- //Set to scroll to the selected hour
299
- //
300
- //This is set even if scrollTo is already set, since
301
- //scrolling to selected hour is more important than
302
- //scrolling to default hour
303
- scrollTo = li;
304
- }
305
- })(time);
306
- }
307
- if (scrollTo) {
308
- //Set timeout of zero so code runs immediately after any calling
309
- //functions are finished (this is needed, since box hasn't been
310
- //added to the DOM yet)
311
- setTimeout(function() {
312
- //Scroll the dropdown box so that scrollTo item is in
313
- //the middle
314
- element[0].scrollTop =
315
- scrollTo[0].offsetTop - scrollTo.height() * 2;
316
- }, 0);
317
- }
318
- element.empty().append(ul);
319
- }
320
-
321
- $.fn.calendricalDate = function(options)
322
- {
323
- options = options || {};
324
- options.padding = options.padding || 4;
325
-
326
- return this.each(function() {
327
- var element = $(this);
328
- var div;
329
- var within = false;
330
-
331
- element.bind('focus click', function() {
332
- if (div) return;
333
- var offset = element.position();
334
- var padding = element.css('padding-left');
335
- div = $('<div />')
336
- .addClass('calendricalDatePopup')
337
- .mouseenter(function() { within = true; })
338
- .mouseleave(function() { within = false; })
339
- .mousedown(function(e) {
340
- e.preventDefault();
341
- })
342
- .css({
343
- position: 'absolute',
344
- left: offset.left,
345
- top: offset.top + element.height() +
346
- options.padding * 2
347
- });
348
- element.after(div);
349
-
350
- var selected = parseDate(element.val(), options.usa);
351
- if (!selected.getFullYear()) selected = getToday();
352
-
353
- renderCalendarPage(
354
- div,
355
- selected.getFullYear(),
356
- selected.getMonth(), {
357
- selected: selected,
358
- selectDate: function(date) {
359
- within = false;
360
- element.val(formatDate(date, options.usa));
361
- div.remove();
362
- div = null;
363
- if (options.endDate) {
364
- var endDate = parseDate(
365
- options.endDate.val(), options.usa
366
- );
367
- if (endDate >= selected) {
368
- options.endDate.val(formatDate(
369
- new Date(
370
- date.getTime() +
371
- endDate.getTime() -
372
- selected.getTime()
373
- ),
374
- options.usa
375
- ));
376
- }
377
- }
378
- }
379
- }
380
- );
381
- }).blur(function() {
382
- if (within){
383
- if (div) element.focus();
384
- return;
385
- }
386
- if (!div) return;
387
- div.remove();
388
- div = null;
389
- });
390
- });
391
- };
392
-
393
- $.fn.calendricalDateRange = function(options)
394
- {
395
- if (this.length >= 2) {
396
- $(this[0]).calendricalDate($.extend({
397
- endDate: $(this[1])
398
- }, options));
399
- $(this[1]).calendricalDate(options);
400
- }
401
- return this;
402
- };
403
-
404
- $.fn.calendricalTime = function(options)
405
- {
406
- options = options || {};
407
- options.timeInterval = options.timeInterval || 30;
408
- options.padding = options.padding || 4;
409
-
410
- return this.each(function() {
411
- var element = $(this);
412
- var div;
413
- var within = false;
414
-
415
- element.bind('focus click', function() {
416
- if (div) return;
417
-
418
- var offset = element.position();
419
- div = $('<div />')
420
- .addClass('calendricalTimePopup')
421
- .mouseenter(function() { within = true; })
422
- .mouseleave(function() { within = false; })
423
- .mousedown(function(e) {
424
- e.preventDefault();
425
- })
426
- .css({
427
- position: 'absolute',
428
- left: offset.left,
429
- top: offset.top + element.height() +
430
- options.padding * 2
431
- });
432
-
433
- element.after(div);
434
-
435
- var renderOptions = {
436
- selection: element.val(),
437
- selectTime: function(time) {
438
- within = false;
439
- element.val(time);
440
- element.trigger("change");
441
- div.remove();
442
- div = null;
443
- },
444
- isoTime: options.isoTime || false,
445
- meridiemUpperCase: options.meridiemUpperCase || false,
446
- defaultTime: options.defaultTime || {hour: 8, minute: 0},
447
- minTime: options.minTime || {hour: 0, minute: 0},
448
- maxTime: options.maxTime || {hour: 23, minute: 59},
449
- timeInterval: options.timeInterval || 30
450
- };
451
-
452
- if (options.startTime) {
453
- var startTime = parseTime(options.startTime.val());
454
- //Don't display duration if part of a datetime range,
455
- //and start and end times are on different days
456
- if (options.startDate && options.endDate &&
457
- !areDatesEqual(parseDate(options.startDate.val()),
458
- parseDate(options.endDate.val()))) {
459
- startTime = null;
460
- }
461
- if (startTime) {
462
- renderOptions.minTime = startTime;
463
- renderOptions.showDuration = true;
464
- div.addClass('calendricalEndTimePopup');
465
- }
466
- }
467
-
468
- renderTimeSelect(div, renderOptions);
469
- }).blur(function() {
470
- if (within){
471
- if (div) element.focus();
472
- return;
473
- }
474
- if (!div) return;
475
- div.remove();
476
- div = null;
477
- });
478
- });
479
- },
480
-
481
- $.fn.calendricalTimeRange = function(options)
482
- {
483
- if (this.length >= 2) {
484
- $(this[0]).calendricalTime(options);
485
- $(this[1]).calendricalTime($.extend({
486
- startTime: $(this[0])
487
- }, options));
488
- }
489
- return this;
490
- };
491
-
492
- $.fn.calendricalDateTimeRange = function(options)
493
- {
494
- if (this.length >= 4) {
495
- $(this[0]).calendricalDate($.extend({
496
- endDate: $(this[2])
497
- }, options));
498
- $(this[1]).calendricalTime(options);
499
- $(this[2]).calendricalDate(options);
500
- $(this[3]).calendricalTime($.extend({
501
- startTime: $(this[1]),
502
- startDate: $(this[0]),
503
- endDate: $(this[2])
504
- }, options));
505
- }
506
- return this;
507
- };
508
- })(jQuery);