source: sandbox/3.0/phpgwapi/js/ckeditor/_source/plugins/listblock/plugin.js @ 2862

Revision 2862, 6.7 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.plugins.add( 'listblock',
7{
8        requires : [ 'panel' ],
9
10        onLoad : function()
11        {
12                CKEDITOR.ui.panel.prototype.addListBlock = function( name, definition )
13                {
14                        return this.addBlock( name, new CKEDITOR.ui.listBlock( this.getHolderElement(), definition ) );
15                };
16
17                CKEDITOR.ui.listBlock = CKEDITOR.tools.createClass(
18                        {
19                                base : CKEDITOR.ui.panel.block,
20
21                                $ : function( blockHolder, blockDefinition )
22                                {
23                                        blockDefinition = blockDefinition || {};
24
25                                        var attribs = blockDefinition.attributes || ( blockDefinition.attributes = {} );
26                                        ( this.multiSelect = !!blockDefinition.multiSelect ) &&
27                                                ( attribs[ 'aria-multiselectable' ] = true );
28                                        // Provide default role of 'listbox'.
29                                        !attribs.role && ( attribs.role = 'listbox' );
30
31                                        // Call the base contructor.
32                                        this.base.apply( this, arguments );
33
34                                        var keys = this.keys;
35                                        keys[ 40 ]      = 'next';                                       // ARROW-DOWN
36                                        keys[ 9 ]       = 'next';                                       // TAB
37                                        keys[ 38 ]      = 'prev';                                       // ARROW-UP
38                                        keys[ CKEDITOR.SHIFT + 9 ]      = 'prev';       // SHIFT + TAB
39                                        keys[ 32 ]      = 'click';                                      // SPACE
40
41                                        this._.pendingHtml = [];
42                                        this._.items = {};
43                                        this._.groups = {};
44                                },
45
46                                _ :
47                                {
48                                        close : function()
49                                        {
50                                                if ( this._.started )
51                                                {
52                                                        this._.pendingHtml.push( '</ul>' );
53                                                        delete this._.started;
54                                                }
55                                        },
56
57                                        getClick : function()
58                                        {
59                                                if ( !this._.click )
60                                                {
61                                                        this._.click = CKEDITOR.tools.addFunction( function( value )
62                                                                {
63                                                                        var marked = true;
64
65                                                                        if ( this.multiSelect )
66                                                                                marked = this.toggle( value );
67                                                                        else
68                                                                                this.mark( value );
69
70                                                                        if ( this.onClick )
71                                                                                this.onClick( value, marked );
72                                                                },
73                                                                this );
74                                                }
75                                                return this._.click;
76                                        }
77                                },
78
79                                proto :
80                                {
81                                        add : function( value, html, title )
82                                        {
83                                                var pendingHtml = this._.pendingHtml,
84                                                        id = 'cke_' + CKEDITOR.tools.getNextNumber();
85
86                                                if ( !this._.started )
87                                                {
88                                                        pendingHtml.push( '<ul role="presentation" class=cke_panel_list>' );
89                                                        this._.started = 1;
90                                                        this._.size = this._.size || 0;
91                                                }
92
93                                                this._.items[ value ] = id;
94
95                                                pendingHtml.push(
96                                                        '<li id=', id, ' class=cke_panel_listItem>' +
97                                                                '<a id="', id, '_option" _cke_focus=1 hidefocus=true' +
98                                                                        ' title="', title || value, '"' +
99                                                                        ' href="javascript:void(\'', value, '\')"' +
100                                                                        ' onclick="CKEDITOR.tools.callFunction(', this._.getClick(), ',\'', value, '\'); return false;"',
101                                                                        ' role="option"' +
102                                                                        ' aria-posinset="' + ++this._.size + '">',
103                                                                        html || value,
104                                                                '</a>' +
105                                                        '</li>' );
106                                        },
107
108                                        startGroup : function( title )
109                                        {
110                                                this._.close();
111
112                                                var id = 'cke_' + CKEDITOR.tools.getNextNumber();
113
114                                                this._.groups[ title ] = id;
115
116                                                this._.pendingHtml.push( '<h1 role="presentation" id=', id, ' class=cke_panel_grouptitle>', title, '</h1>' );
117                                        },
118
119                                        commit : function()
120                                        {
121                                                this._.close();
122                                                this.element.appendHtml( this._.pendingHtml.join( '' ) );
123
124                                                var items = this._.items,
125                                                        doc = this.element.getDocument();
126                                                for ( var value in items )
127                                                        if ( ! ( value in Object.prototype ) )
128                                                                doc.getById( items[ value ] + '_option' ).setAttribute( 'aria-setsize', this._.size );
129                                                delete this._.size;
130
131                                                this._.pendingHtml = [];
132                                        },
133
134                                        toggle : function( value )
135                                        {
136                                                var isMarked = this.isMarked( value );
137
138                                                if ( isMarked )
139                                                        this.unmark( value );
140                                                else
141                                                        this.mark( value );
142
143                                                return !isMarked;
144                                        },
145
146                                        hideGroup : function( groupTitle )
147                                        {
148                                                var group = this.element.getDocument().getById( this._.groups[ groupTitle ] ),
149                                                        list = group && group.getNext();
150
151                                                if ( group )
152                                                {
153                                                        group.setStyle( 'display', 'none' );
154
155                                                        if ( list && list.getName() == 'ul' )
156                                                                list.setStyle( 'display', 'none' );
157                                                }
158                                        },
159
160                                        hideItem : function( value )
161                                        {
162                                                this.element.getDocument().getById( this._.items[ value ] ).setStyle( 'display', 'none' );
163                                        },
164
165                                        showAll : function()
166                                        {
167                                                var items = this._.items,
168                                                        groups = this._.groups,
169                                                        doc = this.element.getDocument();
170
171                                                for ( var value in items )
172                                                        if ( ! ( value in Object.prototype ) )
173                                                        {
174                                                                doc.getById( items[ value ] ).setStyle( 'display', '' );
175                                                        }
176
177                                                for ( var title in groups )
178                                                        if ( ! ( title in Object.prototype ) )
179                                                        {
180                                                                var group = doc.getById( groups[ title ] ),
181                                                                        list = group.getNext();
182
183                                                                group.setStyle( 'display', '' );
184
185                                                                if ( list && list.getName() == 'ul' )
186                                                                        list.setStyle( 'display', '' );
187                                                        }
188                                        },
189
190                                        mark : function( value )
191                                        {
192                                                if ( !this.multiSelect )
193                                                        this.unmarkAll();
194
195                                                var itemId = this._.items[ value ],
196                                                        item = this.element.getDocument().getById( itemId );
197                                                item.addClass( 'cke_selected' );
198
199                                                this.element.getDocument().getById( itemId + '_option' ).setAttribute( 'aria-selected', true );
200                                                this.element.setAttribute( 'aria-activedescendant', itemId + '_option' );
201
202                                                this.onMark && this.onMark( item );
203                                        },
204
205                                        unmark : function( value )
206                                        {
207                                                this.element.getDocument().getById( this._.items[ value ] ).removeClass( 'cke_selected' );
208                                                this.onUnmark && this.onUnmark( this._.items[ value ] );
209                                        },
210
211                                        unmarkAll : function()
212                                        {
213                                                var items = this._.items,
214                                                        doc = this.element.getDocument();
215
216                                                for ( var value in items )
217                                                        if ( ! ( value in Object.prototype ) )
218                                                        {
219                                                                doc.getById( items[ value ] ).removeClass( 'cke_selected' );
220                                                        }
221
222                                                this.onUnmark && this.onUnmark();
223                                        },
224
225                                        isMarked : function( value )
226                                        {
227                                                return this.element.getDocument().getById( this._.items[ value ] ).hasClass( 'cke_selected' );
228                                        },
229
230                                        focus : function( value )
231                                        {
232                                                this._.focusIndex = -1;
233
234                                                if ( value )
235                                                {
236                                                        var selected = this.element.getDocument().getById( this._.items[ value ] ).getFirst();
237
238                                                        var links = this.element.getElementsByTag( 'a' ),
239                                                                link,
240                                                                i = -1;
241
242                                                        while ( ( link = links.getItem( ++i ) ) )
243                                                        {
244                                                                if ( link.equals( selected ) )
245                                                                {
246                                                                        this._.focusIndex = i;
247                                                                        break;
248                                                                }
249                                                        }
250
251                                                        setTimeout( function()
252                                                                {
253                                                                        selected.focus();
254                                                                },
255                                                                0 );
256                                                }
257                                        }
258                                }
259                        });
260        }
261});
Note: See TracBrowser for help on using the repository browser.