Skip to content

Commit

Permalink
Remove data-link-target attribute on anchor
Browse files Browse the repository at this point in the history
Remove unnecessary data-link-target - attribute. It is not necessary anymore and can be removed. Also the support for different kinds of targets was added like _top, _self, etc. Also remove a lot of unnecessary transformation and store target with the default HTML syntax.
  • Loading branch information
sascha-karnatz committed Apr 2, 2024
1 parent 92b3d9c commit 4dc39a2
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tinymce.PluginManager.add("alchemy_link", function (editor) {
link = {
url: anchor.href,
title: anchor.title,
target: anchor.getAttribute("data-link-target"),
target: anchor.target,
type: anchor.className
}
}
Expand All @@ -23,8 +23,7 @@ tinymce.PluginManager.add("alchemy_link", function (editor) {
href: link.url,
class: link.type,
title: link.title,
"data-link-target": link.target,
target: link.target === "blank" ? "_blank" : undefined
target: link.target
})
editor.selection.collapse()
})
Expand Down
8 changes: 1 addition & 7 deletions app/components/alchemy/ingredients/link_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ def initialize(ingredient, text: nil, html_options: {})
end

def call
link_to(link_text, value, {target: link_target}.merge(html_options)).html_safe
end

private

def link_target
(ingredient.link_target == "blank") ? "_blank" : nil
link_to(link_text, value, {target: ingredient.link_target.presence}.merge(html_options)).html_safe
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions app/components/alchemy/ingredients/text_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def call
link_to(value, url_for(link), {
id: dom_id.presence,
title: link_title,
target: ((link_target == "blank") ? "_blank" : nil),
data: {link_target: link_target}
target: link_target
}.merge(html_options))
end.html_safe
end
Expand Down
4 changes: 3 additions & 1 deletion app/models/alchemy/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,10 @@ def link_target_options
options = [[Alchemy.t(:default, scope: "link_target_options"), ""]]
link_target_options = Config.get(:link_target_options)
link_target_options.each do |option|
# add an underscore to the options to provide the default syntax
# @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#target
options << [Alchemy.t(option, scope: "link_target_options",
default: option.to_s.humanize), option]
default: option.to_s.humanize), "_#{option}"]
end
options
end
Expand Down
2 changes: 1 addition & 1 deletion spec/support/tab_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module Alchemy
end

context "with content"
let(:link_target) { "blank" }
let(:link_target) { "_blank" }

it "should have a pre-filled value" do
expect(page.find(:css, "select[name=#{name}_link_target]").value).to eq(link_target)
Expand Down
6 changes: 3 additions & 3 deletions spec/views/alchemy/ingredients/text_view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@
data: {
link: "http://google.com",
link_title: "Foo",
link_target: "blank"
link_target: "_blank"
}
)
end

it "renders the linked value" do
render ingredient
expect(rendered).to have_content("Hello World")
expect(rendered).to have_selector('a[title="Foo"][target="_blank"][data-link-target="blank"][href="http://google.com"]')
expect(rendered).to have_selector('a[title="Foo"][target="_blank"][href="http://google.com"]')
end

context "with html_options given" do
it "renders the linked with these options" do
render ingredient, html_options: {title: "Bar", class: "blue"}
expect(rendered).to have_selector('a.blue[title="Bar"][target="_blank"][data-link-target="blank"]')
expect(rendered).to have_selector('a.blue[title="Bar"][target="_blank"]')
end
end

Expand Down

0 comments on commit 4dc39a2

Please sign in to comment.