megatron 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +43 -2
  3. data/app/assets/javascripts/megatron/form.js +36 -0
  4. data/app/assets/javascripts/megatron/index.js +93 -0
  5. data/app/assets/javascripts/megatron/link.js +58 -0
  6. data/app/assets/javascripts/megatron/utils/auto-navigate.js +24 -0
  7. data/app/assets/javascripts/megatron/utils/form-notify.js +39 -0
  8. data/app/assets/javascripts/megatron/utils/index.js +112 -0
  9. data/app/assets/javascripts/megatron/utils/messages.js +97 -0
  10. data/app/assets/javascripts/megatron/utils/time/date-to-html.js +59 -0
  11. data/app/assets/javascripts/megatron/utils/time/time-switch.js +87 -0
  12. data/app/assets/javascripts/megatron/utils/time/timeago.js +95 -0
  13. data/app/assets/javascripts/megatron/utils/toggler.js +163 -0
  14. data/app/assets/stylesheets/_example.scss +76 -0
  15. data/app/assets/stylesheets/_grid.scss +41 -0
  16. data/app/assets/stylesheets/_typography.scss +38 -0
  17. data/app/assets/stylesheets/application.scss +19 -0
  18. data/app/assets/stylesheets/megatron/error-pages.scss +164 -0
  19. data/app/assets/stylesheets/megatron/error-pages/_animations.scss +96 -0
  20. data/app/assets/stylesheets/megatron/error-pages/_csi.scss +41 -0
  21. data/app/assets/stylesheets/megatron/error-pages/_waves.scss +36 -0
  22. data/app/assets/stylesheets/megatron/megatron.scss +3 -0
  23. data/app/assets/stylesheets/megatron/modules/_crop-height.scss +5 -0
  24. data/app/assets/stylesheets/megatron/modules/_index.scss +22 -0
  25. data/app/assets/stylesheets/megatron/modules/_logo.scss +67 -0
  26. data/app/assets/stylesheets/megatron/modules/_new-tag.scss +11 -0
  27. data/app/assets/stylesheets/megatron/modules/_progress.scss +80 -0
  28. data/app/assets/stylesheets/megatron/modules/app/_animation-classes.scss +3 -0
  29. data/app/assets/stylesheets/megatron/modules/app/_animations.scss +62 -0
  30. data/app/assets/stylesheets/megatron/modules/app/_index.scss +5 -0
  31. data/app/assets/stylesheets/megatron/modules/app/_layout.scss +261 -0
  32. data/app/assets/stylesheets/megatron/modules/app/_sizes.scss +28 -0
  33. data/app/assets/stylesheets/megatron/modules/app/_typography.scss +111 -0
  34. data/app/assets/stylesheets/megatron/modules/box/_base.scss +94 -0
  35. data/app/assets/stylesheets/megatron/modules/box/_color-box.scss +33 -0
  36. data/app/assets/stylesheets/megatron/modules/box/_deployment_box.scss +37 -0
  37. data/app/assets/stylesheets/megatron/modules/box/_index.scss +4 -0
  38. data/app/assets/stylesheets/megatron/modules/box/_placeholder.scss +6 -0
  39. data/app/assets/stylesheets/megatron/modules/buttons/_animations.scss +35 -0
  40. data/app/assets/stylesheets/megatron/modules/buttons/_buttons.scss +266 -0
  41. data/app/assets/stylesheets/megatron/modules/buttons/_index.scss +4 -0
  42. data/app/assets/stylesheets/megatron/modules/buttons/_mixins.scss +108 -0
  43. data/app/assets/stylesheets/megatron/modules/buttons/_pills.scss +44 -0
  44. data/app/assets/stylesheets/megatron/modules/code/_codemirror.scss +98 -0
  45. data/app/assets/stylesheets/megatron/modules/code/_highlighted.scss +65 -0
  46. data/app/assets/stylesheets/megatron/modules/code/_index.scss +3 -0
  47. data/app/assets/stylesheets/megatron/modules/code/_syntax.scss +18 -0
  48. data/app/assets/stylesheets/megatron/modules/core/_colored-items.scss +22 -0
  49. data/app/assets/stylesheets/megatron/modules/core/_colors.scss +163 -0
  50. data/app/assets/stylesheets/megatron/modules/core/_index.scss +3 -0
  51. data/app/assets/stylesheets/megatron/modules/core/_mixins.scss +262 -0
  52. data/app/assets/stylesheets/megatron/modules/core/_vars.scss +30 -0
  53. data/app/assets/stylesheets/megatron/modules/core/_z-index.scss +3 -0
  54. data/app/assets/stylesheets/megatron/modules/dialog/_animations.scss +48 -0
  55. data/app/assets/stylesheets/megatron/modules/dialog/_dialog.scss +81 -0
  56. data/app/assets/stylesheets/megatron/modules/dialog/_index.scss +2 -0
  57. data/app/assets/stylesheets/megatron/modules/forms/_base.scss +31 -0
  58. data/app/assets/stylesheets/megatron/modules/forms/_check-radio.scss +99 -0
  59. data/app/assets/stylesheets/megatron/modules/forms/_check-switch.scss +88 -0
  60. data/app/assets/stylesheets/megatron/modules/forms/_footer.scss +13 -0
  61. data/app/assets/stylesheets/megatron/modules/forms/_index.scss +10 -0
  62. data/app/assets/stylesheets/megatron/modules/forms/_login.scss +92 -0
  63. data/app/assets/stylesheets/megatron/modules/forms/_radio-nav.scss +62 -0
  64. data/app/assets/stylesheets/megatron/modules/forms/_select.scss +37 -0
  65. data/app/assets/stylesheets/megatron/modules/forms/_stacked-form.scss +29 -0
  66. data/app/assets/stylesheets/megatron/modules/forms/_table-form.scss +53 -0
  67. data/app/assets/stylesheets/megatron/modules/forms/_text-input.scss +118 -0
  68. data/app/assets/stylesheets/megatron/modules/grids/_alignment.scss +39 -0
  69. data/app/assets/stylesheets/megatron/modules/grids/_grid.scss +144 -0
  70. data/app/assets/stylesheets/megatron/modules/grids/_index.scss +2 -0
  71. data/app/assets/stylesheets/megatron/modules/headers/_actions.scss +10 -0
  72. data/app/assets/stylesheets/megatron/modules/headers/_base.scss +67 -0
  73. data/app/assets/stylesheets/megatron/modules/headers/_index.scss +4 -0
  74. data/app/assets/stylesheets/megatron/modules/headers/_meta.scss +10 -0
  75. data/app/assets/stylesheets/megatron/modules/headers/_site-header.scss +8 -0
  76. data/app/assets/stylesheets/megatron/modules/lib/_codemirror.scss +301 -0
  77. data/app/assets/stylesheets/megatron/modules/lists/_base.scss +13 -0
  78. data/app/assets/stylesheets/megatron/modules/lists/_box-list.scss +53 -0
  79. data/app/assets/stylesheets/megatron/modules/lists/_index.scss +2 -0
  80. data/app/assets/stylesheets/megatron/modules/messages/_index.scss +3 -0
  81. data/app/assets/stylesheets/megatron/modules/messages/_notice.scss +57 -0
  82. data/app/assets/stylesheets/megatron/modules/messages/_notifications.scss +126 -0
  83. data/app/assets/stylesheets/megatron/modules/messages/_pop-message.scss +157 -0
  84. data/app/assets/stylesheets/megatron/modules/nav/_auto-navigate.scss +7 -0
  85. data/app/assets/stylesheets/megatron/modules/nav/_breadcrumbs.scss +35 -0
  86. data/app/assets/stylesheets/megatron/modules/nav/_index.scss +8 -0
  87. data/app/assets/stylesheets/megatron/modules/nav/_main-sidebar.scss +21 -0
  88. data/app/assets/stylesheets/megatron/modules/nav/_mixins.scss +53 -0
  89. data/app/assets/stylesheets/megatron/modules/nav/_nav-toggle.scss +61 -0
  90. data/app/assets/stylesheets/megatron/modules/nav/_primary-nav.scss +120 -0
  91. data/app/assets/stylesheets/megatron/modules/nav/_secondary-nav.scss +105 -0
  92. data/app/assets/stylesheets/megatron/modules/nav/_tabs.scss +87 -0
  93. data/app/assets/stylesheets/megatron/modules/roboticons/_font.scss +62 -0
  94. data/app/assets/stylesheets/megatron/modules/roboticons/_icons.scss +219 -0
  95. data/app/assets/stylesheets/megatron/modules/roboticons/_index.scss +2 -0
  96. data/app/assets/stylesheets/megatron/modules/slider/_base.scss +49 -0
  97. data/app/assets/stylesheets/megatron/modules/slider/_index.scss +4 -0
  98. data/app/assets/stylesheets/megatron/modules/slider/_slider.scss +282 -0
  99. data/app/assets/stylesheets/megatron/modules/slider/_switch.scss +75 -0
  100. data/app/assets/stylesheets/megatron/modules/slider/_themes.scss +42 -0
  101. data/app/assets/stylesheets/megatron/modules/tables/_base.scss +170 -0
  102. data/app/assets/stylesheets/megatron/modules/tables/_border-table.scss +28 -0
  103. data/app/assets/stylesheets/megatron/modules/tables/_box-table.scss +36 -0
  104. data/app/assets/stylesheets/megatron/modules/tables/_columns.scss +8 -0
  105. data/app/assets/stylesheets/megatron/modules/tables/_doc-table.scss +22 -0
  106. data/app/assets/stylesheets/megatron/modules/tables/_icon-cell.scss +9 -0
  107. data/app/assets/stylesheets/megatron/modules/tables/_index.scss +7 -0
  108. data/app/assets/stylesheets/megatron/modules/tables/_link-cell.scss +8 -0
  109. data/app/assets/stylesheets/megatron/modules/tables/_responsive-table.scss +13 -0
  110. data/app/assets/stylesheets/megatron/modules/widgets/_index.scss +1 -0
  111. data/app/assets/stylesheets/megatron/modules/widgets/_time-switch.scss +24 -0
  112. data/lib/megatron.rb +1 -1
  113. data/lib/megatron/engine.rb +5 -0
  114. data/lib/megatron/version.rb +1 -1
  115. data/lib/tasks/megatron_tasks.rake +4 -4
  116. data/public/assets/megatron/megatron-0.0.4.css +3 -0
  117. data/public/assets/megatron/{megatron-0.0.3.css.map → megatron-0.0.4.css.map} +3 -3
  118. data/public/assets/megatron/{megatron-0.0.3.js → megatron-0.0.4.js} +1 -1
  119. data/public/assets/megatron/megatron-0.0.4.map.json +1 -0
  120. metadata +115 -6
  121. data/public/assets/megatron/megatron-0.0.3.css +0 -2
  122. data/public/assets/megatron/megatron-0.0.3.map.json +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73b5d84546195b3ca909d0462afa86d8de2e09f6
