megatron 0.1.89 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/megatron/index.js +34 -94
  3. data/app/assets/javascripts/megatron/utils/activate-nav-items.js +20 -0
  4. data/app/assets/javascripts/megatron/utils/auto-navigate.js +11 -14
  5. data/app/assets/javascripts/megatron/utils/clipboard.js +9 -1
  6. data/app/assets/javascripts/megatron/utils/form-flash.js +14 -0
  7. data/app/assets/javascripts/megatron/utils/form-notify.js +50 -38
  8. data/app/assets/javascripts/megatron/utils/highlight-code.js +46 -0
  9. data/app/assets/javascripts/megatron/utils/messages.js +10 -6
  10. data/app/assets/javascripts/megatron/utils/progress-bar.js +9 -0
  11. data/app/assets/javascripts/megatron/utils/text-helpers.js +17 -7
  12. data/app/assets/stylesheets/megatron/modules/forms/_range-input.scss +37 -37
  13. data/app/helpers/megatron/application_helper.rb +9 -7
  14. data/app/helpers/megatron/form_helper.rb +6 -4
  15. data/app/views/layouts/megatron/application.html.slim +1 -1
  16. data/lib/megatron/helper.rb +27 -29
  17. data/lib/megatron/version.rb +1 -1
  18. data/public/assets/megatron/{megatron-0.1.89.css → megatron-0.2.0.css} +2 -2
  19. data/public/assets/megatron/megatron-0.2.0.css.gz +0 -0
  20. data/public/assets/megatron/{megatron-0.1.89.css.map → megatron-0.2.0.css.map} +2 -2
  21. data/public/assets/megatron/{megatron-0.1.89.js → megatron-0.2.0.js} +105 -134
  22. data/public/assets/megatron/megatron-0.2.0.js.gz +0 -0
  23. data/public/assets/megatron/megatron-0.2.0.map.json +1 -0
  24. data/public/assets/megatron/{megatron-error-pages-0.1.89.css → megatron-error-pages-0.2.0.css} +0 -0
  25. data/public/assets/megatron/{megatron-error-pages-0.1.89.css.gz → megatron-error-pages-0.2.0.css.gz} +0 -0
  26. metadata +14 -22
  27. data/app/assets/javascripts/megatron/form.js +0 -36
  28. data/app/assets/javascripts/megatron/link.js +0 -58
  29. data/app/assets/javascripts/megatron/utils/index.js +0 -81
  30. data/app/assets/javascripts/megatron/utils/range-input-helper.js +0 -280
  31. data/app/assets/javascripts/megatron/utils/time/date-to-html.js +0 -59
  32. data/app/assets/javascripts/megatron/utils/time/time-switch.js +0 -84
  33. data/app/assets/javascripts/megatron/utils/time/timeago.js +0 -95
  34. data/app/assets/javascripts/megatron/utils/toggler.js +0 -274
  35. data/app/assets/stylesheets/_example.scss +0 -76
  36. data/app/assets/stylesheets/_grid.scss +0 -41
  37. data/app/assets/stylesheets/_typography.scss +0 -38
  38. data/app/assets/stylesheets/application.scss +0 -19
  39. data/public/assets/megatron/megatron-0.1.89.css.gz +0 -0
  40. data/public/assets/megatron/megatron-0.1.89.js.gz +0 -0
  41. 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: 95441e75ea07e858f568ce7faaae77ac23558637
4
- data.tar.gz: bd370c17331d642bc9d1ab18b37ba489d54d225f
3
+ metadata.gz: 2befa154b790a1263b212eadb63a4c4fe083613d
4
+ data.tar.gz: 6f5563efe813ef2d6c6bde4cb5a956d425b89906
5
5
  SHA512:
6
- metadata.gz: c7b2aff9f44cc94b45a1bceb90cd77a686f585a0ea21ee418d56dfa81969acc1b4409abddfdafeea0fa5f4bc910d559a9a4c26b3c806a50c98b9e42d74e06162
7
- data.tar.gz: a6b2ccaa463bc73fea382416aaf89d83077c2b42949614cfc38de09d83a62ea5be91cfd27179d1e850f23de9ae10b7610bcc428aa30ceb271cdef27acd4c0a96
6
+ metadata.gz: 668d49dad27cc632fd44ae4ed35fe5f878fe570776d9ce731961c1ca6d4ee7e259cc18199433bd6ae4cdc05978694132cd5738fb394db539e8b5c5bc614b5053
7
+ data.tar.gz: ed88b7b6ce5f4a9a5aa5650c2d31f063bbd90bb7749b57bea82e01d51e1d36bcc73e5b5cedb20c1d8ded12525c99dc5b27bf7dbe7a63716faa1fd403f85f42fb
@@ -1,106 +1,46 @@
1
- var utils = require('./utils')
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 NProgress = require('nprogress')
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
- Dialog: Dialog,
37
+ dialog: dialog,
17
38
  notify: notify,
18
- utils: utils,
19
- Event: bean,
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 bean = require('bean')
1
+ var Event = require('compose-event')
2
2
 
3
- require('compose-tap-event')
4
-
5
- var AutoNavigate = {
6
- listen: function autoNavigateListen(){
7
- bean.on(document, "click", ".auto-navigate", AutoNavigate.trigger)
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
- bean.fire(link, 'click')
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
- module.exports = Clipboard
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 bean = require('bean')
2
- var notify = require('notify')
3
-
4
- module.exports = {
5
- notify: function formNotify(el, type){
6
- if(type == 'success')
7
- notify.success(this.getMessage(el, 'success'))
8
- else if(type == 'error')
9
- notify.error(this.getMessage(el, 'error'))
10
- else if(type == 'beforeSend')
11
- notify.progress(this.getMessage(el, 'beforeSend'))
12
- },
13
-
14
- getMessage: function formGetMessage(el, type){
15
- if (el.dataset[type])
16
- return el.dataset[type]
17
- else {
18
- var msg_object = document.querySelector('script.'+type)
19
-
20
- if (msg_object) {
21
- var msg = msg_object.innerHTML
22
- if (msg)
23
- return msg
24
- else
25
- return this.defaultMessages[type]
26
- }
27
- }
28
- },
29
-
30
- listen: function formListen() {
31
- bean.on(document.querySelector('body'), 'submit', 'form', function(event){
32
- if(!event.target.dataset['remote']) {
33
- event.preventDefault()
34
- setTimeout(function(){event.target.submit()}, 100)
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 bean = require('bean')
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
- bean.on(this.el(), 'click', '.dismiss', this.dismiss.bind(this))
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\.(io|dev)/)){
90
+ if(window.location.hostname.match(/app\.compose/)){
87
91
  var message = window.Megatron.accountMessage
88
92
  if(!message) {
89
- this.fetch()
93
+ Messages.fetch()
90
94
  } else {
91
- this.showMessage(message)
95
+ Messages.showMessage(message)
92
96
  }
93
97
  }
94
98
  }
95
99
  }
96
100
 
97
- module.exports = Messages
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() })