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 : 350, 10 minHeight : 150, 11 onShow : function() 12 { 13 delete this.button; 14 var element = this.getParentEditor().getSelection().getSelectedElement(); 15 if ( element && element.getName() == "input" ) 16 { 17 var type = element.getAttribute( 'type' ); 18 if ( type == "button" || type == "reset" || type == "submit" ) 19 { 20 this.button = element; 21 this.setupContent( element ); 22 } 23 } 24 }, 25 onOk : function() 26 { 27 var editor, 28 element = this.button, 29 isInsertMode = !element; 30 31 if ( isInsertMode ) 32 { 33 editor = this.getParentEditor(); 34 element = editor.document.createElement( 'input' ); 35 } 36 37 if ( isInsertMode ) 38 editor.insertElement( element ); 39 this.commitContent( { element : element } ); 40 }, 41 contents : [ 42 { 43 id : 'info', 44 label : editor.lang.button.title, 45 title : editor.lang.button.title, 46 elements : [ 47 { 48 id : '_cke_saved_name', 49 type : 'text', 50 label : editor.lang.common.name, 51 'default' : '', 52 setup : function( element ) 53 { 54 this.setValue( 55 element.getAttribute( '_cke_saved_name' ) || 56 element.getAttribute( 'name' ) || 57 '' ); 58 }, 59 commit : function( data ) 60 { 61 var element = data.element; 62 63 if ( this.getValue() ) 64 element.setAttribute( '_cke_saved_name', this.getValue() ); 65 else 66 { 67 element.removeAttribute( '_cke_saved_name' ); 68 element.removeAttribute( 'name' ); 69 } 70 } 71 }, 72 { 73 id : 'value', 74 type : 'text', 75 label : editor.lang.button.text, 76 accessKey : 'V', 77 'default' : '', 78 setup : function( element ) 79 { 80 this.setValue( element.getAttribute( 'value' ) || '' ); 81 }, 82 commit : function( data ) 83 { 84 var element = data.element; 85 86 if ( this.getValue() ) 87 element.setAttribute( 'value', this.getValue() ); 88 else 89 element.removeAttribute( 'value' ); 90 } 91 }, 92 { 93 id : 'type', 94 type : 'select', 95 label : editor.lang.button.type, 96 'default' : 'button', 97 accessKey : 'T', 98 items : 99 [ 100 [ editor.lang.button.typeBtn, 'button' ], 101 [ editor.lang.button.typeSbm, 'submit' ], 102 [ editor.lang.button.typeRst, 'reset' ] 103 ], 104 setup : function( element ) 105 { 106 this.setValue( element.getAttribute( 'type' ) || '' ); 107 }, 108 commit : function( data ) 109 { 110 var element = data.element; 111 112 if ( CKEDITOR.env.ie ) 113 { 114 var elementType = element.getAttribute( 'type' ); 115 var currentType = this.getValue(); 116 117 if ( currentType != elementType ) 118 { 119 var replace = CKEDITOR.dom.element.createFromHtml( '<input type="' + currentType + 120 '"></input>', editor.document ); 121 element.copyAttributes( replace, { type : 1 } ); 122 replace.replace( element ); 123 editor.getSelection().selectElement( replace ); 124 data.element = replace; 125 } 126 } 127 else 128 element.setAttribute( 'type', this.getValue() ); 129 } 130 } 131 ] 132 } 133 ] 134 }; 135 }); 136