Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
open-source
hacklab-blocks
Commits
bc1ba175
Commit
bc1ba175
authored
3 years ago
by
Matheus Gimenez
Browse files
Options
Download
Email Patches
Plain Diff
featured slider
parent
e61e19fc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
27 deletions
+40
-27
blocks/featured-slider/front.js
blocks/featured-slider/front.js
+22
-24
blocks/featured-slider/index.js
blocks/featured-slider/index.js
+18
-3
No files found.
blocks/featured-slider/front.js
View file @
bc1ba175
...
...
@@ -8,32 +8,30 @@ let i = 1;
document
.
querySelectorAll
(
'
.featured-slider .itens-wrapper
'
).
forEach
(
(
element
)
=>
{
let
width
=
element
.
clientWidth
;
sliders
[
i
]
=
tns
({
container
:
element
,
items
:
1
,
nav
:
false
,
controlsText
:
[
'
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" width="1em" height="1em" style="-ms-transform: rotate(360deg); -webkit-transform: rotate(360deg); transform: rotate(360deg);" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path fill="none" stroke="#626262" stroke-width="2" d="M15 6l-6 6l6 6"/></svg>
'
,
'
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" width="1em" height="1em" style="-ms-transform: rotate(360deg); -webkit-transform: rotate(360deg); transform: rotate(360deg);" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path fill="none" stroke="#626262" stroke-width="2" d="M9 6l6 6l-6 6"/></svg>
'
],
slideBy
:
'
page
'
,
mouseDrag
:
true
,
fixedWidth
:
element
.
clientWidth
// gutter: 10,
// responsive: {
// "350": {
// "items": 1,
// "controls": true,
// },
// "900": {
// "items": 4
// }
// },
});
console
.
log
(
element
.
childElementCount
)
document
.
head
.
insertAdjacentHTML
(
'
beforeend
'
,
`<style>
#tns
${
i
}
> .tns-item {
width:
${
width
}
px !important;
}
#tns
${
i
}
> .tns-item {
width:
${
width
}
px !important;
}
</style>`
);
if
(
element
.
childElementCount
>=
2
)
{
sliders
[
i
]
=
tns
({
container
:
element
,
items
:
1
,
nav
:
true
,
navPosition
:
'
bottom
'
,
controlsText
:
[
'
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" width="1em" height="1em" style="-ms-transform: rotate(360deg); -webkit-transform: rotate(360deg); transform: rotate(360deg);" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path fill="none" stroke="#626262" stroke-width="2" d="M15 6l-6 6l6 6"/></svg>
'
,
'
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" width="1em" height="1em" style="-ms-transform: rotate(360deg); -webkit-transform: rotate(360deg); transform: rotate(360deg);" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path fill="none" stroke="#626262" stroke-width="2" d="M9 6l6 6l-6 6"/></svg>
'
],
slideBy
:
'
page
'
,
mouseDrag
:
true
,
fixedWidth
:
element
.
clientWidth
,
mode
:
'
gallery
'
,
animateDelay
:
800
,
speed
:
800
,
});
}
i
++
;
})
\ No newline at end of file
This diff is collapsed.
Click to expand it.
blocks/featured-slider/index.js
View file @
bc1ba175
...
...
@@ -166,7 +166,13 @@ const ImageGallery = ({ images, imagesTitle, imagesDescriptions, imagesButtons,
<
/div
>
);
};
const
sliderNumberZero
=
(
number
)
=>
{
if
(
number
<
10
)
{
return
'
0
'
+
number
;
}
return
number
;
}
wp
.
blocks
.
registerBlockType
(
'
hacklab-blocks/featured-slider
'
,
{
title
:
__
(
'
Featured Slider
'
,
'
jeo
'
),
icon
:
'
format-gallery
'
,
...
...
@@ -255,6 +261,7 @@ wp.blocks.registerBlockType('hacklab-blocks/featured-slider', {
const
{
images
=
[],
imagesDescriptions
=
[],
imagesTitle
=
[],
imagesButtons
=
[]
}
=
attributes
;
const
displayImages
=
(
images
)
=>
{
let
imagesMax
=
images
.
length
;
return
(
images
.
map
((
image
,
index
)
=>
{
...
...
@@ -272,11 +279,19 @@ wp.blocks.registerBlockType('hacklab-blocks/featured-slider', {
<
div
className
=
"
wrapper
"
>
<
div
className
=
"
wrapper-content
"
>
<
div
class
=
"
image-meta
"
>
<
div
class
=
"
image-title
"
>
<
RichText
.
Content
tagName
=
"
span
"
value
=
{
imagesTitle
[
index
]}
/></
div
>
<
div
class
=
"
image-description
"
>
<
RichText
.
Content
tagName
=
"
span
"
value
=
{
imagesDescriptions
[
index
]}
/></
div
>
<
div
class
=
"
image-button
"
>
<
RichText
.
Content
tagName
=
"
span
"
value
=
{
imagesButtons
[
index
]}
/></
div
>
<
div
class
Name
=
"
image-title
"
>
<
RichText
.
Content
tagName
=
"
span
"
value
=
{
imagesTitle
[
index
]}
/></
div
>
<
div
class
Name
=
"
image-description
"
>
<
RichText
.
Content
tagName
=
"
span
"
value
=
{
imagesDescriptions
[
index
]}
/></
div
>
<
div
class
Name
=
"
image-button
"
>
<
RichText
.
Content
tagName
=
"
span
"
value
=
{
imagesButtons
[
index
]}
/></
div
>
<
/div
>
<
/div
>
<
div
className
=
"
slider-index
"
>
<
span
className
=
"
current
"
>
{
sliderNumberZero
(
index
+
1
)}
<
/span
>
<
span
className
=
"
max
"
>
{
sliderNumberZero
(
imagesMax
)}
<
/span
>
<
/div
>
<
/div
>
<
/div
>
<
/div
>
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment