File: button.js

package info (click to toggle)
ckeditor 4.4.4%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 25,632 kB
  • ctags: 2,419
  • sloc: sh: 190; python: 37; makefile: 29; php: 15; xml: 5
file content (100 lines) | stat: -rw-r--r-- 2,772 bytes parent folder | download
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
 * @license Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved.
 * For licensing, see LICENSE.md or http://ckeditor.com/license
 */
CKEDITOR.dialog.add( 'button', function( editor ) {
	function commitAttributes( element ) {
		var val = this.getValue();
		if ( val ) {
			element.attributes[ this.id ] = val;
			if ( this.id == 'name' )
				element.attributes[ 'data-cke-saved-name' ] = val;
		} else {
			delete element.attributes[ this.id ];
			if ( this.id == 'name' )
				delete element.attributes[ 'data-cke-saved-name' ];
		}
	}

	return {
		title: editor.lang.forms.button.title,
		minWidth: 350,
		minHeight: 150,
		onShow: function() {
			delete this.button;
			var element = this.getParentEditor().getSelection().getSelectedElement();
			if ( element && element.is( 'input' ) ) {
				var type = element.getAttribute( 'type' );
				if ( type in { button: 1, reset: 1, submit: 1 } ) {
					this.button = element;
					this.setupContent( element );
				}
			}
		},
		onOk: function() {
			var editor = this.getParentEditor(),
				element = this.button,
				isInsertMode = !element;

			var fake = element ? CKEDITOR.htmlParser.fragment.fromHtml( element.getOuterHtml() ).children[ 0 ] : new CKEDITOR.htmlParser.element( 'input' );
			this.commitContent( fake );

			var writer = new CKEDITOR.htmlParser.basicWriter();
			fake.writeHtml( writer );
			var newElement = CKEDITOR.dom.element.createFromHtml( writer.getHtml(), editor.document );

			if ( isInsertMode )
				editor.insertElement( newElement );
			else {
				newElement.replace( element );
				editor.getSelection().selectElement( newElement );
			}
		},
		contents: [
			{
			id: 'info',
			label: editor.lang.forms.button.title,
			title: editor.lang.forms.button.title,
			elements: [
				{
				id: 'name',
				type: 'text',
				label: editor.lang.common.name,
				'default': '',
				setup: function( element ) {
					this.setValue( element.data( 'cke-saved-name' ) || element.getAttribute( 'name' ) || '' );
				},
				commit: commitAttributes
			},
				{
				id: 'value',
				type: 'text',
				label: editor.lang.forms.button.text,
				accessKey: 'V',
				'default': '',
				setup: function( element ) {
					this.setValue( element.getAttribute( 'value' ) || '' );
				},
				commit: commitAttributes
			},
				{
				id: 'type',
				type: 'select',
				label: editor.lang.forms.button.type,
				'default': 'button',
				accessKey: 'T',
				items: [
					[ editor.lang.forms.button.typeBtn, 'button' ],
					[ editor.lang.forms.button.typeSbm, 'submit' ],
					[ editor.lang.forms.button.typeRst, 'reset' ]
					],
				setup: function( element ) {
					this.setValue( element.getAttribute( 'type' ) || '' );
				},
				commit: commitAttributes
			}
			]
		}
		]
	};
} );