diff --git a/CHANGELOG b/CHANGELOG index fc619bbd0..188b00ed3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,6 +8,9 @@ Version 1.6.1 (unreleased) ========================== [https://github.com/OpenSlides/OpenSlides/issues?milestone=16] +Other: +- Fixed CKEditor stuff (added insertpre plugin and removed unused code) + Version 1.6 (2014-06-02) ======================== diff --git a/openslides/core/static/ckeditor/ckeditor/plugins/insertpre/README.md b/openslides/core/static/ckeditor/ckeditor/plugins/insertpre/README.md new file mode 100644 index 000000000..5bf8edb2f --- /dev/null +++ b/openslides/core/static/ckeditor/ckeditor/plugins/insertpre/README.md @@ -0,0 +1,27 @@ +CKEditor Insert <pre> Plugin +=============================== + +This plugin makes it easier to insert a <pre> tag in CKEditor. + +Installation +------------ + +1. Clone/copy this repository contents in a new "plugins/insertpre" folder in your CKEditor installation. +2. Enable the "insertpre" plugin in the CKEditor configuration file (config.js): + + config.extraPlugins = 'insertpre'; + +That's all. "InsertPre" button will appear on the editor toolbar and will be ready to use. + +3. Optionally, you may specify which class should be added to the <pre> element: + + CKEDITOR.config.insertpre_class = 'prettyprint'; + + As well as specify how the <pre> tag should be rendered inside CKEditor: + + CKEDITOR.config.insertpre_style = 'background-color:#F8F8F8;border:1px solid #DDD;padding:10px;'; + +License +------- + +Licensed under the terms of any of the following licenses at your choice: [GPL](http://www.gnu.org/licenses/gpl.html), [LGPL](http://www.gnu.org/licenses/lgpl.html) and [MPL](http://www.mozilla.org/MPL/MPL-1.1.html). diff --git a/openslides/core/static/ckeditor/ckeditor/plugins/insertpre/icons/insertpre-color.png b/openslides/core/static/ckeditor/ckeditor/plugins/insertpre/icons/insertpre-color.png new file mode 100644 index 000000000..0c76bd129 Binary files /dev/null and b/openslides/core/static/ckeditor/ckeditor/plugins/insertpre/icons/insertpre-color.png differ diff --git a/openslides/core/static/ckeditor/ckeditor/plugins/insertpre/icons/insertpre.png b/openslides/core/static/ckeditor/ckeditor/plugins/insertpre/icons/insertpre.png new file mode 100644 index 000000000..756a4906f Binary files /dev/null and b/openslides/core/static/ckeditor/ckeditor/plugins/insertpre/icons/insertpre.png differ diff --git a/openslides/core/static/ckeditor/ckeditor/plugins/insertpre/lang/en.js b/openslides/core/static/ckeditor/ckeditor/plugins/insertpre/lang/en.js new file mode 100644 index 000000000..661f139c4 --- /dev/null +++ b/openslides/core/static/ckeditor/ckeditor/plugins/insertpre/lang/en.js @@ -0,0 +1,6 @@ +CKEDITOR.plugins.setLang( 'insertpre', 'en', { + title : 'Insert code snippet', + code : 'Code', + edit : 'Edit code', + notEmpty : 'The code field cannot be empty.' +}); diff --git a/openslides/core/static/ckeditor/ckeditor/plugins/insertpre/lang/pl.js b/openslides/core/static/ckeditor/ckeditor/plugins/insertpre/lang/pl.js new file mode 100644 index 000000000..f8ec4eda2 --- /dev/null +++ b/openslides/core/static/ckeditor/ckeditor/plugins/insertpre/lang/pl.js @@ -0,0 +1,6 @@ +CKEDITOR.plugins.setLang( 'insertpre', 'pl', { + title : 'Wstaw kod', + code : 'Kod', + edit : 'Edytuj', + notEmpty: 'Pole z kodem nie może być puste.' +}); \ No newline at end of file diff --git a/openslides/core/static/ckeditor/ckeditor/plugins/insertpre/plugin.js b/openslides/core/static/ckeditor/ckeditor/plugins/insertpre/plugin.js new file mode 100644 index 000000000..b4a1d835f --- /dev/null +++ b/openslides/core/static/ckeditor/ckeditor/plugins/insertpre/plugin.js @@ -0,0 +1,131 @@ +/* + Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. + For licensing, see LICENSE.html or http://ckeditor.com/license + */ + +CKEDITOR.plugins.add( 'insertpre', + { + requires: 'dialog', + lang : 'en,pl', // %REMOVE_LINE_CORE% + icons: 'insertpre', // %REMOVE_LINE_CORE% + onLoad : function() + { + if ( CKEDITOR.config.insertpre_class ) + { + CKEDITOR.addCss( + 'pre.' + CKEDITOR.config.insertpre_class + ' {' + + CKEDITOR.config.insertpre_style + + '}' + ); + } + }, + init : function( editor ) + { + // allowed and required content is the same for this plugin + var required = CKEDITOR.config.insertpre_class ? ( 'pre( ' + CKEDITOR.config.insertpre_class + ' )' ) : 'pre'; + editor.addCommand( 'insertpre', new CKEDITOR.dialogCommand( 'insertpre', { + allowedContent : required, + requiredContent : required + } ) ); + editor.ui.addButton && editor.ui.addButton( 'InsertPre', + { + label : editor.lang.insertpre.title, + icon : this.path + 'icons/insertpre.png', + command : 'insertpre', + toolbar: 'insert,99' + } ); + + if ( editor.contextMenu ) + { + editor.addMenuGroup( 'code' ); + editor.addMenuItem( 'insertpre', + { + label : editor.lang.insertpre.edit, + icon : this.path + 'icons/insertpre.png', + command : 'insertpre', + group : 'code' + }); + editor.contextMenu.addListener( function( element ) + { + if ( element ) + element = element.getAscendant( 'pre', true ); + if ( element && !element.isReadOnly() && element.hasClass( editor.config.insertpre_class ) ) + return { insertpre : CKEDITOR.TRISTATE_OFF }; + return null; + }); + } + + CKEDITOR.dialog.add( 'insertpre', function( editor ) + { + return { + title : editor.lang.insertpre.title, + minWidth : 540, + minHeight : 380, + contents : [ + { + id : 'general', + label : editor.lang.insertpre.code, + elements : [ + { + type : 'textarea', + id : 'contents', + label : editor.lang.insertpre.code, + cols: 140, + rows: 22, + validate : CKEDITOR.dialog.validate.notEmpty( editor.lang.insertpre.notEmpty ), + required : true, + setup : function( element ) + { + var html = element.getHtml(); + if ( html ) + { + var div = document.createElement( 'div' ); + div.innerHTML = html; + this.setValue( div.firstChild.nodeValue ); + } + }, + commit : function( element ) + { + element.setHtml( CKEDITOR.tools.htmlEncode( this.getValue() ) ); + } + } + ] + } + ], + onShow : function() + { + var sel = editor.getSelection(), + element = sel.getStartElement(); + if ( element ) + element = element.getAscendant( 'pre', true ); + + if ( !element || element.getName() != 'pre' || !element.hasClass( editor.config.insertpre_class ) ) + { + element = editor.document.createElement( 'pre' ); + this.insertMode = true; + } + else + this.insertMode = false; + + this.pre = element; + this.setupContent( this.pre ); + }, + onOk : function() + { + if ( editor.config.insertpre_class ) + this.pre.setAttribute( 'class', editor.config.insertpre_class ); + + if ( this.insertMode ) + editor.insertElement( this.pre ); + + this.commitContent( this.pre ); + } + }; + } ); + } + } ); + +if (typeof(CKEDITOR.config.insertpre_style) == 'undefined') + CKEDITOR.config.insertpre_style = 'background-color:#F8F8F8;border:1px solid #DDD;padding:10px;'; +if (typeof(CKEDITOR.config.insertpre_class) == 'undefined') + CKEDITOR.config.insertpre_class = 'prettyprint'; \ No newline at end of file diff --git a/openslides/core/static/css/base.css b/openslides/core/static/css/base.css index 869401b25..bb622b5d1 100644 --- a/openslides/core/static/css/base.css +++ b/openslides/core/static/css/base.css @@ -194,6 +194,12 @@ legend + .control-group { font-weight: bold; } +/* ckeditor plugin insertpre: textarea style */ +table.cke_dialog_contents textarea { + font-family: monospace !important; +} + + /** Left sidebar navigation **/ .leftmenu ul { margin: 0; diff --git a/openslides/core/static/js/ckeditor-config.js b/openslides/core/static/js/ckeditor-config.js deleted file mode 100644 index 5d4831802..000000000 --- a/openslides/core/static/js/ckeditor-config.js +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Configuration file for the CKeditor - */ -var ck_options = { - - // Using a custom CSS file allows us to specifically style elements entered - // using the editor. Using the CSS prefix class .ckeditor_html prevents these - // styles from meddling with the main layout - - contentsCss: "/static/css/ckeditor.css", - bodyClass: "ckeditor_html", - - allowedContent: - 'h1 h2 h3 pre b i u strike em;' + - - // A workaround for the problem described in http://dev.ckeditor.com/ticket/10192 - // Hopefully, the problem will be solved in the final version of CKEditor 4.1 - // If so, then {margin-left} can be removed - 'p{margin-left};' + - - 'a[!href];' + - 'ol ul{list-style};' + - 'li;' + - 'span{color,background-color};', - removePlugins: "save, print, preview, pagebreak, templates, showblocks, magicline", - - // Not part of the standard package of CKEditor - // http://ckeditor.com/addon/insertpre - extraPlugins: "insertpre", - - toolbar_Full: [ - { name: 'document', items : [ 'Source','-','Save','DocProps','Preview','Print','-','Templates' ] }, - { name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] }, - { name: 'editing', items : [ 'Find','Replace','-','SpellChecker', 'Scayt' ] }, - { name: 'forms', items : [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ] }, - { name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] }, - { name: 'paragraph', items : [ 'NumberedList','BulletedList','-','Pre','InsertPre','CreateDiv','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl' ] }, - { name: 'links', items : [ 'Link','Unlink','Anchor' ] }, - { name: 'styles', items : [ 'Format','FontSize','TextColor','BGColor' ] }, - { name: 'tools', items : [ 'Maximize', 'ShowBlocks','-','About' ] } - ], - toolbar: 'Full' -}; diff --git a/openslides/global_settings.py b/openslides/global_settings.py index c52421340..cd105bfcf 100644 --- a/openslides/global_settings.py +++ b/openslides/global_settings.py @@ -135,7 +135,6 @@ INSTALLED_PLUGINS = collect_plugins() # CKeditor settings CKEDITOR_DEFAULT_CONFIG = {'toolbar': 'Full', - 'contentsCss': '/static/css/ckeditor.css', 'bodyClass': 'ckeditor_html', 'allowedContent': 'h1 h2 h3 pre b i u strike em; ' @@ -148,14 +147,16 @@ CKEDITOR_DEFAULT_CONFIG = {'toolbar': 'Full', 'a[!href]; ' 'ol ul{list-style}; ' 'li; ' + 'pre; ' 'span{color,background-color}; ', 'removePlugins': 'save, print, preview, pagebreak, templates, showblocks, magicline', + 'extraPlugins': 'insertpre', # see http://ckeditor.com/addon/insertpre 'toolbar_Full': [ {'name': 'document', 'items': ['Source', '-', 'Save', 'DocProps', 'Preview', 'Print', '-', 'Templates']}, {'name': 'clipboard', 'items': ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo']}, {'name': 'editing', 'items': ['Find', 'Replace', '-', 'SpellChecker', 'Scayt']}, {'name': 'basicstyles', 'items': ['Bold', 'Italic', 'Underline', 'Strike', '-', 'RemoveFormat']}, - {'name': 'paragraph', 'items': ['NumberedList', 'BulletedList', '-', 'Pre', 'InsertPre']}, + {'name': 'paragraph', 'items': ['NumberedList', 'BulletedList', '-', 'InsertPre']}, {'name': 'links', 'items': ['Link', 'Unlink']}, {'name': 'styles', 'items': ['Format', 'TextColor', 'BGColor']}, {'name': 'tools', 'items': ['Maximize', 'ShowBlocks', '-', 'About']} diff --git a/openslides/motion/templates/motion/motion_form.html b/openslides/motion/templates/motion/motion_form.html index 9a8fe9c15..e6831009f 100644 --- a/openslides/motion/templates/motion/motion_form.html +++ b/openslides/motion/templates/motion/motion_form.html @@ -7,7 +7,6 @@ {% block header %} {{ block.super }} - {% endblock %} diff --git a/openslides/utils/forms.py b/openslides/utils/forms.py index 1dfe2404c..ca4db1a7c 100644 --- a/openslides/utils/forms.py +++ b/openslides/utils/forms.py @@ -29,7 +29,8 @@ HTML_TAG_WHITELIST = ('a', HTML_ATTRIBUTES_WHITELIST = { 'a': ['href'], '*': ['style'], - 'img': ['src'], + 'pre': ['class'], + 'img': ['src', 'width', 'height'], } HTML_STYLES_WHITELIST = ('color', 'background-color', 'list-style', 'width', 'height')