Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
heinvv committed Dec 20, 2024
1 parent 55ed840 commit ca429a5
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 5 deletions.
4 changes: 2 additions & 2 deletions assets/dev/js/frontend/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import YouTubeApiLoader from './utils/video-api/youtube-loader';
import VimeoApiLoader from './utils/video-api/vimeo-loader';
import BaseVideoLoader from './utils/video-api/base-loader';
import URLActions from './utils/url-actions';
import Swiper from './utils/swiper';
import SwiperHandler from './utils/swiper';
import LightboxManager from './utils/lightbox/lightbox-manager';
import AssetsLoader from './utils/assets-loader';
import Breakpoints from 'elementor-utils/breakpoints';
Expand Down Expand Up @@ -196,7 +196,7 @@ export default class Frontend extends elementorModules.ViewModule {
return LightboxManager.getLightbox();
},
urlActions: new URLActions(),
swiper: Swiper,
swiper: SwiperHandler,
environment,
assetsLoader: new AssetsLoader(),
escapeHTML,
Expand Down
1 change: 1 addition & 0 deletions assets/dev/js/frontend/utils/assets-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ AssetsLoader.assets = {
'share-link': {
src: `${ assetsUrl }lib/share-link/share-link${ fileSuffix }.js?ver=${ pluginVersion }`,
},
// TODO: Remove 'swiper' in v3.29.0 [ED-16272].
swiper: {
src: `${ assetsUrl }lib/swiper/v8/swiper${ fileSuffix }.js?ver=8.4.5`,
},
Expand Down
17 changes: 14 additions & 3 deletions assets/dev/js/frontend/utils/swiper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default class Swiper {
export default class SwiperHandler {
constructor( container, config ) {
this.config = config;

Expand All @@ -17,8 +17,19 @@ export default class Swiper {
container.closest( '.elementor-widget' )?.classList.add( 'e-widget-swiper' );

return new Promise( ( resolve ) => {
elementorFrontend.utils.assetsLoader.load( 'script', 'swiper' )
.then( () => resolve( this.createSwiperInstance( container, this.config ) ) );
// TODO: Remove in v3.29.0 [ED-16272].
if ( 'undefined' === typeof Swiper ) {
elementorFrontend.utils.assetsLoader.load( 'script', 'swiper' )
.then( () => resolve( this.createSwiperInstance( container, this.config ) ) );

return;
}

if ( 'function' === typeof Swiper && 'undefined' === typeof window.Swiper ) {
window.Swiper = Swiper;
}

resolve( this.createSwiperInstance( container, this.config ) );
} );
}

Expand Down
37 changes: 37 additions & 0 deletions includes/elements/column.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,43 @@ protected function register_controls() {
]
);

$this->add_control(
'handle_slideshow_asset_loading',
[
'type' => Controls_Manager::HIDDEN,
'assets' => [
'styles' => [
[
'name' => 'e-swiper',
'conditions' => [
'terms' => [
[
'name' => 'background_background',
'operator' => '===',
'value' => 'slideshow',
],
],
],
],
],
'scripts' => [
[
'name' => 'swiper',
'conditions' => [
'terms' => [
[
'name' => 'background_background',
'operator' => '===',
'value' => 'slideshow',
],
],
],
],
],
],
]
);

$this->end_controls_tab();

$this->start_controls_tab(
Expand Down
14 changes: 14 additions & 0 deletions includes/elements/container.php
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,20 @@ protected function register_background_controls() {
],
],
],
'scripts' => [
[
'name' => 'swiper',
'conditions' => [
'terms' => [
[
'name' => 'background_background',
'operator' => '===',
'value' => 'slideshow',
],
],
],
],
],
],
]
);
Expand Down
14 changes: 14 additions & 0 deletions includes/elements/section.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,20 @@ protected function register_controls() {
],
],
],
'scripts' => [
[
'name' => 'swiper',
'conditions' => [
'terms' => [
[
'name' => 'background_background',
'operator' => '===',
'value' => 'slideshow',
],
],
],
],
],
],
]
);
Expand Down
14 changes: 14 additions & 0 deletions includes/widgets/image-carousel.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ public function get_style_depends(): array {
return [ 'e-swiper', 'widget-image-carousel' ];
}

/**
* Get script dependencies.
*
* Retrieve the list of script dependencies the widget requires.
*
* @since 3.24.0
* @access public
*
* @return array Widget script dependencies.
*/
public function get_script_depends(): array {
return [ 'swiper' ];
}

public function has_widget_inner_wrapper(): bool {
return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
}
Expand Down
19 changes: 19 additions & 0 deletions includes/widgets/image-gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,25 @@ protected function register_controls() {
],
],
],
'scripts' => [
[
'name' => 'swiper',
'conditions' => [
'terms' => [
[
'name' => 'gallery_link',
'operator' => '===',
'value' => 'file',
],
[
'name' => 'open_lightbox',
'operator' => '!==',
'value' => 'no',
],
],
],
],
],
],
]
);
Expand Down
14 changes: 14 additions & 0 deletions includes/widgets/wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ public function get_style_depends(): array {
return [ 'e-swiper' ];
}

/**
* Get script dependencies.
*
* Retrieve the list of script dependencies the widget requires.
*
* @since 3.24.0
* @access public
*
* @return array Widget script dependencies.
*/
public function get_script_depends(): array {
return [ 'swiper' ];
}

public function get_help_url() {
return '';
}
Expand Down

0 comments on commit ca429a5

Please sign in to comment.