/**
* DataToHtml.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 Tools from 'tinymce/core/api/util/Tools';
import Settings from '../api/Settings';
import HtmlToData from './HtmlToData';
import Mime from './Mime';
import UpdateHtml from './UpdateHtml';
import * as UrlPatterns from './UrlPatterns';
import VideoScript from './VideoScript';
const getIframeHtml = function (data) {
const allowFullscreen = data.allowFullscreen ? ' allowFullscreen="1"' : '';
return '';
};
const getFlashHtml = function (data) {
let html = '';
return html;
};
const getAudioHtml = function (data, audioTemplateCallback) {
if (audioTemplateCallback) {
return audioTemplateCallback(data);
} else {
return (
''
);
}
};
const getVideoHtml = function (data, videoTemplateCallback) {
if (videoTemplateCallback) {
return videoTemplateCallback(data);
} else {
return (
''
);
}
};
const getScriptHtml = function (data) {
return '';
};
const dataToHtml = function (editor, dataIn) {
const data = Tools.extend({}, dataIn);
if (!data.source1) {
Tools.extend(data, HtmlToData.htmlToData(Settings.getScripts(editor), data.embed));
if (!data.source1) {
return '';
}
}
if (!data.source2) {
data.source2 = '';
}
if (!data.poster) {
data.poster = '';
}
data.source1 = editor.convertURL(data.source1, 'source');
data.source2 = editor.convertURL(data.source2, 'source');
data.source1mime = Mime.guess(data.source1);
data.source2mime = Mime.guess(data.source2);
data.poster = editor.convertURL(data.poster, 'poster');
const pattern = UrlPatterns.matchPattern(data.source1);
if (pattern) {
data.source1 = pattern.url;
data.type = pattern.type;
data.allowFullscreen = pattern.allowFullscreen;
data.width = data.width || pattern.w;
data.height = data.height || pattern.h;
}
if (data.embed) {
return UpdateHtml.updateHtml(data.embed, data, true);
} else {
const videoScript = VideoScript.getVideoScriptMatch(Settings.getScripts(editor), data.source1);
if (videoScript) {
data.type = 'script';
data.width = videoScript.width;
data.height = videoScript.height;
}
const audioTemplateCallback = Settings.getAudioTemplateCallback(editor);
const videoTemplateCallback = Settings.getVideoTemplateCallback(editor);
data.width = data.width || 300;
data.height = data.height || 150;
Tools.each(data, function (value, key) {
data[key] = editor.dom.encode(value);
});
if (data.type === 'iframe') {
return getIframeHtml(data);
} else if (data.source1mime === 'application/x-shockwave-flash') {
return getFlashHtml(data);
} else if (data.source1mime.indexOf('audio') !== -1) {
return getAudioHtml(data, audioTemplateCallback);
} else if (data.type === 'script') {
return getScriptHtml(data);
} else {
return getVideoHtml(data, videoTemplateCallback);
}
}
};
export default {
dataToHtml
};