| 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 | 'a' : 'lower-alpha', |
| 15 | 'A' : 'upper-alpha', |
| 16 | 'i' : 'lower-roman', |
| 17 | 'I' : 'upper-roman', |
| 18 | '1' : 'decimal', |
| 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 | || mapListStyle[ element.getAttribute( 'type' ) ] |
| 53 | || element.getAttribute( 'type' ) |
| 54 | || ''; |
| 55 | |
| 56 | this.setValue( value ); |
| 57 | }, |
| 58 | commit : function( element ) |
| 59 | { |
| 60 | var value = this.getValue(); |
| 61 | if ( value != '' ) |
| 62 | element.setStyle( 'list-style-type', value ); |
| 63 | else |
| 64 | element.removeStyle( 'list-style-type' ); |
| 65 | } |
| 66 | } |
| 67 | ] |
| 68 | } |
| 69 | ], |
| 70 | onShow: function() |
| 71 | { |
| 72 | var editor = this.getParentEditor(), |
| 73 | element = getListElement( editor, 'ul' ); |
| 74 | |
| 75 | element && this.setupContent( element ); |
| 76 | }, |
| 77 | onOk: function() |
| 78 | { |
| 79 | var editor = this.getParentEditor(), |
| 80 | element = getListElement( editor, 'ul' ); |
| 81 | |
| 82 | element && this.commitContent( element ); |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | else if ( startupPage == 'numberedListStyle' ) |
| 87 | { |
| 88 | return { |
| 89 | title : editor.lang.list.numberedTitle, |
| 90 | minWidth : 300, |
| 91 | minHeight : 50, |
| 92 | contents : |
| 93 | [ |
| 94 | { |
| 95 | elements : |
| 96 | [ |
| 97 | { |
| 98 | type : 'hbox', |
| 99 | widths : [ '25%', '75%' ], |
| 100 | children : |
| 101 | [ |
| 102 | { |
| 103 | label : editor.lang.list.start, |
| 104 | type : 'text', |
| 105 | id : 'start', |
| 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 | id : 'type', |
| 120 | style : 'width: 100%;', |
| 121 | items : |
| 122 | [ |
| 123 | [ editor.lang.list.notset, '' ], |
| 124 | [ editor.lang.list.armenian, 'armenian' ], |
| 125 | [ editor.lang.list.georgian, 'georgian' ], |
| 126 | [ editor.lang.list.lowerRoman, 'lower-roman' ], |
| 127 | [ editor.lang.list.upperRoman, 'upper-roman' ], |
| 128 | [ editor.lang.list.lowerAlpha, 'lower-alpha' ], |
| 129 | [ editor.lang.list.upperAlpha, 'upper-alpha' ], |
| 130 | [ editor.lang.list.lowerGreek, 'lower-greek' ], |
| 131 | [ editor.lang.list.decimal, 'decimal' ], |
| 132 | [ editor.lang.list.decimalLeadingZero, 'decimal-leading-zero' ], |
| 133 | ], |
| 134 | setup : function( element ) |
| 135 | { |
| 136 | var value = element.getStyle( 'list-style-type' ) |
| 137 | || mapListStyle[ element.getAttribute( 'type' ) ] |
| 138 | || element.getAttribute( 'type' ) |
| 139 | || ''; |
| 140 | |
| 141 | this.setValue( value ); |
| 142 | }, |
| 143 | commit : function( element ) |
| 144 | { |
| 145 | var value = this.getValue(); |
| 146 | if ( value != '' ) |
| 147 | element.setStyle( 'list-style-type', value ); |
| 148 | else |
| 149 | element.removeStyle( 'list-style-type' ); |
| 150 | } |
| 151 | } |
| 152 | ] |
| 153 | } |
| 154 | ] |
| 155 | } |
| 156 | ], |
| 157 | onShow: function() |
| 158 | { |
| 159 | var editor = this.getParentEditor(), |
| 160 | element = getListElement( editor, 'ol' ); |
| 161 | |
| 162 | element && this.setupContent( element ); |
| 163 | }, |
| 164 | onOk: function() |
| 165 | { |
| 166 | var editor = this.getParentEditor(), |
| 167 | element = getListElement( editor, 'ol' ); |
| 168 | |
| 169 | element && this.commitContent( element ); |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | }; |
| 174 | |
| 175 | CKEDITOR.dialog.add( 'numberedListStyle', function( editor ) |
| 176 | { |
| 177 | return listStyle( editor, 'numberedListStyle' ); |
| 178 | }); |
| 179 | |
| 180 | CKEDITOR.dialog.add( 'bulletedListStyle', function( editor ) |
| 181 | { |
| 182 | return listStyle( editor, 'bulletedListStyle' ); |
| 183 | }); |
| 184 | })(); |
| 185 | No newline at end of file |