GitHub PR - LTI Request for Page Information

Closes PLAT-4625

Test Plan:
- TBD: Pull Request from GitHub. Allows tool to query window and
  iframe size

Change-Id: I058dc55e1412c99aad3d0217816b57f2f7557f7a
Reviewed-on: https://gerrit.instructure.com/199596
Tested-by: Jenkins
Reviewed-by: Marc Phillips <mphillips@instructure.com>
QA-Review: Weston Dransfield <wdransfield@instructure.com>
Product-Review: Clint Furse <cfurse@instructure.com>
This commit is contained in:
Alex Slaughter 2018-10-18 21:57:11 -04:00 committed by Clint Furse
parent 567e4e5f61
commit 69494f4103
2 changed files with 32 additions and 0 deletions

View File

@ -74,6 +74,19 @@ export function ltiMessageHandler(e) {
}
break;
case 'lti.fetchWindowSize': {
const iframe = findDomForWindow(e.source);
if (iframe) {
message.height = window.innerHeight;
message.width = window.innerWidth;
message.offset = $('.tool_content_wrapper').offset();
const strMessage = JSON.stringify(message);
iframe.contentWindow.postMessage(strMessage, '*');
}
break;
}
case 'lti.showModuleNavigation':
if(message.show === true || message.show === false){
$('.module-sequence-footer').toggle(message.show);

View File

@ -31,6 +31,10 @@ const resizeMessage = {
height: finalHeight
}
const fetchWindowSize = {
subject: 'lti.fetchWindowSize'
}
const scrollMessage = {
subject: 'lti.scrollToTop'
}
@ -109,6 +113,21 @@ QUnit.module('Messages', function (suiteHooks) {
equal(iframe.height(), finalHeight)
})
test('returns the hight and width of the page along with the iframe offset', () => {
ltiToolWrapperFixture.append(`
<div>
<h1 class="page-title">LTI resize test</h1>
<p><iframe style="width: 100%; height: ${intialHeight}px;" src="https://canvas.example.com/courses/4/external_tools/retrieve?display=borderless" width="100%" height="${intialHeight}px" allowfullscreen="allowfullscreen" webkitallowfullscreen="webkitallowfullscreen" mozallowfullscreen="mozallowfullscreen"></iframe></p>
</div>
`)
const iframe = $('iframe')
sinon.spy(iframe[0].contentWindow, 'postMessage')
notOk(iframe[0].contentWindow.postMessage.calledOnce)
ltiMessageHandler(postMessageEvent(fetchWindowSize, iframe[0].contentWindow))
ok(iframe[0].contentWindow.postMessage.calledOnce)
})
test('hides the module navigation', () => {
ltiToolWrapperFixture.append(`
<div>