Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE REQUEST: addLink event handling #391

Open
MasahiroMorita opened this issue Sep 2, 2020 · 0 comments
Open

FEATURE REQUEST: addLink event handling #391

MasahiroMorita opened this issue Sep 2, 2020 · 0 comments

Comments

@MasahiroMorita
Copy link

I want to add addLink event to detect that a URL has been inserted.
Here is a patch for you.

--- a/source/Editor.js
+++ b/source/Editor.js
@@ -1793,7 +1793,7 @@ var addLinks = function ( frag, root, self ) {
     });
     var linkRegExp = self.linkRegExp;
     var defaultAttributes = self._config.tagAttributes.a;
-    var node, data, parent, match, index, endIndex, child;
+    var node, data, parent, match, index, endIndex, child, href;
     if ( !linkRegExp ) {
         return;
     }
@@ -1807,16 +1807,18 @@ var addLinks = function ( frag, root, self ) {
                 child = doc.createTextNode( data.slice( 0, index ) );
                 parent.insertBefore( child, node );
             }
-            child = self.createElement( 'A', mergeObjects({
-                href: match[1] ?
+            href = match[1] ?
                     /^(?:ht|f)tps?:/i.test( match[1] ) ?
                         match[1] :
                         'http://' + match[1] :
-                    'mailto:' + match[0]
+                    'mailto:' + match[0];
+            child = self.createElement( 'A', mergeObjects({
+                href: href
             }, defaultAttributes, false ));
             child.textContent = data.slice( index, endIndex );
             parent.insertBefore( child, node );
             node.data = data = data.slice( endIndex );
+            self.fireEvent('addLink', { link: href });
         }
     }
 };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant