Commit 2c50b73a authored by Samuel Trégouët's avatar Samuel Trégouët
Browse files

import from fckeditorcompat

parent 04653b4e17e2
......@@ -2,3 +2,32 @@
WYSIWYG js editor with ckeditor
"""
from logilab.common.decorators import monkeypatch, cached
from cubicweb.web.webconfig import WebConfiguration
from cubicweb.web.request import _CubicWebRequestBase
@monkeypatch(_CubicWebRequestBase)
@cached # so it's writed only once
def fckeditor_config(self):
fckeditor_url = '//cdn.ckeditor.com/4.5.7/standard/ckeditor.js'
self.add_js(fckeditor_url, localfile=False)
self.add_js('initwysiwyg.js')
self.add_onload('buildWysiwygEditors()')
self.html_headers.define_var('fcklang', self.lang)
self.html_headers.define_var('fckconfigpath',
self.data_url('ckeditor-config.js'))
@monkeypatch(WebConfiguration)
def fckeditor_installed(self):
if self.uiprops is None:
return False
return True
@monkeypatch(WebConfiguration)
def cwproperty_definitions(self):
for key, pdef in super(WebConfiguration, self).cwproperty_definitions():
yield key, pdef
CKEDITOR.editorConfig = function( config ) {
// Define changes to default configuration here.
// For complete reference see:
// http://docs.ckeditor.com/#!/api/CKEDITOR.config
// The toolbar groups arrangement, optimized for two toolbar rows.
config.toolbarGroups = [
{ name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
{ name: 'editing', groups: [ 'find', 'selection', 'spellchecker' ] },
{ name: 'links' },
{ name: 'insert' },
{ name: 'forms' },
{ name: 'tools' },
{ name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
{ name: 'others' },
'/',
{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
{ name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ] },
{ name: 'styles' },
{ name: 'colors' },
{ name: 'about' }
];
// Remove some buttons provided by the standard plugins, which are
// not needed in the Standard(s) toolbar.
config.removeButtons = 'Underline,Subscript,Superscript';
// Set the most common block elements.
config.format_tags = 'p;h1;h2;h3;pre';
// Simplify the dialog windows.
config.removeDialogTabs = 'image:advanced;link:advanced';
};
function buildWysiwygEditors(parent) {
jQuery('textarea').each(function() {
var cw_type = this.getAttribute('cubicweb:type');
if (cw_type === 'fckeditor' || cw_type === 'wysiwyg') {
// mark editor as instanciated, we may be called a number of times
// (see _postAjaxLoad)
this.setAttribute('cubicweb:type', 'ckeditor');
if (typeof CKEDITOR != "undefined") {
var fck = CKEDITOR.replace(this.id, {
customConfig: fckconfigpath,
defaultLangguage: fcklang
});
} else {
cw.log('fckeditor could not be found.');
}
}
});
}
cw.utils.formContents = function formContents(elem) {
var $elem, array, names, values;
$elem = cw.jqNode(elem);
array = $elem.serializeArray();
if (typeof CKEDITOR !== 'undefined') {
$elem.find('textarea').each(function (idx, textarea) {
var ck = CKEDITOR.instances[textarea.id];
if (ck) {
array = jQuery.map(array, function (dict) {
if (dict.name === textarea.name) {
// filter out the textarea's - likely empty - value ...
return null;
}
return dict;
});
// ... so we can put the HTML coming from FCKeditor instead.
array.push({
name: textarea.name,
value: ck.getData()
});
}
});
}
names = [];
values = [];
jQuery.each(array, function (idx, dict) {
names.push(dict.name);
values.push(dict.value);
});
return [names, values];
};
......@@ -21,5 +21,5 @@ the cube is added to an existing instance.
You could setup site properties or a workflow here for example.
"""
# Example of site property change
#set_property('ui.site-title', "<sitename>")
set_property('ui.fckeditor', True)
set_property('ui.default-text-format', 'text/html')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment