diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-01-25 17:45:33 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-01-25 18:00:33 +0100 |
commit | 7adcb81e4f83f98c468889aaa5a85558ba88c770 (patch) | |
tree | 0d6ede733777b29060b48df4afaa2c64bfbae276 /sources/plugins/forms/dialogs/checkbox.js | |
download | connexionswing-ckeditor-component-4.5.6.tar.gz connexionswing-ckeditor-component-4.5.6.tar.zst connexionswing-ckeditor-component-4.5.6.zip |
Initial commit4.5.6
Diffstat (limited to 'sources/plugins/forms/dialogs/checkbox.js')
-rw-r--r-- | sources/plugins/forms/dialogs/checkbox.js | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/sources/plugins/forms/dialogs/checkbox.js b/sources/plugins/forms/dialogs/checkbox.js new file mode 100644 index 00000000..0bfda9ba --- /dev/null +++ b/sources/plugins/forms/dialogs/checkbox.js | |||
@@ -0,0 +1,146 @@ | |||
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( 'checkbox', function( editor ) { | ||
7 | return { | ||
8 | title: editor.lang.forms.checkboxAndRadio.checkboxTitle, | ||
9 | minWidth: 350, | ||
10 | minHeight: 140, | ||
11 | onShow: function() { | ||
12 | delete this.checkbox; | ||
13 | |||
14 | var element = this.getParentEditor().getSelection().getSelectedElement(); | ||
15 | |||
16 | if ( element && element.getAttribute( 'type' ) == 'checkbox' ) { | ||
17 | this.checkbox = element; | ||
18 | this.setupContent( element ); | ||
19 | } | ||
20 | }, | ||
21 | onOk: function() { | ||
22 | var editor, | ||
23 | element = this.checkbox, | ||
24 | isInsertMode = !element; | ||
25 | |||
26 | if ( isInsertMode ) { | ||
27 | editor = this.getParentEditor(); | ||
28 | element = editor.document.createElement( 'input' ); | ||
29 | element.setAttribute( 'type', 'checkbox' ); | ||
30 | editor.insertElement( element ); | ||
31 | } | ||
32 | this.commitContent( { element: element } ); | ||
33 | }, | ||
34 | contents: [ { | ||
35 | id: 'info', | ||
36 | label: editor.lang.forms.checkboxAndRadio.checkboxTitle, | ||
37 | title: editor.lang.forms.checkboxAndRadio.checkboxTitle, | ||
38 | startupFocus: 'txtName', | ||
39 | elements: [ { | ||
40 | id: 'txtName', | ||
41 | type: 'text', | ||
42 | label: editor.lang.common.name, | ||
43 | 'default': '', | ||
44 | accessKey: 'N', | ||
45 | setup: function( element ) { | ||
46 | this.setValue( element.data( 'cke-saved-name' ) || element.getAttribute( 'name' ) || '' ); | ||
47 | }, | ||
48 | commit: function( data ) { | ||
49 | var element = data.element; | ||
50 | |||
51 | // IE failed to update 'name' property on input elements, protect it now. | ||
52 | if ( this.getValue() ) | ||
53 | element.data( 'cke-saved-name', this.getValue() ); | ||
54 | else { | ||
55 | element.data( 'cke-saved-name', false ); | ||
56 | element.removeAttribute( 'name' ); | ||
57 | } | ||
58 | } | ||
59 | }, | ||
60 | { | ||
61 | id: 'txtValue', | ||
62 | type: 'text', | ||
63 | label: editor.lang.forms.checkboxAndRadio.value, | ||
64 | 'default': '', | ||
65 | accessKey: 'V', | ||
66 | setup: function( element ) { | ||
67 | var value = element.getAttribute( 'value' ); | ||
68 | // IE Return 'on' as default attr value. | ||
69 | this.setValue( CKEDITOR.env.ie && value == 'on' ? '' : value ); | ||
70 | }, | ||
71 | commit: function( data ) { | ||
72 | var element = data.element, | ||
73 | value = this.getValue(); | ||
74 | |||
75 | if ( value && !( CKEDITOR.env.ie && value == 'on' ) ) | ||
76 | element.setAttribute( 'value', value ); | ||
77 | else { | ||
78 | if ( CKEDITOR.env.ie ) { | ||
79 | // Remove attribute 'value' of checkbox (#4721). | ||
80 | var checkbox = new CKEDITOR.dom.element( 'input', element.getDocument() ); | ||
81 | element.copyAttributes( checkbox, { value: 1 } ); | ||
82 | checkbox.replace( element ); | ||
83 | editor.getSelection().selectElement( checkbox ); | ||
84 | data.element = checkbox; | ||
85 | } else { | ||
86 | element.removeAttribute( 'value' ); | ||
87 | } | ||
88 | } | ||
89 | } | ||
90 | }, | ||
91 | { | ||
92 | id: 'cmbSelected', | ||
93 | type: 'checkbox', | ||
94 | label: editor.lang.forms.checkboxAndRadio.selected, | ||
95 | 'default': '', | ||
96 | accessKey: 'S', | ||
97 | value: 'checked', | ||
98 | setup: function( element ) { | ||
99 | this.setValue( element.getAttribute( 'checked' ) ); | ||
100 | }, | ||
101 | commit: function( data ) { | ||
102 | var element = data.element; | ||
103 | |||
104 | if ( CKEDITOR.env.ie ) { | ||
105 | var isElementChecked = !!element.getAttribute( 'checked' ), | ||
106 | isChecked = !!this.getValue(); | ||
107 | |||
108 | if ( isElementChecked != isChecked ) { | ||
109 | var replace = CKEDITOR.dom.element.createFromHtml( '<input type="checkbox"' + ( isChecked ? ' checked="checked"' : '' ) + | ||
110 | '/>', editor.document ); | ||
111 | |||
112 | element.copyAttributes( replace, { type: 1, checked: 1 } ); | ||
113 | replace.replace( element ); | ||
114 | editor.getSelection().selectElement( replace ); | ||
115 | data.element = replace; | ||
116 | } | ||
117 | } else { | ||
118 | var value = this.getValue(); | ||
119 | if ( value ) | ||
120 | element.setAttribute( 'checked', 'checked' ); | ||
121 | else | ||
122 | element.removeAttribute( 'checked' ); | ||
123 | } | ||
124 | } | ||
125 | }, | ||
126 | { | ||
127 | id: 'required', | ||
128 | type: 'checkbox', | ||
129 | label: editor.lang.forms.checkboxAndRadio.required, | ||
130 | 'default': '', | ||
131 | accessKey: 'Q', | ||
132 | value: 'required', | ||
133 | setup: function( element ) { | ||
134 | this.setValue( element.getAttribute( 'required' ) ); | ||
135 | }, | ||
136 | commit: function( data ) { | ||
137 | var element = data.element; | ||
138 | if ( this.getValue() ) | ||
139 | element.setAttribute( 'required', 'required' ); | ||
140 | else | ||
141 | element.removeAttribute( 'required' ); | ||
142 | } | ||
143 | } ] | ||
144 | } ] | ||
145 | }; | ||
146 | } ); | ||