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