How can I load in a bootbox a custom element with javascript methods attached?

770 views Asked by At

I want to use crop and resize images inside a bootbox. To achieve this, I use Cropper.

Based on the examples of Cropper, I should instantiate the cropper object in my bootbox when it is displayed and get rid of it when it is closed.

Is it possible or should I use a regular bootstrap modal?

Could I, for instance, add a script tag in the bootbox message in order to do the job there? That would be dirty, and before I commit into this, I wanted to check for more clean/elegant approaches.

1

There are 1 answers

1
Michel Floyd On BEST ANSWER

My pattern for using bootbox custom dialogs is to write:

message: "<div id='dialogAnchor'></div>"

in the bootbox dialog definition and follow that up (after you create the bootbox) with

Blaze.render(Template.myDialog,$("#dialogAnchor")[0])

to embed my template into the bootbox dialog directly. This makes managing the contents of the bootbox much, much simpler. I haven't used cropper but assuming you can use it in a normal template then you can use the aforementioned pattern to get that template into a bootbox.