| 1 |
import $ from 'jquery'; |
| 2 |
import { domElements } from '../constants/selectors'; |
| 3 |
|
| 4 |
export default class ThickBoxModal { |
| 5 |
openTriggerSelector: string; |
| 6 |
inlineContentId: string; |
| 7 |
windowCssClass: string; |
| 8 |
contentCssClass: string; |
| 9 |
|
| 10 |
constructor( |
| 11 |
openTriggerSelector: string, |
| 12 |
inlineContentId: string, |
| 13 |
windowCssClass: string, |
| 14 |
contentCssClass: string |
| 15 |
) { |
| 16 |
this.openTriggerSelector = openTriggerSelector; |
| 17 |
this.inlineContentId = inlineContentId; |
| 18 |
this.windowCssClass = windowCssClass; |
| 19 |
this.contentCssClass = contentCssClass; |
| 20 |
|
| 21 |
$(openTriggerSelector).on('click', this.init.bind(this)); |
| 22 |
} |
| 23 |
|
| 24 |
close() { |
| 25 |
//@ts-expect-error global |
| 26 |
window.tb_remove(); |
| 27 |
} |
| 28 |
|
| 29 |
init(e: Event) { |
| 30 |
//@ts-expect-error global |
| 31 |
window.tb_show( |
| 32 |
'', |
| 33 |
`#TB_inline?inlineId=${this.inlineContentId}&modal=true` |
| 34 |
); |
| 35 |
// thickbox doesn't respect the width and height url parameters https://core.trac.wordpress.org/ticket/17249 |
| 36 |
// We override thickboxes css with !important in the css |
| 37 |
$(domElements.thickboxModalWindow).addClass(this.windowCssClass); |
| 38 |
|
| 39 |
// have to modify the css of the thickbox content container as well |
| 40 |
$(domElements.thickboxModalContent).addClass(this.contentCssClass); |
| 41 |
|
| 42 |
// we unbind previous handlers because a thickbox modal is a single global object. |
| 43 |
// Everytime it is re-opened, it still has old handlers bound |
| 44 |
$(domElements.thickboxModalClose) |
| 45 |
.off('click') |
| 46 |
.on('click', this.close); |
| 47 |
|
| 48 |
e.preventDefault(); |
| 49 |
} |
| 50 |
} |
| 51 |
|