chr 0.2.8 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/Gruntfile.coffee +33 -27
  3. data/README.md +6 -1
  4. data/app/assets/javascripts/chr.coffee +18 -16
  5. data/app/assets/javascripts/chr/core/chr.coffee +41 -76
  6. data/app/assets/javascripts/chr/core/chr_router.coffee +141 -0
  7. data/app/assets/javascripts/chr/core/item.coffee +36 -49
  8. data/app/assets/javascripts/chr/core/list.coffee +26 -71
  9. data/app/assets/javascripts/chr/core/list_config.coffee +28 -13
  10. data/app/assets/javascripts/chr/core/list_pagination.coffee +56 -13
  11. data/app/assets/javascripts/chr/core/list_reorder.coffee +2 -2
  12. data/app/assets/javascripts/chr/core/list_search.coffee +2 -2
  13. data/app/assets/javascripts/chr/core/module.coffee +24 -93
  14. data/app/assets/javascripts/chr/core/utils.coffee +4 -0
  15. data/app/assets/javascripts/chr/core/view.coffee +123 -43
  16. data/app/assets/javascripts/chr/core/view_local-storage.coffee +58 -0
  17. data/app/assets/javascripts/chr/store/{_array-store.coffee → array-store.coffee} +3 -1
  18. data/app/assets/javascripts/chr/store/{_object-store.coffee → object-store.coffee} +0 -0
  19. data/app/assets/javascripts/chr/store/rails-array-store.coffee +39 -0
  20. data/app/assets/javascripts/chr/store/{mongosteen-object-store.coffee → rails-form-object-parser.coffee} +11 -20
  21. data/app/assets/javascripts/chr/store/rails-object-store.coffee +35 -0
  22. data/app/assets/javascripts/chr/store/rest-array-store.coffee +3 -5
  23. data/app/assets/javascripts/chr/store/rest-object-store.coffee +1 -1
  24. data/app/assets/javascripts/form/expandable-group.coffee +30 -0
  25. data/app/assets/javascripts/{chr/form → form}/form.coffee +3 -1
  26. data/app/assets/javascripts/{chr/form → form}/input-checkbox.coffee +1 -1
  27. data/app/assets/javascripts/{chr/form → form}/input-color.coffee +2 -0
  28. data/app/assets/javascripts/{chr/form → form}/input-date.coffee +0 -0
  29. data/app/assets/javascripts/{chr/form → form}/input-file.coffee +28 -1
  30. data/app/assets/javascripts/{chr/form → form}/input-form.coffee +14 -5
  31. data/app/assets/javascripts/{chr/form → form}/input-form_reorder.coffee +0 -0
  32. data/app/assets/javascripts/{chr/form → form}/input-hidden.coffee +9 -9
  33. data/app/assets/javascripts/{chr/form → form}/input-list.coffee +61 -53
  34. data/app/assets/javascripts/{chr/form → form}/input-list_reorder.coffee +2 -0
  35. data/app/assets/javascripts/form/input-list_typeahead.coffee +55 -0
  36. data/app/assets/javascripts/{chr/form → form}/input-password.coffee +1 -0
  37. data/app/assets/javascripts/{chr/form → form}/input-select.coffee +10 -11
  38. data/app/assets/javascripts/form/input-select2.coffee +33 -0
  39. data/app/assets/javascripts/{chr/form → form}/input-string.coffee +45 -2
  40. data/app/assets/javascripts/{chr/form → form}/input-text.coffee +6 -3
  41. data/app/assets/javascripts/input-html.coffee +8 -5
  42. data/app/assets/javascripts/input-markdown.coffee +10 -5
  43. data/app/assets/javascripts/input-redactor.coffee +1 -61
  44. data/app/assets/javascripts/redactor/input-redactor.coffee +53 -0
  45. data/app/assets/javascripts/redactor/input-redactor_character.coffee +83 -0
  46. data/app/assets/javascripts/redactor/input-redactor_images.coffee +166 -0
  47. data/app/assets/javascripts/{chr/vendor → vendor}/ace.js +0 -0
  48. data/app/assets/javascripts/{chr/vendor → vendor}/jquery.scrollparent.js +0 -0
  49. data/app/assets/javascripts/{chr/vendor → vendor}/jquery.textarea_autosize.js +0 -0
  50. data/app/assets/javascripts/{chr/vendor → vendor}/jquery.typeahead.js +0 -0
  51. data/app/assets/javascripts/{chr/vendor → vendor}/marked.js +0 -0
  52. data/app/assets/javascripts/{chr/vendor → vendor}/mode-html.js +0 -0
  53. data/app/assets/javascripts/{chr/vendor → vendor}/mode-markdown.js +0 -0
  54. data/app/assets/javascripts/{chr/vendor → vendor}/redactor.fixedtoolbar.js +1 -1
  55. data/app/assets/javascripts/vendor/select2.js +5274 -0
  56. data/app/assets/javascripts/{chr/vendor → vendor}/slip.js +0 -0
  57. data/app/assets/stylesheets/_chr.scss +11 -13
  58. data/app/assets/stylesheets/_input-redactor.scss +17 -16
  59. data/app/assets/stylesheets/{core → chr}/_icons.scss +1 -1
  60. data/app/assets/stylesheets/chr/_main.scss +110 -0
  61. data/app/assets/stylesheets/{core → chr}/_mixins.scss +58 -34
  62. data/app/assets/stylesheets/{core → chr}/_settings.scss +7 -1
  63. data/app/assets/stylesheets/form/_expandable-group.scss +16 -0
  64. data/app/assets/stylesheets/form/_input-select2.scss +94 -0
  65. data/app/assets/stylesheets/form/_main.scss +180 -0
  66. data/app/assets/stylesheets/vendor/select2.css +258 -0
  67. data/bower.json +2 -2
  68. data/dist/chr.js +2292 -2030
  69. data/dist/input-ace.js +18 -8
  70. data/dist/input-redactor.js +0 -156
  71. data/docs/bootstrap.md +1 -1
  72. data/docs/rails.md +10 -10
  73. data/lib/chr.rb +1 -8
  74. data/lib/chr/version.rb +1 -1
  75. data/lib/mongoid/character.rb +30 -0
  76. data/package.json +1 -1
  77. metadata +49 -43
  78. data/app/assets/javascripts/chr/store/mongosteen-array-store.coffee +0 -55
  79. data/app/assets/stylesheets/core/_list.scss +0 -39
  80. data/app/assets/stylesheets/core/_main.scss +0 -49
  81. data/app/assets/stylesheets/core/_responsive.scss +0 -62
  82. data/app/assets/stylesheets/form/_form.scss +0 -41
  83. data/app/assets/stylesheets/form/_input-checkbox.scss +0 -18
  84. data/app/assets/stylesheets/form/_input-color.scss +0 -10
  85. data/app/assets/stylesheets/form/_input-file.scss +0 -29
  86. data/app/assets/stylesheets/form/_input-form.scss +0 -26
  87. data/app/assets/stylesheets/form/_input-list.scss +0 -36
  88. data/app/assets/stylesheets/form/_input-string.scss +0 -8
