scrivito_editors 0.40.0 → 0.41.0.rc1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8cd655f0c8e4dc6ef31ab2370da5166cb50e17d
4
- data.tar.gz: af2c116ad1ebf36bfc69efcc2b28281bc7927c78
3
+ metadata.gz: 67f5aedc7181ead6c2782fae77773a56dfa8ff61
4
+ data.tar.gz: 162b00e6981d66cec5e975f39df882c00a57ce55
5
5
  SHA512:
6
- metadata.gz: 8a07c21e92396e780db4f5b92d8636da87e46189a297a5688f2348fa54460ae912b131fbea03b8fcdbaf3bea140e7c834565da66cd27f93e6d75afbf728483fb
7
- data.tar.gz: 5fded99d3f799e35c0c05f442a35ca8ae85f2ae394769886fcb8e1f25fc1e45fdda529c4858468025ff9c361ed6963e1c72729480dd64560aa411ee1b75edc02
6
+ metadata.gz: 3543ba8d15cd33d894b30aa74074bdb4581c025d81ce6ae5ba46092bdd2ba6bbe7d0dff1d30a9618864cfc7ec1e33c768aa7df21e90ec361e8994962c2951b03
7
+ data.tar.gz: 91c45bf04573c1650313d3bcd93b6934649cd33d9314efe8c0595bef8294908081940378ebb465b20e049f34cd0e98a0edc436874667baa9493c74d606e5e9f8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # v0.41.0
2
+ * Link and linklist editors initially show description for editor (for internal links).
3
+
1
4
  # v0.40.0
2
5
  * Updated HTML editor to Redactor 10.0.6
3
6
  * Introduced API for Redactor options, e. g.
@@ -1,49 +1,22 @@
1
- $ ->
2
- selector = '[data-scrivito-field-type=binary]:not([data-editor])'
3
- status_indicator_class = 'image-editor-dragover'
4
- image_container_class = 'scrivito-editor-image-container'
5
-
6
- handle_file_upload = (event, element, file) ->
7
- element.scrivito('save', file).then ->
8
- element.scrivito('reload')
9
-
10
- delete_binary = (cms_field) ->
11
- if $(cms_field).scrivito('content')
12
- $(cms_field).scrivito('save', null).then ->
13
- $(cms_field).scrivito('reload')
14
-
15
- binary_field_container = (binary_field) ->
16
- if $(binary_field).prop('tagName') == 'IMG'
17
- if $(binary_field).parent(".#{image_container_class}").length == 0
18
- $(binary_field).wrap("<div class='#{image_container_class}'></div>")
19
- $(binary_field).parent(".#{image_container_class}")
20
- else
21
- binary_field
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
- statusIndicatorClass = 'image-editor-dragover'
3
-
4
- activateForFieldType = (fieldType) ->
5
- selector = 'img[data-scrivito-field-type=' + fieldType + ']:not([data-editor])'
6
- scrivito.editors._file_drop_zone(selector, save)
7
-
8
- save = (event, element, file) ->
9
- fieldType = element.attr('data-scrivito-field-type')
10
-
11
- createImage(file).then (obj) ->
12
- value = switch
13
- when fieldType == 'reference' then obj.id
14
- when fieldType == 'linklist' then [{obj_id: obj.id}]
15
- else $.error('Field type must be "reference" or "linklist".')
16
-
17
- element.scrivito('save', value).then ->
18
- element.scrivito('reload')
19
-
20
- createImage = (file) ->
21
- name = file.name.replace(/[^a-z0-9_.$\-]/ig, '-')
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
- $("<ul><li>
13
- <input type=\"text\" name=\"title\" value=\"#{title}\" placeholder=\"Title\" />
14
- <input type=\"text\" name=\"url\" value=\"#{url}\" placeholder=\"Url\" class=\"editing-url\" />
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></li></ul>")
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]').val(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
- url = item.find('[name=url]').val()
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=\"#{url}\" placeholder=\"Url\" class=\"editing-url\" />
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]').val(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
- url = item.find('[name=url]').val()
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.40.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-01-26 00:00:00.000000000 Z
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.40.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.40.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.40.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.40.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/file_drop_zone.js.coffee
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
-