X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=_source%2Fplugins%2Flink%2Fplugin.js;h=3cdc6fb8e699a428ae224c3d437019068ff49012;hb=refs%2Ftags%2Fv3.4.1;hp=f373eaf339f2caef828b4fc03254b651c8b97970;hpb=f8fc585c18d287eb325c575596d183122486b641;p=ckeditor.git diff --git a/_source/plugins/link/plugin.js b/_source/plugins/link/plugin.js index f373eaf..3cdc6fb 100644 --- a/_source/plugins/link/plugin.js +++ b/_source/plugins/link/plugin.js @@ -37,8 +37,8 @@ CKEDITOR.plugins.add( 'link', 'background-position: center center;' + 'background-repeat: no-repeat;' + 'border: 1px solid #a9a9a9;' + - 'width: 18px;' + - 'height: 18px;' + + 'width: 18px !important;' + + 'height: 18px !important;' + '}\n' + 'a.cke_anchor' + '{' + @@ -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' ); @@ -176,13 +176,22 @@ CKEDITOR.plugins.link = */ getSelectedLink : function( editor ) { - var range; - try { range = editor.getSelection().getRanges()[ 0 ]; } + try + { + var selection = editor.getSelection(); + if ( selection.getType() == CKEDITOR.SELECTION_ELEMENT ) + { + var selectedElement = selection.getSelectedElement(); + if ( selectedElement.is( 'a' ) ) + return selectedElement; + } + + var range = selection.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 ); } };