forked from sakaiproject/sakai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SAK-30431 - Initial commit for lti.frameResize support
- Loading branch information
Showing
7 changed files
with
233 additions
and
7 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
basiclti/basiclti-docs/resources/docs/sakai-api-test/resize.htm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<html> | ||
<head> | ||
<title>Testing lti.frameResize</title> | ||
</head> | ||
<body> | ||
<h1>Testing lti.frameResize</h1> | ||
<p> | ||
This script sends the "lti.frameResize" to its parent | ||
frame using <b>parent.postMessage()</b> to sneak across | ||
origins. You can just link to this file with any | ||
key and secret to test the behavior. | ||
</p> | ||
<script> | ||
function getRandomInt(min, max) { | ||
return Math.floor(Math.random() * (max - min)) + min; | ||
} | ||
function zap() { | ||
var num = getRandomInt(200,800); | ||
console.log("Sending "+num); | ||
parent.postMessage(JSON.stringify({ | ||
subject: "lti.frameResize", | ||
height: num | ||
}), "*"); | ||
} | ||
</script> | ||
<button onclick="zap();return false;" value="click">Press to Send Random Height</button><br/> | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
Support for Emerging "lti" postmessages | ||
--------------------------------------- | ||
|
||
Sakai has support for an informal standard currently supported | ||
by Canvas, Lumen Learning, and others that allows a tool nestled | ||
in an iframe to inform its parent that it needs to so a resize | ||
even if it the parent and frame are served from different origins. | ||
|
||
The trick is to use web messaging: | ||
|
||
https://www.w3.org/TR/2012/WD-webmessaging-20120313/ | ||
|
||
The messages and parameters are defined by convention and | ||
hopefully will evolve to being a standard. For example, | ||
to commuicate that a tool has been resized it would | ||
run the following JavaScript: | ||
|
||
parent.postMessage(JSON.stringify({ | ||
subject: "lti.frameResize", | ||
height: num | ||
}), "*"); | ||
|
||
|
||
Support in Sakai | ||
---------------- | ||
|
||
It is necessary to add a message listener at each of the points in Sakai | ||
where iframe markup is generated that might include an LTI URL. So far | ||
the following tools have been changed: | ||
|
||
* Lessons | ||
* LTI Portlet (External Tool) | ||
* Iframe tool | ||
|
||
There may be more iframes that we identify as we go forward. | ||
|
||
Use in Sakai Tool Markup | ||
------------------------ | ||
|
||
Code has been added to headscripts.js to send this message if the | ||
Sakai tool is using setMainFrameHeight() to communicate height changes | ||
to the parent document. The code detects whether or not we are | ||
same or different origins and uses the old resize trick or the | ||
postMessage as appropriate. | ||
|
||
So this means that auto-resizing Sakai tools will resize when | ||
placed in an iframe Canvas or a Sakai hosted on a different domain. | ||
|
||
Test Harness | ||
------------ | ||
|
||
To test this in Sakai or in Canvas, you can use this: | ||
|
||
https://online.dr-chuck.com/sakai-api-test/resize.htm | ||
|
||
Use any key/secret. You press a button and this tool resizes itself | ||
randomly each time the button is presed. Watch the console | ||
to see what is happening. | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters