2 * Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 * For licensing, see LICENSE.html or http://ckeditor.com/license
8 function getListElement( editor, listTag )
11 try { range = editor.getSelection().getRanges()[ 0 ]; }
12 catch( e ) { return null; }
14 range.shrink( CKEDITOR.SHRINK_TEXT );
15 return range.getCommonAncestor().getAscendant( listTag, 1 );
18 var listItem = function( node ) { return node.type == CKEDITOR.NODE_ELEMENT && node.is( 'li' ); };
31 function listStyle( editor, startupPage )
33 var lang = editor.lang.list;
34 if ( startupPage == 'bulletedListStyle' )
37 title : lang.bulletedTitle,
52 style : 'width:150px',
56 [ lang.circle, 'circle' ],
57 [ lang.disc, 'disc' ],
58 [ lang.square, 'square' ]
60 setup : function( element )
62 var value = element.getStyle( 'list-style-type' )
63 || mapListStyle[ element.getAttribute( 'type' ) ]
64 || element.getAttribute( 'type' )
67 this.setValue( value );
69 commit : function( element )
71 var value = this.getValue();
73 element.setStyle( 'list-style-type', value );
75 element.removeStyle( 'list-style-type' );
83 var editor = this.getParentEditor(),
84 element = getListElement( editor, 'ul' );
86 element && this.setupContent( element );
90 var editor = this.getParentEditor(),
91 element = getListElement( editor, 'ul' );
93 element && this.commitContent( element );
97 else if ( startupPage == 'numberedListStyle' )
100 var listStyleOptions =
103 [ lang.lowerRoman, 'lower-roman' ],
104 [ lang.upperRoman, 'upper-roman' ],
105 [ lang.lowerAlpha, 'lower-alpha' ],
106 [ lang.upperAlpha, 'upper-alpha' ],
107 [ lang.decimal, 'decimal' ]
110 if ( !CKEDITOR.env.ie || CKEDITOR.env.version > 7 )
112 listStyleOptions.concat( [
113 [ lang.armenian, 'armenian' ],
114 [ lang.decimalLeadingZero, 'decimal-leading-zero' ],
115 [ lang.georgian, 'georgian' ],
116 [ lang.lowerGreek, 'lower-greek' ]
121 title : lang.numberedTitle,
133 widths : [ '25%', '75%' ],
140 validate : CKEDITOR.dialog.validate.integer( lang.validateStartNumber ),
141 setup : function( element )
143 // List item start number dominates.
144 var value = element.getFirst( listItem ).getAttribute( 'value' ) || element.getAttribute( 'start' ) || 1;
145 value && this.setValue( value );
147 commit : function( element )
149 var firstItem = element.getFirst( listItem );
150 var oldStart = firstItem.getAttribute( 'value' ) || element.getAttribute( 'start' ) || 1;
152 // Force start number on list root.
153 element.getFirst( listItem ).removeAttribute( 'value' );
154 var val = parseInt( this.getValue(), 10 );
156 element.removeAttribute( 'start' );
158 element.setAttribute( 'start', val );
160 // Update consequent list item numbering.
161 var nextItem = firstItem, conseq = oldStart, startNumber = isNaN( val ) ? 1 : val;
162 while ( ( nextItem = nextItem.getNext( listItem ) ) && conseq++ )
164 if ( nextItem.getAttribute( 'value' ) == conseq )
165 nextItem.setAttribute( 'value', startNumber + conseq - oldStart );
173 style : 'width: 100%;',
174 items : listStyleOptions,
175 setup : function( element )
177 var value = element.getStyle( 'list-style-type' )
178 || mapListStyle[ element.getAttribute( 'type' ) ]
179 || element.getAttribute( 'type' )
182 this.setValue( value );
184 commit : function( element )
186 var value = this.getValue();
188 element.setStyle( 'list-style-type', value );
190 element.removeStyle( 'list-style-type' );
200 var editor = this.getParentEditor(),
201 element = getListElement( editor, 'ol' );
203 element && this.setupContent( element );
207 var editor = this.getParentEditor(),
208 element = getListElement( editor, 'ol' );
210 element && this.commitContent( element );
216 CKEDITOR.dialog.add( 'numberedListStyle', function( editor )
218 return listStyle( editor, 'numberedListStyle' );
221 CKEDITOR.dialog.add( 'bulletedListStyle', function( editor )
223 return listStyle( editor, 'bulletedListStyle' );