source: trunk/phpgwapi/js/ckeditor/_source/themes/default/theme.js @ 2862

Revision 2862, 11.4 KB checked in by rodsouza, 14 years ago (diff)

Ticket #663 - Atualizando e centralizando o CKEditor (v. 3.2.1)

Line 
1/*
2Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
3For licensing, see LICENSE.html or http://ckeditor.com/license
4*/
5
6CKEDITOR.themes.add( 'default', (function()
7{
8        function checkSharedSpace( editor, spaceName )
9        {
10                var container,
11                        element;
12
13                // Try to retrieve the target element from the sharedSpaces settings.
14                element = editor.config.sharedSpaces;
15                element = element && element[ spaceName ];
16                element = element && CKEDITOR.document.getById( element );
17
18                // If the element is available, we'll then create the container for
19                // the space.
20                if ( element )
21                {
22                        // Creates an HTML structure that reproduces the editor class hierarchy.
23                        var html =
24                                '<span class="cke_shared">' +
25                                '<span class="' + editor.skinClass + ' cke_editor_' + editor.name + '">' +
26                                '<span class="' + CKEDITOR.env.cssClass + '">' +
27                                '<span class="cke_wrapper cke_' + editor.lang.dir + '">' +
28                                '<span class="cke_editor">' +
29                                '<div class="cke_' + spaceName + '">' +
30                                '</div></span></span></span></span></span>';
31
32                        var mainContainer = element.append( CKEDITOR.dom.element.createFromHtml( html, element.getDocument() ) );
33
34                        // Only the first container starts visible. Others get hidden.
35                        if ( element.getCustomData( 'cke_hasshared' ) )
36                                mainContainer.hide();
37                        else
38                                element.setCustomData( 'cke_hasshared', 1 );
39
40                        // Get the deeper inner <div>.
41                        container = mainContainer.getChild( [0,0,0,0] );
42
43                        // When the editor gets focus, we show the space container, hiding others.
44                        editor.on( 'focus', function()
45                                {
46                                        for ( var i = 0, sibling, children = element.getChildren() ; ( sibling = children.getItem( i ) ) ; i++ )
47                                        {
48                                                if ( sibling.type == CKEDITOR.NODE_ELEMENT
49                                                        && !sibling.equals( mainContainer )
50                                                        && sibling.hasClass( 'cke_shared' ) )
51                                                {
52                                                        sibling.hide();
53                                                }
54                                        }
55
56                                        mainContainer.show();
57                                });
58
59                        editor.on( 'destroy', function()
60                                {
61                                        mainContainer.remove();
62                                });
63                }
64
65                return container;
66        }
67
68        return {
69                build : function( editor, themePath )
70                {
71                        var name = editor.name,
72                                element = editor.element,
73                                elementMode = editor.elementMode;
74
75                        if ( !element || elementMode == CKEDITOR.ELEMENT_MODE_NONE )
76                                return;
77
78                        if ( elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
79                                element.hide();
80
81                        // Get the HTML for the predefined spaces.
82                        var topHtml                     = editor.fire( 'themeSpace', { space : 'top', html : '' } ).html;
83                        var contentsHtml        = editor.fire( 'themeSpace', { space : 'contents', html : '' } ).html;
84                        var bottomHtml          = editor.fireOnce( 'themeSpace', { space : 'bottom', html : '' } ).html;
85
86                        var height      = contentsHtml && editor.config.height;
87
88                        var tabIndex = editor.config.tabIndex || editor.element.getAttribute( 'tabindex' ) || 0;
89
90                        // The editor height is considered only if the contents space got filled.
91                        if ( !contentsHtml )
92                                height = 'auto';
93                        else if ( !isNaN( height ) )
94                                height += 'px';
95
96                        var style = '';
97                        var width       = editor.config.width;
98
99                        if ( width )
100                        {
101                                if ( !isNaN( width ) )
102                                        width += 'px';
103
104                                style += "width: " + width + ";";
105                        }
106
107                        var sharedTop           = topHtml && checkSharedSpace( editor, 'top' ),
108                                sharedBottoms   = checkSharedSpace( editor, 'bottom' );
109
110                        sharedTop               && ( sharedTop.setHtml( topHtml )               , topHtml = '' );
111                        sharedBottoms   && ( sharedBottoms.setHtml( bottomHtml ), bottomHtml = '' );
112
113                        var container = CKEDITOR.dom.element.createFromHtml( [
114                                '<span' +
115                                        ' id="cke_', name, '"' +
116                                        ' onmousedown="return false;"' +
117                                        ' class="', editor.skinClass, ' cke_editor_', name, '"' +
118                                        ' dir="', editor.lang.dir, '"' +
119                                        ' title="', ( CKEDITOR.env.gecko ? ' ' : '' ), '"' +
120                                        ' lang="', editor.langCode, '"' +
121                                        ' role="application"' +
122                                        ' aria-labelledby="cke_', name, '_arialbl"' +
123                                        ( style ? ' style="' + style + '"' : '' ) +
124                                        '>' +
125                                        '<span id="cke_', name, '_arialbl" class="cke_voice_label">' + editor.lang.editor + '</span>' +
126                                        '<span class="' , CKEDITOR.env.cssClass, '" role="presentation">' +
127                                                '<span class="cke_wrapper cke_', editor.lang.dir, '" role="presentation">' +
128                                                        '<table class="cke_editor" border="0" cellspacing="0" cellpadding="0" role="presentation"><tbody>' +
129                                                                '<tr', topHtml          ? '' : ' style="display:none"', '><td id="cke_top_'             , name, '" class="cke_top" role="presentation">'        , topHtml               , '</td></tr>' +
130                                                                '<tr', contentsHtml     ? '' : ' style="display:none"', '><td id="cke_contents_', name, '" class="cke_contents" style="height:', height, '" role="presentation">', contentsHtml, '</td></tr>' +
131                                                                '<tr', bottomHtml       ? '' : ' style="display:none"', '><td id="cke_bottom_'  , name, '" class="cke_bottom" role="presentation">'     , bottomHtml    , '</td></tr>' +
132                                                        '</tbody></table>' +
133                                                        //Hide the container when loading skins, later restored by skin css.
134                                                        '<style>.', editor.skinClass, '{visibility:hidden;}</style>' +
135                                                '</span>' +
136                                        '</span>' +
137                                '</span>' ].join( '' ) );
138
139                        container.getChild( [1, 0, 0, 0, 0] ).unselectable();
140                        container.getChild( [1, 0, 0, 0, 2] ).unselectable();
141
142                        if ( elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
143                                container.insertAfter( element );
144                        else
145                                element.append( container );
146
147                        /**
148                         * The DOM element that holds the main editor interface.
149                         * @name CKEDITOR.editor.prototype.container
150                         * @type CKEDITOR.dom.element
151                         * @example
152                         * var editor = CKEDITOR.instances.editor1;
153                         * alert( <b>editor.container</b>.getName() );  "span"
154                         */
155                        editor.container = container;
156
157                        // Disable browser context menu for editor's chrome.
158                        container.disableContextMenu();
159
160                        editor.fireOnce( 'themeLoaded' );
161                        editor.fireOnce( 'uiReady' );
162                },
163
164                buildDialog : function( editor )
165                {
166                        var baseIdNumber = CKEDITOR.tools.getNextNumber();
167
168                        var element = CKEDITOR.dom.element.createFromHtml( [
169                                        '<div class="cke_editor_' + editor.name.replace('.', '\\.') + '_dialog cke_skin_', editor.skinName,
170                                                '" dir="', editor.lang.dir, '"' +
171                                                ' lang="', editor.langCode, '"' +
172                                                ' role="dialog"' +
173                                                ' aria-labelledby="%title#"' +
174                                                '>' +
175                                                '<table class="cke_dialog', ' ' + CKEDITOR.env.cssClass,
176                                                        ' cke_', editor.lang.dir, '" style="position:absolute" role="presentation">' +
177                                                        '<tr><td role="presentation">' +
178                                                        '<div class="%body" role="presentation">' +
179                                                                '<div id="%title#" class="%title" role="presentation"></div>' +
180                                                                '<a id="%close_button#" class="%close_button" href="javascript:void(0)" title="' +  editor.lang.common.close+'" role="button"><span class="cke_label">X</span></a>' +
181                                                                '<div id="%tabs#" class="%tabs" role="tablist"></div>' +
182                                                                '<table class="%contents" role="presentation"><tr>' +
183                                                                  '<td id="%contents#" class="%contents" role="presentation"></td>' +
184                                                                '</tr></table>' +
185                                                                '<div id="%footer#" class="%footer" role="presentation"></div>' +
186                                                        '</div>' +
187                                                        '<div id="%tl#" class="%tl"></div>' +
188                                                        '<div id="%tc#" class="%tc"></div>' +
189                                                        '<div id="%tr#" class="%tr"></div>' +
190                                                        '<div id="%ml#" class="%ml"></div>' +
191                                                        '<div id="%mr#" class="%mr"></div>' +
192                                                        '<div id="%bl#" class="%bl"></div>' +
193                                                        '<div id="%bc#" class="%bc"></div>' +
194                                                        '<div id="%br#" class="%br"></div>' +
195                                                        '</td></tr>' +
196                                                '</table>',
197
198                                                //Hide the container when loading skins, later restored by skin css.
199                                                ( CKEDITOR.env.ie ? '' : '<style>.cke_dialog{visibility:hidden;}</style>' ),
200
201                                        '</div>'
202                                ].join( '' )
203                                        .replace( /#/g, '_' + baseIdNumber )
204                                        .replace( /%/g, 'cke_dialog_' ) );
205
206                        var body = element.getChild( [ 0, 0, 0, 0, 0 ] ),
207                                title = body.getChild( 0 ),
208                                close = body.getChild( 1 );
209
210                        // Make the Title and Close Button unselectable.
211                        title.unselectable();
212                        close.unselectable();
213
214
215                        return {
216                                element : element,
217                                parts :
218                                {
219                                        dialog          : element.getChild( 0 ),
220                                        title           : title,
221                                        close           : close,
222                                        tabs            : body.getChild( 2 ),
223                                        contents        : body.getChild( [ 3, 0, 0, 0 ] ),
224                                        footer          : body.getChild( 4 )
225                                }
226                        };
227                },
228
229                destroy : function( editor )
230                {
231                        var container = editor.container;
232                        container.clearCustomData();
233                        editor.element.clearCustomData();
234
235                        /*
236                         * IE BUG: Removing the editor DOM elements while the selection is inside
237                         * the editing area would break IE7/8's selection system. So we need to put
238                         * the selection back to the parent document without scrolling the window.
239                         * (#3812)
240                         */
241                        if ( CKEDITOR.env.ie )
242                        {
243                                container.setStyle( 'display', 'none' );
244
245                                var $range = document.body.createTextRange();
246                                $range.moveToElementText( container.$ );
247                                try
248                                {
249                                        // Putting the selection to a display:none element - this will certainly
250                                        // fail. But! We've just put the selection document back to the parent
251                                        // document without scrolling the window!
252                                        $range.select();
253                                }
254                                catch ( e ) {}
255                        }
256
257                        if ( container )
258                                container.remove();
259
260                        if ( editor.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
261                                editor.element.show();
262
263                        delete editor.element;
264                }
265        };
266})() );
267
268CKEDITOR.editor.prototype.getThemeSpace = function( spaceName )
269{
270        var spacePrefix = 'cke_' + spaceName;
271        var space = this._[ spacePrefix ] ||
272                ( this._[ spacePrefix ] = CKEDITOR.document.getById( spacePrefix + '_' + this.name ) );
273        return space;
274};
275
276CKEDITOR.editor.prototype.resize = function( width, height, isContentHeight, resizeInner )
277{
278        var numberRegex = /^\d+$/;
279        if ( numberRegex.test( width ) )
280                width += 'px';
281
282        var container = this.container,
283                contents = CKEDITOR.document.getById( 'cke_contents_' + this.name ),
284                outer = resizeInner ? container.getChild( 1 ) : container;
285
286        // Resize the width first.
287        // WEBKIT BUG: Webkit requires that we put the editor off from display when we
288        // resize it. If we don't, the browser crashes!
289        CKEDITOR.env.webkit && outer.setStyle( 'display', 'none' );
290        outer.setStyle( 'width', width );
291        if ( CKEDITOR.env.webkit )
292        {
293                outer.$.offsetWidth;
294                outer.setStyle( 'display', '' );
295        }
296
297        // Get the height delta between the outer table and the content area.
298        // If we're setting the content area's height, then we don't need the delta.
299        var delta = isContentHeight ? 0 : ( outer.$.offsetHeight || 0 ) - ( contents.$.clientHeight || 0 );
300        contents.setStyle( 'height', Math.max( height - delta, 0 ) + 'px' );
301
302        // Emit a resize event.
303        this.fire( 'resize' );
304};
305
306CKEDITOR.editor.prototype.getResizable = function()
307{
308        return this.container.getChild( 1 );
309};
310
311/**
312 * Makes it possible to place some of the editor UI blocks, like the toolbar
313 * and the elements path, into any element in the page.
314 * The elements used to hold the UI blocks can be shared among several editor
315 * instances. In that case, only the blocks of the active editor instance will
316 * display.
317 * @name CKEDITOR.config.sharedSpaces
318 * @type Object
319 * @default undefined
320 * @example
321 * // Place the toolbar inside the element with ID "someElementId" and the
322 * // elements path into the element with ID "anotherId".
323 * config.sharedSpaces =
324 * {
325 *     top : 'someElementId',
326 *     bottom : 'anotherId'
327 * };
328 * @example
329 * // Place the toolbar inside the element with ID "someElementId". The
330 * // elements path will remain attached to the editor UI.
331 * config.sharedSpaces =
332 * {
333 *     top : 'someElementId'
334 * };
335 */
Note: See TracBrowser for help on using the repository browser.