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( 'textfield', function( editor ) 6 { 7 return { 8 title : editor.lang.textfield.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" && ( element.getAttribute( 'type' ) == "text" && !element.getAttribute( 'type' ) ) ) 19 { 20 this._element = element; 21 this.setupContent( element ); 22 } 23 }, 24 onOk : function() 25 { 26 var editor, 27 element = this._element, 28 isInsertMode = !element; 29 30 if ( isInsertMode ) 31 { 32 editor = this.getParentEditor(); 33 element = editor.document.createElement( 'input' ); 34 element.setAttribute( 'type', 'text' ); 35 } 36 this.commitContent( element ); 37 38 if ( isInsertMode ) 39 { 40 this.restoreSelection(); 41 this.clearSavedSelection(); 42 editor.insertElement( element ); 43 } 44 }, 45 contents : [ 46 { 47 id : 'info', 48 label : editor.lang.textfield.title, 49 title : editor.lang.textfield.title, 50 elements : [ 51 { 52 type : 'hbox', 53 widths : [ '50%', '50%' ], 54 children : 55 [ 56 { 57 id : 'txtName', 58 type : 'text', 59 label : editor.lang.textfield.name, 60 'default' : '', 61 accessKey : 'N', 62 setup : function( element ) 63 { 64 this.setValue( element.getAttribute( 'name' ) ); 65 this.focus(); 66 }, 67 commit : function( element ) 68 { 69 if ( this.getValue() != '' || this.isChanged() ) 70 element.setAttribute( 'name', this.getValue() ); 71 } 72 }, 73 { 74 id : 'txtValue', 75 type : 'text', 76 label : editor.lang.textfield.value, 77 'default' : '', 78 accessKey : 'V', 79 setup : function( element ) 80 { 81 this.setValue( element.getAttribute( 'value' ) ); 82 }, 83 commit : function( element ) 84 { 85 if ( this.getValue() != '' || this.isChanged() ) 86 element.setAttribute( 'value', this.getValue() ); 87 } 88 } 89 ] 90 }, 91 { 92 type : 'hbox', 93 widths : [ '50%', '50%' ], 94 children : 95 [ 96 { 97 id : 'txtTextCharWidth', 98 type : 'text', 99 label : editor.lang.textfield.charWidth, 100 'default' : '', 101 accessKey : 'C', 102 style : 'width:50px', 103 validate: function() 104 { 105 var func = CKEDITOR.dialog.validate.integer( editor.lang.common.validateNumberFailed ); 106 return isValid = func.apply( this ); 107 }, 108 setup : function( element ) 109 { 110 this.setValue( element.getAttribute( 'size' ) ); 111 }, 112 commit : function( element ) 113 { 114 if ( this.getValue() != '' || this.isChanged() ) 115 element.setAttribute( 'size', this.getValue() ); 116 } 117 }, 118 { 119 id : 'txtMaxChars', 120 type : 'text', 121 label : editor.lang.textfield.maxChars, 122 'default' : '', 123 accessKey : 'M', 124 style : 'width:50px', 125 validate: function() 126 { 127 var func = CKEDITOR.dialog.validate.integer( editor.lang.common.validateNumberFailed ); 128 return isValid = func.apply( this ); 129 }, 130 setup : function( element ) 131 { 132 this.setValue( element.getAttribute( 'maxlength' ) ); 133 }, 134 commit : function( element ) 135 { 136 if ( this.getValue() != '' || this.isChanged() ) 137 element.setAttribute( 'maxlength', this.getValue() ); 138 } 139 } 140 ] 141 }, 142 { 143 id : 'cmbType', 144 type : 'select', 145 label : editor.lang.textfield.type, 146 'default' : 'text', 147 accessKey : 'M', 148 items : 149 [ 150 [ editor.lang.textfield.typeText, 'text' ], 151 [ editor.lang.textfield.typePass, 'pass' ], 152 ], 153 setup : function( element ) 154 { 155 this.setValue( element.getAttribute( 'type' ) ); 156 }, 157 commit : function( element ) 158 { 159 element.setAttribute( 'type', this.getValue() ); 160 } 161 } 162 ] 163 } 164 ] 165 }; 166 }); 167