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