@@ -107,30 +107,39 @@ function LtiConsumerXBlock(runtime, element) {
107107
108108 function confirmDialog ( message , triggerElement , showCancelButton ) {
109109 var def = $ . Deferred ( ) ;
110+
111+ // In order to scope the dialog container to the lti-consumer-container, grab the ID of the
112+ // lti-consumer-container ancestor and append it to the ID of the dialog container.
113+ var container_id = triggerElement . closest ( ".lti-consumer-container" ) . attr ( "id" ) ;
114+ var dialog_container_id = "dialog-container-" + container_id ;
115+
110116 // Hide the button that triggered the event, i.e. the launch button.
111117 triggerElement . hide ( ) ;
112118
113- $ ( '<div id="dialog-container "></div>' ) . insertAfter ( triggerElement ) // TODO: this will need some cute styling. It looks like trash but it works.
119+ $ ( '<div id="' + dialog_container_id + ' "></div>') . insertAfter ( triggerElement ) // TODO: this will need some cute styling. It looks like trash but it works.
114120 . append ( '<p>' + message + '</p>' )
121+
122+ var $dialog_container = $ ( "#" + dialog_container_id ) ;
123+
115124 if ( showCancelButton ) {
116- $ ( '#dialog-container' )
125+ $dialog_container
117126 . append ( '<button style="margin-right:1rem" id="cancel-button">Cancel</button>' ) ;
118127 }
119- $ ( '#dialog-container' ) . append ( '<button id="confirm-button">OK</button>' ) ;
128+ $dialog_container . append ( '<button id="confirm-button">OK</button>' ) ;
120129
121130 // When a learner clicks "OK" or "Cancel" in the consent dialog, remove the consent dialog, show the launch
122131 // button, and resolve the promise.
123- $ ( '#confirm-button' ) . click ( function ( ) {
132+ $dialog_container . find ( '#confirm-button' ) . click ( function ( ) {
124133 // Show the button that triggered the event, i.e. the launch button.
125134 triggerElement . show ( ) ;
126- $ ( "#dialog-container" ) . remove ( )
135+ $dialog_container . remove ( )
127136 $ ( 'body' ) . append ( '<h1>Confirm Dialog Result: <i>Yes</i></h1>' ) ;
128137 def . resolve ( "OK" ) ;
129138 } )
130- $ ( '#cancel-button' ) . click ( function ( ) {
139+ $dialog_container . find ( '#cancel-button' ) . click ( function ( ) {
131140 // Hide the button that triggered the event, i.e. the launch button.
132141 triggerElement . show ( )
133- $ ( "#dialog-container" ) . remove ( )
142+ $dialog_container . remove ( )
134143 $ ( 'body' ) . append ( '<h1>Confirm Dialog Result: <i>No</i></h1>' ) ;
135144 def . resolve ( "Cancel" ) ;
136145 } )
0 commit comments