Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uw_wcms_ohana
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WCMS
uw_wcms_ohana
Commits
81353715
Commit
81353715
authored
1 month ago
by
Martin Leblanc
Committed by
Kevin Paxman
5 days ago
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-5650: Add window the scope of the Flickity carousel in banners.js
parent
27bbbb76
No related branches found
No related tags found
1 merge request
!273
Feature/istwcms 5650 m26lebla owl carousel replacement
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/patterns/04-components/banners/banners.js
+16
-13
16 additions, 13 deletions
src/patterns/04-components/banners/banners.js
with
16 additions
and
13 deletions
src/patterns/04-components/banners/banners.js
+
16
−
13
View file @
81353715
...
...
@@ -4,13 +4,12 @@
* Ensures autoplay, navigation, and pause/play functionality.
*/
(
function
(
$
,
Drupal
,
Flickity
)
{
(
function
(
$
,
Drupal
,
window
)
{
'
use strict
'
;
Drupal
.
behaviors
.
bannersFlickity
=
{
attach
:
function
()
{
$
(
document
).
ready
(
function
()
{
document
.
querySelectorAll
(
'
.uw-carousel__banner
'
).
forEach
(
function
(
banner
)
{
var
selector
=
'
div[data-uuid="
'
+
banner
.
getAttribute
(
'
data-uuid
'
)
+
'
"] .carousel
'
;
var
elem
=
document
.
querySelector
(
selector
);
...
...
@@ -20,7 +19,8 @@
// Get the slide speed and autoplay settings.
var
bannerSlideSpeed
=
parseInt
(
banner
.
getAttribute
(
'
data-slide-speed
'
),
10
)
||
3000
;
var
bannerAutoplay
=
banner
.
getAttribute
(
'
data-autoplay
'
)
!==
'
0
'
&&
!
document
.
querySelector
(
'
.layout-builder
'
);
var
bannerAutoplay
=
banner
.
getAttribute
(
'
data-autoplay
'
)
!==
'
0
'
&&
!
document
.
querySelector
(
'
.layout-builder
'
);
// Add a class if there's only one slide.
if
(
elem
.
children
.
length
<=
1
)
{
...
...
@@ -31,48 +31,51 @@
var
bannerDots
=
elem
.
children
.
length
>
1
;
// Ensure Flickity is defined before initializing.
if
(
typeof
Flickity
===
'
undefined
'
)
{
if
(
typeof
window
.
Flickity
===
'
undefined
'
)
{
console
.
error
(
'
Flickity is not defined. Ensure the library is loaded.
'
);
return
;
}
var
flkty
=
new
Flickity
(
elem
,
{
var
flkty
=
new
window
.
Flickity
(
elem
,
{
autoPlay
:
bannerAutoplay
?
bannerSlideSpeed
:
false
,
draggable
:
true
,
fade
:
true
,
cellSelector
:
'
.card__banner
'
,
pageDots
:
bannerDots
,
on
:
{
ready
:
function
(){
ready
:
function
()
{
var
dots
=
document
.
querySelectorAll
(
'
.flickity-page-dots .dot
'
);
if
(
!
dots
.
length
)
{
return
;
}
dots
.
forEach
(
function
(
dot
){
// Make dots focusable
dots
.
forEach
(
function
(
dot
)
{
// Make dots focusable
.
dot
.
setAttribute
(
'
tabindex
'
,
'
0
'
);
dot
.
addEventListener
(
'
keydown
'
,
function
(
event
){
dot
.
addEventListener
(
'
keydown
'
,
function
(
event
)
{
if
(
event
.
key
===
'
Enter
'
||
event
.
keyCode
===
13
)
{
var
label
=
dot
.
getAttribute
(
'
aria-label
'
);
// Get "Page dot # // Extract the number"
// Extract the number from "Page dot #".
var
match
=
label
.
match
(
/
\d
+/
);
if
(
!
match
)
{
return
;
}
// Convert to zero-based index
// Convert to zero-based index
.
var
targetIndex
=
parseInt
(
match
[
0
],
10
)
-
1
;
flkty
.
select
(
targetIndex
);
// Move to the slide
// Move to the slide.
flkty
.
select
(
targetIndex
);
}
});
});
}
}
});
// Get play and pause buttons.
var
bannerPlay
=
banner
.
querySelector
(
'
.uw-play
'
);
var
bannerPause
=
banner
.
querySelector
(
'
.uw-pause
'
);
...
...
@@ -108,4 +111,4 @@
});
}
};
})(
jQuery
,
Drupal
,
Flickity
);
})(
jQuery
,
Drupal
,
window
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment