source: sandbox/2.3-MailArchiver/filemanager/tp/ckeditor/_source/plugins/panel/plugin.js @ 6779

Revision 6779, 7.6 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado Expresso(branch 2.3) integrado ao MailArchiver?.

Line 
1/*
2Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
3For licensing, see LICENSE.html or http://ckeditor.com/license
4*/
5
6CKEDITOR.plugins.add( 'panel',
7{
8        beforeInit : function( editor )
9        {
10                editor.ui.addHandler( CKEDITOR.UI_PANEL, CKEDITOR.ui.panel.handler );
11        }
12});
13
14/**
15 * Panel UI element.
16 * @constant
17 * @example
18 */
19CKEDITOR.UI_PANEL = 2;
20
21CKEDITOR.ui.panel = function( document, definition )
22{
23        // Copy all definition properties to this object.
24        if ( definition )
25                CKEDITOR.tools.extend( this, definition );
26
27        // Set defaults.
28        CKEDITOR.tools.extend( this,
29                {
30                        className : '',
31                        css : []
32                });
33
34        this.id = CKEDITOR.tools.getNextNumber();
35        this.document = document;
36
37        this._ =
38        {
39                blocks : {}
40        };
41};
42
43/**
44 * Transforms a rich combo definition in a {@link CKEDITOR.ui.richCombo}
45 * instance.
46 * @type Object
47 * @example
48 */
49CKEDITOR.ui.panel.handler =
50{
51        create : function( definition )
52        {
53                return new CKEDITOR.ui.panel( definition );
54        }
55};
56
57CKEDITOR.ui.panel.prototype =
58{
59        renderHtml : function( editor )
60        {
61                var output = [];
62                this.render( editor, output );
63                return output.join( '' );
64        },
65
66        /**
67         * Renders the combo.
68         * @param {CKEDITOR.editor} editor The editor instance which this button is
69         *              to be used by.
70         * @param {Array} output The output array to which append the HTML relative
71         *              to this button.
72         * @example
73         */
74        render : function( editor, output )
75        {
76                var id = 'cke_' + this.id;
77
78                output.push(
79                        '<div class="', editor.skinClass ,'"' +
80                                ' lang="', editor.langCode, '"' +
81                                // iframe loading need sometime, keep the panel hidden(#4186).
82                                ' style="display:none;z-index:' + ( editor.config.baseFloatZIndex + 1 ) + '">' +
83                                '<div' +
84                                        ' id=', id,
85                                        ' dir=', editor.lang.dir,
86                                        ' class="cke_panel cke_', editor.lang.dir );
87
88                if ( this.className )
89                        output.push( ' ', this.className );
90
91                output.push(
92                                '">' );
93
94                if ( this.forceIFrame || this.css.length )
95                {
96                        output.push(
97                                                '<iframe id="', id, '_frame"' +
98                                                        ' frameborder="0"' +
99                                                        ' src="javascript:void(' );
100
101                        output.push(
102                                                        // Support for custom document.domain in IE.
103                                                        CKEDITOR.env.isCustomDomain() ?
104                                                                '(function(){' +
105                                                                        'document.open();' +
106                                                                        'document.domain=\'' + document.domain + '\';' +
107                                                                        'document.close();' +
108                                                                '})()'
109                                                        :
110                                                                '0' );
111
112                        output.push(
113                                                ')"></iframe>' );
114                }
115
116                output.push(
117                                '</div>' +
118                        '</div>' );
119
120                return id;
121        },
122
123        getHolderElement : function()
124        {
125                var holder = this._.holder;
126
127                if ( !holder )
128                {
129                        if ( this.forceIFrame || this.css.length )
130                        {
131                                var iframe = this.document.getById( 'cke_' + this.id + '_frame' ),
132                                        parentDiv = iframe.getParent(),
133                                        dir = parentDiv.getAttribute( 'dir' ),
134                                        className = parentDiv.getParent().getAttribute( 'class' ),
135                                        langCode = parentDiv.getParent().getAttribute( 'lang' ),
136                                        doc = iframe.getFrameDocument();
137                                // Initialize the IFRAME document body.
138                                doc.$.open();
139
140                                // Support for custom document.domain in IE.
141                                if ( CKEDITOR.env.isCustomDomain() )
142                                        doc.$.domain = document.domain;
143
144                                var onLoad = CKEDITOR.tools.addFunction( CKEDITOR.tools.bind( function( ev )
145                                        {
146                                                this.isLoaded = true;
147                                                if ( this.onLoad )
148                                                        this.onLoad();
149                                        }, this ) );
150
151                                doc.$.write(
152                                        '<!DOCTYPE html>' +
153                                        '<html dir="' + dir + '" class="' + className + '_container" lang="' + langCode + '">' +
154                                                '<head>' +
155                                                        '<style>.' + className + '_container{visibility:hidden}</style>' +
156                                                '</head>' +
157                                                '<body class="cke_' + dir + ' cke_panel_frame ' + CKEDITOR.env.cssClass + '" style="margin:0;padding:0"' +
158                                                ' onload="( window.CKEDITOR || window.parent.CKEDITOR ).tools.callFunction(' + onLoad + ');">' +
159                                                '</body>' +
160                                                // It looks strange, but for FF2, the styles must go
161                                                // after <body>, so it (body) becames immediatelly
162                                                // available. (#3031)
163                                                '<link type="text/css" rel=stylesheet href="' + this.css.join( '"><link type="text/css" rel="stylesheet" href="' ) + '">' +
164                                        '<\/html>' );
165                                doc.$.close();
166
167                                var win = doc.getWindow();
168
169                                // Register the CKEDITOR global.
170                                win.$.CKEDITOR = CKEDITOR;
171
172                                doc.on( 'keydown', function( evt )
173                                        {
174                                                var keystroke = evt.data.getKeystroke();
175
176                                                // Delegate key processing to block.
177                                                if ( this._.onKeyDown && this._.onKeyDown( keystroke ) === false )
178                                                {
179                                                        evt.data.preventDefault();
180                                                        return;
181                                                }
182
183                                                if ( keystroke == 27 )          // ESC
184                                                        this.onEscape && this.onEscape();
185                                        },
186                                        this );
187
188                                holder = doc.getBody();
189                        }
190                        else
191                                holder = this.document.getById( 'cke_' + this.id );
192
193                        this._.holder = holder;
194                }
195
196                return holder;
197        },
198
199        addBlock : function( name, block )
200        {
201                block = this._.blocks[ name ] = block || new CKEDITOR.ui.panel.block( this.getHolderElement() );
202
203                if ( !this._.currentBlock )
204                        this.showBlock( name );
205
206                return block;
207        },
208
209        getBlock : function( name )
210        {
211                return this._.blocks[ name ];
212        },
213
214        showBlock : function( name )
215        {
216                var blocks = this._.blocks,
217                        block = blocks[ name ],
218                        current = this._.currentBlock;
219
220                if ( current )
221                        current.hide();
222
223                this._.currentBlock = block;
224
225                // Reset the focus index, so it will always go into the first one.
226                block._.focusIndex = -1;
227
228                this._.onKeyDown = block.onKeyDown && CKEDITOR.tools.bind( block.onKeyDown, block );
229
230                block.show();
231
232                return block;
233        }
234};
235
236CKEDITOR.ui.panel.block = CKEDITOR.tools.createClass(
237{
238        $ : function( blockHolder )
239        {
240                this.element = blockHolder.append(
241                        blockHolder.getDocument().createElement( 'div',
242                                {
243                                        attributes :
244                                        {
245                                                'class' : 'cke_panel_block'
246                                        },
247                                        styles :
248                                        {
249                                                display : 'none'
250                                        }
251                                }) );
252
253                this.keys = {};
254
255                this._.focusIndex = -1;
256
257                // Disable context menu for panels.
258                this.element.disableContextMenu();
259        },
260
261        _ : {},
262
263        proto :
264        {
265                show : function()
266                {
267                        this.element.setStyle( 'display', '' );
268                },
269
270                hide : function()
271                {
272                        if ( !this.onHide || this.onHide.call( this )  !== true )
273                                this.element.setStyle( 'display', 'none' );
274                },
275
276                onKeyDown : function( keystroke )
277                {
278                        var keyAction = this.keys[ keystroke ];
279                        switch ( keyAction )
280                        {
281                                // Move forward.
282                                case 'next' :
283                                        var index = this._.focusIndex,
284                                                links = this.element.getElementsByTag( 'a' ),
285                                                link;
286
287                                        while ( ( link = links.getItem( ++index ) ) )
288                                        {
289                                                // Move the focus only if the element is marked with
290                                                // the _cke_focus and it it's visible (check if it has
291                                                // width).
292                                                if ( link.getAttribute( '_cke_focus' ) && link.$.offsetWidth )
293                                                {
294                                                        this._.focusIndex = index;
295                                                        link.focus();
296                                                        break;
297                                                }
298                                        }
299                                        return false;
300
301                                // Move backward.
302                                case 'prev' :
303                                        index = this._.focusIndex;
304                                        links = this.element.getElementsByTag( 'a' );
305
306                                        while ( index > 0 && ( link = links.getItem( --index ) ) )
307                                        {
308                                                // Move the focus only if the element is marked with
309                                                // the _cke_focus and it it's visible (check if it has
310                                                // width).
311                                                if ( link.getAttribute( '_cke_focus' ) && link.$.offsetWidth )
312                                                {
313                                                        this._.focusIndex = index;
314                                                        link.focus();
315                                                        break;
316                                                }
317                                        }
318                                        return false;
319
320                                case 'click' :
321                                        index = this._.focusIndex;
322                                        link = index >= 0 && this.element.getElementsByTag( 'a' ).getItem( index );
323
324                                        if ( link )
325                                                link.$.click ? link.$.click() : link.$.onclick();
326
327                                        return false;
328                        }
329
330                        return true;
331                }
332        }
333});
Note: See TracBrowser for help on using the repository browser.