X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Flink%2Fplugin.js;h=c8e145f527f8f86d522b3aeff6b8b8f6d738fbfa;hb=refs%2Ftags%2Fv3.4;hp=c7f7adb77e3f3d6164749bd8644bfc2d13f3ca9b;hpb=055b6b0792ce7dc53d47af606b367c04b927c2ab;p=ckeditor.git diff --git a/_source/plugins/link/plugin.js b/_source/plugins/link/plugin.js index c7f7adb..c8e145f 100644 --- a/_source/plugins/link/plugin.js +++ b/_source/plugins/link/plugin.js @@ -58,7 +58,7 @@ CKEDITOR.plugins.add( 'link', * for this in Firefox. So we must detect the state by element paths. */ var command = editor.getCommand( 'unlink' ), - element = evt.data.path.lastElement.getAscendant( 'a', true ); + element = evt.data.path.lastElement && evt.data.path.lastElement.getAscendant( 'a', true ); if ( element && element.getName() == 'a' && element.getAttribute( 'href' ) ) command.setState( CKEDITOR.TRISTATE_OFF ); else @@ -110,7 +110,7 @@ CKEDITOR.plugins.add( 'link', { editor.contextMenu.addListener( function( element, selection ) { - if ( !element ) + if ( !element || element.isReadOnly() ) return null; var isAnchor = ( element.is( 'img' ) && element.getAttribute( '_cke_real_element_type' ) == 'anchor' ); @@ -177,12 +177,14 @@ CKEDITOR.plugins.link = getSelectedLink : function( editor ) { var range; - try { range = editor.getSelection().getRanges()[ 0 ]; } + try + { + range = editor.getSelection().getRanges( true )[ 0 ]; + range.shrink( CKEDITOR.SHRINK_TEXT ); + var root = range.getCommonAncestor(); + return root.getAscendant( 'a', true ); + } catch( e ) { return null; } - - range.shrink( CKEDITOR.SHRINK_TEXT ); - var root = range.getCommonAncestor(); - return root.getAscendant( 'a', true ); } };