| 1 | /* |
| 2 | Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. |
| 3 | For licensing, see LICENSE.html or http://ckeditor.com/license |
| 4 | */ |
| 5 | |
| 6 | CKEDITOR.dialog.add( 'link', function( editor ) |
| 7 | { |
| 8 | // Handles the event when the "Target" selection box is changed. |
| 9 | var targetChanged = function() |
| 10 | { |
| 11 | var dialog = this.getDialog(), |
| 12 | popupFeatures = dialog.getContentElement( 'target', 'popupFeatures' ), |
| 13 | targetName = dialog.getContentElement( 'target', 'linkTargetName' ), |
| 14 | value = this.getValue(); |
| 15 | |
| 16 | if ( !popupFeatures || !targetName ) |
| 17 | return; |
| 18 | |
| 19 | popupFeatures = popupFeatures.getElement(); |
| 20 | |
| 21 | if ( value == 'popup' ) |
| 22 | { |
| 23 | popupFeatures.show(); |
| 24 | targetName.setLabel( editor.lang.link.targetPopupName ); |
| 25 | } |
| 26 | else |
| 27 | { |
| 28 | popupFeatures.hide(); |
| 29 | targetName.setLabel( editor.lang.link.targetFrameName ); |
| 30 | this.getDialog().setValueOf( 'target', 'linkTargetName', value.charAt( 0 ) == '_' ? value : '' ); |
| 31 | } |
| 32 | }; |
| 33 | |
| 34 | // Handles the event when the "Type" selection box is changed. |
| 35 | var linkTypeChanged = function() |
| 36 | { |
| 37 | var dialog = this.getDialog(), |
| 38 | partIds = [ 'urlOptions', 'anchorOptions', 'emailOptions' ], |
| 39 | typeValue = this.getValue(); |
| 40 | if ( typeValue == 'url' ) |
| 41 | { |
| 42 | if ( editor.config.linkShowTargetTab ) |
| 43 | dialog.showPage( 'target' ); |
| 44 | if ( editor.config.linkUploadTab ) |
| 45 | dialog.showPage( 'upload' ); |
| 46 | } |
| 47 | else |
| 48 | { |
| 49 | dialog.hidePage( 'target' ); |
| 50 | dialog.hidePage( 'upload' ); |
| 51 | } |
| 52 | |
| 53 | for ( var i = 0 ; i < partIds.length ; i++ ) |
| 54 | { |
| 55 | var element = dialog.getContentElement( 'info', partIds[i] ); |
| 56 | if ( !element ) |
| 57 | continue; |
| 58 | |
| 59 | element = element.getElement().getParent().getParent(); |
| 60 | if ( partIds[i] == typeValue + 'Options' ) |
| 61 | element.show(); |
| 62 | else |
| 63 | element.hide(); |
| 64 | } |
| 65 | }; |
| 66 | |
| 67 | // Loads the parameters in a selected link to the link dialog fields. |
| 68 | var emailRegex = /^mailto:([^?]+)(?:\?(.+))?$/, |
| 69 | emailSubjectRegex = /subject=([^;?:@&=$,\/]*)/, |
| 70 | emailBodyRegex = /body=([^;?:@&=$,\/]*)/, |
| 71 | anchorRegex = /^#(.*)$/, |
| 72 | urlRegex = /^((?:http|https|ftp|news):\/\/)?(.*)$/, |
| 73 | selectableTargets = /^(_(?:self|top|parent|blank))$/; |
| 74 | |
| 75 | var popupRegex = |
| 76 | /\s*window.open\(\s*this\.href\s*,\s*(?:'([^']*)'|null)\s*,\s*'([^']*)'\s*\)\s*;\s*return\s*false;*\s*/; |
| 77 | var popupFeaturesRegex = /(?:^|,)([^=]+)=(\d+|yes|no)/gi; |
| 78 | |
| 79 | var parseLink = function( editor, element ) |
| 80 | { |
| 81 | var href = element ? ( element.getAttribute( '_cke_saved_href' ) || element.getAttribute( 'href' ) ) : '', |
| 82 | emailMatch = '', |
| 83 | anchorMatch = '', |
| 84 | urlMatch = false, |
| 85 | retval = {}; |
| 86 | |
| 87 | if ( href != null ) |
| 88 | { |
| 89 | emailMatch = href.match( emailRegex ); |
| 90 | anchorMatch = href.match( anchorRegex ); |
| 91 | urlMatch = href.match( urlRegex ); |
| 92 | } |
| 93 | |
| 94 | // Load the link type and URL. |
| 95 | if ( emailMatch ) |
| 96 | { |
| 97 | var subjectMatch = href.match( emailSubjectRegex ), |
| 98 | bodyMatch = href.match( emailBodyRegex ); |
| 99 | retval.type = 'email'; |
| 100 | retval.email = {}; |
| 101 | retval.email.address = emailMatch[1]; |
| 102 | subjectMatch && ( retval.email.subject = decodeURIComponent( subjectMatch[1] ) ); |
| 103 | bodyMatch && ( retval.email.body = decodeURIComponent( bodyMatch[1] ) ); |
| 104 | } |
| 105 | else if ( anchorMatch ) |
| 106 | { |
| 107 | retval.type = 'anchor'; |
| 108 | retval.anchor = {}; |
| 109 | retval.anchor.name = retval.anchor.id = anchorMatch[1]; |
| 110 | } |
| 111 | else if ( href && urlMatch ) // urlRegex matches empty strings, so need to check for href as well. |
| 112 | { |
| 113 | retval.type = 'url'; |
| 114 | retval.url = {}; |
| 115 | retval.url.protocol = urlMatch[1]; |
| 116 | retval.url.url = urlMatch[2]; |
| 117 | } |
| 118 | else |
| 119 | retval.type = 'url'; |
| 120 | |
| 121 | // Load target and popup settings. |
| 122 | if ( element ) |
| 123 | { |
| 124 | var target = element.getAttribute( 'target' ); |
| 125 | retval.target = {}; |
| 126 | retval.adv = {}; |
| 127 | |
| 128 | // IE BUG: target attribute is an empty string instead of null in IE if it's not set. |
| 129 | if ( !target ) |
| 130 | { |
| 131 | var onclick = element.getAttribute( '_cke_saved_onclick' ) || element.getAttribute( 'onclick' ), |
| 132 | onclickMatch = onclick && onclick.match( popupRegex ); |
| 133 | if ( onclickMatch ) |
| 134 | { |
| 135 | retval.target.type = 'popup'; |
| 136 | retval.target.name = onclickMatch[1]; |
| 137 | |
| 138 | var featureMatch; |
| 139 | while ( ( featureMatch = popupFeaturesRegex.exec( onclickMatch[2] ) ) ) |
| 140 | { |
| 141 | if ( featureMatch[2] == 'yes' || featureMatch[2] == '1' ) |
| 142 | retval.target[ featureMatch[1] ] = true; |
| 143 | else if ( isFinite( featureMatch[2] ) ) |
| 144 | retval.target[ featureMatch[1] ] = featureMatch[2]; |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | else |
| 149 | { |
| 150 | var targetMatch = target.match( selectableTargets ); |
| 151 | if ( targetMatch ) |
| 152 | retval.target.type = retval.target.name = target; |
| 153 | else |
| 154 | { |
| 155 | retval.target.type = 'frame'; |
| 156 | retval.target.name = target; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | var me = this; |
| 161 | var advAttr = function( inputName, attrName ) |
| 162 | { |
| 163 | var value = element.getAttribute( attrName ); |
| 164 | if ( value != null ) |
| 165 | retval.adv[ inputName ] = value || ''; |
| 166 | }; |
| 167 | advAttr( 'advId', 'id' ); |
| 168 | advAttr( 'advLangDir', 'dir' ); |
| 169 | advAttr( 'advAccessKey', 'accessKey' ); |
| 170 | advAttr( 'advName', 'name' ); |
| 171 | advAttr( 'advLangCode', 'lang' ); |
| 172 | advAttr( 'advTabIndex', 'tabindex' ); |
| 173 | advAttr( 'advTitle', 'title' ); |
| 174 | advAttr( 'advContentType', 'type' ); |
| 175 | advAttr( 'advCSSClasses', 'class' ); |
| 176 | advAttr( 'advCharset', 'charset' ); |
| 177 | advAttr( 'advStyles', 'style' ); |
| 178 | } |
| 179 | |
| 180 | // Find out whether we have any anchors in the editor. |
| 181 | // Get all IMG elements in CK document. |
| 182 | var elements = editor.document.$.getElementsByTagName( 'img' ), |
| 183 | realAnchors = editor.document.$.anchors, |
| 184 | anchors = retval.anchors = []; |
| 185 | for( var i = 0; i < elements.length ; i++ ) |
| 186 | { |
| 187 | var item = elements.item( i ); |
| 188 | if ( item.getAttribute( '_cke_realelement' ) && item.getAttribute( '_cke_real_element_type' ) == 'anchor' ) |
| 189 | { |
| 190 | var domElement = new CKEDITOR.dom.element( item ); |
| 191 | domElement = editor.restoreRealElement( domElement ); |
| 192 | anchors.push( domElement ); |
| 193 | } |
| 194 | } |
| 195 | for ( var i = 0 ; i < realAnchors.length ; i++ ) |
| 196 | anchors.push( realAnchors[i] ); |
| 197 | for ( var i = 0, item, length = anchors.length ; i < length && ( item = anchors.shift() ) ; i++ ) |
| 198 | anchors.push( { name : item.getAttribute( 'name' ), id : item.getAttribute( 'id' ) } ); |
| 199 | |
| 200 | // Record down the selected element in the dialog. |
| 201 | this._.selectedElement = element; |
| 202 | |
| 203 | return retval; |
| 204 | }; |
| 205 | |
| 206 | var setupParams = function( page, data ) |
| 207 | { |
| 208 | if ( data[page] ) |
| 209 | this.setValue( data[page][this.id] || '' ); |
| 210 | }; |
| 211 | |
| 212 | var setupPopupParams = function( data ) |
| 213 | { |
| 214 | return setupParams.call( this, 'target', data ); |
| 215 | }; |
| 216 | |
| 217 | var setupAdvParams = function( data ) |
| 218 | { |
| 219 | return setupParams.call( this, 'adv', data ); |
| 220 | }; |
| 221 | |
| 222 | var commitParams = function( page, data ) |
| 223 | { |
| 224 | if ( !data[page] ) |
| 225 | data[page] = {}; |
| 226 | |
| 227 | data[page][this.id] = this.getValue() || ''; |
| 228 | }; |
| 229 | |
| 230 | var commitPopupParams = function( data ) |
| 231 | { |
| 232 | return commitParams.call( this, 'target', data ); |
| 233 | }; |
| 234 | |
| 235 | var commitAdvParams = function( data ) |
| 236 | { |
| 237 | return commitParams.call( this, 'adv', data ); |
| 238 | }; |
| 239 | |
| 240 | return { |
| 241 | title : editor.lang.link.title, |
| 242 | minWidth : 400, |
| 243 | minHeight : 320, |
| 244 | contents : [ |
| 245 | { |
| 246 | id : 'info', |
| 247 | label : editor.lang.link.info, |
| 248 | title : editor.lang.link.info, |
| 249 | elements : |
| 250 | [ |
| 251 | { |
| 252 | id : 'linkType', |
| 253 | type : 'select', |
| 254 | label : editor.lang.link.type, |
| 255 | 'default' : 'url', |
| 256 | items : |
| 257 | [ |
| 258 | [ editor.lang.common.url, 'url' ], |
| 259 | [ editor.lang.link.toAnchor, 'anchor' ], |
| 260 | [ editor.lang.link.toEmail, 'email' ] |
| 261 | ], |
| 262 | onChange : linkTypeChanged, |
| 263 | setup : function( data ) |
| 264 | { |
| 265 | if ( data.type ) |
| 266 | this.setValue( data.type ); |
| 267 | }, |
| 268 | commit : function( data ) |
| 269 | { |
| 270 | data.type = this.getValue(); |
| 271 | } |
| 272 | }, |
| 273 | { |
| 274 | type : 'vbox', |
| 275 | id : 'urlOptions', |
| 276 | children : |
| 277 | [ |
| 278 | { |
| 279 | type : 'hbox', |
| 280 | widths : [ '25%', '75%' ], |
| 281 | children : |
| 282 | [ |
| 283 | { |
| 284 | id : 'protocol', |
| 285 | type : 'select', |
| 286 | label : editor.lang.common.protocol, |
| 287 | 'default' : 'http://', |
| 288 | style : 'width : 100%;', |
| 289 | items : |
| 290 | [ |
| 291 | [ 'http://' ], |
| 292 | [ 'https//' ], |
| 293 | [ 'ftp://' ], |
| 294 | [ 'news://' ], |
| 295 | [ '<other>', '' ] |
| 296 | ], |
| 297 | setup : function( data ) |
| 298 | { |
| 299 | if ( data.url ) |
| 300 | this.setValue( data.url.protocol ); |
| 301 | }, |
| 302 | commit : function( data ) |
| 303 | { |
| 304 | if ( !data.url ) |
| 305 | data.url = {}; |
| 306 | |
| 307 | data.url.protocol = this.getValue(); |
| 308 | } |
| 309 | }, |
| 310 | { |
| 311 | type : 'text', |
| 312 | id : 'url', |
| 313 | label : editor.lang.common.url, |
| 314 | validate : function() |
| 315 | { |
| 316 | var dialog = this.getDialog(); |
| 317 | |
| 318 | if ( dialog.getContentElement( 'info', 'linkType' ) && |
| 319 | dialog.getValueOf( 'info', 'linkType' ) != 'url' ) |
| 320 | return true; |
| 321 | |
| 322 | if ( this.getDialog().fakeObj != false ) // Edit Anchor. |
| 323 | return true; |
| 324 | |
| 325 | var func = CKEDITOR.dialog.validate.notEmpty( editor.lang.link.noUrl ); |
| 326 | return func.apply( this ); |
| 327 | }, |
| 328 | setup : function( data ) |
| 329 | { |
| 330 | if ( data.url ) |
| 331 | this.setValue( data.url.url ); |
| 332 | |
| 333 | var linkType = this.getDialog().getContentElement( 'info', 'linkType' ); |
| 334 | if ( linkType && linkType.getValue() == 'url' ) |
| 335 | this.select(); |
| 336 | }, |
| 337 | commit : function( data ) |
| 338 | { |
| 339 | if ( !data.url ) |
| 340 | data.url = {}; |
| 341 | |
| 342 | data.url.url = this.getValue(); |
| 343 | } |
| 344 | } |
| 345 | ], |
| 346 | setup : function( data ) |
| 347 | { |
| 348 | if ( !this.getDialog().getContentElement( 'info', 'linkType' ) ) |
| 349 | this.getElement().show(); |
| 350 | } |
| 351 | }, |
| 352 | { |
| 353 | type : 'button', |
| 354 | id : 'browse', |
| 355 | label : editor.lang.common.browseServer |
| 356 | } |
| 357 | ] |
| 358 | }, |
| 359 | { |
| 360 | type : 'vbox', |
| 361 | id : 'anchorOptions', |
| 362 | width : 260, |
| 363 | align : 'center', |
| 364 | padding : 0, |
| 365 | children : |
| 366 | [ |
| 367 | { |
| 368 | type : 'html', |
| 369 | id : 'selectAnchorText', |
| 370 | html : CKEDITOR.tools.htmlEncode( editor.lang.link.selectAnchor ), |
| 371 | setup : function( data ) |
| 372 | { |
| 373 | if ( data.anchors.length > 0 ) |
| 374 | this.getElement().show(); |
| 375 | else |
| 376 | this.getElement().hide(); |
| 377 | } |
| 378 | }, |
| 379 | { |
| 380 | type : 'html', |
| 381 | id : 'noAnchors', |
| 382 | style : 'text-align: center;', |
| 383 | html : '<div>' + CKEDITOR.tools.htmlEncode( editor.lang.link.noAnchors ) + '</div>', |
| 384 | setup : function( data ) |
| 385 | { |
| 386 | if ( data.anchors.length < 1 ) |
| 387 | this.getElement().show(); |
| 388 | else |
| 389 | this.getElement().hide(); |
| 390 | } |
| 391 | }, |
| 392 | { |
| 393 | type : 'hbox', |
| 394 | id : 'selectAnchor', |
| 395 | children : |
| 396 | [ |
| 397 | { |
| 398 | type : 'select', |
| 399 | id : 'anchorName', |
| 400 | 'default' : '', |
| 401 | label : editor.lang.link.anchorName, |
| 402 | style : 'width: 100%;', |
| 403 | items : |
| 404 | [ |
| 405 | [ '' ] |
| 406 | ], |
| 407 | setup : function( data ) |
| 408 | { |
| 409 | this.clear(); |
| 410 | this.add( '' ); |
| 411 | for ( var i = 0 ; i < data.anchors.length ; i++ ) |
| 412 | { |
| 413 | if ( data.anchors[i].name ) |
| 414 | this.add( data.anchors[i].name ); |
| 415 | } |
| 416 | |
| 417 | if ( data.anchor ) |
| 418 | this.setValue( data.anchor.name ); |
| 419 | |
| 420 | var linkType = this.getDialog().getContentElement( 'info', 'linkType' ); |
| 421 | if ( linkType && linkType.getValue() == 'email' ) |
| 422 | this.focus(); |
| 423 | }, |
| 424 | commit : function( data ) |
| 425 | { |
| 426 | if ( !data.anchor ) |
| 427 | data.anchor = {}; |
| 428 | |
| 429 | data.anchor.name = this.getValue(); |
| 430 | } |
| 431 | }, |
| 432 | { |
| 433 | type : 'select', |
| 434 | id : 'anchorId', |
| 435 | 'default' : '', |
| 436 | label : editor.lang.link.anchorId, |
| 437 | style : 'width: 100%;', |
| 438 | items : |
| 439 | [ |
| 440 | [ '' ] |
| 441 | ], |
| 442 | setup : function( data ) |
| 443 | { |
| 444 | this.clear(); |
| 445 | this.add( '' ); |
| 446 | for ( var i = 0 ; i < data.anchors.length ; i++ ) |
| 447 | { |
| 448 | if ( data.anchors[i].id ) |
| 449 | this.add( data.anchors[i].id ); |
| 450 | } |
| 451 | |
| 452 | if ( data.anchor ) |
| 453 | this.setValue( data.anchor.id ); |
| 454 | }, |
| 455 | commit : function( data ) |
| 456 | { |
| 457 | if ( !data.anchor ) |
| 458 | data.anchor = {}; |
| 459 | |
| 460 | data.anchor.id = this.getValue(); |
| 461 | } |
| 462 | } |
| 463 | ], |
| 464 | setup : function( data ) |
| 465 | { |
| 466 | if ( data.anchors.length > 0 ) |
| 467 | this.getElement().show(); |
| 468 | else |
| 469 | this.getElement().hide(); |
| 470 | } |
| 471 | } |
| 472 | ], |
| 473 | setup : function( data ) |
| 474 | { |
| 475 | if ( !this.getDialog().getContentElement( 'info', 'linkType' ) ) |
| 476 | this.getElement().hide(); |
| 477 | } |
| 478 | }, |
| 479 | { |
| 480 | type : 'vbox', |
| 481 | id : 'emailOptions', |
| 482 | padding : 1, |
| 483 | children : |
| 484 | [ |
| 485 | { |
| 486 | type : 'text', |
| 487 | id : 'emailAddress', |
| 488 | label : editor.lang.link.emailAddress, |
| 489 | validate : function() |
| 490 | { |
| 491 | var dialog = this.getDialog(); |
| 492 | |
| 493 | if ( !dialog.getContentElement( 'info', 'linkType' ) || |
| 494 | dialog.getValueOf( 'info', 'linkType' ) != 'email' ) |
| 495 | return true; |
| 496 | |
| 497 | var func = CKEDITOR.dialog.validate.notEmpty( editor.lang.link.noEmail ); |
| 498 | return func.apply( this ); |
| 499 | }, |
| 500 | setup : function( data ) |
| 501 | { |
| 502 | if ( data.email ) |
| 503 | this.setValue( data.email.address ); |
| 504 | |
| 505 | var linkType = this.getDialog().getContentElement( 'info', 'linkType' ); |
| 506 | if ( linkType && linkType.getValue() == 'email' ) |
| 507 | this.select(); |
| 508 | }, |
| 509 | commit : function( data ) |
| 510 | { |
| 511 | if ( !data.email ) |
| 512 | data.email = {}; |
| 513 | |
| 514 | data.email.address = this.getValue(); |
| 515 | } |
| 516 | }, |
| 517 | { |
| 518 | type : 'text', |
| 519 | id : 'emailSubject', |
| 520 | label : editor.lang.link.emailSubject, |
| 521 | setup : function( data ) |
| 522 | { |
| 523 | if ( data.email ) |
| 524 | this.setValue( data.email.subject ); |
| 525 | }, |
| 526 | commit : function( data ) |
| 527 | { |
| 528 | if ( !data.email ) |
| 529 | data.email = {}; |
| 530 | |
| 531 | data.email.subject = this.getValue(); |
| 532 | } |
| 533 | }, |
| 534 | { |
| 535 | type : 'textarea', |
| 536 | id : 'emailBody', |
| 537 | label : editor.lang.link.emailBody, |
| 538 | rows : 3, |
| 539 | 'default' : '', |
| 540 | setup : function( data ) |
| 541 | { |
| 542 | if ( data.email ) |
| 543 | this.setValue( data.email.body ); |
| 544 | }, |
| 545 | commit : function( data ) |
| 546 | { |
| 547 | if ( !data.email ) |
| 548 | data.email = {}; |
| 549 | |
| 550 | data.email.body = this.getValue(); |
| 551 | } |
| 552 | } |
| 553 | ], |
| 554 | setup : function( data ) |
| 555 | { |
| 556 | if ( !this.getDialog().getContentElement( 'info', 'linkType' ) ) |
| 557 | this.getElement().hide(); |
| 558 | } |
| 559 | } |
| 560 | ] |
| 561 | }, |
| 562 | { |
| 563 | id : 'target', |
| 564 | label : editor.lang.link.target, |
| 565 | title : editor.lang.link.target, |
| 566 | elements : |
| 567 | [ |
| 568 | { |
| 569 | type : 'hbox', |
| 570 | widths : [ '50%', '50%' ], |
| 571 | children : |
| 572 | [ |
| 573 | { |
| 574 | type : 'select', |
| 575 | id : 'linkTargetType', |
| 576 | label : editor.lang.link.target, |
| 577 | 'default' : 'notSet', |
| 578 | style : 'width : 100%;', |
| 579 | 'items' : |
| 580 | [ |
| 581 | [ editor.lang.link.targetNotSet, 'notSet' ], |
| 582 | [ editor.lang.link.targetFrame, 'frame' ], |
| 583 | [ editor.lang.link.targetPopup, 'popup' ], |
| 584 | [ editor.lang.link.targetNew, '_blank' ], |
| 585 | [ editor.lang.link.targetTop, '_top' ], |
| 586 | [ editor.lang.link.targetSelf, '_self' ], |
| 587 | [ editor.lang.link.targetParent, '_parent' ] |
| 588 | ], |
| 589 | onChange : targetChanged, |
| 590 | setup : function( data ) |
| 591 | { |
| 592 | if ( data.target ) |
| 593 | this.setValue( data.target.type ); |
| 594 | }, |
| 595 | commit : function( data ) |
| 596 | { |
| 597 | if ( !data.target ) |
| 598 | data.target = {}; |
| 599 | |
| 600 | data.target.type = this.getValue(); |
| 601 | } |
| 602 | }, |
| 603 | { |
| 604 | type : 'text', |
| 605 | id : 'linkTargetName', |
| 606 | label : editor.lang.link.targetFrameName, |
| 607 | 'default' : '', |
| 608 | setup : function( data ) |
| 609 | { |
| 610 | if ( data.target ) |
| 611 | this.setValue( data.target.name ); |
| 612 | }, |
| 613 | commit : function( data ) |
| 614 | { |
| 615 | if ( !data.target ) |
| 616 | data.target = {}; |
| 617 | |
| 618 | data.target.name = this.getValue(); |
| 619 | } |
| 620 | } |
| 621 | ] |
| 622 | }, |
| 623 | { |
| 624 | type : 'vbox', |
| 625 | width : 260, |
| 626 | align : 'center', |
| 627 | padding : 2, |
| 628 | id : 'popupFeatures', |
| 629 | children : |
| 630 | [ |
| 631 | { |
| 632 | type : 'html', |
| 633 | html : CKEDITOR.tools.htmlEncode( editor.lang.link.popupFeatures ) |
| 634 | }, |
| 635 | { |
| 636 | type : 'hbox', |
| 637 | children : |
| 638 | [ |
| 639 | { |
| 640 | type : 'checkbox', |
| 641 | id : 'resizable', |
| 642 | label : editor.lang.link.popupResizable, |
| 643 | setup : setupPopupParams, |
| 644 | commit : commitPopupParams |
| 645 | }, |
| 646 | { |
| 647 | type : 'checkbox', |
| 648 | id : 'status', |
| 649 | label : editor.lang.link.popupStatusBar, |
| 650 | setup : setupPopupParams, |
| 651 | commit : commitPopupParams |
| 652 | |
| 653 | } |
| 654 | ] |
| 655 | }, |
| 656 | { |
| 657 | type : 'hbox', |
| 658 | children : |
| 659 | [ |
| 660 | { |
| 661 | type : 'checkbox', |
| 662 | id : 'location', |
| 663 | label : editor.lang.link.popupLocationBar, |
| 664 | setup : setupPopupParams, |
| 665 | commit : commitPopupParams |
| 666 | |
| 667 | }, |
| 668 | { |
| 669 | type : 'checkbox', |
| 670 | id : 'toolbar', |
| 671 | label : editor.lang.link.popupToolbar, |
| 672 | setup : setupPopupParams, |
| 673 | commit : commitPopupParams |
| 674 | |
| 675 | } |
| 676 | ] |
| 677 | }, |
| 678 | { |
| 679 | type : 'hbox', |
| 680 | children : |
| 681 | [ |
| 682 | { |
| 683 | type : 'checkbox', |
| 684 | id : 'menubar', |
| 685 | label : editor.lang.link.popupMenuBar, |
| 686 | setup : setupPopupParams, |
| 687 | commit : commitPopupParams |
| 688 | |
| 689 | }, |
| 690 | { |
| 691 | type : 'checkbox', |
| 692 | id : 'fullscreen', |
| 693 | label : editor.lang.link.popupFullScreen, |
| 694 | setup : setupPopupParams, |
| 695 | commit : commitPopupParams |
| 696 | |
| 697 | } |
| 698 | ] |
| 699 | }, |
| 700 | { |
| 701 | type : 'hbox', |
| 702 | children : |
| 703 | [ |
| 704 | { |
| 705 | type : 'checkbox', |
| 706 | id : 'scrollbars', |
| 707 | label : editor.lang.link.popupScrollBars, |
| 708 | setup : setupPopupParams, |
| 709 | commit : commitPopupParams |
| 710 | |
| 711 | }, |
| 712 | { |
| 713 | type : 'checkbox', |
| 714 | id : 'dependent', |
| 715 | label : editor.lang.link.popupDependent, |
| 716 | setup : setupPopupParams, |
| 717 | commit : commitPopupParams |
| 718 | |
| 719 | } |
| 720 | ] |
| 721 | }, |
| 722 | { |
| 723 | type : 'hbox', |
| 724 | children : |
| 725 | [ |
| 726 | { |
| 727 | type : 'text', |
| 728 | widths : [ '30%', '70%' ], |
| 729 | labelLayout : 'horizontal', |
| 730 | label : editor.lang.link.popupWidth, |
| 731 | id : 'width', |
| 732 | setup : setupPopupParams, |
| 733 | commit : commitPopupParams |
| 734 | |
| 735 | }, |
| 736 | { |
| 737 | type : 'text', |
| 738 | labelLayout : 'horizontal', |
| 739 | widths : [ '55%', '45%' ], |
| 740 | label : editor.lang.link.popupLeft, |
| 741 | id : 'left', |
| 742 | setup : setupPopupParams, |
| 743 | commit : commitPopupParams |
| 744 | |
| 745 | } |
| 746 | ] |
| 747 | }, |
| 748 | { |
| 749 | type : 'hbox', |
| 750 | children : |
| 751 | [ |
| 752 | { |
| 753 | type : 'text', |
| 754 | labelLayout : 'horizontal', |
| 755 | widths : [ '30%', '70%' ], |
| 756 | label : editor.lang.link.popupHeight, |
| 757 | id : 'height', |
| 758 | setup : setupPopupParams, |
| 759 | commit : commitPopupParams |
| 760 | |
| 761 | }, |
| 762 | { |
| 763 | type : 'text', |
| 764 | labelLayout : 'horizontal', |
| 765 | label : editor.lang.link.popupTop, |
| 766 | widths : [ '55%', '45%' ], |
| 767 | id : 'top', |
| 768 | setup : setupPopupParams, |
| 769 | commit : commitPopupParams |
| 770 | |
| 771 | } |
| 772 | ] |
| 773 | } |
| 774 | ] |
| 775 | } |
| 776 | ] |
| 777 | }, |
| 778 | { |
| 779 | id : 'upload', |
| 780 | label : editor.lang.link.upload, |
| 781 | title : editor.lang.link.upload, |
| 782 | elements : |
| 783 | [ |
| 784 | { |
| 785 | type : 'file', |
| 786 | id : 'upload', |
| 787 | label : editor.lang.common.upload, |
| 788 | action : editor.config.linkUploadAction, |
| 789 | size : 38 |
| 790 | }, |
| 791 | { |
| 792 | type : 'fileButton', |
| 793 | id : 'uploadButton', |
| 794 | label : editor.lang.common.uploadSubmit, |
| 795 | 'for' : [ 'upload', 'upload' ] |
| 796 | } |
| 797 | ] |
| 798 | }, |
| 799 | { |
| 800 | id : 'advanced', |
| 801 | label : editor.lang.link.advanced, |
| 802 | title : editor.lang.link.advanced, |
| 803 | elements : |
| 804 | [ |
| 805 | { |
| 806 | type : 'vbox', |
| 807 | padding : 1, |
| 808 | children : |
| 809 | [ |
| 810 | { |
| 811 | type : 'hbox', |
| 812 | widths : [ '45%', '35%', '20%' ], |
| 813 | children : |
| 814 | [ |
| 815 | { |
| 816 | type : 'text', |
| 817 | id : 'advId', |
| 818 | label : editor.lang.link.id, |
| 819 | setup : setupAdvParams, |
| 820 | commit : commitAdvParams |
| 821 | }, |
| 822 | { |
| 823 | type : 'select', |
| 824 | id : 'advLangDir', |
| 825 | label : editor.lang.link.langDir, |
| 826 | 'default' : '', |
| 827 | style : 'width: 100%;', |
| 828 | items : |
| 829 | [ |
| 830 | [ editor.lang.link.langDirNotSet, '' ], |
| 831 | [ editor.lang.link.langDirLTR, 'ltr' ], |
| 832 | [ editor.lang.link.langDirRTL, 'rtl' ] |
| 833 | ], |
| 834 | setup : setupAdvParams, |
| 835 | commit : commitAdvParams |
| 836 | }, |
| 837 | { |
| 838 | type : 'text', |
| 839 | id : 'advAccessKey', |
| 840 | label : editor.lang.link.acccessKey, |
| 841 | maxLength : 1, |
| 842 | setup : setupAdvParams, |
| 843 | commit : commitAdvParams |
| 844 | |
| 845 | } |
| 846 | ] |
| 847 | }, |
| 848 | { |
| 849 | type : 'hbox', |
| 850 | widths : [ '45%', '35%', '20%' ], |
| 851 | children : |
| 852 | [ |
| 853 | { |
| 854 | type : 'text', |
| 855 | label : editor.lang.link.name, |
| 856 | id : 'advName', |
| 857 | setup : setupAdvParams, |
| 858 | commit : commitAdvParams |
| 859 | |
| 860 | }, |
| 861 | { |
| 862 | type : 'text', |
| 863 | label : editor.lang.link.langCode, |
| 864 | id : 'advLangCode', |
| 865 | 'default' : '', |
| 866 | setup : setupAdvParams, |
| 867 | commit : commitAdvParams |
| 868 | |
| 869 | }, |
| 870 | { |
| 871 | type : 'text', |
| 872 | label : editor.lang.link.tabIndex, |
| 873 | id : 'advTabIndex', |
| 874 | maxLength : 5, |
| 875 | setup : setupAdvParams, |
| 876 | commit : commitAdvParams |
| 877 | |
| 878 | } |
| 879 | ] |
| 880 | } |
| 881 | ] |
| 882 | }, |
| 883 | { |
| 884 | type : 'vbox', |
| 885 | padding : 1, |
| 886 | children : |
| 887 | [ |
| 888 | { |
| 889 | type : 'hbox', |
| 890 | widths : [ '45%', '55%' ], |
| 891 | children : |
| 892 | [ |
| 893 | { |
| 894 | type : 'text', |
| 895 | label : editor.lang.link.advisoryTitle, |
| 896 | 'default' : '', |
| 897 | id : 'advTitle', |
| 898 | setup : setupAdvParams, |
| 899 | commit : commitAdvParams |
| 900 | |
| 901 | }, |
| 902 | { |
| 903 | type : 'text', |
| 904 | label : editor.lang.link.advisoryContentType, |
| 905 | 'default' : '', |
| 906 | id : 'advContentType', |
| 907 | setup : setupAdvParams, |
| 908 | commit : commitAdvParams |
| 909 | |
| 910 | } |
| 911 | ] |
| 912 | }, |
| 913 | { |
| 914 | type : 'hbox', |
| 915 | widths : [ '45%', '55%' ], |
| 916 | children : |
| 917 | [ |
| 918 | { |
| 919 | type : 'text', |
| 920 | label : editor.lang.link.cssClasses, |
| 921 | 'default' : '', |
| 922 | id : 'advCSSClasses', |
| 923 | setup : setupAdvParams, |
| 924 | commit : commitAdvParams |
| 925 | |
| 926 | }, |
| 927 | { |
| 928 | type : 'text', |
| 929 | label : editor.lang.link.charset, |
| 930 | 'default' : '', |
| 931 | id : 'advCharset', |
| 932 | setup : setupAdvParams, |
| 933 | commit : commitAdvParams |
| 934 | |
| 935 | } |
| 936 | ] |
| 937 | }, |
| 938 | { |
| 939 | type : 'hbox', |
| 940 | children : |
| 941 | [ |
| 942 | { |
| 943 | type : 'text', |
| 944 | label : editor.lang.link.styles, |
| 945 | 'default' : '', |
| 946 | id : 'advStyles', |
| 947 | setup : setupAdvParams, |
| 948 | commit : commitAdvParams |
| 949 | |
| 950 | } |
| 951 | ] |
| 952 | } |
| 953 | ] |
| 954 | } |
| 955 | ] |
| 956 | } |
| 957 | ], |
| 958 | onShow : function() |
| 959 | { |
| 960 | this.fakeObj = false; |
| 961 | // IE BUG: Selection must be in the editor for getSelection() to work. |
| 962 | this.restoreSelection(); |
| 963 | var editor = this.getParentEditor(), |
| 964 | selection = editor.getSelection(), |
| 965 | ranges = selection.getRanges(), |
| 966 | element = null, |
| 967 | me = this; |
| 968 | |
| 969 | // Fill in all the relevant fields if there's already one link selected. |
| 970 | if ( ranges.length == 1 ) |
| 971 | { |
| 972 | ranges[0].enlarge( CKEDITOR.ENLARGE_ELEMENT ); |
| 973 | |
| 974 | var rangeRoot = ranges[0].getCommonAncestor( true ); |
| 975 | element = rangeRoot.getAscendant( 'a', true ); |
| 976 | if ( element && element.getAttribute( 'href' ) ) |
| 977 | { |
| 978 | selection.selectElement( element ); |
| 979 | this.saveSelection(); |
| 980 | } |
| 981 | else |
| 982 | { |
| 983 | element = rangeRoot.getAscendant( 'img', true ); |
| 984 | if ( element && element.getAttribute( '_cke_real_element_type' ) && element.getAttribute( '_cke_real_element_type' ) == 'anchor' ) |
| 985 | { |
| 986 | this.fakeObj = element; |
| 987 | element = editor.restoreRealElement( this.fakeObj ); |
| 988 | selection.selectElement( this.fakeObj ); |
| 989 | this.saveSelection(); |
| 990 | } |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | this.setupContent( parseLink.apply( this, [ editor, element ] ) ); |
| 995 | }, |
| 996 | onOk : function() |
| 997 | { |
| 998 | var attributes = { href : 'javascript:void(0)/*' + CKEDITOR.tools.getNextNumber() + '*/' }, |
| 999 | removeAttributes = [], |
| 1000 | data = { href : attributes.href }, |
| 1001 | me = this, editor = this.getParentEditor(); |
| 1002 | |
| 1003 | this.commitContent( data ); |
| 1004 | |
| 1005 | // Compose the URL. |
| 1006 | switch ( data.type || 'url' ) |
| 1007 | { |
| 1008 | case 'url': |
| 1009 | var protocol = ( data.url && data.url.protocol ) || 'http://', |
| 1010 | url = ( data.url && data.url.url ) || ''; |
| 1011 | attributes._cke_saved_href = protocol + url; |
| 1012 | break; |
| 1013 | case 'anchor': |
| 1014 | var name = ( data.anchor && data.anchor.name ), |
| 1015 | id = ( data.anchor && data.anchor.id ); |
| 1016 | attributes._cke_saved_href = '#' + ( name || id || '' ); |
| 1017 | break; |
| 1018 | case 'email': |
| 1019 | var address = ( data.email && data.email.address ), |
| 1020 | subject = ( data.email && encodeURIComponent( data.email.subject || '' ) ), |
| 1021 | body = ( data.email && encodeURIComponent( data.email.body || '' ) ), |
| 1022 | linkList = [ 'mailto:', address ]; |
| 1023 | if ( subject || body ) |
| 1024 | { |
| 1025 | var argList = []; |
| 1026 | linkList.push( '?' ); |
| 1027 | subject && argList.push( 'subject=' + subject ); |
| 1028 | body && argList.push( 'body=' + body ); |
| 1029 | linkList.push( argList.join( '&' ) ); |
| 1030 | } |
| 1031 | attributes._cke_saved_href = linkList.join( '' ); |
| 1032 | break; |
| 1033 | default: |
| 1034 | } |
| 1035 | |
| 1036 | // Popups and target. |
| 1037 | if ( data.target ) |
| 1038 | { |
| 1039 | if ( data.target.type == 'popup' ) |
| 1040 | { |
| 1041 | var onclickList = [ 'window.open(this.href, \'', |
| 1042 | data.target.name || '', '\', \'' ]; |
| 1043 | var featureList = [ 'resizable', 'status', 'location', 'toolbar', 'menubar', 'fullscreen', |
| 1044 | 'scrollbars', 'dependent' ]; |
| 1045 | var featureLength = featureList.length; |
| 1046 | var addFeature = function( featureName ) |
| 1047 | { |
| 1048 | if ( data.target[ featureName ] ) |
| 1049 | featureList.push( featureName + '=' + data.target[ featureName ] ); |
| 1050 | }; |
| 1051 | |
| 1052 | for ( var i = 0 ; i < featureLength ; i++ ) |
| 1053 | featureList[i] = featureList[i] + ( data.target[ featureList[i] ] ? '=yes' : '=no' ) ; |
| 1054 | addFeature( 'width' ); |
| 1055 | addFeature( 'left' ); |
| 1056 | addFeature( 'height' ); |
| 1057 | addFeature( 'top' ); |
| 1058 | |
| 1059 | onclickList.push( featureList.join( ',' ), '\'); return false;' ); |
| 1060 | attributes._cke_saved_onclick = onclickList.join( '' ); |
| 1061 | } |
| 1062 | else |
| 1063 | { |
| 1064 | if ( data.target.type != 'notSet' && data.target.name ) |
| 1065 | attributes.target = data.target.name; |
| 1066 | removeAttributes.push( '_cke_saved_onclick', 'onclick' ); |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | // Advanced attributes. |
| 1071 | if ( data.adv ) |
| 1072 | { |
| 1073 | var advAttr = function( inputName, attrName ) |
| 1074 | { |
| 1075 | var value = data.adv[ inputName ]; |
| 1076 | if ( value ) |
| 1077 | attributes[attrName] = value; |
| 1078 | else |
| 1079 | removeAttributes.push( attrName ); |
| 1080 | }; |
| 1081 | |
| 1082 | if ( this._.selectedElement ) |
| 1083 | advAttr( 'advId', 'id' ); |
| 1084 | advAttr( 'advLangDir', 'dir' ); |
| 1085 | advAttr( 'advAccessKey', 'accessKey' ); |
| 1086 | advAttr( 'advName', 'name' ); |
| 1087 | advAttr( 'advLangCode', 'lang' ); |
| 1088 | advAttr( 'advTabIndex', 'tabindex' ); |
| 1089 | advAttr( 'advTitle', 'title' ); |
| 1090 | advAttr( 'advContentType', 'type' ); |
| 1091 | advAttr( 'advCSSClasses', 'class' ); |
| 1092 | advAttr( 'advCharset', 'charset' ); |
| 1093 | advAttr( 'advStyles', 'style' ); |
| 1094 | } |
| 1095 | |
| 1096 | if ( !this._.selectedElement ) |
| 1097 | { |
| 1098 | // IE BUG: Selection must be in the editor for getSelection() to work. |
| 1099 | this.restoreSelection(); |
| 1100 | this.clearSavedSelection(); |
| 1101 | |
| 1102 | // Create element if current selection is collapsed. |
| 1103 | var selection = editor.getSelection(), |
| 1104 | ranges = selection.getRanges(); |
| 1105 | if ( ranges.length == 1 && ranges[0].collapsed ) |
| 1106 | { |
| 1107 | var text = new CKEDITOR.dom.text( attributes._cke_saved_href, editor.document ); |
| 1108 | ranges[0].insertNode( text ); |
| 1109 | ranges[0].selectNodeContents( text ); |
| 1110 | selection.selectRanges( ranges ); |
| 1111 | } |
| 1112 | |
| 1113 | // Apply style. |
| 1114 | var style = new CKEDITOR.style( { element : 'a', attributes : attributes } ); |
| 1115 | style.type = CKEDITOR.STYLE_INLINE; // need to override... dunno why. |
| 1116 | style.apply( editor.document ); |
| 1117 | |
| 1118 | // Id. Apply only to the first link. |
| 1119 | if ( data.adv && data.adv.advId != '' ) |
| 1120 | { |
| 1121 | var links = this.getParentEditor().document.$.getElementsByTagName( 'a' ); |
| 1122 | for ( var i = 0 ; i < links.length ; i++ ) |
| 1123 | { |
| 1124 | if ( links[i].href == attributes.href ) |
| 1125 | { |
| 1126 | links[i].id = data.adv.advId; |
| 1127 | break; |
| 1128 | } |
| 1129 | } |
| 1130 | } |
| 1131 | } |
| 1132 | else |
| 1133 | { |
| 1134 | // We're only editing an existing link, so just overwrite the attributes. |
| 1135 | var element = this._.selectedElement; |
| 1136 | |
| 1137 | // IE BUG: Setting the name attribute to an existing link doesn't work. |
| 1138 | // Must re-create the link from weired syntax to workaround. |
| 1139 | if ( CKEDITOR.env.ie && attributes.name != element.getAttribute( 'name' ) ) |
| 1140 | { |
| 1141 | var newElement = new CKEDITOR.dom.element( '<a name="' + CKEDITOR.tools.htmlEncode( attributes.name ) + '">', |
| 1142 | editor.document ); |
| 1143 | |
| 1144 | this.restoreSelection(); |
| 1145 | var selection = editor.getSelection(); |
| 1146 | |
| 1147 | element.moveChildren( newElement ); |
| 1148 | element.copyAttributes( newElement, { name : 1 } ); |
| 1149 | newElement.replace( element ); |
| 1150 | element = newElement; |
| 1151 | |
| 1152 | this.clearSavedSelection(); |
| 1153 | selection.selectElement( element ); |
| 1154 | } |
| 1155 | |
| 1156 | element.setAttributes( attributes ); |
| 1157 | element.removeAttributes( removeAttributes ); |
| 1158 | |
| 1159 | // Make the element display as an anchor if a name has been set. |
| 1160 | if ( element.getAttribute( 'name' ) ) |
| 1161 | element.addClass( 'cke_anchor' ); |
| 1162 | else |
| 1163 | element.removeClass( 'cke_anchor' ); |
| 1164 | |
| 1165 | if ( this.fakeObj ) |
| 1166 | editor.createFakeElement( element, 'cke_anchor', 'anchor' ).replace( this.fakeObj ); |
| 1167 | |
| 1168 | delete this._.selectedElement; |
| 1169 | } |
| 1170 | }, |
| 1171 | onLoad : function() |
| 1172 | { |
| 1173 | if ( editor.config.linkUploadTab == false ) |
| 1174 | this.hidePage( 'upload' ); //Hide Upload tab. |
| 1175 | |
| 1176 | if ( editor.config.linkShowAdvancedTab == false ) |
| 1177 | this.hidePage( 'advanced' ); //Hide Advanded tab. |
| 1178 | |
| 1179 | if ( editor.config.linkBrowseServer == false ) |
| 1180 | this.getContentElement( 'info', 'browse' ).getElement().hide(); |
| 1181 | |
| 1182 | if ( editor.config.linkShowTargetTab == false ) |
| 1183 | this.hidePage( 'target' ); //Hide Target tab. |
| 1184 | |
| 1185 | } |
| 1186 | }; |
| 1187 | } ); |