1
1
import { registry } from "@web/core/registry" ;
2
2
import { Plugin } from "@html_editor/plugin" ;
3
3
import { applyModifications , loadImageInfo } from "@html_editor/utils/image_processing" ;
4
- import { _t } from "@web/core/l10n/translation" ;
5
4
6
5
class ImageGalleryOption extends Plugin {
7
6
static id = "imageGalleryOption" ;
@@ -15,8 +14,6 @@ class ImageGalleryOption extends Plugin {
15
14
] ,
16
15
builder_actions : this . getActions ( ) ,
17
16
system_classes : [ "o_empty_gallery_alert" ] ,
18
- clean_for_save_handlers : this . cleanForSave . bind ( this ) ,
19
- normalize_handlers : this . updateAlertBanner . bind ( this ) ,
20
17
on_reorder_items_handlers : this . reorderGalleryItems . bind ( this ) ,
21
18
on_remove_handlers : this . onRemove . bind ( this ) ,
22
19
after_remove_handlers : this . afterRemove . bind ( this ) ,
@@ -26,8 +23,15 @@ class ImageGalleryOption extends Plugin {
26
23
return {
27
24
addImage : this . addImageAction ,
28
25
removeAllImages : {
29
- apply : ( { editingElement } ) => {
30
- this . insertEmptyGalleryAlert ( this . getContainer ( editingElement ) ) ;
26
+ apply : ( { editingElement : el } ) => {
27
+ const containerEl = el . querySelector (
28
+ ".container, .container-fluid, .o_container_small"
29
+ ) ;
30
+ for ( const subEl of containerEl . querySelectorAll (
31
+ ":scope > *:not(.o_empty_gallery_alert)"
32
+ ) ) {
33
+ subEl . remove ( ) ;
34
+ }
31
35
} ,
32
36
} ,
33
37
setImageGalleryLayout : {
@@ -69,21 +73,6 @@ class ImageGalleryOption extends Plugin {
69
73
}
70
74
}
71
75
72
- cleanForSave ( { root } ) {
73
- for ( const emptyGalleryAlert of root . querySelectorAll ( ".o_empty_gallery_alert" ) ) {
74
- emptyGalleryAlert . remove ( ) ;
75
- }
76
- }
77
-
78
- updateAlertBanner ( ) {
79
- const imageGalleries = this . document . querySelectorAll ( ".s_image_gallery" ) ;
80
- for ( const imageGallery of imageGalleries ) {
81
- const container = this . getContainer ( imageGallery ) ;
82
- if ( ! container . querySelector ( "img" ) && ! container . querySelector ( ".alert" ) ) {
83
- this . insertEmptyGalleryAlert ( container ) ;
84
- }
85
- }
86
- }
87
76
reorderGalleryItems ( { elementToReorder, position, optionName } ) {
88
77
if ( optionName === "GalleryImageList" ) {
89
78
const editingGalleryElement = elementToReorder . closest ( ".s_image_gallery" ) ;
@@ -145,46 +134,6 @@ class ImageGalleryOption extends Plugin {
145
134
} ;
146
135
}
147
136
148
- insertEmptyGalleryAlert ( container ) {
149
- const addImg = document . createElement ( "div" ) ;
150
- addImg . classList . add (
151
- "alert" ,
152
- "alert-info" ,
153
- "o_empty_gallery_alert" ,
154
- "text-center" ,
155
- "o_not_editable"
156
- ) ;
157
- addImg . contentEditable = false ;
158
- const text = document . createElement ( "span" ) ;
159
- text . classList . add ( "o_add_images" ) ;
160
- text . textContent = _t ( " Add Images" ) ;
161
- text . style . cursor = "pointer" ;
162
-
163
- const icon = document . createElement ( "i" ) ;
164
- icon . classList . add ( "fa" , "fa-plus-circle" ) ;
165
-
166
- addImg . appendChild ( icon ) ;
167
- addImg . appendChild ( text ) ;
168
- container . replaceChildren ( addImg ) ;
169
-
170
- this . addDomListener ( addImg , "click" , ( { target } ) => {
171
- const editingElement = target . closest ( ".s_image_gallery" ) ;
172
- const applySpec = { editingElement } ;
173
- this . dependencies . operation . next (
174
- ( ) => {
175
- this . addImageAction . apply ( applySpec ) ;
176
- this . dependencies . history . addStep ( ) ;
177
- } ,
178
- {
179
- load : async ( ) => {
180
- const loadResult = await this . addImageAction . load ( { editingElement } ) ;
181
- applySpec . loadResult = loadResult ;
182
- } ,
183
- }
184
- ) ;
185
- } ) ;
186
- }
187
-
188
137
/**
189
138
* Set the images in the gallery by following the wanted layout
190
139
* @param {Element } imageGalleryElement
0 commit comments