Skip to content

Commit

Permalink
fix: fixes issue where class is lost when update a link
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyjb committed Jul 11, 2021
1 parent a90b8f6 commit d3fcb4d
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 18 deletions.
33 changes: 27 additions & 6 deletions build/content-tools.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/content-tools.min.css

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions build/content-tools.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ContentTools",
"description": "A JS library for building WYSIWYG editors for HTML content",
"version": "1.6.12",
"version": "1.6.13",
"keywords": [
"wysiwyg",
"inline",
Expand Down
2 changes: 1 addition & 1 deletion sandbox/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h1 data-fixture data-name="article-title">
</p>

<p>
The names we devise for folders, files, variables,
The <a href="#test" class="foo" target="_blank">names</a> we devise for folders, files, variables,
functions, classes and any other user definable construct
will (for the most part) determine how easily someone else
can read and understand what we have written.
Expand Down
1 change: 0 additions & 1 deletion src/scripts/editor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ class _EditorApp extends ContentTools.ComponentUI
content = new HTMLString.String(wrapper.innerHTML)

else
console.log wrapper.textContent
content = new HTMLString.String(
HTMLString.String.encode(wrapper.textContent)
)
Expand Down
31 changes: 26 additions & 5 deletions src/scripts/tools.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,6 @@ class ContentTools.Tools.Link extends ContentTools.Tools.Bold
if detail.href
element.a = {href: detail.href}

if element.a
element.a.class = element.a['class']

if detail.target
element.a.target = detail.target

Expand Down Expand Up @@ -390,12 +387,36 @@ class ContentTools.Tools.Link extends ContentTools.Tools.Bold
else
# Text elements

# Attempt to find any existing tag
firstATag = null
for i in [from...to]
for tag in element.content.characters[i].tags()
if tag.name() == 'a'
firstATag = tag
break

if firstATag
break

# Clear any existing link
element.content = element.content.unformat(from, to, 'a')

# If specified add the new link
if detail.href
a = new HTMLString.Tag('a', detail)

if firstATag
a = firstATag.copy()
else
a = new HTMLString.Tag('a')

a.attr('href', detail.href)
if detail.target
a.attr('target', detail.target)
else
a.removeAttr('target')

console.log(a)

element.content = element.content.format(from, to, a)
element.content.optimize()

Expand Down Expand Up @@ -1439,4 +1460,4 @@ class ContentTools.Tools.Remove extends ContentTools.Tool
callback(true)

# Dispatch `applied` event
@dispatchEditorEvent('tool-applied', toolDetail)
@dispatchEditorEvent('tool-applied', toolDetail)

0 comments on commit d3fcb4d

Please sign in to comment.