scrivito_editors 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c08476ab0a102e46e91e58ad43e617a3ee6ff3b2
4
- data.tar.gz: f07ebb84641bd5244c695d25010c3fda9ce99501
3
+ metadata.gz: 18977d126e4b35ad587ce7fb5037209c057d903b
4
+ data.tar.gz: 9031005f81cffa1fe61c817b8e25fb17038d5ffe
5
5
  SHA512:
6
- metadata.gz: 2ee789cbf8672495e67bb72537fc83a63c648695e73ba22d30144cb19f290b815c4d883743aa7a1507d2dfc4f493769f3b6673df0dcb7fd939fbdcb9eb2a5ae4
7
- data.tar.gz: b7b13acf7da281ef64b8def0ca6ade7916f3fa50f7aa7ddb0da10655ad6e637cb5e8d3d5e625860b42037bc7ae96692e2ade5d56c38c36f3e7ae5f108e57697b
6
+ metadata.gz: 9bdc8e2382aa12229772012003692b34116b92ff90a760c0dbd34a3a859da4d3fcded838a5f054df5790ab5a33a62e9dbe1f3be8762a395163745e6858a56edc
7
+ data.tar.gz: df60487fb2c03b11209b818f55395836d722b3fccbbb22a93dd3991ca2b0717f9759141d7299ff103264e37f4266321e97f329870c9067bca574d44c5e895609
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ # v0.0.11
2
+ * Added "Close" button to the HTML editor, to have an additional option to close the editor,
3
+ besides hitting "Esc".
4
+ * The new Scrivito SDK feature to serialize save requests allows editors to automatically save the
5
+ content on every input instead of every 3 seconds. The `string`, `text` and `html` editor now
6
+ all make use of this feature.
7
+ * The "Esc" key on `string`, `text` and `html` editors now just destroys the editor, without
8
+ resetting to any old content.
9
+ * All editors now trigger a `save.scrivito_editors` event, when the content was successfully
10
+ saved in the CMS.
11
+ * `string` and `text` editors now only save, if the content has changed, as it is already
12
+ the case for the `html` editor.
13
+ * `referencelist` and `linklist` editors now make use of the new single selection mode option of
14
+ the resource browser.
15
+
1
16
  # v0.0.10
2
17
  * Extracted resource browser into separate gem.
3
18
 
@@ -23,6 +23,7 @@ $ ->
23
23
 
24
24
  cmsField.scrivito('save', dateTimeText)
25
25
  .done ->
26
+ cmsField.trigger('save.scrivito_editors')
26
27
  cmsField.trigger('scrivito_reload')
27
28
 
28
29
  $('body').on 'click', '[data-scrivito-field-type="date"]:not(.hasDatepicker):not([data-editor]), [data-editor="date"]', (event) ->
@@ -19,6 +19,7 @@ $ ->
19
19
  cmsField = element.data('cmsField')
20
20
  content = element.val()
21
21
  cmsField.scrivito('save', content).done ->
22
+ cmsField.trigger('save.scrivito_editors')
22
23
  cmsField.trigger('scrivito_reload')
23
24
 
24
25
  $(document).on 'click', '[data-scrivito-field-type="enum"]:not([data-editor]), [data-editor="enum"]', (event) ->
@@ -1,43 +1,33 @@
1
- $ ->
2
- # Configuration and behavior of Redactor html editor. The editor is used for all html CMS
3
- # attributes and provides autosave, undo and redo functionality on top of the default Redactor
4
- # settings.
5
-
6
- # Stores the id of the last triggered timeout for later reference.
7
- timeoutID = undefined
1
+ # Configuration and behavior of Redactor html editor. The editor is used for all html CMS
2
+ # attributes and provides autosave on top of the default Redactor settings.
8
3
 
9
- # Milliseconds after which to save the content automatically.
10
- autosaveInterval = 3000
4
+ # Check if the namespace for plugins exists and create it otherwise.
5
+ unless @RedactorPlugins?
6
+ @RedactorPlugins = {}
11
7
 
12
- # Stores the last saved content written to the CMS to allow comparison with editor content.
13
- savedContent = undefined
8
+ # Plugin for closing the editor with a button in the toolbar.
9
+ @RedactorPlugins.close =
10
+ init: ->
11
+ @buttonAddFirst('close', 'Close', @closeAction)
14
12
 
15
- # Stores the content before the editor is opened and changes occur.
16
- originalContent = undefined
13
+ closeAction: (buttonName, buttonDOM, buttonObj, event) ->
14
+ @.callback('blur')
17
15
 
16
+ $ ->
18
17
  # Stores redactor options, custom settings and configures callbacks.
19
18
  redactorOptions = ->
20
19
  return {} =
21
- # This option allows you to add your own buttons with callback to the toolbar.
22
- # http://imperavi.com/redactor/docs/settings/#set-buttonsCustom
23
- buttonsCustom:
24
- undoButton:
25
- title: 'Undo'
26
- callback: undoAction
27
- redoButton:
28
- title: 'Redo'
29
- callback: redoAction
30
-
31
20
  # This setting defines the array of toolbar buttons.
32
21
  # http://imperavi.com/redactor/docs/settings/#set-buttons
33
- buttons: ['undoButton', 'redoButton',
34
- '|', 'formatting',
35
- '|', 'bold', 'italic', 'deleted', 'underline',
36
- '|', 'unorderedlist', 'orderedlist',
37
- '|', 'table', 'link',
38
- '|', 'html'
22
+ buttons: [
23
+ 'formatting', 'bold', 'italic', 'deleted', 'underline',
24
+ 'unorderedlist', 'orderedlist', 'table', 'link', 'html',
39
25
  ]
40
26
 
27
+ # This options allows to configure what plugins are loaded. Plugins need to be defined in the
28
+ # +RedactorPlugins+ namespace.
29
+ plugins: ['close']
30
+
41
31
  # This option allows you to set whether Redactor gets cursor focus on load or not.
42
32
  # http://imperavi.com/redactor/docs/settings/#set-focus
43
33
  focus: true
@@ -46,22 +36,16 @@ $ ->
46
36
  # http://imperavi.com/redactor/docs/settings/#set-convertDivs
47
37
  convertDivs: false
48
38
 
49
- # This callback is triggered after Redactor is launched.
50
- # http://imperavi.com/redactor/docs/callbacks/#callback-initCallback
51
- initCallback: ->
52
- originalContent = @get()
53
-
54
39
  # This callback fires every time when content changes in Redactor.
55
40
  # http://imperavi.com/redactor/docs/callbacks/#callback-changeCallback
56
41
  changeCallback: ->
57
- autosaveAction(@)
42
+ saveContents(@)
58
43
 
59
44
  # This callback is triggered when Redactor loses focus.
60
45
  # http://imperavi.com/redactor/docs/callbacks/#callback-blurCallback
61
46
  blurCallback: ->
62
- saveContents(@).done =>
63
- @.destroy()
64
- reload(@)
47
+ @.destroy()
48
+ saveContents(@)
65
49
 
66
50
  # This callback is triggered when a key is released.
67
51
  # http://imperavi.com/redactor/docs/callbacks/#callback-keyupCallback
@@ -70,56 +54,27 @@ $ ->
70
54
  key = event.keyCode || event.which
71
55
 
72
56
  if key == 27
73
- cancelEditing(@)
57
+ @.callback('blur')
74
58
  else
75
- autosaveAction(@)
59
+ saveContents(@)
76
60
 
77
61
  # This callback allows to get pasted code after clean on paste.
78
62
  # http://imperavi.com/redactor/docs/callbacks/#callback-pasteAfterCallback
79
63
  pasteAfterCallback: (html) ->
80
- autosaveAction(@)
64
+ saveContents(@)
81
65
  html
82
66
 
83
- # Registers a timeout to save the editor content after a certain interval. The timeout gets reset
84
- # on every change.
85
- autosaveAction = (editor) ->
86
- if timeoutID
87
- clearTimeout(timeoutID)
88
-
89
- timeoutID = setTimeout ( ->
90
- saveContents(editor)
91
- ), autosaveInterval
92
-
93
- undoAction = ->
94
- @execCommand('undo')
95
-
96
- redoAction = ->
97
- @execCommand('redo')
98
-
99
- # Saves the current editor content to the CMS if it has changed.
67
+ # Saves the current editor content to the CMS.
100
68
  saveContents = (editor) ->
69
+ cmsField = editor.$element
101
70
  content = editor.get()
102
71
 
103
- if savedContent != content
104
- cmsField = editor.$element
72
+ if content != cmsField.scrivito('content')
105
73
  cmsField.scrivito('save', content).done ->
106
- savedContent = content
107
-
74
+ cmsField.trigger('save.scrivito_editors')
108
75
  else
109
76
  $.Deferred().resolve()
110
77
 
111
- reload = (editor) ->
112
- cmsField = editor.$element
113
- cmsField.trigger('scrivito_reload')
114
-
115
- # Restores the original content before the editor was opened, also saves it back to the CMS
116
- # because autosave could have overwritten the content and closes the editor.
117
- cancelEditing = (editor) ->
118
- editor.set(originalContent)
119
- saveContents(editor).done ->
120
- reload(editor)
121
- editor.destroy()
122
-
123
78
  # Registers Redactor for all CMS html attributes found in the given scope of the DOM element.
124
79
  addOnclickRedactorHandlers = (domElement) ->
125
80
  domElement.on 'click', '[data-scrivito-field-type="html"]:not([data-editor]), [data-editor="html"]', (event) ->
@@ -44,6 +44,7 @@ $ ->
44
44
 
45
45
  unless JSON.stringify(value) == JSON.stringify(lastSaved)
46
46
  cmsField.scrivito('save', value).done ->
47
+ cmsField.trigger('save.scrivito_editors')
47
48
  storeLastSaved(cmsField, value)
48
49
 
49
50
  # Run when clicking the '...' button inside a li.
@@ -57,6 +58,7 @@ $ ->
57
58
  Resourcebrowser.open
58
59
  selection: []
59
60
  filters: filters
61
+ selectionMode: 'single'
60
62
  onSave: (selection) =>
61
63
  onResourcebrowserSaveLinkItem(selection, linkItem)
62
64
 
@@ -20,6 +20,7 @@ $ ->
20
20
  cmsField = element.data('cmsField')
21
21
  content = element.val()
22
22
  cmsField.scrivito('save', content).done ->
23
+ cmsField.trigger('save.scrivito_editors')
23
24
  cmsField.trigger('scrivito_reload')
24
25
 
25
26
  $(document).on 'click', '[data-scrivito-field-type="multienum"]:not([data-editor]), [data-editor="multienum"]', (event) ->
@@ -13,6 +13,7 @@ $ ->
13
13
  Resourcebrowser.open
14
14
  selection: selected
15
15
  filters: filters
16
+ selectionMode: 'single'
16
17
 
17
18
  onSave: (selection) =>
18
19
  onResourcebrowserSave(selection, cmsField)
@@ -23,6 +24,7 @@ $ ->
23
24
 
24
25
  cmsField.scrivito('save', value)
25
26
  .done ->
27
+ cmsField.trigger('save.scrivito_editors')
26
28
  cmsField.trigger('scrivito_reload')
27
29
 
28
30
  true
@@ -35,6 +35,7 @@ $ ->
35
35
  cmsField.scrivito('save', ids)
36
36
  .done ->
37
37
  storeLastSaved(cmsField, ids)
38
+ cmsField.trigger('save.scrivito_editors')
38
39
  cmsField.trigger('scrivito_reload')
39
40
 
40
41
  # Run when clicking the resource browser button.
@@ -9,6 +9,7 @@ $ ->
9
9
  cmsField = $(@).data('cmsField')
10
10
  content = ui.value
11
11
  cmsField.scrivito('save', content).done ->
12
+ cmsField.trigger('save.scrivito_editors')
12
13
  cmsField.trigger('scrivito_reload')
13
14
 
14
15
  onSlide = (event, ui) ->
@@ -1,12 +1,7 @@
1
1
  $ ->
2
2
  # This file integrates contenteditable for string attributes.
3
3
 
4
- timeout = undefined
5
-
6
4
  onKey = (event) ->
7
- if timeout?
8
- clearTimeout(timeout)
9
-
10
5
  cmsField = $(event.currentTarget)
11
6
  key = event.keyCode || event.which
12
7
 
@@ -15,18 +10,12 @@ $ ->
15
10
  event.preventDefault()
16
11
  cmsField.blur()
17
12
  when 27 # Esc
18
- if event.type == 'keyup'
19
- event.stopPropagation()
20
- cmsField
21
- .off('blur')
22
- .trigger('scrivito_reload')
23
- else
24
- setTimeout ->
25
- cleanUp(cmsField)
13
+ event.stopPropagation()
14
+ cmsField.blur()
26
15
 
27
- timeout = setTimeout ( ->
28
- save(cmsField, false)
29
- ), 3000
16
+ onInput = (event) ->
17
+ cmsField = $(event.currentTarget)
18
+ save(cmsField, false)
30
19
 
31
20
  onBlur = (event) ->
32
21
  cmsField = $(event.currentTarget)
@@ -36,9 +25,6 @@ $ ->
36
25
  cmsField.trigger('scrivito_reload')
37
26
 
38
27
  save = (cmsField, andClose) ->
39
- if timeout?
40
- clearTimeout(timeout)
41
-
42
28
  cleanUp(cmsField)
43
29
 
44
30
  clone = cmsFieldAndPastedContent(cmsField).clone()
@@ -49,7 +35,12 @@ $ ->
49
35
  if andClose
50
36
  cmsField.text(content)
51
37
 
52
- cmsField.scrivito('save', content)
38
+ # Save only if the content has changed.
39
+ if content != cmsField.scrivito('content')
40
+ cmsField.scrivito('save', content).done ->
41
+ cmsField.trigger('save.scrivito_editors')
42
+ else
43
+ $.Deferred().resolve()
53
44
 
54
45
  cleanUp = (cmsField) ->
55
46
  siblings = cmsFieldAndPastedContent(cmsField)
@@ -72,6 +63,7 @@ $ ->
72
63
  .blur(onBlur)
73
64
  .keypress(onKey)
74
65
  .keyup(onKey)
66
+ .on('input', onInput)
75
67
 
76
68
  # Prevent editable link strings to follow the link target on click.
77
69
  $('body').on 'click', '[data-scrivito-field-type="string"]:not([data-editor]), [data-editor="string"]', (event) ->
@@ -2,29 +2,18 @@ $ ->
2
2
  # This file integrates contenteditable for text attributes.
3
3
  # It provides multiline editing support.
4
4
 
5
- timeout = undefined
6
-
7
5
  onKey = (event) ->
8
- if timeout?
9
- clearTimeout(timeout)
10
-
11
6
  cmsField = $(event.currentTarget)
12
7
  key = event.keyCode || event.which
13
8
 
14
9
  switch key
15
10
  when 27 # Esc
16
- if event.type == 'keyup'
17
- event.stopPropagation()
18
- cmsField
19
- .off('blur')
20
- .trigger('scrivito_reload')
21
- else
22
- setTimeout ->
23
- cleanUp(cmsField)
24
-
25
- timeout = setTimeout ( ->
26
- save(cmsField, false)
27
- ), 3000
11
+ event.stopPropagation()
12
+ cmsField.blur()
13
+
14
+ onInput = (event) ->
15
+ cmsField = $(event.currentTarget)
16
+ save(cmsField, false)
28
17
 
29
18
  onBlur = (event) ->
30
19
  cmsField = $(event.currentTarget)
@@ -34,9 +23,6 @@ $ ->
34
23
  cmsField.trigger('scrivito_reload')
35
24
 
36
25
  save = (cmsField, andClose) ->
37
- if timeout?
38
- clearTimeout(timeout)
39
-
40
26
  cleanUp(cmsField)
41
27
 
42
28
  clone = cmsFieldAndPastedContent(cmsField).clone()
@@ -47,7 +33,12 @@ $ ->
47
33
  if andClose
48
34
  cmsField.text(content)
49
35
 
50
- cmsField.scrivito('save', content)
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()
51
42
 
52
43
  cleanUp = (cmsField) ->
53
44
  siblings = cmsFieldAndPastedContent(cmsField)
@@ -75,6 +66,7 @@ $ ->
75
66
  .blur(onBlur)
76
67
  .keypress(onKey)
77
68
  .keyup(onKey)
69
+ .on('input', onInput)
78
70
 
79
71
  # Prevent editable link text to follow the link target on click.
80
72
  $('body').on 'click', '[data-scrivito-field-type="text"]:not([data-editor]), [data-editor="text"]', (event) ->
@@ -0,0 +1,18 @@
1
+ /*
2
+ Plugin styles for the close button.
3
+ */
4
+
5
+ .redactor_toolbar li a.re-close {
6
+ color: #aa4040;
7
+ font-family: 'editing_iconsregular';
8
+ font-size: 7px;
9
+ padding: 14px 10px 4px 10px;
10
+ }
11
+
12
+ .redactor_toolbar li a.re-close:before {
13
+ content: "\F028";
14
+ }
15
+
16
+ .redactor_toolbar li a.re-close:hover {
17
+ color: #fff;
18
+ }
@@ -1,3 +1,3 @@
1
1
  module ScrivitoEditors
2
- VERSION = '0.0.10'
2
+ VERSION = '0.0.11'
3
3
  end
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.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scrivito
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-27 00:00:00.000000000 Z
11
+ date: 2014-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -123,6 +123,7 @@ files:
123
123
  - app/assets/javascripts/scrivito_editors/text_editor.js.coffee
124
124
  - app/assets/stylesheets/scrivito_editors.css
125
125
  - app/assets/stylesheets/scrivito_editors/buttons.css
126
+ - app/assets/stylesheets/scrivito_editors/editors/html_editor.css
126
127
  - app/assets/stylesheets/scrivito_editors/editors/linklist_editor.css
127
128
  - app/assets/stylesheets/scrivito_editors/editors/referencelist_editor.css
128
129
  - app/assets/stylesheets/scrivito_editors/editors/text_editor.css