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