4
- data.tar.gz: 8d71a31f503a5cfb9fdce2638d974323e920cae8
3
+ metadata.gz: 43cae2501c2d529b579278a0df4001db3f206c34
4
+ data.tar.gz: 2a0ad552fc5270c703e59d331dc566a02cf9978c
5
5
  SHA512:
6
- metadata.gz: b4c95704bf46d07198ca3388bceda66d317d1a90032261c3ab967861c2d26f6e12fbec535de57883d9ee79a767f232d02aa5dacecc04029f9d2bd5eccd559f15
7
- data.tar.gz: 5d30ae0cb7d69de04a7527f45cb1f531011ea662f4dbd78c8be8ee98c255d8a2e507c07477b3a535684f592f2829f2dc44b1f3c9da9b828452560077544987ee
6
+ metadata.gz: d68f6dda9700881f48a325f4eada41e436ffa1ecffbdf9d04a9d681d05443091d9889fe6336ffde3ac8125e8f2b11243091b914f8de02b7260ae28e044a013b1
7
+ data.tar.gz: 99bf9152662f7715155fba1b92dabfb6a39a5acf53ca620edb4d1d58779c09e378d63c92510363c9708df83abc0dad2c052d110d8b57684de39dffb446cad3e7
data/Rakefile CHANGED
@@ -14,11 +14,52 @@ RDoc::Task.new(:rdoc) do |rdoc|
14
14
  rdoc.rdoc_files.include('lib/**/*.rb')
