]> git.immae.eu Git - perso/Immae/Projets/packagist/connexionswing-ckeditor-component.git/blob - sources/plugins/forms/dialogs/button.js
Initial commit
[perso/Immae/Projets/packagist/connexionswing-ckeditor-component.git] / sources / plugins / forms / dialogs / button.js
1 /**
2 * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
3 * For licensing, see LICENSE.md or http://ckeditor.com/license
4 */
5
6 CKEDITOR.dialog.add( 'button', function( editor ) {
7 function commitAttributes( element ) {
8 var val = this.getValue();
9 if ( val ) {
10 element.attributes[ this.id ] = val;
11 if ( this.id == 'name' )
12 element.attributes[ 'data-cke-saved-name' ] = val;
13 } else {
14 delete element.attributes[ this.id ];
15 if ( this.id == 'name' )
16 delete element.attributes[ 'data-cke-saved-name' ];
17 }
18 }
19
20 return {
21 title: editor.lang.forms.button.title,
22 minWidth: 350,
23 minHeight: 150,
24 onShow: function() {
25 delete this.button;
26 var element = this.getParentEditor().getSelection().getSelectedElement();
27 if ( element && element.is( 'input' ) ) {
28 var type = element.getAttribute( 'type' );
29 if ( type in { button: 1, reset: 1, submit: 1 } ) {
30 this.button = element;
31 this.setupContent( element );
32 }
33 }
34 },
35 onOk: function() {
36 var editor = this.getParentEditor(),
37 element = this.button,
38 isInsertMode = !element;
39
40 var fake = element ? CKEDITOR.htmlParser.fragment.fromHtml( element.getOuterHtml() ).children[ 0 ] : new CKEDITOR.htmlParser.element( 'input' );
41 this.commitContent( fake );
42
43 var writer = new CKEDITOR.htmlParser.basicWriter();
44 fake.writeHtml( writer );
45 var newElement = CKEDITOR.dom.element.createFromHtml( writer.getHtml(), editor.document );
46
47 if ( isInsertMode )
48 editor.insertElement( newElement );
49 else {
50 newElement.replace( element );
51 editor.getSelection().selectElement( newElement );
52 }
53 },
54 contents: [ {
55 id: 'info',
56 label: editor.lang.forms.button.title,
57 title: editor.lang.forms.button.title,
58 elements: [
59 {
60 id: 'name',
61 type: 'text',
62 bidi: true,
63 label: editor.lang.common.name,
64 'default': '',
65 setup: function( element ) {
66 this.setValue( element.data( 'cke-saved-name' ) || element.getAttribute( 'name' ) || '' );
67 },
68 commit: commitAttributes
69 },
70 {
71 id: 'value',
72 type: 'text',
73 label: editor.lang.forms.button.text,
74 accessKey: 'V',
75 'default': '',
76 setup: function( element ) {
77 this.setValue( element.getAttribute( 'value' ) || '' );
78 },
79 commit: commitAttributes
80 },
81 {
82 id: 'type',
83 type: 'select',
84 label: editor.lang.forms.button.type,
85 'default': 'button',
86 accessKey: 'T',
87 items: [
88 [ editor.lang.forms.button.typeBtn, 'button' ],
89 [ editor.lang.forms.button.typeSbm, 'submit' ],
90 [ editor.lang.forms.button.typeRst, 'reset' ]
91 ],
92 setup: function( element ) {
93 this.setValue( element.getAttribute( 'type' ) || '' );
94 },
95 commit: commitAttributes
96 }
97 ]
98 } ]
99 };
100 } );