// Module ui/save-html // Saves content to HTML when asked to define( ["jquery", "core/utils"], function ($, utils) { var msg, doc, conf; var cleanup = function (rootEl) { $(".removeOnSave", rootEl).remove(); utils.removeReSpec(rootEl); }; return { show: function (ui, _conf, _doc, _msg) { msg = _msg, doc = _doc, conf = _conf; if (!conf.diffTool) conf.diffTool = "http://www5.aptest.com/standards/htmldiff/htmldiff.pl"; var supportsDownload = $("A")[0].download === "x" , self = this ; var $div = $("
") , buttonCSS = { background: "#eee" , border: "1px solid #000" , borderRadius: "5px" , padding: "5px" , margin: "5px" , display: "block" , width: "100%" , color: "#000" , textDecoration: "none" , textAlign: "center" , fontSize: "inherit" } , addButton = function (title, content, fileName, popupContent) { if (supportsDownload) { $("") .appendTo($div) .text(title) .css(buttonCSS) .attr({ href: "data:text/html;charset=utf-8," + encodeURIComponent(content) , download: fileName }) .click(function () { ui.closeModal(); }) ; } else { $("") .appendTo($div) .text(title) .css(buttonCSS) .click(function () { popupContent(); ui.closeModal(); }) ; } } ; addButton("Save as HTML", self.toString(), "Overview.html", function () { self.toHTMLSource(); }); addButton("Save as XHTML5", self.toXML(5), "Overview.xhtml", function () { self.toXHTMLSource(5); }); addButton("Save as XHTML 1.0", self.toXML(1), "Overview.xhtml", function () { self.toXHTMLSource(1); }); if (conf.diffTool && (conf.previousDiffURI || conf.previousURI)) { $("") .appendTo($div) .css(buttonCSS) .click(function () { self.toDiffHTML(); ui.closeModal(); }) ; } ui.freshModal("Save Snapshot", $div); } // convert the document to a string (HTML) , toString: function () { respecEvents.pub("save", "toString") var str = "\n"; } } // comments else if (8 === node.nodeType) { out += "\n\n"; } // text or cdata else if (3 === node.nodeType || 4 === node.nodeType) { out += noEsc[noEsc.length - 1] ? node.nodeValue : utils.xmlEscape(node.nodeValue); } // we don't handle other types else { msg.pub("warning", "Cannot handle serialising nodes of type: " + node.nodeType); } return out; }; str += dumpNode(rootEl) + ""; return str; } // create a diff marked version against the previousURI // strategy - open a window in which there is a form with the // data needed for diff marking - submit the form so that the response populates // page with the diff marked version , toDiffHTML: function () { respecEvents.pub("save", "toDiffHTML") var base = window.location.href.replace(/\/[^\/]*$/, "/") , str = "\n\n" + "Diff form\n" + "
\n" + "\n"; if (conf.previousDiffURI) { str += "\n"; } else { str += "\n"; } str += '\n' + '

Submitting, please wait...

' + "
\n"; var x = window.open(); x.document.write(str); x.document.close(); x.document.form.submit(); }, // popup the generated HTML content // toHTML: function () { // var x = window.open(); // x.document.write(this.toString()); // x.document.close(); // }, // popup the generated source toHTMLSource: function () { var x = window.open(); x.document.write("
" + utils.xmlEscape(this.toString()) + "
"); x.document.close(); }, // popup the generated XHTML content // toXHTML: function (mode) { // var x = window.open(); // x.document.write(this.toXML(mode)) ; // x.document.close(); // }, // popup the generated XHTML source toXHTMLSource: function (mode) { var x = window.open(); x.document.write("
" + utils.xmlEscape(this.toXML(mode)) + "
"); x.document.close(); } }; } );