Explorar o código

优化单页打印

Minho %!s(int64=7) %!d(string=hai) anos
pai
achega
b18147f32c
Modificáronse 3 ficheiros con 15 adicións e 19 borrados
  1. 3 2
      static/css/print.css
  2. 11 8
      static/js/kancloud.js
  3. 1 9
      views/document/default_read.tpl

+ 3 - 2
static/css/print.css

@@ -1,6 +1,7 @@
 body {font-size: 12pt !important;}
-.m-manual .manual-left,.navbar {display: none;}
-.m-manual .manual-right{left: 0;}
+.m-manual .manual-left,.navbar {display: none;height: 0 !important; width: 0!important;}
+.m-manual .manual-right{position: relative;left: 0 !important; top: 0;}
+.manual-article .article-content{ min-width: initial !important;max-width: initial !important; width: inherit !important;padding: auto !important;}
 pre, code {white-space: pre-wrap !important;word-wrap: break-word !important;}
 a:link, a:visited {color: blue !important;text-decoration: underline !important;}
 body a:link:after, body a:visited:after {content: " (" attr(href) ") ";}

+ 11 - 8
static/js/kancloud.js

@@ -72,14 +72,17 @@ function loadDocument($url, $id, $callback) {
  * 初始化代码高亮
  */
 function initHighlighting() {
-    $('pre,pre.ql-syntax').each(function (i, block) {
-        if($(this).hasClass('prettyprinted')){
-            return;
-        }
-        hljs.highlightBlock(block);
-    });
-    hljs.initLineNumbersOnLoad();
-
+    try {
+        $('pre,pre.ql-syntax').each(function (i, block) {
+            if ($(this).hasClass('prettyprinted')) {
+                return;
+            }
+            hljs.highlightBlock(block);
+        });
+        hljs.initLineNumbersOnLoad();
+    }catch (e){
+        console.log(e);
+    }
 }
 
 

+ 1 - 9
views/document/default_read.tpl

@@ -46,7 +46,7 @@
                 <span style="font-size: 12px;font-weight: 100;"></span>
             </div>
             <div class="navbar-header pull-right manual-menu">
-                <button id="printSinglePage" class="btn btn-default" style="margin-right: 10px;"><i class="fa fa-print"></i> 打印</button>
+                <a href="javascript:window.print();" id="printSinglePage" class="btn btn-default" style="margin-right: 10px;"><i class="fa fa-print"></i> 打印</a>
                 {{if gt .Member.MemberId 0}}
                 {{if gt .Model.RelationshipId 0}}
                 {{if eq .Model.RoleId 0 1 2}}
@@ -295,14 +295,6 @@ $(function () {
             return $(body).highlight(window.keyword);
         });
     });
-    //打印设置
-    $("#printSinglePage").on("click",function () {
-        var body = $("body");
-        var bodyContent = body.html();
-        body.html($(".manual-right").html());
-       window.print();
-        body.html(bodyContent);
-    });
 });
 
 </script>