diff --git a/data/navs.json b/data/navs.json index b756b2f..b55a668 100644 --- a/data/navs.json +++ b/data/navs.json @@ -377,6 +377,10 @@ { "title": "okLayx", "href": "pages/tripartite/okLayx.html" + }, + { + "title": "jqprint", + "href": "pages/tripartite/jqprint.html" } ] }, diff --git a/lib/layui/lay/okmodules/jqprint.js b/lib/layui/lay/okmodules/jqprint.js new file mode 100644 index 0000000..5f4fa03 --- /dev/null +++ b/lib/layui/lay/okmodules/jqprint.js @@ -0,0 +1,139 @@ +// ----------------------------------------------------------------------- +// Eros Fratini - eros@recoding.it +// jqprint 0.3 +// +// - 19/06/2009 - some new implementations, added Opera support +// - 11/05/2009 - first sketch +// +// Printing plug-in for jQuery, evolution of jPrintArea: http://plugins.jquery.com/project/jPrintArea +// requires jQuery 1.3.x +// +// Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php +//------------------------------------------------------------------------ +"use strict"; +layui.define(["jquery"], function (exports) { + var $ = layui.jquery; + var opt; + $.fn.jqprint = function (options) { + opt = $.extend({}, $.fn.jqprint.defaults, options); + + var $element = (this instanceof layui.jquery) ? this : $(this); + + if (opt.operaSupport && $.support.opera) + { + var tab = window.open("","jqPrint-preview"); + tab.document.open(); + + var doc = tab.document; + } + else + { + var $iframe = $(""); + + if (!opt.debug) { $iframe.css({ position: "absolute", width: "0px", height: "0px", left: "-600px", top: "-600px" }); } + + $iframe.appendTo("body"); + var doc = $iframe[0].contentWindow.document; + } + + if (opt.importCSS) + { + if ($("link[media=print]").length > 0) + { + $("link[media=print]").each( function() { + doc.write(""); + }); + } + else + { + $("link").each( function() { + doc.write(""); + }); + } + } + + if (opt.printContainer) { doc.write($element.outer()); } + else { $element.each( function() { doc.write($(this).html()); }); } + + doc.close(); + + (opt.operaSupport && $.support.opera ? tab : $iframe[0].contentWindow).focus(); + setTimeout( function() { (opt.operaSupport && $.support.opera ? tab : $iframe[0].contentWindow).print(); if (tab) { tab.close(); } }, 1000); + } + + $.fn.jqprint.defaults = { + debug: false, + importCSS: true, + printContainer: true, + operaSupport: true + }; + + // Thanks to 9__, found at http://users.livejournal.com/9__/380664.html + $.fn.outer = function() { + return $($('
').html(this.clone())).html(); + } + + exports("jqprint", {}); +}) +/*(function($) { + var opt; + + $.fn.jqprint = function (options) { + opt = $.extend({}, $.fn.jqprint.defaults, options); + + var $element = (this instanceof $) ? this : $(this); + + if (opt.operaSupport && $.browser.opera) + { + var tab = window.open("","jqPrint-preview"); + tab.document.open(); + + var doc = tab.document; + } + else + { + var $iframe = $(""); + + if (!opt.debug) { $iframe.css({ position: "absolute", width: "0px", height: "0px", left: "-600px", top: "-600px" }); } + + $iframe.appendTo("body"); + var doc = $iframe[0].contentWindow.document; + } + + if (opt.importCSS) + { + if ($("link[media=print]").length > 0) + { + $("link[media=print]").each( function() { + doc.write(""); + }); + } + else + { + $("link").each( function() { + doc.write(""); + }); + } + } + + if (opt.printContainer) { doc.write($element.outer()); } + else { $element.each( function() { doc.write($(this).html()); }); } + + doc.close(); + + (opt.operaSupport && $.browser.opera ? tab : $iframe[0].contentWindow).focus(); + setTimeout( function() { (opt.operaSupport && $.browser.opera ? tab : $iframe[0].contentWindow).print(); if (tab) { tab.close(); } }, 1000); + } + + $.fn.jqprint.defaults = { + debug: false, + importCSS: true, + printContainer: true, + operaSupport: true + }; + + // Thanks to 9__, found at http://users.livejournal.com/9__/380664.html + $.fn.outer = function() { + return $($('').html(this.clone())).html(); + } +})(jQuery);*/ diff --git a/lib/layui/layui.js b/lib/layui/layui.js index 24a9161..bd87d5e 100644 --- a/lib/layui/layui.js +++ b/lib/layui/layui.js @@ -44,6 +44,7 @@ if (!Object.assign) { "okSweetAlert2": "okmodules/okSweetAlert2", "okHoliday": "okmodules/okHoliday", "okLayx": "okmodules/okLayx", + "jqprint": "okmodules/jqprint", }; var modulePath = Object.assign({ layer: "modules/layer", @@ -318,4 +319,4 @@ if (!Object.assign) { c && layui.each(t, s))) }), i) }, e.layui = new r -}(window); \ No newline at end of file +}(window); diff --git a/pages/tripartite/jqprint.html b/pages/tripartite/jqprint.html new file mode 100644 index 0000000..4766579 --- /dev/null +++ b/pages/tripartite/jqprint.html @@ -0,0 +1,69 @@ + + + + +++打印 okPrint
+1. 创建对象
+2. 调用对象的start方法执行
+
+layui.use(['code', 'jquery', 'jqprint'], function () {
+ var $ = layui.jquery,
+ code = layui.code;
+
+ $('#btnPrint').click(function (){
+ $('#content').jqprint();
+ });
+});
+
+