1 /*
  2 Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
  3 For licensing, see LICENSE.html or http://ckeditor.com/license
  4 */
  5 CKEDITOR.dialog.add( 'hiddenfield', function( editor )
  6 {
  7 	return {
  8 		title : editor.lang.hidden.title,
  9 		hiddenField : null,
 10 		minWidth : 350,
 11 		minHeight : 110,
 12 		onShow : function()
 13 		{
 14 			delete this.hiddenField;
 15 
 16 			var editor = this.getParentEditor(),
 17 				selection = editor.getSelection(),
 18 				element = selection.getSelectedElement();
 19 
 20 			if ( element && element.data( 'cke-real-element-type' ) && element.data( 'cke-real-element-type' ) == 'hiddenfield' )
 21 			{
 22 				this.hiddenField = element;
 23 				element = editor.restoreRealElement( this.hiddenField );
 24 				this.setupContent( element );
 25 				selection.selectElement( this.hiddenField );
 26 			}
 27 		},
 28 		onOk : function()
 29 		{
 30 			var name = this.getValueOf( 'info', '_cke_saved_name' ),
 31 				value = this.getValueOf( 'info', 'value' ),
 32 				editor = this.getParentEditor(),
 33 				element = CKEDITOR.env.ie && !( CKEDITOR.document.$.documentMode >= 8 ) ?
 34 					editor.document.createElement( '<input name="' + CKEDITOR.tools.htmlEncode( name ) + '">' )
 35 					: editor.document.createElement( 'input' );
 36 
 37 			element.setAttribute( 'type', 'hidden' );
 38 			this.commitContent( element );
 39 			var fakeElement = editor.createFakeElement( element, 'cke_hidden', 'hiddenfield' );
 40 			if ( !this.hiddenField )
 41 				editor.insertElement( fakeElement );
 42 			else
 43 			{
 44 				fakeElement.replace( this.hiddenField );
 45 				editor.getSelection().selectElement( fakeElement );
 46 			}
 47 			return true;
 48 		},
 49 		contents : [
 50 			{
 51 				id : 'info',
 52 				label : editor.lang.hidden.title,
 53 				title : editor.lang.hidden.title,
 54 				elements : [
 55 					{
 56 						id : '_cke_saved_name',
 57 						type : 'text',
 58 						label : editor.lang.hidden.name,
 59 						'default' : '',
 60 						accessKey : 'N',
 61 						setup : function( element )
 62 						{
 63 							this.setValue(
 64 									element.data( 'cke-saved-name' ) ||
 65 									element.getAttribute( 'name' ) ||
 66 									'' );
 67 						},
 68 						commit : function( element )
 69 						{
 70 							if ( this.getValue() )
 71 								element.setAttribute( 'name', this.getValue() );
 72 							else
 73 							{
 74 								element.removeAttribute( 'name' );
 75 							}
 76 						}
 77 					},
 78 					{
 79 						id : 'value',
 80 						type : 'text',
 81 						label : editor.lang.hidden.value,
 82 						'default' : '',
 83 						accessKey : 'V',
 84 						setup : function( element )
 85 						{
 86 							this.setValue( element.getAttribute( 'value' ) || '' );
 87 						},
 88 						commit : function( element )
 89 						{
 90 							if ( this.getValue() )
 91 								element.setAttribute( 'value', this.getValue() );
 92 							else
 93 								element.removeAttribute( 'value' );
 94 						}
 95 					}
 96 				]
 97 			}
 98 		]
 99 	};
100 });
101