@@ -18,8 +18,8 @@
18
18
  # body_html: { type: 'html', label: 'Article' }
19
19
  #
20
20
  # Dependencies:
21
- #= require chr/vendor/ace
22
- #= require chr/vendor/mode-html
21
+ #= require vendor/ace
22
+ #= require vendor/mode-html
23
23
  #
24
24
  # -----------------------------------------------------------------------------
25
25
 
@@ -38,20 +38,23 @@ class @InputHtml extends InputString
38
38
  _update_inputs: ->
39
39
  @value = @editor.getSession().getValue()
40
40
  @$input.val(@value)
41
+ @$input.trigger('change')
41
42
 
42
43
 
43
44
  # PUBLIC ================================================
44
45
 
45
46
  initialize: ->
46
- @editor = ace.edit(@$editor.get(0))
47
- @session = @editor.getSession()
47
+ @config.beforeInitialize?(this)
48
+
49
+ @editor = ace.edit(@$editor.get(0))
50
+ @editor.$blockScrolling = Infinity
48
51
 
52
+ @session = @editor.getSession()
49
53
  @session.setValue(@$input.val())
50
54
  @session.setUseWrapMode(true)
51
55
  @session.setMode("ace/mode/html")
52
56
 
53
57
  # ace options: https://github.com/ajaxorg/ace/wiki/Configuring-Ace
