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