Iframe.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * Iframe.js
  3. *
  4. * Copyright, Moxiecode Systems AB
  5. * Released under LGPL License.
  6. *
  7. * License: http://www.tinymce.com/license
  8. * Contributing: http://www.tinymce.com/contributing
  9. */
  10. /*jshint scripturl:true */
  11. /**
  12. * This class creates an iframe.
  13. *
  14. * @setting {String} url Url to open in the iframe.
  15. *
  16. * @-x-less Iframe.less
  17. * @class tinymce.ui.Iframe
  18. * @extends tinymce.ui.Widget
  19. */
  20. define("tinymce/ui/Iframe", [
  21. "tinymce/ui/Widget"
  22. ], function(Widget) {
  23. "use strict";
  24. return Widget.extend({
  25. /**
  26. * Renders the control as a HTML string.
  27. *
  28. * @method renderHtml
  29. * @return {String} HTML representing the control.
  30. */
  31. renderHtml: function() {
  32. var self = this;
  33. self.addClass('iframe');
  34. self.canFocus = false;
  35. /*eslint no-script-url:0 */
  36. return (
  37. '<iframe id="' + self._id + '" class="' + self.classes() + '" tabindex="-1" src="' +
  38. (self.settings.url || "javascript:\'\'") + '" frameborder="0"></iframe>'
  39. );
  40. },
  41. /**
  42. * Setter for the iframe source.
  43. *
  44. * @method src
  45. * @param {String} src Source URL for iframe.
  46. */
  47. src: function(src) {
  48. this.getEl().src = src;
  49. },
  50. /**
  51. * Inner HTML for the iframe.
  52. *
  53. * @method html
  54. * @param {String} html HTML string to set as HTML inside the iframe.
  55. * @param {function} callback Optional callback to execute when the iframe body is filled with contents.
  56. * @return {tinymce.ui.Iframe} Current iframe control.
  57. */
  58. html: function(html, callback) {
  59. var self = this, body = this.getEl().contentWindow.document.body;
  60. // Wait for iframe to initialize IE 10 takes time
  61. if (!body) {
  62. setTimeout(function() {
  63. self.html(html);
  64. }, 0);
  65. } else {
  66. body.innerHTML = html;
  67. if (callback) {
  68. callback();
  69. }
  70. }
  71. return this;
  72. }
  73. });
  74. });