plugin.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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.plugins.add( 'panelbutton', {
  6. requires: 'button',
  7. onLoad: function() {
  8. function clickFn( editor ) {
  9. var _ = this._;
  10. if ( _.state == CKEDITOR.TRISTATE_DISABLED )
  11. return;
  12. this.createPanel( editor );
  13. if ( _.on ) {
  14. _.panel.hide();
  15. return;
  16. }
  17. _.panel.showBlock( this._.id, this.document.getById( this._.id ), 4 );
  18. }
  19. /**
  20. * @class
  21. * @extends CKEDITOR.ui.button
  22. * @todo class and methods
  23. */
  24. CKEDITOR.ui.panelButton = CKEDITOR.tools.createClass( {
  25. base: CKEDITOR.ui.button,
  26. /**
  27. * Creates a panelButton class instance.
  28. *
  29. * @constructor
  30. */
  31. $: function( definition ) {
  32. // We don't want the panel definition in this object.
  33. var panelDefinition = definition.panel || {};
  34. delete definition.panel;
  35. this.base( definition );
  36. this.document = ( panelDefinition.parent && panelDefinition.parent.getDocument() ) || CKEDITOR.document;
  37. panelDefinition.block = {
  38. attributes: panelDefinition.attributes
  39. };
  40. panelDefinition.toolbarRelated = true;
  41. this.hasArrow = true;
  42. this.click = clickFn;
  43. this._ = {
  44. panelDefinition: panelDefinition
  45. };
  46. },
  47. statics: {
  48. handler: {
  49. create: function( definition ) {
  50. return new CKEDITOR.ui.panelButton( definition );
  51. }
  52. }
  53. },
  54. proto: {
  55. createPanel: function( editor ) {
  56. var _ = this._;
  57. if ( _.panel )
  58. return;
  59. var panelDefinition = this._.panelDefinition,
  60. panelBlockDefinition = this._.panelDefinition.block,
  61. panelParentElement = panelDefinition.parent || CKEDITOR.document.getBody(),
  62. panel = this._.panel = new CKEDITOR.ui.floatPanel( editor, panelParentElement, panelDefinition ),
  63. block = panel.addBlock( _.id, panelBlockDefinition ),
  64. me = this;
  65. panel.onShow = function() {
  66. if ( me.className )
  67. this.element.addClass( me.className + '_panel' );
  68. me.setState( CKEDITOR.TRISTATE_ON );
  69. _.on = 1;
  70. me.editorFocus && editor.focus();
  71. if ( me.onOpen )
  72. me.onOpen();
  73. };
  74. panel.onHide = function( preventOnClose ) {
  75. if ( me.className )
  76. this.element.getFirst().removeClass( me.className + '_panel' );
  77. me.setState( me.modes && me.modes[ editor.mode ] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED );
  78. _.on = 0;
  79. if ( !preventOnClose && me.onClose )
  80. me.onClose();
  81. };
  82. panel.onEscape = function() {
  83. panel.hide( 1 );
  84. me.document.getById( _.id ).focus();
  85. };
  86. if ( this.onBlock )
  87. this.onBlock( panel, block );
  88. block.onHide = function() {
  89. _.on = 0;
  90. me.setState( CKEDITOR.TRISTATE_OFF );
  91. };
  92. }
  93. }
  94. } );
  95. },
  96. beforeInit: function( editor ) {
  97. editor.ui.addHandler( CKEDITOR.UI_PANELBUTTON, CKEDITOR.ui.panelButton.handler );
  98. }
  99. } );
  100. /**
  101. * Button UI element.
  102. *
  103. * @readonly
  104. * @property {String} [='panelbutton']
  105. * @member CKEDITOR
  106. */
  107. CKEDITOR.UI_PANELBUTTON = 'panelbutton';