Ticket #2839: 2839.patch
File 2839.patch, 35.1 KB (added by , 15 years ago) |
---|
-
_samples/api_dialog.html
56 56 57 57 // Remove the "Link Type" combo and the "Browser 58 58 // Server" button from the "info" tab. 59 infoTab.remove( ' protocol' );59 infoTab.remove( 'linkType' ); 60 60 infoTab.remove( 'browse' ); 61 61 62 62 // Set the default value for the URL field. -
_source/plugins/dialogui/plugin.js
884 884 accessKeyUp : function() 885 885 { 886 886 this.select(); 887 }, 888 889 /** 890 * Sets the value of this text input object. 891 * @param {Object} value The new value. 892 * @returns {CKEDITOR.ui.dialog.textInput} The current UI element. 893 * @example 894 * uiElement.setValue( 'Blamo' ); 895 */ 896 setValue : function( value ) 897 { 898 value = value || ''; 899 return CKEDITOR.ui.dialog.uiElement.prototype.setValue.call( this, value ); 887 900 } 888 901 }, commonPrototype, true ); 889 902 -
_source/plugins/link/dialogs/link.js
8 8 // Handles the event when the "Target" selection box is changed. 9 9 var targetChanged = function() 10 10 { 11 var popupFeatures = this.getDialog().getContentElement( 'target', 'popupFeatures' ).getElement(), 12 targetName = this.getDialog().getContentElement( 'target', 'linkTargetName' ), 11 var dialog = this.getDialog(), 12 popupFeatures = dialog.getContentElement( 'target', 'popupFeatures' ), 13 targetName = dialog.getContentElement( 'target', 'linkTargetName' ), 13 14 value = this.getValue(); 15 16 if ( !popupFeatures || !targetName ) 17 return; 18 19 popupFeatures = popupFeatures.getElement(); 20 14 21 if ( value == 'popup' ) 15 22 { 16 23 popupFeatures.show(); … … 44 51 45 52 for ( var i = 0 ; i < partIds.length ; i++ ) 46 53 { 47 var element = dialog.getContentElement( 'info', partIds[i] ).getElement().getParent().getParent(); 54 var element = dialog.getContentElement( 'info', partIds[i] ); 55 if ( !element ) 56 continue; 57 58 element = element.getElement().getParent().getParent(); 48 59 if ( partIds[i] == typeValue + 'Options' ) 49 60 element.show(); 50 61 else … … 61 72 popupRegex = 62 73 /\s*window.open\(\s*this\.href\s*,\s*(?:'([^']*)'|null)\s*,\s*'([^']*)'\s*\)\s*;\s*return\s*false;*\s*/, 63 74 popupFeaturesRegex = /(?:^|,)([^=]+)=(\d+|yes|no)/gi, 64 loadLink = function( editor, selection, ranges, element )75 parseLink = function( editor, element ) 65 76 { 66 var href = element.getAttribute( '_cke_saved_href' ) || element.getAttribute( 'href' ); 67 var emailMatch = ''; 68 var anchorMatch = ''; 69 var urlMatch = false; 77 var href = element ? ( element.getAttribute( '_cke_saved_href' ) || element.getAttribute( 'href' ) ) : '', 78 emailMatch = '', 79 anchorMatch = '', 80 urlMatch = false, 81 retval = {}; 82 70 83 if ( href != null ) 71 84 { 72 85 emailMatch = href.match( emailRegex ); 73 86 anchorMatch = href.match( anchorRegex ); 74 87 urlMatch = href.match( urlRegex ); 75 88 } 76 var me = this;77 89 78 90 // Load the link type and URL. 79 91 if ( emailMatch ) 80 92 { 81 93 var subjectMatch = href.match( emailSubjectRegex ), 82 94 bodyMatch = href.match( emailBodyRegex ); 83 this.setValueOf( 'info', 'linkType', 'email' ); 84 this.setValueOf( 'info', 'emailAddress', emailMatch[1] ); 85 subjectMatch && this.setValueOf( 'info', 'emailSubject', decodeURIComponent( subjectMatch[1] ) ); 86 bodyMatch && this.setValueOf( 'info', 'emailBody', decodeURIComponent( bodyMatch[1] ) ); 95 retval.type = 'email'; 96 retval.email = {}; 97 retval.email.address = emailMatch[1]; 98 subjectMatch && ( retval.email.subject = decodeURIComponent( subjectMatch[1] ) ); 99 bodyMatch && ( retval.email.body = decodeURIComponent( bodyMatch[1] ) ); 87 100 } 88 101 else if ( anchorMatch ) 89 102 { 90 this.setValueOf( 'info', 'linkType', 'anchor' );91 this.setValueOf( 'info', 'anchorName', anchorMatch[1] );92 this.setValueOf( 'info', 'anchorId', anchorMatch[1] );103 retval.type = 'anchor'; 104 retval.anchor = {}; 105 retval.anchor.name = retval.anchor.id = anchorMatch[1]; 93 106 } 94 107 else if ( urlMatch ) 95 108 { 96 var urlMatch = href.match( urlRegex );97 this.setValueOf( 'info', 'linkType', 'url' );98 this.setValueOf( 'info', 'protocol', urlMatch[1] );99 this.setValueOf( 'info', 'url', urlMatch[2] );109 retval.type = 'url'; 110 retval.url = {}; 111 retval.url.protocol = urlMatch[1]; 112 retval.url.url = urlMatch[2]; 100 113 } 101 114 else 102 { 103 this.setValueOf( 'info', 'linkType', editor.config.link.defaultValues.linkType ); 104 this.setValueOf( 'info', 'protocol', editor.config.link.defaultValues.protocol ); 105 this.setValueOf( 'info', 'url', '' ); 106 } 115 retval.type = 'url'; 107 116 108 117 // Load target and popup settings. 109 var target = element.getAttribute( 'target' ); 110 if ( target == null ) 118 if ( element ) 111 119 { 112 var onclick = element.getAttribute( '_cke_saved_onclick' ) || element.getAttribute( 'onclick' ); 113 onclickMatch = onclick && onclick.match( popupRegex ); 114 if ( onclickMatch ) 120 var target = element.getAttribute( 'target' ); 121 retval.target = {}; 122 retval.adv = {}; 123 124 if ( target == null ) 115 125 { 116 this.setValueOf( 'target', 'linkTargetType', 'popup' ); 117 this.setValueOf( 'target', 'linkTargetName', onclickMatch[1] ); 126 var onclick = element.getAttribute( '_cke_saved_onclick' ) || element.getAttribute( 'onclick' ), 127 onclickMatch = onclick && onclick.match( popupRegex ); 128 if ( onclickMatch ) 129 { 130 retval.target.type = 'popup'; 131 retval.target.name = onclickMatch[1]; 118 132 119 var featureMatch; 120 while ( ( featureMatch = popupFeaturesRegex.exec( onclickMatch[2] ) ) ) 121 { 122 if ( featureMatch[2] == 'yes' || featureMatch[2] == '1' ) 123 this.setValueOf( 'target', featureMatch[1], true ); 124 else if ( isFinite( featureMatch[2] ) ) 125 this.setValueOf( 'target', featureMatch[1], featureMatch[2] ); 133 var featureMatch; 134 while ( ( featureMatch = popupFeaturesRegex.exec( onclickMatch[2] ) ) ) 135 { 136 if ( featureMatch[2] == 'yes' || featureMatch[2] == '1' ) 137 retval.target[ featureMatch[1] ] = true; 138 else if ( isFinite( featureMatch[2] ) ) 139 retval.target[ featureMatch[1] ] = featureMatch[2]; 140 } 126 141 } 127 142 } 128 143 else 129 144 { 130 this.setValueOf( 'target', 'linkTargetType', 'notSet' ); 131 this.setValueOf( 'target', 'linkTargetName', '' ); 145 var targetMatch = target.match( selectableTargets ); 146 if ( targetMatch ) 147 retval.target.type = retval.target.name = target; 148 else 149 { 150 retval.target.type = 'frame'; 151 retval.target.name = target; 152 } 132 153 } 154 155 var me = this, 156 advAttr = function( inputName, attrName ) 157 { 158 var value = element.getAttribute( attrName ); 159 if ( value != null ) 160 retval.adv[ inputName ] = value || ''; 161 }; 162 advAttr( 'advId', 'id' ); 163 advAttr( 'advLangDir', 'dir' ); 164 advAttr( 'advAccessKey', 'accessKey' ); 165 advAttr( 'advName', 'name' ); 166 advAttr( 'advLangCode', 'lang' ); 167 advAttr( 'advTabIndex', 'tabindex' ); 168 advAttr( 'advTitle', 'title' ); 169 advAttr( 'advContentType', 'type' ); 170 advAttr( 'advCSSClasses', 'class' ); 171 advAttr( 'advCharset', 'charset' ); 172 advAttr( 'advStyles', 'style' ); 133 173 } 134 else 174 175 // Find out whether we have any anchors in the editor. 176 // Get all IMG elements in CK document. 177 var elements = editor.document.$.getElementsByTagName( 'img' ), 178 anchors = retval.anchors = []; 179 for( var i = 0; i < elements.length; i++ ) 135 180 { 136 var targetMatch = target.match( selectableTargets);137 if ( targetMatch)181 var item = elements.item( i ); 182 if ( item.getAttribute( '_cke_protected_html' ) && item.getAttribute( '_cke_real_element_type' ) == "anchor" ) 138 183 { 139 this.setValueOf( 'target', 'linkTargetType', target ); 140 this.setValueOf( 'target', 'linkTargetName', target ); 184 var domElement = new CKEDITOR.dom.element( item ); 185 domElement = editor.fakeobjects.restoreElement( domElement ); 186 anchors.push( domElement ); 141 187 } 142 else143 {144 this.setValueOf( 'target', 'linkTargetType', 'frame' );145 this.setValueOf( 'target', 'linkTargetName', target );146 }147 188 } 148 149 // Load advanced attributes. 150 var advAttr = function( inputName, attrName ) 189 for ( var i = 0, name, id ; i < anchors.length ; i++ ) 151 190 { 152 var value = element.getAttribute( attrName ); 153 if ( value != null ) 154 me.setValueOf( 'advanced', inputName, value ); 155 }; 156 advAttr( 'advLangDir', 'dir' ); 157 advAttr( 'advAccessKey', 'accessKey' ); 158 advAttr( 'advName', 'name' ); 159 advAttr( 'advLangCode', 'lang' ); 160 advAttr( 'advTabIndex', 'tabindex' ); 161 advAttr( 'advTitle', 'title' ); 162 advAttr( 'advContentType', 'type' ); 163 advAttr( 'advCSSClasses', 'class' ); 164 advAttr( 'advCharset', 'charset' ); 165 advAttr( 'advStyles', 'style' ); 191 name = anchors[i].getAttribute( 'name' ); 192 id = anchors[i].getAttribute( 'id' ); 193 anchors.push( { name : name, id : id } ); 194 } 166 195 167 196 // Record down the selected element in the dialog. 168 197 this._.selectedElement = element; 198 199 return retval; 200 }, 201 setupParams = function( page, data ) 202 { 203 if ( data[page] ) 204 this.setValue( data[page][this.id] || '' ); 205 }, 206 setupPopupParams = function( data ) 207 { 208 return setupParams.call( this, 'target', data ); 209 }, 210 setupAdvParams = function( data ) 211 { 212 return setupParams.call( this, 'adv', data ); 213 }, 214 commitParams = function( page, data ) 215 { 216 if ( !data[page] ) 217 data[page] = {}; 218 219 data[page][this.id] = this.getValue() || ''; 220 }, 221 commitPopupParams = function( data ) 222 { 223 return commitParams.call( this, 'target', data ); 224 }, 225 commitAdvParams = function( data ) 226 { 227 return commitParams.call( this, 'adv', data ); 169 228 }; 170 229 171 230 return { … … 190 249 [ editor.lang.link.toAnchor, 'anchor' ], 191 250 [ editor.lang.link.toEmail, 'email' ] 192 251 ], 193 onChange : linkTypeChanged 252 onChange : linkTypeChanged, 253 setup : function( data ) 254 { 255 if ( data.type ) 256 this.setValue( data.type ); 257 }, 258 commit : function( data ) 259 { 260 data.type = this.getValue(); 261 } 194 262 }, 195 263 { 196 264 type : 'vbox', … … 215 283 [ 'ftp://' ], 216 284 [ 'news://' ], 217 285 [ '<other>', '' ] 218 ] 286 ], 287 setup : function( data ) 288 { 289 if ( data.url ) 290 this.setValue( data.url.protocol ); 291 }, 292 commit : function( data ) 293 { 294 if ( !data.url ) 295 data.url = {}; 296 297 data.url.protocol = this.getValue(); 298 } 219 299 }, 220 300 { 221 301 type : 'text', … … 223 303 label : editor.lang.common.url, 224 304 validate : function() 225 305 { 226 if ( this.getDialog().getValueOf( 'info', 'linkType' ) != 'url' ) 306 var dialog = this.getDialog(); 307 308 if ( dialog.getContentElement( 'info', 'linkType' ) && 309 dialog.getValueOf( 'info', 'linkType' ) != 'url' ) 227 310 return true; 228 311 229 312 if ( this.getDialog().fakeObj != false ) // Edit Anchor. … … 231 314 232 315 var func = CKEDITOR.dialog.validate.notEmpty( editor.lang.link.noUrl ); 233 316 return func.apply( this ); 317 }, 318 setup : function( data ) 319 { 320 if ( data.url ) 321 this.setValue( data.url.url ); 322 323 var linkType = this.getDialog().getContentElement( 'info', 'linkType' ); 324 if ( linkType && linkType.getValue() == 'url' ) 325 this.select(); 326 }, 327 commit : function( data ) 328 { 329 if ( !data.url ) 330 data.url = {}; 331 332 data.url.url = this.getValue(); 234 333 } 235 334 } 236 ] 335 ], 336 setup : function( data ) 337 { 338 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) ) 339 this.getElement().show(); 340 } 237 341 }, 238 342 { 239 343 type : 'button', … … 253 357 { 254 358 type : 'html', 255 359 id : 'selectAnchorText', 256 html : CKEDITOR.tools.htmlEncode( editor.lang.link.selectAnchor ) 360 html : CKEDITOR.tools.htmlEncode( editor.lang.link.selectAnchor ), 361 setup : function( data ) 362 { 363 if ( data.anchors.length > 0 ) 364 this.getElement().show(); 365 else 366 this.getElement().hide(); 367 } 257 368 }, 258 369 { 259 370 type : 'html', 260 371 id : 'noAnchors', 261 372 style : 'text-align: center;', 262 html : '<div>' + CKEDITOR.tools.htmlEncode( editor.lang.link.noAnchors ) + '</div>' 373 html : '<div>' + CKEDITOR.tools.htmlEncode( editor.lang.link.noAnchors ) + '</div>', 374 setup : function( data ) 375 { 376 if ( data.anchors.length < 1 ) 377 this.getElement().show(); 378 else 379 this.getElement().hide(); 380 } 263 381 }, 264 382 { 265 383 type : 'hbox', … … 275 393 items : 276 394 [ 277 395 [ '' ] 278 ] 396 ], 397 setup : function( data ) 398 { 399 this.clear(); 400 this.add( '' ); 401 for ( var i = 0 ; i < data.anchors.length ; i++ ) 402 { 403 if ( data.anchors[i].name ) 404 this.add( data.anchors[i].name ); 405 } 406 407 if ( data.anchor ) 408 this.setValue( data.anchor.name ); 409 410 var linkType = this.getDialog().getContentElement( 'info', 'linkType' ); 411 if ( linkType && linkType.getValue() == 'email' ) 412 this.focus(); 413 }, 414 commit : function( data ) 415 { 416 if ( !data.anchor ) 417 data.anchor = {}; 418 419 data.anchor.name = this.getValue(); 420 } 279 421 }, 280 422 { 281 423 type : 'select', … … 286 428 items : 287 429 [ 288 430 [ '' ] 289 ] 431 ], 432 setup : function( data ) 433 { 434 this.clear(); 435 this.add( '' ); 436 for ( var i = 0 ; i < data.anchors.length ; i++ ) 437 { 438 if ( data.anchors[i].id ) 439 this.add( data.anchors[i].id ); 440 } 441 442 if ( data.anchor ) 443 this.setValue( data.anchor.id ); 444 }, 445 commit : function( data ) 446 { 447 if ( !data.anchor ) 448 data.anchor = {}; 449 450 data.anchor.id = this.getValue(); 451 } 290 452 } 291 ] 453 ], 454 setup : function( data ) 455 { 456 if ( data.anchors.length > 0 ) 457 this.getElement().show(); 458 else 459 this.getElement().hide(); 460 } 292 461 } 293 ] 462 ], 463 setup : function( data ) 464 { 465 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) ) 466 this.getElement().hide(); 467 } 294 468 }, 295 469 { 296 470 type : 'vbox', … … 304 478 label : editor.lang.link.emailAddress, 305 479 validate : function() 306 480 { 307 if ( this.getDialog().getValueOf( 'info', 'linkType' ) != 'email' ) 481 var dialog = this.getDialog(); 482 483 if ( !dialog.getContentElement( 'info', 'linkType' ) || 484 dialog.getValueOf( 'info', 'linkType' ) != 'email' ) 308 485 return true; 309 486 310 487 var func = CKEDITOR.dialog.validate.notEmpty( editor.lang.link.noEmail ); 311 488 return func.apply( this ); 489 }, 490 setup : function( data ) 491 { 492 if ( data.email ) 493 this.setValue( data.email.address ); 494 495 var linkType = this.getDialog().getContentElement( 'info', 'linkType' ); 496 if ( linkType && linkType.getValue() == 'email' ) 497 this.select(); 498 }, 499 commit : function( data ) 500 { 501 if ( !data.email ) 502 data.email = {}; 503 504 data.email.address = this.getValue(); 312 505 } 313 506 }, 314 507 { 315 508 type : 'text', 316 509 id : 'emailSubject', 317 label : editor.lang.link.emailSubject 510 label : editor.lang.link.emailSubject, 511 setup : function( data ) 512 { 513 if ( data.email ) 514 this.setValue( data.email.subject ); 515 }, 516 commit : function( data ) 517 { 518 if ( !data.email ) 519 data.email = {}; 520 521 data.email.subject = this.getValue(); 522 } 318 523 }, 319 524 { 320 525 type : 'textarea', 321 526 id : 'emailBody', 322 527 label : editor.lang.link.emailBody, 323 528 rows : 3, 324 'default' : '' 529 'default' : '', 530 setup : function( data ) 531 { 532 if ( data.email ) 533 this.setValue( data.email.body ); 534 }, 535 commit : function( data ) 536 { 537 if ( !data.email ) 538 data.email = {}; 539 540 data.email.body = this.getValue(); 541 } 325 542 } 326 ] 543 ], 544 setup : function( data ) 545 { 546 if ( !this.getDialog().getContentElement( 'info', 'linkType' ) ) 547 this.getElement().hide(); 548 } 327 549 } 328 550 ] 329 551 }, … … 354 576 [ editor.lang.link.targetSelf, '_self' ], 355 577 [ editor.lang.link.targetParent, '_parent' ] 356 578 ], 357 onChange : targetChanged 579 onChange : targetChanged, 580 setup : function( data ) 581 { 582 if ( data.target ) 583 this.setValue( data.target.type ); 584 }, 585 commit : function( data ) 586 { 587 if ( !data.target ) 588 data.target = {}; 589 590 data.target.type = this.getValue(); 591 } 358 592 }, 359 593 { 360 594 type : 'text', 361 595 id : 'linkTargetName', 362 596 label : editor.lang.link.targetFrameName, 363 'default' : editor.config.link.defaultValues.targetFrameName 597 'default' : editor.config.link.defaultValues.targetFrameName, 598 setup : function( data ) 599 { 600 if ( data.target ) 601 this.setValue( data.target.name ); 602 }, 603 commit : function( data ) 604 { 605 if ( !data.target ) 606 data.target = {}; 607 608 data.target.name = this.getValue(); 609 } 364 610 } 365 611 ] 366 612 }, … … 383 629 { 384 630 type : 'checkbox', 385 631 id : 'resizable', 386 label : editor.lang.link.popupResizable 632 label : editor.lang.link.popupResizable, 633 setup : setupPopupParams, 634 commit : commitPopupParams 387 635 }, 388 636 { 389 637 type : 'checkbox', 390 638 id : 'status', 391 label : editor.lang.link.popupStatusBar 639 label : editor.lang.link.popupStatusBar, 640 setup : setupPopupParams, 641 commit : commitPopupParams 642 392 643 } 393 644 ] 394 645 }, … … 399 650 { 400 651 type : 'checkbox', 401 652 id : 'location', 402 label : editor.lang.link.popupLocationBar 653 label : editor.lang.link.popupLocationBar, 654 setup : setupPopupParams, 655 commit : commitPopupParams 656 403 657 }, 404 658 { 405 659 type : 'checkbox', 406 660 id : 'toolbar', 407 label : editor.lang.link.popupToolbar 661 label : editor.lang.link.popupToolbar, 662 setup : setupPopupParams, 663 commit : commitPopupParams 664 408 665 } 409 666 ] 410 667 }, … … 415 672 { 416 673 type : 'checkbox', 417 674 id : 'menubar', 418 label : editor.lang.link.popupMenuBar 675 label : editor.lang.link.popupMenuBar, 676 setup : setupPopupParams, 677 commit : commitPopupParams 678 419 679 }, 420 680 { 421 681 type : 'checkbox', 422 682 id : 'fullscreen', 423 label : editor.lang.link.popupFullScreen 683 label : editor.lang.link.popupFullScreen, 684 setup : setupPopupParams, 685 commit : commitPopupParams 686 424 687 } 425 688 ] 426 689 }, … … 431 694 { 432 695 type : 'checkbox', 433 696 id : 'scrollbars', 434 label : editor.lang.link.popupScrollBars 697 label : editor.lang.link.popupScrollBars, 698 setup : setupPopupParams, 699 commit : commitPopupParams 700 435 701 }, 436 702 { 437 703 type : 'checkbox', 438 704 id : 'dependent', 439 label : editor.lang.link.popupDependent 705 label : editor.lang.link.popupDependent, 706 setup : setupPopupParams, 707 commit : commitPopupParams 708 440 709 } 441 710 ] 442 711 }, … … 449 718 widths : [ '30%', '70%' ], 450 719 labelLayout : 'horizontal', 451 720 label : editor.lang.link.popupWidth, 452 id : 'width' 721 id : 'width', 722 setup : setupPopupParams, 723 commit : commitPopupParams 724 453 725 }, 454 726 { 455 727 type : 'text', 456 728 labelLayout : 'horizontal', 457 729 widths : [ '55%', '45%' ], 458 730 label : editor.lang.link.popupLeft, 459 id : 'left' 731 id : 'left', 732 setup : setupPopupParams, 733 commit : commitPopupParams 734 460 735 } 461 736 ] 462 737 }, … … 469 744 labelLayout : 'horizontal', 470 745 widths : [ '30%', '70%' ], 471 746 label : editor.lang.link.popupHeight, 472 id : 'height' 747 id : 'height', 748 setup : setupPopupParams, 749 commit : commitPopupParams 750 473 751 }, 474 752 { 475 753 type : 'text', 476 754 labelLayout : 'horizontal', 477 755 label : editor.lang.link.popupTop, 478 756 widths : [ '55%', '45%' ], 479 id : 'top' 757 id : 'top', 758 setup : setupPopupParams, 759 commit : commitPopupParams 760 480 761 } 481 762 ] 482 763 } … … 524 805 { 525 806 type : 'text', 526 807 id : 'advId', 527 label : editor.lang.link.id 808 label : editor.lang.link.id, 809 setup : setupAdvParams, 810 commit : commitAdvParams 528 811 }, 529 812 { 530 813 type : 'select', … … 537 820 [ editor.lang.link.langDirNotSet, '' ], 538 821 [ editor.lang.link.langDirLTR, 'ltr' ], 539 822 [ editor.lang.link.langDirRTL, 'rtl' ] 540 ] 823 ], 824 setup : setupAdvParams, 825 commit : commitAdvParams 826 541 827 }, 542 828 { 543 829 type : 'text', 544 830 id : 'advAccessKey', 545 831 label : editor.lang.link.acccessKey, 546 maxLength : 1 832 maxLength : 1, 833 setup : setupAdvParams, 834 commit : commitAdvParams 835 547 836 } 548 837 ] 549 838 }, … … 555 844 { 556 845 type : 'text', 557 846 label : editor.lang.link.name, 558 id : 'advName' 847 id : 'advName', 848 setup : setupAdvParams, 849 commit : commitAdvParams 850 559 851 }, 560 852 { 561 853 type : 'text', 562 854 label : editor.lang.link.langCode, 563 855 id : 'advLangCode', 564 'default' : editor.config.link.defaultValues.langCode 856 'default' : editor.config.link.defaultValues.langCode, 857 setup : setupAdvParams, 858 commit : commitAdvParams 859 565 860 }, 566 861 { 567 862 type : 'text', 568 863 label : editor.lang.link.tabIndex, 569 864 id : 'advTabIndex', 570 maxLength : 5 865 maxLength : 5, 866 setup : setupAdvParams, 867 commit : commitAdvParams 868 571 869 } 572 870 ] 573 871 } … … 587 885 type : 'text', 588 886 label : editor.lang.link.advisoryTitle, 589 887 'default' : editor.config.link.defaultValues.title, 590 id : 'advTitle' 888 id : 'advTitle', 889 setup : setupAdvParams, 890 commit : commitAdvParams 891 591 892 }, 592 893 { 593 894 type : 'text', 594 895 label : editor.lang.link.advisoryContentType, 595 896 'default' : editor.config.link.defaultValues.type, 596 id : 'advContentType' 897 id : 'advContentType', 898 setup : setupAdvParams, 899 commit : commitAdvParams 900 597 901 } 598 902 ] 599 903 }, … … 606 910 type : 'text', 607 911 label : editor.lang.link.cssClasses, 608 912 'default' : editor.config.link.defaultValues.classes, 609 id : 'advCSSClasses' 913 id : 'advCSSClasses', 914 setup : setupAdvParams, 915 commit : commitAdvParams 916 610 917 }, 611 918 { 612 919 type : 'text', 613 920 label : editor.lang.link.charset, 614 921 'default' : editor.config.link.defaultValues.charset, 615 id : 'advCharset' 922 id : 'advCharset', 923 setup : setupAdvParams, 924 commit : commitAdvParams 925 616 926 } 617 927 ] 618 928 }, … … 624 934 type : 'text', 625 935 label : editor.lang.link.styles, 626 936 'default' : editor.config.link.defaultValues.style, 627 id : 'advStyles' 937 id : 'advStyles', 938 setup : setupAdvParams, 939 commit : commitAdvParams 940 628 941 } 629 942 ] 630 943 } … … 641 954 var editor = this.getParentEditor(), 642 955 selection = editor.getSelection(), 643 956 ranges = selection.getRanges(), 957 element = null, 644 958 me = this; 645 959 646 // Find out whether we have any anchors in the editor.647 648 // Get all IMG elements in CK document.649 var elements = editor.document.$.getElementsByTagName( 'img' );650 var anchors = new Array();651 for( var i = 0; i < elements.length; i++ )652 {653 element = elements.item( i );654 if ( element.getAttribute( '_cke_protected_html' ) && element.getAttribute( '_cke_real_element_type' ) == "anchor" )655 {656 var domElement = new CKEDITOR.dom.element( element );657 domElement = editor.fakeobjects.restoreElement( domElement );658 anchors.push( domElement );659 }660 }661 if ( anchors.length < 1 )662 {663 this.getContentElement( 'info', 'selectAnchor' ).getElement().hide();664 this.getContentElement( 'info', 'selectAnchorText' ).getElement().hide();665 this.getContentElement( 'info', 'noAnchors' ).getElement().show();666 }667 else668 {669 this.getContentElement( 'info', 'selectAnchor' ).getElement().show();670 this.getContentElement( 'info', 'selectAnchorText' ).getElement().show();671 this.getContentElement( 'info', 'noAnchors' ).getElement().hide();672 673 var names = this.getContentElement( 'info', 'anchorName' ).clear(),674 ids = this.getContentElement( 'info', 'anchorId' ).clear();675 names.add( '' );676 ids.add( '' );677 for ( var i = 0 ; i < anchors.length ; i++ )678 {679 if ( anchors[i].getAttribute( 'name' ) )680 names.add( anchors[i].getAttribute( 'name' ) );681 else if ( anchors[i].getAttribute( 'id' ) )682 names.add( anchors[i].getAttribute( 'id' ) );683 }684 names.setValue( '' );685 ids.setValue( '' );686 }687 688 960 // Fill in all the relevant fields if there's already one link selected. 689 961 if ( ranges.length == 1 ) 690 962 { 691 963 ranges[0].enlarge( CKEDITOR.ENLARGE_ELEMENT ); 692 964 693 var rangeRoot = ranges[0].getCommonAncestor( true ) ,694 965 var rangeRoot = ranges[0].getCommonAncestor( true ); 966 element = rangeRoot.getAscendant( 'a', true ); 695 967 if ( element && element.getAttribute( 'href' ) ) 696 968 { 697 loadLink.apply( this, [ editor, selection, ranges, element ] );698 969 selection.selectElement( element ); 699 970 this.saveSelection(); 700 971 } 701 702 element = rangeRoot.getAscendant( 'img', true ); 703 if ( element && element.getAttribute( '_cke_real_element_type' ) && element.getAttribute( '_cke_real_element_type' ) == 'anchor' ) 972 else 704 973 { 705 this.fakeObj = element; 706 element = editor.fakeobjects.restoreElement( this.fakeObj ); 707 loadLink.apply( this, [ editor, selection, ranges, element ] ); 708 selection.selectElement( this.fakeObj ); 709 this.saveSelection(); 974 element = rangeRoot.getAscendant( 'img', true ); 975 if ( element && element.getAttribute( '_cke_real_element_type' ) && element.getAttribute( '_cke_real_element_type' ) == 'anchor' ) 976 { 977 this.fakeObj = element; 978 element = editor.fakeobjects.restoreElement( this.fakeObj ); 979 selection.selectElement( this.fakeObj ); 980 this.saveSelection(); 981 } 710 982 } 711 983 } 712 984 985 this.setupContent( parseLink.apply( this, [ editor, element ] ) ); 986 713 987 // Push the current values into the dialog default value stack. 714 988 this.pushDefault(); 715 716 // Put focus into the first most likely used input.717 var linkType = this.getValueOf( 'info', 'linkType' );718 if ( linkType == 'url' )719 me.getContentElement( 'info', 'url' ).select();720 else if ( linkType == 'email' )721 me.getContentElement( 'info', 'emailAddress' ).select();722 else723 me.getContentElement( 'info', 'anchorName' ).focus();724 989 }, 725 990 onOk : function() 726 991 { 727 992 var attributes = { href : 'javascript:void(0)/*' + CKEDITOR.tools.getNextNumber() + '*/' }, 728 linkList, subject, body, me = this, editor = this.getParentEditor(); 993 data = { href : attributes.href }, 994 me = this, editor = this.getParentEditor(); 729 995 996 this.commitContent( data ); 997 730 998 // Compose the URL. 731 switch ( this.getValueOf( 'info', 'linkType' ))999 switch ( data.type || 'url' ) 732 1000 { 733 1001 case 'url': 734 attributes._cke_saved_href = this.getValueOf( 'info', 'protocol' ) + this.getValueOf( 'info', 'url' ); 1002 var protocol = ( data.url && data.url.protocol ) || 'http://', 1003 url = ( data.url && data.url.url ) || ''; 1004 attributes._cke_saved_href = protocol + url; 735 1005 break; 736 1006 case 'anchor': 737 attributes._cke_saved_href = '#' + ( this.getValueOf( 'info', 'anchorName' ) || this.getValueOf( 'info', 'anchorId' ) ); 1007 var name = ( data.anchor && data.anchor.name ), 1008 id = ( data.anchor && data.anchor.id ); 1009 attributes._cke_saved_href = '#' + ( name || id || '' ); 738 1010 break; 739 1011 case 'email': 740 linkList = [ 'mailto:', this.getValueOf( 'info', 'emailAddress' ) ]; 741 subject = encodeURIComponent( this.getValueOf( 'info', 'emailSubject' ) ); 742 body = encodeURIComponent( this.getValueOf( 'info', 'emailBody' ) ); 743 if ( subject || body) 1012 var address = ( data.email && data.email.address ), 1013 subject = ( data.email && encodeURIComponent( data.email.subject || '' ) ), 1014 body = ( data.email && encodeURIComponent( data.email.body || '' ) ), 1015 linkList = [ 'mailto:', address ]; 1016 if ( subject || body ) 744 1017 { 745 1018 var argList = []; 746 1019 linkList.push( '?' ); … … 754 1027 } 755 1028 756 1029 // Popups and target. 757 if ( this.getValueOf( 'target', 'linkTargetType' ) == 'popup')1030 if ( data.target ) 758 1031 { 759 var onclickList = [ 'window.open(this.href, \'', 760 this.getValueOf( 'target', 'linkTargetName' ), '\', \'' ], 761 featureList = [ 'resizable', 'status', 'location', 'toolbar', 'menubar', 'fullscreen', 762 'scrollbars', 'dependent' ], 763 featureLength = featureList.length, 764 addFeature = function( featureName ) 765 { 766 if ( me.getValueOf( 'target', featureName ) != '' ) 767 featureList.push( featureName + '=' + me.getValueOf( 'target', featureName ) ); 768 }; 1032 if ( data.target.type == 'popup' ) 1033 { 1034 var onclickList = [ 'window.open(this.href, \'', 1035 data.target.name || '', '\', \'' ], 1036 featureList = [ 'resizable', 'status', 'location', 'toolbar', 'menubar', 'fullscreen', 1037 'scrollbars', 'dependent' ], 1038 featureLength = featureList.length, 1039 addFeature = function( featureName ) 1040 { 1041 if ( data.target[ featureName ] ) 1042 featureList.push( featureName + '=' + data.target[ featureName ] ); 1043 }; 769 1044 770 for ( var i = 0 ; i < featureLength ; i++ )771 featureList[i] = featureList[i] + ( this.getValueOf( 'target', featureList[i] ) ? '=yes' : '=no' );772 addFeature( 'width' );773 addFeature( 'left' );774 addFeature( 'height' );775 addFeature( 'top' );1045 for ( var i = 0 ; i < featureLength ; i++ ) 1046 featureList[i] = featureList[i] + ( data.target[ featureList[i] ] ) ? '=yes' : '=no' ; 1047 addFeature( 'width' ); 1048 addFeature( 'left' ); 1049 addFeature( 'height' ); 1050 addFeature( 'top' ); 776 1051 777 onclickList.push( featureList.join( ',' ), '\'); return false;' ); 778 attributes._cke_saved_onclick = onclickList.join( '' ); 1052 onclickList.push( featureList.join( ',' ), '\'); return false;' ); 1053 attributes._cke_saved_onclick = onclickList.join( '' ); 1054 } 1055 else 1056 { 1057 if ( data.target.type != 'notSet' ) 1058 attributes.target = data.target.name; 1059 } 779 1060 } 780 else781 {782 if ( this.getValueOf( 'target', 'linkTargetType' ) != 'notSet' )783 attributes.target = this.getValueOf( 'target', 'linkTargetName' );784 }785 1061 786 1062 // Advanced attributes. 787 var advAttr = function( inputName, attrName)1063 if ( data.adv ) 788 1064 { 789 var value = me.getValueOf( 'advanced', inputName ); 790 if ( value != '' ) 791 attributes[attrName] = value; 792 }; 793 advAttr( 'advLangDir', 'dir' ); 794 advAttr( 'advAccessKey', 'accessKey' ); 795 advAttr( 'advName', 'name' ); 796 advAttr( 'advLangCode', 'lang' ); 797 advAttr( 'advTabIndex', 'tabindex' ); 798 advAttr( 'advTitle', 'title' ); 799 advAttr( 'advContentType', 'type' ); 800 advAttr( 'advCSSClasses', 'class' ); 801 advAttr( 'advCharset', 'charset' ); 802 advAttr( 'advStyles', 'style' ); 1065 var advAttr = function( inputName, attrName ) 1066 { 1067 var value = data.adv[ inputName ]; 1068 if ( value ) 1069 attributes[attrName] = value; 1070 }; 1071 advAttr( 'advLangDir', 'dir' ); 1072 advAttr( 'advAccessKey', 'accessKey' ); 1073 advAttr( 'advName', 'name' ); 1074 advAttr( 'advLangCode', 'lang' ); 1075 advAttr( 'advTabIndex', 'tabindex' ); 1076 advAttr( 'advTitle', 'title' ); 1077 advAttr( 'advContentType', 'type' ); 1078 advAttr( 'advCSSClasses', 'class' ); 1079 advAttr( 'advCharset', 'charset' ); 1080 advAttr( 'advStyles', 'style' ); 1081 } 803 1082 804 1083 if ( !this._.selectedElement ) 805 1084 { … … 822 1101 style.apply( editor.document ); 823 1102 824 1103 // Id. Apply only to the first link. 825 if ( this.getValueOf( 'advanced', 'advId' )!= '' )1104 if ( data.adv && data.adv.id != '' ) 826 1105 { 827 1106 var links = this.getParentEditor().document.$.getElementsByTagName( 'a' ); 828 1107 for ( var i = 0 ; i < links.length ; i++ ) 829 1108 { 830 1109 if ( links[i].href == attributes.href ) 831 1110 { 832 links[i].id = this.getValueOf( 'advanced', 'advId' );1111 links[i].id = data.adv.id; 833 1112 break; 834 1113 } 835 1114 }