figure.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. CKEDITOR.dialog.add( 'figureDialog', function( editor ) {
  2. function createDiv( editor ) {
  3. var dialog = this;
  4. var containers = [];
  5. var database = {};
  6. var containedBlocks = [],
  7. block;
  8. var selection = editor.getSelection(),
  9. ranges = selection.getRanges();
  10. var bookmarks = selection.createBookmarks();
  11. var i, iterator;
  12. console.log(selection);
  13. console.log(bookmarks);
  14. var figure = editor.document.createElement( 'span' );
  15. figure.setAttribute('class', 'infoblock');
  16. figure.setAttribute( 'type', dialog.getValueOf('tab-basic', 'orientation') );
  17. figure.setAttribute( 'data-info', dialog.getValueOf( 'tab-basic', 'data-info' ) );
  18. var selection = editor.getSelection(),
  19. ranges = selection.getRanges();
  20. var bookmarks = selection.createBookmarks();
  21. var i, iterator;
  22. var txt = selection.getSelectedText();
  23. figure.appendHtml(txt);
  24. editor.insertElement( figure );
  25. containers.push( divElement );
  26. return containers;
  27. }
  28. return {
  29. title: 'Вставка информационный блок',
  30. minWidth: 400,
  31. minHeight: 200,
  32. contents: [
  33. {
  34. id: 'tab-basic',
  35. label: 'Базовые',
  36. elements: [
  37. {
  38. type: 'text',
  39. id: 'data-title',
  40. rows: 4,
  41. controlStyle: 'height:100%',
  42. inputStyle: 'height:100%',
  43. label: 'Заголовок',
  44. validate: CKEDITOR.dialog.validate.notEmpty( "Поле не должно быть пустым" ),
  45. setup: function( element ) {
  46. this.setValue( element.getAttribute( "data-title" ) );
  47. },
  48. commit: function( element ) {
  49. element.setText( this.getValue() );
  50. }
  51. },
  52. {
  53. type: 'textarea',
  54. id: 'data-info',
  55. rows: 4,
  56. controlStyle: 'height:100%',
  57. inputStyle: 'height:100%',
  58. label: 'Текст',
  59. validate: CKEDITOR.dialog.validate.notEmpty( "Поле не должно быть пустым" ),
  60. setup: function( element ) {
  61. this.setValue( element.getAttribute( "data-info" ) );
  62. },
  63. commit: function( element ) {
  64. element.setText( this.getValue() );
  65. }
  66. },
  67. {
  68. type: 'radio',
  69. id: 'orientation',
  70. label: 'Выбрать',
  71. items: [ [ 'тип 1', '1' ], [ 'тип 2', '2' ] ],
  72. 'default': '1',
  73. setup: function( element ) {
  74. this.setValue( element.getAttribute( "type" ) );
  75. },
  76. commit: function( element ) {
  77. element.setAttribute( "orientation", this.getValue() );
  78. }
  79. }
  80. ]
  81. },
  82. ],
  83. onShow: function() {
  84. var selection = editor.getSelection();
  85. var element = selection.getStartElement();
  86. if ( !element || $(element).attr('class') != 'infoblock' ) {
  87. element = editor.document.createElement( 'span' );
  88. this.insertMode = true;
  89. }
  90. else
  91. this.insertMode = false;
  92. this.element = element;
  93. if ( !this.insertMode )
  94. this.setupContent( this.element );
  95. },
  96. onOk: function() {
  97. var dialog = this;
  98. var fitem = this.element;
  99. var selection = editor.getSelection();
  100. // console.log(selection);
  101. if ( this.insertMode ){
  102. var figure = editor.document.createElement( 'span' );
  103. figure.setAttribute('class', 'infoblock');
  104. figure.setAttribute( 'type', dialog.getValueOf('tab-basic', 'orientation') );
  105. figure.setAttribute( 'data-info', dialog.getValueOf( 'tab-basic', 'data-info' ) );
  106. figure.setAttribute( 'data-title', dialog.getValueOf( 'tab-basic', 'data-title' ) );
  107. var selection = editor.getSelection();
  108. var txt = selection.getSelectedText();
  109. figure.appendHtml( txt );
  110. // editor.insertElement( figure );
  111. //console.log(figure.getOuterHtml());
  112. editor.insertHtml( ' '+figure.getOuterHtml()+' ','text');
  113. }else{
  114. fitem.setAttribute( 'data-info', dialog.getValueOf( 'tab-basic', 'data-info' ) );
  115. fitem.setAttribute( 'data-title', dialog.getValueOf( 'tab-basic', 'data-title' ) );
  116. fitem.setAttribute( 'type', dialog.getValueOf('tab-basic', 'orientation') );
  117. //dialog.commitContent( fitem );
  118. }
  119. /*
  120. containers.push( figure );
  121. var size = containers.length;
  122. for ( var i = 0; i < size; i++ ) {
  123. this.commitContent( containers[ i ] );
  124. !containers[ i ].getAttribute( 'style' ) && containers[ i ].removeAttribute( 'style' );
  125. }*/
  126. this.hide();
  127. }
  128. }
  129. }
  130. );