Skip to content

Commit 24300c6

Browse files
committed
PloneLink plugin
integration with plonefinder also added SourceEditing
1 parent bf33849 commit 24300c6

File tree

8 files changed

+142
-29
lines changed

8 files changed

+142
-29
lines changed

src/collective/ckeditor/browser/ckeditor5/main.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
Mention,
3434
Paragraph,
3535
SimpleUploadAdapter,
36+
SourceEditing,
3637
Table,
3738
TableCaption,
3839
TableCellProperties,
@@ -44,6 +45,8 @@ import {
4445
Underline
4546
} from 'ckeditor5';
4647

48+
import PloneLink from 'plonelink';
49+
4750
/**
4851
* Create a free account with a trial: https://portal.ckeditor.com/checkout?plan=free
4952
*/
@@ -70,7 +73,9 @@ const editorConfig = {
7073
'numberedList',
7174
'todoList',
7275
'outdent',
73-
'indent'
76+
'indent',
77+
'|',
78+
'sourceEditing'
7479
],
7580
shouldNotGroupWhenFull: false
7681
},
@@ -97,12 +102,14 @@ const editorConfig = {
97102
IndentBlock,
98103
Italic,
99104
Link,
105+
PloneLink,
100106
LinkImage,
101107
List,
102108
ListProperties,
103109
Mention,
104110
Paragraph,
105111
SimpleUploadAdapter,
112+
SourceEditing,
106113
Table,
107114
TableCaption,
108115
TableCellProperties,
@@ -173,7 +180,7 @@ const editorConfig = {
173180
initialData:'',
174181
licenseKey: LICENSE_KEY,
175182
link: {
176-
addTargetToExternalLinks: true,
183+
// addTargetToExternalLinks: true,
177184
defaultProtocol: 'https://',
178185
decorators: {
179186
toggleDownloadable: {
@@ -208,12 +215,21 @@ const editorConfig = {
208215
}
209216
};
210217

211-
var launchCK5Instances = function () {
218+
219+
function launchCK5Instances() {
220+
window.plone_ckeditors = {};
212221
var editors = document.querySelectorAll('.ckeditor_plone');
213222
editors.forEach(function(currentValue) {
214223
content = currentValue.value;
215224
editorConfig['initialData'] = content;
216-
ClassicEditor.create(currentValue, editorConfig);
225+
var CK4Config = {};
226+
get_CKEditorConfig(CK4Config);
227+
var plone_dom_id = currentValue.getAttribute('id');
228+
editorConfig['plone_dom_id'] = plone_dom_id;
229+
editorConfig['filebrowserBrowserUrl'] = CK4Config.filebrowserBrowseUrl
230+
ClassicEditor.create(currentValue, editorConfig).then( editor => {;
231+
window.plone_ckeditors[plone_dom_id] = editor;
232+
});
217233
});
218234
}
219235

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// plonelink/plonelink.js
2+
import PloneLinkUI from './plonelinkui.js';
3+
import { Plugin } from 'ckeditor5';
4+
5+
export default class PloneLink extends Plugin {
6+
static get requires() {
7+
return [ PloneLinkUI ];
8+
}
9+
}
10+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// plonelink/plonelinkediting.js
2+
3+
import { Plugin } from 'ckeditor5';
4+
5+
6+
7+
var createPloneLinkElement = function(uid, writer) {
8+
var linkElement = writer.createAttributeElement( 'a', { uid }, { priority: 5 } );
9+
writer.setCustomProperty( 'plonelink', true, linkElement );
10+
return linkElement;
11+
}
12+
13+
export default class PloneLinkEditing extends Plugin {
14+
init() {
15+
// console.log( 'PloneLinkEditing#init() got called' );
16+
// var editor = this.editor;
17+
// editor.model.schema.extend('$text', { allowAttributes: 'linkPloneUid'});
18+
// editor.conversion.for( 'dataDowncast' )
19+
// .attributeToElement( { model: 'linkPloneUid', view: createPloneLinkElement } );
20+
// console.log( 'PloneLinkEditing#init() done' );
21+
}
22+
}
23+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// plonelink/plonelinkui.js
2+
3+
import { ButtonView, Plugin, LinkUI, LinkFormView } from 'ckeditor5';
4+
5+
export default class PloneLinkUI extends LinkUI {
6+
static get pluginName() {
7+
return 'PloneLinkUI';
8+
}
9+
10+
init() {
11+
console.log( 'plonelinkui#init() got called' );
12+
super.init();
13+
const editor = this.editor;
14+
editor.config.define( 'filebrowserBrowserUrl', 'none');
15+
}
16+
17+
_createFormView() {
18+
var view = super._createFormView();
19+
view.urlInputView.label = 'Plone Link';
20+
view.children.first.label = 'Plone Link';
21+
view.children.last.children.add(this._createBrowseButton(view), 1);
22+
view.on('plone_set_url', (evt, data) => {
23+
console.log('view plone_set_url URL: ' + data.url);
24+
view.urlInputView.fieldView.value = data.url;
25+
view.fire('submit');
26+
this._showUI();
27+
});
28+
this.editor.on('plone_set_url', (evt, data) => {
29+
view.fire('plone_set_url', data);
30+
});
31+
return view;
32+
}
33+
34+
_createBrowseButton(locale) {
35+
const t = locale.t;
36+
const saveButton = new ButtonView( locale );
37+
38+
saveButton.set( {
39+
label: t( 'Browse server' ),
40+
tooltip: false,
41+
withText: true,
42+
type: 'submit',
43+
class: 'ck-button-action ck-button-bold'
44+
} );
45+
var plone_dom_id = this.editor.config.get('plone_dom_id');
46+
var filebrowserBrowserUrl = this.editor.config.get('filebrowserBrowserUrl') + '&CKEditorFuncNum=' + plone_dom_id;
47+
saveButton.on('execute', () => {
48+
window.open(
49+
filebrowserBrowserUrl,
50+
null,
51+
'location=no,menubar=no,toolbar=no,dependent=yes,minimizable=no,modal=yes,alwaysRaised=yes,resizable=yes,scrollbars=yes'
52+
);
53+
});
54+
return saveButton;
55+
}
56+
57+
}
58+

src/collective/ckeditor/browser/ckeditorfinder.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from Acquisition import aq_inner
22
from collective.plonefinder.browser.finder import Finder
33
from collective.ckeditor.browser.ckeditorview import get_registry_value
4+
from zope.component import getMultiAdapter
45

56

67
class CKFinder(Finder):
@@ -14,6 +15,9 @@ def __init__(self, context, request):
1415
self.multiselect = False
1516
self.allowupload = True
1617
self.allowaddfolder = True
18+
pstate = getMultiAdapter((self.context, self.request),
19+
name="plone_portal_state")
20+
self.portal_url = pstate.portal_url()
1721

1822
def __call__(self):
1923

@@ -124,10 +128,10 @@ def get_jsaddons(self):
124128
selectCKEditorItem = function (selector, title, image_preview) {
125129
image_preview = (typeof image_preview != "undefined") ? image_preview : false;
126130
if (image_preview) selector = selector + '/@@images/image/preview' ;
127-
window.opener.CKEDITOR.tools.callFunction( %s, 'resolveuid/' + selector );
131+
window.opener.plone_ckeditors['%s'].fire('plone_set_url', {url: '%s/resolveuid/' + selector} );
128132
window.close();
129133
};
130134
Browser.selectItem = selectCKEditorItem;
131-
""" % CKEditorFuncNum
135+
""" % (CKEditorFuncNum, self.portal_url)
132136

133137
return jsstring

src/collective/ckeditor/browser/ckeditorview.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -371,25 +371,25 @@ def getCK_plone_config(self):
371371
"""
372372
request = self.request
373373
response = request.RESPONSE
374-
params_js_string = """CKEDITOR.editorConfig = function( config ) {"""
374+
params_js_string = """var get_CKEditorConfig = function( config ) {"""
375375
params = self.cke_params
376376
for k, v in params.items():
377377
params_js_string += """
378378
config.%s = %s;
379379
""" % (k, v)
380380

381381
ids = ['plone']
382-
for line in get_registry_value('plugins', []):
383-
# ignore the rest so we get no error
384-
if len(line.split(';')) == 2:
385-
id, url = line.split(';')
386-
abs_url = self.portal_url + url
387-
base_url, plugin = abs_url.rsplit('/', 1)
388-
ids.append(id)
389-
params_js_string += (
390-
"""CKEDITOR.plugins.addExternal('%s', '%s/', '%s');"""
391-
% (id, base_url.rstrip('/'), plugin))
392-
params_js_string += '''config.extraPlugins = "%s";''' % ','.join(ids)
382+
# for line in get_registry_value('plugins', []):
383+
# # ignore the rest so we get no error
384+
# if len(line.split(';')) == 2:
385+
# id, url = line.split(';')
386+
# abs_url = self.portal_url + url
387+
# base_url, plugin = abs_url.rsplit('/', 1)
388+
# ids.append(id)
389+
# params_js_string += (
390+
# """CKEDITOR.plugins.addExternal('%s', '%s/', '%s');"""
391+
# % (id, base_url.rstrip('/'), plugin))
392+
# params_js_string += '''config.extraPlugins = "%s";''' % ','.join(ids)
393393

394394
removePlugins = get_registry_value('removePlugins', [])
395395
if removePlugins:

src/collective/ckeditor/browser/templates/ckeditor_wysiwyg_support.pt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,18 @@
4444
id python:inputname.replace('.', '_');
4545
onfocus onfocus|nothing;
4646
onblur onblur|nothing;"></textarea>
47-
<script type="importmap">
48-
{
49-
"imports": {
50-
"ckeditor5": "./++resource++ckeditor5/ckeditor5/ckeditor5.js",
51-
"ckeditor5/": "./++resource++ckeditor5/ckeditor5/"
52-
}
53-
}
54-
</script>
55-
<script type="module" src="++resource++ckeditor5/main.js"></script>
56-
47+
<script type="importmap">
48+
{
49+
"imports": {
50+
"ckeditor5": "./++resource++ckeditor5/ckeditor5/ckeditor5.js",
51+
"ckeditor5/": "./++resource++ckeditor5/ckeditor5/",
52+
"plonelink": "./++resource++ckeditor5/plonelink/plonelink.js",
53+
"plonelink/": "./++resource++ckeditor5/plonelink/"
54+
}
55+
}
56+
</script>
57+
<script type="module" src="++resource++ckeditor5/main.js"></script>
58+
<script tal:attributes="src python:ckview.cke_config_url(finder_context)"></script>
5759
</tal:block>
5860
<tal:block condition="not: usesCKeditor">
5961
<textarea cols="80"

src/collective/ckeditor/profiles/default/registry.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
key="default_editor"
163163
purge="True">CKeditor</value>
164164
</records>
165-
<records prefix="plone.bundles/collective.ckeditor.ckeditor5-css" interface="Products.CMFPlone.interfaces.IBundleRegistry">
165+
<records prefix="plone.bundles/collective.ckeditor.ckeditor5" interface="Products.CMFPlone.interfaces.IBundleRegistry">
166166
<value key="depends">plone</value>
167167
<value key="enabled">True</value>
168168
<value key="compile">False</value>

0 commit comments

Comments
 (0)