1 /*
  2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
  3 For licensing, see LICENSE.html or http://ckeditor.com/license
  4 */
  5 CKEDITOR.dialog.add( 'button', function( editor )
  6 {
  7 	return {
  8 		title : editor.lang.button.title,
  9 		minWidth : 400,
 10 		minHeight : 230,
 11 		onShow : function()
 12 		{
 13 			// IE BUG: Selection must be in the editor for getSelectedElement()
 14 			// to work.
 15 			this.restoreSelection();
 16
 17 			var element = this.getParentEditor().getSelection().getSelectedElement();
 18 			if ( element && element.getName() == "input" )
 19 			{
 20 				var type = element.getAttribute( 'type' );
 21 				if ( type == "button" || type == "reset" || type == "submit" )
 22 				{
 23 					this._element = element;
 24 					this.setupContent( element );
 25 				}
 26 			}
 27 		},
 28 		onOk : function()
 29 		{
 30 			var editor,
 31 				element = this._element,
 32 				isInsertMode = !element;
 33
 34 			if ( isInsertMode )
 35 			{
 36 				editor = this.getParentEditor();
 37 				element = editor.document.createElement( 'input' );
 38 			}
 39 			this.commitContent( element );
 40
 41 			if ( isInsertMode )
 42 			{
 43 				this.restoreSelection();
 44 				this.clearSavedSelection();
 45 				editor.insertElement( element );
 46 			}
 47 		},
 48 		contents : [
 49 			{
 50 				id : 'info',
 51 				label : editor.lang.button.title,
 52 				title : editor.lang.button.title,
 53 				elements : [
 54 					{
 55 						id : 'txtName',
 56 						type : 'text',
 57 						label : editor.lang.common.name,
 58 						'default' : '',
 59 						setup : function( element )
 60 						{
 61 							this.setValue( element.getAttribute( 'name' ) );
 62 							this.focus();
 63 						},
 64 						commit : function( element )
 65 						{
 66 							if ( this.getValue() != '' || this.isChanged() )
 67 								element.setAttribute( 'name', this.getValue() );
 68 						}
 69 					},
 70 					{
 71 						id : 'txtValue',
 72 						type : 'text',
 73 						label : editor.lang.button.text,
 74 						accessKey : 'V',
 75 						'default' : '',
 76 						setup : function( element )
 77 						{
 78 							this.setValue( element.getAttribute( 'value' ) );
 79 						},
 80 						commit : function( element )
 81 						{
 82 							if ( this.getValue() != '' || this.isChanged() )
 83 								element.setAttribute( 'value', this.getValue() );
 84 						}
 85 					},
 86 					{
 87 						id : 'txtType',
 88 						type : 'select',
 89 						label : editor.lang.button.type,
 90 						'default' : 'button',
 91 						accessKey : 'T',
 92 						items :
 93 						[
 94 							[ editor.lang.button.typeBtn, 'button' ],
 95 							[ editor.lang.button.typeSbm, 'submit' ],
 96 							[ editor.lang.button.typeRst, 'reset' ]
 97 						],
 98 						setup : function( element )
 99 						{
100 							this.setValue( element.getAttribute( 'type' ) );
101 						},
102 						commit : function( element )
103 						{
104 							element.setAttribute( 'type', this.getValue() );
105 						}
106 					}
107 				]
108 			}
109 		]
110 	};
111 });
112