hiddenfield.js 2.5 KB

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