embedded_chat.mustache 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <%
  2. # Copyright (C) 2013 - present Instructure, Inc.
  3. #
  4. # This file is part of Canvas.
  5. #
  6. # Canvas is free software: you can redistribute it and/or modify it under
  7. # the terms of the GNU Affero General Public License as published by the Free
  8. # Software Foundation, version 3 of the License.
  9. #
  10. # Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
  11. # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. # A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. # details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License along
  16. # with this program. If not, see <http://www.gnu.org/licenses/>.
  17. %>
  18. <% launch_token = SecureRandom.uuid %>
  19. <script>
  20. window.addEventListener('message', function(event) {
  21. var iframes = document.getElementsByTagName('iframe'),
  22. iframe;
  23. for (var i=0, l=iframes.length; i < l; i++) {
  24. if (iframes[i].contentWindow === event.source) {
  25. iframe = iframes[i];
  26. break;
  27. }
  28. }
  29. if (!iframe) {return;}
  30. var data = JSON.parse(event.data)
  31. if (data.request_launch_url) {
  32. event.source.postMessage(JSON.stringify({launch_url: iframe.getAttribute('data-launch-url')}), '*');
  33. return;
  34. }
  35. if (data.quicklaunch) {
  36. event.source.postMessage(JSON.stringify({quicklaunch: <%= embedded_chat_quicklaunch_params.to_json.html_safe %>}), '*');
  37. return;
  38. }
  39. if (!data.width && data.width !== 0) {return;}
  40. if (data.width > document.documentElement.clientWidth / 2) {return;}
  41. iframe.style.width = data.width+'px';
  42. iframe.style.height = data.height+'px';
  43. iframe.style.bottom = data.bottom+'px';
  44. }, false);
  45. </script>
  46. <div data-tool-wrapper-id="<%= launch_token %>">
  47. <iframe
  48. data-launch-url="<%= full_url(context_url(@context, :context_external_tool_resource_selection_url, active_external_tool_by_id('chat').id, launch_type: 'course_navigation', launch_token: launch_token)) %>"
  49. style="position: fixed; right: 0; bottom: 0; width: 0; height: 0; border: 1px solid #808080; z-index: 100"
  50. src="<%= embedded_chat_url %>"
  51. title="{{#t}}Chat{{/t}}"></iframe>
  52. </div>