15
15
  end
16
16
 
17
+ load 'rails/tasks/statistics.rake'
17
18
 
19
+ Bundler::GemHelper.install_tasks
18
20
 
19
- load 'rails/tasks/statistics.rake'
21
+ desc "Pick a random user as the winner"
22
+ task :sass_watch do
23
+ require 'listen'
24
+ listen
25
+ end
20
26
 
27
+ def listen
28
+ listener = Listen.to('app/assets/stylesheets/megatron/', only: /\.scss$/) do |modified, added, removed|
29
+ output_paths("Changes detected to", modified)
30
+ output_paths("Added", added)
31
+ output_paths("Removed", removed)
21
32
 
33
+ build
34
+ end
22
35
 
23
- Bundler::GemHelper.install_tasks
36
+ build
37
+
38
+ listener.start # not blocking
39
+ sleep
40
+ end
41
+
42
+ def output_paths(prefix, paths)
43
+ unless paths.empty?
44
+ paths.map! { |p| localize_path(p) }
45
+ puts "#{prefix}: #{paths.join("\n")}"
46
+ end
47
+ end
48
+
49
+ def localize_path(path)
50
+ path.sub(/#{Dir.pwd}\//, '')
51
+ end
52
+
53
+ def destination
54
+ "public/assets/megatron/megatron-#{version}.css"
55
+ end
56
+
57
+ def build
58
+ system "sass app/assets/stylesheets/megatron/megatron.scss:#{destination}"
59
+ system "./node_modules/postcss-cli/bin/postcss --use autoprefixer #{destination} -o #{destination}"
60
+ puts "Built: #{destination}"
61
+ end
24
62
 
63
+ def version
64
+ Gem.loaded_specs["megatron"].version
65
+ end
@@ -0,0 +1,36 @@
1
+ var RemoteForm = require('remote-form')
2
+ var bean = require('bean')
3
+ var notify = require('notify')
4
+
5
+ var MegatronForm = module.exports = RemoteForm.extend({
6
+
7
+ defaultMessages: {
8
+ beforeSend: 'Submitting...',
9
+ success: 'Success!',
10
+ error: 'Something went wrong.'
11
+ },
12
+
13
+ messageFor: function(type){
14
+ if (this.el.dataset[type])
15
+ return this.el.dataset[type]
16
+ else {
17
+ var msg = this.$('[data-ajax-event='+type+']').innerHTML || this.$('script.'+type).innerHTML
18
+ if (msg)
19
+ return msg
20
+ else
21
+ return this.defaultMessages[type]
22
+ }
23
+ },
24
+
25
+ beforeSend: function(req){
26
+ notify.progress(this.messageFor('beforeSend'))
27
+ },
28
+
29
+ success: function(body, status, xhr){
30
+ notify.success(this.messageFor('success'))
31
+ },
32
+
33
+ error: function(xhr, error){
34
+ notify.error(this.messageFor('error'))
35
+ }
36
+ })
@@ -0,0 +1,93 @@
1
+ import * as utils from './utils'
2
+ import * as bean from 'bean'
3
+ import * as Dialog from 'dialog'
4
+ var tap = require('tap-event')
5
+ import * as Form from './form'
6
+ import * as Link from './link'
7
+ import * as _ from 'lodash'
8
+ import * as notify from 'notify'
9
+ import * as request from 'superagent'
10
+
11
+ module.exports = {
12
+ Dialog: Dialog,
13
+ notify: notify,
14
+ utils: utils,
15
+ Event: bean,
16
+ Toggler: utils.Toggler,
17
+ Form: Form,
18
+ request: request,
19
+ Link: Link,
20
+ _: _
21
+ }
22
+
23
+ bean.on(document, 'DOMContentLoaded', pageLoad)
24
+
25
+ // Support rails turbolinks page load event
26
+ bean.on(document, 'page:change', pageChange)
27
+
28
+ function pageLoad(){
29
+ utils.Toggler.listen()
30
+ utils.AutoNavigate.listen()
31
+ if(!window.Turbolinks) {
32
+ pageChange()
33
+ }
34
+ }
35
+
36
+ function pageChange(){
37
+ utils.linkHeadings()
38
+ utils.toggleActiveNav()
39
+ utils.autoSizeTextarea()
40
+ utils.highlightCode()
41
+ utils.Toggler.refresh()
42
+ utils.autofocus()
43
+ utils.notifyFormFlash()
44
+ utils.TimeSwitch.setup()
45
+ utils.Timeago.setup()
46
+ utils.Messages.load()
47
+ }
48
+
49
+ console.log(tap)
50
+
51
+ // Dialog document listener and auto-creator
52
+ bean.on(document, 'click', '[data-trigger=dialog]', handleDialogTrigger)
53
+ bean.on(document, 'click', '[data-trigger=dialog]', tap(handleDialogTrigger))
54
+ bean.on(document, 'click', '.nav_toggle', toggleNavigationMode)
55
+
56
+ function handleDialogTrigger(event){
57
+ event.preventDefault()
58
+ new Dialog(event.currentTarget.dataset).show()
59
+ }
60
+
61
+ function toggleNavigationMode(event) {
62
+ event.target.blur()
63
+ utils.Classie.toggle(document.querySelector('body'), 'active-nav')
64
+ }
65
+
66
+ function disableWith(event){
67
+ var buttons = event.currentTarget.querySelectorAll('[data-disable-with]')
68
+ Array.prototype.forEach.call(buttons, function(button){
69
+ button.disabled = true
70
+ utils.Classie.add(button, 'disabled')
71
+
72
+ var buttonText = button.dataset.disableWith
73
+ if (!buttonText || buttonText == '') { buttonText = button.innerHTML }
74
+
75
+ button.innerHTML = buttonText.replace(/\.{3}/, '…')
76
+ })
77
+ }
78
+
79
+ // If jQuery exists, be sure Rails UJS doesn't
80
+ if (!window.$ || !$.rails) {
81
+ var boundForms = []
82
+ // Form event listener
83
+ bean.on(document, 'submit', 'form[data-remote]', handleRemoteFormSubmit)
84
+ bean.on(document, 'submit', 'form', disableWith)
85
+ bean.on(document, 'click', 'a[data-method], a[data-confirm], button[data-method], button[data-confirm]', Link.click)
86
+ }
87
+
88
+ function handleRemoteFormSubmit(event){
89
+ if (_.find(boundForms, function(el){return el == event.currentTarget}))
90
+ return
91
+ new Form({el: event.currentTarget}).submit(event)
92
+ boundForms.push(event.currentTarget)
93
+ }
@@ -0,0 +1,58 @@
1
+ var domify = require('domify')
2
+ var Dialog = require('dialog')
3
+ var bean = require('bean')
4
+
5
+ module.exports = Link
6
+
7
+ var counter = 0
8
+ var DEFAULT_CONTINUE_BUTTON = 'Yes'
9
+
10
+ function Link(){}
11
+
12
+ Link.click = function(event){
13
+ event.preventDefault()
14
+ var el = event.currentTarget
15
+ var form = null
16
+ if (el.dataset.method) {
17
+ form = Link.buildForm(el)
18
+ document.body.appendChild(form)
19
+ }
20
+
21
+ if (el.dataset.confirm) {
22
+ var opts = {
23
+ title: el.dataset.confirm,
24
+ message: el.dataset.message || null,
25
+ continue: el.dataset.continue || DEFAULT_CONTINUE_BUTTON
26
+ }
27
+ if (el.dataset.method) {
28
+ opts.submit = '#' + form.getAttribute('id')
29
+ if (el.dataset.method.toLowerCase() === 'delete') {
30
+ opts.destructive = true
31
+ opts.continue = el.dataset.continue || 'Delete'
32
+ }
33
+ } else {
34
+ opts.follow = el.getAttribute('href')
35
+ opts.destructive = !!el.dataset.destructive
36
+ opts.submit = el.dataset.submit
37
+ }
38
+
39
+ new Dialog(opts).show()
40
+ } else {
41
+ form.submit()
42
+ }
43
+ }
44
+
45
+ Link.buildForm = function(el){
46
+ var method = el.dataset.method || 'post'
47
+ var csrfToken = document.querySelector('meta[name=csrf-token]')
48
+ var csrfParam = document.querySelector('meta[name=csrf-param]')
49
+
50
+ var form = domify('<form id="link-'+ (++counter) +'" class="hidden" action="'+el.href+'" method="post"></form>')
51
+
52
+ form.appendChild(domify('<input name="_method" value="' + method + '" type="hidden">'))
53
+
54
+ if (csrfToken && csrfParam)
55
+ form.appendChild(domify('<input name="' + csrfParam.getAttribute('content') + '" value="' + csrfToken.getAttribute('content') + '" type="hidden" />'))
56
+
57
+ return form
58
+ }
@@ -0,0 +1,24 @@
1
+ var bean = require('bean')
2
+ var classie = require('classie')
3
+
4
+ require('compose-tap-event')
5
+
6
+ var AutoNavigate = {
7
+ listen: function(){
8
+ bean.on(document, "click", ".auto-navigate", AutoNavigate.trigger)
9
+ },
10
+
11
+ trigger: function(event) {
12
+ var target = event.target
13
+ if (target.tagName.toLowerCase() != 'a') {
14
+ link = event.currentTarget.querySelector('a.navigate')
15
+ if (event.metaKey) {
16
+ window.open(link)
17
+ } else {
18
+ bean.fire(link, 'click')
19
+ }
20
+ }
21
+ }
22
+ }
23
+
24
+ module.exports = AutoNavigate
@@ -0,0 +1,39 @@
1
+ var bean = require('bean')
2
+ var notify = require('notify')
3
+
4
+ module.exports = {
5
+ notify: function(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(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() {
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
+ }
39
+ }
@@ -0,0 +1,112 @@
1
+ var bean = require('bean')
2
+ var CodeMirror = require('codemirror')
3
+ var classie = require('classie')
4
+ var Toggler = require('./toggler')
5
+ var Messages = require('./messages')
6
+ var AutoNavigate = require('./auto-navigate')
7
+ var Timeago = require('./time/timeago')
8
+ var TimeSwitch = require('./time/time-switch')
9
+ var notify = require('notify')
10
+
11
+ require('codemirror/mode/htmlmixed/htmlmixed')
12
+ require('codemirror/mode/slim/slim')
13
+ require('codemirror/mode/javascript/javascript')
14
+ require('codemirror/mode/css/css')
15
+ require('codemirror/mode/sql/sql')
16
+ require('codemirror/addon/runmode/runmode.js')
17
+ require('codemirror/addon/edit/matchbrackets.js')
18
+
19
+ module.exports = {
20
+ Timeago: Timeago,
21
+ TimeSwitch: TimeSwitch,
22
+ CodeMirror: CodeMirror,
23
+ Classie: classie,
24
+ Toggler: Toggler,
25
+ Messages: Messages,
26
+ AutoNavigate: AutoNavigate,
27
+
28
+ toggleActiveNav: function toggleActiveNav(){
29
+ Array.prototype.forEach.call(document.querySelectorAll('[data-match-url]'), function(node){
30
+ var matcher = node.getAttribute('data-match-url')
31
+ if (matcher && new RegExp(node.getAttribute('data-match-url'), "i").test(location.pathname)) {
32
+ node.className += ' here'
33
+ }
34
+ })
35
+ },
36
+
37
+ highlightCode: function highlightCode(){
38
+ var aliasLang = function(lang) {
39
+ var aliases = {
40
+ 'markup': 'htmlmixed',
41
+ 'html': 'htmlmixed',
42
+ 'json': 'javascript',
43
+ }
44
+
45
+ return(aliases[lang] || lang)
46
+ }
47
+ var elements = document.querySelectorAll('[class*="language-"], [class*="lang-"]');
48
+ for (var i=0, element; element = elements[i++];) {
49
+ var lang = element.className.match(/lang.*?-(\S+)/)[1]
50
+
51
+ // Standardize classes: lang-[language]
52
+ if (classie.has(element, 'language-'+lang)) {
53
+ classie.remove(element, 'language-'+lang)
54
+ classie.add(element, 'lang-'+lang)
55
+ }
56
+ var code = element.textContent.trim()
57
+
58
+ var options = {}
59
+ if(lang == 'json') {
60
+ options.json = true
61
+ }
62
+
63
+ CodeMirror.runMode(code, aliasLang(lang), element, options)
64
+ element.innerHTML = "<code class='highlighted-code static-code cm-s-default'>" + element.innerHTML + "</code>"
65
+ classie.add(element, 'highlighted')
66
+ }
67
+ },
68
+
69
+ linkHeadings: function linkHeadings(){
70
+ var headings = document.querySelectorAll('h2, h3, h4')
71
+ for(let i = 0; i < headings.length; i++){
72
+ var heading = headings[i];
73
+ if (heading.id != ''){
74
+ heading.innerHTML = "<a href='#"+heading.id+"' class='heading-link'>"+ heading.innerHTML +"</a>"
75
+ heading.className = heading.className + " linked_heading";
76
+ }
77
+ }
78
+ },
79
+
80
+ autoSizeTextarea: function autoSizeTextarea() {
81
+
82
+ var autoHeight = function(node) {
83
+ if (!node.className.match(/fixed/)) {
84
+ var offset = node.offsetHeight - node.clientHeight;
85
+ node.style.height = 'auto';
86
+ node.style.height = (node.scrollHeight + offset ) + 'px';
87
+ }
88
+ }
89
+ Array.prototype.forEach.call(document.querySelectorAll('textarea'), autoHeight)
90
+
91
+ bean.on(document.querySelector('body'), 'keyup', 'textarea', function(event){
92
+ autoHeight(event.currentTarget)
93
+ })
94
+ },
95
+
96
+ notifyFormFlash: function notifyFormFlash(){
97
+ var flash = document.querySelector('.form-flash')
98
+ if (flash) {
99
+ var type = flash.dataset.type || 'error'
100
+ if (type == 'info') type = 'action'
101
+ notify[type](flash.textContent.trim())
102
+ classie.add(flash, 'hidden')
103
+ }
104
+ },
105
+
106
+ autofocus: function autofocus() {
107
+ var focus_el = document.querySelector('.autofocus')
108
+ if (focus_el) {
109
+ focus_el.focus()
110
+ }
111
+ }
112
+ }
@@ -0,0 +1,97 @@
1
+ var request = require('superagent')
2
+ var bean = require('bean')
3
+
4
+ var Messages = {
5
+ el: function(){
6
+ return document.querySelector('.pop-message')
7
+ },
8
+
9
+ fetch: function(){
10
+ request.get('/messages.json', this.success.bind(this));
11
+ },
12
+
13
+ dismiss: function(event){
14
+ self = this
15
+ event.preventDefault()
16
+ event.stopPropagation()
17
+
18
+ // Track dismissal
19
+ request.get(event.currentTarget.getAttribute('href')).end(function(response){
20
+ // Ask for any new messages
21
+ self.fetch()
22
+ })
23
+
24
+ // Remove element and clear cache
25
+ this.el().remove()
26
+ window.Megatron.accountMessage = null
27
+
28
+ },
29
+
30
+ success: function(response) {
31
+ if (response.serverError) {
32
+ return
33
+ } else {
34
+ var options = JSON.parse(response.text)[0]
35
+ if(options) {
36
+ var html = this.messageHTML(options)
37
+ this.saveMessage(html)
38
+ this.showMessage(html)
39
+ bean.on(this.el(), 'click', '.dismiss', this.dismiss.bind(this))
40
+ }
41
+ }
42
+ },
43
+
44
+ messageHTML: function(options){
45
+ options.style = options.style || ''
46
+ var classnames = "message-content "
47
+ if (options.style)
48
+ classnames += options.style
49
+ if (options.url)
50
+ classnames += " with-url"
51
+ if (options.dismissable)
52
+ classnames += " dismissable"
53
+
54
+ var html = "<div class='"+classnames+"'>"
55
+ if (options.dismissable)
56
+ html += "<a href='/messages/"+options.id+"/dismiss' class='dismiss' data-no-turbolink><span class='dismiss-icon x_circle_icon'></span><span class='hidden_label'>dismiss message</span></a>"
57
+
58
+ html += "<p>"
59
+ if (options.url)
60
+ html += "<a href='/messages/"+options.id+"/link'>"+options.body+"</a>"
61
+ else
62
+ html += options.body
63
+ html += "</p></div>"
64
+
65
+ return html
66
+ },
67
+
68
+ saveMessage: function(content){
69
+ window.Megatron.accountMessage = content
70
+ },
71
+
72
+ showMessage: function(content) {
73
+ if(this.el()) {
74
+ this.el().innerHTML = content
75
+ } else {
76
+ var header = document.querySelector('.site-header')
77
+
78
+ // if message display isn't disabled by data-no-messages=true
79
+ if (header.dataset.noMessages == null) {
80
+ header.innerHTML = "<div class='pop-message'>"+content+"</div>" + header.innerHTML
81
+ }
82
+ }
83
+ },
84
+
85
+ load: function(){
86
+ if(window.location.hostname.match(/app\.compose\.(io|dev)/)){
87
+ message = window.Megatron.accountMessage
88
+ if(!message) {
89
+ this.fetch()
90
+ } else {
91
+ this.showMessage(message)
92
+ }
93
+ }
94
+ }
95
+ }
96
+
97
+ module.exports = Messages