active_frontend 13.3.0 → 14.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/.fasterer.yml +19 -0
  4. data/.reek +27 -0
  5. data/.rubocop.yml +38 -0
  6. data/.scss-lint.yml +27 -0
  7. data/Rakefile +1 -1
  8. data/active_frontend.gemspec +21 -18
  9. data/app/.DS_Store +0 -0
  10. data/app/assets/.DS_Store +0 -0
  11. data/app/assets/fonts/.DS_Store +0 -0
  12. data/app/assets/fonts/dripicons/.DS_Store +0 -0
  13. data/app/assets/fonts/dripicons/dripicons.woff +0 -0
  14. data/app/assets/fonts/fakt-pro/.DS_Store +0 -0
  15. data/app/assets/fonts/fakt-pro/fakt-pro-bold.woff +0 -0
  16. data/app/assets/fonts/fakt-pro/fakt-pro-normal.woff +0 -0
  17. data/app/assets/fonts/fakt-pro/fakt-pro-semibold.woff +0 -0
  18. data/app/assets/fonts/fakt-pro/fakt-pro-semilight.woff +0 -0
  19. data/app/assets/fonts/fakt-soft-pro/.DS_Store +0 -0
  20. data/app/assets/fonts/fakt-soft-pro/fakt-soft-pro-bold.woff +0 -0
  21. data/app/assets/fonts/fakt-soft-pro/fakt-soft-pro-normal.woff +0 -0
  22. data/app/assets/fonts/fakt-soft-pro/fakt-soft-pro-semibold.woff +0 -0
  23. data/app/assets/fonts/fakt-soft-pro/fakt-soft-pro-semilight.woff +0 -0
  24. data/app/assets/images/.DS_Store +0 -0
  25. data/app/assets/images/.keep +0 -0
  26. data/app/assets/images/placeholders/.DS_Store +0 -0
  27. data/app/assets/images/placeholders/camera-large.png +0 -0
  28. data/app/assets/images/placeholders/camera-small.png +0 -0
  29. data/app/assets/images/placeholders/camera.png +0 -0
  30. data/app/assets/images/placeholders/document-large.png +0 -0
  31. data/app/assets/images/placeholders/document-small.png +0 -0
  32. data/app/assets/images/placeholders/document.png +0 -0
  33. data/app/assets/images/placeholders/photo-large.png +0 -0
  34. data/app/assets/images/placeholders/{picture-small.png → photo-small.png} +0 -0
  35. data/app/assets/images/placeholders/photo.png +0 -0
  36. data/app/assets/images/placeholders/store-large.png +0 -0
  37. data/app/assets/images/placeholders/store-small.png +0 -0
  38. data/app/assets/images/placeholders/store.png +0 -0
  39. data/app/assets/images/placeholders/user-large.png +0 -0
  40. data/app/assets/images/placeholders/user-small.png +0 -0
  41. data/app/assets/images/placeholders/user.png +0 -0
  42. data/app/helpers/active_frontend_helper.rb +22 -37
  43. data/lib/.DS_Store +0 -0
  44. data/lib/active_frontend.rb +3 -4
  45. data/lib/active_frontend/.DS_Store +0 -0
  46. data/lib/active_frontend/version.rb +1 -1
  47. data/lib/generators/active_frontend/install_generator.rb +3 -3
  48. data/lib/generators/active_frontend/templates/install.js +35 -30
  49. data/lib/generators/active_frontend/templates/install.scss +55 -58
  50. data/vendor/.DS_Store +0 -0
  51. data/vendor/assets/.DS_Store +0 -0
  52. data/vendor/assets/javascripts/.DS_Store +0 -0
  53. data/vendor/assets/javascripts/active_frontend.js +35 -30
  54. data/vendor/assets/javascripts/base/_affix.js +170 -0
  55. data/vendor/assets/javascripts/base/_alert.js +80 -0
  56. data/vendor/assets/javascripts/base/_animation.js +106 -0
  57. data/vendor/assets/javascripts/base/_button.js +123 -0
  58. data/vendor/assets/javascripts/base/_carousel.js +237 -0
  59. data/vendor/assets/javascripts/base/_collapse.js +200 -0
  60. data/vendor/assets/javascripts/base/_colorpicker.js +147 -0
  61. data/vendor/assets/javascripts/base/_datepicker.js +1411 -0
  62. data/vendor/assets/javascripts/base/_dropdown.js +154 -0
  63. data/vendor/assets/javascripts/base/_filepicker.js +235 -0
  64. data/vendor/assets/javascripts/base/_hoverdown.js +116 -0
  65. data/vendor/assets/javascripts/base/_layout.js +126 -0
  66. data/vendor/assets/javascripts/base/_list.js +103 -0
  67. data/vendor/assets/javascripts/{_modal.js → base/_modal.js} +170 -167
  68. data/vendor/assets/javascripts/base/_popover.js +101 -0
  69. data/vendor/assets/javascripts/base/_scrollspy.js +161 -0
  70. data/vendor/assets/javascripts/base/_switch.js +160 -0
  71. data/vendor/assets/javascripts/base/_tab.js +139 -0
  72. data/vendor/assets/javascripts/base/_table.js +224 -0
  73. data/vendor/assets/javascripts/base/_timeago.js +270 -0
  74. data/vendor/assets/javascripts/base/_timepicker.js +541 -0
  75. data/vendor/assets/javascripts/base/_tooltip.js +525 -0
  76. data/vendor/assets/javascripts/base/_tour.js +268 -0
  77. data/vendor/assets/javascripts/base/_transition.js +52 -0
  78. data/vendor/assets/javascripts/base/_typeahead.js +362 -0
  79. data/vendor/assets/javascripts/extensions/_calendar.js +4709 -0
  80. data/vendor/assets/javascripts/extensions/_chart.js +9371 -0
  81. data/vendor/assets/javascripts/extensions/_map.js +2153 -0
  82. data/vendor/assets/stylesheets/.DS_Store +0 -0
  83. data/vendor/assets/stylesheets/{_mixin.scss → _utility.scss} +96 -10
  84. data/vendor/assets/stylesheets/_variable.scss +201 -19
  85. data/vendor/assets/stylesheets/active_frontend.scss +55 -58
  86. data/vendor/assets/stylesheets/blocks/_anchor.scss +15 -0
  87. data/vendor/assets/stylesheets/blocks/_button.scss +278 -0
  88. data/vendor/assets/stylesheets/blocks/_code.scss +144 -0
  89. data/vendor/assets/stylesheets/blocks/_common.scss +127 -0
  90. data/vendor/assets/stylesheets/blocks/_form.scss +508 -0
  91. data/vendor/assets/stylesheets/blocks/_icon.scss +359 -0
  92. data/vendor/assets/stylesheets/blocks/_list.scss +76 -0
  93. data/vendor/assets/stylesheets/blocks/_multimedia.scss +62 -0
  94. data/vendor/assets/stylesheets/blocks/_reset.scss +179 -0
  95. data/vendor/assets/stylesheets/blocks/_table.scss +211 -0
  96. data/vendor/assets/stylesheets/blocks/_typography.scss +204 -0
  97. data/vendor/assets/stylesheets/components/_ad.scss +78 -0
  98. data/vendor/assets/stylesheets/components/_affix.scss +14 -0
  99. data/vendor/assets/stylesheets/components/_alert.scss +50 -0
  100. data/vendor/assets/stylesheets/components/_animation.scss +1670 -0
  101. data/vendor/assets/stylesheets/components/_breadcrumb.scss +17 -0
  102. data/vendor/assets/stylesheets/components/_calendar.scss +213 -0
  103. data/vendor/assets/stylesheets/components/_card.scss +30 -0
  104. data/vendor/assets/stylesheets/components/_carousel.scss +135 -0
  105. data/vendor/assets/stylesheets/components/_chart.scss +10 -0
  106. data/vendor/assets/stylesheets/components/_collapse.scss +17 -0
  107. data/vendor/assets/stylesheets/components/_colorpicker.scss +38 -0
  108. data/vendor/assets/stylesheets/components/_datepicker.scss +80 -0
  109. data/vendor/assets/stylesheets/components/_dropmenu.scss +151 -0
  110. data/vendor/assets/stylesheets/components/_footer.scss +11 -0
  111. data/vendor/assets/stylesheets/components/_grid.scss +144 -0
  112. data/vendor/assets/stylesheets/components/_header.scss +99 -0
  113. data/vendor/assets/stylesheets/components/_label_and_badge.scss +57 -0
  114. data/vendor/assets/stylesheets/components/_layout.scss +63 -0
  115. data/vendor/assets/stylesheets/components/_map.scss +14 -0
  116. data/vendor/assets/stylesheets/components/_milestone.scss +49 -0
  117. data/vendor/assets/stylesheets/components/_missive.scss +40 -0
  118. data/vendor/assets/stylesheets/components/_modal.scss +126 -0
  119. data/vendor/assets/stylesheets/components/_nav_and_tab.scss +202 -0
  120. data/vendor/assets/stylesheets/components/_navbar.scss +66 -0
  121. data/vendor/assets/stylesheets/components/_pagination.scss +79 -0
  122. data/vendor/assets/stylesheets/components/_placeholder.scss +23 -0
  123. data/vendor/assets/stylesheets/components/_popover.scss +167 -0
  124. data/vendor/assets/stylesheets/components/_progress.scss +62 -0
  125. data/vendor/assets/stylesheets/components/_sidebar.scss +74 -0
  126. data/vendor/assets/stylesheets/components/_spinner.scss +83 -0
  127. data/vendor/assets/stylesheets/components/_switch.scss +150 -0
  128. data/vendor/assets/stylesheets/components/_timepicker.scss +30 -0
  129. data/vendor/assets/stylesheets/components/_tooltip.scss +93 -0
  130. data/vendor/assets/stylesheets/components/_transition.scss +12 -0
  131. data/vendor/assets/stylesheets/components/_typeahead.scss +18 -0
  132. metadata +150 -94
  133. data/app/assets/fonts/gotham/gotham-bold.woff +0 -0
  134. data/app/assets/fonts/gotham/gotham-book.woff +0 -0
  135. data/app/assets/fonts/gotham/gotham-light.woff +0 -0
  136. data/app/assets/fonts/gotham/gotham-medium.woff +0 -0
  137. data/app/assets/fonts/gotham/gotham-rounded-bold.woff +0 -0
  138. data/app/assets/fonts/gotham/gotham-rounded-book.woff +0 -0
  139. data/app/assets/fonts/gotham/gotham-rounded-light.woff +0 -0
  140. data/app/assets/fonts/gotham/gotham-rounded-medium.woff +0 -0
  141. data/app/assets/images/placeholders/archive-large.png +0 -0
  142. data/app/assets/images/placeholders/archive-small.png +0 -0
  143. data/app/assets/images/placeholders/archive.png +0 -0
  144. data/app/assets/images/placeholders/picture-large.png +0 -0
  145. data/app/assets/images/placeholders/picture.png +0 -0
  146. data/vendor/assets/javascripts/_affix.js +0 -153
  147. data/vendor/assets/javascripts/_alert.js +0 -85
  148. data/vendor/assets/javascripts/_animation.js +0 -103
  149. data/vendor/assets/javascripts/_button.js +0 -107
  150. data/vendor/assets/javascripts/_carousel.js +0 -228
  151. data/vendor/assets/javascripts/_chart.js +0 -3742
  152. data/vendor/assets/javascripts/_collapse.js +0 -202
  153. data/vendor/assets/javascripts/_color_picker.js +0 -108
  154. data/vendor/assets/javascripts/_date_picker.js +0 -1650
  155. data/vendor/assets/javascripts/_dropdown.js +0 -156
  156. data/vendor/assets/javascripts/_file_input.js +0 -71
  157. data/vendor/assets/javascripts/_hoverdown.js +0 -109
  158. data/vendor/assets/javascripts/_inputmask.js +0 -341
  159. data/vendor/assets/javascripts/_loader.js +0 -361
  160. data/vendor/assets/javascripts/_map.js +0 -2401
  161. data/vendor/assets/javascripts/_popover.js +0 -99
  162. data/vendor/assets/javascripts/_scrollspy.js +0 -163
  163. data/vendor/assets/javascripts/_slider.js +0 -1572
  164. data/vendor/assets/javascripts/_sort.js +0 -1432
  165. data/vendor/assets/javascripts/_swoggle.js +0 -415
  166. data/vendor/assets/javascripts/_tab.js +0 -146
  167. data/vendor/assets/javascripts/_tablespy.js +0 -1883
  168. data/vendor/assets/javascripts/_time_ago.js +0 -206
  169. data/vendor/assets/javascripts/_time_picker.js +0 -1088
  170. data/vendor/assets/javascripts/_tooltip.js +0 -504
  171. data/vendor/assets/javascripts/_transition.js +0 -50
  172. data/vendor/assets/javascripts/_typeahead.js +0 -366
  173. data/vendor/assets/stylesheets/_ad.scss +0 -63
  174. data/vendor/assets/stylesheets/_affix.scss +0 -14
  175. data/vendor/assets/stylesheets/_alert.scss +0 -114
  176. data/vendor/assets/stylesheets/_animation.scss +0 -1370
  177. data/vendor/assets/stylesheets/_breadcrumb.scss +0 -100
  178. data/vendor/assets/stylesheets/_button.scss +0 -386
  179. data/vendor/assets/stylesheets/_canvas.scss +0 -182
  180. data/vendor/assets/stylesheets/_carousel.scss +0 -158
  181. data/vendor/assets/stylesheets/_chart.scss +0 -15
  182. data/vendor/assets/stylesheets/_code.scss +0 -150
  183. data/vendor/assets/stylesheets/_collapse.scss +0 -14
  184. data/vendor/assets/stylesheets/_color.scss +0 -55
  185. data/vendor/assets/stylesheets/_colorpicker.scss +0 -63
  186. data/vendor/assets/stylesheets/_datepicker.scss +0 -122
  187. data/vendor/assets/stylesheets/_dropdown.scss +0 -248
  188. data/vendor/assets/stylesheets/_footer.scss +0 -71
  189. data/vendor/assets/stylesheets/_form.scss +0 -661
  190. data/vendor/assets/stylesheets/_grid.scss +0 -184
  191. data/vendor/assets/stylesheets/_header.scss +0 -156
  192. data/vendor/assets/stylesheets/_icon.scss +0 -362
  193. data/vendor/assets/stylesheets/_image.scss +0 -33
  194. data/vendor/assets/stylesheets/_label_and_badge.scss +0 -104
  195. data/vendor/assets/stylesheets/_link.scss +0 -55
  196. data/vendor/assets/stylesheets/_list.scss +0 -122
  197. data/vendor/assets/stylesheets/_loader.scss +0 -71
  198. data/vendor/assets/stylesheets/_map.scss +0 -44
  199. data/vendor/assets/stylesheets/_missive.scss +0 -74
  200. data/vendor/assets/stylesheets/_modal.scss +0 -204
  201. data/vendor/assets/stylesheets/_nav_and_tab.scss +0 -230
  202. data/vendor/assets/stylesheets/_navbar.scss +0 -73
  203. data/vendor/assets/stylesheets/_pagination.scss +0 -79
  204. data/vendor/assets/stylesheets/_panel.scss +0 -80
  205. data/vendor/assets/stylesheets/_placeholder.scss +0 -63
  206. data/vendor/assets/stylesheets/_popover.scss +0 -128
  207. data/vendor/assets/stylesheets/_progress.scss +0 -86
  208. data/vendor/assets/stylesheets/_reset.scss +0 -140
  209. data/vendor/assets/stylesheets/_sidebar.scss +0 -148
  210. data/vendor/assets/stylesheets/_slider.scss +0 -151
  211. data/vendor/assets/stylesheets/_spinner.scss +0 -572
  212. data/vendor/assets/stylesheets/_subheader.scss +0 -112
  213. data/vendor/assets/stylesheets/_swoggle.scss +0 -120
  214. data/vendor/assets/stylesheets/_table.scss +0 -210
  215. data/vendor/assets/stylesheets/_timepicker.scss +0 -77
  216. data/vendor/assets/stylesheets/_toolbar.scss +0 -130
  217. data/vendor/assets/stylesheets/_tooltip.scss +0 -105
  218. data/vendor/assets/stylesheets/_transition.scss +0 -11
  219. data/vendor/assets/stylesheets/_trunk.scss +0 -147
  220. data/vendor/assets/stylesheets/_typeahead.scss +0 -18
  221. data/vendor/assets/stylesheets/_typography.scss +0 -233
