Ticket #28258: 28258.2.patch
| File 28258.2.patch, 3.8 KB (added by , 12 years ago) |
|---|
-
src/wp-includes/js/tinymce/plugins/wpview/plugin.js
4 4 */ 5 5 tinymce.PluginManager.add( 'wpview', function( editor ) { 6 6 var selected, 7 VK = tinymce.util.VK,7 Env = tinymce.Env, 8 8 TreeWalker = tinymce.dom.TreeWalker, 9 VK = tinymce.util.VK, 9 10 toRemove = false; 10 11 11 12 function getParentView( node ) { … … 24 25 25 26 function createPadNode() { 26 27 return editor.dom.create( 'p', { 'data-wpview-pad': 1 }, 27 ( tinymce.Env.ie && tinymce.Env.ie < 11 ) ? '' : '<br data-mce-bogus="1" />' );28 ( Env.ie && Env.ie < 11 ) ? '' : '<br data-mce-bogus="1" />' ); 28 29 } 29 30 30 31 /** … … 289 290 event.stopPropagation(); 290 291 291 292 // Hack to try and keep the block resize handles from appearing. They will show on mousedown and then be removed on mouseup. 292 if ( tinymce.Env.ie <= 10 ) {293 if ( Env.ie <= 10 ) { 293 294 deselect(); 294 295 } 295 296 … … 309 310 310 311 // Fix issue with deselecting a view in IE8. Without this hack, clicking content above the view wouldn't actually deselect it 311 312 // and the caret wouldn't be placed at the mouse location 312 if ( tinymce.Env.ie && tinymce.Env.ie <= 8 ) {313 if ( Env.ie && Env.ie <= 8 ) { 313 314 deselectEventType = 'mouseup'; 314 315 } else { 315 316 deselectEventType = 'mousedown'; … … 357 358 }); 358 359 359 360 editor.on( 'keydown', function( event ) { 360 var keyCode = event.keyCode,361 var dom = editor.dom, 361 362 body = editor.getBody(), 363 keyCode = event.keyCode, 364 selection = editor.selection, 362 365 view, padNode; 363 366 364 367 // If a view isn't selected, let the event go on its merry way. … … 375 378 return; 376 379 } 377 380 378 view = getParentView( editor.selection.getNode() );381 view = getParentView( selection.getNode() ); 379 382 380 383 // If the caret is not within the selected view, deselect the 381 384 // view and bail. … … 394 397 } else if ( ! view.previousSibling ) { 395 398 padNode = createPadNode(); 396 399 body.insertBefore( padNode, body.firstChild ); 397 editor.selection.setCursorLocation( body.firstChild, 0 );400 selection.setCursorLocation( body.firstChild, 0 ); 398 401 // Handle default case 399 402 } else { 400 editor.selection.select( view.previousSibling, true );401 editor.selection.collapse();403 selection.select( view.previousSibling, true ); 404 selection.collapse(); 402 405 } 403 406 } else if ( keyCode === VK.RIGHT || keyCode === VK.DOWN ) { 404 407 deselect(); … … 409 412 } else if ( ! view.nextSibling ) { 410 413 padNode = createPadNode(); 411 414 body.appendChild( padNode ); 412 editor.selection.setCursorLocation( body.lastChild, 0 );415 selection.setCursorLocation( body.lastChild, 0 ); 413 416 // Handle default case where the next node is a non-wpview 414 417 } else { 415 editor.selection.setCursorLocation( view.nextSibling, 0 );418 selection.setCursorLocation( view.nextSibling, 0 ); 416 419 } 420 // Create a new paragraph when pressing enter/return. 421 } else if ( keyCode === VK.ENTER ) { 422 if ( dom.isEmpty( view.nextSibling ) && view.nextSibling.nodeName === 'P' ) { 423 padNode = view.nextSibling; 424 } else { 425 padNode = dom.create( 'p' ); 426 // BR is needed in empty blocks on non IE browsers. 427 if ( ! ( Env.ie && Env.ie < 11 ) ) { 428 padNode.innerHTML = '<br data-mce-bogus="1">'; 429 } 430 dom.insertAfter( padNode, selected ); 431 } 432 deselect(); 433 selection.setCursorLocation( padNode, 0 ); 434 // If delete or backspace is pressed, delete the view. 417 435 } else if ( keyCode === VK.DELETE || keyCode === VK.BACKSPACE ) { 418 // If delete or backspace is pressed, delete the view. 419 editor.dom.remove( selected ); 436 dom.remove( selected ); 420 437 } 421 438 422 439 event.preventDefault();