chr 0.2.1 → 0.2.4

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 (59) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/Gruntfile.coffee +50 -16
  4. data/app/assets/javascripts/chr.coffee +9 -16
  5. data/app/assets/javascripts/chr/core/chr.coffee +38 -20
  6. data/app/assets/javascripts/chr/core/item.coffee +30 -24
  7. data/app/assets/javascripts/chr/core/list.coffee +30 -60
  8. data/app/assets/javascripts/chr/core/list_config.coffee +65 -0
  9. data/app/assets/javascripts/chr/core/list_pagination.coffee +27 -0
  10. data/app/assets/javascripts/chr/core/list_reorder.coffee +75 -0
  11. data/app/assets/javascripts/chr/core/list_search.coffee +41 -0
  12. data/app/assets/javascripts/chr/core/module.coffee +55 -32
  13. data/app/assets/javascripts/chr/core/utils.coffee +34 -13
  14. data/app/assets/javascripts/chr/core/view.coffee +70 -97
  15. data/app/assets/javascripts/chr/form/form.coffee +63 -49
  16. data/app/assets/javascripts/chr/form/input-checkbox.coffee +40 -27
  17. data/app/assets/javascripts/chr/form/input-color.coffee +26 -8
  18. data/app/assets/javascripts/chr/form/input-date.coffee +0 -0
  19. data/app/assets/javascripts/chr/form/input-file.coffee +81 -46
  20. data/app/assets/javascripts/chr/form/input-form.coffee +162 -0
  21. data/app/assets/javascripts/chr/form/input-form_reorder.coffee +67 -0
  22. data/app/assets/javascripts/chr/form/input-hidden.coffee +27 -11
  23. data/app/assets/javascripts/chr/form/input-list.coffee +60 -56
  24. data/app/assets/javascripts/chr/form/input-list_reorder.coffee +37 -0
  25. data/app/assets/javascripts/chr/form/input-password.coffee +31 -0
  26. data/app/assets/javascripts/chr/form/input-select.coffee +61 -35
  27. data/app/assets/javascripts/chr/form/input-string.coffee +55 -25
  28. data/app/assets/javascripts/chr/form/input-text.coffee +22 -5
  29. data/app/assets/javascripts/chr/store/mongosteen-array-store.coffee +1 -1
  30. data/app/assets/javascripts/chr/vendor/ace.js +18280 -0
  31. data/app/assets/javascripts/chr/vendor/marked.js +1272 -0
  32. data/app/assets/javascripts/chr/vendor/mode-html.js +2436 -0
  33. data/app/assets/javascripts/chr/vendor/mode-markdown.js +2820 -0
  34. data/app/assets/javascripts/chr/vendor/redactor.fixedtoolbar.js +110 -0
  35. data/app/assets/javascripts/input-html.coffee +78 -0
  36. data/app/assets/javascripts/input-markdown.coffee +88 -0
  37. data/app/assets/javascripts/input-redactor.coffee +66 -0
  38. data/app/assets/stylesheets/_chr.scss +6 -6
  39. data/app/assets/stylesheets/_input-redactor.scss +34 -0
  40. data/app/assets/stylesheets/core/_mixins.scss +75 -0
  41. data/app/assets/stylesheets/form/_input-checkbox.scss +18 -0
  42. data/app/assets/stylesheets/form/{_input_color.scss → _input-color.scss} +0 -0
  43. data/app/assets/stylesheets/form/{_input_file.scss → _input-file.scss} +1 -0
  44. data/app/assets/stylesheets/form/{_nested_form.scss → _input-form.scss} +0 -0
  45. data/app/assets/stylesheets/form/{_input_list.scss → _input-list.scss} +0 -0
  46. data/app/assets/stylesheets/form/_input-string.scss +8 -0
  47. data/bower.json +3 -2
  48. data/{app/assets/javascripts/chr-dist.js → dist/chr.js} +1472 -1337
  49. data/dist/input-ace.js +24936 -0
  50. data/dist/input-redactor.js +156 -0
  51. data/lib/chr/version.rb +1 -1
  52. data/package.json +2 -2
  53. metadata +29 -13
  54. data/app/assets/javascripts/chr/core/list-pagination.coffee +0 -26
  55. data/app/assets/javascripts/chr/core/list-reorder.coffee +0 -70
  56. data/app/assets/javascripts/chr/core/list-search.coffee +0 -37
  57. data/app/assets/javascripts/chr/form/nested-form.coffee +0 -164
  58. data/app/assets/stylesheets/form/_input_checkbox.scss +0 -91
  59. data/app/assets/stylesheets/form/_input_string.scss +0 -8
@@ -0,0 +1,110 @@
1
+ /*
2
+ * webhook-redactor
3
+ *
4
+ *
5
+ * Copyright (c) 2014 Webhook
6
+ * Licensed under the MIT license.
7
+ */
8
+
9
+ (function ($) {
10
+ "use strict";
11
+
12
+ // namespacing
13
+ var Fixedtoolbar = function (redactor) {
14
+ this.redactor = redactor;
15
+ this.$window = $('.view > form'); //$(window);
16
+ this.viewHeaderHeight = 40;
17
+
18
+ this.$window.on('scroll', $.proxy(this.checkOffset, this));
19
+ redactor.$box.on('scroll', $.proxy(this.checkOffset, this));
20
+
21
+ this.redactor.$editor.on('focus', $.proxy(function () {
22
+ this.isFocused = true;
23
+ }, this));
24
+
25
+ this.redactor.$editor.on('blur', $.proxy(function () {
26
+ this.isFocused = false;
27
+ }, this));
28
+ };
29
+ Fixedtoolbar.prototype = {
30
+ isFixed: false,
31
+ isFocused: false,
32
+
33
+ checkOffset: function () {
34
+ if ( !this.redactor.fullscreen.isOpen )
35
+ {
36
+ var boxOffset = this.redactor.$box.offset();
37
+
38
+ var isBelowBoxTop = boxOffset.top - this.viewHeaderHeight <= 0;
39
+ //var isAboveBoxBottom = boxOffset.top + this.redactor.$box.outerHeight() - this.redactor.$toolbar.outerHeight() - this.$window.scrollTop() >= 0;
40
+ var isAboveBoxBottom = this.redactor.$box.outerHeight() + boxOffset.top - this.viewHeaderHeight - this.redactor.$toolbar.outerHeight() >= 0;
41
+
42
+ if (isBelowBoxTop && isAboveBoxBottom) {
43
+ this.fix();
44
+ } else {
45
+ this.unfix();
46
+ }
47
+ }
48
+ },
49
+
50
+ fix: function () {
51
+
52
+ if (this.isFixed) {
53
+
54
+ // webkit does not recalc top: 0 when focused on contenteditable
55
+ if (this.redactor.utils.isMobile() && this.isFocused) {
56
+ this.redactor.$toolbar.css({
57
+ position: 'absolute',
58
+ top : this.$window.scrollTop() - this.redactor.$box.offset().top,
59
+ left : this.redactor.$box.offset().left
60
+ });
61
+ }
62
+
63
+ return;
64
+ }
65
+
66
+ var border_left = parseInt(this.redactor.$box.css('border-left-width').replace('px', ''), 10);
67
+
68
+ this.redactor.$toolbar.css({
69
+ position: 'fixed',
70
+ top : this.viewHeaderHeight,
71
+ left : this.redactor.$box.offset().left + border_left,
72
+ width : this.redactor.$box.width(),
73
+ zIndex : 300
74
+ });
75
+
76
+ this.redactor.$editor.css('padding-top', this.redactor.$toolbar.height() + 10);
77
+
78
+ this.isFixed = true;
79
+
80
+ },
81
+
82
+ unfix: function () {
83
+ if (!this.isFixed) {
84
+ return;
85
+ }
86
+
87
+ this.redactor.$toolbar.css({
88
+ position: 'relative',
89
+ left : '',
90
+ width : '',
91
+ top : ''
92
+ });
93
+
94
+ this.redactor.$editor.css('padding-top', 10);
95
+
96
+ this.isFixed = false;
97
+ }
98
+ };
99
+
100
+ // Hook up plugin to Redactor.
101
+ window.RedactorPlugins = window.RedactorPlugins || {};
102
+ window.RedactorPlugins.fixedtoolbar = function() {
103
+ return {
104
+ init: function () {
105
+ this.fixedtoolbar = new Fixedtoolbar(this);
106
+ }
107
+ };
108
+ };
109
+
110
+ }(jQuery));
@@ -0,0 +1,78 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Author: Alexander Kravets <alex@slatestudio.com>,
3
+ # Slate Studio (http://www.slatestudio.com)
4
+ #
5
+ # Coding Guide:
6
+ # https://github.com/thoughtbot/guides/tree/master/style/coffeescript
7
+ # -----------------------------------------------------------------------------
8
+
9
+ # -----------------------------------------------------------------------------
10
+ # INPUT HTML
11
+ # -----------------------------------------------------------------------------
12
+ #
13
+ # Config options:
14
+ # label - Input label
15
+ # aceOptions - Custom options for overriding default ones
16
+ #
17
+ # Input config example:
18
+ # body_html: { type: 'html', label: 'Article' }
19
+ #
20
+ # Dependencies:
21
+ #= require chr/vendor/ace
22
+ #= require chr/vendor/mode-html
23
+ #
24
+ # -----------------------------------------------------------------------------
25
+
26
+ class @InputHtml extends InputString
27
+
28
+ # PRIVATE ===============================================
29
+
30
+ _add_input: ->
31
+ @$input =$ "<input type='hidden' name='#{ @name }' value='#{ @_safe_value() }' />"
32
+ @$el.append @$input
33
+
34
+ @$editor =$ "<div></div>"
35
+ @$el.append @$editor
36
+
37
+
38
+ _update_inputs: ->
39
+ @value = @editor.getSession().getValue()
40
+ @$input.val(@value)
41
+
42
+
43
+ # PUBLIC ================================================
44
+
45
+ initialize: ->
46
+ @editor = ace.edit(@$editor.get(0))
47
+ @session = @editor.getSession()
48
+
49
+ @session.setValue(@$input.val())
50
+ @session.setUseWrapMode(true)
51
+ @session.setMode("ace/mode/html")
52
+
53
+ # ace options: https://github.com/ajaxorg/ace/wiki/Configuring-Ace
54
+ @editor.$blockScrolling = Infinity # disable warning
55
+ @editor.setOptions
56
+ autoScrollEditorIntoView: true
57
+ minLines: 5
58
+ maxLines: Infinity
59
+ showLineNumbers: false
60
+ showGutter: false
61
+ highlightActiveLine: false
62
+ showPrintMargin: false
63
+
64
+ @session.on 'change', (e) => @_update_inputs()
65
+
66
+ @config.onInitialize?(this)
67
+
68
+
69
+ updateValue: (@value) ->
70
+ @editor.getSession().setValue(@value)
71
+ @$input.val(@value)
72
+
73
+
74
+ chr.formInputs['html'] = InputHtml
75
+
76
+
77
+
78
+
@@ -0,0 +1,88 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Author: Alexander Kravets <alex@slatestudio.com>,
3
+ # Slate Studio (http://www.slatestudio.com)
4
+ #
5
+ # Coding Guide:
6
+ # https://github.com/thoughtbot/guides/tree/master/style/coffeescript
7
+ # -----------------------------------------------------------------------------
8
+
9
+ # -----------------------------------------------------------------------------
10
+ # INPUT MARKDOWN
11
+ # -----------------------------------------------------------------------------
12
+ # Markdown input supports syntax highlighting and optional compilation to html.
13
+ #
14
+ # Config options:
15
+ # label - Input label
16
+ # aceOptions - Custom options for overriding default ones
17
+ # htmlFieldName - Input name for generated HTML content
18
+ #
19
+ # Input config example:
20
+ # body_md: { type: 'markdown', label: 'Article', htmlFieldName: 'body_html' }
21
+ #
22
+ # Dependencies:
23
+ #= require chr/vendor/marked
24
+ #= require chr/vendor/ace
25
+ #= require chr/vendor/mode-markdown
26
+ #
27
+ # -----------------------------------------------------------------------------
28
+
29
+ class @InputMarkdown extends InputString
30
+
31
+ # PRIVATE ===============================================
32
+
33
+ _add_input: ->
34
+ if @config.htmlFieldName
35
+ @$inputHtml =$ "<input type='hidden' name='[#{ @config.htmlFieldName }]' />"
36
+ @$el.append @$inputHtml
37
+
38
+ @$input =$ "<input type='hidden' name='#{ @name }' value='#{ @_safe_value() }' />"
39
+ @$el.append @$input
40
+
41
+ @$editor =$ "<div></div>"
42
+ @$el.append @$editor
43
+
44
+
45
+ _update_inputs: ->
46
+ md_source = @session.getValue()
47
+ @$input.val(md_source)
48
+
49
+ if @$inputHtml
50
+ html = marked(md_source)
51
+ @$inputHtml.val(html)
52
+
53
+
54
+ # PUBLIC ================================================
55
+
56
+ initialize: ->
57
+ @editor = ace.edit(@$editor.get(0))
58
+ @session = @editor.getSession()
59
+
60
+ @session.setValue(@$input.val())
61
+ @session.setMode("ace/mode/markdown")
62
+
63
+ # options: https://github.com/ajaxorg/ace/wiki/Configuring-Ace
64
+ @editor.$blockScrolling = Infinity # disable warning
65
+ @editor.setOptions
66
+ autoScrollEditorIntoView: true
67
+ minLines: 5
68
+ maxLines: Infinity
69
+ showLineNumbers: false
70
+ showGutter: false
71
+ highlightActiveLine: false
72
+ showPrintMargin: false
73
+
74
+ @session.on 'change', (e) => @_update_inputs()
75
+
76
+ @config.onInitialize?(this)
77
+
78
+
79
+ updateValue: (@value) ->
80
+ @session.setValue(@value)
81
+ @_update_inputs()
82
+
83
+
84
+ chr.formInputs['markdown'] = InputMarkdown
85
+
86
+
87
+
88
+
@@ -0,0 +1,66 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Author: Alexander Kravets <alex@slatestudio.com>,
3
+ # Slate Studio (http://www.slatestudio.com)
4
+ #
5
+ # Coding Guide:
6
+ # https://github.com/thoughtbot/guides/tree/master/style/coffeescript
7
+ # -----------------------------------------------------------------------------
8
+
9
+ # -----------------------------------------------------------------------------
10
+ # INPUT REDACTOR
11
+ # -----------------------------------------------------------------------------
12
+ #
13
+ # Dependencies:
14
+ #= require redactor
15
+ #= require chr/vendor/redactor.fixedtoolbar
16
+ #
17
+ # -----------------------------------------------------------------------------
18
+
19
+ class @InputRedactor extends InputString
20
+
21
+ # PRIVATE ===============================================
22
+
23
+ _add_input: ->
24
+ @$el.css('opacity', 0)
25
+ @$input =$ "<textarea class='redactor' name='#{ @name }' rows=1>#{ @_safe_value() }</textarea>"
26
+ @$el.append @$input
27
+
28
+
29
+ # PUBLIC ================================================
30
+
31
+ initialize: ->
32
+ redactor_options =
33
+ focus: false
34
+ imageFloatMargin: '20px'
35
+ buttonSource: true
36
+ pastePlainText: true
37
+ plugins: [ 'fixedtoolbar', 'loft' ]
38
+ buttons: [ 'html',
39
+ 'formatting',
40
+ 'bold',
41
+ 'italic',
42
+ 'deleted',
43
+ 'alignment',
44
+ 'unorderedlist',
45
+ 'orderedlist',
46
+ 'link' ]
47
+
48
+ @config.redactorOptions ?= {}
49
+ $.extend(redactor_options, @config.redactorOptions)
50
+
51
+ @$input.redactor(redactor_options)
52
+
53
+ @$el.css('opacity', 1)
54
+
55
+ @config.onInitialize?(this)
56
+
57
+
58
+ updateValue: (@value) ->
59
+ @$input.redactor('insert.set', @_safe_value())
60
+
61
+
62
+ chr.formInputs['redactor'] = InputRedactor
63
+
64
+
65
+
66
+
@@ -8,9 +8,9 @@
8
8
  @import "core/responsive";
9
9
 
10
10
  @import "form/form";
11
- @import "form/input_checkbox";
12
- @import "form/input_color";
13
- @import "form/input_file";
14
- @import "form/input_list";
15
- @import "form/input_string";
16
- @import "form/nested_form";
11
+ @import "form/input-checkbox";
12
+ @import "form/input-color";
13
+ @import "form/input-file";
14
+ @import "form/input-form";
15
+ @import "form/input-list";
16
+ @import "form/input-string";
@@ -0,0 +1,34 @@
1
+ @import "redactor";
2
+
3
+
4
+ // input
5
+ .input-inverter,
6
+ .input-redactor {
7
+ .redactor-box { margin-bottom: 0; }
8
+ .redactor-toolbar { box-shadow: none; border-bottom: 2px solid $contrastColor; }
9
+ .redactor-editor { border: 1px solid $contrastColor; border-top: 0; }
10
+ }
11
+
12
+
13
+ // fullscreen
14
+ .redactor-box-fullscreen {
15
+ .redactor-toolbar { box-shadow: none; border-bottom: 2px solid $contrastColor; }
16
+ .redactor-placeholder:after { content: ''; }
17
+ .redactor-editor { padding-bottom: 5em; border: none; }
18
+ }
19
+
20
+
21
+ // placeholder
22
+ .redactor-placeholder:after { color: $lightColor!important; }
23
+
24
+
25
+ // scrollbars
26
+ .redactor-editor, textarea.redactor { @include customScrollbar(); }
27
+
28
+
29
+ // line-height issue fix
30
+ .redactor-editor { line-height: inherit !important; }
31
+
32
+
33
+
34
+
@@ -50,6 +50,81 @@
50
50
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.2);
51
51
  }
