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
@@ -0,0 +1,224 @@
1
+ +function ($) {
2
+ 'use strict';
3
+
4
+ // TABLE CLASS DEFINITION
5
+ // ======================
6
+
7
+ var Table = function (element, options) {
8
+ this.$element = $(element);
9
+ this.options = $.extend({}, Table.DEFAULTS, options);
10
+
11
+ this.init();
12
+ };
13
+
14
+ Table.VERSION = '1.0.0';
15
+ Table.DEFAULTS = {
16
+ templates: {
17
+ downArrow: '<i class="icon-chevron-down pull-right"></i>',
18
+ noArrow: '<i class="icon-minus pull-right"></i>',
19
+ upArrow: '<i class="icon-chevron-up pull-right"></i>'
20
+ }
21
+ };
22
+
23
+ Table.prototype.constructor = Table;
24
+
25
+ Table.prototype.init = function () {
26
+ this.setSortableColumns();
27
+ this.setSortableClone();
28
+ };
29
+
30
+ Table.prototype.setSortableClone = function () {
31
+ this.$container = $('<span>')
32
+ .addClass('bsTableClone')
33
+ .css({
34
+ display: 'none',
35
+ height: 0,
36
+ position: 'absolute',
37
+ width: 0
38
+ });
39
+
40
+ this.$container.append(this.$element.clone());
41
+ this.$element.parent().append(this.$container);
42
+ };
43
+
44
+ Table.prototype.setSortableColumns = function () {
45
+ var _self = this;
46
+
47
+ this.$element.find('thead tr th').each(function () {
48
+ var trTh = $(this);
49
+
50
+ if (trTh.hasClass('no-sort') === false) {
51
+ trTh.addClass('sort');
52
+
53
+ _self.setSortStatus(trTh, 'sortable');
54
+ _self.bindSortClick(trTh);
55
+ }
56
+ });
57
+ };
58
+
59
+ Table.prototype.setSortStatus = function (trTh, type) {
60
+ trTh.attr('data-sort', type);
61
+
62
+ var icon = trTh.find('.bsTableIcon').first();
63
+
64
+ if (icon !== null) icon.remove();
65
+
66
+ switch (type) {
67
+ case 'up':
68
+ icon = this.options.templates.upArrow;
69
+ break;
70
+ case 'down':
71
+ icon = this.options.templates.downArrow;
72
+ break;
73
+ default:
74
+ icon = this.options.templates.noArrow;
75
+ break;
76
+ }
77
+
78
+ icon = $(icon).addClass('bsTableIcon');
79
+
80
+ trTh.append(icon);
81
+ };
82
+
83
+ Table.prototype.bindSortClick = function (trTh) {
84
+ var bindEvent = 'click';
85
+
86
+ trTh.unbind(bindEvent);
87
+ trTh.bind(bindEvent, this.initSortClick(trTh));
88
+ };
89
+
90
+ Table.prototype.initSortClick = function (trTh) {
91
+ var _self = this;
92
+ var table = this.$element;
93
+
94
+ var sortClick = function () {
95
+ var dataSort = trTh.attr('data-sort');
96
+ var trThParentTh = trTh.parent().find('th');
97
+ var reSort = 'sortable';
98
+
99
+ trThParentTh.each(function () {
100
+ var th = $(this);
101
+
102
+ if (th.hasClass('no-sort') === false) _self.setSortStatus(th, 'sortable');
103
+ });
104
+
105
+ switch (dataSort) {
106
+ case 'up':
107
+ reSort = 'down';
108
+ break;
109
+ case 'down':
110
+ reSort = 'sortable';
111
+ break;
112
+ default:
113
+ reSort = 'up';
114
+ break;
115
+ }
116
+
117
+ _self.setSortStatus(trTh, reSort);
118
+
119
+ var colIndex = 0;
120
+ var sudoColIndex = 0;
121
+
122
+ trThParentTh.each(function () {
123
+ if ($(this).attr('data-sort') === reSort) {
124
+ sudoColIndex = colIndex;
125
+ return false;
126
+ } else {
127
+ colIndex++;
128
+ }
129
+ });
130
+
131
+ var numeric = true;
132
+ var clonedTable = _self.$container.find('table');
133
+ var clonedTr = clonedTable.find('tbody tr');
134
+ var clonedColVals = [];
135
+ var clonedRowsMap = {};
136
+ var i = 0;
137
+
138
+ for (i = 0; i < clonedTr.length; i++) {
139
+ var currentRow = clonedTable.find('tbody tr:eq(' + i + ')');
140
+ var key = currentRow.children('td:eq(' + sudoColIndex + ')').html();
141
+
142
+ if ($.isNumeric(key)) {
143
+ var trailing_i;
144
+
145
+ trailing_i = (i + 1) / (clonedTr.length + 1);
146
+ trailing_i = trailing_i.toString();
147
+ trailing_i = trailing_i.substr(2);
148
+
149
+ if (key.indexOf('.') === -1) {
150
+ key = key + '.' + trailing_i;
151
+ } else {
152
+ key = key + trailing_i;
153
+ }
154
+ } else {
155
+ key = key + ':' + i;
156
+ numeric = false;
157
+ }
158
+
159
+ clonedColVals.push(key);
160
+ clonedRowsMap[key] = currentRow.clone();
161
+ }
162
+
163
+ if (reSort !== 'sortable') {
164
+ if (numeric) {
165
+ clonedColVals.sort(function (a, b) {
166
+ return a - b;
167
+ });
168
+ } else {
169
+ clonedColVals.sort();
170
+ }
171
+
172
+ if (reSort === 'up') clonedColVals.reverse();
173
+ }
174
+
175
+ var tbody = table.find('tbody');
176
+ tbody.html('');
177
+
178
+ for (i = 0; i < clonedColVals.length; i++) {
179
+ tbody.append(clonedRowsMap[clonedColVals[i]]);
180
+ }
181
+ };
182
+
183
+ return sortClick;
184
+ };
185
+
186
+ // TABLE PLUGIN DEFINITION
187
+ // =======================
188
+
189
+ function Plugin(option) {
190
+ return this.each(function () {
191
+ var $this = $(this);
192
+ var data = $this.data('bs.table');
193
+ var options = typeof option === 'object' && option;
194
+
195
+ if (!data) $this.data('bs.table', (data = new Table(this, options)));
196
+ if (typeof option === 'string') data[option]();
197
+ });
198
+ }
199
+
200
+ var old = $.fn.table;
201
+
202
+ $.fn.table = Plugin;
203
+ $.fn.table.Constructor = Table;
204
+
205
+ // TABLE NO CONFLICT
206
+ // =================
207
+
208
+ $.fn.table.noConflict = function () {
209
+ $.fn.table = old;
210
+ return this;
211
+ };
212
+
213
+ // TABLE DATA-API
214
+ // ==============
215
+
216
+ $(document).on('ready.bs.table.data-api', function () {
217
+ $('[data-toggle="table"]').each(function () {
218
+ var $this = $(this);
219
+ if ($this.data('table')) return;
220
+ Plugin.call($this, $this.data());
221
+ });
222
+ });
223
+
224
+ }(jQuery);
@@ -0,0 +1,270 @@
1
+ +function ($) {
2
+ 'use strict';
3
+
4
+ // TIMEAGO CLASS DEFINITION
5
+ // ========================
6
+
7
+ var Timeago = function (element, options) {
8
+ this.$element = $(element);
9
+ this.settings = {
10
+ time: this.$element.data('time')
11
+ };
12
+ this.options = $.extend({}, Timeago.DEFAULTS, this.settings, options);
13
+
14
+ this.$time = this.options.time;
15
+
16
+ this.refresh();
17
+ };
18
+
19
+ Timeago.VERSION = '1.0.0';
20
+ Timeago.DEFAULTS = {
21
+ approximate: true,
22
+ maxRelative: false,
23
+ showNow: false,
24
+ showSeconds: false,
25
+ spacing: true,
26
+ text: {
27
+ prefixes: {
28
+ now: 'just now',
29
+ lt: 'less than a',
30
+ about: 'about',
31
+ over: 'over',
32
+ almost: 'almost',
33
+ ago: ''
34
+ },
35
+ suffix: ' ago',
36
+ units: {
37
+ second: 'second',
38
+ seconds: 'seconds',
39
+ minute: 'minute',
40
+ minutes: 'minutes',
41
+ hour: 'hour',
42
+ hours: 'hours',
43
+ day: 'day',
44
+ days: 'days',
45
+ month: 'month',
46
+ months: 'months',
47
+ year: 'year',
48
+ years: 'years'
49
+ }
50
+ }
51
+ };
52
+
53
+ Timeago.prototype.constructor = Timeago;
54
+
55
+ Timeago.prototype.startTimer = function () {
56
+ var _self = this;
57
+
58
+ return this.interval = setTimeout(function () {
59
+ return _self.refresh();
60
+ }, this.startInterval);
61
+ };
62
+
63
+ Timeago.prototype.stopTimer = function () {
64
+ return clearTimeout(this.interval);
65
+ };
66
+
67
+ Timeago.prototype.restartTimer = function () {
68
+ this.stopTimer();
69
+ return this.startTimer();
70
+ };
71
+
72
+ Timeago.prototype.refresh = function () {
73
+ this.updateTime();
74
+ return this.updateInterval();
75
+ };
76
+
77
+ Timeago.prototype.updateTime = function () {
78
+ var timeStr = this.timeAgoInWords(this.$time);
79
+
80
+ return this.$element.html(timeStr);
81
+ };
82
+
83
+ Timeago.prototype.updateInterval = function () {
84
+ var newestTime = this.parseStr(this.$time);
85
+ var distance = this.getTimeDistanceInSeconds(newestTime);
86
+
87
+ if (this.options.maxRelative && distance >= this.options.maxRelative) {
88
+ return this.stopTimer();
89
+ } else if (this.options.showNow && distance < this.options.showNow) {
90
+ this.startInterval = (this.options.showNow - distance) * 1000;
91
+ return this.restartTimer();
92
+ } else if (this.options.showSeconds && distance < 60) {
93
+ this.startInterval = 1000;
94
+ return this.restartTimer();
95
+ } else if (distance < 2700) {
96
+ this.startInterval = (60 - distance % 60) * 1000;
97
+ return this.restartTimer();
98
+ } else if (distance < 5400) {
99
+ this.startInterval = (5400 - distance) * 1000;
100
+ return this.restartTimer();
101
+ } else if (distance < 151200) {
102
+ this.startInterval = (3600 - distance % 3600) * 1000;
103
+ return this.restartTimer();
104
+ } else {
105
+ this.startInterval = (86400 - distance % 86400) * 1000;
106
+ return this.restartTimer();
107
+ }
108
+ };
109
+
110
+ Timeago.prototype.timeAgoInWords = function (timeStr) {
111
+ var absTime = this.parseStr(timeStr);
112
+ var distance = this.getTimeDistanceInSeconds(absTime);
113
+
114
+ if (this.options.showNow && this.options.showNow > distance) {
115
+ return this.options.text.prefixes.now;
116
+ } else if (this.options.maxRelative && this.options.maxRelative <= distance) {
117
+ return timeStr;
118
+ } else {
119
+ return '' +
120
+ this.options.text.prefixes.ago +
121
+ this.distanceOfTimeInWords(distance) +
122
+ this.options.text.suffix;
123
+ }
124
+ };
125
+
126
+ Timeago.prototype.parseStr = function (iso8601) {
127
+ var timeStr = $.trim(iso8601);
128
+
129
+ timeStr = timeStr.replace(/\.\d+/, '');
130
+ timeStr = timeStr.replace(/-/, '/').replace(/-/, '/');
131
+ timeStr = timeStr.replace(/T/, ' ').replace(/Z/, ' UTC');
132
+ timeStr = timeStr.replace(/([\+\-]\d\d)\:?(\d\d)/, ' $1$2');
133
+
134
+ return new Date(timeStr);
135
+ };
136
+
137
+ Timeago.prototype.getTimeDistanceInSeconds = function (absTime) {
138
+ var distance = new Date().getTime() - absTime.getTime();
139
+
140
+ return Math.round(Math.abs(distance) / 1000);
141
+ };
142
+
143
+ Timeago.prototype.distanceOfTimeInWords = function (distance) {
144
+ var about = this.options.approximate ? this.options.text.prefixes.about + ' ' : '';
145
+ var space = this.options.spacing ? ' ' : '';
146
+
147
+ if (distance < 60) {
148
+ if (this.options.showSeconds) {
149
+ if (distance === 0 || distance === 1) {
150
+ return '1' +
151
+ space +
152
+ this.options.text.units.second;
153
+ } else {
154
+ return '' +
155
+ distance +
156
+ space +
157
+ this.options.text.units.seconds;
158
+ }
159
+ } else {
160
+ return '' +
161
+ (this.options.approximate ? this.options.text.prefixes.lt + ' ' : '1' + space) +
162
+ this.options.text.units.minute;
163
+ }
164
+ } else if (distance < 120) {
165
+ return '1' +
166
+ space +
167
+ this.options.text.units.minute;
168
+ } else if (distance < 2700) {
169
+ return '' +
170
+ (Math.round(distance / 60)) +
171
+ space +
172
+ this.options.text.units.minutes;
173
+ } else if (distance < 5400) {
174
+ return '' +
175
+ about +
176
+ '1' +
177
+ space +
178
+ this.options.text.units.hour;
179
+ } else if (distance < 86400) {
180
+ return '' +
181
+ about +
182
+ (Math.round(distance / 3600)) +
183
+ space +
184
+ this.options.text.units.hours;
185
+ } else if (distance < 151200) {
186
+ return '1' +
187
+ space +
188
+ this.options.text.units.day;
189
+ } else if (distance < 2592000) {
190
+ return '' +
191
+ (Math.round(distance / 86400)) +
192
+ space +
193
+ this.options.text.units.days;
194
+ } else if (distance < 5184000) {
195
+ return '' +
196
+ about +
197
+ '1' +
198
+ space +
199
+ this.options.text.units.month;
200
+ } else if (distance < 31536000) {
201
+ return '' +
202
+ (Math.round(distance / 2592000)) +
203
+ space +
204
+ this.options.text.units.months;
205
+ } else if (distance < 39312000) {
206
+ return '' +
207
+ about +
208
+ '1' +
209
+ space +
210
+ this.options.text.units.year;
211
+ } else if (distance < 54864000) {
212
+ return '' +
213
+ about +
214
+ '1' +
215
+ space +
216
+ this.options.text.units.year;
217
+ } else if (distance < 63072000) {
218
+ return '' +
219
+ about +
220
+ '2' +
221
+ space +
222
+ this.options.text.units.years;
223
+ } else {
224
+ return '' +
225
+ about +
226
+ (Math.round(distance / 31536000)) +
227
+ space +
228
+ this.options.text.units.years;
229
+ }
230
+ };
231
+
232
+ // TIMEAGO PLUGIN DEFINITION
233
+ // =========================
234
+
235
+ function Plugin(option) {
236
+ return this.each(function () {
237
+ var $this = $(this);
238
+ var data = $this.data('bs.timeago');
239
+ var options = typeof option === 'object' && option;
240
+
241
+ if (!data) $this.data('bs.timeago', (data = new Timeago(this, options)));
242
+ if (typeof option === 'string') data[option]();
243
+ });
244
+ }
245
+
246
+ var old = $.fn.timeago;
247
+
248
+ $.fn.timeago = Plugin;
249
+ $.fn.timeago.Constructor = Timeago;
250
+
251
+ // TIMEAGO NO CONFLICT
252
+ // ===================
253
+
254
+ $.fn.timeago.noConflict = function () {
255
+ $.fn.timeago = old;
256
+ return this;
257
+ };
258
+
259
+ // TIMEAGO DATA-API
260
+ // ================
261
+
262
+ $(document).on('ready.bs.timeago.data-api', function () {
263
+ $('[data-toggle="timeago"]').each(function () {
264
+ var $this = $(this);
265
+ if ($this.data('timeago')) return;
266
+ Plugin.call($this, $this.data());
267
+ });
268
+ });
269
+
270
+ }(jQuery);