megatron 0.1.89 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/megatron/index.js +34 -94
- data/app/assets/javascripts/megatron/utils/activate-nav-items.js +20 -0
- data/app/assets/javascripts/megatron/utils/auto-navigate.js +11 -14
- data/app/assets/javascripts/megatron/utils/clipboard.js +9 -1
- data/app/assets/javascripts/megatron/utils/form-flash.js +14 -0
- data/app/assets/javascripts/megatron/utils/form-notify.js +50 -38
- data/app/assets/javascripts/megatron/utils/highlight-code.js +46 -0
- data/app/assets/javascripts/megatron/utils/messages.js +10 -6
- data/app/assets/javascripts/megatron/utils/progress-bar.js +9 -0
- data/app/assets/javascripts/megatron/utils/text-helpers.js +17 -7
- data/app/assets/stylesheets/megatron/modules/forms/_range-input.scss +37 -37
- data/app/helpers/megatron/application_helper.rb +9 -7
- data/app/helpers/megatron/form_helper.rb +6 -4
- data/app/views/layouts/megatron/application.html.slim +1 -1
- data/lib/megatron/helper.rb +27 -29
- data/lib/megatron/version.rb +1 -1
- data/public/assets/megatron/{megatron-0.1.89.css → megatron-0.2.0.css} +2 -2
- data/public/assets/megatron/megatron-0.2.0.css.gz +0 -0
- data/public/assets/megatron/{megatron-0.1.89.css.map → megatron-0.2.0.css.map} +2 -2
- data/public/assets/megatron/{megatron-0.1.89.js → megatron-0.2.0.js} +105 -134
- data/public/assets/megatron/megatron-0.2.0.js.gz +0 -0
- data/public/assets/megatron/megatron-0.2.0.map.json +1 -0
- data/public/assets/megatron/{megatron-error-pages-0.1.89.css → megatron-error-pages-0.2.0.css} +0 -0
- data/public/assets/megatron/{megatron-error-pages-0.1.89.css.gz → megatron-error-pages-0.2.0.css.gz} +0 -0
- metadata +14 -22
- data/app/assets/javascripts/megatron/form.js +0 -36
- data/app/assets/javascripts/megatron/link.js +0 -58
- data/app/assets/javascripts/megatron/utils/index.js +0 -81
- data/app/assets/javascripts/megatron/utils/range-input-helper.js +0 -280
- data/app/assets/javascripts/megatron/utils/time/date-to-html.js +0 -59
- data/app/assets/javascripts/megatron/utils/time/time-switch.js +0 -84
- data/app/assets/javascripts/megatron/utils/time/timeago.js +0 -95
- data/app/assets/javascripts/megatron/utils/toggler.js +0 -274
- data/app/assets/stylesheets/_example.scss +0 -76
- data/app/assets/stylesheets/_grid.scss +0 -41
- data/app/assets/stylesheets/_typography.scss +0 -38
- data/app/assets/stylesheets/application.scss +0 -19
- data/public/assets/megatron/megatron-0.1.89.css.gz +0 -0
- data/public/assets/megatron/megatron-0.1.89.js.gz +0 -0
- data/public/assets/megatron/megatron-0.1.89.map.json +0 -1
@@ -1,81 +0,0 @@
|
|
1
|
-
var bean = require('bean')
|
2
|
-
var CodeMirror = require('codemirror')
|
3
|
-
var Toggler = require('./toggler')
|
4
|
-
var Messages = require('./messages')
|
5
|
-
var AutoNavigate = require('./auto-navigate')
|
6
|
-
var TextHelpers = require('./text-helpers')
|
7
|
-
var RangeInputHelper = require('./range-input-helper')
|
8
|
-
var Timeago = require('./time/timeago')
|
9
|
-
var TimeSwitch = require('./time/time-switch')
|
10
|
-
var notify = require('notify')
|
11
|
-
|
12
|
-
require('codemirror/mode/htmlmixed/htmlmixed')
|
13
|
-
require('codemirror/mode/slim/slim')
|
14
|
-
require('codemirror/mode/javascript/javascript')
|
15
|
-
require('codemirror/mode/css/css')
|
16
|
-
require('codemirror/mode/sql/sql')
|
17
|
-
require('codemirror/addon/runmode/runmode.js')
|
18
|
-
require('codemirror/addon/edit/matchbrackets.js')
|
19
|
-
|
20
|
-
module.exports = {
|
21
|
-
Timeago: Timeago,
|
22
|
-
TimeSwitch: TimeSwitch,
|
23
|
-
CodeMirror: CodeMirror,
|
24
|
-
Toggler: Toggler,
|
25
|
-
Messages: Messages,
|
26
|
-
AutoNavigate: AutoNavigate,
|
27
|
-
TextHelpers: TextHelpers,
|
28
|
-
RangeInputHelper: RangeInputHelper,
|
29
|
-
|
30
|
-
toggleActiveNav: function toggleActiveNav(){
|
31
|
-
Array.prototype.forEach.call(document.querySelectorAll('[data-match-url]'), function(node){
|
32
|
-
var matcher = node.getAttribute('data-match-url')
|
33
|
-
if (matcher && new RegExp(node.getAttribute('data-match-url'), "i").test(location.pathname)) {
|
34
|
-
node.className += ' here'
|
35
|
-
}
|
36
|
-
})
|
37
|
-
},
|
38
|
-
|
39
|
-
highlightCode: function highlightCode(){
|
40
|
-
var aliasLang = function(lang) {
|
41
|
-
var aliases = {
|
42
|
-
'markup': 'htmlmixed',
|
43
|
-
'html': 'htmlmixed',
|
44
|
-
'json': 'javascript',
|
45
|
-
}
|
46
|
-
|
47
|
-
return(aliases[lang] || lang)
|
48
|
-
}
|
49
|
-
var elements = document.querySelectorAll('[class*="language-"], [class*="lang-"]');
|
50
|
-
for (var i=0, element; element = elements[i++];) {
|
51
|
-
var lang = element.className.match(/lang.*?-(\S+)/)[1]
|
52
|
-
|
53
|
-
// Standardize classes: lang-[language]
|
54
|
-
if (element.classList.contains('language-'+lang)) {
|
55
|
-
element.classList.remove('language-'+lang)
|
56
|
-
element.classList.add('lang-'+lang)
|
57
|
-
}
|
58
|
-
var code = element.textContent.trim()
|
59
|
-
|
60
|
-
var options = {}
|
61
|
-
if(lang == 'json') {
|
62
|
-
options.json = true
|
63
|
-
}
|
64
|
-
|
65
|
-
CodeMirror.runMode(code, aliasLang(lang), element, options)
|
66
|
-
element.innerHTML = "<code class='highlighted-code static-code cm-s-default'>" + element.innerHTML + "</code>"
|
67
|
-
element.classList.add('highlighted')
|
68
|
-
}
|
69
|
-
},
|
70
|
-
|
71
|
-
notifyFormFlash: function notifyFormFlash(){
|
72
|
-
var flash = document.querySelector('.form-flash')
|
73
|
-
if (flash) {
|
74
|
-
var type = flash.dataset.type || 'error'
|
75
|
-
if (type == 'info') type = 'action'
|
76
|
-
notify[type](flash.textContent.trim())
|
77
|
-
flash.classList.add('hidden')
|
78
|
-
}
|
79
|
-
}
|
80
|
-
|
81
|
-
}
|
@@ -1,280 +0,0 @@
|
|
1
|
-
var bean = require('bean')
|
2
|
-
|
3
|
-
require('compose-tap-event')
|
4
|
-
|
5
|
-
var RangeInputHelper = {
|
6
|
-
listen: function(){
|
7
|
-
bean.on(document, "input toggler:show", "[type=range]", RangeInputHelper.change)
|
8
|
-
bean.on(document, "click change input", "[type=range]", RangeInputHelper.focus)
|
9
|
-
},
|
10
|
-
|
11
|
-
change: function(event) {
|
12
|
-
RangeInputHelper.refresh(event.currentTarget)
|
13
|
-
},
|
14
|
-
|
15
|
-
refresh: function (slider) {
|
16
|
-
RangeInputHelper.setLabels(slider)
|
17
|
-
RangeInputHelper.setInput(slider)
|
18
|
-
},
|
19
|
-
|
20
|
-
focus: function(event){
|
21
|
-
event.currentTarget.focus()
|
22
|
-
},
|
23
|
-
|
24
|
-
setup: function(){
|
25
|
-
var ranges = document.querySelectorAll('[type=range]:not(.range-input)')
|
26
|
-
Array.prototype.forEach.call(ranges, RangeInputHelper.initSlider)
|
27
|
-
RangeInputHelper.listen()
|
28
|
-
},
|
29
|
-
|
30
|
-
initSlider: function(slider){
|
31
|
-
slider.className += ' range-input'
|
32
|
-
slider.dataset.id = String(parseInt(Math.random() * 10000))
|
33
|
-
RangeInputHelper.cacheSet(slider)
|
34
|
-
|
35
|
-
slider.insertAdjacentHTML('beforebegin', RangeInputHelper.template(slider))
|
36
|
-
RangeInputHelper.refresh(slider)
|
37
|
-
|
38
|
-
slider.remove()
|
39
|
-
},
|
40
|
-
|
41
|
-
cacheSet: function(slider) {
|
42
|
-
var labels = RangeInputHelper.getLabels(slider)
|
43
|
-
slider.dataset.cache = JSON.stringify({
|
44
|
-
labels: labels,
|
45
|
-
externalLabels: RangeInputHelper.extractLabels(slider, 'data-external-label-'),
|
46
|
-
})
|
47
|
-
},
|
48
|
-
|
49
|
-
template: function(slider){
|
50
|
-
|
51
|
-
var inputTemplate = RangeInputHelper.inputTemplate(slider)
|
52
|
-
var rangeTemplate = RangeInputHelper.rangeTemplate(slider)
|
53
|
-
|
54
|
-
return inputTemplate + rangeTemplate
|
55
|
-
},
|
56
|
-
|
57
|
-
rangeTemplate: function(slider){
|
58
|
-
var html = ""
|
59
|
-
var lineLabels = RangeInputHelper.lineLabels(slider)
|
60
|
-
|
61
|
-
if (slider.dataset.mark || slider.dataset.lineLabels) {
|
62
|
-
var segments = RangeInputHelper.segments(slider)
|
63
|
-
var mark = []
|
64
|
-
|
65
|
-
if (slider.dataset.mark) {
|
66
|
-
mark = slider.dataset.mark.split(',').map(Number)
|
67
|
-
}
|
68
|
-
|
69
|
-
for(var i = 1; i <= segments; i++) {
|
70
|
-
var markClass = ((mark.indexOf(i) != -1) ? ' mark' : '')
|
71
|
-
var lineLabel = lineLabels[String(i)]
|
72
|
-
|
73
|
-
html += "<div class='range-segment'><span class='range-segment-content'>"
|
74
|
-
if (mark.indexOf(i) != -1){
|
75
|
-
html += "<span class='range-segment-mark'></span>"
|
76
|
-
}
|
77
|
-
if (lineLabel) {
|
78
|
-
html += "<span class='range-line-label'>"+lineLabel+"</span>"
|
79
|
-
}
|
80
|
-
html += "</span></div>"
|
81
|
-
}
|
82
|
-
}
|
83
|
-
|
84
|
-
slider.className += ' range-input-slider'
|
85
|
-
html = "<div class='range-input-container'>" + slider.outerHTML + "<div class='range-track'>" + html + "</div><div class='range-track-bg'></div></div>"
|
86
|
-
|
87
|
-
var labelHTML = RangeInputHelper.labelTemplate(slider)
|
88
|
-
|
89
|
-
return "<div class='slider-container"
|
90
|
-
+ (RangeInputHelper.objectSize(lineLabels) > 0 ? " line-labels" : "")
|
91
|
-
+ (labelHTML.length > 0 ? " with-label" : " without-label")
|
92
|
-
+ "' id='slider-"+ slider.dataset.id +"' >"
|
93
|
-
+ html
|
94
|
-
+ labelHTML
|
95
|
-
+ "</div>"
|
96
|
-
},
|
97
|
-
|
98
|
-
lineLabels: function(slider){
|
99
|
-
var lineLabels = {}
|
100
|
-
if(slider.dataset.lineLabels) {
|
101
|
-
slider.dataset.lineLabels.split(';').map(function(labels){
|
102
|
-
var l = labels.split(':')
|
103
|
-
lineLabels[l[0]] = l[1]
|
104
|
-
})
|
105
|
-
}
|
106
|
-
return lineLabels
|
107
|
-
},
|
108
|
-
|
109
|
-
labelTemplate: function(slider){
|
110
|
-
var html = ""
|
111
|
-
var labels = JSON.parse(slider.dataset.cache).labels
|
112
|
-
|
113
|
-
for(var key in labels){
|
114
|
-
var altKey = RangeInputHelper.camelCase(key)
|
115
|
-
var before = slider.dataset.beforeLabel || slider.dataset[altKey+'BeforeLabel']
|
116
|
-
var after = slider.dataset.afterLabel || slider.dataset[altKey+'AfterLabel']
|
117
|
-
|
118
|
-
html += "<span class='range-label-"+key+"'>"
|
119
|
-
if (before) { html += "<span class='before-label'>"+before+"</span>" }
|
120
|
-
html += "<span data-label='"+key+"'></span>"
|
121
|
-
if (after) { html += "<span class='after-label'>"+after+"</span>" }
|
122
|
-
html += "</span> "
|
123
|
-
}
|
124
|
-
|
125
|
-
if (html.length > 0) {
|
126
|
-
html = "<div class='range-label'>" + html + "</div>"
|
127
|
-
}
|
128
|
-
|
129
|
-
return html
|
130
|
-
},
|
131
|
-
|
132
|
-
inputTemplate: function(slider) {
|
133
|
-
if (slider.dataset.input && slider.dataset.values) {
|
134
|
-
// Generate a class name for querying later (because some name attributes contain illegal characters for queries)
|
135
|
-
var classname = slider.dataset.input.replace(/\W/g,'-')
|
136
|
-
|
137
|
-
var input = this.existingInput(slider)
|
138
|
-
|
139
|
-
if (input) {
|
140
|
-
input.classList.add(classname)
|
141
|
-
return ""
|
142
|
-
}
|
143
|
-
|
144
|
-
return "<input class='"+classname+"' type='hidden' name='"+slider.dataset.input+"' value='"+slider.value+"'>"
|
145
|
-
} else return ""
|
146
|
-
},
|
147
|
-
|
148
|
-
existingInput: function(slider) {
|
149
|
-
return this.scope(slider).querySelector('input[name="'+slider.dataset.input+'"]')
|
150
|
-
},
|
151
|
-
|
152
|
-
scope: function(slider) {
|
153
|
-
var el = slider
|
154
|
-
|
155
|
-
while (el && el.tagName != "FORM") {
|
156
|
-
el = el.parentNode
|
157
|
-
}
|
158
|
-
|
159
|
-
return el || document
|
160
|
-
},
|
161
|
-
|
162
|
-
getLabels: function(slider) {
|
163
|
-
var labels = {}
|
164
|
-
|
165
|
-
if (slider.dataset.label == 'false')
|
166
|
-
return labels
|
167
|
-
|
168
|
-
labels = RangeInputHelper.extractLabels(slider, 'data-label-')
|
169
|
-
|
170
|
-
if (RangeInputHelper.objectSize(labels) == 0) {
|
171
|
-
if (slider.dataset.label) {
|
172
|
-
labels['default'] = slider.dataset.label.split(';')
|
173
|
-
} else if(slider.dataset.values){
|
174
|
-
labels['default'] = slider.dataset.values.split(',')
|
175
|
-
} else {
|
176
|
-
labels['default'] = RangeInputHelper.valueLabels(slider)
|
177
|
-
}
|
178
|
-
}
|
179
|
-
|
180
|
-
return labels
|
181
|
-
},
|
182
|
-
|
183
|
-
extractLabels: function(slider, pattern) {
|
184
|
-
var labels = {}
|
185
|
-
|
186
|
-
for (var i = 0; i < slider.attributes.length; i++){
|
187
|
-
var name = slider.attributes[i].nodeName
|
188
|
-
|
189
|
-
if(new RegExp("^"+pattern).test(name)) {
|
190
|
-
name = name.replace(pattern, '')
|
191
|
-
labels[name] = slider.attributes[i].nodeValue.split(';')
|
192
|
-
}
|
193
|
-
}
|
194
|
-
return labels
|
195
|
-
},
|
196
|
-
|
197
|
-
setLabels: function(slider) {
|
198
|
-
var labels = JSON.parse(slider.dataset.cache).labels
|
199
|
-
var externalLabels = JSON.parse(slider.dataset.cache).externalLabels
|
200
|
-
|
201
|
-
RangeInputHelper.updateLabels(slider, labels)
|
202
|
-
RangeInputHelper.updateLabels(slider, externalLabels, 'external')
|
203
|
-
},
|
204
|
-
|
205
|
-
updateLabels: function(slider, labels, type) {
|
206
|
-
for (var key in labels) {
|
207
|
-
var elements = RangeInputHelper.labelElements(slider, type, key)
|
208
|
-
|
209
|
-
Array.prototype.forEach.call(elements, function(target) {
|
210
|
-
var index = RangeInputHelper.rangeValueIndex(slider)
|
211
|
-
target.innerHTML = RangeInputHelper.getLabelsAtIndex(labels, index)[key]
|
212
|
-
})
|
213
|
-
}
|
214
|
-
},
|
215
|
-
|
216
|
-
labelElements: function(slider, type, key) {
|
217
|
-
var selector = ''
|
218
|
-
|
219
|
-
if (type == 'external')
|
220
|
-
selector = '[data-range-label='+key+']'
|
221
|
-
else
|
222
|
-
selector = '#slider-'+slider.dataset.id+' [data-label='+key+']'
|
223
|
-
|
224
|
-
return document.querySelectorAll(selector)
|
225
|
-
},
|
226
|
-
|
227
|
-
setInput: function(slider) {
|
228
|
-
if (slider.offsetParent === null) { return }
|
229
|
-
if (slider.dataset.input && slider.dataset.values) {
|
230
|
-
var value = slider.dataset.values.split(',')[RangeInputHelper.rangeValueIndex(slider)]
|
231
|
-
var selector = "."+slider.dataset.input.replace(/\W/g,'-')
|
232
|
-
var inputs = this.scope(slider).querySelectorAll(selector)
|
233
|
-
|
234
|
-
Array.prototype.forEach.call(inputs, function(input){
|
235
|
-
input.value = value
|
236
|
-
})
|
237
|
-
}
|
238
|
-
},
|
239
|
-
|
240
|
-
getLabelsAtIndex: function(labels, index){
|
241
|
-
var set = {}
|
242
|
-
for (var key in labels) {
|
243
|
-
set[key] = labels[key][index]
|
244
|
-
}
|
245
|
-
return set
|
246
|
-
},
|
247
|
-
|
248
|
-
segments: function(slider){
|
249
|
-
return Number(slider.getAttribute('max') || 100) - Number(slider.getAttribute('min') || 0) + 1
|
250
|
-
},
|
251
|
-
|
252
|
-
valueLabels: function(slider) {
|
253
|
-
var values = []
|
254
|
-
var start = Number(slider.getAttribute('min')) || 0
|
255
|
-
var end = Number(slider.getAttribute('max')) || 100
|
256
|
-
|
257
|
-
for (var i = start; i <= end; i++ ) {
|
258
|
-
values[i] = i
|
259
|
-
}
|
260
|
-
|
261
|
-
return values
|
262
|
-
},
|
263
|
-
|
264
|
-
rangeValueIndex: function(slider){
|
265
|
-
return Number(slider.value) - Number(slider.getAttribute('min'))
|
266
|
-
},
|
267
|
-
|
268
|
-
objectSize: function(object) {
|
269
|
-
var length = 0; for(var i in object) { length++ }
|
270
|
-
return length
|
271
|
-
},
|
272
|
-
|
273
|
-
camelCase: function(input) {
|
274
|
-
return input.toLowerCase().replace(/-(.)/g, function(match, group) {
|
275
|
-
return group.toUpperCase();
|
276
|
-
});
|
277
|
-
}
|
278
|
-
}
|
279
|
-
|
280
|
-
module.exports = RangeInputHelper
|
@@ -1,59 +0,0 @@
|
|
1
|
-
// Converts a simple date string into Date + Time + Timezone wrapped in HTML
|
2
|
-
//
|
3
|
-
// Input:
|
4
|
-
// - String, compatible with JS date parsing e.g. "2014-10-20" or "2014-05-21 10:63"
|
5
|
-
// - String, timezone: "UTC", "CST", etc.
|
6
|
-
//
|
7
|
-
// Returns: HTML which is "2014-01-28 18:00:00 CST", separated and wrapped with spans
|
8
|
-
// with classnames: date, time and timezone
|
9
|
-
//
|
10
|
-
var dateToHtml = function dateToHtml(dateString, zone) {
|
11
|
-
|
12
|
-
if(isNaN(new Date("2014-01-29T18:14:29+00:00").getDate())) {
|
13
|
-
return false
|
14
|
-
}
|
15
|
-
|
16
|
-
var date = new Date(dateString)
|
17
|
-
var zone = zone || date.getTimezoneOffset()/-60
|
18
|
-
|
19
|
-
if(zone === 'UTC') {
|
20
|
-
var y = date.getUTCFullYear()
|
21
|
-
var mo = pad(date.getUTCMonth() + 1)
|
22
|
-
var d = pad(date.getUTCDate())
|
23
|
-
var h = pad(date.getUTCHours())
|
24
|
-
var m = pad(date.getUTCMinutes())
|
25
|
-
var s = pad(date.getUTCSeconds())
|
26
|
-
} else {
|
27
|
-
var y = date.getFullYear()
|
28
|
-
var mo = pad(date.getMonth() + 1)
|
29
|
-
var d = pad(date.getDate())
|
30
|
-
var h = pad(date.getHours())
|
31
|
-
var m = pad(date.getMinutes())
|
32
|
-
var s = pad(date.getSeconds())
|
33
|
-
|
34
|
-
var tz = String(date).match(/\((.+)\)$/)
|
35
|
-
|
36
|
-
if(tz) {
|
37
|
-
var zone = tz[1]
|
38
|
-
} else {
|
39
|
-
var zone = "GMT "
|
40
|
-
zone += ((zone > 0) ? '+' : '')
|
41
|
-
zone += " "+ pad(zone*100, 4)
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
|
-
var str = '<span class="date">'+y+'-'+mo+'-'+d+'</span>'
|
46
|
-
str += ' <span class="time">'+h+':'+m+':'+s+'</span>'
|
47
|
-
str += ' <span class="timezone">'+zone+'</span>'
|
48
|
-
return str
|
49
|
-
}
|
50
|
-
|
51
|
-
var pad = function datePad(num, pad){
|
52
|
-
pad = pad || 2
|
53
|
-
while(String(num).length < pad) {
|
54
|
-
num = '0' + num
|
55
|
-
}
|
56
|
-
return num
|
57
|
-
}
|
58
|
-
|
59
|
-
module.exports = dateToHtml
|
@@ -1,84 +0,0 @@
|
|
1
|
-
var timeago = require('./timeago')
|
2
|
-
var dateToHtml = require('./date-to-html')
|
3
|
-
var bean = require('bean')
|
4
|
-
|
5
|
-
var TimeSwitch = {
|
6
|
-
|
7
|
-
// Attach listeners, setup HTML templates
|
8
|
-
setup: function timeSwitchSetup() {
|
9
|
-
if(!timeago.browserSupport()) return false
|
10
|
-
if(!this.listening) this.listen()
|
11
|
-
|
12
|
-
var timeEls = document.querySelectorAll('.time-switch[datetime]')
|
13
|
-
|
14
|
-
Array.prototype.forEach.call(timeEls, function(el) {
|
15
|
-
var datetime = el.getAttribute('datetime')
|
16
|
-
var timeagoPosition = el.dataset.timeago
|
17
|
-
var timeagoStyle = el.dataset.timeagoStyle
|
18
|
-
el.innerHTML = TimeSwitch.template(datetime, timeagoPosition, timeagoStyle)
|
19
|
-
el.classList.add('time-switch')
|
20
|
-
el.setAttribute('title', 'toggle timezones')
|
21
|
-
})
|
22
|
-
},
|
23
|
-
|
24
|
-
// Attach listeners to toggle time zones whine clicked
|
25
|
-
listen: function timeSwitchListen() {
|
26
|
-
bean.on(document, "click", ".time-switch", TimeSwitch.toggle)
|
27
|
-
this.listening = true
|
28
|
-
},
|
29
|
-
|
30
|
-
// Switch between UTC and local time
|
31
|
-
toggle: function timeSwitchToggle(event) {
|
32
|
-
var timeEls = document.querySelectorAll('.time-switch')
|
33
|
-
|
34
|
-
Array.prototype.forEach.call(timeEls, function(el) {
|
35
|
-
el.classList.toggle('alt-zone')
|
36
|
-
})
|
37
|
-
},
|
38
|
-
|
39
|
-
// Supply HTML for UTC and local datetime
|
40
|
-
//
|
41
|
-
// Input:
|
42
|
-
// - date (a date object)
|
43
|
-
// - timeagoPosition, String, either 'before' or 'after'
|
44
|
-
//
|
45
|
-
template: function timeSwitchTemplate(date, timeagoPosition, timeagoStyle) {
|
46
|
-
var utc = dateToHtml(date, 'UTC')
|
47
|
-
var local = dateToHtml(date)
|
48
|
-
var t = '';
|
49
|
-
|
50
|
-
if (timeagoPosition === 'before') {
|
51
|
-
t += this.timeagoTemplate(date, timeagoPosition, timeagoStyle)
|
52
|
-
}
|
53
|
-
|
54
|
-
t += "<span class='utc'><span class='clock_line_icon'></span> "
|
55
|
-
t += utc + "</span>"
|
56
|
-
t += "<span class='local'><span class='clock_fill_icon'></span> "
|
57
|
-
t += local + "</span>"
|
58
|
-
|
59
|
-
if (timeagoPosition === 'after') {
|
60
|
-
t += this.timeagoTemplate(date, timeagoPosition, timeagoStyle)
|
61
|
-
}
|
62
|
-
|
63
|
-
return t
|
64
|
-
},
|
65
|
-
|
66
|
-
// Converts a date to relative time string wrapped in a span
|
67
|
-
timeagoTemplate: function timeSwitchTimeagoTemplate(date, position, style) {
|
68
|
-
var relative = timeago.parse(date, style)
|
69
|
-
var dash = "<span class='dash'> - </span>"
|
70
|
-
var html = ''
|
71
|
-
|
72
|
-
if(relative) {
|
73
|
-
if (position === 'after') html += dash
|
74
|
-
html += "<span class='timeago'>"+ relative +"</span> "
|
75
|
-
return html
|
76
|
-
} else {
|
77
|
-
return ''
|
78
|
-
}
|
79
|
-
}
|
80
|
-
|
81
|
-
}
|
82
|
-
|
83
|
-
module.exports = TimeSwitch
|
84
|
-
|