JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.0
[ckeditor.git] / _source / plugins / panelbutton / plugin.js
diff --git a/_source/plugins/panelbutton/plugin.js b/_source/plugins/panelbutton/plugin.js
new file mode 100644 (file)
index 0000000..155fa95
--- /dev/null
@@ -0,0 +1,140 @@
+/*\r
+Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+For licensing, see LICENSE.html or http://ckeditor.com/license\r
+*/\r
+\r
+CKEDITOR.plugins.add( 'panelbutton',\r
+{\r
+       requires : [ 'button' ],\r
+       beforeInit : function( editor )\r
+       {\r
+               editor.ui.addHandler( CKEDITOR.UI_PANELBUTTON, CKEDITOR.ui.panelButton.handler );\r
+       }\r
+});\r
+\r
+/**\r
+ * Button UI element.\r
+ * @constant\r
+ * @example\r
+ */\r
+CKEDITOR.UI_PANELBUTTON = 4;\r
+\r
+(function()\r
+{\r
+       var clickFn = function( editor )\r
+       {\r
+               var _ = this._;\r
+\r
+               if ( _.state == CKEDITOR.TRISTATE_DISABLED )\r
+                       return;\r
+\r
+               this.createPanel( editor );\r
+\r
+               if ( _.on )\r
+               {\r
+                       _.panel.hide();\r
+                       return;\r
+               }\r
+\r
+               _.panel.showBlock( this._.id, this.document.getById( this._.id ), 4 );\r
+       };\r
+\r
+\r
+       CKEDITOR.ui.panelButton = CKEDITOR.tools.createClass(\r
+       {\r
+               base : CKEDITOR.ui.button,\r
+\r
+               $ : function( definition )\r
+               {\r
+                       // We don't want the panel definition in this object.\r
+                       var panelDefinition = definition.panel;\r
+                       delete definition.panel;\r
+\r
+                       this.base( definition );\r
+\r
+                       this.document = ( panelDefinition\r
+                                                               && panelDefinition.parent\r
+                                                               && panelDefinition.parent.getDocument() )\r
+                                                       || CKEDITOR.document;\r
+\r
+                       this.hasArrow = true;\r
+\r
+                       this.click = clickFn;\r
+\r
+                       this._ =\r
+                       {\r
+                               panelDefinition : panelDefinition\r
+                       };\r
+               },\r
+\r
+               statics :\r
+               {\r
+                       handler :\r
+                       {\r
+                               create : function( definition )\r
+                               {\r
+                                       return new CKEDITOR.ui.panelButton( definition );\r
+                               }\r
+                       }\r
+               },\r
+\r
+               proto :\r
+               {\r
+                       createPanel : function( editor )\r
+                       {\r
+                               var _ = this._;\r
+\r
+                               if ( _.panel )\r
+                                       return;\r
+\r
+                               var panelDefinition = this._.panelDefinition || {},\r
+                                       panelParentElement = panelDefinition.parent || CKEDITOR.document.getBody(),\r
+                                       panel = this._.panel = new CKEDITOR.ui.floatPanel( editor, panelParentElement, panelDefinition ),\r
+                                       me = this;\r
+\r
+                               panel.onShow = function()\r
+                                       {\r
+                                               if ( me.className )\r
+                                                       this.element.getFirst().addClass( me.className + '_panel' );\r
+\r
+                                               _.oldState = me._.state;\r
+                                               me.setState( CKEDITOR.TRISTATE_ON );\r
+\r
+                                               _.on = 1;\r
+\r
+                                               if ( me.onOpen )\r
+                                                       me.onOpen();\r
+                                       };\r
+\r
+                               panel.onHide = function()\r
+                                       {\r
+                                               if ( me.className )\r
+                                                       this.element.getFirst().removeClass( me.className + '_panel' );\r
+\r
+                                               me.setState( _.oldState );\r
+\r
+                                               _.on = 0;\r
+\r
+                                               if ( me.onClose )\r
+                                                       me.onClose();\r
+                                       };\r
+\r
+                               panel.onEscape = function()\r
+                                       {\r
+                                               panel.hide();\r
+                                               me.document.getById( _.id ).focus();\r
+                                       };\r
+\r
+                               if ( this.onBlock )\r
+                                       this.onBlock( panel, _.id );\r
+\r
+                               panel.getBlock( _.id ).onHide = function()\r
+                                               {\r
+                                                               _.on = 0;\r
+                                                               me.setState( CKEDITOR.TRISTATE_OFF );\r
+                                               };\r
+                       }\r
+               }\r
+       });\r
+\r
+})();\r