diff --git a/mod/lti/amd/build/contentitem.min.js b/mod/lti/amd/build/contentitem.min.js index 574f74cfa97..dfa1bb92ae6 100644 --- a/mod/lti/amd/build/contentitem.min.js +++ b/mod/lti/amd/build/contentitem.min.js @@ -1 +1 @@ -define(["jquery","core/notification","core/str","core/templates","mod_lti/form-field","core/yui"],function(a,b,c,d,e){var f,g={init:function(a,e){var g="";c.get_string("selectcontent","lti").then(function(b){g=b;var c={url:a,postData:e};return d.render("mod_lti/contentitem",c)}).then(function(a,c){f=new M.core.dialogue({modal:!0,headerContent:g,bodyContent:a,draggable:!0,width:"800px",height:"600px"}),f.show(),f.after("visibleChange",function(a){a.prevVal&&!a.newVal&&(this.destroy(),b.fetchNotifications())},f),d.runTemplateJS(c)}).fail(b.exception)}},h=[new e("name",e.TYPES.TEXT,(!1),""),new e("introeditor",e.TYPES.EDITOR,(!1),""),new e("toolurl",e.TYPES.TEXT,(!0),""),new e("securetoolurl",e.TYPES.TEXT,(!0),""),new e("instructorchoiceacceptgrades",e.TYPES.CHECKBOX,(!0),(!0)),new e("instructorchoicesendname",e.TYPES.CHECKBOX,(!0),(!0)),new e("instructorchoicesendemailaddr",e.TYPES.CHECKBOX,(!0),(!0)),new e("instructorcustomparameters",e.TYPES.TEXT,(!0),""),new e("icon",e.TYPES.TEXT,(!0),""),new e("secureicon",e.TYPES.TEXT,(!0),""),new e("launchcontainer",e.TYPES.SELECT,(!0),0)];return window.processContentItemReturnData=function(b){f&&f.hide();var c;for(c in h){var d=h[c],e=null;"undefined"!==a.type(b[d.name])&&(e=b[d.name]),d.setFieldValue(e)}},g}); \ No newline at end of file +define(["jquery","core/notification","core/str","core/templates","mod_lti/form-field","core/modal_factory","core/modal_events"],function(a,b,c,d,e,f,g){var h,i={init:function(a,e){var i="";c.get_string("selectcontent","lti").then(function(c){i=c;var j={url:a,postData:e},k=d.render("mod_lti/contentitem",j);h?(h.setBody(k),h.show()):f.create({title:i,body:k,large:!0}).done(function(a){h=a,h.show(),a.getRoot().on(g.hidden,function(){a.setBody(""),b.fetchNotifications()})})})}},j=[new e("name",e.TYPES.TEXT,(!1),""),new e("introeditor",e.TYPES.EDITOR,(!1),""),new e("toolurl",e.TYPES.TEXT,(!0),""),new e("securetoolurl",e.TYPES.TEXT,(!0),""),new e("instructorchoiceacceptgrades",e.TYPES.CHECKBOX,(!0),(!0)),new e("instructorchoicesendname",e.TYPES.CHECKBOX,(!0),(!0)),new e("instructorchoicesendemailaddr",e.TYPES.CHECKBOX,(!0),(!0)),new e("instructorcustomparameters",e.TYPES.TEXT,(!0),""),new e("icon",e.TYPES.TEXT,(!0),""),new e("secureicon",e.TYPES.TEXT,(!0),""),new e("launchcontainer",e.TYPES.SELECT,(!0),0)];return window.processContentItemReturnData=function(b){h&&h.hide();var c;for(c in j){var d=j[c],e=null;"undefined"!==a.type(b[d.name])&&(e=b[d.name]),d.setFieldValue(e)}},i}); \ No newline at end of file diff --git a/mod/lti/amd/build/contentitem_return.min.js b/mod/lti/amd/build/contentitem_return.min.js index 6c08d1a888a..ef56c529454 100644 --- a/mod/lti/amd/build/contentitem_return.min.js +++ b/mod/lti/amd/build/contentitem_return.min.js @@ -1 +1 @@ -define([],function(){return{init:function(a){window!=top&&parent.processContentItemReturnData(a)}}}); \ No newline at end of file +define(["jquery"],function(a){return{init:function(b){a(window).ready(function(){window!=top&&parent.processContentItemReturnData(b)})}}}); \ No newline at end of file diff --git a/mod/lti/amd/src/contentitem.js b/mod/lti/amd/src/contentitem.js index cf1fe526332..f8e26345dd7 100644 --- a/mod/lti/amd/src/contentitem.js +++ b/mod/lti/amd/src/contentitem.js @@ -26,8 +26,17 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since 3.2 */ -define(['jquery', 'core/notification', 'core/str', 'core/templates', 'mod_lti/form-field', 'core/yui'], - function($, notification, str, templates, FormField) { +define( + [ + 'jquery', + 'core/notification', + 'core/str', + 'core/templates', + 'mod_lti/form-field', + 'core/modal_factory', + 'core/modal_events' + ], + function($, notification, str, templates, FormField, ModalFactory, ModalEvents) { var dialogue; var contentItem = { /** @@ -44,35 +53,35 @@ define(['jquery', 'core/notification', 'core/str', 'core/templates', 'mod_lti/fo url: url, postData: postData }; - return templates.render('mod_lti/contentitem', context); - }).then(function(html, js) { - // Set dialog's body content. - dialogue = new M.core.dialogue({ - modal: true, - headerContent: dialogueTitle, - bodyContent: html, - draggable: true, - width: '800px', - height: '600px' - }); + var body = templates.render('mod_lti/contentitem', context); + if (dialogue) { + // Set dialogue body. + dialogue.setBody(body); + // Display the dialogue. + dialogue.show(); + } else { + ModalFactory.create({ + title: dialogueTitle, + body: body, + large: true + }).done(function(modal) { + dialogue = modal; - // Show dialog. - dialogue.show(); + // Display the dialogue. + dialogue.show(); - // Destroy after hiding. - dialogue.after('visibleChange', function(e) { - // Going from visible to hidden. - if (e.prevVal && !e.newVal) { - this.destroy(); - // Fetch notifications. - notification.fetchNotifications(); - } - }, dialogue); + // On hide handler. + modal.getRoot().on(ModalEvents.hidden, function () { + // Empty modal contents when it's hidden. + modal.setBody(''); - templates.runTemplateJS(js); - - }).fail(notification.exception); + // Fetch notifications. + notification.fetchNotifications(); + }); + }); + } + }); } }; diff --git a/mod/lti/amd/src/contentitem_return.js b/mod/lti/amd/src/contentitem_return.js index 2ae3ceca6f7..37d7c37de93 100644 --- a/mod/lti/amd/src/contentitem_return.js +++ b/mod/lti/amd/src/contentitem_return.js @@ -23,7 +23,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since 3.2 */ -define([], function() { +define(['jquery'], function($) { return { /** * Init function. @@ -31,10 +31,13 @@ define([], function() { * @param {string} returnData The returned data. */ init: function(returnData) { - if (window != top) { - // Send return data to be processed by the parent window. - parent.processContentItemReturnData(returnData); - } + // Make sure the window has loaded before we perform processing. + $(window).ready(function() { + if (window != top) { + // Send return data to be processed by the parent window. + parent.processContentItemReturnData(returnData); + } + }); } }; }); diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php index ece6c9f41ab..7012c17134f 100644 --- a/mod/lti/locallib.php +++ b/mod/lti/locallib.php @@ -1344,15 +1344,15 @@ function lti_get_type_config($typeid) { FROM {lti_types_config} WHERE typeid = :typeid1 UNION ALL - SELECT 'toolurl' AS name, " . $DB->sql_compare_text('baseurl', 1333) . " AS value + SELECT 'toolurl' AS name, baseurl AS value FROM {lti_types} WHERE id = :typeid2 UNION ALL - SELECT 'icon' AS name, " . $DB->sql_compare_text('icon', 1333) . " AS value + SELECT 'icon' AS name, icon AS value FROM {lti_types} WHERE id = :typeid3 UNION ALL - SELECT 'secureicon' AS name, " . $DB->sql_compare_text('secureicon', 1333) . " AS value + SELECT 'secureicon' AS name, secureicon AS value FROM {lti_types} WHERE id = :typeid4"; diff --git a/mod/lti/templates/contentitem.mustache b/mod/lti/templates/contentitem.mustache index aa317342705..eab9868d949 100644 --- a/mod/lti/templates/contentitem.mustache +++ b/mod/lti/templates/contentitem.mustache @@ -76,13 +76,11 @@ // Adjust iframe's width to the fit the container's width. var containerWidth = $('div.contentitem-container').width(); - $('#contentitem-page-iframe').attr('width', containerWidth); + $('#contentitem-page-iframe').width(containerWidth + 'px'); - var dialogueContentDiv = $('div.contentitem-container').parent(); - var dialogueContainer = dialogueContentDiv.parent(); - // Adjust iframe's height to container's height - 55px (dialogue title bar + top/bottom margins). - var containerHeight = dialogueContainer.height() - 55; - $('#contentitem-page-iframe').attr('height', containerHeight); + // Adjust iframe's height to 75% of the width. + var containerHeight = containerWidth * 0.75; + $('#contentitem-page-iframe').height(containerHeight + 'px'); }); }); {{/js}}