Class: Emjay::Components::MjCarouselImage
Instance Attribute Summary
#attributes, #context, #props
Class Method Summary
collapse
Instance Method Summary
collapse
#get_box_widths, #get_child_context, #get_shorthand_attr_value, #get_shorthand_border_value, #html_attributes, #render_children, #styles
#get_attribute, #get_child_context, #get_content, #initialize, raw_element?
Class Method Details
.allowed_attributes ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/emjay/components/body/mj_carousel_image.rb', line 24
def self.allowed_attributes
{
"alt" => "string",
"href" => "string",
"rel" => "string",
"target" => "string",
"title" => "string",
"src" => "string",
"thumbnails-src" => "string",
"border-radius" => "string",
"tb-border" => "string",
"tb-border-radius" => "string"
}
end
|
.component_name ⇒ Object
9
10
11
|
# File 'lib/emjay/components/body/mj_carousel_image.rb', line 9
def self.component_name
"mj-carousel-image"
end
|
.default_attributes ⇒ Object
17
18
19
20
21
22
|
# File 'lib/emjay/components/body/mj_carousel_image.rb', line 17
def self.default_attributes
{
"alt" => "",
"target" => "_blank"
}
end
|
.ending_tag? ⇒ Boolean
13
14
15
|
# File 'lib/emjay/components/body/mj_carousel_image.rb', line 13
def self.ending_tag?
true
end
|
Instance Method Details
#get_styles ⇒ Object
39
40
41
42
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
|
# File 'lib/emjay/components/body/mj_carousel_image.rb', line 39
def get_styles
has_thumbnails_supported = thumbnails_supported?
{
images: {
img: {
"border-radius" => get_attribute("border-radius"),
"display" => "block",
"width" => @context[:container_width],
"max-width" => "100%",
"height" => "auto"
},
firstImageDiv: {},
otherImageDiv: {
"display" => "none",
"mso-hide" => "all"
}
},
radio: {
input: {
"display" => "none",
"mso-hide" => "all"
}
},
thumbnails: {
a: {
"border" => get_attribute("tb-border"),
"border-radius" => get_attribute("tb-border-radius"),
"display" => has_thumbnails_supported ? "none" : "inline-block",
"overflow" => "hidden",
"width" => get_attribute("tb-width")
},
img: {
"display" => "block",
"width" => "100%",
"height" => "auto"
}
}
}
end
|
#render ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/emjay/components/body/mj_carousel_image.rb', line 79
def render
src = get_attribute("src")
alt = get_attribute("alt")
href = get_attribute("href")
rel = get_attribute("rel")
title = get_attribute("title")
index = @props[:index] || 0
img_attrs = html_attributes(
title: title,
src: src,
alt: alt,
style: "images.img",
width: @context[:container_width].to_i,
border: "0"
)
image = "<img\n #{img_attrs} />"
css_class = get_attribute("css-class") || ""
div_style = (index == 0) ? "images.firstImageDiv" : "images.otherImageDiv"
div_attrs = html_attributes(
class: "mj-carousel-image mj-carousel-image-#{index + 1} #{css_class}",
style: div_style
)
content = href ? "<a#{html_attributes(href: href, rel: rel, target: "_blank")}>#{image}</a>" : image
<<~HTML
<div
#{div_attrs}
>
#{content}
</div>
HTML
end
|
#render_radio ⇒ Object
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/emjay/components/body/mj_carousel_image.rb', line 115
def render_radio
index = @props[:index] || 0
carousel_id = get_attribute("carouselId")
input_attrs = html_attributes(
class: "mj-carousel-radio mj-carousel-#{carousel_id}-radio mj-carousel-#{carousel_id}-radio-#{index + 1}",
checked: (index == 0) ? "checked" : nil,
type: "radio",
name: "mj-carousel-radio-#{carousel_id}",
id: "mj-carousel-#{carousel_id}-radio-#{index + 1}",
style: "radio.input"
)
<<~HTML
<input
#{input_attrs}
/>
HTML
end
|
#render_thumbnail ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/emjay/components/body/mj_carousel_image.rb', line 135
def render_thumbnail
carousel_id = get_attribute("carouselId")
src = get_attribute("src")
alt = get_attribute("alt")
width = get_attribute("tb-width")
target = get_attribute("target")
index = @props[:index] || 0
img_index = index + 1
css_class = SuffixCssClasses.call(get_attribute("css-class"), "thumbnail")
a_attrs = html_attributes(
style: "thumbnails.a",
href: "##{img_index}",
target: target,
class: "mj-carousel-thumbnail mj-carousel-#{carousel_id}-thumbnail mj-carousel-#{carousel_id}-thumbnail-#{img_index} #{css_class}"
)
label_attrs = html_attributes(
for: "mj-carousel-#{carousel_id}-radio-#{img_index}"
)
img_attrs = html_attributes(
style: "thumbnails.img",
src: get_attribute("thumbnails-src") || src,
alt: alt,
width: width.to_i
)
<<~HTML
<a
#{a_attrs}
>
<label#{label_attrs}>
<img
#{img_attrs}
/>
</label>
</a>
HTML
end
|