Ticket #2839: 2839.patch

File 2839.patch, 35.1 KB (added by Martin Kou, 15 years ago)
  • _samples/api_dialog.html

     
    5656
    5757                        // Remove the "Link Type" combo and the "Browser
    5858                        // Server" button from the "info" tab.
    59                         infoTab.remove( 'protocol' );
     59                        infoTab.remove( 'linkType' );
    6060                        infoTab.remove( 'browse' );
    6161
    6262                        // Set the default value for the URL field.
  • _source/plugins/dialogui/plugin.js

     
    884884                                accessKeyUp : function()
    885885                                {
    886886                                        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 );
    887900                                }
    888901                        }, commonPrototype, true );
    889902
  • _source/plugins/link/dialogs/link.js

     
    88        // Handles the event when the "Target" selection box is changed.
    99        var targetChanged = function()
    1010        {
    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' ),
    1314                        value = this.getValue();
     15
     16                if ( !popupFeatures || !targetName )
     17                        return;
     18
     19                popupFeatures = popupFeatures.getElement();
     20
    1421                if ( value == 'popup' )
    1522                {
    1623                        popupFeatures.show();
     
    4451
    4552                for ( var i = 0 ; i < partIds.length ; i++ )
    4653                {
    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();
    4859                        if ( partIds[i] == typeValue + 'Options' )
    4960                                element.show();
    5061                        else
     
    6172                popupRegex =
    6273                /\s*window.open\(\s*this\.href\s*,\s*(?:'([^']*)'|null)\s*,\s*'([^']*)'\s*\)\s*;\s*return\s*false;*\s*/,
    6374                popupFeaturesRegex = /(?:^|,)([^=]+)=(\d+|yes|no)/gi,
    64                 loadLink = function( editor, selection, ranges, element )
     75                parseLink = function( editor, element )
    6576        {
    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
    7083                if ( href != null )
    7184                {
    7285                        emailMatch = href.match( emailRegex );
    7386                        anchorMatch = href.match( anchorRegex );
    7487                        urlMatch = href.match( urlRegex );
    7588                }
    76                 var me = this;
    7789
    7890                // Load the link type and URL.
    7991                if ( emailMatch )
    8092                {
    8193                        var subjectMatch = href.match( emailSubjectRegex ),
    8294                                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] ) );
    87100                }
    88101                else if ( anchorMatch )
    89102                {
    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];
    93106                }
    94107                else if ( urlMatch )
    95108                {
    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];
    100113                }
    101114                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';
    107116
    108117                // Load target and popup settings.
    109                 var target = element.getAttribute( 'target' );
    110                 if ( target == null )
     118                if ( element )
    111119                {
    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 )
    115125                        {
    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];
    118132
    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                                        }
    126141                                }
    127142                        }
    128143                        else
    129144                        {
    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                                }
    132153                        }
     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' );
    133173                }
    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++ )
    135180                {
    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" )
    138183                        {
    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 );
    141187                        }
    142                         else
    143                         {
    144                                 this.setValueOf( 'target', 'linkTargetType', 'frame' );
    145                                 this.setValueOf( 'target', 'linkTargetName', target );
    146                         }
    147188                }
    148 
    149                 // Load advanced attributes.
    150                 var advAttr = function( inputName, attrName )
     189                for ( var i = 0, name, id ; i < anchors.length ; i++ )
    151190                {
    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                }
    166195
    167196                // Record down the selected element in the dialog.
    168197                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 );
    169228        };
    170229
    171230        return {
     
    190249                                                        [ editor.lang.link.toAnchor, 'anchor' ],
    191250                                                        [ editor.lang.link.toEmail, 'email' ]
    192251                                                ],
    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                                                }
    194262                                        },
    195263                                        {
    196264                                                type : 'vbox',
     
    215283                                                                                        [ 'ftp://' ],
    216284                                                                                        [ 'news://' ],
    217285                                                                                        [ '<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                                                                                }
    219299                                                                        },
    220300                                                                        {
    221301                                                                                type : 'text',
     
    223303                                                                                label : editor.lang.common.url,
    224304                                                                                validate : function()
    225305                                                                                {
    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' )
    227310                                                                                                return true;
    228311
    229312                                                                                        if ( this.getDialog().fakeObj != false )        // Edit Anchor.
     
    231314
    232315                                                                                        var func = CKEDITOR.dialog.validate.notEmpty( editor.lang.link.noUrl );
    233316                                                                                        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();
    234333                                                                                }
    235334                                                                        }
    236                                                                 ]
     335                                                                ],
     336                                                                setup : function( data )
     337                                                                {
     338                                                                        if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
     339                                                                                this.getElement().show();
     340                                                                }
    237341                                                        },
    238342                                                        {
    239343                                                                type : 'button',
     
    253357                                                        {
    254358                                                                type : 'html',
    255359                                                                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                                                                }
    257368                                                        },
    258369                                                        {
    259370                                                                type : 'html',
    260371                                                                id : 'noAnchors',
    261372                                                                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                                                                }
    263381                                                        },
    264382                                                        {
    265383                                                                type : 'hbox',
     
    275393                                                                                items :
    276394                                                                                [
    277395                                                                                        [ '' ]
    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                                                                                }
    279421                                                                        },
    280422                                                                        {
    281423                                                                                type : 'select',
     
    286428                                                                                items :
    287429                                                                                [
    288430                                                                                        [ '' ]
    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                                                                                }
    290452                                                                        }
    291                                                                 ]
     453                                                                ],
     454                                                                setup : function( data )
     455                                                                {
     456                                                                        if ( data.anchors.length > 0 )
     457                                                                                this.getElement().show();
     458                                                                        else
     459                                                                                this.getElement().hide();
     460                                                                }
    292461                                                        }
    293                                                 ]
     462                                                ],
     463                                                setup : function( data )
     464                                                {
     465                                                        if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
     466                                                                this.getElement().hide();
     467                                                }
    294468                                        },
    295469                                        {
    296470                                                type :  'vbox',
     
    304478                                                                label : editor.lang.link.emailAddress,
    305479                                                                validate : function()
    306480                                                                {
    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' )
    308485                                                                                return true;
    309486
    310487                                                                        var func = CKEDITOR.dialog.validate.notEmpty( editor.lang.link.noEmail );
    311488                                                                        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();
    312505                                                                }
    313506                                                        },
    314507                                                        {
    315508                                                                type : 'text',
    316509                                                                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                                                                }
    318523                                                        },
    319524                                                        {
    320525                                                                type : 'textarea',
    321526                                                                id : 'emailBody',
    322527                                                                label : editor.lang.link.emailBody,
    323528                                                                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                                                                }
    325542                                                        }
    326                                                 ]
     543                                                ],
     544                                                setup : function( data )
     545                                                {
     546                                                        if ( !this.getDialog().getContentElement( 'info', 'linkType' ) )
     547                                                                this.getElement().hide();
     548                                                }
    327549                                        }
    328550                                ]
    329551                        },
     
    354576                                                                        [ editor.lang.link.targetSelf, '_self' ],
    355577                                                                        [ editor.lang.link.targetParent, '_parent' ]
    356578                                                                ],
    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                                                                }
    358592                                                        },
    359593                                                        {
    360594                                                                type : 'text',
    361595                                                                id : 'linkTargetName',
    362596                                                                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                                                                }
    364610                                                        }
    365611                                                ]
    366612                                        },
     
    383629                                                                        {
    384630                                                                                type : 'checkbox',
    385631                                                                                id : 'resizable',
    386                                                                                 label : editor.lang.link.popupResizable
     632                                                                                label : editor.lang.link.popupResizable,
     633                                                                                setup : setupPopupParams,
     634                                                                                commit : commitPopupParams
    387635                                                                        },
    388636                                                                        {
    389637                                                                                type : 'checkbox',
    390638                                                                                id : 'status',
    391                                                                                 label : editor.lang.link.popupStatusBar
     639                                                                                label : editor.lang.link.popupStatusBar,
     640                                                                                setup : setupPopupParams,
     641                                                                                commit : commitPopupParams
     642
    392643                                                                        }
    393644                                                                ]
    394645                                                        },
     
    399650                                                                        {
    400651                                                                                type : 'checkbox',
    401652                                                                                id : 'location',
    402                                                                                 label : editor.lang.link.popupLocationBar
     653                                                                                label : editor.lang.link.popupLocationBar,
     654                                                                                setup : setupPopupParams,
     655                                                                                commit : commitPopupParams
     656
    403657                                                                        },
    404658                                                                        {
    405659                                                                                type : 'checkbox',
    406660                                                                                id : 'toolbar',
    407                                                                                 label : editor.lang.link.popupToolbar
     661                                                                                label : editor.lang.link.popupToolbar,
     662                                                                                setup : setupPopupParams,
     663                                                                                commit : commitPopupParams
     664
    408665                                                                        }
    409666                                                                ]
    410667                                                        },
     
    415672                                                                        {
    416673                                                                                type : 'checkbox',
    417674                                                                                id : 'menubar',
    418                                                                                 label : editor.lang.link.popupMenuBar
     675                                                                                label : editor.lang.link.popupMenuBar,
     676                                                                                setup : setupPopupParams,
     677                                                                                commit : commitPopupParams
     678
    419679                                                                        },
    420680                                                                        {
    421681                                                                                type : 'checkbox',
    422682                                                                                id : 'fullscreen',
    423                                                                                 label : editor.lang.link.popupFullScreen
     683                                                                                label : editor.lang.link.popupFullScreen,
     684                                                                                setup : setupPopupParams,
     685                                                                                commit : commitPopupParams
     686
    424687                                                                        }
    425688                                                                ]
    426689                                                        },
     
    431694                                                                        {
    432695                                                                                type : 'checkbox',
    433696                                                                                id : 'scrollbars',
    434                                                                                 label : editor.lang.link.popupScrollBars
     697                                                                                label : editor.lang.link.popupScrollBars,
     698                                                                                setup : setupPopupParams,
     699                                                                                commit : commitPopupParams
     700
    435701                                                                        },
    436702                                                                        {
    437703                                                                                type : 'checkbox',
    438704                                                                                id : 'dependent',
    439                                                                                 label : editor.lang.link.popupDependent
     705                                                                                label : editor.lang.link.popupDependent,
     706                                                                                setup : setupPopupParams,
     707                                                                                commit : commitPopupParams
     708
    440709                                                                        }
    441710                                                                ]
    442711                                                        },
     
    449718                                                                                widths : [ '30%', '70%' ],
    450719                                                                                labelLayout : 'horizontal',
    451720                                                                                label : editor.lang.link.popupWidth,
    452                                                                                 id : 'width'
     721                                                                                id : 'width',
     722                                                                                setup : setupPopupParams,
     723                                                                                commit : commitPopupParams
     724
    453725                                                                        },
    454726                                                                        {
    455727                                                                                type :  'text',
    456728                                                                                labelLayout : 'horizontal',
    457729                                                                                widths : [ '55%', '45%' ],
    458730                                                                                label : editor.lang.link.popupLeft,
    459                                                                                 id : 'left'
     731                                                                                id : 'left',
     732                                                                                setup : setupPopupParams,
     733                                                                                commit : commitPopupParams
     734
    460735                                                                        }
    461736                                                                ]
    462737                                                        },
     
    469744                                                                                labelLayout : 'horizontal',
    470745                                                                                widths : [ '30%', '70%' ],
    471746                                                                                label : editor.lang.link.popupHeight,
    472                                                                                 id : 'height'
     747                                                                                id : 'height',
     748                                                                                setup : setupPopupParams,
     749                                                                                commit : commitPopupParams
     750
    473751                                                                        },
    474752                                                                        {
    475753                                                                                type :  'text',
    476754                                                                                labelLayout : 'horizontal',
    477755                                                                                label : editor.lang.link.popupTop,
    478756                                                                                widths : [ '55%', '45%' ],
    479                                                                                 id : 'top'
     757                                                                                id : 'top',
     758                                                                                setup : setupPopupParams,
     759                                                                                commit : commitPopupParams
     760
    480761                                                                        }
    481762                                                                ]
    482763                                                        }
     
    524805                                                                        {
    525806                                                                                type : 'text',
    526807                                                                                id : 'advId',
    527                                                                                 label : editor.lang.link.id
     808                                                                                label : editor.lang.link.id,
     809                                                                                setup : setupAdvParams,
     810                                                                                commit : commitAdvParams
    528811                                                                        },
    529812                                                                        {
    530813                                                                                type : 'select',
     
    537820                                                                                        [ editor.lang.link.langDirNotSet, '' ],
    538821                                                                                        [ editor.lang.link.langDirLTR, 'ltr' ],
    539822                                                                                        [ editor.lang.link.langDirRTL, 'rtl' ]
    540                                                                                 ]
     823                                                                                ],
     824                                                                                setup : setupAdvParams,
     825                                                                                commit : commitAdvParams
     826
    541827                                                                        },
    542828                                                                        {
    543829                                                                                type : 'text',
    544830                                                                                id : 'advAccessKey',
    545831                                                                                label : editor.lang.link.acccessKey,
    546                                                                                 maxLength : 1
     832                                                                                maxLength : 1,
     833                                                                                setup : setupAdvParams,
     834                                                                                commit : commitAdvParams
     835
    547836                                                                        }
    548837                                                                ]
    549838                                                        },
     
    555844                                                                        {
    556845                                                                                type : 'text',
    557846                                                                                label : editor.lang.link.name,
    558                                                                                 id : 'advName'
     847                                                                                id : 'advName',
     848                                                                                setup : setupAdvParams,
     849                                                                                commit : commitAdvParams
     850
    559851                                                                        },
    560852                                                                        {
    561853                                                                                type : 'text',
    562854                                                                                label : editor.lang.link.langCode,
    563855                                                                                id : 'advLangCode',
    564                                                                                 'default' : editor.config.link.defaultValues.langCode
     856                                                                                'default' : editor.config.link.defaultValues.langCode,
     857                                                                                setup : setupAdvParams,
     858                                                                                commit : commitAdvParams
     859
    565860                                                                        },
    566861                                                                        {
    567862                                                                                type : 'text',
    568863                                                                                label : editor.lang.link.tabIndex,
    569864                                                                                id : 'advTabIndex',
    570                                                                                 maxLength : 5
     865                                                                                maxLength : 5,
     866                                                                                setup : setupAdvParams,
     867                                                                                commit : commitAdvParams
     868
    571869                                                                        }
    572870                                                                ]
    573871                                                        }
     
    587885                                                                                type : 'text',
    588886                                                                                label : editor.lang.link.advisoryTitle,
    589887                                                                                'default' : editor.config.link.defaultValues.title,
    590                                                                                 id : 'advTitle'
     888                                                                                id : 'advTitle',
     889                                                                                setup : setupAdvParams,
     890                                                                                commit : commitAdvParams
     891
    591892                                                                        },
    592893                                                                        {
    593894                                                                                type : 'text',
    594895                                                                                label : editor.lang.link.advisoryContentType,
    595896                                                                                'default' : editor.config.link.defaultValues.type,
    596                                                                                 id : 'advContentType'
     897                                                                                id : 'advContentType',
     898                                                                                setup : setupAdvParams,
     899                                                                                commit : commitAdvParams
     900
    597901                                                                        }
    598902                                                                ]
    599903                                                        },
     
    606910                                                                                type : 'text',
    607911                                                                                label : editor.lang.link.cssClasses,
    608912                                                                                'default' : editor.config.link.defaultValues.classes,
    609                                                                                 id : 'advCSSClasses'
     913                                                                                id : 'advCSSClasses',
     914                                                                                setup : setupAdvParams,
     915                                                                                commit : commitAdvParams
     916
    610917                                                                        },
    611918                                                                        {
    612919                                                                                type : 'text',
    613920                                                                                label : editor.lang.link.charset,
    614921                                                                                'default' : editor.config.link.defaultValues.charset,
    615                                                                                 id : 'advCharset'
     922                                                                                id : 'advCharset',
     923                                                                                setup : setupAdvParams,
     924                                                                                commit : commitAdvParams
     925
    616926                                                                        }
    617927                                                                ]
    618928                                                        },
     
    624934                                                                                type : 'text',
    625935                                                                                label : editor.lang.link.styles,
    626936                                                                                'default' : editor.config.link.defaultValues.style,
    627                                                                                 id : 'advStyles'
     937                                                                                id : 'advStyles',
     938                                                                                setup : setupAdvParams,
     939                                                                                commit : commitAdvParams
     940
    628941                                                                        }
    629942                                                                ]
    630943                                                        }
     
    641954                        var editor = this.getParentEditor(),
    642955                                selection = editor.getSelection(),
    643956                                ranges = selection.getRanges(),
     957                                element = null,
    644958                                me = this;
    645959
    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                         else
    668                         {
    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 
    688960                        // Fill in all the relevant fields if there's already one link selected.
    689961                        if ( ranges.length == 1 )
    690962                        {
    691963                                ranges[0].enlarge( CKEDITOR.ENLARGE_ELEMENT );
    692964
    693                                 var rangeRoot = ranges[0].getCommonAncestor( true ),
    694                                         element = rangeRoot.getAscendant( 'a', true );
     965                                var rangeRoot = ranges[0].getCommonAncestor( true );
     966                                element = rangeRoot.getAscendant( 'a', true );
    695967                                if ( element && element.getAttribute( 'href' ) )
    696968                                {
    697                                         loadLink.apply( this, [ editor, selection, ranges, element ] );
    698969                                        selection.selectElement( element );
    699970                                        this.saveSelection();
    700971                                }
    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
    704973                                {
    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                                        }
    710982                                }
    711983                        }
    712984
     985                        this.setupContent( parseLink.apply( this, [ editor, element ] ) );
     986
    713987                        // Push the current values into the dialog default value stack.
    714988                        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                         else
    723                                 me.getContentElement( 'info', 'anchorName' ).focus();
    724989                },
    725990                onOk : function()
    726991                {
    727992                        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();
    729995
     996                        this.commitContent( data );
     997
    730998                        // Compose the URL.
    731                         switch ( this.getValueOf( 'info', 'linkType' ) )
     999                        switch ( data.type || 'url' )
    7321000                        {
    7331001                                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;
    7351005                                        break;
    7361006                                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 || '' );
    7381010                                        break;
    7391011                                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 )
    7441017                                        {
    7451018                                                var argList = [];
    7461019                                                linkList.push( '?' );
     
    7541027                        }
    7551028
    7561029                        // Popups and target.
    757                         if ( this.getValueOf( 'target', 'linkTargetType' ) == 'popup' )
     1030                        if ( data.target )
    7581031                        {
    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                                                };
    7691044
    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' );
    7761051
    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                                }
    7791060                        }
    780                         else
    781                         {
    782                                 if ( this.getValueOf( 'target', 'linkTargetType' ) != 'notSet' )
    783                                         attributes.target = this.getValueOf( 'target', 'linkTargetName' );
    784                         }
    7851061
    7861062                        // Advanced attributes.
    787                         var advAttr = function( inputName, attrName )
     1063                        if ( data.adv )
    7881064                        {
    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                        }
    8031082
    8041083                        if ( !this._.selectedElement )
    8051084                        {
     
    8221101                                style.apply( editor.document );
    8231102
    8241103                                // Id. Apply only to the first link.
    825                                 if ( this.getValueOf( 'advanced', 'advId' ) != '' )
     1104                                if ( data.adv && data.adv.id != '' )
    8261105                                {
    8271106                                        var links = this.getParentEditor().document.$.getElementsByTagName( 'a' );
    8281107                                        for ( var i = 0 ; i < links.length ; i++ )
    8291108                                        {
    8301109                                                if ( links[i].href == attributes.href )
    8311110                                                {
    832                                                         links[i].id = this.getValueOf( 'advanced', 'advId' );
     1111                                                        links[i].id = data.adv.id;
    8331112                                                        break;
    8341113                                                }
    8351114                                        }
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy