| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 /* 2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. 3 For licensing, see LICENSE.html or http://ckeditor.com/license 4 */ 5 6 CKEDITOR.plugins.add( 'link', 7 { 8 init : function( editor ) 9 { 10 // Add the link and unlink buttons. 11 editor.addCommand( 'link', new CKEDITOR.dialogCommand( 'link' ) ); 12 editor.addCommand( 'anchor', new CKEDITOR.dialogCommand( 'anchor' ) ); 13 editor.addCommand( 'unlink', new CKEDITOR.unlinkCommand() ); 14 editor.ui.addButton( 'Link', 15 { 16 label : editor.lang.link.toolbar, 17 command : 'link' 18 } ); 19 editor.ui.addButton( 'Unlink', 20 { 21 label : editor.lang.unlink, 22 command : 'unlink' 23 } ); 24 editor.ui.addButton( 'Anchor', 25 { 26 label : editor.lang.anchor.toolbar, 27 command : 'anchor' 28 } ); 29 CKEDITOR.dialog.add( 'link', this.path + 'dialogs/link.js' ); 30 CKEDITOR.dialog.add( 'anchor', this.path + 'dialogs/anchor.js' ); 31 32 // Add the CSS styles for anchor placeholders. 33 editor.addCss( 34 'img.cke_anchor' + 35 '{' + 36 'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/anchor.gif' ) + ');' + 37 'background-position: center center;' + 38 'background-repeat: no-repeat;' + 39 'border: 1px solid #a9a9a9;' + 40 'width: 18px !important;' + 41 'height: 18px !important;' + 42 '}\n' + 43 'a.cke_anchor' + 44 '{' + 45 'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/anchor.gif' ) + ');' + 46 'background-position: 0 center;' + 47 'background-repeat: no-repeat;' + 48 'border: 1px solid #a9a9a9;' + 49 'padding-left: 18px;' + 50 '}' 51 ); 52 53 // Register selection change handler for the unlink button. 54 editor.on( 'selectionChange', function( evt ) 55 { 56 /* 57 * Despite our initial hope, document.queryCommandEnabled() does not work 58 * for this in Firefox. So we must detect the state by element paths. 59 */ 60 var command = editor.getCommand( 'unlink' ), 61 element = evt.data.path.lastElement && evt.data.path.lastElement.getAscendant( 'a', true ); 62 if ( element && element.getName() == 'a' && element.getAttribute( 'href' ) ) 63 command.setState( CKEDITOR.TRISTATE_OFF ); 64 else 65 command.setState( CKEDITOR.TRISTATE_DISABLED ); 66 } ); 67 68 editor.on( 'doubleclick', function( evt ) 69 { 70 var element = CKEDITOR.plugins.link.getSelectedLink( editor ) || evt.data.element; 71 72 if ( element.is( 'a' ) ) 73 evt.data.dialog = ( element.getAttribute( 'name' ) && !element.getAttribute( 'href' ) ) ? 'anchor' : 'link'; 74 else if ( element.is( 'img' ) && element.getAttribute( '_cke_real_element_type' ) == 'anchor' ) 75 evt.data.dialog = 'anchor'; 76 }); 77 78 // If the "menu" plugin is loaded, register the menu items. 79 if ( editor.addMenuItems ) 80 { 81 editor.addMenuItems( 82 { 83 anchor : 84 { 85 label : editor.lang.anchor.menu, 86 command : 'anchor', 87 group : 'anchor' 88 }, 89 90 link : 91 { 92 label : editor.lang.link.menu, 93 command : 'link', 94 group : 'link', 95 order : 1 96 }, 97 98 unlink : 99 { 100 label : editor.lang.unlink, 101 command : 'unlink', 102 group : 'link', 103 order : 5 104 } 105 }); 106 } 107 108 // If the "contextmenu" plugin is loaded, register the listeners. 109 if ( editor.contextMenu ) 110 { 111 editor.contextMenu.addListener( function( element, selection ) 112 { 113 if ( !element || element.isReadOnly() ) 114 return null; 115 116 var isAnchor = ( element.is( 'img' ) && element.getAttribute( '_cke_real_element_type' ) == 'anchor' ); 117 118 if ( !isAnchor ) 119 { 120 if ( !( element = CKEDITOR.plugins.link.getSelectedLink( editor ) ) ) 121 return null; 122 123 isAnchor = ( element.getAttribute( 'name' ) && !element.getAttribute( 'href' ) ); 124 } 125 126 return isAnchor ? 127 { anchor : CKEDITOR.TRISTATE_OFF } : 128 { link : CKEDITOR.TRISTATE_OFF, unlink : CKEDITOR.TRISTATE_OFF }; 129 }); 130 } 131 }, 132 133 afterInit : function( editor ) 134 { 135 // Register a filter to displaying placeholders after mode change. 136 137 var dataProcessor = editor.dataProcessor, 138 dataFilter = dataProcessor && dataProcessor.dataFilter; 139 140 if ( dataFilter ) 141 { 142 dataFilter.addRules( 143 { 144 elements : 145 { 146 a : function( element ) 147 { 148 var attributes = element.attributes; 149 if ( attributes.name && !attributes.href ) 150 return editor.createFakeParserElement( element, 'cke_anchor', 'anchor' ); 151 } 152 } 153 }); 154 } 155 }, 156 157 requires : [ 'fakeobjects' ] 158 } ); 159 160 CKEDITOR.plugins.link = 161 { 162 /** 163 * Get the surrounding link element of current selection. 164 * @param editor 165 * @example CKEDITOR.plugins.link.getSelectedLink( editor ); 166 * @since 3.2.1 167 * The following selection will all return the link element. 168 * <pre> 169 * <a href="#">li^nk</a> 170 * <a href="#">[link]</a> 171 * text[<a href="#">link]</a> 172 * <a href="#">li[nk</a>] 173 * [<b><a href="#">li]nk</a></b>] 174 * [<a href="#"><b>li]nk</b></a> 175 * </pre> 176 */ 177 getSelectedLink : function( editor ) 178 { 179 var range; 180 try 181 { 182 range = editor.getSelection().getRanges( true )[ 0 ]; 183 range.shrink( CKEDITOR.SHRINK_TEXT ); 184 var root = range.getCommonAncestor(); 185 return root.getAscendant( 'a', true ); 186 } 187 catch( e ) { return null; } 188 } 189 }; 190 191 CKEDITOR.unlinkCommand = function(){}; 192 CKEDITOR.unlinkCommand.prototype = 193 { 194 /** @ignore */ 195 exec : function( editor ) 196 { 197 /* 198 * execCommand( 'unlink', ... ) in Firefox leaves behind <span> tags at where 199 * the <a> was, so again we have to remove the link ourselves. (See #430) 200 * 201 * TODO: Use the style system when it's complete. Let's use execCommand() 202 * as a stopgap solution for now. 203 */ 204 var selection = editor.getSelection(), 205 bookmarks = selection.createBookmarks(), 206 ranges = selection.getRanges(), 207 rangeRoot, 208 element; 209 210 for ( var i = 0 ; i < ranges.length ; i++ ) 211 { 212 rangeRoot = ranges[i].getCommonAncestor( true ); 213 element = rangeRoot.getAscendant( 'a', true ); 214 if ( !element ) 215 continue; 216 ranges[i].selectNodeContents( element ); 217 } 218 219 selection.selectRanges( ranges ); 220 editor.document.$.execCommand( 'unlink', false, null ); 221 selection.selectBookmarks( bookmarks ); 222 }, 223 224 startDisabled : true 225 }; 226 227 CKEDITOR.tools.extend( CKEDITOR.config, 228 { 229 linkShowAdvancedTab : true, 230 linkShowTargetTab : true 231 } );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |