Class: Foliokit::Overlay::OverlayHyperlink
Instance Attribute Summary
Attributes inherited from OverlayBase
#section_index, #state
Instance Method Summary
collapse
Methods inherited from OverlayBase
element_base, #initialize, #stateful?
#initialize
Instance Method Details
#export(document, options = {}) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/foliokit/overlay/overlay_hyperlink.rb', line 15
def export(document, options = {})
node = super(document, options)
href = parse_url(node)
return nil unless href
node["href"] = href
node["confirm"] = req_nav_confirm
node["external"] = !open_in_app
node["swipable"] = true
node["touchable"] = true
if source.present?
img = Nokogiri::XML::Node.new("img", document)
package.apply_asset(img, "src", source)
img["class"] = "source"
node << img
end
if active_source.present?
img = Nokogiri::XML::Node.new("img", document)
package.apply_asset(img, "src", active_source)
img["class"] = "active-source"
node << img
end
node
end
|
#parse_url(node) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/foliokit/overlay/overlay_hyperlink.rb', line 43
def parse_url(node)
return url if url =~ %r{^goto://}
if url =~ %r{^http://.+} || url =~ %r{^https://.+}
uri = Addressable::URI.parse(url)
if open_in_app
params = URI.decode_www_form(uri.normalized_query || "").to_h
params["referrer"] = "Baker"
uri.query = URI.encode_www_form(params)
return uri.to_s
else
node["target"] = "_blank"
return url
end
elsif url =~ /^mailto:/
return url
end
if (matches = url.match(%r{^navto://relative/current#([0-9.]+)?}))
page_index = matches[1].to_i
return "#/#{page_index}/0"
elsif (matches = url.match(%r{^navto://tmp#?([0-9.]+)?}))
page_index = matches[1].to_i
return "#/#{page_index}/0"
elsif (matches = url.match(%r{^navto://([^#]+)#?([0-9.]+)?}))
page_id = matches[1]
page_index = @package.root_package.manifest.content_stack_ids.index(page_id)
return false if page_index.nil?
section_index = matches[2].to_i || 0
current_page_index = @package.root_package.manifest.content_stack_ids.index(@package.id)
current_section_index = @section_index
return false if page_index == current_page_index and section_index == current_section_index
return "#/#{page_index}/#{section_index}"
end
false
end
|
#tagname ⇒ Object
11
12
13
|
# File 'lib/foliokit/overlay/overlay_hyperlink.rb', line 11
def tagname
"a"
end
|