Skip to content

Commit d3fcb4d

Browse files
committed
fix: fixes issue where class is lost when update a link
1 parent a90b8f6 commit d3fcb4d

File tree

7 files changed

+59
-18
lines changed

7 files changed

+59
-18
lines changed

build/content-tools.js

Lines changed: 27 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/content-tools.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/content-tools.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ContentTools",
33
"description": "A JS library for building WYSIWYG editors for HTML content",
4-
"version": "1.6.12",
4+
"version": "1.6.13",
55
"keywords": [
66
"wysiwyg",
77
"inline",

sandbox/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ <h1 data-fixture data-name="article-title">
5555
</p>
5656

5757
<p>
58-
The names we devise for folders, files, variables,
58+
The <a href="#test" class="foo" target="_blank">names</a> we devise for folders, files, variables,
5959
functions, classes and any other user definable construct
6060
will (for the most part) determine how easily someone else
6161
can read and understand what we have written.

src/scripts/editor.coffee

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ class _EditorApp extends ContentTools.ComponentUI
402402
content = new HTMLString.String(wrapper.innerHTML)
403403

404404
else
405-
console.log wrapper.textContent
406405
content = new HTMLString.String(
407406
HTMLString.String.encode(wrapper.textContent)
408407
)

src/scripts/tools.coffee

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,6 @@ class ContentTools.Tools.Link extends ContentTools.Tools.Bold
358358
if detail.href
359359
element.a = {href: detail.href}
360360

361-
if element.a
362-
element.a.class = element.a['class']
363-
364361
if detail.target
365362
element.a.target = detail.target
366363

@@ -390,12 +387,36 @@ class ContentTools.Tools.Link extends ContentTools.Tools.Bold
390387
else
391388
# Text elements
392389

390+
# Attempt to find any existing tag
391+
firstATag = null
392+
for i in [from...to]
393+
for tag in element.content.characters[i].tags()
394+
if tag.name() == 'a'
395+
firstATag = tag
396+
break
397+
398+
if firstATag
399+
break
400+
393401
# Clear any existing link
394402
element.content = element.content.unformat(from, to, 'a')
395403

396404
# If specified add the new link
397405
if detail.href
398-
a = new HTMLString.Tag('a', detail)
406+
407+
if firstATag
408+
a = firstATag.copy()
409+
else
410+
a = new HTMLString.Tag('a')
411+
412+
a.attr('href', detail.href)
413+
if detail.target
414+
a.attr('target', detail.target)
415+
else
416+
a.removeAttr('target')
417+
418+
console.log(a)
419+
399420
element.content = element.content.format(from, to, a)
400421
element.content.optimize()
401422

@@ -1439,4 +1460,4 @@ class ContentTools.Tools.Remove extends ContentTools.Tool
14391460
callback(true)
14401461

14411462
# Dispatch `applied` event
1442-
@dispatchEditorEvent('tool-applied', toolDetail)
1463+
@dispatchEditorEvent('tool-applied', toolDetail)

0 commit comments

Comments
 (0)