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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2befa154b790a1263b212eadb63a4c4fe083613d
|
4
|
+
data.tar.gz: 6f5563efe813ef2d6c6bde4cb5a956d425b89906
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 668d49dad27cc632fd44ae4ed35fe5f878fe570776d9ce731961c1ca6d4ee7e259cc18199433bd6ae4cdc05978694132cd5738fb394db539e8b5c5bc614b5053
|
7
|
+
data.tar.gz: ed88b7b6ce5f4a9a5aa5650c2d31f063bbd90bb7749b57bea82e01d51e1d36bcc73e5b5cedb20c1d8ded12525c99dc5b27bf7dbe7a63716faa1fd403f85f42fb
|
@@ -1,106 +1,46 @@
|
|
1
|
-
var
|
2
|
-
var bean = require('bean')
|
3
|
-
var Dialog = require('dialog')
|
4
|
-
var tap = require('tap-event')
|
5
|
-
var Form = require('./form')
|
6
|
-
var Link = require('./link')
|
7
|
-
var _ = require('lodash')
|
1
|
+
var event = require('compose-event')
|
8
2
|
var notify = require('notify')
|
9
3
|
var request = require('superagent')
|
10
|
-
var
|
4
|
+
var dialog = require('compose-dialog')
|
5
|
+
var toggler = require('compose-toggler')
|
11
6
|
var esvg = require('./esvg')
|
12
7
|
|
8
|
+
// CodeMirror Settings
|
9
|
+
var CodeMirror = require('codemirror')
|
10
|
+
require('codemirror/mode/htmlmixed/htmlmixed')
|
11
|
+
require('codemirror/mode/slim/slim')
|
12
|
+
require('codemirror/mode/javascript/javascript')
|
13
|
+
require('codemirror/mode/css/css')
|
14
|
+
require('codemirror/mode/sql/sql')
|
15
|
+
require('codemirror/addon/runmode/runmode.js')
|
16
|
+
require('codemirror/addon/edit/matchbrackets.js')
|
17
|
+
|
18
|
+
var form = require('compose-remote-form') // Our UJS implementation
|
19
|
+
require('compose-time-toggle') // Switch time elements between local and UTC
|
20
|
+
require('compose-slider') // Our slider (range input) component
|
21
|
+
var rangeTouch = require('rangetouch') // mobile accessiblity on sliders
|
22
|
+
rangeTouch.set("thumbWidth", 19);
|
23
|
+
|
24
|
+
require('./utils/activate-nav-items')
|
25
|
+
require('./utils/auto-navigate')
|
26
|
+
require('./utils/clipboard')
|
27
|
+
require('./utils/form-flash')
|
28
|
+
require('./utils/form-notify')
|
29
|
+
require('./utils/highlight-code')
|
30
|
+
require('./utils/messages')
|
31
|
+
require('./utils/text-helpers')
|
32
|
+
require('./utils/progress-bar')
|
33
|
+
|
13
34
|
require('./shims/classlist')
|
14
35
|
|
15
36
|
window.Megatron = module.exports = {
|
16
|
-
|
37
|
+
dialog: dialog,
|
17
38
|
notify: notify,
|
18
|
-
|
19
|
-
|
20
|
-
Toggler: utils.Toggler,
|
21
|
-
Form: Form,
|
39
|
+
event: event,
|
40
|
+
form: form,
|
22
41
|
request: request,
|
23
|
-
Link: Link,
|
24
42
|
esvg: esvg,
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
bean.on(document, 'DOMContentLoaded', pageLoad)
|
29
|
-
|
30
|
-
// Support rails turbolinks page load event
|
31
|
-
bean.on(document, 'page:change', pageChange)
|
32
|
-
|
33
|
-
NProgress.configure({showSpinner: false})
|
34
|
-
|
35
|
-
bean.on(document, 'page:fetch', function() { NProgress.start() })
|
36
|
-
bean.on(document, 'page:change', function() { NProgress.done() })
|
37
|
-
bean.on(document, 'page:restore', function() { NProgress.remove() })
|
38
|
-
|
39
|
-
function pageLoad(){
|
40
|
-
utils.Toggler.listen()
|
41
|
-
utils.AutoNavigate.listen()
|
42
|
-
utils.TextHelpers.listen()
|
43
|
-
if(!window.Turbolinks) {
|
44
|
-
pageChange()
|
45
|
-
}
|
46
|
-
}
|
47
|
-
|
48
|
-
function pageChange(){
|
49
|
-
utils.toggleActiveNav()
|
50
|
-
utils.highlightCode()
|
51
|
-
utils.notifyFormFlash()
|
52
|
-
utils.TimeSwitch.setup()
|
53
|
-
utils.Timeago.setup()
|
54
|
-
utils.Messages.load()
|
55
|
-
utils.RangeInputHelper.setup()
|
56
|
-
utils.TextHelpers.setup()
|
57
|
-
|
58
|
-
// Do last to ensure no other default setup overrides visibility state
|
59
|
-
utils.Toggler.refresh()
|
60
|
-
}
|
61
|
-
|
62
|
-
// Dialog document listener and auto-creator
|
63
|
-
bean.on(document, 'click', '[data-trigger=dialog]', handleDialogTrigger)
|
64
|
-
bean.on(document, 'click', '[data-trigger=dialog]', tap(handleDialogTrigger))
|
65
|
-
bean.on(document, 'click', '.nav_toggle', toggleNavigationMode)
|
66
|
-
|
67
|
-
function handleDialogTrigger(event){
|
68
|
-
event.preventDefault()
|
69
|
-
new Dialog(event.currentTarget.dataset).show()
|
70
|
-
}
|
71
|
-
|
72
|
-
function toggleNavigationMode(event) {
|
73
|
-
event.target.blur()
|
74
|
-
document.querySelector('body').classList.toggle('active-nav')
|
43
|
+
code: CodeMirror,
|
44
|
+
toggler: toggler
|
75
45
|
}
|
76
46
|
|
77
|
-
function disableWith(event){
|
78
|
-
var buttons = event.currentTarget.querySelectorAll('[data-disable-with]')
|
79
|
-
Array.prototype.forEach.call(buttons, function(button){
|
80
|
-
button.disabled = true
|
81
|
-
button.classList.add('disabled')
|
82
|
-
|
83
|
-
var buttonText = button.dataset.disableWith
|
84
|
-
if (!buttonText || buttonText == '') { buttonText = button.innerHTML }
|
85
|
-
|
86
|
-
button.innerHTML = buttonText.replace(/\.{3}/, '…')
|
87
|
-
})
|
88
|
-
}
|
89
|
-
|
90
|
-
// If jQuery exists, be sure Rails UJS doesn't
|
91
|
-
if (!window.$ || !$.rails) {
|
92
|
-
var boundForms = []
|
93
|
-
// Form event listener
|
94
|
-
bean.on(document, 'submit', 'form[data-remote]', handleRemoteFormSubmit)
|
95
|
-
bean.on(document, 'submit', 'form', disableWith)
|
96
|
-
bean.on(document, 'click', 'a[data-method], a[data-confirm], button[data-method], button[data-confirm]', Link.click)
|
97
|
-
}
|
98
|
-
|
99
|
-
function handleRemoteFormSubmit(event){
|
100
|
-
// Prevent doubling up on form event hanlding.
|
101
|
-
if(boundForms.filter(function(el){return el == event.currentTarget})[0])
|
102
|
-
return
|
103
|
-
// Trigger a form submission event.
|
104
|
-
new Form({el: event.currentTarget}).submit(event)
|
105
|
-
boundForms.push(event.currentTarget)
|
106
|
-
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
var Event = require('compose-event')
|
2
|
+
|
3
|
+
// This module helps show which navigation elements match the current page.
|
4
|
+
// It assigns 'here' classes to all elements which match the current url.
|
5
|
+
//
|
6
|
+
// The value for data-match-url is converted to a regex to match the current url.
|
7
|
+
//
|
8
|
+
// Examples:
|
9
|
+
//
|
10
|
+
// a href='/users" data-match-url='^/users'
|
11
|
+
// a href='/users/your-username/followers" data-match-url='/followers/'
|
12
|
+
//
|
13
|
+
Event.change(function(){
|
14
|
+
Array.prototype.forEach.call(document.querySelectorAll('[data-match-url]'), function(node){
|
15
|
+
var matcher = node.getAttribute('data-match-url')
|
16
|
+
if (matcher && new RegExp(node.dataset.matchUrl, "i").test(location.pathname)) {
|
17
|
+
node.classList.add('here')
|
18
|
+
}
|
19
|
+
})
|
20
|
+
})
|
@@ -1,23 +1,20 @@
|
|
1
|
-
var
|
1
|
+
var Event = require('compose-event')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
},
|
9
|
-
|
10
|
-
trigger: function autoNavigateTrigger(event) {
|
3
|
+
// Allow clicking an element with .auto-navigate transfers the
|
4
|
+
// click to the link (a child element) with the class navigate
|
5
|
+
//
|
6
|
+
Event.ready(function(){
|
7
|
+
Event.on(document, "click", ".auto-navigate", function(event) {
|
11
8
|
var target = event.target
|
9
|
+
|
12
10
|
if (target.tagName.toLowerCase() != 'a') {
|
13
11
|
var link = event.currentTarget.querySelector('a.navigate')
|
12
|
+
|
14
13
|
if (event.metaKey) {
|
15
14
|
window.open(link)
|
16
15
|
} else {
|
17
|
-
|
16
|
+
Event.fire(link, 'click')
|
18
17
|
}
|
19
18
|
}
|
20
|
-
}
|
21
|
-
}
|
22
|
-
|
23
|
-
module.exports = AutoNavigate
|
19
|
+
})
|
20
|
+
})
|
@@ -1,5 +1,10 @@
|
|
1
|
+
var Event = require('compose-event')
|
1
2
|
var clipboard = require('clipboard')
|
2
3
|
|
4
|
+
// This handles the process of adding to clipboard,
|
5
|
+
// handling failure states, and hiding buttons when
|
6
|
+
// clipboard access is not supported.
|
7
|
+
|
3
8
|
var Clipboard = {
|
4
9
|
setup: function() {
|
5
10
|
if (document.queryCommandSupported('copy')) {
|
@@ -7,12 +12,14 @@ var Clipboard = {
|
|
7
12
|
cbwatcher.on('success', Clipboard.success)
|
8
13
|
cbwatcher.on('error', Clipboard.failure)
|
9
14
|
} else {
|
15
|
+
// Hide buttons which offer the option to copy to clipboard
|
10
16
|
Array.prototype.forEach.call(document.querySelectorAll('[data-clipboard-target],[data-clipboard-text]'), function(el) {
|
11
17
|
el.classList.add('hidden')
|
12
18
|
})
|
13
19
|
}
|
14
20
|
},
|
15
21
|
|
22
|
+
// Copied to clipboard
|
16
23
|
success: function(cbEvent) {
|
17
24
|
cbEvent.trigger.classList.add('clipboard-copied')
|
18
25
|
setTimeout(function(){
|
@@ -20,6 +27,7 @@ var Clipboard = {
|
|
20
27
|
}, 1200)
|
21
28
|
},
|
22
29
|
|
30
|
+
// Failed: to copy to clipboard
|
23
31
|
error: function(event) {
|
24
32
|
cbEvent.trigger.classList.add('clipboard-failed')
|
25
33
|
setTimeout(function(){
|
@@ -28,4 +36,4 @@ var Clipboard = {
|
|
28
36
|
}
|
29
37
|
}
|
30
38
|
|
31
|
-
|
39
|
+
Event.change(Clipboard.setup)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
var Event = require('compose-event')
|
2
|
+
var Notify = require('compose-notification')
|
3
|
+
|
4
|
+
// If a page has an element .form-flash, trigger a notification
|
5
|
+
//
|
6
|
+
Event.change(function(){
|
7
|
+
var flash = document.querySelector('.form-flash')
|
8
|
+
if (flash) {
|
9
|
+
var type = flash.dataset.type || 'error'
|
10
|
+
if (type == 'info') type = 'action'
|
11
|
+
Notify[type](flash.textContent.trim())
|
12
|
+
flash.classList.add('hidden')
|
13
|
+
}
|
14
|
+
})
|
@@ -1,39 +1,51 @@
|
|
1
|
-
var
|
2
|
-
var
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
this.notify(event.target, 'beforeSend')
|
36
|
-
}
|
37
|
-
}.bind(this))
|
38
|
-
}
|
1
|
+
var Event = require('compose-event')
|
2
|
+
var Notify = require('notify')
|
3
|
+
|
4
|
+
|
5
|
+
// Notify user of actions on ajax forms.
|
6
|
+
// Default messages are:
|
7
|
+
//
|
8
|
+
// beforeSend: 'Submitting...',
|
9
|
+
// success: 'Success!',
|
10
|
+
// error: 'Something went wrong.'
|
11
|
+
//
|
12
|
+
// You can customize form messages by nesting scripts
|
13
|
+
// inside your form. Note, the classnames of the scripts
|
14
|
+
// should match the message type.
|
15
|
+
//
|
16
|
+
// <form data-remote='true'>
|
17
|
+
// <script class='beforeSend'>Submitting form</script>
|
18
|
+
// <script class='success'>You did it!</script>
|
19
|
+
// <script class='error'>Try again</script>
|
20
|
+
//
|
21
|
+
|
22
|
+
var defaultMessages = {
|
23
|
+
beforeSend: 'Submitting...',
|
24
|
+
success: 'Success!',
|
25
|
+
error: 'Something went wrong.'
|
26
|
+
}
|
27
|
+
|
28
|
+
var notifyForm = function(event) {
|
29
|
+
var message = getMessage(event.target, event.type)
|
30
|
+
|
31
|
+
if (event.type == 'beforeSend')
|
32
|
+
Notify.progress(message)
|
33
|
+
else
|
34
|
+
Notify[type](message)
|
39
35
|
}
|
36
|
+
|
37
|
+
var getMessage = function(form, type) {
|
38
|
+
if (form.dataset[type])
|
39
|
+
return form.dataset[type]
|
40
|
+
|
41
|
+
var el = form.querySelector('[data-ajax-event='+type+'], script.'+type)
|
42
|
+
|
43
|
+
if (el)
|
44
|
+
return el.innerHTML
|
45
|
+
else
|
46
|
+
return defaultMessages[type]
|
47
|
+
}
|
48
|
+
|
49
|
+
Event.ready(function() {
|
50
|
+
Event.on(document, 'beforeSend success error', 'form[data-remote]', notifyForm)
|
51
|
+
})
|
@@ -0,0 +1,46 @@
|
|
1
|
+
var Event = require('compose-event')
|
2
|
+
var CodeMirror = require('codemirror')
|
3
|
+
|
4
|
+
// Use CodeMirror to render static code higlighting
|
5
|
+
//
|
6
|
+
// Example:
|
7
|
+
//
|
8
|
+
// <pre class="lang-ruby">
|
9
|
+
// puts 'awesome' if true
|
10
|
+
// </pre>
|
11
|
+
//
|
12
|
+
var aliasLang = function(lang) {
|
13
|
+
var aliases = {
|
14
|
+
'markup': 'htmlmixed',
|
15
|
+
'html': 'htmlmixed',
|
16
|
+
'json': 'javascript',
|
17
|
+
}
|
18
|
+
|
19
|
+
return(aliases[lang] || lang)
|
20
|
+
}
|
21
|
+
|
22
|
+
var highlightCode = function() {
|
23
|
+
var elements = document.querySelectorAll('[class*="language-"], [class*="lang-"]');
|
24
|
+
|
25
|
+
Array.prototype.forEach.call(elements, function(element) {
|
26
|
+
var lang = element.className.match(/lang.*?-(\S+)/)[1]
|
27
|
+
|
28
|
+
// Standardize classes: lang-[language]
|
29
|
+
if (element.classList.contains('language-'+lang)) {
|
30
|
+
element.classList.remove('language-'+lang)
|
31
|
+
element.classList.add('lang-'+lang)
|
32
|
+
}
|
33
|
+
var code = element.textContent.trim()
|
34
|
+
|
35
|
+
var options = {}
|
36
|
+
if(lang == 'json') {
|
37
|
+
options.json = true
|
38
|
+
}
|
39
|
+
|
40
|
+
CodeMirror.runMode(code, aliasLang(lang), element, options)
|
41
|
+
element.innerHTML = "<code class='highlighted-code static-code cm-s-default'>" + element.innerHTML + "</code>"
|
42
|
+
element.classList.add('highlighted')
|
43
|
+
})
|
44
|
+
}
|
45
|
+
|
46
|
+
Event.change(highlightCode)
|
@@ -1,5 +1,9 @@
|
|
1
1
|
var request = require('superagent')
|
2
|
-
var
|
2
|
+
var Event = require('compose-event')
|
3
|
+
|
4
|
+
// Look for messages at /messages.json
|
5
|
+
// (an internal json document which we use to publish site-wide messages)
|
6
|
+
// Then pin the topmost message to the top of the page.
|
3
7
|
|
4
8
|
var Messages = {
|
5
9
|
el: function messagesEl(){
|
@@ -36,7 +40,7 @@ var Messages = {
|
|
36
40
|
var html = this.messageHTML(options)
|
37
41
|
this.saveMessage(html)
|
38
42
|
this.showMessage(html)
|
39
|
-
|
43
|
+
Event.on(this.el(), 'click', '.dismiss', this.dismiss.bind(this))
|
40
44
|
}
|
41
45
|
}
|
42
46
|
},
|
@@ -83,15 +87,15 @@ var Messages = {
|
|
83
87
|
},
|
84
88
|
|
85
89
|
load: function messagesLoad(){
|
86
|
-
if(window.location.hostname.match(/app\.compose
|
90
|
+
if(window.location.hostname.match(/app\.compose/)){
|
87
91
|
var message = window.Megatron.accountMessage
|
88
92
|
if(!message) {
|
89
|
-
|
93
|
+
Messages.fetch()
|
90
94
|
} else {
|
91
|
-
|
95
|
+
Messages.showMessage(message)
|
92
96
|
}
|
93
97
|
}
|
94
98
|
}
|
95
99
|
}
|
96
100
|
|
97
|
-
|
101
|
+
Event.ready(Messages.load)
|
@@ -0,0 +1,9 @@
|
|
1
|
+
var Event = require('compose-event')
|
2
|
+
var NProgress = require('nprogress')
|
3
|
+
|
4
|
+
// NProgress loading bar visualization
|
5
|
+
//
|
6
|
+
NProgress.configure({showSpinner: false})
|
7
|
+
Event.on(document, 'page:fetch', function() { NProgress.start() })
|
8
|
+
Event.on(document, 'page:change', function() { NProgress.done() })
|
9
|
+
Event.on(document, 'page:restore', function() { NProgress.remove() })
|