froala-editor
Version:
The next generation Javascript WYSIWYG HTML rich text editor made by devs for devs. High performance and modern design make it easy to use for developers and loved by users.
7 lines (6 loc) • 2.87 kB
JavaScript
/*!
* froala_editor v4.7.0 (https://www.froala.com/wysiwyg-editor)
* License https://froala.com/wysiwyg-editor/terms/
* Copyright 2014-2025 Froala Labs
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("froala-editor")):"function"==typeof define&&define.amd?define(["froala-editor"],t):t(e.FroalaEditor)}(this,function(e){"use strict";e=e&&e.hasOwnProperty("default")?e["default"]:e,Object.assign(e.DEFAULTS,{html2pdf:window.html2pdf}),e.PLUGINS.print=function(s){return{run:function e(){!function a(e){var t=s.opts.useClasses;t||s.$el.addClass("print");var n=s.html.get();t||s.$el.removeClass("print");var o=null;s.shared.print_iframe?o=s.shared.print_iframe:((o=document.createElement("iframe")).name="fr-print",o.style.position="fixed",o.style.top="0",o.style.left="-9999px",o.style.height="100%",o.style.width="0",o.style.overflow="hidden",o.style["z-index"]="2147483647",o.style.tabIndex="-1",s.events.on("shared.destroy",function(){o.remove()}),s.shared.print_iframe=o);try{document.body.removeChild(o)}catch(l){}document.body.appendChild(o);var i=function(){e(),o.removeEventListener("load",i)};o.addEventListener("load",i);var r=o.contentWindow;r.document.open(),r.document.write("<!DOCTYPE html><html "+(s.opts.documentReady?'style="margin: 0; padding: 0;"':"")+"><head><title>"+document.title+"</title>"),Array.prototype.forEach.call(document.querySelectorAll("style"),function(e){e=e.cloneNode(!0),r.document.write(e.outerHTML)});var d=document.querySelectorAll("link[rel=stylesheet]");Array.prototype.forEach.call(d,function(e){var t=document.createElement("link");t.rel=e.rel,t.href=e.href,t.media="print",t.type="text/css",t.media="all",r.document.write(t.outerHTML)}),r.document.write('</head><body style="height:auto;text-align: '+("rtl"==s.opts.direction?"right":"left")+"; direction: "+s.opts.direction+"; "+(s.opts.documentReady?" padding: 2cm; width: 17cm; margin: 0;":"")+'"><div class="fr-view">'),r.document.write(n),r.document.write("</div></body></html>"),r.document.close()}(function(){setTimeout(function(){s.events.disableBlur(),window.frames["fr-print"].focus(),window.frames["fr-print"].print(),s.$win.get(0).focus(),s.events.disableBlur(),s.events.focus()},0)})},toPDF:function t(){s.opts.html2pdf&&(s.$el.css("text-align","left"),s.$el.addClass("pdf-export"),s.opts.html2pdf().set({margin:[10,20],html2canvas:{useCORS:!0}}).from(s.el).save(),setTimeout(function(){s.$el.css("text-align",""),s.$el.removeClass("pdf-export")},100))}}},e.DefineIcon("print",{NAME:"print",SVG_KEY:"print"}),e.RegisterCommand("print",{title:"Print",undo:!1,focus:!1,plugin:"print",callback:function(){this.print.run()}}),e.DefineIcon("getPDF",{NAME:"file-pdf-o",FA5NAME:"file-pdf",SVG_KEY:"pdfExport"}),e.RegisterCommand("getPDF",{title:"Download PDF",type:"button",focus:!1,undo:!1,callback:function(){this.print.toPDF()}})});