scrivito_editors 0.40.0 → 0.41.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/app/assets/javascripts/scrivito_editors/binary_editor.js.coffee +22 -49
- data/app/assets/javascripts/scrivito_editors/helpers/file_dropzone.js.coffee +10 -0
- data/app/assets/javascripts/scrivito_editors/image_editor.js.coffee +21 -37
- data/app/assets/javascripts/scrivito_editors/link_editor.js.coffee +17 -6
- data/app/assets/javascripts/scrivito_editors/linklist_editor.js.coffee +15 -3
- data/app/assets/javascripts/scrivito_editors_core.js +9 -1
- data/app/helpers/scrivito_editors/scrivito_tag_helper.rb +1 -1
- metadata +7 -7
- data/app/assets/javascripts/scrivito_editors/helpers/file_drop_zone.js.coffee +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67f5aedc7181ead6c2782fae77773a56dfa8ff61
|
4
|
+
data.tar.gz: 162b00e6981d66cec5e975f39df882c00a57ce55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3543ba8d15cd33d894b30aa74074bdb4581c025d81ce6ae5ba46092bdd2ba6bbe7d0dff1d30a9618864cfc7ec1e33c768aa7df21e90ec361e8994962c2951b03
|
7
|
+
data.tar.gz: 91c45bf04573c1650313d3bcd93b6934649cd33d9314efe8c0595bef8294908081940378ebb465b20e049f34cd0e98a0edc436874667baa9493c74d606e5e9f8
|
data/CHANGELOG.md
CHANGED
@@ -1,49 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
add_delete_to_binary = (binary_element) ->
|
24
|
-
if $(binary_element).scrivito('content')
|
25
|
-
container = binary_field_container(binary_element)
|
26
|
-
|
27
|
-
if $(container).find('delete-binary').length == 0
|
28
|
-
delete_icon = $(
|
29
|
-
'<a href="#" class="delete-binary editing-button editing-red delete">' +
|
30
|
-
'<i class="editing-icon editing-icon-trash" /></a>'
|
31
|
-
)
|
32
|
-
|
33
|
-
delete_icon.click (event) ->
|
34
|
-
event.preventDefault()
|
35
|
-
delete_binary(binary_element)
|
36
|
-
|
37
|
-
$(container).prepend(delete_icon)
|
38
|
-
|
39
|
-
scrivito.on 'content', (content_root) ->
|
40
|
-
if scrivito.in_editable_view()
|
41
|
-
binary_elements = $(content_root).find(
|
42
|
-
"#{selector}[data-scrivito-editors-allow-delete]")
|
43
|
-
|
44
|
-
for binary_element in binary_elements
|
45
|
-
add_delete_to_binary(binary_element)
|
46
|
-
|
47
|
-
scrivito.on 'load', ->
|
48
|
-
if scrivito.in_editable_view()
|
49
|
-
scrivito.editors._file_drop_zone(selector, handle_file_upload, status_indicator_class)
|
1
|
+
scrivito.on 'content', (content) ->
|
2
|
+
return unless scrivito.in_editable_view()
|
3
|
+
fields = $(content).find('[data-scrivito-field-type=binary]:not([data-editor])')
|
4
|
+
scrivito.editors._file_dropzone fields,
|
5
|
+
(el, file) -> el.scrivito('save', file).then(-> el.scrivito('reload')),
|
6
|
+
'image-editor-dragover'
|
7
|
+
fields.filter('[data-scrivito-editors-allow-delete]').each -> setup_delete_btn $(this)
|
8
|
+
|
9
|
+
setup_delete_btn = (el) ->
|
10
|
+
return unless el.scrivito('content')
|
11
|
+
container = if el.prop('tagName') is 'IMG'
|
12
|
+
css_class = 'scrivito-editor-image-container'
|
13
|
+
el.wrap("<div class=#{css_class}></div>") unless el.parent(".#{css_class}").length
|
14
|
+
el.parent(".#{css_class}")
|
15
|
+
else
|
16
|
+
el
|
17
|
+
|
18
|
+
return if container.find('.delete-binary').length
|
19
|
+
$("<a href=# class='delete-binary editing-button editing-red delete'>
|
20
|
+
<i class='editing-icon editing-icon-trash'></i></a>")
|
21
|
+
.prependTo(container)
|
22
|
+
.click -> el.scrivito('save', null).then(-> el.scrivito('reload')) and off
|
@@ -0,0 +1,10 @@
|
|
1
|
+
scrivito.editors._file_dropzone = (fields, callback) -> fields.each(-> setup $(this), callback)
|
2
|
+
setup = (el, callback) ->
|
3
|
+
field = el.closest('[data-scrivito-field-name]')
|
4
|
+
el.on 'dragenter', -> field.addClass('image-editor-dragover') and off
|
5
|
+
el.on 'dragleave', -> field.removeClass('image-editor-dragover') and off
|
6
|
+
el.on 'drop', (e) ->
|
7
|
+
field.removeClass 'image-editor-dragover'
|
8
|
+
if (files = e.originalEvent.dataTransfer?.files)?.length is 1
|
9
|
+
callback field, files[0]
|
10
|
+
off
|
@@ -1,37 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
path = '_resources/' + Math.floor(Math.random() * 1000) + '/' + name
|
23
|
-
|
24
|
-
scrivito.create_obj
|
25
|
-
blob: file
|
26
|
-
_path: path
|
27
|
-
_obj_class: 'Image'
|
28
|
-
|
29
|
-
# Integrates an image drag & drop editor.
|
30
|
-
scrivito.on 'load', ->
|
31
|
-
if scrivito.in_editable_view()
|
32
|
-
# Activate the image editor for all supported field types.
|
33
|
-
activateForFieldType('linklist')
|
34
|
-
activateForFieldType('reference')
|
35
|
-
|
36
|
-
# Activate the image editor if it is explicitely selected.
|
37
|
-
scrivito.editors._file_drop_zone('[data-editor~="image"]', save,statusIndicatorClass)
|
1
|
+
scrivito.on 'content', (content) ->
|
2
|
+
return unless scrivito.in_editable_view()
|
3
|
+
setup = (sel) -> scrivito.editors._file_dropzone $(content).find(sel), save
|
4
|
+
setup 'img[data-scrivito-field-type=linklist]:not([data-editor])'
|
5
|
+
setup 'img[data-scrivito-field-type=reference]:not([data-editor])'
|
6
|
+
setup '[data-editor~=image]'
|
7
|
+
|
8
|
+
save = (field, file) ->
|
9
|
+
createImage(file).then (obj) ->
|
10
|
+
type = field.attr('data-scrivito-field-type')
|
11
|
+
value = switch
|
12
|
+
when type is 'reference' then obj.id
|
13
|
+
when type is 'linklist' then [{obj_id: obj.id}]
|
14
|
+
else $.error 'Field type must be "reference" or "linklist"'
|
15
|
+
field.scrivito('save', value).then -> field.scrivito('reload')
|
16
|
+
|
17
|
+
createImage = (blob) ->
|
18
|
+
name = blob.name.replace(/[^a-z0-9_.$\-]/ig, '-')
|
19
|
+
_path = "_resources/#{Math.floor(Math.random() * 1000)}/#{name}"
|
20
|
+
_obj_class = 'Image'
|
21
|
+
scrivito.create_obj {blob, _path, _obj_class}
|
@@ -6,17 +6,18 @@ $ ->
|
|
6
6
|
template = (attributes) ->
|
7
7
|
attributes ||= {}
|
8
8
|
|
9
|
+
description = attributes['description'] || ''
|
9
10
|
title = attributes['title'] || ''
|
10
11
|
url = attributes['url'] || ''
|
11
12
|
|
12
|
-
$("<
|
13
|
-
<input type=\"text\" name=\"
|
14
|
-
|
13
|
+
$("<input type=\"text\" name=\"title\" value=\"#{title}\" placeholder=\"Title\" />
|
14
|
+
<input type=\"text\" name=\"url\" value=\"#{description}\" data-value=\"#{url}\"
|
15
|
+
placeholder=\"Url\" class=\"editing-url\" />
|
15
16
|
<div class=\"actions\">
|
16
17
|
<a href=\"#\" class=\"editing-button content-browser-open editing-green\">
|
17
18
|
<i class=\"editing-icon editing-icon-search\" />
|
18
19
|
</a>
|
19
|
-
</div
|
20
|
+
</div>")
|
20
21
|
|
21
22
|
contentBrowserButtonTemplate = ->
|
22
23
|
icon = $('<i></i>')
|
@@ -62,7 +63,9 @@ $ ->
|
|
62
63
|
# Resource browser callback for saving a single link.
|
63
64
|
onContentBrowserSaveLinkItem = (selection, linkItem) ->
|
64
65
|
url = buildUrl(selection[0])
|
65
|
-
linkItem.find('[name=url]')
|
66
|
+
linkItem.find('[name=url]')
|
67
|
+
.data "value", url
|
68
|
+
.val "Content browser selection (#{url})"
|
66
69
|
|
67
70
|
# trigger save after inserting the value
|
68
71
|
cmsField = getCmsField(linkItem)
|
@@ -82,7 +85,8 @@ $ ->
|
|
82
85
|
if items.length > 0
|
83
86
|
item = $(items[0])
|
84
87
|
title = item.find('[name=title]').val()
|
85
|
-
|
88
|
+
input = item.find('[name=url]')
|
89
|
+
url = input.data('value') || input.val()
|
86
90
|
|
87
91
|
if url
|
88
92
|
'title': title
|
@@ -98,10 +102,17 @@ $ ->
|
|
98
102
|
item = $(item)
|
99
103
|
|
100
104
|
content = template
|
105
|
+
description: item.data('description')
|
101
106
|
title: item.data('title')
|
102
107
|
url: item.data('url')
|
103
108
|
|
104
109
|
item.html(content)
|
110
|
+
.find('[name=url]')
|
111
|
+
.on 'focus', ->
|
112
|
+
input = $(this)
|
113
|
+
raw = input.data 'value'
|
114
|
+
input.val raw if raw
|
115
|
+
input.data 'value', null
|
105
116
|
|
106
117
|
if items.length == 0
|
107
118
|
cmsField.append(template())
|
@@ -6,11 +6,13 @@ $ ->
|
|
6
6
|
template = (attributes) ->
|
7
7
|
attributes ||= {}
|
8
8
|
|
9
|
+
description = attributes['description'] || ''
|
9
10
|
title = attributes['title'] || ''
|
10
11
|
url = attributes['url'] || ''
|
11
12
|
|
12
13
|
$("<input type=\"text\" name=\"title\" value=\"#{title}\" placeholder=\"Title\" />
|
13
|
-
<input type=\"text\" name=\"url\" value=\"#{
|
14
|
+
<input type=\"text\" name=\"url\" value=\"#{description}\" data-value=\"#{url}\"
|
15
|
+
placeholder=\"Url\" class=\"editing-url\" />
|
14
16
|
<div class=\"actions\">
|
15
17
|
<a href=\"#\" class=\"editing-button content-browser-open editing-green\">
|
16
18
|
<i class=\"editing-icon editing-icon-search\" />
|
@@ -67,7 +69,9 @@ $ ->
|
|
67
69
|
# Resource browser callback for saving a single link.
|
68
70
|
onContentBrowserSaveLinkItem = (selection, linkItem) ->
|
69
71
|
url = buildUrl(selection[0])
|
70
|
-
linkItem.find('[name=url]')
|
72
|
+
linkItem.find('[name=url]')
|
73
|
+
.data "value", url
|
74
|
+
.val "Content browser selection (#{url})"
|
71
75
|
|
72
76
|
# trigger save after inserting the value
|
73
77
|
cmsField = getCmsField(linkItem)
|
@@ -88,7 +92,8 @@ $ ->
|
|
88
92
|
for item in items
|
89
93
|
item = $(item)
|
90
94
|
title = item.find('[name=title]').val()
|
91
|
-
|
95
|
+
input = item.find('[name=url]')
|
96
|
+
url = input.data('value') || input.val()
|
92
97
|
|
93
98
|
# Make sure the url is not empty.
|
94
99
|
if !isEmpty(url)
|
@@ -133,10 +138,17 @@ $ ->
|
|
133
138
|
item = $(item)
|
134
139
|
|
135
140
|
content = template
|
141
|
+
description: item.data('description')
|
136
142
|
title: item.data('title')
|
137
143
|
url: item.data('url')
|
138
144
|
|
139
145
|
item.html(content)
|
146
|
+
.find('[name=url]')
|
147
|
+
.on 'focus', ->
|
148
|
+
input = $(this)
|
149
|
+
raw = input.data 'value'
|
150
|
+
input.val raw if raw
|
151
|
+
input.data 'value', null
|
140
152
|
|
141
153
|
# Returns the last saved value.
|
142
154
|
getLastSaved = (cmsField) ->
|
@@ -2,4 +2,12 @@
|
|
2
2
|
//= require_self
|
3
3
|
//= require_tree ./scrivito_editors
|
4
4
|
|
5
|
-
scrivito.editors = {}
|
5
|
+
scrivito.editors = {};
|
6
|
+
|
7
|
+
scrivito.on('load', function() {
|
8
|
+
if (scrivito.in_editable_view()) {
|
9
|
+
scrivito.register_select_content(function() {
|
10
|
+
return scrivito.content_browser.open({selectionMode: 'single'});
|
11
|
+
});
|
12
|
+
}
|
13
|
+
});
|
@@ -129,7 +129,7 @@ module ScrivitoEditors
|
|
129
129
|
query = link.query.present? ? "?#{link.query}" : ""
|
130
130
|
url = link.internal? ? scrivito_path(link).sub(/\?.*/, query) : link.url
|
131
131
|
description = link.internal? ? link.obj.description_for_editor : link.url
|
132
|
-
data = { title: link.title, url: url }
|
132
|
+
data = { description: description, title: link.title, url: url }
|
133
133
|
data[:id] = link.obj.id if link.internal?
|
134
134
|
|
135
135
|
content_tag(:li, data: data) do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scrivito_editors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.41.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scrivito
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coffee-rails
|
@@ -58,28 +58,28 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
61
|
+
version: 0.41.0.rc1
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.
|
68
|
+
version: 0.41.0.rc1
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: scrivito_sdk
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - '='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
75
|
+
version: 0.41.0.rc1
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - '='
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
82
|
+
version: 0.41.0.rc1
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: pry
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,7 +142,7 @@ files:
|
|
142
142
|
- app/assets/javascripts/scrivito_editors/binary_editor.js.coffee
|
143
143
|
- app/assets/javascripts/scrivito_editors/date_editor.js.coffee
|
144
144
|
- app/assets/javascripts/scrivito_editors/enum_editor.js.coffee
|
145
|
-
- app/assets/javascripts/scrivito_editors/helpers/
|
145
|
+
- app/assets/javascripts/scrivito_editors/helpers/file_dropzone.js.coffee
|
146
146
|
- app/assets/javascripts/scrivito_editors/html_editor.js.coffee
|
147
147
|
- app/assets/javascripts/scrivito_editors/image_editor.js.coffee
|
148
148
|
- app/assets/javascripts/scrivito_editors/link_editor.js.coffee
|
@@ -1,43 +0,0 @@
|
|
1
|
-
fetch_file = (event) ->
|
2
|
-
data_transfer = event.originalEvent.dataTransfer
|
3
|
-
return unless data_transfer
|
4
|
-
|
5
|
-
files = data_transfer.files
|
6
|
-
if (files.length > 1)
|
7
|
-
alert('You dropped multiple files, but only one file is supported.')
|
8
|
-
return
|
9
|
-
|
10
|
-
files[0]
|
11
|
-
|
12
|
-
find_cms_field = (target) ->
|
13
|
-
if $(target).attr('data-scrivito-field-name')
|
14
|
-
$(target)
|
15
|
-
else
|
16
|
-
$(target).parent('[data-scrivito-field-name]')
|
17
|
-
|
18
|
-
scrivito.editors._file_drop_zone = (selector, callback, status_indicator_class) ->
|
19
|
-
# Disable DnD for all elements by default to prevent the user
|
20
|
-
# from accidentally opening an image in browser.
|
21
|
-
$('body').on 'dragover', -> false
|
22
|
-
$('body').on 'drop', -> false
|
23
|
-
|
24
|
-
status_indicator_class ||= 'scrivito-editor-dragover'
|
25
|
-
|
26
|
-
body_element = $('body')
|
27
|
-
body_element.on 'dragover.scrivito-editor', selector, (event) ->
|
28
|
-
event.preventDefault()
|
29
|
-
$(find_cms_field(event.target)).addClass(status_indicator_class)
|
30
|
-
|
31
|
-
body_element.on 'dragleave.scrivito-editor', selector, (event) ->
|
32
|
-
event.preventDefault()
|
33
|
-
$(find_cms_field(event.target)).removeClass(status_indicator_class)
|
34
|
-
|
35
|
-
body_element.on 'drop.scrivito-editor', selector, (event) ->
|
36
|
-
event.preventDefault()
|
37
|
-
cms_field = find_cms_field(event.target)
|
38
|
-
file = fetch_file(event)
|
39
|
-
$(cms_field).removeClass(status_indicator_class)
|
40
|
-
|
41
|
-
if file
|
42
|
-
callback(event, cms_field, file)
|
43
|
-
|