2 This file is part of Moodle - http://moodle.org/
4 Moodle is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 Moodle is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 @template mod_lti/contentitem
20 Provides a template for the creation of a new external tool instance via the content-item message.
22 Classes required for JS:
25 Data attributes required for JS:
28 Context variables required for this template:
29 * url The URL the iframe has to load.
30 * postData The JSON object that contains the information to be POSTed for the ContentItemSelectionRequest.
32 Example context (json):
38 "title": "Sample title",
39 "text": "This is a description"
44 <div id="contentitem-container" class="contentitem-container">
45 <div class="contentitem-loading-container loading-screen">
47 <p class="loading-text">{{#str}} loadinghelp, moodle {{/str}}</p>
48 <p id="tool-loading-failed" class="hidden">{{#str}} register_warning, mod_lti {{/str}}</p>
50 <div class="contentitem-page">
51 <iframe id="contentitem-page-iframe" name="contentitem-page-iframe" class="hidden" tabindex="0">
53 <form target="contentitem-page-iframe" action="{{url}}" id="contentitem-request-form" method="post">
54 <input type="hidden" name="id" value="{{postData.id}}" />
55 <input type="hidden" name="course" value="{{postData.course}}" />
56 <input type="hidden" name="title" value="{{postData.title}}" />
57 <input type="hidden" name="text" value="{{postData.text}}" />
62 require(['jquery'], function($) {
63 var loadingContainer = $('.contentitem-loading-container');
64 var iframe = $('#contentitem-page-iframe');
65 var timeout = setTimeout(function () {
66 var failedContainer = $('#tool-loading-failed');
67 failedContainer.removeClass('hidden');
71 $('#contentitem-request-form').submit();
73 iframe.on('load', function() {
74 loadingContainer.addClass('hidden');
75 iframe.removeClass('hidden');
77 // Adjust iframe's width to the fit the container's width.
78 var containerWidth = $('div.contentitem-container').width();
79 $('#contentitem-page-iframe').width(containerWidth + 'px');
81 // Adjust iframe's height to 75% of the width.
82 var containerHeight = containerWidth * 0.75;
83 $('#contentitem-page-iframe').height(containerHeight + 'px');