| 8 | /** |
| 9 | * Simulate "this" of a dialog for non-dialog events. |
| 10 | * @type {CKEDITOR.dialog} |
| 11 | */ |
| 12 | var dialog; |
| 13 | var onChoice = function( evt ) |
| 14 | { |
| 15 | var target = evt.data.getTarget(), |
| 16 | value; |
| 17 | |
| 18 | if ( target.getName() == 'a' && ( value = target.getChild( 0 ).getHtml() ) ) |
| 19 | { |
| 20 | target.removeClass( "cke_light_background" ); |
| 21 | editor.insertHtml( value ); |
| 22 | dialog.hide(); |
| 23 | } |
| 24 | }; |
| 25 | |
| 26 | var focusedNode; |
| 27 | |
| 28 | var onFocus = function( evt, target ) |
| 29 | { |
| 30 | var value; |
| 31 | target = target || evt.data.getTarget(); |
| 32 | |
| 33 | if ( target.getName() == 'span' ) |
| 34 | target = target.getParent(); |
| 35 | |
| 36 | if ( target.getName() == 'a' && ( value = target.getChild( 0 ).getHtml() ) ) |
| 37 | { |
| 38 | // Trigger blur manually if there is focused node. |
| 39 | if ( focusedNode ) |
| 40 | onBlur( null, focusedNode ); |
| 41 | |
| 42 | var htmlPreview = dialog.getContentElement( 'info', 'htmlPreview' ).getElement(); |
| 43 | |
| 44 | dialog.getContentElement( 'info', 'charPreview' ).getElement().setHtml( value ); |
| 45 | htmlPreview.setHtml( CKEDITOR.tools.htmlEncode( value ) ); |
| 46 | target.getParent().addClass( "cke_light_background" ); |
| 47 | |
| 48 | // Memorize focused node. |
| 49 | focusedNode = target; |
| 50 | } |
| 51 | }; |
| 52 | |
| 53 | var onBlur = function( evt, target ) |
| 54 | { |
| 55 | target = target || evt.data.getTarget(); |
| 56 | |
| 57 | if ( target.getName() == 'span' ) |
| 58 | target = target.getParent(); |
| 59 | |
| 60 | if ( target.getName() == 'a' ) |
| 61 | { |
| 62 | dialog.getContentElement( 'info', 'charPreview' ).getElement().setHtml( ' ' ); |
| 63 | dialog.getContentElement( 'info', 'htmlPreview' ).getElement().setHtml( ' ' ); |
| 64 | target.getParent().removeClass( "cke_light_background" ); |
| 65 | |
| 66 | focusedNode = undefined; |
| 67 | } |
| 68 | }; |
| 69 | |
| 70 | var onKeydown = CKEDITOR.tools.addFunction( function( ev ) |
| 71 | { |
| 72 | ev = new CKEDITOR.dom.event( ev ); |
| 73 | |
| 74 | // Get an Anchor element. |
| 75 | var element = ev.getTarget(); |
| 76 | var relative, nodeToMove; |
| 77 | var keystroke = ev.getKeystroke(); |
| 78 | |
| 79 | switch ( keystroke ) |
| 80 | { |
| 81 | // RIGHT-ARROW |
| 82 | case 39 : |
| 83 | // relative is TD |
| 84 | if ( ( relative = element.getParent().getNext() ) ) |
| 85 | { |
| 86 | nodeToMove = relative.getChild( 0 ); |
| 87 | if ( nodeToMove.type == 1 ) |
| 88 | { |
| 89 | nodeToMove.focus(); |
| 90 | onBlur( null, element ); |
| 91 | onFocus( null, nodeToMove ); |
| 92 | } |
| 93 | } |
| 94 | ev.preventDefault(); |
| 95 | break; |
| 96 | // LEFT-ARROW |
| 97 | case 37 : |
| 98 | // relative is TD |
| 99 | if ( ( relative = element.getParent().getPrevious() ) ) |
| 100 | { |
| 101 | nodeToMove = relative.getChild( 0 ); |
| 102 | nodeToMove.focus(); |
| 103 | onBlur( null, element ); |
| 104 | onFocus( null, nodeToMove ); |
| 105 | } |
| 106 | ev.preventDefault(); |
| 107 | break; |
| 108 | // UP-ARROW |
| 109 | case 38 : |
| 110 | // relative is TR |
| 111 | if ( ( relative = element.getParent().getParent().getPrevious() ) ) |
| 112 | { |
| 113 | nodeToMove = relative.getChild( [element.getParent().getIndex(), 0] ); |
| 114 | nodeToMove.focus(); |
| 115 | onBlur( null, element ); |
| 116 | onFocus( null, nodeToMove ); |
| 117 | } |
| 118 | ev.preventDefault(); |
| 119 | break; |
| 120 | // DOWN-ARROW |
| 121 | case 40 : |
| 122 | // relative is TR |
| 123 | if ( ( relative = element.getParent().getParent().getNext() ) ) |
| 124 | { |
| 125 | nodeToMove = relative.getChild( [ element.getParent().getIndex(), 0 ] ); |
| 126 | if ( nodeToMove && nodeToMove.type == 1 ) |
| 127 | { |
| 128 | nodeToMove.focus(); |
| 129 | onBlur( null, element ); |
| 130 | onFocus( null, nodeToMove ); |
| 131 | } |
| 132 | } |
| 133 | ev.preventDefault(); |
| 134 | break; |
| 135 | // ENTER |
| 136 | // SPACE |
| 137 | case 13 : |
| 138 | case 32 : |
| 139 | onChoice( { data: ev } ); |
| 140 | ev.preventDefault(); |
| 141 | break; |
| 142 | // TAB |
| 143 | case 9 : |
| 144 | // relative is TD |
| 145 | if ( ( relative = element.getParent().getNext() ) ) |
| 146 | { |
| 147 | nodeToMove = relative.getChild( 0 ); |
| 148 | if ( nodeToMove.type == 1 ) |
| 149 | { |
| 150 | nodeToMove.focus(); |
| 151 | onBlur( null, element ); |
| 152 | onFocus( null, nodeToMove ); |
| 153 | ev.preventDefault( true ); |
| 154 | } |
| 155 | else |
| 156 | onBlur( null, element ); |
| 157 | } |
| 158 | // relative is TR |
| 159 | else if ( ( relative = element.getParent().getParent().getNext() ) ) |
| 160 | { |
| 161 | nodeToMove = relative.getChild( [ 0, 0 ] ); |
| 162 | if ( nodeToMove && nodeToMove.type == 1 ) |
| 163 | { |
| 164 | nodeToMove.focus(); |
| 165 | onBlur( null, element ); |
| 166 | onFocus( null, nodeToMove ); |
| 167 | ev.preventDefault( true ); |
| 168 | } |
| 169 | else |
| 170 | onBlur( null, element ); |
| 171 | } |
| 172 | break; |
| 173 | // SHIFT + TAB |
| 174 | case CKEDITOR.SHIFT + 9 : |
| 175 | // relative is TD |
| 176 | if ( ( relative = element.getParent().getPrevious() ) ) |
| 177 | { |
| 178 | nodeToMove = relative.getChild( 0 ); |
| 179 | nodeToMove.focus(); |
| 180 | onBlur( null, element ); |
| 181 | onFocus( null, nodeToMove ); |
| 182 | ev.preventDefault( true ); |
| 183 | } |
| 184 | // relative is TR |
| 185 | else if ( ( relative = element.getParent().getParent().getPrevious() ) ) |
| 186 | { |
| 187 | nodeToMove = relative.getLast().getChild( 0 ); |
| 188 | nodeToMove.focus(); |
| 189 | onBlur( null, element ); |
| 190 | onFocus( null, nodeToMove ); |
| 191 | ev.preventDefault( true ); |
| 192 | } |
| 193 | else |
| 194 | onBlur( null, element ); |
| 195 | break; |
| 196 | default : |
| 197 | // Do not stop not handled events. |
| 198 | return; |
| 199 | } |
| 200 | }); |
| 201 | |