File: customwidget.js

package info (click to toggle)
ckeditor 4.16.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 258,804 kB
  • sloc: javascript: 239,590; sh: 184; makefile: 64; python: 37; php: 15; xml: 5
file content (54 lines) | stat: -rw-r--r-- 1,509 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
CKEDITOR.addCss(
	'.customwidget {' +
		'border: 2px dashed black;' +
		'padding: 0 15px;' +
		'background-color: #BBFFF0' +
	'}' +
	'.customwidget h2 {' +
		'margin-top: 15px;' +
		'font-size: 24px;' +
		'color: red;' +
		'font-weight: 700;' +
		'text-align: center;' +
	'}' +
	'.customwidget__instruction {' +
		'font-weight: 700;' +
		'margin-left: 30px;' +
	'}' +
	'.customwidget__title {' +
		'font-size: 20px;' +
		'text-align: center;' +
		'background-color: #ffffff;' +
	'}' +
	'.customwidget__content {' +
		'background-color: #ffffff;' +
	'}'
);

CKEDITOR.plugins.add( 'customwidget', {
	requires: 'widget',
	allowedContent: 'div',

	init: function( editor ) {
		editor.widgets.add( 'customwidget', {
			button: 'Create custom widget',
			template: '<div class="customwidget"><h2>Awesome widget!!!</h2><h3 class="customwidget__title">Type here some title</h3>' +
				'<p class="customwidget__instruction">Below is place to add some fancy text.</p><p class="customwidget__content">Type here something</p></div>',
			editables: {
				title: {
					selector: '.customwidget__title',
					allowedContent: 'br strong em'
				},
				content: {
					selector: '.customwidget__content',
					allowedContent: 'br strong em span{*}'
				}
			},
			allowedContent: 'div(!customwidget);h3(!customwidget__title);p(!customwidget__content);h2;p;',
			requiredContent: 'div(customwidget)',
			upcast: function( element ) {
				return element.name == 'div' && element.hasClass( 'customwidget' );
			}
		} );
	}
} );