Updated Jasmine tests as per Anton's and Alex's suggestions.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<div id="lti_id" class="lti" data-open_in_a_new_page="true">
|
||||
|
||||
<form
|
||||
action="http://www.example.com/some_book"
|
||||
action=""
|
||||
name="ltiLaunchForm"
|
||||
class="ltiLaunchForm"
|
||||
method="post"
|
||||
@@ -27,7 +27,5 @@
|
||||
<input type="submit" value="Press to Launch" />
|
||||
</form>
|
||||
|
||||
<a href="#" class='link_lti_new_window'>Click to view LTI in new window</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,36 +0,0 @@
|
||||
<div class="lti-wrapper">
|
||||
<div id="lti_id" class="lti" data-open_in_a_new_page="false">
|
||||
|
||||
<form
|
||||
action="http://www.example.com"
|
||||
name="ltiLaunchForm"
|
||||
class="ltiLaunchForm"
|
||||
method="post"
|
||||
target="ltiLaunchFrame"
|
||||
enctype="application/x-www-form-urlencoded"
|
||||
>
|
||||
<input name="launch_presentation_return_url" value="" />
|
||||
<input name="lti_version" value="LTI-1p0" />
|
||||
<input name="user_id" value="student" />
|
||||
<input name="oauth_nonce" value="28347958723982798572" />
|
||||
<input name="oauth_timestamp" value="2389479832" />
|
||||
<input name="oauth_consumer_key" value="" />
|
||||
<input name="lis_result_sourcedid" value="" />
|
||||
<input name="oauth_signature_method" value="HMAC-SHA1" />
|
||||
<input name="oauth_version" value="1.0" />
|
||||
<input name="role" value="student" />
|
||||
<input name="lis_outcome_service_url" value="" />
|
||||
<input name="oauth_signature" value="89ru3289r3ry283y3r82ryr38yr" />
|
||||
<input name="lti_message_type" value="basic-lti-launch-request" />
|
||||
<input name="oauth_callback" value="about:blank" />
|
||||
|
||||
<input type="submit" value="Press to Launch" />
|
||||
</form>
|
||||
|
||||
<h3 class="error_message">
|
||||
Please provide launch_url. Click "Edit", and fill in the
|
||||
required fields.
|
||||
</h3>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,37 +0,0 @@
|
||||
<div class="lti-wrapper">
|
||||
<div id="lti_id" class="lti" data-open_in_a_new_page="false">
|
||||
|
||||
<form
|
||||
action="http://www.example.com/some_book"
|
||||
name="ltiLaunchForm"
|
||||
class="ltiLaunchForm"
|
||||
method="post"
|
||||
target="ltiLaunchFrame"
|
||||
enctype="application/x-www-form-urlencoded"
|
||||
>
|
||||
<input name="launch_presentation_return_url" value="" />
|
||||
<input name="lti_version" value="LTI-1p0" />
|
||||
<input name="user_id" value="student" />
|
||||
<input name="oauth_nonce" value="28347958723982798572" />
|
||||
<input name="oauth_timestamp" value="2389479832" />
|
||||
<input name="oauth_consumer_key" value="" />
|
||||
<input name="lis_result_sourcedid" value="" />
|
||||
<input name="oauth_signature_method" value="HMAC-SHA1" />
|
||||
<input name="oauth_version" value="1.0" />
|
||||
<input name="role" value="student" />
|
||||
<input name="lis_outcome_service_url" value="" />
|
||||
<input name="oauth_signature" value="89ru3289r3ry283y3r82ryr38yr" />
|
||||
<input name="lti_message_type" value="basic-lti-launch-request" />
|
||||
<input name="oauth_callback" value="about:blank" />
|
||||
|
||||
<input type="submit" value="Press to Launch" />
|
||||
</form>
|
||||
|
||||
<iframe
|
||||
name="ltiLaunchFrame"
|
||||
class="ltiLaunchFrame"
|
||||
src=""
|
||||
></iframe>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,36 +0,0 @@
|
||||
<div class="lti-wrapper">
|
||||
<div id="lti_id" class="lti" data-open_in_a_new_page="true">
|
||||
|
||||
<form
|
||||
action="http://www.example.com"
|
||||
name="ltiLaunchForm"
|
||||
class="ltiLaunchForm"
|
||||
method="post"
|
||||
target="_blank"
|
||||
enctype="application/x-www-form-urlencoded"
|
||||
>
|
||||
<input name="launch_presentation_return_url" value="" />
|
||||
<input name="lti_version" value="LTI-1p0" />
|
||||
<input name="user_id" value="student" />
|
||||
<input name="oauth_nonce" value="28347958723982798572" />
|
||||
<input name="oauth_timestamp" value="2389479832" />
|
||||
<input name="oauth_consumer_key" value="" />
|
||||
<input name="lis_result_sourcedid" value="" />
|
||||
<input name="oauth_signature_method" value="HMAC-SHA1" />
|
||||
<input name="oauth_version" value="1.0" />
|
||||
<input name="role" value="student" />
|
||||
<input name="lis_outcome_service_url" value="" />
|
||||
<input name="oauth_signature" value="89ru3289r3ry283y3r82ryr38yr" />
|
||||
<input name="lti_message_type" value="basic-lti-launch-request" />
|
||||
<input name="oauth_callback" value="about:blank" />
|
||||
|
||||
<input type="submit" value="Press to Launch" />
|
||||
</form>
|
||||
|
||||
<h3 class="error_message">
|
||||
Please provide launch_url. Click "Edit", and fill in the
|
||||
required fields.
|
||||
</h3>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,36 +0,0 @@
|
||||
<div class="lti-wrapper">
|
||||
<div id="lti_id" class="lti" data-open_in_a_new_page="true">
|
||||
|
||||
<form
|
||||
action=""
|
||||
name="ltiLaunchForm"
|
||||
class="ltiLaunchForm"
|
||||
method="post"
|
||||
target="_blank"
|
||||
enctype="application/x-www-form-urlencoded"
|
||||
>
|
||||
<input name="launch_presentation_return_url" value="" />
|
||||
<input name="lti_version" value="LTI-1p0" />
|
||||
<input name="user_id" value="student" />
|
||||
<input name="oauth_nonce" value="28347958723982798572" />
|
||||
<input name="oauth_timestamp" value="2389479832" />
|
||||
<input name="oauth_consumer_key" value="" />
|
||||
<input name="lis_result_sourcedid" value="" />
|
||||
<input name="oauth_signature_method" value="HMAC-SHA1" />
|
||||
<input name="oauth_version" value="1.0" />
|
||||
<input name="role" value="student" />
|
||||
<input name="lis_outcome_service_url" value="" />
|
||||
<input name="oauth_signature" value="89ru3289r3ry283y3r82ryr38yr" />
|
||||
<input name="lti_message_type" value="basic-lti-launch-request" />
|
||||
<input name="oauth_callback" value="about:blank" />
|
||||
|
||||
<input type="submit" value="Press to Launch" />
|
||||
</form>
|
||||
|
||||
<h3 class="error_message">
|
||||
Please provide launch_url. Click "Edit", and fill in the
|
||||
required fields.
|
||||
</h3>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -25,16 +25,48 @@
|
||||
*/
|
||||
|
||||
(function () {
|
||||
var element, form, frame, link;
|
||||
var element, container, form, link,
|
||||
IN_NEW_WINDOW = 'true',
|
||||
IN_IFRAME = 'false',
|
||||
EMPTY_URL = '',
|
||||
DEFAULT_URL = 'http://www.example.com',
|
||||
NEW_URL = 'http://www.example.com/some_book';
|
||||
|
||||
function initialize(fixture, hasLink) {
|
||||
loadFixtures(fixture);
|
||||
function initialize(target, action) {
|
||||
var tempEl;
|
||||
|
||||
loadFixtures('lti.html');
|
||||
|
||||
element = $('.lti-wrapper');
|
||||
if (hasLink) {
|
||||
link = element.find('a.link_lti_new_window');
|
||||
container = element.find('.lti');
|
||||
form = container.find('.ltiLaunchForm');
|
||||
|
||||
if (target === IN_IFRAME) {
|
||||
container.data('open_in_a_new_page', 'false');
|
||||
form.attr('target', 'ltiLaunchFrame');
|
||||
}
|
||||
|
||||
form.attr('action', action);
|
||||
|
||||
// If we have a new proper action (non-default), we create either
|
||||
// a link that will submit the form, or an iframe that will contain
|
||||
// the answer of auto submitted form.
|
||||
if (action !== EMPTY_URL && action !== DEFAULT_URL) {
|
||||
if (target === IN_NEW_WINDOW) {
|
||||
$('<a />', {
|
||||
href: '#',
|
||||
class: 'link_lti_new_window'
|
||||
}).appendTo(container);
|
||||
|
||||
link = container.find('.link_lti_new_window');
|
||||
} else {
|
||||
$('<iframe />', {
|
||||
name: 'ltiLaunchFrame',
|
||||
class: 'ltiLaunchFrame',
|
||||
src: ''
|
||||
}).appendTo(container);
|
||||
}
|
||||
}
|
||||
form = element.find('.ltiLaunchForm');
|
||||
|
||||
spyOnEvent(form, 'submit');
|
||||
|
||||
@@ -48,7 +80,7 @@
|
||||
function () {
|
||||
|
||||
beforeEach(function () {
|
||||
initialize('lti_newpage_url_empty.html');
|
||||
initialize(IN_NEW_WINDOW, EMPTY_URL);
|
||||
});
|
||||
|
||||
it('form is not submitted', function () {
|
||||
@@ -61,7 +93,7 @@
|
||||
function () {
|
||||
|
||||
beforeEach(function () {
|
||||
initialize('lti_newpage_url_default.html');
|
||||
initialize(IN_NEW_WINDOW, DEFAULT_URL);
|
||||
});
|
||||
|
||||
it('form is not submitted', function () {
|
||||
@@ -75,7 +107,7 @@
|
||||
function () {
|
||||
|
||||
beforeEach(function () {
|
||||
initialize('lti_newpage_url_new.html', true);
|
||||
initialize(IN_NEW_WINDOW, NEW_URL);
|
||||
});
|
||||
|
||||
it('form is not submitted', function () {
|
||||
@@ -94,7 +126,7 @@
|
||||
function () {
|
||||
|
||||
beforeEach(function () {
|
||||
initialize('lti_iframe_url_empty.html');
|
||||
initialize(IN_IFRAME, EMPTY_URL);
|
||||
});
|
||||
|
||||
it('form is not submitted', function () {
|
||||
@@ -107,7 +139,7 @@
|
||||
function () {
|
||||
|
||||
beforeEach(function () {
|
||||
initialize('lti_iframe_url_default.html');
|
||||
initialize(IN_IFRAME, DEFAULT_URL);
|
||||
});
|
||||
|
||||
it('form is not submitted', function () {
|
||||
@@ -121,7 +153,7 @@
|
||||
function () {
|
||||
|
||||
beforeEach(function () {
|
||||
initialize('lti_iframe_url_new.html');
|
||||
initialize(IN_IFRAME, NEW_URL);
|
||||
});
|
||||
|
||||
it('form is submitted', function () {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*
|
||||
* 1.) Submit the form. The results will be shown on the current page in an
|
||||
* iframe.
|
||||
* 2.) attach a handler function to a link which will submit the form. The
|
||||
* 2.) Attach a handler function to a link which will submit the form. The
|
||||
* results will be shown in a new window.
|
||||
*
|
||||
* The 'open_in_a_new_page' data attribute of the LTI element dictates which of
|
||||
@@ -32,8 +32,12 @@ window.LTI = (function () {
|
||||
// Function initialize(element)
|
||||
//
|
||||
// Initialize the LTI module.
|
||||
//
|
||||
// @param element DOM element, or jQuery element object.
|
||||
//
|
||||
// @return undefined
|
||||
function initialize(element) {
|
||||
var form, open_in_a_new_page;
|
||||
var form, openInANewPage, formAction;
|
||||
|
||||
// In cms (Studio) the element is already a jQuery object. In lms it is
|
||||
// a DOM object.
|
||||
@@ -43,37 +47,35 @@ window.LTI = (function () {
|
||||
element = $(element);
|
||||
|
||||
form = element.find('.ltiLaunchForm');
|
||||
formAction = form.attr('action');
|
||||
|
||||
if (
|
||||
// Action is one of: null, undefined, 0, 000, '', false.
|
||||
!Boolean(form.attr('action')) ||
|
||||
// If action is empty string, or action is the default URL that should
|
||||
// not cause a form submit.
|
||||
if (!formAction || formAction === 'http://www.example.com') {
|
||||
|
||||
// Default URL that should not cause a form submit.
|
||||
form.attr('action') === 'http://www.example.com'
|
||||
) {
|
||||
return; // Nothing to do - no valid action provided.
|
||||
// Nothing to do - no valid action provided. Error message will be
|
||||
// displaced in browser (HTML).
|
||||
return;
|
||||
}
|
||||
|
||||
// We want a Boolean 'true' or 'false'. First we will retrieve the data
|
||||
// attribute, and then we will parse it via native JSON.parse().
|
||||
open_in_a_new_page = element.find('.lti').data('open_in_a_new_page');
|
||||
try {
|
||||
open_in_a_new_page = JSON.parse(open_in_a_new_page);
|
||||
} catch (e) {
|
||||
console.log('ERROR: Parsing data attribute "open_in_a_new_page".');
|
||||
console.log('*** error = "' + e.toString() + '".');
|
||||
|
||||
open_in_a_new_page = null;
|
||||
}
|
||||
openInANewPage = element.find('.lti').data('open_in_a_new_page');
|
||||
openInANewPage = JSON.parse(openInANewPage);
|
||||
|
||||
// If the Form's action attribute is set (i.e. we can perform a normal
|
||||
// submit), then we submit the form immediately or when user will click
|
||||
// on a link (depending on instance settings) and make the frame shown.
|
||||
if (open_in_a_new_page === true) {
|
||||
// submit), then we (depending on instance settings) submit the form
|
||||
// when user will click on a link, or submit the form immediately.
|
||||
if (openInANewPage === true) {
|
||||
element.find('.link_lti_new_window').on('click', function () {
|
||||
form.submit();
|
||||
});
|
||||
} else if (open_in_a_new_page === false) {
|
||||
} else {
|
||||
// At this stage the form exists on the page and has a valid
|
||||
// action. We are safe to submit it, even if `openInANewPage` is
|
||||
// set to some weird value.
|
||||
//
|
||||
// Best case scenario is that `openInANewPage` is set to `true`.
|
||||
form.submit();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user