52
52
 
53
+ @mixin switchControl() {
54
+ $switch-width: 52px;
55
+ $switch-padding: 2px;
56
+ $switch-height: 32px;
57
+ $switch-radius: $switch-height;
58
+ $knob-size: $switch-height - ($switch-padding * 2);
59
+ $knob-radius: $switch-height - ($switch-padding * 2);
60
+ $knob-width: $knob-size;
61
+ $switch-background: $white;
62
+ $switch-border-background: $contrastColor;
63
+ $switch-shadow: 0 0px 2px transparentize(black, 0.6);
64
+
65
+ border-radius: $switch-radius;
66
+ cursor: pointer;
67
+ display: inline-block;
68
+ height: $switch-height;
69
+ position: relative;
70
+ width: $switch-width;
71
+
72
+ input[type="checkbox"] {
73
+ display: none;
74
+
75
+ + .checkbox {
76
+ @include transition(all 0.3s ease);
77
+ background: $switch-border-background;
78
+ border-radius: $switch-radius;
79
+ border: none;
80
+ cursor: pointer;
81
+ height: $switch-height;
82
+ margin: 0;
83
+ padding: 0;
84
+ position: relative;
85
+ width: $switch-width;
86
+ z-index: 0;
87
+
88
+ &:before {
89
+ @include position(absolute, 2px 0 0 2px);
90
+ @include transform(scale(1));
91
+ @include transition(all 0.3s ease);
92
+ background: $switch-background;
93
+ border-radius: $switch-radius;
94
+ content: "";
95
+ height: $knob-radius;
96
+ width: $switch-width - ($switch-padding * 2);
97
+ z-index: 1;
98
+ }
99
+
100
+ &:after {
101
+ @include position(absolute, 2px 0 0 2px);
102
+ @include transition(all 0.3s ease);
103
+ @include size($knob-size);
104
+ background: $switch-background;
105
+ border-radius: $knob-radius;
106
+ box-shadow: $switch-shadow;
107
+ content: "";
108
+ z-index: 2;
109
+ }
110
+ }
111
+
112
+ &:checked {
113
+ + .checkbox {
114
+ background: $positiveColor;
115
+
116
+ &:before {
117
+ @include transform(scale(0));
118
+ }
119
+
120
+ &:after {
121
+ left: $switch-width - $knob-width - ($switch-padding);
122
+ }
123
+ }
124
+ }
125
+ }
126
+ }
127
+
53
128
 
54
129
 
55
130