chr 0.3.5 → 0.4.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +2 -0
- data/.gitignore +6 -1
- data/.ruby-version +1 -0
- data/.travis.yml +18 -0
- data/README.md +4 -0
- data/Rakefile +17 -2
- data/app/assets/javascripts/chr.coffee +13 -26
- data/app/assets/javascripts/chr/{core/chr.coffee → chr.coffee} +4 -1
- data/app/assets/javascripts/chr/{core/chr_router.coffee → chr_router.coffee} +0 -0
- data/app/assets/javascripts/chr/{core/item.coffee → item.coffee} +2 -1
- data/app/assets/javascripts/chr/{core/list.coffee → list.coffee} +1 -1
- data/app/assets/javascripts/chr/{core/list_config.coffee → list_config.coffee} +0 -0
- data/app/assets/javascripts/chr/{core/list_pagination.coffee → list_pagination.coffee} +15 -4
- data/app/assets/javascripts/chr/{core/list_reorder.coffee → list_reorder.coffee} +0 -0
- data/app/assets/javascripts/chr/{core/list_search.coffee → list_search.coffee} +1 -1
- data/app/assets/javascripts/chr/{core/module.coffee → module.coffee} +0 -0
- data/app/assets/javascripts/chr/{core/utils.coffee → utils.coffee} +0 -0
- data/app/assets/javascripts/chr/{core/view.coffee → view.coffee} +21 -9
- data/app/assets/javascripts/chr/{core/view_local-storage.coffee → view_local-storage.coffee} +0 -0
- data/app/assets/javascripts/{chr/store/array-store.coffee → stores/array.coffee} +0 -0
- data/app/assets/javascripts/{chr/store/object-store.coffee → stores/object.coffee} +0 -0
- data/app/assets/javascripts/{chr/store/rails-array-store.coffee → stores/rails-array.coffee} +0 -0
- data/app/assets/javascripts/{chr/store → stores}/rails-form-object-parser.coffee +4 -1
- data/app/assets/javascripts/{chr/store/rails-object-store.coffee → stores/rails-object.coffee} +0 -0
- data/app/assets/javascripts/{chr/store/rest-array-store.coffee → stores/rest-array.coffee} +5 -2
- data/app/assets/javascripts/{chr/store/rest-object-store.coffee → stores/rest-object.coffee} +0 -0
- data/app/assets/stylesheets/{_chr.scss → chr.scss} +2 -7
- data/app/assets/stylesheets/chr/{_icons.scss → icons.scss} +0 -0
- data/app/assets/stylesheets/chr/{_main.scss → main.scss} +10 -3
- data/app/assets/stylesheets/chr/{_mixins.scss → mixins.scss} +0 -77
- data/app/assets/stylesheets/chr/{_settings.scss → settings.scss} +1 -1
- data/bin/chr +13 -0
- data/bin/rake +16 -0
- data/bin/setup +13 -0
- data/chr.gemspec +41 -21
- data/docs/tests.md +64 -0
- data/lib/chr.rb +10 -2
- data/lib/chr/app_builder.rb +385 -0
- data/lib/chr/generators/app_generator.rb +213 -0
- data/lib/chr/version.rb +3 -1
- data/lib/generators/chr/controller_generator.rb +18 -0
- data/templates/Gemfile.erb +38 -0
- data/templates/Procfile +1 -0
- data/templates/README.md.erb +45 -0
- data/templates/_analytics.html.erb +9 -0
- data/templates/_flashes.html.erb +7 -0
- data/templates/_javascript.html.erb +12 -0
- data/templates/application.coffee +2 -0
- data/templates/application.scss +1 -0
- data/templates/application.yml +6 -0
- data/templates/application_gitignore +14 -0
- data/templates/application_layout.html.erb.erb +29 -0
- data/templates/asset_sync.rb +28 -0
- data/templates/bin_setup.erb +36 -0
- data/templates/body_class_helper.rb +19 -0
- data/templates/bundler_audit.rake +12 -0
- data/templates/carrierwave.rb +23 -0
- data/templates/character_admin.coffee.erb +28 -0
- data/templates/character_admin.scss +3 -0
- data/templates/character_admin_index.html.erb +2 -0
- data/templates/character_admin_layout.html.erb +21 -0
- data/templates/character_base_controller.rb +16 -0
- data/templates/development_seeds.rb +12 -0
- data/templates/devise_overrides_passwords_controller.rb +10 -0
- data/templates/devise_overrides_passwords_edit.html.erb +30 -0
- data/templates/devise_overrides_passwords_new.html.erb +21 -0
- data/templates/devise_overrides_sessions_controller.rb +12 -0
- data/templates/devise_overrides_sessions_new.html.erb +31 -0
- data/templates/errors.rb +34 -0
- data/templates/json_encoding.rb +1 -0
- data/templates/newrelic.yml.erb +34 -0
- data/templates/puma.rb +18 -0
- data/templates/routes.rb +90 -0
- data/templates/sample.env +6 -0
- data/templates/secrets.yml +14 -0
- data/templates/smtp.rb +9 -0
- data/templates/staging.rb +5 -0
- data/test/factories/article_factory.rb +19 -0
- data/test/files/test.jpg +0 -0
- data/test/integration/article_fullsize_test.rb +33 -0
- data/test/integration/article_test.rb +33 -0
- data/test/integration/magazine_article_test.rb +33 -0
- data/test/integration/restricted_article_test.rb +33 -0
- data/test/integration/sport_article_test.rb +34 -0
- data/test/rails_app/Rakefile +6 -0
- data/test/rails_app/app/assets/javascripts/admin.coffee +137 -0
- data/test/rails_app/app/assets/javascripts/application.js +1 -0
- data/test/rails_app/app/assets/stylesheets/admin.scss +1 -0
- data/test/rails_app/app/assets/stylesheets/application.css +1 -0
- data/test/rails_app/app/controllers/admin/articles_controller.rb +7 -0
- data/test/rails_app/app/controllers/admin/base_controller.rb +8 -0
- data/test/rails_app/app/controllers/application_controller.rb +5 -0
- data/test/rails_app/app/helpers/application_helper.rb +2 -0
- data/test/rails_app/app/models/article.rb +46 -0
- data/test/rails_app/app/uploaders/article_image_uploader.rb +16 -0
- data/test/rails_app/app/views/admin/index.html.erb +4 -0
- data/test/rails_app/app/views/layouts/admin.html.erb +17 -0
- data/test/rails_app/app/views/layouts/application.html.erb +14 -0
- data/test/rails_app/bin/bundle +3 -0
- data/test/rails_app/bin/rails +8 -0
- data/test/rails_app/bin/rake +8 -0
- data/test/rails_app/bin/setup +29 -0
- data/test/rails_app/bin/spring +15 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/config/application.rb +36 -0
- data/test/rails_app/config/boot.rb +3 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +38 -0
- data/test/rails_app/config/environments/production.rb +76 -0
- data/test/rails_app/config/environments/test.rb +46 -0
- data/test/rails_app/config/initializers/assets.rb +12 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/carrierwave.rb +5 -0
- data/test/rails_app/config/initializers/cookies_serializer.rb +3 -0
- data/test/rails_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/rails_app/config/initializers/inflections.rb +16 -0
- data/test/rails_app/config/initializers/mime_types.rb +4 -0
- data/test/rails_app/config/initializers/session_store.rb +3 -0
- data/test/rails_app/config/initializers/wrap_parameters.rb +9 -0
- data/test/rails_app/config/locales/en.yml +23 -0
- data/test/rails_app/config/mongoid.yml +9 -0
- data/test/rails_app/config/routes.rb +8 -0
- data/test/rails_app/config/secrets.yml +22 -0
- data/test/rails_app/db/seeds.rb +7 -0
- data/test/rails_app/public/404.html +67 -0
- data/test/rails_app/public/422.html +67 -0
- data/test/rails_app/public/500.html +66 -0
- data/{app/assets/javascripts/form/input-date.coffee → test/rails_app/public/favicon.ico} +0 -0
- data/test/rails_app/public/robots.txt +5 -0
- data/test/support/character_front_end.rb +196 -0
- data/test/support/chr/item.rb +32 -0
- data/test/support/chr/list.rb +31 -0
- data/test/support/chr/list_pagination.rb +163 -0
- data/test/support/chr/list_reorder.rb +46 -0
- data/test/support/chr/list_search.rb +41 -0
- data/test/support/chr/view.rb +112 -0
- data/test/support/stores/array.rb +20 -0
- data/test/support/stores/rest-array.rb +34 -0
- data/test/test_helper.rb +68 -0
- metadata +373 -80
- data/Gruntfile.coffee +0 -101
- data/app/assets/javascripts/form/expandable-group.coffee +0 -30
- data/app/assets/javascripts/form/form.coffee +0 -221
- data/app/assets/javascripts/form/input-checkbox.coffee +0 -83
- data/app/assets/javascripts/form/input-color.coffee +0 -55
- data/app/assets/javascripts/form/input-file.coffee +0 -144
- data/app/assets/javascripts/form/input-form.coffee +0 -171
- data/app/assets/javascripts/form/input-form_reorder.coffee +0 -67
- data/app/assets/javascripts/form/input-hidden.coffee +0 -57
- data/app/assets/javascripts/form/input-list.coffee +0 -154
- data/app/assets/javascripts/form/input-list_reorder.coffee +0 -39
- data/app/assets/javascripts/form/input-list_typeahead.coffee +0 -55
- data/app/assets/javascripts/form/input-password.coffee +0 -32
- data/app/assets/javascripts/form/input-select.coffee +0 -84
- data/app/assets/javascripts/form/input-select2.coffee +0 -33
- data/app/assets/javascripts/form/input-string.coffee +0 -160
- data/app/assets/javascripts/form/input-text.coffee +0 -43
- data/app/assets/javascripts/input-html.coffee +0 -81
- data/app/assets/javascripts/input-markdown.coffee +0 -93
- data/app/assets/javascripts/input-redactor.coffee +0 -1
- data/app/assets/javascripts/redactor/input-redactor.coffee +0 -53
- data/app/assets/javascripts/redactor/input-redactor_character.coffee +0 -83
- data/app/assets/javascripts/redactor/input-redactor_images.coffee +0 -166
- data/app/assets/javascripts/vendor/ace.js +0 -18280
- data/app/assets/javascripts/vendor/jquery.scrollparent.js +0 -14
- data/app/assets/javascripts/vendor/jquery.textarea_autosize.js +0 -55
- data/app/assets/javascripts/vendor/jquery.typeahead.js +0 -1782
- data/app/assets/javascripts/vendor/marked.js +0 -1272
- data/app/assets/javascripts/vendor/mode-html.js +0 -2436
- data/app/assets/javascripts/vendor/mode-markdown.js +0 -2820
- data/app/assets/javascripts/vendor/redactor.fixedtoolbar.js +0 -107
- data/app/assets/javascripts/vendor/select2.js +0 -5274
- data/app/assets/stylesheets/_input-redactor.scss +0 -35
- data/app/assets/stylesheets/form/_expandable-group.scss +0 -16
- data/app/assets/stylesheets/form/_input-select2.scss +0 -94
- data/app/assets/stylesheets/form/_main.scss +0 -180
- data/app/assets/stylesheets/vendor/select2.css +0 -258
- data/bower.json +0 -38
- data/dist/chr.js +0 -5949
- data/dist/input-ace.js +0 -24946
- data/dist/input-redactor.js +0 -1
- data/lib/mongoid/character.rb +0 -30
- data/package.json +0 -10
@@ -1,81 +0,0 @@
|
|
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 vendor/ace
|
22
|
-
#= require 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
|
-
@$input.trigger('change')
|
42
|
-
|
43
|
-
|
44
|
-
# PUBLIC ================================================
|
45
|
-
|
46
|
-
initialize: ->
|
47
|
-
@config.beforeInitialize?(this)
|
48
|
-
|
49
|
-
@editor = ace.edit(@$editor.get(0))
|
50
|
-
@editor.$blockScrolling = Infinity
|
51
|
-
|
52
|
-
@session = @editor.getSession()
|
53
|
-
@session.setValue(@$input.val())
|
54
|
-
@session.setUseWrapMode(true)
|
55
|
-
@session.setMode("ace/mode/html")
|
56
|
-
|
57
|
-
# ace options: https://github.com/ajaxorg/ace/wiki/Configuring-Ace
|
58
|
-
@editor.setOptions
|
59
|
-
autoScrollEditorIntoView: true
|
60
|
-
minLines: 5
|
61
|
-
maxLines: Infinity
|
62
|
-
showLineNumbers: false
|
63
|
-
showGutter: false
|
64
|
-
highlightActiveLine: false
|
65
|
-
showPrintMargin: false
|
66
|
-
|
67
|
-
@session.on 'change', (e) => @_update_inputs()
|
68
|
-
|
69
|
-
@config.onInitialize?(this)
|
70
|
-
|
71
|
-
|
72
|
-
updateValue: (@value) ->
|
73
|
-
@editor.getSession().setValue(@value)
|
74
|
-
@$input.val(@value)
|
75
|
-
|
76
|
-
|
77
|
-
chr.formInputs['html'] = InputHtml
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
@@ -1,93 +0,0 @@
|
|
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 vendor/marked
|
24
|
-
#= require vendor/ace
|
25
|
-
#= require 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
|
-
@$input.trigger('change')
|
49
|
-
|
50
|
-
if @$inputHtml
|
51
|
-
html = marked(md_source)
|
52
|
-
@$inputHtml.val(html)
|
53
|
-
@$inputHtml.trigger('change')
|
54
|
-
|
55
|
-
|
56
|
-
# PUBLIC ================================================
|
57
|
-
|
58
|
-
initialize: ->
|
59
|
-
@config.beforeInitialize?(this)
|
60
|
-
|
61
|
-
@editor = ace.edit(@$editor.get(0))
|
62
|
-
@editor.$blockScrolling = Infinity
|
63
|
-
|
64
|
-
@session = @editor.getSession()
|
65
|
-
@session.setValue(@$input.val())
|
66
|
-
@session.setUseWrapMode(true)
|
67
|
-
@session.setMode("ace/mode/markdown")
|
68
|
-
|
69
|
-
# options: https://github.com/ajaxorg/ace/wiki/Configuring-Ace
|
70
|
-
@editor.setOptions
|
71
|
-
autoScrollEditorIntoView: true
|
72
|
-
minLines: 5
|
73
|
-
maxLines: Infinity
|
74
|
-
showLineNumbers: false
|
75
|
-
showGutter: false
|
76
|
-
highlightActiveLine: false
|
77
|
-
showPrintMargin: false
|
78
|
-
|
79
|
-
@session.on 'change', (e) => @_update_inputs()
|
80
|
-
|
81
|
-
@config.onInitialize?(this)
|
82
|
-
|
83
|
-
|
84
|
-
updateValue: (@value) ->
|
85
|
-
@session.setValue(@value)
|
86
|
-
@_update_inputs()
|
87
|
-
|
88
|
-
|
89
|
-
chr.formInputs['markdown'] = InputMarkdown
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
@@ -1 +0,0 @@
|
|
1
|
-
#= require ./redactor/input-redactor
|
@@ -1,53 +0,0 @@
|
|
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
|
-
|
@@ -1,83 +0,0 @@
|
|
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
|
-
|
@@ -1,166 +0,0 @@
|
|
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
|
-
|