/** * InitIframe.js * * Released under LGPL License. * Copyright (c) 1999-2017 Ephox Corp. All rights reserved * * License: http://www.tinymce.com/license * Contributing: http://www.tinymce.com/contributing */ import { Element, Attr, Css } from '@ephox/sugar'; import Env from '../api/Env'; import Settings from '../api/Settings'; import DOMUtils from '../api/dom/DOMUtils'; import InitContentBody from './InitContentBody'; import Uuid from '../util/Uuid'; const DOM = DOMUtils.DOM; const relaxDomain = function (editor, ifr) { // Domain relaxing is required since the user has messed around with document.domain // This only applies to IE 11 other browsers including Edge seems to handle document.domain if (document.domain !== window.location.hostname && Env.ie && Env.ie < 12) { const bodyUuid = Uuid.uuid('mce'); editor[bodyUuid] = function () { InitContentBody.initContentBody(editor); }; /*eslint no-script-url:0 */ const domainRelaxUrl = 'javascript:(function(){' + 'document.open();document.domain="' + document.domain + '";' + 'var ed = window.parent.tinymce.get("' + editor.id + '");document.write(ed.iframeHTML);' + 'document.close();ed.' + bodyUuid + '(true);})()'; DOM.setAttrib(ifr, 'src', domainRelaxUrl); return true; } return false; }; const normalizeHeight = function (height) { const normalizedHeight = typeof height === 'number' ? height + 'px' : height; return normalizedHeight ? normalizedHeight : ''; }; const createIframeElement = function (id, title, height, customAttrs) { const iframe = Element.fromTag('iframe'); Attr.setAll(iframe, customAttrs); Attr.setAll(iframe, { id: id + '_ifr', frameBorder: '0', allowTransparency: 'true', title }); Css.setAll(iframe, { width: '100%', height: normalizeHeight(height), display: 'block' // Important for Gecko to render the iframe correctly }); return iframe; }; const getIframeHtml = function (editor) { let bodyId, bodyClass, iframeHTML; iframeHTML = Settings.getDocType(editor) + '
'; // We only need to override paths if we have to // IE has a bug where it remove site absolute urls to relative ones if this is specified if (Settings.getDocumentBaseUrl(editor) !== editor.documentBaseUrl) { iframeHTML += '