Skip to content

Commit

Permalink
Merge pull request #3421 from ckeditor/t/2227
Browse files Browse the repository at this point in the history
Add link protocol field customization
  • Loading branch information
f1ames authored Sep 17, 2019
2 parents 23582c4 + 19e8b3b commit b6b486f
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ New Features:
* [#3118](https://github.com/ckeditor/ckeditor-dev/issues/3118): Selecting a paragraph with triple-click and applying heading applies heading only to selected paragraph.
* [#3161](https://github.com/ckeditor/ckeditor-dev/issues/3161): Double click on a `span` element containing one word only creates correct selection including clicked `span` only.
* [#3359](https://github.com/ckeditor/ckeditor-dev/issues/3359): Improved [dialog](https://ckeditor.com/cke4/addon/dialog) positioning and behaviour when browser window is resized, dialog resized or moved.
* [#2227](https://github.com/ckeditor/ckeditor-dev/issues/2227): Added [`config.linkDefaultProtocol`](https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-linkDefaultProtocol) configuration option that allows setting default URL protocol for [Link](https://ckeditor.com/cke4/addon/link) plugin dialog.

Fixed Issues:

Expand Down
5 changes: 3 additions & 2 deletions plugins/link/dialogs/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@
id: 'protocol',
type: 'select',
label: commonLang.protocol,
'default': 'http://',
items: [
// Force 'ltr' for protocol names in BIDI. (https://dev.ckeditor.com/ticket/5433)
[ 'http://\u200E', 'http://' ],
Expand All @@ -281,9 +280,11 @@
[ 'news://\u200E', 'news://' ],
[ linkLang.other, '' ]
],
'default': editor.config.linkDefaultProtocol,
setup: function( data ) {
if ( data.url )
if ( data.url ) {
this.setValue( data.url.protocol || '' );
}
},
commit: function( data ) {
if ( !data.url )
Expand Down
23 changes: 22 additions & 1 deletion plugins/link/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,28 @@
* @cfg {Boolean} [linkShowTargetTab=true]
* @member CKEDITOR.config
*/
linkShowTargetTab: true
linkShowTargetTab: true,

/**
* Default URL protocol used for link dialog.
*
* Available values are:
*
* * `'http://'`
* * `'https://'`
* * `'ftp://'`
* * `'news://'`
* * `''` - empty string for `<other>` option
*
* ```javascript
* config.linkDefaultProtocol = 'https://';
* ```
*
* @cfg {String}
* @member CKEDITOR.config
* @since 4.13.0
*/
linkDefaultProtocol: 'http://'

/**
* Whether JavaScript code is allowed as a `href` attribute in an anchor tag.
Expand Down
33 changes: 32 additions & 1 deletion tests/plugins/link/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@
linkPhoneRegExp: /^[0-9]{9}$/,
linkPhoneMsg: 'Invalid number'
}
},
customProtocol: {
config: {
linkDefaultProtocol: 'https://'
}
},

otherProtocol: {
config: {
linkDefaultProtocol: ''
}
}
};

Expand Down Expand Up @@ -627,7 +638,27 @@

'test email address with "?" in domain': assertEmail( 'mailto:?ck?editor@cksou?rce.com' ),

'test email address with "?" and arguments': assertEmail( 'mailto:[email protected]?subject=cke4&amp;body=hello' )
'test email address with "?" and arguments': assertEmail( 'mailto:[email protected]?subject=cke4&amp;body=hello' ),

// (#2227)
'test custom URL protocol': function() {
var bot = this.editorBots.customProtocol;

bot.dialog( 'link', function( dialog ) {
assert.areEqual( 'https://', dialog.getContentElement( 'info', 'protocol' ).getValue() );
dialog.hide();
} );
},

// (#2227)
'test other URL protocol': function() {
var bot = this.editorBots.otherProtocol;

bot.dialog( 'link', function( dialog ) {
assert.areEqual( '', dialog.getContentElement( 'info', 'protocol' ).getValue() );
dialog.hide();
} );
}
} );

function assertEmail( link ) {
Expand Down
15 changes: 15 additions & 0 deletions tests/plugins/link/manual/protocol.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<h2>First editor</h2>
<div id="editor1"></div>

<h2>Second editor</h2>
<div id="editor2"</div>

<script>
CKEDITOR.replace( 'editor1', {
linkDefaultProtocol: 'https://'
} );

CKEDITOR.replace( 'editor2', {
linkDefaultProtocol: 'https://'
} );
</script>
16 changes: 16 additions & 0 deletions tests/plugins/link/manual/protocol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@bender-tags: feature, link, 2227, 4.13.0
@bender-ckeditor-plugins: link, toolbar, wysiwygarea
@bender-ui: collapsed

1. Click link button in the first editor.

**Expected:** Protocol set to `https://`.

2. Change protocol into `http://`.
3. Fill URL field with `foo`.
4. Click `OK`.
5. Double click inserted link to open dialog.

**Expected**: Link protocol remains `http://`.

6. Repeat 1-5 test steps with the second editor using `<other>` protocol instead of `http://`.

0 comments on commit b6b486f

Please sign in to comment.