@@ -43,6 +43,7 @@ import { Component, markup, onMounted, onWillUnmount, useEffect, useRef, useStat
43
43
import {
44
44
BackgroundToggler ,
45
45
Box ,
46
+ CarouselHandler ,
46
47
LayoutColumn ,
47
48
Many2oneUserValue ,
48
49
registerBackgroundOptions ,
@@ -1977,11 +1978,13 @@ options.registry.menu_data = options.Class.extend({
1977
1978
} ,
1978
1979
} ) ;
1979
1980
1980
- options . registry . Carousel = options . registry . CarouselHandler . extend ( {
1981
+ class Carousel extends CarouselHandler {
1981
1982
/**
1982
1983
* @override
1983
1984
*/
1984
- start : function ( ) {
1985
+ constructor ( ) {
1986
+ super ( ...arguments ) ;
1987
+
1985
1988
this . $bsTarget . carousel ( 'pause' ) ;
1986
1989
this . $indicators = this . $target . find ( '.carousel-indicators' ) ;
1987
1990
this . $controls = this . $target . find ( '.carousel-control-prev, .carousel-control-next, .carousel-indicators' ) ;
@@ -1994,7 +1997,7 @@ options.registry.Carousel = options.registry.CarouselHandler.extend({
1994
1997
let _slideTimestamp ;
1995
1998
this . $bsTarget . on ( 'slide.bs.carousel.carousel_option' , ( ) => {
1996
1999
_slideTimestamp = window . performance . now ( ) ;
1997
- setTimeout ( ( ) => this . trigger_up ( 'hide_overlay' ) ) ;
2000
+ setTimeout ( ( ) => this . env . hideOverlay ( ) ) ;
1998
2001
} ) ;
1999
2002
this . $bsTarget . on ( 'slid.bs.carousel.carousel_option' , ( ) => {
2000
2003
// slid.bs.carousel is most of the time fired too soon by bootstrap
@@ -2003,52 +2006,48 @@ options.registry.Carousel = options.registry.CarouselHandler.extend({
2003
2006
// should be enough...
2004
2007
const _slideDuration = ( window . performance . now ( ) - _slideTimestamp ) ;
2005
2008
setTimeout ( ( ) => {
2006
- this . trigger_up ( 'activate_snippet' , {
2007
- $snippet : this . $target . find ( '.carousel-item.active' ) ,
2008
- ifInactiveOptions : true ,
2009
- } ) ;
2009
+ this . env . activateSnippet ( this . $target . find ( '.carousel-item.active' ) , false , true ) ;
2010
2010
this . $bsTarget . trigger ( 'active_slide_targeted' ) ;
2011
2011
} , 0.2 * _slideDuration ) ;
2012
2012
} ) ;
2013
-
2014
- return this . _super . apply ( this , arguments ) ;
2015
- } ,
2013
+ }
2016
2014
/**
2017
2015
* @override
2018
2016
*/
2019
- destroy : function ( ) {
2020
- this . _super . apply ( this , arguments ) ;
2017
+ destroy ( ) {
2018
+ super . destroy ( ... arguments ) ;
2021
2019
this . $bsTarget . off ( '.carousel_option' ) ;
2022
- } ,
2020
+ }
2023
2021
/**
2024
2022
* @override
2025
2023
*/
2026
- onBuilt : function ( ) {
2024
+ onBuilt ( ) {
2027
2025
this . _assignUniqueID ( ) ;
2028
- } ,
2026
+ }
2029
2027
/**
2030
2028
* @override
2031
2029
*/
2032
- onClone : function ( ) {
2030
+ onClone ( ) {
2033
2031
this . _assignUniqueID ( ) ;
2034
- } ,
2032
+ }
2035
2033
/**
2036
2034
* @override
2037
2035
*/
2038
- cleanForSave : function ( ) {
2036
+ // TODO: @owl -options check if this should be cleanUI() rather than cleanForSave()
2037
+ cleanUI ( ) {
2039
2038
const $items = this . $target . find ( '.carousel-item' ) ;
2040
2039
$items . removeClass ( 'next prev left right active' ) . first ( ) . addClass ( 'active' ) ;
2041
2040
this . $indicators . find ( 'li' ) . removeClass ( 'active' ) . empty ( ) . first ( ) . addClass ( 'active' ) ;
2042
- } ,
2041
+ }
2043
2042
/**
2044
2043
* @override
2045
2044
*/
2046
- notify : function ( name , data ) {
2047
- this . _super ( ...arguments ) ;
2045
+ notify ( name , data ) {
2046
+ super . notify ( ...arguments ) ;
2048
2047
if ( name === 'add_slide' ) {
2049
2048
this . _addSlide ( ) ;
2050
2049
}
2051
- } ,
2050
+ }
2052
2051
2053
2052
//--------------------------------------------------------------------------
2054
2053
// Options
@@ -2059,7 +2058,7 @@ options.registry.Carousel = options.registry.CarouselHandler.extend({
2059
2058
*/
2060
2059
addSlide ( previewMode , widgetValue , params ) {
2061
2060
this . _addSlide ( ) ;
2062
- } ,
2061
+ }
2063
2062
2064
2063
//--------------------------------------------------------------------------
2065
2064
// Private
@@ -2071,7 +2070,7 @@ options.registry.Carousel = options.registry.CarouselHandler.extend({
2071
2070
*
2072
2071
* @private
2073
2072
*/
2074
- _assignUniqueID : function ( ) {
2073
+ _assignUniqueID ( ) {
2075
2074
const id = 'myCarousel' + Date . now ( ) ;
2076
2075
this . $target . attr ( 'id' , id ) ;
2077
2076
this . $target . find ( '[data-bs-target]' ) . attr ( 'data-bs-target' , '#' + id ) ;
@@ -2083,7 +2082,7 @@ options.registry.Carousel = options.registry.CarouselHandler.extend({
2083
2082
$el . attr ( 'href' , '#' + id ) ;
2084
2083
}
2085
2084
} ) ;
2086
- } ,
2085
+ }
2087
2086
/**
2088
2087
* Adds a slide.
2089
2088
*
@@ -2103,13 +2102,13 @@ options.registry.Carousel = options.registry.CarouselHandler.extend({
2103
2102
. removeClass ( 'active' )
2104
2103
. insertAfter ( $active ) ;
2105
2104
this . $bsTarget . carousel ( 'next' ) ;
2106
- } ,
2105
+ }
2107
2106
/**
2108
2107
* @override
2109
2108
*/
2110
2109
_getItemsGallery ( ) {
2111
2110
return Array . from ( this . $target [ 0 ] . querySelectorAll ( ".carousel-item" ) ) ;
2112
- } ,
2111
+ }
2113
2112
/**
2114
2113
* @override
2115
2114
*/
@@ -2122,36 +2121,36 @@ options.registry.Carousel = options.registry.CarouselHandler.extend({
2122
2121
carouselInnerEl . append ( itemsEl ) ;
2123
2122
}
2124
2123
this . _updateIndicatorAndActivateSnippet ( newItemPosition ) ;
2125
- } ,
2126
-
2124
+ }
2125
+ }
2126
+ registerWebsiteOption ( "Carousel" , {
2127
+ Class : Carousel ,
2128
+ template : "website.Carousel" ,
2129
+ selector : "section" ,
2130
+ target : "> .carousel" ,
2127
2131
} ) ;
2128
2132
2129
- options . registry . CarouselItem = options . Class . extend ( {
2130
- isTopOption : true ,
2131
- forceNoDeleteButton : true ,
2133
+ class CarouselItem extends SnippetOption {
2134
+ static isTopOption = true ;
2135
+ static forceNoDeleteButton = true ;
2132
2136
2133
2137
/**
2134
2138
* @override
2135
2139
*/
2136
- start : function ( ) {
2140
+ constructor ( ) {
2141
+ super ( ...arguments ) ;
2142
+
2137
2143
this . $carousel = this . $bsTarget . closest ( '.carousel' ) ;
2138
2144
this . $indicators = this . $carousel . find ( '.carousel-indicators' ) ;
2139
2145
this . $controls = this . $carousel . find ( '.carousel-control-prev, .carousel-control-next, .carousel-indicators' ) ;
2140
-
2141
- var leftPanelEl = this . $overlay . data ( '$optionsSection' ) [ 0 ] ;
2142
- var titleTextEl = leftPanelEl . querySelector ( 'we-title > span' ) ;
2143
- this . counterEl = document . createElement ( 'span' ) ;
2144
- titleTextEl . appendChild ( this . counterEl ) ;
2145
-
2146
- return this . _super ( ...arguments ) ;
2147
- } ,
2146
+ }
2148
2147
/**
2149
2148
* @override
2150
2149
*/
2151
- destroy : function ( ) {
2152
- this . _super ( ...arguments ) ;
2150
+ destroy ( ) {
2151
+ super . destroy ( ...arguments ) ;
2153
2152
this . $carousel . off ( '.carousel_item_option' ) ;
2154
- } ,
2153
+ }
2155
2154
2156
2155
//--------------------------------------------------------------------------
2157
2156
// Public
@@ -2162,13 +2161,14 @@ options.registry.CarouselItem = options.Class.extend({
2162
2161
*
2163
2162
* @override
2164
2163
*/
2165
- updateUI : async function ( ) {
2166
- await this . _super ( ...arguments ) ;
2164
+ async updateUI ( ) {
2165
+ await super . updateUI ( ...arguments ) ;
2167
2166
const $items = this . $carousel . find ( '.carousel-item' ) ;
2168
2167
const $activeSlide = $items . filter ( '.active' ) ;
2169
- const updatedText = ` (${ $activeSlide . index ( ) + 1 } /${ $items . length } )` ;
2170
- this . counterEl . textContent = updatedText ;
2171
- } ,
2168
+ // TODO: @owl -options: block the editor UI until the new options are
2169
+ // created.
2170
+ this . callbacks . updateExtraTitle ( ` (${ $activeSlide . index ( ) + 1 } /${ $items . length } )` ) ;
2171
+ }
2172
2172
2173
2173
//--------------------------------------------------------------------------
2174
2174
// Options
@@ -2178,17 +2178,17 @@ options.registry.CarouselItem = options.Class.extend({
2178
2178
* @see this.selectClass for parameters
2179
2179
*/
2180
2180
addSlideItem ( previewMode , widgetValue , params ) {
2181
- this . trigger_up ( 'option_update' , {
2181
+ this . callbacks . notifyOptions ( {
2182
2182
optionName : 'Carousel' ,
2183
2183
name : 'add_slide' ,
2184
2184
} ) ;
2185
- } ,
2185
+ }
2186
2186
/**
2187
2187
* Removes the current slide.
2188
2188
*
2189
2189
* @see this.selectClass for parameters.
2190
2190
*/
2191
- removeSlide : function ( previewMode ) {
2191
+ removeSlide ( previewMode ) {
2192
2192
const $items = this . $carousel . find ( '.carousel-item' ) ;
2193
2193
const newLength = $items . length - 1 ;
2194
2194
if ( ! this . removing && newLength > 0 ) {
@@ -2210,13 +2210,13 @@ options.registry.CarouselItem = options.Class.extend({
2210
2210
this . removing = true ;
2211
2211
this . $carousel . carousel ( 'prev' ) ;
2212
2212
}
2213
- } ,
2213
+ }
2214
2214
/**
2215
2215
* Goes to next slide or previous slide.
2216
2216
*
2217
2217
* @see this.selectClass for parameters
2218
2218
*/
2219
- switchToSlide : function ( previewMode , widgetValue , params ) {
2219
+ switchToSlide ( previewMode , widgetValue , params ) {
2220
2220
switch ( widgetValue ) {
2221
2221
case 'left' :
2222
2222
this . $controls . filter ( '.carousel-control-prev' ) [ 0 ] . click ( ) ;
@@ -2225,7 +2225,12 @@ options.registry.CarouselItem = options.Class.extend({
2225
2225
this . $controls . filter ( '.carousel-control-next' ) [ 0 ] . click ( ) ;
2226
2226
break ;
2227
2227
}
2228
- } ,
2228
+ }
2229
+ }
2230
+ registerWebsiteOption ( "CarouselItem" , {
2231
+ Class : CarouselItem ,
2232
+ template : "website.CarouselItem" ,
2233
+ selector : ".s_carousel .carousel-item, .s_quotes_carousel .carousel-item" ,
2229
2234
} ) ;
2230
2235
2231
2236
class Parallax extends SnippetOption {
@@ -4286,8 +4291,8 @@ options.registry.GridImage = options.Class.extend({
4286
4291
} ,
4287
4292
} ) ;
4288
4293
4289
- options . registry . GalleryElement = options . Class . extend ( {
4290
4294
4295
+ class GalleryElement extends SnippetOption {
4291
4296
//--------------------------------------------------------------------------
4292
4297
// Options
4293
4298
//--------------------------------------------------------------------------
@@ -4301,16 +4306,21 @@ options.registry.GalleryElement = options.Class.extend({
4301
4306
const optionName = this . $target [ 0 ] . classList . contains ( "carousel-item" ) ? "Carousel"
4302
4307
: "GalleryImageList" ;
4303
4308
const itemEl = this . $target [ 0 ] ;
4304
- this . trigger_up ( "option_update" , {
4309
+ this . callbacks . notifyOptions ( {
4305
4310
optionName : optionName ,
4306
4311
name : "reorder_items" ,
4307
4312
data : {
4308
4313
itemEl : itemEl ,
4309
4314
position : widgetValue ,
4310
4315
} ,
4311
4316
} ) ;
4312
- } ,
4313
- } ) ;
4317
+ }
4318
+ }
4319
+ registerWebsiteOption ( "GalleryElement" , {
4320
+ Class : GalleryElement ,
4321
+ template : "website.GalleryElement" ,
4322
+ selector : ".s_image_gallery img, .s_carousel .carousel-item" ,
4323
+ } , { sequence : 10 } ) ;
4314
4324
4315
4325
options . registry . Button = options . Class . extend ( {
4316
4326
/**
0 commit comments