diff --git a/src/content.js b/src/content.js index c75f6354..3df7799e 100644 --- a/src/content.js +++ b/src/content.js @@ -186,6 +186,19 @@ var content = (function() { } }, + getParentsAndSelf: function(node, tagName) { + var parents = []; + while (node) { + if (node.nodeType === nodeType.elementNode) { + if (!tagName || node.nodeName === tagName.toUpperCase()) { + parents.push(node); + } + } + node = node.parentNode; + } + return parents; + }, + /** * Get all tags that start or end inside the range */ diff --git a/src/selection.js b/src/selection.js index 4616c1c7..078b73fa 100644 --- a/src/selection.js +++ b/src/selection.js @@ -70,6 +70,16 @@ var Selection = (function() { return coords; }, + /** + * Check if a link can be added. + * If the editableHost or a parent is a link element linking + * should not be possible. + */ + canLinkBeSet: function() { + var linkParents = content.getParentsAndSelf(this.host, 'a'); + return linkParents.length ? false : true; + }, + /** * * @method link