[2000] | 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 | var autoAttributes =
|
---|
| 8 | {
|
---|
| 9 | value : 1,
|
---|
| 10 | size : 1,
|
---|
| 11 | maxLength : 1
|
---|
| 12 | };
|
---|
| 13 |
|
---|
| 14 | var acceptedTypes =
|
---|
| 15 | {
|
---|
| 16 | text : 1,
|
---|
| 17 | password : 1
|
---|
| 18 | };
|
---|
| 19 |
|
---|
| 20 | return {
|
---|
| 21 | title : editor.lang.textfield.title,
|
---|
| 22 | minWidth : 350,
|
---|
| 23 | minHeight : 150,
|
---|
| 24 | onShow : function()
|
---|
| 25 | {
|
---|
| 26 | delete this.textField;
|
---|
| 27 |
|
---|
| 28 | var element = this.getParentEditor().getSelection().getSelectedElement();
|
---|
| 29 | if ( element && element.getName() == "input" &&
|
---|
| 30 | ( acceptedTypes[ element.getAttribute( 'type' ) ] || !element.getAttribute( 'type' ) ) )
|
---|
| 31 | {
|
---|
| 32 | this.textField = element;
|
---|
| 33 | this.setupContent( element );
|
---|
| 34 | }
|
---|
| 35 | },
|
---|
| 36 | onOk : function()
|
---|
| 37 | {
|
---|
| 38 | var editor,
|
---|
| 39 | element = this.textField,
|
---|
| 40 | isInsertMode = !element;
|
---|
| 41 |
|
---|
| 42 | if ( isInsertMode )
|
---|
| 43 | {
|
---|
| 44 | editor = this.getParentEditor();
|
---|
| 45 | element = editor.document.createElement( 'input' );
|
---|
| 46 | element.setAttribute( 'type', 'text' );
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | if ( isInsertMode )
|
---|
| 50 | editor.insertElement( element );
|
---|
| 51 | this.commitContent( { element : element } );
|
---|
| 52 | },
|
---|
| 53 | onLoad : function()
|
---|
| 54 | {
|
---|
| 55 | var autoSetup = function( element )
|
---|
| 56 | {
|
---|
| 57 | var value = element.hasAttribute( this.id ) && element.getAttribute( this.id );
|
---|
| 58 | this.setValue( value || '' );
|
---|
| 59 | };
|
---|
| 60 |
|
---|
| 61 | var autoCommit = function( data )
|
---|
| 62 | {
|
---|
| 63 | var element = data.element;
|
---|
| 64 | var value = this.getValue();
|
---|
| 65 |
|
---|
| 66 | if ( value )
|
---|
| 67 | element.setAttribute( this.id, value );
|
---|
| 68 | else
|
---|
| 69 | element.removeAttribute( this.id );
|
---|
| 70 | };
|
---|
| 71 |
|
---|
| 72 | this.foreach( function( contentObj )
|
---|
| 73 | {
|
---|
| 74 | if ( autoAttributes[ contentObj.id ] )
|
---|
| 75 | {
|
---|
| 76 | contentObj.setup = autoSetup;
|
---|
| 77 | contentObj.commit = autoCommit;
|
---|
| 78 | }
|
---|
| 79 | } );
|
---|
| 80 | },
|
---|
| 81 | contents : [
|
---|
| 82 | {
|
---|
| 83 | id : 'info',
|
---|
| 84 | label : editor.lang.textfield.title,
|
---|
| 85 | title : editor.lang.textfield.title,
|
---|
| 86 | elements : [
|
---|
| 87 | {
|
---|
| 88 | type : 'hbox',
|
---|
| 89 | widths : [ '50%', '50%' ],
|
---|
| 90 | children :
|
---|
| 91 | [
|
---|
| 92 | {
|
---|
| 93 | id : '_cke_saved_name',
|
---|
| 94 | type : 'text',
|
---|
| 95 | label : editor.lang.textfield.name,
|
---|
| 96 | 'default' : '',
|
---|
| 97 | accessKey : 'N',
|
---|
| 98 | setup : function( element )
|
---|
| 99 | {
|
---|
| 100 | this.setValue(
|
---|
| 101 | element.getAttribute( '_cke_saved_name' ) ||
|
---|
| 102 | element.getAttribute( 'name' ) ||
|
---|
| 103 | '' );
|
---|
| 104 | },
|
---|
| 105 | commit : function( data )
|
---|
| 106 | {
|
---|
| 107 | var element = data.element;
|
---|
| 108 |
|
---|
| 109 | if ( this.getValue() )
|
---|
| 110 | element.setAttribute( '_cke_saved_name', this.getValue() );
|
---|
| 111 | else
|
---|
| 112 | {
|
---|
| 113 | element.removeAttribute( '_cke_saved_name' );
|
---|
| 114 | element.removeAttribute( 'name' );
|
---|
| 115 | }
|
---|
| 116 | }
|
---|
| 117 | },
|
---|
| 118 | {
|
---|
| 119 | id : 'value',
|
---|
| 120 | type : 'text',
|
---|
| 121 | label : editor.lang.textfield.value,
|
---|
| 122 | 'default' : '',
|
---|
| 123 | accessKey : 'V'
|
---|
| 124 | }
|
---|
| 125 | ]
|
---|
| 126 | },
|
---|
| 127 | {
|
---|
| 128 | type : 'hbox',
|
---|
| 129 | widths : [ '50%', '50%' ],
|
---|
| 130 | children :
|
---|
| 131 | [
|
---|
| 132 | {
|
---|
| 133 | id : 'size',
|
---|
| 134 | type : 'text',
|
---|
| 135 | label : editor.lang.textfield.charWidth,
|
---|
| 136 | 'default' : '',
|
---|
| 137 | accessKey : 'C',
|
---|
| 138 | style : 'width:50px',
|
---|
| 139 | validate : CKEDITOR.dialog.validate.integer( editor.lang.common.validateNumberFailed )
|
---|
| 140 | },
|
---|
| 141 | {
|
---|
| 142 | id : 'maxLength',
|
---|
| 143 | type : 'text',
|
---|
| 144 | label : editor.lang.textfield.maxChars,
|
---|
| 145 | 'default' : '',
|
---|
| 146 | accessKey : 'M',
|
---|
| 147 | style : 'width:50px',
|
---|
| 148 | validate : CKEDITOR.dialog.validate.integer( editor.lang.common.validateNumberFailed )
|
---|
| 149 | }
|
---|
| 150 | ]
|
---|
| 151 | },
|
---|
| 152 | {
|
---|
| 153 | id : 'type',
|
---|
| 154 | type : 'select',
|
---|
| 155 | label : editor.lang.textfield.type,
|
---|
| 156 | 'default' : 'text',
|
---|
| 157 | accessKey : 'M',
|
---|
| 158 | items :
|
---|
| 159 | [
|
---|
| 160 | [ editor.lang.textfield.typeText, 'text' ],
|
---|
| 161 | [ editor.lang.textfield.typePass, 'password' ]
|
---|
| 162 | ],
|
---|
| 163 | setup : function( element )
|
---|
| 164 | {
|
---|
| 165 | this.setValue( element.getAttribute( 'type' ) );
|
---|
| 166 | },
|
---|
| 167 | commit : function( data )
|
---|
| 168 | {
|
---|
| 169 | var element = data.element;
|
---|
| 170 |
|
---|
| 171 | if ( CKEDITOR.env.ie )
|
---|
| 172 | {
|
---|
| 173 | var elementType = element.getAttribute( 'type' );
|
---|
| 174 | var myType = this.getValue();
|
---|
| 175 |
|
---|
| 176 | if ( elementType != myType )
|
---|
| 177 | {
|
---|
| 178 | var replace = CKEDITOR.dom.element.createFromHtml( '<input type="' + myType + '"></input>', editor.document );
|
---|
| 179 | element.copyAttributes( replace, { type : 1 } );
|
---|
| 180 | replace.replace( element );
|
---|
| 181 | editor.getSelection().selectElement( replace );
|
---|
| 182 | data.element = element;
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
| 185 | else
|
---|
| 186 | element.setAttribute( 'type', this.getValue() );
|
---|
| 187 | }
|
---|
| 188 | }
|
---|
| 189 | ]
|
---|
| 190 | }
|
---|
| 191 | ]
|
---|
| 192 | };
|
---|
| 193 | });
|
---|