diff --git a/src/js/template-loader.js b/src/js/template-loader.js index cc6f5eb96..bfe6a93da 100644 --- a/src/js/template-loader.js +++ b/src/js/template-loader.js @@ -308,7 +308,7 @@ var templateCompiler = function(performanceAwareCaller, templateUrlConverter, te plugins.push(templatesPlugin); // initialize the viewModel object based on the content model. - var viewModel = performanceAwareCaller('initializeViewmodel', initializeViewmodel.bind(this, content, blockModels.blockList, templateUrlConverter, galleryUrl, modelImporter)); + var viewModel = performanceAwareCaller('initializeViewmodel', initializeViewmodel.bind(this, content, blockModels.blockList, templateUrlConverter, galleryUrl, modelImporter, exportCleanedHTML)); viewModel.metadata = metadata; // let's run some version check on template and editor used to build the model being loaded. @@ -367,6 +367,7 @@ var isCompatible = function(detailedException) { }); // Since 0.18 some of our dependencies use block level functions in strict-mode: // They throw a parsing error in IE10 and Safari 8-9 that we previously supported. + /*jslint evil: true */ checkFeature('Block-level functions', function() { try { new Function('\'use strict\'; { function g() { } }'); @@ -406,13 +407,42 @@ var isCompatible = function(detailedException) { } }; -var checkBadBrowserExtensions = function() { - var id = 'checkbadbrowsersframe'; - var origTpl = ko.bindingHandlers.bindIframe.tpl; - ko.bindingHandlers.bindIframe.tpl = "\r\n\r\nA\r\n\r\n

B

\r\n\r\n"; +var cleanUpMap = { + '': '', + ' data-gr-c-s-loaded="true"': '', + '': '', + '': '', +}; + +var cleanUpKnownExtensionsGarbage = function(input) { + for (var search in cleanUpMap) input = input.replace(search, cleanUpMap[search]); + return input; +}; + + +function conditional_restore(html) { + return html.replace(/]* condition="([^"]*)"[^>]*>([\s\S]*?)<\/replacedcc>/g, function(match, condition, body) { + var dd = '/g, '') // restore closing tags (including lost tags) + .replace(/>/g, '/>') // restore selfclosing tags + .replace(//,'') // remove content before start + .replace(/.*$/,''); // remove content after end + dd += ''; + return dd; + }); +} + +function exportCleanedHTML(viewModel) { + var id = 'exportframe'; $('body').append(''); var frameEl = global.document.getElementById(id); - ko.applyBindings({ content: "dummy content" }, frameEl); + ko.applyBindings(viewModel, frameEl); + + ko.cleanNode(frameEl); + + if (viewModel.inline) viewModel.inline(frameEl.contentWindow.document); + // Obsolete method didn't work on IE11 when using "HTML5 doctype": // var docType = new XMLSerializer().serializeToString(global.document.doctype); var node = frameEl.contentWindow.document.doctype; @@ -421,15 +451,45 @@ var checkBadBrowserExtensions = function() { (!node.publicId && node.systemId ? ' SYSTEM' : '') + (node.systemId ? ' "' + node.systemId + '"' : '') + '>'; var content = docType + "\n" + frameEl.contentWindow.document.documentElement.outerHTML; - ko.cleanNode(frameEl); ko.removeNode(frameEl); + + content = content.replace(/