| 1 |
export default function elementorWidget( |
| 2 |
elementor: any, |
| 3 |
options: any, |
| 4 |
callback: Function, |
| 5 |
done = () => {} |
| 6 |
) { |
| 7 |
return elementor.modules.controls.BaseData.extend({ |
| 8 |
onReady() { |
| 9 |
const self = this; |
| 10 |
const controlContainer = this.ui.contentEditable.prevObject[0].querySelector( |
| 11 |
options.controlSelector |
| 12 |
); |
| 13 |
let widgetContainer = this.options.element.$el[0].querySelector( |
| 14 |
options.containerSelector |
| 15 |
); |
| 16 |
if (widgetContainer) { |
| 17 |
callback(controlContainer, widgetContainer, (args: any) => |
| 18 |
self.setValue(args) |
| 19 |
); |
| 20 |
} else { |
| 21 |
//@ts-expect-error global |
| 22 |
window.elementorFrontend.hooks.addAction( |
| 23 |
`frontend/element_ready/${options.widgetName}.default`, |
| 24 |
(element: HTMLElement[]) => { |
| 25 |
widgetContainer = element[0].querySelector( |
| 26 |
options.containerSelector |
| 27 |
); |
| 28 |
callback(controlContainer, widgetContainer, (args: any) => |
| 29 |
self.setValue(args) |
| 30 |
); |
| 31 |
} |
| 32 |
); |
| 33 |
} |
| 34 |
}, |
| 35 |
saveValue(props: any) { |
| 36 |
this.setValue(props); |
| 37 |
}, |
| 38 |
onBeforeDestroy() { |
| 39 |
//@ts-expect-error global |
| 40 |
window.elementorFrontend.hooks.removeAction( |
| 41 |
`frontend/element_ready/${options.widgetName}.default` |
| 42 |
); |
| 43 |
done(); |
| 44 |
}, |
| 45 |
}); |
| 46 |
} |
| 47 |
|