diff options
Diffstat (limited to 'sources/plugins/forms/dialogs/hiddenfield.js')
-rw-r--r-- | sources/plugins/forms/dialogs/hiddenfield.js | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/sources/plugins/forms/dialogs/hiddenfield.js b/sources/plugins/forms/dialogs/hiddenfield.js new file mode 100644 index 00000000..b4e0fe3b --- /dev/null +++ b/sources/plugins/forms/dialogs/hiddenfield.js | |||
@@ -0,0 +1,83 @@ | |||
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( 'hiddenfield', function( editor ) { | ||
7 | return { | ||
8 | title: editor.lang.forms.hidden.title, | ||
9 | hiddenField: null, | ||
10 | minWidth: 350, | ||
11 | minHeight: 110, | ||
12 | onShow: function() { | ||
13 | delete this.hiddenField; | ||
14 | |||
15 | var editor = this.getParentEditor(), | ||
16 | selection = editor.getSelection(), | ||
17 | element = selection.getSelectedElement(); | ||
18 | |||
19 | if ( element && element.data( 'cke-real-element-type' ) && element.data( 'cke-real-element-type' ) == 'hiddenfield' ) { | ||
20 | this.hiddenField = element; | ||
21 | element = editor.restoreRealElement( this.hiddenField ); | ||
22 | this.setupContent( element ); | ||
23 | selection.selectElement( this.hiddenField ); | ||
24 | } | ||
25 | }, | ||
26 | onOk: function() { | ||
27 | var name = this.getValueOf( 'info', '_cke_saved_name' ), | ||
28 | editor = this.getParentEditor(), | ||
29 | element = CKEDITOR.env.ie && CKEDITOR.document.$.documentMode < 8 ? | ||
30 | editor.document.createElement( '<input name="' + CKEDITOR.tools.htmlEncode( name ) + '">' ) : | ||
31 | editor.document.createElement( 'input' ); | ||
32 | |||
33 | element.setAttribute( 'type', 'hidden' ); | ||
34 | this.commitContent( element ); | ||
35 | var fakeElement = editor.createFakeElement( element, 'cke_hidden', 'hiddenfield' ); | ||
36 | if ( !this.hiddenField ) | ||
37 | editor.insertElement( fakeElement ); | ||
38 | else { | ||
39 | fakeElement.replace( this.hiddenField ); | ||
40 | editor.getSelection().selectElement( fakeElement ); | ||
41 | } | ||
42 | return true; | ||
43 | }, | ||
44 | contents: [ { | ||
45 | id: 'info', | ||
46 | label: editor.lang.forms.hidden.title, | ||
47 | title: editor.lang.forms.hidden.title, | ||
48 | elements: [ { | ||
49 | id: '_cke_saved_name', | ||
50 | type: 'text', | ||
51 | label: editor.lang.forms.hidden.name, | ||
52 | 'default': '', | ||
53 | accessKey: 'N', | ||
54 | setup: function( element ) { | ||
55 | this.setValue( element.data( 'cke-saved-name' ) || element.getAttribute( 'name' ) || '' ); | ||
56 | }, | ||
57 | commit: function( element ) { | ||
58 | if ( this.getValue() ) | ||
59 | element.setAttribute( 'name', this.getValue() ); | ||
60 | else | ||
61 | element.removeAttribute( 'name' ); | ||
62 | |||
63 | } | ||
64 | }, | ||
65 | { | ||
66 | id: 'value', | ||
67 | type: 'text', | ||
68 | label: editor.lang.forms.hidden.value, | ||
69 | 'default': '', | ||
70 | accessKey: 'V', | ||
71 | setup: function( element ) { | ||
72 | this.setValue( element.getAttribute( 'value' ) || '' ); | ||
73 | }, | ||
74 | commit: function( element ) { | ||
75 | if ( this.getValue() ) | ||
76 | element.setAttribute( 'value', this.getValue() ); | ||
77 | else | ||
78 | element.removeAttribute( 'value' ); | ||
79 | } | ||
80 | } ] | ||
81 | } ] | ||
82 | }; | ||
83 | } ); | ||