Skip to content

Commit 718848f

Browse files
author
Katochimoto
committed
замена email
1 parent 0eed78f commit 718848f

File tree

3 files changed

+51
-15
lines changed

3 files changed

+51
-15
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ckeditor-autolink2",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"description": "A hyperlink auto-generator plugin for CKEditor",
55
"main": "plugin.js",
66
"scripts": {

plugin.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
var REG_PROTO_HTTP = /^(?:https?:\/\/|ssh:\/\/|ftp:\/\/|file:\/|mailto:)/i;
99
var REG_MAILTO = /^mailto:([^\?]+)/i;
1010
var REG_EMAIL = /^[a-zа-яёÇçĞğIıİiÖöŞşÜüß0-9!#$%&'*+\/=?.^_`{|}~-]+?@(?:[a-zа-яёÇçĞğIıİiÖöŞşÜüß0-9](?:[a-zа-яёÇçĞğIıİiÖöŞşÜüß0-9-_]*?[a-zа-яёÇçĞğIıİiÖöŞşÜüß0-9])?\.)+?(?:xn--[-a-z0-9]+|[a-zа-яё]{2,}|\d{1,3})$/i;
11+
var REG_CHECK_EMAIL = /(?:^|\s+)[a-zа-яёÇçĞğIıİiÖöŞşÜüß0-9!#$%&'*+\/=?.^_`{|}~-]+?@(?:[a-zа-яёÇçĞğIıİiÖöŞşÜüß0-9](?:[a-zа-яёÇçĞğIıİiÖöŞşÜüß0-9-_]*?[a-zа-яёÇçĞğIıİiÖöŞşÜüß0-9])?\.)+?(?:xn--[-a-z0-9]+|[a-zа-яё]{2,}|\d{1,3})(?:$|\s+)/i;
12+
var REG_CHECK_EMAIL_START = /^[a-zа-яёÇçĞğIıİiÖöŞşÜüß0-9!#$%&'*+\/=?.^_`{|}~-]+?@(?:[a-zа-яёÇçĞğIıİiÖöŞşÜüß0-9](?:[a-zа-яёÇçĞğIıİiÖöŞşÜüß0-9-_]*?[a-zа-яёÇçĞğIıİiÖöŞşÜüß0-9])?\.)+?(?:xn--[-a-z0-9]+|[a-zа-яё]{2,}|\d{1,3})/i;
1113
var REG_BREAK_STRING = /(?:^|\s)\S+$/;
1214

1315
CKEDITOR.plugins.add('autolink2', {
@@ -105,13 +107,24 @@
105107

106108
} while (charCode !== 160 && charCode !== 32);
107109

108-
if (!REG_CHECK_LINK.test(rangeNative.toString().replace(REG_REPLACE_EMPTY_CHAR, ''))) {
110+
var rangeString = rangeNative.toString().replace(REG_REPLACE_EMPTY_CHAR, '');
111+
var isLink = REG_CHECK_LINK.test(rangeString);
112+
var isEmail = REG_CHECK_EMAIL.test(rangeString);
113+
114+
if (!isLink && !isEmail) {
109115
return;
110116
}
111117

112-
var rangeString;
113118
var next;
114-
while ((rangeString = rangeNative.toString()) && !REG_CHECK_LINK_START.test(rangeString)) {
119+
while ((rangeString = rangeNative.toString())) {
120+
if (isLink && REG_CHECK_LINK_START.test(rangeString)) {
121+
break;
122+
}
123+
124+
if (isEmail && REG_CHECK_EMAIL_START.test(rangeString)) {
125+
break;
126+
}
127+
115128
try {
116129
rangeNative.setStart(rangeNative.startContainer, rangeNative.startOffset + 1);
117130

@@ -163,7 +176,12 @@
163176
href = CKEDITOR.tools.htmlDecodeAttr(href);
164177

165178
if (!REG_PROTO_HTTP.test(href)) {
166-
href = 'http://' + href;
179+
if (REG_EMAIL.test(href)) {
180+
href = 'mailto:' + href;
181+
182+
} else {
183+
href = 'http://' + href;
184+
}
167185
}
168186

169187
var style = new CKEDITOR.style({

samples/index.html

+28-10
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ <h2 class="project-tagline">CKEditor dragable image resizing with support divare
2121
</section>
2222

2323
<section class="main-content">
24-
<h2>DIV</h2>
25-
<textarea id="editor1"></textarea>
26-
<h2>IFRAME</h2>
27-
<textarea id="editor2"></textarea>
24+
<h2>DIV</h2>
25+
<textarea id="editor1"></textarea>
26+
<h2>IFRAME</h2>
27+
<textarea id="editor2"></textarea>
2828

29-
<footer class="site-footer">
30-
<span class="site-footer-owner"><a href="https://github.com/Katochimoto/ckeditor-autolink2">Ckeditor-autolink2</a> is maintained by <a href="https://github.com/Katochimoto">Katochimoto</a>.</span>
29+
<footer class="site-footer">
30+
<span class="site-footer-owner"><a href="https://github.com/Katochimoto/ckeditor-autolink2">Ckeditor-autolink2</a> is maintained by <a href="https://github.com/Katochimoto">Katochimoto</a>.</span>
3131

32-
<span class="site-footer-credits">This page was generated by <a href="https://pages.github.com">GitHub Pages</a> using the <a href="https://github.com/jasonlong/cayman-theme">Cayman theme</a> by <a href="https://twitter.com/jasonlong">Jason Long</a>.</span>
33-
</footer>
32+
<span class="site-footer-credits">This page was generated by <a href="https://pages.github.com">GitHub Pages</a> using the <a href="https://github.com/jasonlong/cayman-theme">Cayman theme</a> by <a href="https://twitter.com/jasonlong">Jason Long</a>.</span>
33+
</footer>
3434

3535
</section>
3636

@@ -46,7 +46,16 @@ <h2>IFRAME</h2>
4646
],
4747
on: {
4848
instanceReady: function() {
49-
this.setData('');
49+
this.setData(
50+
'<div>[email protected]</div>' +
51+
'<div>mailto:[email protected]</div>' +
52+
'<div>www.somedomain.com</div>' +
53+
'<div>http://somedomain.com</div>' +
54+
'<div>https://somedomain.com</div>' +
55+
'<div>ftp://somedomain.com</div>' +
56+
'<div>file:/somefile</div>' +
57+
'<div>mailto:[email protected]</div>'
58+
);
5059
}
5160
}
5261
});
@@ -62,7 +71,16 @@ <h2>IFRAME</h2>
6271
],
6372
on: {
6473
instanceReady: function() {
65-
this.setData('');
74+
this.setData(
75+
'<div>[email protected]</div>' +
76+
'<div>mailto:[email protected]</div>' +
77+
'<div>www.somedomain.com</div>' +
78+
'<div>http://somedomain.com</div>' +
79+
'<div>https://somedomain.com</div>' +
80+
'<div>ftp://somedomain.com</div>' +
81+
'<div>file:/somefile</div>' +
82+
'<div>mailto:[email protected]</div>'
83+
);
6684
}
6785
}
6886
});

0 commit comments

Comments
 (0)