54
- @editor.$blockScrolling = Infinity # disable warning
55
58
  @editor.setOptions
56
59
  autoScrollEditorIntoView: true
57
60
  minLines: 5
@@ -20,9 +20,9 @@
20
20
  # body_md: { type: 'markdown', label: 'Article', htmlFieldName: 'body_html' }
21
21
  #
22
22
  # Dependencies:
23
- #= require chr/vendor/marked
24
- #= require chr/vendor/ace
25
- #= require chr/vendor/mode-markdown
23
+ #= require vendor/marked
24
+ #= require vendor/ace
25
+ #= require vendor/mode-markdown
26
26
  #
27
27
  # -----------------------------------------------------------------------------
28
28
 
@@ -45,23 +45,28 @@ class @InputMarkdown extends InputString
45
45
  _update_inputs: ->
46
46
  md_source = @session.getValue()
47
47
  @$input.val(md_source)
48
+ @$input.trigger('change')
48
49
 
49
50
  if @$inputHtml
50
51
  html = marked(md_source)
51
52
  @$inputHtml.val(html)
53
+ @$inputHtml.trigger('change')
52
54
 
53
55
 
54
56
  # PUBLIC ================================================
55
57
 
56
58
  initialize: ->
59
+ @config.beforeInitialize?(this)
60
+
57
61
  @editor = ace.edit(@$editor.get(0))
58
- @session = @editor.getSession()
62
+ @editor.$blockScrolling = Infinity
59
63
 
64
+ @session = @editor.getSession()
60
65
  @session.setValue(@$input.val())
66
+ @session.setUseWrapMode(true)
61
67
  @session.setMode("ace/mode/markdown")
62
68
 
63
69
  # options: https://github.com/ajaxorg/ace/wiki/Configuring-Ace
64
- @editor.$blockScrolling = Infinity # disable warning
65
70
  @editor.setOptions
66
71
  autoScrollEditorIntoView: true
67
72
  minLines: 5
