From 7adcb81e4f83f98c468889aaa5a85558ba88c770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Mon, 25 Jan 2016 17:45:33 +0100 Subject: Initial commit --- sources/plugins/forms/dialogs/button.js | 100 ++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 sources/plugins/forms/dialogs/button.js (limited to 'sources/plugins/forms/dialogs/button.js') diff --git a/sources/plugins/forms/dialogs/button.js b/sources/plugins/forms/dialogs/button.js new file mode 100644 index 00000000..b0dd161c --- /dev/null +++ b/sources/plugins/forms/dialogs/button.js @@ -0,0 +1,100 @@ +/** + * @license Copyright (c) 2003-2015, 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', + bidi: true, + 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 + } + ] + } ] + }; +} ); -- cgit v1.2.3