@@ -1,206 +0,0 @@
1
- (function() {
2
- var TimeAgo;
3
-
4
- TimeAgo = (function() {
5
- function TimeAgo(element, options) {
6
- this.$element = $(element);
7
- this.options = $.extend({}, $.fn.timeago.defaults, options);
8
- this.refresh();
9
- }
10
-
11
- TimeAgo.prototype.startTimer = function() {
12
- return this.interval = setTimeout((function(_this) {
13
- return function() {
14
- return _this.refresh();
15
- };
16
- })(this), this.startInterval);
17
- };
18
-
19
- TimeAgo.prototype.stopTimer = function() {
20
- return clearTimeout(this.interval);
21
- };
22
-
23
- TimeAgo.prototype.restartTimer = function() {
24
- this.stopTimer();
25
- return this.startTimer();
26
- };
27
-
28
- TimeAgo.prototype.refresh = function() {
29
- this.updateTime();
30
- return this.updateInterval();
31
- };
32
-
33
- TimeAgo.prototype.updateTime = function() {
34
- var timeAgoInWords;
35
- timeAgoInWords = this.timeAgoInWords(this.$element.attr(this.options.attr));
36
- return this.$element.html(timeAgoInWords);
37
- };
38
-
39
- TimeAgo.prototype.updateInterval = function() {
40
- var dis, newestTime, newestTimeSrc;
41
- newestTimeSrc = this.$element.attr(this.options.attr);
42
- newestTime = this.parse(newestTimeSrc);
43
- dis = this.getTimeDistanceInSeconds(newestTime);
44
- if (this.options.maxRelative && dis >= this.options.maxRelative) {
45
- return this.stopTimer();
46
- } else if (this.options.showNow && dis < this.options.showNow) {
47
- this.startInterval = (this.options.showNow - dis) * 1000;
48
- return this.restartTimer();
49
- } else if (this.options.showSeconds && dis < 60) {
50
- this.startInterval = 1000;
51
- return this.restartTimer();
52
- } else if (dis < 2700) {
53
- this.startInterval = (60 - dis % 60) * 1000;
54
- return this.restartTimer();
55
- } else if (dis < 5400) {
56
- this.startInterval = (5400 - dis) * 1000;
57
- return this.restartTimer();
58
- } else if (dis < 151200) {
59
- this.startInterval = (3600 - dis % 3600) * 1000;
60
- return this.restartTimer();
61
- } else {
62
- this.startInterval = (86400 - dis % 86400) * 1000;
63
- return this.restartTimer();
64
- }
65
- };
66
-
67
- TimeAgo.prototype.timeAgoInWords = function(timeString) {
68
- var absolutTime, dis;
69
- absolutTime = this.parse(timeString);
70
- dis = this.getTimeDistanceInSeconds(absolutTime);
71
- if (this.options.showNow && this.options.showNow > dis) {
72
- return this.options.lang.prefixes.now;
73
- } else if (this.options.maxRelative && this.options.maxRelative <= dis) {
74
- return this.options.absoluteDate(absolutTime, timeString);
75
- } else {
76
- return this.options.relativeDate(this.options.lang.prefixes.ago, this.distanceOfTimeInWords(dis), this.options.suffix || this.options.lang.suffix);
77
- }
78
- };
79
-
80
- TimeAgo.prototype.parse = function(iso8601) {
81
- var timeStr;
82
- timeStr = $.trim(iso8601);
83
- timeStr = timeStr.replace(/\.\d+/, "");
84
- timeStr = timeStr.replace(/-/, "/").replace(/-/, "/");
85
- timeStr = timeStr.replace(/T/, " ").replace(/Z/, " UTC");
86
- timeStr = timeStr.replace(/([\+\-]\d\d)\:?(\d\d)/, " $1$2");
87
- return new Date(timeStr);
88
- };
89
-
90
- TimeAgo.prototype.getTimeDistanceInSeconds = function(absolutTime) {
91
- var timeDistance;
92
- timeDistance = new Date().getTime() - absolutTime.getTime();
93
- return Math.round(Math.abs(timeDistance) / 1000);
94
- };
95
-
96
- TimeAgo.prototype.distanceOfTimeInWords = function(dis) {
97
- var space;
98
- space = this.options.spacing ? ' ' : '';
99
- if (dis < 60) {
100
- if (this.options.showSeconds) {
101
- if (dis === 0 || dis === 1) {
102
- return "1" + space + this.options.lang.units.second;
103
- } else {
104
- return "" + dis + space + this.options.lang.units.seconds;
105
- }
106
- } else {
107
- return "" + (this.options.approximate ? this.options.lang.prefixes.lt + " " : "1" + space) + this.options.lang.units.minute;
108
- }
109
- } else if (dis < 120) {
110
- return "1" + space + this.options.lang.units.minute;
111
- } else if (dis < 2700) {
112
- return "" + (Math.round(dis / 60)) + space + this.options.lang.units.minutes;
113
- } else if (dis < 5400) {
114
- return "" + (this.options.approximate ? this.options.lang.prefixes.about + " " : "") + "1" + space + this.options.lang.units.hour;
115
- } else if (dis < 86400) {
116
- return "" + (this.options.approximate ? this.options.lang.prefixes.about + " " : "") + (Math.round(dis / 3600)) + space + this.options.lang.units.hours;
117
- } else if (dis < 151200) {
118
- return "1" + space + this.options.lang.units.day;
119
- } else if (dis < 2592000) {
120
- return "" + (Math.round(dis / 86400)) + space + this.options.lang.units.days;
121
- } else if (dis < 5184000) {
122
- return "" + (this.options.approximate ? this.options.lang.prefixes.about + " " : "") + "1" + space + this.options.lang.units.month;
123
- } else if (dis < 31536000) {
124
- return "" + (Math.round(dis / 2592000)) + space + this.options.lang.units.months;
125
- } else if (dis < 39312000) {
126
- return "" + (this.options.approximate ? this.options.lang.prefixes.about + " " : "") + "1" + space + this.options.lang.units.year;
127
- } else if (dis < 54864000) {
128
- return "" + (this.options.approximate ? this.options.lang.prefixes.over + " " : "") + "1" + space + this.options.lang.units.year;
129
- } else if (dis < 63072000) {
130
- return "" + (this.options.approximate ? this.options.lang.prefixes.almost + " " : "") + "2" + space + this.options.lang.units.years;
131
- } else {
132
- return "" + (this.options.approximate ? this.options.lang.prefixes.about + " " : "") + (Math.round(dis / 31536000)) + space + this.options.lang.units.years;
133
- }
134
- };
135
-
136
- return TimeAgo;
137
-
138
- })();
139
-
140
- $.fn.timeago = function(options) {
141
- if (options == null) {
142
- options = {};
143
- }
144
- return this.each(function() {
145
- var $this, attr, data;
146
- $this = $(this);
147
- attr = $this.attr(options.attr || $.fn.timeago.defaults.attr);
148
- if (attr === void 0 || attr === false) {
149
- return;
150
- }
151
- data = $this.data("timeago");
152
- if (!data) {
153
- return $this.data("timeago", new TimeAgo(this, options));
154
- } else if (typeof options === 'string') {
155
- return data[options]();
156
- }
157
- });
158
- };
159
-
160
- $.fn.findAndSelf = function(selector) {
161
- return this.find(selector).add(this.filter(selector));
162
- };
163
-
164
- $.fn.timeago.Constructor = TimeAgo;
165
-
166
- $.fn.timeago.defaults = {
167
- attr: 'datetime',
168
- spacing: true,
169
- approximate: true,
170
- showSeconds: false,
171
- showNow: false,
172
- maxRelative: false,
173
- absoluteDate: function(date, datetime) {
174
- return datetime;
175
- },
176
- relativeDate: function(prefix, distance, suffix) {
177
- return "" + prefix + distance + suffix;
178
- },
179
- lang: {
180
- units: {
181
- second: "second",
182
- seconds: "seconds",
183
- minute: "minute",
184
- minutes: "minutes",
185
- hour: "hour",
186
- hours: "hours",
187
- day: "day",
188
- days: "days",
189
- month: "month",
190
- months: "months",
191
- year: "year",
192
- years: "years"
193
- },
194
- prefixes: {
195
- now: "just now",
196
- lt: "less than a",
197
- about: "about",
198
- over: "over",
199
- almost: "almost",
200
- ago: ""
201
- },
202
- suffix: ' ago'
203
- }
204
- };
205
-
206
- }).call(this);
@@ -1,1088 +0,0 @@
1
- (function($, window, document, undefined) {
2
- 'use strict';
3
-
4
- // TIMEPICKER PUBLIC CLASS DEFINITION
5
- var Timepicker = function(element, options) {
6
- this.widget = '';
7
- this.$element = $(element);
8
- this.defaultTime = options.defaultTime;
9
- this.disableFocus = options.disableFocus;
10
- this.disableMousewheel = options.disableMousewheel;
11
- this.dropdown = options.dropdown;
12
- this.isOpen = options.isOpen;
13
- this.minuteStep = options.minuteStep;
14
- this.modalBackdrop = options.modalBackdrop;
15
- this.orientation = options.orientation;
16
- this.secondStep = options.secondStep;
17
- this.showInputs = options.showInputs;
18
- this.showMeridian = options.showMeridian;
19
- this.showSeconds = options.showSeconds;
20
- this.template = options.template;
21
- this.appendWidgetTo = options.appendWidgetTo;
22
- this.showWidgetOnAddonClick = options.showWidgetOnAddonClick;
23
-
24
- this._init();
25
- };
26
-
27
- Timepicker.prototype = {
28
-
29
- constructor: Timepicker,
30
- _init: function() {
31
- var self = this;
32
-
33
- if (this.showWidgetOnAddonClick && (this.$element.parent().hasClass('input-append') || this.$element.parent().hasClass('input-prepend'))) {
34
- this.$element.parent('.input-append, .input-prepend').find('.add-on').on({
35
- 'click.timepicker': $.proxy(this.showWidget, this)
36
- });
37
- this.$element.on({
38
- 'focus.timepicker': $.proxy(this.highlightUnit, this),
39
- 'click.timepicker': $.proxy(this.highlightUnit, this),
40
- 'keydown.timepicker': $.proxy(this.elementKeydown, this),
41
- 'blur.timepicker': $.proxy(this.blurElement, this),
42
- 'mousewheel.timepicker DOMMouseScroll.timepicker': $.proxy(this.mousewheel, this)
43
- });
44
- } else {
45
- if (this.template) {
46
- this.$element.on({
47
- 'focus.timepicker': $.proxy(this.showWidget, this),
48
- 'click.timepicker': $.proxy(this.showWidget, this),
49
- 'blur.timepicker': $.proxy(this.blurElement, this),
50
- 'mousewheel.timepicker DOMMouseScroll.timepicker': $.proxy(this.mousewheel, this)
51
- });
52
- } else {
53
- this.$element.on({
54
- 'focus.timepicker': $.proxy(this.highlightUnit, this),
55
- 'click.timepicker': $.proxy(this.highlightUnit, this),
56
- 'keydown.timepicker': $.proxy(this.elementKeydown, this),
57
- 'blur.timepicker': $.proxy(this.blurElement, this),
58
- 'mousewheel.timepicker DOMMouseScroll.timepicker': $.proxy(this.mousewheel, this)
59
- });
60
- }
61
- }
62
-
63
- if (this.template !== false) {
64
- this.$widget = $(this.getTemplate()).on('click', $.proxy(this.widgetClick, this));
65
- } else {
66
- this.$widget = false;
67
- }
68
-
69
- if (this.showInputs && this.$widget !== false) {
70
- this.$widget.find('input').each(function() {
71
- $(this).on({
72
- 'click.timepicker': function() { $(this).select(); },
73
- 'keydown.timepicker': $.proxy(self.widgetKeydown, self),
74
- 'keyup.timepicker': $.proxy(self.widgetKeyup, self)
75
- });
76
- });
77
- }
78
-
79
- this.setDefaultTime(this.defaultTime);
80
- },
81
-
82
- blurElement: function() {
83
- this.highlightedUnit = null;
84
- this.updateFromElementVal();
85
- },
86
-
87
- clear: function() {
88
- this.hour = '';
89
- this.minute = '';
90
- this.second = '';
91
- this.meridian = '';
92
-
93
- this.$element.val('');
94
- },
95
-
96
- decrementHour: function() {
97
- if (this.showMeridian) {
98
- if (this.hour === 1) {
99
- this.hour = 12;
100
- } else if (this.hour === 12) {
101
- this.hour--;
102
-
103
- return this.toggleMeridian();
104
- } else if (this.hour === 0) {
105
- this.hour = 11;
106
-
107
- return this.toggleMeridian();
108
- } else {
109
- this.hour--;
110
- }
111
- } else {
112
- if (this.hour <= 0) {
113
- this.hour = 23;
114
- } else {
115
- this.hour--;
116
- }
117
- }
118
- },
119
-
120
- decrementMinute: function(step) {
121
- var newVal;
122
-
123
- if (step) {
124
- newVal = this.minute - step;
125
- } else {
126
- newVal = this.minute - this.minuteStep;
127
- }
128
-
129
- if (newVal < 0) {
130
- this.decrementHour();
131
- this.minute = newVal + 60;
132
- } else {
133
- this.minute = newVal;
134
- }
135
- },
136
-
137
- decrementSecond: function() {
138
- var newVal = this.second - this.secondStep;
139
-
140
- if (newVal < 0) {
141
- this.decrementMinute(true);
142
- this.second = newVal + 60;
143
- } else {
144
- this.second = newVal;
145
- }
146
- },
147
-
148
- elementKeydown: function(e) {
149
- switch (e.keyCode) {
150
- case 9: //tab
151
- case 27: // escape
152
- this.updateFromElementVal();
153
- break;
154
- case 37: // left arrow
155
- e.preventDefault();
156
- this.highlightPrevUnit();
157
- break;
158
- case 38: // up arrow
159
- e.preventDefault();
160
- switch (this.highlightedUnit) {
161
- case 'hour':
162
- this.incrementHour();
163
- this.highlightHour();
164
- break;
165
- case 'minute':
166
- this.incrementMinute();
167
- this.highlightMinute();
168
- break;
169
- case 'second':
170
- this.incrementSecond();
171
- this.highlightSecond();
172
- break;
173
- case 'meridian':
174
- this.toggleMeridian();
175
- this.highlightMeridian();
176
- break;
177
- }
178
- this.update();
179
- break;
180
- case 39: // right arrow
181
- e.preventDefault();
182
- this.highlightNextUnit();
183
- break;
184
- case 40: // down arrow
185
- e.preventDefault();
186
- switch (this.highlightedUnit) {
187
- case 'hour':
188
- this.decrementHour();
189
- this.highlightHour();
190
- break;
191
- case 'minute':
192
- this.decrementMinute();
193
- this.highlightMinute();
194
- break;
195
- case 'second':
196
- this.decrementSecond();
197
- this.highlightSecond();
198
- break;
199
- case 'meridian':
200
- this.toggleMeridian();
201
- this.highlightMeridian();
202
- break;
203
- }
204
-
205
- this.update();
206
- break;
207
- }
208
- },
209
-
210
- getCursorPosition: function() {
211
- var input = this.$element.get(0);
212
-
213
- if ('selectionStart' in input) {// Standard-compliant browsers
214
-
215
- return input.selectionStart;
216
- } else if (document.selection) {// IE fix
217
- input.focus();
218
- var sel = document.selection.createRange(),
219
- selLen = document.selection.createRange().text.length;
220
-
221
- sel.moveStart('character', - input.value.length);
222
-
223
- return sel.text.length - selLen;
224
- }
225
- },
226
-
227
- getTemplate: function() {
228
- var template,
229
- hourTemplate,
230
- minuteTemplate,
231
- secondTemplate,
232
- meridianTemplate,
233
- templateContent;
234
-
235
- if (this.showInputs) {
236
- hourTemplate = '<input type="text" class="timepicker-hour" maxlength="2"/>';
237
- minuteTemplate = '<input type="text" class="timepicker-minute" maxlength="2"/>';
238
- secondTemplate = '<input type="text" class="timepicker-second" maxlength="2"/>';
239
- meridianTemplate = '<input type="text" class="timepicker-meridian" maxlength="2"/>';
240
- } else {
241
- hourTemplate = '<span class="timepicker-hour"></span>';
242
- minuteTemplate = '<span class="timepicker-minute"></span>';
243
- secondTemplate = '<span class="timepicker-second"></span>';
244
- meridianTemplate = '<span class="timepicker-meridian"></span>';
245
- }
246
-
247
- templateContent = '<table>'+
248
- '<tr>'+
249
- '<td><a href="#" data-action="incrementHour"><i class="icon-chevron-up"></i></a></td>'+
250
- '<td class="separator">&nbsp;</td>'+
251
- '<td><a href="#" data-action="incrementMinute"><i class="icon-chevron-up"></i></a></td>'+
252
- (this.showSeconds ?
253
- '<td class="separator">&nbsp;</td>'+
254
- '<td><a href="#" data-action="incrementSecond"><i class="icon-chevron-up"></i></a></td>'
255
- : '') +
256
- (this.showMeridian ?
257
- '<td class="separator">&nbsp;</td>'+
258
- '<td class="meridian-column"><a href="#" data-action="toggleMeridian"><i class="icon-chevron-up"></i></a></td>'
259
- : '') +
260
- '</tr>'+
261
- '<tr>'+
262
- '<td>'+ hourTemplate +'</td> '+
263
- '<td class="separator">:</td>'+
264
- '<td>'+ minuteTemplate +'</td> '+
265
- (this.showSeconds ?
266
- '<td class="separator">:</td>'+
267
- '<td>'+ secondTemplate +'</td>'
268
- : '') +
269
- (this.showMeridian ?
270
- '<td class="separator">&nbsp;</td>'+
271
- '<td>'+ meridianTemplate +'</td>'
272
- : '') +
273
- '</tr>'+
274
- '<tr>'+
275
- '<td><a href="#" data-action="decrementHour"><i class="icon-chevron-down"></i></a></td>'+
276
- '<td class="separator"></td>'+
277
- '<td><a href="#" data-action="decrementMinute"><i class="icon-chevron-down"></i></a></td>'+
278
- (this.showSeconds ?
279
- '<td class="separator">&nbsp;</td>'+
280
- '<td><a href="#" data-action="decrementSecond"><i class="icon-chevron-down"></i></a></td>'
281
- : '') +
282
- (this.showMeridian ?
283
- '<td class="separator">&nbsp;</td>'+
284
- '<td><a href="#" data-action="toggleMeridian"><i class="icon-chevron-down"></i></a></td>'
285
- : '') +
286
- '</tr>'+
287
- '</table>';
288
-
289
- switch(this.template) {
290
- case 'modal':
291
- template = '<div class="timepicker-widget modal hide fade in" data-backdrop="'+ (this.modalBackdrop ? 'true' : 'false') +'">'+
292
- '<div class="modal-header">'+
293
- '<h3>Pick a Time</h3>'+
294
- '</div>'+
295
- '<div class="modal-content">'+
296
- templateContent +
297
- '</div>'+
298
- '<div class="modal-footer">'+
299
- '<a href="#" class="btn btn-primary" data-dismiss="modal">OK</a>'+
300
- '</div>'+
301
- '</div>';
302
- break;
303
- case 'dropdown':
304
- template = '<div class="timepicker-widget ' + this.dropdown +'">'+ templateContent +'</div>';
305
- break;
306
- }
307
-
308
- return template;
309
- },
310
-
311
- getTime: function() {
312
- if (this.hour === '') {
313
- return '';
314
- }
315
-
316
- return this.hour + ':' + (this.minute.toString().length === 1 ? '0' + this.minute : this.minute) + (this.showSeconds ? ':' + (this.second.toString().length === 1 ? '0' + this.second : this.second) : '') + (this.showMeridian ? ' ' + this.meridian : '');
317
- },
318
-
319
- hideWidget: function() {
320
- if (this.isOpen === false) {
321
- return;
322
- }
323
-
324
- this.$element.trigger({
325
- 'type': 'hide.timepicker',
326
- 'time': {
327
- 'value': this.getTime(),
328
- 'hours': this.hour,
329
- 'minutes': this.minute,
330
- 'seconds': this.second,
331
- 'meridian': this.meridian
332
- }
333
- });
334
-
335
- if (this.template === 'modal' && this.$widget.modal) {
336
- this.$widget.modal('hide');
337
- } else {
338
- this.$widget.removeClass('open');
339
- }
340
-
341
- $(document).off('mousedown.timepicker, touchend.timepicker');
342
-
343
- this.isOpen = false;
344
- // show/hide approach taken by datepicker
345
- this.$widget.detach();
346
- },
347
-
348
- highlightUnit: function() {
349
- this.position = this.getCursorPosition();
350
- if (this.position >= 0 && this.position <= 2) {
351
- this.highlightHour();
352
- } else if (this.position >= 3 && this.position <= 5) {
353
- this.highlightMinute();
354
- } else if (this.position >= 6 && this.position <= 8) {
355
- if (this.showSeconds) {
356
- this.highlightSecond();
357
- } else {
358
- this.highlightMeridian();
359
- }
360
- } else if (this.position >= 9 && this.position <= 11) {
361
- this.highlightMeridian();
362
- }
363
- },
364
-
365
- highlightNextUnit: function() {
366
- switch (this.highlightedUnit) {
367
- case 'hour':
368
- this.highlightMinute();
369
- break;
370
- case 'minute':
371
- if (this.showSeconds) {
372
- this.highlightSecond();
373
- } else if (this.showMeridian){
374
- this.highlightMeridian();
375
- } else {
376
- this.highlightHour();
377
- }
378
- break;
379
- case 'second':
380
- if (this.showMeridian) {
381
- this.highlightMeridian();
382
- } else {
383
- this.highlightHour();
384
- }
385
- break;
386
- case 'meridian':
387
- this.highlightHour();
388
- break;
389
- }
390
- },
391
-
392
- highlightPrevUnit: function() {
393
- switch (this.highlightedUnit) {
394
- case 'hour':
395
- if(this.showMeridian){
396
- this.highlightMeridian();
397
- } else if (this.showSeconds) {
398
- this.highlightSecond();
399
- } else {
400
- this.highlightMinute();
401
- }
402
- break;
403
- case 'minute':
404
- this.highlightHour();
405
- break;
406
- case 'second':
407
- this.highlightMinute();
408
- break;
409
- case 'meridian':
410
- if (this.showSeconds) {
411
- this.highlightSecond();
412
- } else {
413
- this.highlightMinute();
414
- }
415
- break;
416
- }
417
- },
418
-
419
- highlightHour: function() {
420
- var $element = this.$element.get(0),
421
- self = this;
422
-
423
- this.highlightedUnit = 'hour';
424
-
425
- if ($element.setSelectionRange) {
426
- setTimeout(function() {
427
- if (self.hour < 10) {
428
- $element.setSelectionRange(0,1);
429
- } else {
430
- $element.setSelectionRange(0,2);
431
- }
432
- }, 0);
433
- }
434
- },
435
-
436
- highlightMinute: function() {
437
- var $element = this.$element.get(0),
438
- self = this;
439
-
440
- this.highlightedUnit = 'minute';
441
-
442
- if ($element.setSelectionRange) {
443
- setTimeout(function() {
444
- if (self.hour < 10) {
445
- $element.setSelectionRange(2,4);
446
- } else {
447
- $element.setSelectionRange(3,5);
448
- }
449
- }, 0);
450
- }
451
- },
452
-
453
- highlightSecond: function() {
454
- var $element = this.$element.get(0),
455
- self = this;
456
-
457
- this.highlightedUnit = 'second';
458
-
459
- if ($element.setSelectionRange) {
460
- setTimeout(function() {
461
- if (self.hour < 10) {
462
- $element.setSelectionRange(5,7);
463
- } else {
464
- $element.setSelectionRange(6,8);
465
- }
466
- }, 0);
467
- }
468
- },
469
-
470
- highlightMeridian: function() {
471
- var $element = this.$element.get(0),
472
- self = this;
473
-
474
- this.highlightedUnit = 'meridian';
475
-
476
- if ($element.setSelectionRange) {
477
- if (this.showSeconds) {
478
- setTimeout(function() {
479
- if (self.hour < 10) {
480
- $element.setSelectionRange(8,10);
481
- } else {
482
- $element.setSelectionRange(9,11);
483
- }
484
- }, 0);
485
- } else {
486
- setTimeout(function() {
487
- if (self.hour < 10) {
488
- $element.setSelectionRange(5,7);
489
- } else {
490
- $element.setSelectionRange(6,8);
491
- }
492
- }, 0);
493
- }
494
- }
495
- },
496
-
497
- incrementHour: function() {
498
- if (this.showMeridian) {
499
- if (this.hour === 11) {
500
- this.hour++;
501
- return this.toggleMeridian();
502
- } else if (this.hour === 12) {
503
- this.hour = 0;
504
- }
505
- }
506
- if (this.hour === 23) {
507
- this.hour = 0;
508
-
509
- return;
510
- }
511
- this.hour++;
512
- },
513
-
514
- incrementMinute: function(step) {
515
- var newVal;
516
-
517
- if (step) {
518
- newVal = this.minute + step;
519
- } else {
520
- newVal = this.minute + this.minuteStep - (this.minute % this.minuteStep);
521
- }
522
-
523
- if (newVal > 59) {
524
- this.incrementHour();
525
- this.minute = newVal - 60;
526
- } else {
527
- this.minute = newVal;
528
- }
529
- },
530
-
531
- incrementSecond: function() {
532
- var newVal = this.second + this.secondStep - (this.second % this.secondStep);
533
-
534
- if (newVal > 59) {
535
- this.incrementMinute(true);
536
- this.second = newVal - 60;
537
- } else {
538
- this.second = newVal;
539
- }
540
- },
541
-
542
- mousewheel: function(e) {
543
- if (this.disableMousewheel) {
544
- return;
545
- }
546
-
547
- e.preventDefault();
548
- e.stopPropagation();
549
-
550
- var delta = e.originalEvent.wheelDelta || -e.originalEvent.detail,
551
- scrollTo = null;
552
-
553
- if (e.type === 'mousewheel') {
554
- scrollTo = (e.originalEvent.wheelDelta * -1);
555
- }
556
- else if (e.type === 'DOMMouseScroll') {
557
- scrollTo = 40 * e.originalEvent.detail;
558
- }
559
-
560
- if (scrollTo) {
561
- e.preventDefault();
562
- $(this).scrollTop(scrollTo + $(this).scrollTop());
563
- }
564
-
565
- switch (this.highlightedUnit) {
566
- case 'minute':
567
- if (delta > 0) {
568
- this.incrementMinute();
569
- } else {
570
- this.decrementMinute();
571
- }
572
- this.highlightMinute();
573
- break;
574
- case 'second':
575
- if (delta > 0) {
576
- this.incrementSecond();
577
- } else {
578
- this.decrementSecond();
579
- }
580
- this.highlightSecond();
581
- break;
582
- case 'meridian':
583
- this.toggleMeridian();
584
- this.highlightMeridian();
585
- break;
586
- default:
587
- if (delta > 0) {
588
- this.incrementHour();
589
- } else {
590
- this.decrementHour();
591
- }
592
- this.highlightHour();
593
- break;
594
- }
595
-
596
- return false;
597
- },
598
-
599
- // This method was adapted from datepicker.
600
- place : function() {
601
- if (this.isInline) {
602
- return;
603
- }
604
- var widgetWidth = this.$widget.outerWidth(), widgetHeight = this.$widget.outerHeight(), visualPadding = 10, windowWidth =
605
- $(window).width(), windowHeight = $(window).height(), scrollTop = $(window).scrollTop();
606
-
607
- var zIndex = parseInt(this.$element.parents().filter(function() {}).first().css('z-index'), 10) + 10;
608
- var offset = this.component ? this.component.parent().offset() : this.$element.offset();
609
- var height = this.component ? this.component.outerHeight(true) : this.$element.outerHeight(false);
610
- var width = this.component ? this.component.outerWidth(true) : this.$element.outerWidth(false);
611
- var left = offset.left, top = offset.top;
612
-
613
- this.$widget.removeClass('timepicker-orient-top timepicker-orient-bottom timepicker-orient-right timepicker-orient-left');
614
-
615
- if (this.orientation.x !== 'auto') {
616
- this.picker.addClass('datepicker-orient-' + this.orientation.x);
617
- if (this.orientation.x === 'right') {
618
- left -= widgetWidth - width;
619
- }
620
- } else{
621
- // auto x orientation is best-placement: if it crosses a window edge, fudge it sideways
622
- // Default to left
623
- this.$widget.addClass('timepicker-orient-left');
624
- if (offset.left < 0) {
625
- left -= offset.left - visualPadding;
626
- } else if (offset.left + widgetWidth > windowWidth) {
627
- left = windowWidth - widgetWidth - visualPadding;
628
- }
629
- }
630
- // auto y orientation is best-situation: top or bottom, no fudging, decision based on which shows more of the widget
631
- var yorient = this.orientation.y, topOverflow, bottomOverflow;
632
- if (yorient === 'auto') {
633
- topOverflow = -scrollTop + offset.top - widgetHeight;
634
- bottomOverflow = scrollTop + windowHeight - (offset.top + height + widgetHeight);
635
- if (Math.max(topOverflow, bottomOverflow) === bottomOverflow) {
636
- yorient = 'top';
637
- } else {
638
- yorient = 'bottom';
639
- }
640
- }
641
- this.$widget.addClass('timepicker-orient-' + yorient);
642
- if (yorient === 'top'){
643
- top += height;
644
- } else{
645
- top -= widgetHeight + parseInt(this.$widget.css('padding-top'), 10);
646
- }
647
-
648
- this.$widget.css({
649
- top : top,
650
- left : left,
651
- zIndex : zIndex
652
- });
653
- },
654
-
655
- remove: function() {
656
- $('document').off('.timepicker');
657
- if (this.$widget) {
658
- this.$widget.remove();
659
- }
660
- delete this.$element.data().timepicker;
661
- },
662
-
663
- setDefaultTime: function(defaultTime) {
664
- if (!this.$element.val()) {
665
- if (defaultTime === 'current') {
666
- var dTime = new Date(),
667
- hours = dTime.getHours(),
668
- minutes = dTime.getMinutes(),
669
- seconds = dTime.getSeconds(),
670
- meridian = 'AM';
671
-
672
- if (seconds !== 0) {
673
- seconds = Math.ceil(dTime.getSeconds() / this.secondStep) * this.secondStep;
674
- if (seconds === 60) {
675
- minutes += 1;
676
- seconds = 0;
677
- }
678
- }
679
-
680
- if (minutes !== 0) {
681
- minutes = Math.ceil(dTime.getMinutes() / this.minuteStep) * this.minuteStep;
682
- if (minutes === 60) {
683
- hours += 1;
684
- minutes = 0;
685
- }
686
- }
687
-
688
- if (this.showMeridian) {
689
- if (hours === 0) {
690
- hours = 12;
691
- } else if (hours >= 12) {
692
- if (hours > 12) {
693
- hours = hours - 12;
694
- }
695
- meridian = 'PM';
696
- } else {
697
- meridian = 'AM';
698
- }
699
- }
700
-
701
- this.hour = hours;
702
- this.minute = minutes;
703
- this.second = seconds;
704
- this.meridian = meridian;
705
-
706
- this.update();
707
-
708
- } else if (defaultTime === false) {
709
- this.hour = 0;
710
- this.minute = 0;
711
- this.second = 0;
712
- this.meridian = 'AM';
713
- } else {
714
- this.setTime(defaultTime);
715
- }
716
- } else {
717
- this.updateFromElementVal();
718
- }
719
- },
720
-
721
- setTime: function(time, ignoreWidget) {
722
- if (!time) {
723
- this.clear();
724
- return;
725
- }
726
-
727
- var timeArray,
728
- hour,
729
- minute,
730
- second,
731
- meridian;
732
-
733
- if (typeof time === 'object' && time.getMonth){
734
- // this is a date object
735
- hour = time.getHours();
736
- minute = time.getMinutes();
737
- second = time.getSeconds();
738
-
739
- if (this.showMeridian){
740
- meridian = 'AM';
741
- if (hour > 12){
742
- meridian = 'PM';
743
- hour = hour % 12;
744
- }
745
-
746
- if (hour === 12){
747
- meridian = 'PM';
748
- }
749
- }
750
- } else {
751
- if (time.match(/p/i) !== null) {
752
- meridian = 'PM';
753
- } else {
754
- meridian = 'AM';
755
- }
756
-
757
- time = time.replace(/[^0-9\:]/g, '');
758
-
759
- timeArray = time.split(':');
760
-
761
- hour = timeArray[0] ? timeArray[0].toString() : timeArray.toString();
762
- minute = timeArray[1] ? timeArray[1].toString() : '';
763
- second = timeArray[2] ? timeArray[2].toString() : '';
764
-
765
- // idiot proofing
766
- if (hour.length > 4) {
767
- second = hour.substr(4, 2);
768
- }
769
- if (hour.length > 2) {
770
- minute = hour.substr(2, 2);
771
- hour = hour.substr(0, 2);
772
- }
773
- if (minute.length > 2) {
774
- second = minute.substr(2, 2);
775
- minute = minute.substr(0, 2);
776
- }
777
- if (second.length > 2) {
778
- second = second.substr(2, 2);
779
- }
780
-
781
- hour = parseInt(hour, 10);
782
- minute = parseInt(minute, 10);
783
- second = parseInt(second, 10);
784
-
785
- if (isNaN(hour)) {
786
- hour = 0;
787
- }
788
- if (isNaN(minute)) {
789
- minute = 0;
790
- }
791
- if (isNaN(second)) {
792
- second = 0;
793
- }
794
-
795
- if (this.showMeridian) {
796
- if (hour < 1) {
797
- hour = 1;
798
- } else if (hour > 12) {
799
- hour = 12;
800
- }
801
- } else {
802
- if (hour >= 24) {
803
- hour = 23;
804
- } else if (hour < 0) {
805
- hour = 0;
806
- }
807
- if (hour < 13 && meridian === 'PM') {
808
- hour = hour + 12;
809
- }
810
- }
811
-
812
- if (minute < 0) {
813
- minute = 0;
814
- } else if (minute >= 60) {
815
- minute = 59;
816
- }
817
-
818
- if (this.showSeconds) {
819
- if (isNaN(second)) {
820
- second = 0;
821
- } else if (second < 0) {
822
- second = 0;
823
- } else if (second >= 60) {
824
- second = 59;
825
- }
826
- }
827
- }
828
-
829
- this.hour = hour;
830
- this.minute = minute;
831
- this.second = second;
832
- this.meridian = meridian;
833
-
834
- this.update(ignoreWidget);
835
- },
836
-
837
- showWidget: function() {
838
- if (this.isOpen) {
839
- return;
840
- }
841
-
842
- if (this.$element.is(':disabled')) {
843
- return;
844
- }
845
-
846
- // show/hide approach taken by datepicker
847
- this.$widget.appendTo(this.appendWidgetTo);
848
- var self = this;
849
- $(document).on('mousedown.timepicker, touchend.timepicker', function (e) {
850
- // This condition was inspired by datepicker.
851
- // The element the timepicker is invoked on is the input but it has a sibling for addon/button.
852
- if (!(self.$element.parent().find(e.target).length ||
853
- self.$widget.is(e.target) ||
854
- self.$widget.find(e.target).length)) {
855
- self.hideWidget();
856
- }
857
- });
858
-
859
- this.$element.trigger({
860
- 'type': 'show.timepicker',
861
- 'time': {
862
- 'value': this.getTime(),
863
- 'hours': this.hour,
864
- 'minutes': this.minute,
865
- 'seconds': this.second,
866
- 'meridian': this.meridian
867
- }
868
- });
869
-
870
- this.place();
871
- if (this.disableFocus) {
872
- this.$element.blur();
873
- }
874
-
875
- // widget shouldn't be empty on open
876
- if (this.hour === '') {
877
- if (this.defaultTime) {
878
- this.setDefaultTime(this.defaultTime);
879
- } else {
880
- this.setTime('0:0:0');
881
- }
882
- }
883
-
884
- if (this.template === 'modal' && this.$widget.modal) {
885
- this.$widget.modal('show').on('hidden', $.proxy(this.hideWidget, this));
886
- } else {
887
- if (this.isOpen === false) {
888
- this.$widget.addClass('open');
889
- }
890
- }
891
-
892
- this.isOpen = true;
893
- },
894
-
895
- toggleMeridian: function() {
896
- this.meridian = this.meridian === 'AM' ? 'PM' : 'AM';
897
- },
898
-
899
- update: function(ignoreWidget) {
900
- this.updateElement();
901
- if (!ignoreWidget) {
902
- this.updateWidget();
903
- }
904
-
905
- this.$element.trigger({
906
- 'type': 'changeTime.timepicker',
907
- 'time': {
908
- 'value': this.getTime(),
909
- 'hours': this.hour,
910
- 'minutes': this.minute,
911
- 'seconds': this.second,
912
- 'meridian': this.meridian
913
- }
914
- });
915
- },
916
-
917
- updateElement: function() {
918
- this.$element.val(this.getTime()).change();
919
- },
920
-
921
- updateFromElementVal: function() {
922
- this.setTime(this.$element.val());
923
- },
924
-
925
- updateWidget: function() {
926
- if (this.$widget === false) {
927
- return;
928
- }
929
-
930
- var hour = this.hour,
931
- minute = this.minute.toString().length === 1 ? '0' + this.minute : this.minute,
932
- second = this.second.toString().length === 1 ? '0' + this.second : this.second;
933
-
934
- if (this.showInputs) {
935
- this.$widget.find('input.timepicker-hour').val(hour);
936
- this.$widget.find('input.timepicker-minute').val(minute);
937
-
938
- if (this.showSeconds) {
939
- this.$widget.find('input.timepicker-second').val(second);
940
- }
941
- if (this.showMeridian) {
942
- this.$widget.find('input.timepicker-meridian').val(this.meridian);
943
- }
944
- } else {
945
- this.$widget.find('span.timepicker-hour').text(hour);
946
- this.$widget.find('span.timepicker-minute').text(minute);
947
-
948
- if (this.showSeconds) {
949
- this.$widget.find('span.timepicker-second').text(second);
950
- }
951
- if (this.showMeridian) {
952
- this.$widget.find('span.timepicker-meridian').text(this.meridian);
953
- }
954
- }
955
- },
956
-
957
- updateFromWidgetInputs: function() {
958
- if (this.$widget === false) {
959
- return;
960
- }
961
-
962
- var t = this.$widget.find('input.timepicker-hour').val() + ':' +
963
- this.$widget.find('input.timepicker-minute').val() +
964
- (this.showSeconds ? ':' + this.$widget.find('input.timepicker-second').val() : '') +
965
- (this.showMeridian ? this.$widget.find('input.timepicker-meridian').val() : '')
966
- ;
967
-
968
- this.setTime(t, true);
969
- },
970
-
971
- widgetClick: function(e) {
972
- e.stopPropagation();
973
- e.preventDefault();
974
-
975
- var $input = $(e.target),
976
- action = $input.closest('a').data('action');
977
-
978
- if (action) {
979
- this[action]();
980
- }
981
- this.update();
982
-
983
- if ($input.is('input')) {
984
- $input.get(0).setSelectionRange(0,2);
985
- }
986
- },
987
-
988
- widgetKeydown: function(e) {
989
- var $input = $(e.target),
990
- name = $input.attr('class').replace('timepicker-', '');
991
-
992
- switch (e.keyCode) {
993
- case 9: //tab
994
- if ((this.showMeridian && name === 'meridian') || (this.showSeconds && name === 'second') || (!this.showMeridian && !this.showSeconds && name === 'minute')) {
995
- return this.hideWidget();
996
- }
997
- break;
998
- case 27: // escape
999
- this.hideWidget();
1000
- break;
1001
- case 38: // up arrow
1002
- e.preventDefault();
1003
- switch (name) {
1004
- case 'hour':
1005
- this.incrementHour();
1006
- break;
1007
- case 'minute':
1008
- this.incrementMinute();
1009
- break;
1010
- case 'second':
1011
- this.incrementSecond();
1012
- break;
1013
- case 'meridian':
1014
- this.toggleMeridian();
1015
- break;
1016
- }
1017
- this.setTime(this.getTime());
1018
- $input.get(0).setSelectionRange(0,2);
1019
- break;
1020
- case 40: // down arrow
1021
- e.preventDefault();
1022
- switch (name) {
1023
- case 'hour':
1024
- this.decrementHour();
1025
- break;
1026
- case 'minute':
1027
- this.decrementMinute();
1028
- break;
1029
- case 'second':
1030
- this.decrementSecond();
1031
- break;
1032
- case 'meridian':
1033
- this.toggleMeridian();
1034
- break;
1035
- }
1036
- this.setTime(this.getTime());
1037
- $input.get(0).setSelectionRange(0,2);
1038
- break;
1039
- }
1040
- },
1041
-
1042
- widgetKeyup: function(e) {
1043
- if ((e.keyCode === 65) || (e.keyCode === 77) || (e.keyCode === 80) || (e.keyCode === 46) || (e.keyCode === 8) || (e.keyCode >= 46 && e.keyCode <= 57)) {
1044
- this.updateFromWidgetInputs();
1045
- }
1046
- }
1047
- };
1048
-
1049
- //TIMEPICKER PLUGIN DEFINITION
1050
- $.fn.timepicker = function(option) {
1051
- var args = Array.apply(null, arguments);
1052
- args.shift();
1053
- return this.each(function() {
1054
- var $this = $(this),
1055
- data = $this.data('timepicker'),
1056
- options = typeof option === 'object' && option;
1057
-
1058
- if (!data) {
1059
- $this.data('timepicker', (data = new Timepicker(this, $.extend({}, $.fn.timepicker.defaults, options, $(this).data()))));
1060
- }
1061
-
1062
- if (typeof option === 'string') {
1063
- data[option].apply(data, args);
1064
- }
1065
- });
1066
- };
1067
-
1068
- $.fn.timepicker.defaults = {
1069
- defaultTime: 'current',
1070
- disableFocus: false,
1071
- disableMousewheel: false,
1072
- dropdown: 'dropdown-menu',
1073
- isOpen: false,
1074
- minuteStep: 15,
1075
- modalBackdrop: false,
1076
- orientation: { x: 'auto', y: 'auto'},
1077
- secondStep: 15,
1078
- showSeconds: false,
1079
- showInputs: true,
1080
- showMeridian: true,
1081
- template: 'dropdown',
1082
- appendWidgetTo: 'body',
1083
- showWidgetOnAddonClick: true
1084
- };
1085
-
1086
- $.fn.timepicker.Constructor = Timepicker;
1087
-
1088
- })(jQuery, window, document);