@@ -1,61 +1 @@
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
- plugins = [ 'fixedtoolbar' ]
33
- if Loft? then plugins.push('loft')
34
-
35
- redactor_options =
36
- focus: false
37
- imageFloatMargin: '20px'
38
- buttonSource: true
39
- pastePlainText: true
40
- plugins: plugins
41
- buttons: [ 'html', 'formatting', 'bold', 'italic', 'deleted', 'unorderedlist', 'orderedlist', 'link' ]
42
-
43
- @config.redactorOptions ?= {}
44
- $.extend(redactor_options, @config.redactorOptions)
45
-
46
- @$input.redactor(redactor_options)
47
-
48
- @$el.css('opacity', 1)
49
-
50
- @config.onInitialize?(this)
51
-
52
-
53
- updateValue: (@value) ->
54
- @$input.redactor('insert.set', @_safe_value())
55
-
56
-
57
- chr.formInputs['redactor'] = InputRedactor
58
-
59
-
60
-
61
-
1
+ #= require ./redactor/input-redactor
@@ -0,0 +1,53 @@
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 vendor/redactor.fixedtoolbar
16
+ #= require ./input-redactor_character
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
+ @config.beforeInitialize?(this)
33
+
34
+ @$input.redactor(@_redactor_options())
35
+
36
+ @$el.css('opacity', 1)
37
+
38
+ @config.onInitialize?(this)
39
+
40
+
41
+ updateValue: (@value) ->
42
+ @_trigger_change = false
43
+ @$input.redactor('code.set', @value)
44
+
45
+
46
+ include(InputRedactor, redactorCharacter)
47
+
48
+
49
+ chr.formInputs['redactor'] = InputRedactor
50
+
51
+
52
+
53
+
@@ -0,0 +1,83 @@
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
+ # REDACTOR CUSTOM VERSION
11
+ #= require ./input-redactor_images
12
+ # -----------------------------------------------------------------------------
13
+
14
+ # change default fast speed from 200 to 10 as it's used by redactor modals
15
+ # while closing
16
+ console.log ':: [redactor-character] change $.fx.speeds.fast from 200 to 10 ::'
17
+ $.fx.speeds.fast = 10
18
+
19
+ @redactorCharacter =
20
+
21
+ # PRIVATE ===============================================
22
+
23
+ # TODO: fixed toolbar disabled on mobile
24
+ _redactor_options: ->
25
+ @_trigger_change = true
26
+
27
+ @config.redactorOptions ?= {}
28
+
29
+ # workaround plugins & custom configuration to include loft
30
+ # and optional fixedtoolbar
31
+ plugins = @config.redactorOptions.plugins || []
32
+ delete @config.redactorOptions.plugins
33
+
34
+ if ! chr.isMobile()
35
+ plugins.push('fixedtoolbar')
36
+
37
+ if Loft?
38
+ plugins.push('loft')
39
+
40
+ config = @_get_default_config(plugins)
41
+
42
+ if chr.isMobile()
43
+ config.toolbarFixed = false
44
+ # config.toolbarFixedTopOffset = 40
45
+
46
+ $.extend(config, @config.redactorOptions)
47
+
48
+ return config
49
+
50
+
51
+ _get_default_config: (plugins) ->
52
+ focus: false
53
+ imageFloatMargin: '20px'
54
+ buttonSource: true
55
+ pastePlainText: true
56
+ scrollTarget: chr.module.view.$content
57
+ plugins: plugins
58
+ buttons: [ 'html',
59
+ 'formatting',
60
+ 'bold',
61
+ 'italic',
62
+ 'deleted',
63
+ 'unorderedlist',
64
+ 'orderedlist',
65
+ 'link' ]
66
+
67
+
68
+ # to have caching working we need to trigger 'change' event for textarea
69
+ # when content got changed in redactor, but skip this when updating value
70
+ # via `updateValue` method
71
+ changeCallback: =>
72
+ if @_trigger_change
73
+ @$input.trigger('change')
74
+ @_trigger_change = true
75
+
76
+
77
+ initCallback: ->
78
+ new RedactorImages(this)
79
+
80
+
81
+
82
+
83
+
@@ -0,0 +1,166 @@
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
+ # REDACTOR IMAGES
11
+ # -----------------------------------------------------------------------------
12
+
13
+ class @RedactorImages
14
+ constructor: (@redactor) ->
15
+
16
+ @redactor.opts.modal.imageEdit = @_modal_edit_image()
17
+ @redactor.image.update = ($image) => @update($image)
18
+ @redactor.image.showEdit = ($image) => @_show_edit($image)
19
+ @redactor.image.loadEditableControls = ($image) => @_load_editable_controls($image)
20
+
21
+
22
+ _modal_edit_image: ->
23
+ """<section id="redactor-modal-image-edit">
24
+ <label>Image Alternative Text</label>
25
+ <input type="text" id="redactor-image-title" />
26
+
27
+ <label class="redactor-image-position-option">Position</label>
28
+ <select class="redactor-image-position-option" id="redactor-image-align">
29
+ <option value="none">None</option>
30
+ <option value="left">Left</option>
31
+ <option value="center">Center</option>
32
+ <option value="right">Right</option>
33
+ </select>
34
+
35
+ <label class="redactor-image-link-option">Link URL</label>
36
+ <input type="text" id="redactor-image-link-url" class="redactor-image-link-option" />
37
+
38
+ <label class="redactor-image-link-option">Link Title</label>
39
+ <input type="text" id="redactor-image-link-title" class="redactor-image-link-option" />
40
+
41
+ <label class="redactor-image-link-option"><input type="checkbox" id="redactor-image-link-blank"> Open link in new tab</label>
42
+ </section>"""
43
+
44
+
45
+ update: ($image) ->
46
+ @redactor.image.hideResize()
47
+ @redactor.buffer.set()
48
+
49
+ $link = $image.closest('a')
50
+
51
+ $image.attr('alt', $('#redactor-image-title').val())
52
+
53
+ @redactor.image.setFloating($image)
54
+
55
+ # as link
56
+ link = $.trim($('#redactor-image-link-url').val())
57
+ title = $.trim($('#redactor-image-link-title').val())
58
+
59
+ if link != ''
60
+
61
+ target = if ( $('#redactor-image-link-blank').prop('checked') ) then true else false
62
+
63
+ if $link.size() == 0
64
+ a =$ "<a href='#{ link }' title='#{ title }'>#{ @redactor.utils.getOuterHtml($image) }</a>"
65
+
66
+ if target
67
+ a.attr('target', '_blank')
68
+
69
+ $image.replaceWith(a)
70
+
71
+ else
72
+ $link.attr('href', link)
73
+ $link.attr('title', title)
74
+
75
+ if target
76
+ $link.attr('target', '_blank')
77
+
78
+ else
79
+ $link.removeAttr('target')
80
+
81
+ else if $link.size() != 0
82
+ $link.replaceWith(@redactor.utils.getOuterHtml($image))
83
+
84
+ @redactor.modal.close()
85
+ @redactor.observe.images()
86
+ @redactor.code.sync()
87
+
88
+
89
+ _show_edit: ($image) ->
90
+ $link = $image.closest('a')
91
+
92
+ @redactor.image.hideResize()
93
+ @redactor.modal.load('imageEdit', @redactor.lang.get('edit'), 705)
94
+
95
+ @redactor.modal.createCancelButton()
96
+ @redactor.image.buttonDelete = @redactor.modal.createDeleteButton(@redactor.lang.get('_delete'))
97
+ @redactor.image.buttonSave = @redactor.modal.createActionButton(@redactor.lang.get('save'))
98
+
99
+ @redactor.image.buttonDelete.on 'click', $.proxy(( => @redactor.image.remove($image) ), @redactor)
100
+ @redactor.image.buttonSave.on 'click', $.proxy(( => @redactor.image.update($image) ), @redactor)
101
+
102
+ $('#redactor-image-title').val($image.attr('alt'))
103
+
104
+ if ! @redactor.opts.imageLink
105
+ $('.redactor-image-link-option').hide()
106
+
107
+ else
108
+ $redactorImageLinkUrl = $('#redactor-image-link-url')
109
+ $redactorImageLinkTitle = $('#redactor-image-link-title')
110
+
111
+ $redactorImageLinkUrl.attr('href', $image.attr('src'))
112
+
113
+ if $link.size() != 0
114
+ $redactorImageLinkUrl.val($link.attr('href'))
115
+ $redactorImageLinkTitle.val($link.attr('title'))
116
+
117
+ if $link.attr('target') == '_blank'
118
+ $('#redactor-image-link-blank').prop('checked', true)
119
+
120
+ if ! @redactor.opts.imagePosition
121
+ $('.redactor-image-position-option').hide()
122
+
123
+ else
124
+ floatValue = if ($image.css('display') == 'block' && $image.css('float') == 'none') then 'center' else $image.css('float')
125
+ $('#redactor-image-align').val(floatValue)
126
+
127
+ @redactor.modal.show()
128
+
129
+
130
+ # for some reason when image is a link, tooltip is shown with the image edit dialog,
131
+ # add e.stopPropagation() to skip tooltip callback
132
+ _load_editable_controls: ($image) ->
133
+ imageBox =$ '<span id="redactor-image-box" data-redactor="verified">'
134
+ imageBox.css('float', $image.css('float')).attr('contenteditable', false)
135
+
136
+ if $image[0].style.margin != 'auto'
137
+ imageBox.css
138
+ marginTop: $image[0].style.marginTop
139
+ marginBottom: $image[0].style.marginBottom
140
+ marginLeft: $image[0].style.marginLeft
141
+ marginRight: $image[0].style.marginRight
142
+
143
+ $image.css('margin', '')
144
+
145
+ else
146
+ imageBox.css({ 'display': 'block', 'margin': 'auto' })
147
+
148
+ $image.css('opacity', '.5').after(imageBox)
149
+
150
+ if @redactor.opts.imageEditable
151
+ # editter
152
+ @redactor.image.editter =$ "<span id='redactor-image-editter' data-redactor='verified'>Edit</span>"
153
+ @redactor.image.editter.attr('contenteditable', false)
154
+ @redactor.image.editter.on('click', $.proxy(( (e) => e.stopPropagation() ; @redactor.image.showEdit($image) ), @redactor))
155
+
156
+ imageBox.append(@redactor.image.editter)
157
+
158
+ # position correction
159
+ editerWidth = @redactor.image.editter.innerWidth()
160
+ @redactor.image.editter.css('margin-left', '-' + editerWidth/2 + 'px')
161
+
162
+ return @redactor.image.loadResizableControls($image, imageBox)
163
+
164
+
165
+
166
+