1 | /*
|
---|
2 | Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
|
---|
3 | For licensing, see LICENSE.html or http://ckeditor.com/license
|
---|
4 | */
|
---|
5 |
|
---|
6 | CKEDITOR.plugins.add( 'panelbutton',
|
---|
7 | {
|
---|
8 | requires : [ 'button' ],
|
---|
9 | beforeInit : function( editor )
|
---|
10 | {
|
---|
11 | editor.ui.addHandler( CKEDITOR.UI_PANELBUTTON, CKEDITOR.ui.panelButton.handler );
|
---|
12 | }
|
---|
13 | });
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Button UI element.
|
---|
17 | * @constant
|
---|
18 | * @example
|
---|
19 | */
|
---|
20 | CKEDITOR.UI_PANELBUTTON = 4;
|
---|
21 |
|
---|
22 | (function()
|
---|
23 | {
|
---|
24 | var clickFn = function( editor )
|
---|
25 | {
|
---|
26 | var _ = this._;
|
---|
27 |
|
---|
28 | if ( _.state == CKEDITOR.TRISTATE_DISABLED )
|
---|
29 | return;
|
---|
30 |
|
---|
31 | this.createPanel( editor );
|
---|
32 |
|
---|
33 | if ( _.on )
|
---|
34 | {
|
---|
35 | _.panel.hide();
|
---|
36 | return;
|
---|
37 | }
|
---|
38 |
|
---|
39 | _.panel.showBlock( this._.id, this.document.getById( this._.id ), 4 );
|
---|
40 | };
|
---|
41 |
|
---|
42 |
|
---|
43 | CKEDITOR.ui.panelButton = CKEDITOR.tools.createClass(
|
---|
44 | {
|
---|
45 | base : CKEDITOR.ui.button,
|
---|
46 |
|
---|
47 | $ : function( definition )
|
---|
48 | {
|
---|
49 | // We don't want the panel definition in this object.
|
---|
50 | var panelDefinition = definition.panel;
|
---|
51 | delete definition.panel;
|
---|
52 |
|
---|
53 | this.base( definition );
|
---|
54 |
|
---|
55 | this.document = ( panelDefinition
|
---|
56 | && panelDefinition.parent
|
---|
57 | && panelDefinition.parent.getDocument() )
|
---|
58 | || CKEDITOR.document;
|
---|
59 |
|
---|
60 | panelDefinition.block =
|
---|
61 | {
|
---|
62 | attributes : panelDefinition.attributes
|
---|
63 | };
|
---|
64 |
|
---|
65 | this.hasArrow = true;
|
---|
66 |
|
---|
67 | this.click = clickFn;
|
---|
68 |
|
---|
69 | this._ =
|
---|
70 | {
|
---|
71 | panelDefinition : panelDefinition
|
---|
72 | };
|
---|
73 | },
|
---|
74 |
|
---|
75 | statics :
|
---|
76 | {
|
---|
77 | handler :
|
---|
78 | {
|
---|
79 | create : function( definition )
|
---|
80 | {
|
---|
81 | return new CKEDITOR.ui.panelButton( definition );
|
---|
82 | }
|
---|
83 | }
|
---|
84 | },
|
---|
85 |
|
---|
86 | proto :
|
---|
87 | {
|
---|
88 | createPanel : function( editor )
|
---|
89 | {
|
---|
90 | var _ = this._;
|
---|
91 |
|
---|
92 | if ( _.panel )
|
---|
93 | return;
|
---|
94 |
|
---|
95 | var panelDefinition = this._.panelDefinition || {},
|
---|
96 | panelBlockDefinition = this._.panelDefinition.block,
|
---|
97 | panelParentElement = panelDefinition.parent || CKEDITOR.document.getBody(),
|
---|
98 | panel = this._.panel = new CKEDITOR.ui.floatPanel( editor, panelParentElement, panelDefinition ),
|
---|
99 | block = panel.addBlock( _.id, panelBlockDefinition ),
|
---|
100 | me = this;
|
---|
101 |
|
---|
102 | panel.onShow = function()
|
---|
103 | {
|
---|
104 | if ( me.className )
|
---|
105 | this.element.getFirst().addClass( me.className + '_panel' );
|
---|
106 |
|
---|
107 | _.oldState = me._.state;
|
---|
108 | me.setState( CKEDITOR.TRISTATE_ON );
|
---|
109 |
|
---|
110 | _.on = 1;
|
---|
111 |
|
---|
112 | if ( me.onOpen )
|
---|
113 | me.onOpen();
|
---|
114 | };
|
---|
115 |
|
---|
116 | panel.onHide = function()
|
---|
117 | {
|
---|
118 | if ( me.className )
|
---|
119 | this.element.getFirst().removeClass( me.className + '_panel' );
|
---|
120 |
|
---|
121 | me.setState( _.oldState );
|
---|
122 |
|
---|
123 | _.on = 0;
|
---|
124 |
|
---|
125 | if ( me.onClose )
|
---|
126 | me.onClose();
|
---|
127 | };
|
---|
128 |
|
---|
129 | panel.onEscape = function()
|
---|
130 | {
|
---|
131 | panel.hide();
|
---|
132 | me.document.getById( _.id ).focus();
|
---|
133 | };
|
---|
134 |
|
---|
135 | if ( this.onBlock )
|
---|
136 | this.onBlock( panel, block );
|
---|
137 |
|
---|
138 | block.onHide = function()
|
---|
139 | {
|
---|
140 | _.on = 0;
|
---|
141 | me.setState( CKEDITOR.TRISTATE_OFF );
|
---|
142 | };
|
---|
143 | }
|
---|
144 | }
|
---|
145 | });
|
---|
146 |
|
---|
147 | })();
|
---|