Refactoring

This commit is contained in:
gamonoid
2017-09-03 20:39:22 +02:00
parent af40881847
commit a7274d3cfd
5075 changed files with 238202 additions and 16291 deletions

View File

@@ -0,0 +1,7 @@
// Exports the "preview" plugin for usage with module loaders
// Usage:
// CommonJS:
// require('tinymce/plugins/preview')
// ES2015:
// import 'tinymce/plugins/preview'
require('./plugin.js');

View File

@@ -0,0 +1,101 @@
/**
* plugin.js
*
* Released under LGPL License.
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
*
* License: http://www.tinymce.com/license
* Contributing: http://www.tinymce.com/contributing
*/
/*global tinymce:true */
tinymce.PluginManager.add('preview', function(editor) {
var settings = editor.settings, sandbox = !tinymce.Env.ie;
editor.addCommand('mcePreview', function() {
editor.windowManager.open({
title: 'Preview',
width: parseInt(editor.getParam("plugin_preview_width", "650"), 10),
height: parseInt(editor.getParam("plugin_preview_height", "500"), 10),
html: '<iframe src="javascript:\'\'" frameborder="0"' + (sandbox ? ' sandbox="allow-scripts"' : '') + '></iframe>',
buttons: {
text: 'Close',
onclick: function() {
this.parent().parent().close();
}
},
onPostRender: function() {
var previewHtml, headHtml = '';
headHtml += '<base href="' + editor.documentBaseURI.getURI() + '">';
tinymce.each(editor.contentCSS, function(url) {
headHtml += '<link type="text/css" rel="stylesheet" href="' + editor.documentBaseURI.toAbsolute(url) + '">';
});
var bodyId = settings.body_id || 'tinymce';
if (bodyId.indexOf('=') != -1) {
bodyId = editor.getParam('body_id', '', 'hash');
bodyId = bodyId[editor.id] || bodyId;
}
var bodyClass = settings.body_class || '';
if (bodyClass.indexOf('=') != -1) {
bodyClass = editor.getParam('body_class', '', 'hash');
bodyClass = bodyClass[editor.id] || '';
}
var preventClicksOnLinksScript = (
'<script>' +
'document.addEventListener && document.addEventListener("click", function(e) {' +
'for (var elm = e.target; elm; elm = elm.parentNode) {' +
'if (elm.nodeName === "A") {' +
'e.preventDefault();' +
'}' +
'}' +
'}, false);' +
'</script> '
);
var dirAttr = editor.settings.directionality ? ' dir="' + editor.settings.directionality + '"' : '';
previewHtml = (
'<!DOCTYPE html>' +
'<html>' +
'<head>' +
headHtml +
'</head>' +
'<body id="' + bodyId + '" class="mce-content-body ' + bodyClass + '"' + dirAttr + '>' +
editor.getContent() +
preventClicksOnLinksScript +
'</body>' +
'</html>'
);
if (!sandbox) {
// IE 6-11 doesn't support data uris on iframes
// so I guess they will have to be less secure since we can't sandbox on those
// TODO: Use sandbox if future versions of IE supports iframes with data: uris.
var doc = this.getEl('body').firstChild.contentWindow.document;
doc.open();
doc.write(previewHtml);
doc.close();
} else {
this.getEl('body').firstChild.src = 'data:text/html;charset=utf-8,' + encodeURIComponent(previewHtml);
}
}
});
});
editor.addButton('preview', {
title: 'Preview',
cmd: 'mcePreview'
});
editor.addMenuItem('preview', {
text: 'Preview',
cmd: 'mcePreview',
context: 'view'
});
});

View File

@@ -0,0 +1 @@
tinymce.PluginManager.add("preview",function(e){var t=e.settings,n=!tinymce.Env.ie;e.addCommand("mcePreview",function(){e.windowManager.open({title:"Preview",width:parseInt(e.getParam("plugin_preview_width","650"),10),height:parseInt(e.getParam("plugin_preview_height","500"),10),html:'<iframe src="javascript:\'\'" frameborder="0"'+(n?' sandbox="allow-scripts"':"")+"></iframe>",buttons:{text:"Close",onclick:function(){this.parent().parent().close()}},onPostRender:function(){var r,i="";i+='<base href="'+e.documentBaseURI.getURI()+'">',tinymce.each(e.contentCSS,function(t){i+='<link type="text/css" rel="stylesheet" href="'+e.documentBaseURI.toAbsolute(t)+'">'});var o=t.body_id||"tinymce";o.indexOf("=")!=-1&&(o=e.getParam("body_id","","hash"),o=o[e.id]||o);var a=t.body_class||"";a.indexOf("=")!=-1&&(a=e.getParam("body_class","","hash"),a=a[e.id]||"");var s='<script>document.addEventListener && document.addEventListener("click", function(e) {for (var elm = e.target; elm; elm = elm.parentNode) {if (elm.nodeName === "A") {e.preventDefault();}}}, false);</script> ',l=e.settings.directionality?' dir="'+e.settings.directionality+'"':"";if(r="<!DOCTYPE html><html><head>"+i+'</head><body id="'+o+'" class="mce-content-body '+a+'"'+l+">"+e.getContent()+s+"</body></html>",n)this.getEl("body").firstChild.src="data:text/html;charset=utf-8,"+encodeURIComponent(r);else{var c=this.getEl("body").firstChild.contentWindow.document;c.open(),c.write(r),c.close()}}})}),e.addButton("preview",{title:"Preview",cmd:"mcePreview"}),e.addMenuItem("preview",{text:"Preview",cmd:"mcePreview",context:"view"})});