| 1 | (function() |
| 2 | { |
| 3 | function getListElement( editor, listTag ) |
| 4 | { |
| 5 | var range; |
| 6 | try { range = editor.getSelection().getRanges()[ 0 ]; } |
| 7 | catch( e ) { return null; } |
| 8 | |
| 9 | range.shrink( CKEDITOR.SHRINK_TEXT ); |
| 10 | return range.getCommonAncestor().getAscendant( listTag, true ); |
| 11 | } |
| 12 | |
| 13 | var mapListStyle = { |
| 14 | 'lower-alpha' : 'a', |
| 15 | 'upper-alpha' : 'A', |
| 16 | 'lower-roman' : 'i', |
| 17 | 'upper-roman' : 'I', |
| 18 | 'decimal' : 1, |
| 19 | 'disc' : 'disc', |
| 20 | 'circle' : 'circle', |
| 21 | 'square' : 'square' |
| 22 | }; |
| 23 | |
| 24 | function listStyle( editor, startupPage ) |
| 25 | { |
| 26 | if ( startupPage == 'bulletedListStyle' ) |
| 27 | { |
| 28 | return { |
| 29 | title : editor.lang.list.bulletedTitle, |
| 30 | minWidth : 300, |
| 31 | minHeight : 50, |
| 32 | contents : |
| 33 | [ |
| 34 | { |
| 35 | elements : |
| 36 | [ |
| 37 | { |
| 38 | type : 'select', |
| 39 | label : editor.lang.list.type, |
| 40 | id: 'type', |
| 41 | style: 'width: 150px; margin: auto;', |
| 42 | items : |
| 43 | [ |
| 44 | [ editor.lang.list.notset, '' ], |
| 45 | [ editor.lang.list.circle, 'circle' ], |
| 46 | [ editor.lang.list.disc, 'disc' ], |
| 47 | [ editor.lang.list.square, 'square' ] |
| 48 | ], |
| 49 | setup : function( element ) |
| 50 | { |
| 51 | var value = element.getStyle( 'list-style-type' ) || |
| 52 | element.getAttribute( 'type' ) || ''; |
| 53 | |
| 54 | this.setValue( value ); |
| 55 | }, |
| 56 | commit : function( element ) |
| 57 | { |
| 58 | var value = this.getValue(); |
| 59 | if ( value != '' ) |
| 60 | { |
| 61 | element.setStyle( 'list-style-type', value ); |
| 62 | if ( value in mapListStyle ) |
| 63 | element.setAttribute( 'type', value ); |
| 64 | } |
| 65 | else |
| 66 | { |
| 67 | element.removeAttribute( 'type' ); |
| 68 | element.removeStyle( 'list-style-type' ); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | ] |
| 73 | } |
| 74 | ], |
| 75 | onShow: function() |
| 76 | { |
| 77 | var editor = this.getParentEditor(), |
| 78 | element = getListElement( editor, 'ul' ); |
| 79 | |
| 80 | element && this.setupContent( element ); |
| 81 | }, |
| 82 | onOk: function() |
| 83 | { |
| 84 | var editor = this.getParentEditor(), |
| 85 | element = getListElement( editor, 'ul' ); |
| 86 | |
| 87 | element && this.commitContent( element ); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | else if ( startupPage == 'numberedListStyle' ) |
| 92 | { |
| 93 | return { |
| 94 | title : editor.lang.list.numberedTitle, |
| 95 | minWidth : 300, |
| 96 | minHeight : 50, |
| 97 | contents : |
| 98 | [ |
| 99 | { |
| 100 | elements : |
| 101 | [ |
| 102 | { |
| 103 | type : 'hbox', |
| 104 | widths : [ '25%', '75%' ], |
| 105 | children : |
| 106 | [ |
| 107 | { |
| 108 | label: editor.lang.list.start, |
| 109 | type: 'text', |
| 110 | setup : function( element ) |
| 111 | { |
| 112 | var value = element.getAttribute( 'start' ) || 1; |
| 113 | value && this.setValue( value ); |
| 114 | }, |
| 115 | commit : function( element ) |
| 116 | { |
| 117 | element.setAttribute( 'start', this.getValue() ); |
| 118 | } |
| 119 | }, |
| 120 | { |
| 121 | type : 'select', |
| 122 | label : editor.lang.list.type, |
| 123 | style: 'width: 100%;', |
| 124 | items : |
| 125 | [ |
| 126 | [ editor.lang.list.notset, '' ], |
| 127 | [ editor.lang.list.armenian, 'armenian' ], |
| 128 | [ editor.lang.list.georgian, 'georgian' ], |
| 129 | [ editor.lang.list.lowerRoman, 'lower-roman' ], |
| 130 | [ editor.lang.list.upperRoman, 'upper-roman' ], |
| 131 | [ editor.lang.list.lowerAlpha, 'lower-alpha' ], |
| 132 | [ editor.lang.list.upperAlpha, 'upper-alpha' ], |
| 133 | [ editor.lang.list.lowerGreek, 'lower-greek' ], |
| 134 | [ editor.lang.list.decimal, 'decimal' ], |
| 135 | [ editor.lang.list.decimalLeadingZero, 'decimal-leading-zero' ], |
| 136 | ], |
| 137 | setup : function( element ) |
| 138 | { |
| 139 | var value = element.getStyle( 'list-style-type' ) || |
| 140 | element.getAttribute( 'type' ) || ''; |
| 141 | |
| 142 | this.setValue( value ); |
| 143 | }, |
| 144 | commit : function( element ) |
| 145 | { |
| 146 | var value = this.getValue(); |
| 147 | // Reset style. |
| 148 | element.removeAttribute( 'type' ); |
| 149 | element.removeStyle( 'list-style-type' ); |
| 150 | |
| 151 | if ( value != '' ) |
| 152 | element.setStyle( 'list-style-type', value ); |
| 153 | |
| 154 | if ( value in mapListStyle ) |
| 155 | element.setAttribute( 'type', mapListStyle[value] ); |
| 156 | |
| 157 | } |
| 158 | } |
| 159 | ] |
| 160 | } |
| 161 | ] |
| 162 | } |
| 163 | ], |
| 164 | onShow: function() |
| 165 | { |
| 166 | var editor = this.getParentEditor(), |
| 167 | element = getListElement( editor, 'ol' ); |
| 168 | |
| 169 | element && this.setupContent( element ); |
| 170 | }, |
| 171 | onOk: function() |
| 172 | { |
| 173 | var editor = this.getParentEditor(), |
| 174 | element = getListElement( editor, 'ol' ); |
| 175 | |
| 176 | element && this.commitContent( element ); |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | }; |
| 181 | |
| 182 | CKEDITOR.dialog.add( 'numberedListStyle', function( editor ) |
| 183 | { |
| 184 | return listStyle( editor, 'numberedListStyle' ); |
| 185 | }); |
| 186 | |
| 187 | CKEDITOR.dialog.add( 'bulletedListStyle', function( editor ) |
| 188 | { |
| 189 | return listStyle( editor, 'bulletedListStyle' ); |
| 190 | }); |
| 191 | })(); |
| 192 | No newline at end of file |