textarea.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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( 'textarea', function( editor ) {
  6. return {
  7. title: editor.lang.forms.textarea.title,
  8. minWidth: 350,
  9. minHeight: 220,
  10. onShow: function() {
  11. delete this.textarea;
  12. var element = this.getParentEditor().getSelection().getSelectedElement();
  13. if ( element && element.getName() == 'textarea' ) {
  14. this.textarea = element;
  15. this.setupContent( element );
  16. }
  17. },
  18. onOk: function() {
  19. var editor,
  20. element = this.textarea,
  21. isInsertMode = !element;
  22. if ( isInsertMode ) {
  23. editor = this.getParentEditor();
  24. element = editor.document.createElement( 'textarea' );
  25. }
  26. this.commitContent( element );
  27. if ( isInsertMode )
  28. editor.insertElement( element );
  29. },
  30. contents: [ {
  31. id: 'info',
  32. label: editor.lang.forms.textarea.title,
  33. title: editor.lang.forms.textarea.title,
  34. elements: [ {
  35. id: '_cke_saved_name',
  36. type: 'text',
  37. label: editor.lang.common.name,
  38. 'default': '',
  39. accessKey: 'N',
  40. setup: function( element ) {
  41. this.setValue( element.data( 'cke-saved-name' ) || element.getAttribute( 'name' ) || '' );
  42. },
  43. commit: function( element ) {
  44. if ( this.getValue() )
  45. element.data( 'cke-saved-name', this.getValue() );
  46. else {
  47. element.data( 'cke-saved-name', false );
  48. element.removeAttribute( 'name' );
  49. }
  50. }
  51. },
  52. {
  53. type: 'hbox',
  54. widths: [ '50%', '50%' ],
  55. children: [ {
  56. id: 'cols',
  57. type: 'text',
  58. label: editor.lang.forms.textarea.cols,
  59. 'default': '',
  60. accessKey: 'C',
  61. style: 'width:50px',
  62. validate: CKEDITOR.dialog.validate.integer( editor.lang.common.validateNumberFailed ),
  63. setup: function( element ) {
  64. var value = element.hasAttribute( 'cols' ) && element.getAttribute( 'cols' );
  65. this.setValue( value || '' );
  66. },
  67. commit: function( element ) {
  68. if ( this.getValue() )
  69. element.setAttribute( 'cols', this.getValue() );
  70. else
  71. element.removeAttribute( 'cols' );
  72. }
  73. },
  74. {
  75. id: 'rows',
  76. type: 'text',
  77. label: editor.lang.forms.textarea.rows,
  78. 'default': '',
  79. accessKey: 'R',
  80. style: 'width:50px',
  81. validate: CKEDITOR.dialog.validate.integer( editor.lang.common.validateNumberFailed ),
  82. setup: function( element ) {
  83. var value = element.hasAttribute( 'rows' ) && element.getAttribute( 'rows' );
  84. this.setValue( value || '' );
  85. },
  86. commit: function( element ) {
  87. if ( this.getValue() )
  88. element.setAttribute( 'rows', this.getValue() );
  89. else
  90. element.removeAttribute( 'rows' );
  91. }
  92. } ]
  93. },
  94. {
  95. id: 'value',
  96. type: 'textarea',
  97. label: editor.lang.forms.textfield.value,
  98. 'default': '',
  99. setup: function( element ) {
  100. this.setValue( element.$.defaultValue );
  101. },
  102. commit: function( element ) {
  103. element.$.value = element.$.defaultValue = this.getValue();
  104. }
  105. },
  106. {
  107. id: 'required',
  108. type: 'checkbox',
  109. label: editor.lang.forms.textfield.required,
  110. 'default': '',
  111. accessKey: 'Q',
  112. value: 'required',
  113. setup: function( element ) {
  114. this.setValue( element.getAttribute( 'required' ) );
  115. },
  116. commit: function( element ) {
  117. if ( this.getValue() )
  118. element.setAttribute( 'required', 'required' );
  119. else
  120. element.removeAttribute( 'required' );
  121. }
  122. } ]
  123. } ]
  124. };
  125. } );