scrivito_editors 0.71.2 → 0.90.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/scrivito_editors/binary_editor.js +41 -0
- data/app/assets/javascripts/scrivito_editors/date_editor.js +66 -0
- data/app/assets/javascripts/scrivito_editors/default_editor.js +43 -0
- data/app/assets/javascripts/scrivito_editors/deprecated_data_attrs.js +44 -0
- data/app/assets/javascripts/scrivito_editors/enum_editor.js +68 -0
- data/app/assets/javascripts/scrivito_editors/filter_context.js +54 -0
- data/app/assets/javascripts/scrivito_editors/helpers/file_dropzone.js +33 -0
- data/app/assets/javascripts/scrivito_editors/helpers/imgly_assets.js.erb +5 -0
- data/app/assets/javascripts/scrivito_editors/helpers/setup_binary_button_container.js +12 -0
- data/app/assets/javascripts/scrivito_editors/html_editor.js +15 -0
- data/app/assets/javascripts/scrivito_editors/image_drop_editor.js +52 -0
- data/app/assets/javascripts/scrivito_editors/image_editor.js +114 -0
- data/app/assets/javascripts/scrivito_editors/link_editor.js +88 -0
- data/app/assets/javascripts/scrivito_editors/linklist_editor.js +187 -0
- data/app/assets/javascripts/scrivito_editors/medium_editor.js +97 -0
- data/app/assets/javascripts/scrivito_editors/multienum_editor.js +48 -0
- data/app/assets/javascripts/scrivito_editors/permalink_editor.js +124 -0
- data/app/assets/javascripts/scrivito_editors/placeholder.js +37 -0
- data/app/assets/javascripts/scrivito_editors/redactor_editor.js +155 -0
- data/app/assets/javascripts/scrivito_editors/redactor_plugins/scrivito_editors_image_manager.js +41 -0
- data/app/assets/javascripts/scrivito_editors/redactor_plugins/scrivito_editors_link_manager.js +56 -0
- data/app/assets/javascripts/scrivito_editors/reference_editor.js +60 -0
- data/app/assets/javascripts/scrivito_editors/referencelist_editor.js +120 -0
- data/app/assets/javascripts/scrivito_editors/reload.js +14 -0
- data/app/assets/javascripts/scrivito_editors/slider_editor.js +62 -0
- data/app/assets/javascripts/scrivito_editors/string_editor.js +156 -0
- data/app/assets/javascripts/scrivito_editors/stringlist_editor.js +22 -0
- data/app/assets/javascripts/scrivito_editors.js +3 -0
- data/app/assets/stylesheets/scrivito_editors/editors/medium_editor.css +20 -0
- data/app/assets/stylesheets/scrivito_editors/editors/{html_editor.css → redactor_editor.css} +0 -0
- data/app/assets/stylesheets/scrivito_editors/editors/referencelist_editor.css +4 -0
- data/app/assets/stylesheets/scrivito_editors/placeholder.css +14 -3
- data/app/helpers/scrivito_editors/scrivito_tag_helper.rb +40 -135
- data/lib/scrivito_editors/engine.rb +0 -1
- data/vendor/assets/javascripts/medium-editor.js +6445 -0
- data/{app → vendor}/assets/javascripts/redactor.js +0 -0
- data/{app/assets/javascripts/scrivito_editors → vendor/assets/javascripts}/redactor_plugins/table.js +0 -0
- data/vendor/assets/stylesheets/medium-editor-themes/flat.css +58 -0
- data/vendor/assets/stylesheets/medium-editor.css +214 -0
- metadata +78 -56
- data/app/assets/javascripts/scrivito_editors/binary_editor.js.coffee +0 -25
- data/app/assets/javascripts/scrivito_editors/date_editor.js.coffee +0 -59
- data/app/assets/javascripts/scrivito_editors/enum_editor.js.coffee +0 -41
- data/app/assets/javascripts/scrivito_editors/filter_context.js.coffee +0 -26
- data/app/assets/javascripts/scrivito_editors/helpers/file_dropzone.js.coffee +0 -16
- data/app/assets/javascripts/scrivito_editors/helpers/setup_binary_button_container.js.coffee +0 -6
- data/app/assets/javascripts/scrivito_editors/html_editor.js.coffee +0 -138
- data/app/assets/javascripts/scrivito_editors/image_drop_editor.js.coffee +0 -19
- data/app/assets/javascripts/scrivito_editors/image_editor.js.coffee.erb +0 -96
- data/app/assets/javascripts/scrivito_editors/link_editor.js.coffee +0 -141
- data/app/assets/javascripts/scrivito_editors/linklist_editor.js.coffee +0 -197
- data/app/assets/javascripts/scrivito_editors/multienum_editor.js.coffee +0 -42
- data/app/assets/javascripts/scrivito_editors/permalink_editor.js.coffee +0 -111
- data/app/assets/javascripts/scrivito_editors/placeholder.js.coffee +0 -22
- data/app/assets/javascripts/scrivito_editors/redactor_plugins/scrivito_editors_image_manager.js.coffee +0 -22
- data/app/assets/javascripts/scrivito_editors/redactor_plugins/scrivito_editors_link_manager.js.coffee +0 -49
- data/app/assets/javascripts/scrivito_editors/reference_editor.js.coffee +0 -33
- data/app/assets/javascripts/scrivito_editors/referencelist_editor.js.coffee +0 -113
- data/app/assets/javascripts/scrivito_editors/reload.js.coffee +0 -12
- data/app/assets/javascripts/scrivito_editors/slider_editor.js.coffee +0 -41
- data/app/assets/javascripts/scrivito_editors/string_editor.js.coffee +0 -136
- data/app/assets/javascripts/scrivito_editors/stringlist_editor.js.coffee +0 -13
- data/app/helpers/scrivito_editors/cms_tag_helper.rb +0 -36
@@ -1,111 +0,0 @@
|
|
1
|
-
scrivito.on 'content', (content) ->
|
2
|
-
return unless scrivito.in_editable_view()
|
3
|
-
|
4
|
-
$(content).find('''
|
5
|
-
[data-scrivito-field-name="_permalink"]:not([data-editor]),
|
6
|
-
[data-editor~=permalink]
|
7
|
-
''').each -> create($(@))
|
8
|
-
|
9
|
-
create = (field) ->
|
10
|
-
editor = field.html(render(field.scrivito('content') || ''))
|
11
|
-
input = editor.find('input')
|
12
|
-
button = editor.find('a')
|
13
|
-
error = editor.find('div.scrivito_error')
|
14
|
-
clear = editor.find('.scrivito_clear')
|
15
|
-
|
16
|
-
input.on 'input', ->
|
17
|
-
permalink = input.val()
|
18
|
-
if permalink == field.scrivito('content')
|
19
|
-
hideError()
|
20
|
-
disableSaveButton()
|
21
|
-
else if permalink.match(/^([\w._-]+[\/\w._-]*)?$/)
|
22
|
-
hideError()
|
23
|
-
enableSaveButton()
|
24
|
-
else
|
25
|
-
showError(
|
26
|
-
'The permalink may only contain letters from A to Z, periods, hyphens, and underscores.')
|
27
|
-
disableSaveButton()
|
28
|
-
|
29
|
-
clear.on 'click', ->
|
30
|
-
input.val('')
|
31
|
-
hideError()
|
32
|
-
if !field.scrivito('content')
|
33
|
-
disableSaveButton()
|
34
|
-
else
|
35
|
-
enableSaveButton()
|
36
|
-
off
|
37
|
-
|
38
|
-
button.on 'click', ->
|
39
|
-
trySave()
|
40
|
-
off
|
41
|
-
|
42
|
-
editor.on 'keyup', (event) ->
|
43
|
-
switch event.keyCode
|
44
|
-
when 13 # Enter
|
45
|
-
trySave()
|
46
|
-
when 27 # Esc
|
47
|
-
input.val(field.scrivito('content'))
|
48
|
-
hideError()
|
49
|
-
disableSaveButton()
|
50
|
-
input.blur()
|
51
|
-
|
52
|
-
trySave = ->
|
53
|
-
return off if button.hasClass('scrivito_disabled')
|
54
|
-
|
55
|
-
showSaving()
|
56
|
-
|
57
|
-
permalink = input.val()
|
58
|
-
if permalink
|
59
|
-
scrivito.obj_where('_permalink', 'equals', permalink).size().then (total) ->
|
60
|
-
if total > 0
|
61
|
-
hideSaving()
|
62
|
-
showError('Permalink already taken.')
|
63
|
-
disableSaveButton()
|
64
|
-
input.focus()
|
65
|
-
else
|
66
|
-
save(permalink)
|
67
|
-
else
|
68
|
-
save(null)
|
69
|
-
|
70
|
-
disableSaveButton = ->
|
71
|
-
button.addClass('scrivito_disabled')
|
72
|
-
|
73
|
-
enableSaveButton = ->
|
74
|
-
button.removeClass('scrivito_disabled scrivito_saving')
|
75
|
-
|
76
|
-
showError = (message) ->
|
77
|
-
disableSaveButton()
|
78
|
-
input.addClass('scrivito_error')
|
79
|
-
error.text(message)
|
80
|
-
error.show()
|
81
|
-
|
82
|
-
hideError = ->
|
83
|
-
input.removeClass('scrivito_error')
|
84
|
-
error.hide()
|
85
|
-
|
86
|
-
showSaving = ->
|
87
|
-
input.attr('disabled', 'disabled')
|
88
|
-
disableSaveButton()
|
89
|
-
button.addClass('scrivito_saving')
|
90
|
-
button.find('span').text('Saving...')
|
91
|
-
|
92
|
-
hideSaving = ->
|
93
|
-
input.removeAttr('disabled')
|
94
|
-
enableSaveButton()
|
95
|
-
button.find('span').text('Save')
|
96
|
-
|
97
|
-
save = (permalink) ->
|
98
|
-
field.scrivito('save', permalink).then ->
|
99
|
-
create(field)
|
100
|
-
|
101
|
-
render = (content) ->
|
102
|
-
"""
|
103
|
-
<div class="scrivito_permalink_editor">
|
104
|
-
<input type="text" value="#{content}" />
|
105
|
-
<span class="scrivito_clear"></span>
|
106
|
-
<a href="#" class="scrivito_editing_button scrivito_disabled">
|
107
|
-
<span>Save</span>
|
108
|
-
</a>
|
109
|
-
<div class="scrivito_error"></div>
|
110
|
-
</div>
|
111
|
-
"""
|
@@ -1,22 +0,0 @@
|
|
1
|
-
$ ->
|
2
|
-
# Display a placeholder for empty CMS attributes. The placeholder can be overwritten by
|
3
|
-
# defining a +data-placeholder+ HTML attribute on the DOM element generated by +scrivito_tag+.
|
4
|
-
#
|
5
|
-
# For example:
|
6
|
-
# scrivito_tag(:div, @obj, :my_attribute, data: { placeholder: 'My custom placeholder text.' })
|
7
|
-
addPlaceholder = ->
|
8
|
-
cmsFields = $('[data-scrivito-field-type]')
|
9
|
-
.not('[data-scrivito-field-type=widgetlist]')
|
10
|
-
.not('[data-scrivito-field-type$=enum]:not([data-values])')
|
11
|
-
|
12
|
-
cmsFields.each ->
|
13
|
-
cmsField = $(@)
|
14
|
-
fieldName = cmsField.attr('data-scrivito-field-name')
|
15
|
-
defaultPlaceholder = 'Click to edit the "' + fieldName + '" attribute ...'
|
16
|
-
placeholder = cmsField.attr('data-placeholder') || defaultPlaceholder
|
17
|
-
|
18
|
-
cmsField.attr('data-placeholder', placeholder)
|
19
|
-
|
20
|
-
scrivito.on 'content', ->
|
21
|
-
if scrivito.in_editable_view()
|
22
|
-
addPlaceholder()
|
@@ -1,22 +0,0 @@
|
|
1
|
-
@RedactorPlugins ?= {}
|
2
|
-
|
3
|
-
$ ->
|
4
|
-
RedactorPlugins.scrivito_editors_image_manager = -> self =
|
5
|
-
init: ->
|
6
|
-
@modal.addCallback 'image', self.browse
|
7
|
-
|
8
|
-
browse: ->
|
9
|
-
filterContext = $.extend {_image: true}, @$element.data('filterContext')
|
10
|
-
|
11
|
-
scrivito.content_browser.open
|
12
|
-
filter: @$element.data('filter')
|
13
|
-
filter_context: filterContext
|
14
|
-
selection_mode: 'single'
|
15
|
-
.done (selection) =>
|
16
|
-
id = selection[0]
|
17
|
-
self.insert id if id?
|
18
|
-
.always =>
|
19
|
-
@modal.close()
|
20
|
-
|
21
|
-
insert: (id) ->
|
22
|
-
@image.insert "<img src='/#{id}'>"
|
@@ -1,49 +0,0 @@
|
|
1
|
-
@RedactorPlugins ?= {}
|
2
|
-
|
3
|
-
$ ->
|
4
|
-
RedactorPlugins.scrivito_editors_link_manager = -> self =
|
5
|
-
init: ->
|
6
|
-
@modal.addTemplate 'scrivito_link_manager_browse', self.browseButtonHtml
|
7
|
-
@modal.addTemplate 'scrivito_link_manager_url', '/$id'
|
8
|
-
@modal.addCallback 'imageEdit', self.addBrowseToModal
|
9
|
-
@modal.addCallback 'link', self.addBrowseToModal
|
10
|
-
|
11
|
-
browseButtonHtml: """
|
12
|
-
<button class="editing-button editing-green">
|
13
|
-
<i class="editing-icon editing-icon-search"></i>
|
14
|
-
Browse
|
15
|
-
</button>
|
16
|
-
"""
|
17
|
-
|
18
|
-
urlInput: ->
|
19
|
-
@modal.getModal().find '#redactor-link-url, #redactor-image-link'
|
20
|
-
|
21
|
-
addBrowseToModal: ->
|
22
|
-
self.urlInput()
|
23
|
-
.wrap '<div id="scrivito-link-manager-url"></div>'
|
24
|
-
.after @modal.getTemplate 'scrivito_link_manager_browse'
|
25
|
-
.siblings 'button'
|
26
|
-
.on 'click', self.browse
|
27
|
-
|
28
|
-
browse: ->
|
29
|
-
scrivito.content_browser.open
|
30
|
-
filter: @$element.data('filter')
|
31
|
-
filter_context: @$element.data('filterContext')
|
32
|
-
selection: self.getObjIds()
|
33
|
-
selection_mode: 'single'
|
34
|
-
.done (selection) =>
|
35
|
-
id = selection[0]
|
36
|
-
self.setObjId id if id?
|
37
|
-
|
38
|
-
getObjIds: ->
|
39
|
-
matches = self.urlInput()
|
40
|
-
.val()
|
41
|
-
.match(/[\/:]([a-f0-9]{16})\b/)
|
42
|
-
if matches? then [matches[1]] else []
|
43
|
-
|
44
|
-
setObjId: (id) ->
|
45
|
-
self.urlInput()
|
46
|
-
.val self.toUrl id
|
47
|
-
|
48
|
-
toUrl: (id) ->
|
49
|
-
@modal.getTemplate('scrivito_link_manager_url').replace("$id", id)
|
@@ -1,33 +0,0 @@
|
|
1
|
-
$ ->
|
2
|
-
# Integrates a content browser based editor for reference CMS attributes.
|
3
|
-
|
4
|
-
scrivito.on 'load', ->
|
5
|
-
if scrivito.in_editable_view()
|
6
|
-
$('body').on 'click', '[data-scrivito-field-type="reference"]:not([data-editor]), [data-editor~="reference"]', (event) ->
|
7
|
-
event.preventDefault()
|
8
|
-
|
9
|
-
cmsField = $(event.currentTarget)
|
10
|
-
selected = [cmsField.scrivito('content')].filter (element) -> element
|
11
|
-
filters = cmsField.data('filters')
|
12
|
-
filterContext = $.extend {_image: cmsField.is('img')}, cmsField.data('filterContext')
|
13
|
-
|
14
|
-
# Open content browser with current reference selected.
|
15
|
-
scrivito.content_browser.open
|
16
|
-
filters: filters
|
17
|
-
filter_context: filterContext
|
18
|
-
selection: selected
|
19
|
-
selection_mode: 'single'
|
20
|
-
|
21
|
-
.done (selection) =>
|
22
|
-
onContentBrowserSave(selection, cmsField)
|
23
|
-
|
24
|
-
# Save single reference when content browser calls "save".
|
25
|
-
onContentBrowserSave = (selection, cmsField) ->
|
26
|
-
value = selection[0] || null
|
27
|
-
|
28
|
-
cmsField.scrivito('save', value)
|
29
|
-
.done ->
|
30
|
-
cmsField.trigger('save.scrivito_editors')
|
31
|
-
cmsField.scrivito('reload')
|
32
|
-
|
33
|
-
true
|
@@ -1,113 +0,0 @@
|
|
1
|
-
$ ->
|
2
|
-
# An editor for CMS referencelist attributes.
|
3
|
-
|
4
|
-
# Creates the DOM for one reference element of the referencelist and substitutes the
|
5
|
-
# name and id attribute.
|
6
|
-
itemTemplate = ->
|
7
|
-
$("<div class=\"actions\">
|
8
|
-
<a href=\"#\" class=\"editing-button editing-red delete\">
|
9
|
-
<i class=\"editing-icon editing-icon-trash\" />
|
10
|
-
</a>
|
11
|
-
</div>")
|
12
|
-
|
13
|
-
contentBrowserButtonTemplate = ->
|
14
|
-
icon = $('<i></i>')
|
15
|
-
.addClass('editing-icon')
|
16
|
-
.addClass('editing-icon-plus')
|
17
|
-
|
18
|
-
button = $('<button></button>')
|
19
|
-
.addClass('editing-button')
|
20
|
-
.addClass('editing-green')
|
21
|
-
.addClass('content-browser-open')
|
22
|
-
.html(icon)
|
23
|
-
|
24
|
-
button
|
25
|
-
|
26
|
-
# Returns the closest referencelist DOM element.
|
27
|
-
getCmsField = (element) ->
|
28
|
-
element.closest('[data-scrivito-field-type=referencelist]')
|
29
|
-
|
30
|
-
# Saves the referencelist to the CMS when changed and stores the last successfully saved value.
|
31
|
-
save = (ids, cmsField, reload = true) ->
|
32
|
-
lastSaved = getLastSaved(cmsField)
|
33
|
-
|
34
|
-
unless JSON.stringify(ids) == JSON.stringify(lastSaved)
|
35
|
-
cmsField.scrivito('save', ids)
|
36
|
-
.done ->
|
37
|
-
storeLastSaved(cmsField, ids)
|
38
|
-
cmsField.trigger('save.scrivito_editors')
|
39
|
-
cmsField.scrivito('reload') if reload
|
40
|
-
|
41
|
-
# Run when clicking the content browser button.
|
42
|
-
onContentBrowserOpen = (event) ->
|
43
|
-
event.preventDefault()
|
44
|
-
|
45
|
-
cmsField = getCmsField($(event.currentTarget))
|
46
|
-
filters = cmsField.data('filters')
|
47
|
-
filterContext = cmsField.data('filterContext')
|
48
|
-
|
49
|
-
scrivito.content_browser.open
|
50
|
-
filters: filters
|
51
|
-
filter_context: filterContext
|
52
|
-
.done (selection) =>
|
53
|
-
ids = getIds(cmsField).concat(selection)
|
54
|
-
save(ids, cmsField)
|
55
|
-
|
56
|
-
# Collects all reference ids for a given referencelist.
|
57
|
-
getIds = (cmsField) ->
|
58
|
-
items = $(cmsField).find('[data-id]')
|
59
|
-
|
60
|
-
value =
|
61
|
-
for item in items
|
62
|
-
$(item).data('id')
|
63
|
-
|
64
|
-
# Removes a single reference from the referencelist.
|
65
|
-
remove = (event) ->
|
66
|
-
event.preventDefault()
|
67
|
-
|
68
|
-
target = $(event.currentTarget)
|
69
|
-
cmsField = getCmsField(target)
|
70
|
-
|
71
|
-
target.closest('li').remove()
|
72
|
-
|
73
|
-
ids = getIds(cmsField)
|
74
|
-
save(ids, cmsField, false)
|
75
|
-
|
76
|
-
# Turns the server side generated referencelist data into the reference editor using a template.
|
77
|
-
transform = (elements) ->
|
78
|
-
elements.append(contentBrowserButtonTemplate)
|
79
|
-
|
80
|
-
items = elements.find('li')
|
81
|
-
|
82
|
-
for item in items
|
83
|
-
$(item).append(itemTemplate)
|
84
|
-
|
85
|
-
# Returns the last saved value.
|
86
|
-
getLastSaved = (cmsField) ->
|
87
|
-
$(cmsField).data('last-saved')
|
88
|
-
|
89
|
-
# Stores a given value as last saved.
|
90
|
-
storeLastSaved = (cmsField, value) ->
|
91
|
-
$(cmsField).data('last-saved', value)
|
92
|
-
|
93
|
-
# Initialize referencelist editor and setup event callbacks.
|
94
|
-
scrivito.on 'content', (root) ->
|
95
|
-
if scrivito.in_editable_view()
|
96
|
-
elements = $(root).find('[data-scrivito-field-type="referencelist"]:not([data-editor]), [data-editor~="referencelist"]')
|
97
|
-
|
98
|
-
if elements.length
|
99
|
-
transform(elements)
|
100
|
-
|
101
|
-
for element in elements
|
102
|
-
ids = getIds(element)
|
103
|
-
storeLastSaved(element, ids)
|
104
|
-
|
105
|
-
elements.on 'click', 'li a.delete', remove
|
106
|
-
elements.on 'click', 'button.content-browser-open', onContentBrowserOpen
|
107
|
-
|
108
|
-
elements.find('ul').sortable
|
109
|
-
update: (event) ->
|
110
|
-
cmsField = getCmsField($(event.target))
|
111
|
-
ids = getIds(cmsField)
|
112
|
-
|
113
|
-
save(ids, cmsField)
|
@@ -1,12 +0,0 @@
|
|
1
|
-
$ ->
|
2
|
-
# Enable `data-reload=true` for automatic reload when an editor is done.
|
3
|
-
#
|
4
|
-
# For example:
|
5
|
-
# scrivito_tag(:div, @obj, :my_attribute, data: { reload: true })
|
6
|
-
|
7
|
-
selector = '[data-scrivito-field-type][data-reload=true]'
|
8
|
-
|
9
|
-
scrivito.on 'content', ->
|
10
|
-
if scrivito.in_editable_view()
|
11
|
-
$(':root').on 'scrivito_editors:blur', selector, (event) ->
|
12
|
-
$(this).scrivito("reload")
|
@@ -1,41 +0,0 @@
|
|
1
|
-
$ ->
|
2
|
-
# Slider for integer values stored in a string CMS attribute.
|
3
|
-
|
4
|
-
scrivito.on 'load', ->
|
5
|
-
if scrivito.in_editable_view()
|
6
|
-
template = ->
|
7
|
-
$('<div></div>')
|
8
|
-
|
9
|
-
onStop = (event, ui) ->
|
10
|
-
cmsField = $(@).data('cmsField')
|
11
|
-
content = ui.value
|
12
|
-
cmsField.scrivito('save', content).done ->
|
13
|
-
cmsField.trigger('save.scrivito_editors')
|
14
|
-
cmsField.trigger('scrivito_editors:blur')
|
15
|
-
|
16
|
-
onSlide = (event, ui) ->
|
17
|
-
cmsField = $(@).data('cmsField')
|
18
|
-
content = ui.value
|
19
|
-
cmsField.text(ui.value)
|
20
|
-
|
21
|
-
$('body').on 'click', '[data-editor~="slider"]:not(.active)', (event) ->
|
22
|
-
cmsField = $(event.currentTarget)
|
23
|
-
content = cmsField.scrivito('content')
|
24
|
-
min = cmsField.attr('data-min') || 1
|
25
|
-
max = cmsField.attr('data-max') || 10
|
26
|
-
step = cmsField.attr('data-step') || 1
|
27
|
-
|
28
|
-
cmsField.addClass('active')
|
29
|
-
|
30
|
-
template()
|
31
|
-
.data('cmsField', cmsField)
|
32
|
-
.insertAfter(cmsField)
|
33
|
-
.slider(
|
34
|
-
min: parseInt(min)
|
35
|
-
max: parseInt(max)
|
36
|
-
step: parseInt(step)
|
37
|
-
value: content
|
38
|
-
range: 'min'
|
39
|
-
stop: onStop
|
40
|
-
slide: onSlide
|
41
|
-
)
|
@@ -1,136 +0,0 @@
|
|
1
|
-
$ ->
|
2
|
-
# This file integrates contenteditable for string attributes.
|
3
|
-
|
4
|
-
onKey = (event) ->
|
5
|
-
cmsField = $(event.currentTarget)
|
6
|
-
key = event.keyCode || event.which
|
7
|
-
|
8
|
-
switch key
|
9
|
-
when 13 # Enter
|
10
|
-
if !isNewlineAllowed(cmsField)
|
11
|
-
event.preventDefault()
|
12
|
-
cmsField.blur()
|
13
|
-
when 27 # Esc
|
14
|
-
event.stopPropagation()
|
15
|
-
cmsField.blur()
|
16
|
-
|
17
|
-
onInput = (event) ->
|
18
|
-
cmsField = $(event.currentTarget)
|
19
|
-
save(cmsField)
|
20
|
-
|
21
|
-
onFocus = (event) ->
|
22
|
-
cmsField = $(event.currentTarget)
|
23
|
-
prepareForEditing(cmsField)
|
24
|
-
|
25
|
-
onBlur = (event) ->
|
26
|
-
cmsField = $(event.currentTarget)
|
27
|
-
|
28
|
-
save(cmsField).done ->
|
29
|
-
cmsField.trigger('scrivito_editors:blur')
|
30
|
-
|
31
|
-
finishEditing(cmsField)
|
32
|
-
|
33
|
-
save = (cmsField) ->
|
34
|
-
content = getCurrentContent(cmsField)
|
35
|
-
|
36
|
-
# Save only if the content has changed.
|
37
|
-
if content != cmsField.scrivito('content')
|
38
|
-
cmsField.scrivito('save', content).done ->
|
39
|
-
cmsField.trigger('save.scrivito_editors')
|
40
|
-
else
|
41
|
-
$.Deferred().resolve()
|
42
|
-
|
43
|
-
getCurrentContent = (cmsField) ->
|
44
|
-
cleanUp(cmsField)
|
45
|
-
|
46
|
-
clone = cmsFieldAndPastedContent(cmsField).clone()
|
47
|
-
# Starting with empty element, entering 3 lines, per browser:
|
48
|
-
# Chrome: 1<div>2</div><div>3</div>
|
49
|
-
# IE: <p>1</p><p>2</p><p>3</p>
|
50
|
-
# Firefox: 1<br>2<br>3<br>
|
51
|
-
clone.find('div:not(:has(br)),p:not(:first)').before('\n')
|
52
|
-
clone.find('br').replaceWith('\n')
|
53
|
-
content = clone.text()
|
54
|
-
clone.remove()
|
55
|
-
content
|
56
|
-
|
57
|
-
cleanUp = (cmsField) ->
|
58
|
-
siblings = cmsFieldAndPastedContent(cmsField)
|
59
|
-
pasted = siblings.not(cmsField)
|
60
|
-
if pasted.length > 0
|
61
|
-
pasted.remove()
|
62
|
-
cmsField.text(siblings.text())
|
63
|
-
|
64
|
-
cmsFieldAndPastedContent = (cmsField) ->
|
65
|
-
siblingsBefore = cmsField.data('scrivito_editors_siblings_before_edit')
|
66
|
-
siblings = cmsField.siblings()
|
67
|
-
needsReset = !siblingsBefore || siblings.filter(siblingsBefore).length < siblingsBefore.length
|
68
|
-
if needsReset
|
69
|
-
cmsField.data('scrivito_editors_siblings_before_edit', siblings)
|
70
|
-
else
|
71
|
-
cmsField.siblings().addBack().not(siblingsBefore)
|
72
|
-
|
73
|
-
_deprecationLogged = false
|
74
|
-
|
75
|
-
isNewlineAllowed = (cmsField) ->
|
76
|
-
if cmsField.data('editor') == 'text'
|
77
|
-
if !_deprecationLogged
|
78
|
-
console.warn 'Scrivito editors: data-editor="text" is deprecated, please use data-editor="string" data-newlines="true" instead.'
|
79
|
-
_deprecationLogged = true
|
80
|
-
return true
|
81
|
-
|
82
|
-
return true if cmsField.data('newlines') == true
|
83
|
-
return false if cmsField.data('newlines') == false
|
84
|
-
cmsField.css('white-space').match /pre/
|
85
|
-
|
86
|
-
prepareForEditing = (cmsField) ->
|
87
|
-
if isNewlineAllowed(cmsField) && !cmsField.data('scrivito_editors_prepared_for_editing')
|
88
|
-
cmsField.data('scrivito_editors_prepared_for_editing', true)
|
89
|
-
html = cmsField.html()
|
90
|
-
htmlNl2Br = html.replace(/\n/g, '<br />')
|
91
|
-
if html != htmlNl2Br
|
92
|
-
cmsField.html(htmlNl2Br)
|
93
|
-
|
94
|
-
finishEditing = (cmsField) ->
|
95
|
-
cmsField.data('scrivito_editors_prepared_for_editing', false)
|
96
|
-
cmsField.text(cmsField.scrivito('content'))
|
97
|
-
|
98
|
-
DOUBLE_CLICK_MS = 300
|
99
|
-
|
100
|
-
editSelector = '''
|
101
|
-
[data-scrivito-field-type="string"]:not([data-editor]):not([data-scrivito-field-name=_permalink]),
|
102
|
-
[data-editor~="string"],
|
103
|
-
[data-editor~="text"]
|
104
|
-
'''
|
105
|
-
|
106
|
-
initialize = ->
|
107
|
-
$(':root').on 'mouseenter', editSelector, (event) ->
|
108
|
-
cmsField = $(@)
|
109
|
-
|
110
|
-
unless cmsField.attr('contenteditable')?
|
111
|
-
cmsField
|
112
|
-
.attr('contenteditable', true)
|
113
|
-
.blur(onBlur)
|
114
|
-
.focus(onFocus)
|
115
|
-
.keypress(onKey)
|
116
|
-
.keyup(onKey)
|
117
|
-
|
118
|
-
if cmsField.attr('data-autosave') != 'false'
|
119
|
-
cmsField.on('cut input keypress keyup paste', onInput)
|
120
|
-
|
121
|
-
prepareForEditing(cmsField)
|
122
|
-
|
123
|
-
$(':root').on 'click', editSelector, (event) ->
|
124
|
-
cmsField = $(@)
|
125
|
-
|
126
|
-
cmsField.attr('contenteditable', true)
|
127
|
-
cleanUp(cmsField)
|
128
|
-
|
129
|
-
# Prevent editable link strings from being opened on click, but allow an enforcing double click
|
130
|
-
unless event.timeStamp - cmsField.data('scrivito_editors_last_click') < DOUBLE_CLICK_MS
|
131
|
-
event.preventDefault()
|
132
|
-
cmsField.data('scrivito_editors_last_click', event.timeStamp)
|
133
|
-
|
134
|
-
scrivito.on 'load', ->
|
135
|
-
if scrivito.in_editable_view()
|
136
|
-
initialize()
|
@@ -1,13 +0,0 @@
|
|
1
|
-
#= require jquery.caret
|
2
|
-
#= require jquery.tag-editor
|
3
|
-
|
4
|
-
scrivito.on 'content', (content) ->
|
5
|
-
if scrivito.in_editable_view()
|
6
|
-
$(content).find('''
|
7
|
-
[data-scrivito-field-type=stringlist]:not([data-editor]),
|
8
|
-
[data-editor~=stringlist]
|
9
|
-
''').each ->
|
10
|
-
field = $(this)
|
11
|
-
field.tagEditor
|
12
|
-
initialTags: field.scrivito('content')
|
13
|
-
onChange: (field, editor, tags) -> field.scrivito('save', tags)
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module ScrivitoEditors
|
2
|
-
# @deprecated Please use ScrivitoEditors::ScrivitoTagHelper
|
3
|
-
module CmsTagHelper
|
4
|
-
|
5
|
-
def cms_edit_enum(object, attribute_name, options = {})
|
6
|
-
_cms_edit_deprecated __method__
|
7
|
-
end
|
8
|
-
|
9
|
-
def cms_edit_multienum(object, attribute_name, options = {})
|
10
|
-
_cms_edit_deprecated __method__
|
11
|
-
end
|
12
|
-
|
13
|
-
def cms_edit_reference(object, attribute_name, options = {})
|
14
|
-
_cms_edit_deprecated __method__
|
15
|
-
end
|
16
|
-
|
17
|
-
def cms_edit_referencelist(object, attribute_name, options = {})
|
18
|
-
_cms_edit_deprecated __method__
|
19
|
-
end
|
20
|
-
|
21
|
-
def cms_edit_linklist(object, attribute_name, options = {})
|
22
|
-
_cms_edit_deprecated __method__
|
23
|
-
end
|
24
|
-
|
25
|
-
def cms_edit_link(object, attribute_name, options = {})
|
26
|
-
_cms_edit_deprecated __method__
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def _cms_edit_deprecated(method)
|
32
|
-
raise "The helper method `#{method}' has been removed.\n" +
|
33
|
-
"Please use `#{method.to_s.sub("cms", "scrivito")}' instead."
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|