X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Flink%2Fplugin.js;h=f0278ec20f0067237e58388dc9dba6b210ff1ef5;hb=614511639979907ceb0da3614122a4d8eb963ad4;hp=7993a0f30d60b9c9528b55a3131fd4f1d9be6f6b;hpb=941b0a9ba4e673e292510d80a5a86806994b8ea6;p=ckeditor.git diff --git a/_source/plugins/link/plugin.js b/_source/plugins/link/plugin.js index 7993a0f..f0278ec 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,13 +58,26 @@ 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 command.setState( CKEDITOR.TRISTATE_DISABLED ); } ); + editor.on( 'doubleclick', function( evt ) + { + var element = CKEDITOR.plugins.link.getSelectedLink( editor ) || evt.data.element; + + if ( !element.isReadOnly() ) + { + if ( element.is( 'a' ) ) + evt.data.dialog = ( element.getAttribute( 'name' ) && !element.getAttribute( 'href' ) ) ? 'anchor' : 'link'; + else if ( element.is( 'img' ) && element.getAttribute( '_cke_real_element_type' ) == 'anchor' ) + evt.data.dialog = 'anchor'; + } + }); + // If the "menu" plugin is loaded, register the menu items. if ( editor.addMenuItems ) { @@ -100,14 +113,14 @@ 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' ); if ( !isAnchor ) { - if ( !( element = element.getAscendant( 'a', true ) ) ) + if ( !( element = CKEDITOR.plugins.link.getSelectedLink( editor ) ) ) return null; isAnchor = ( element.getAttribute( 'name' ) && !element.getAttribute( 'href' ) ); @@ -147,6 +160,44 @@ CKEDITOR.plugins.add( 'link', requires : [ 'fakeobjects' ] } ); +CKEDITOR.plugins.link = +{ + /** + * Get the surrounding link element of current selection. + * @param editor + * @example CKEDITOR.plugins.link.getSelectedLink( editor ); + * @since 3.2.1 + * The following selection will all return the link element. + *
+	 *  li^nk
+	 *  [link]
+	 *  text[link]
+	 *  li[nk]
+	 *  [li]nk]
+	 *  [li]nk
+	 * 
+ */ + getSelectedLink : function( editor ) + { + 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; } + } +}; + CKEDITOR.unlinkCommand = function(){}; CKEDITOR.unlinkCommand.prototype = { @@ -178,7 +229,9 @@ CKEDITOR.unlinkCommand.prototype = selection.selectRanges( ranges ); editor.document.$.execCommand( 'unlink', false, null ); selection.selectBookmarks( bookmarks ); - } + }, + + startDisabled : true }; CKEDITOR.tools.extend( CKEDITOR.config,