wyq il y a 3 ans
Parent
commit
bb8c2850ba

+ 9 - 0
src/css/print.css

@@ -0,0 +1,9 @@
+
+@media print {
+  body{
+    background: #ffffff;
+  }
+  .scaletitle{
+    display: block;
+  }
+}

+ 2 - 2
src/css/staticInfo.less

@@ -343,6 +343,7 @@
   line-height: 28px;
   margin: 30px 0 8px 0;
   text-align: center;
+  display: none;
 }
 .scaleBox{
   border-bottom: none;
@@ -429,7 +430,6 @@
     min-width: 100px;
     display: inline-block;
     .result_left{
-      display: inline-block;
       float: left;
       .hel{
         background: #2C96E5;
@@ -442,7 +442,6 @@
     }
     .result_title{
       max-width: 85%;
-      display: inline-block;
       float: left;
     }
   }
@@ -502,6 +501,7 @@
 #Print{
   width: 100%!important;
   overflow-x: hidden;
+  overflow: auto;
 }
 .scale{
   .infos-box{

+ 4 - 1
src/html/staticInfo.html

@@ -3,6 +3,7 @@
 
 <head>
   <meta charset="utf-8">
+  <!-- <link href="../css/print.css" media="print" rel="stylesheet" /> -->
   <style>
 
   </style>
@@ -59,14 +60,16 @@
   <div class=" container disCopy scale">
     <div class="content">
       <div class="infos" id="Print">
+        <p class="scaletitle"></p>
         <div class="infos-box"></div>
       </div>
+      
     </div>
   </div>
   <div class="btmFix"></div>
 </body>
 
- 
+
 
 
 </html>

+ 237 - 0
src/js/jQuery.print.js

@@ -0,0 +1,237 @@
+/* @license 
+ * jQuery.print, version 1.3.2
+ *  (c) Sathvik Ponangi, Doers' Guild
+ * Licence: CC-By (http://creativecommons.org/licenses/by/3.0/)
+ *--------------------------------------------------------------------------*/
+const $ = require("jquery");
+(function ($) {
+    "use strict";
+    // A nice closure for our definitions
+    function getjQueryObject(string) {
+        // Make string a vaild jQuery thing
+        var jqObj = $("");
+        try {
+            jqObj = $(string)
+                .clone();
+        } catch (e) {
+            jqObj = $("<span />")
+                .html(string);
+        }
+        return jqObj;
+    }
+
+    function printFrame(frameWindow) {
+        // Print the selected window/iframe
+        var def = $.Deferred();
+        try {
+            setTimeout(function () {
+                // Fix for IE : Allow it to render the iframe
+                frameWindow.focus();
+                try {
+                    // Fix for IE11 - printng the whole page instead of the iframe content
+                    if (!frameWindow.document.execCommand('print', false, null)) {
+                        // document.execCommand returns false if it failed -http://stackoverflow.com/a/21336448/937891
+                        frameWindow.print();
+                    }
+                } catch (e) {
+                    frameWindow.print();
+                }
+                frameWindow.close();
+                def.resolve();
+            }, 250);
+        } catch (err) {
+            def.reject(err);
+        }
+        return def;
+    }
+
+    function printContentInNewWindow(content) {
+        // Open a new window and print selected content
+        var w = window.open();
+        w.document.write(content);
+        w.document.close();
+        return printFrame(w);
+    }
+
+    function isNode(o) {
+        /* http://stackoverflow.com/a/384380/937891 */
+        return !!(typeof Node === "object" ? o instanceof Node : o && typeof o === "object" && typeof o.nodeType === "number" && typeof o.nodeName === "string");
+    }
+    $.print = $.fn.print = function () {
+        // Print a given set of elements
+        var options, $this, self = this;
+        // console.log("Printing", this, arguments);
+        if (self instanceof $) {
+            // Get the node if it is a jQuery object
+            self = self.get(0);
+        }
+        if (isNode(self)) {
+            // If `this` is a HTML element, i.e. for
+            // $(selector).print()
+            $this = $(self);
+            if (arguments.length > 0) {
+                options = arguments[0];
+            }
+        } else {
+            if (arguments.length > 0) {
+                // $.print(selector,options)
+                $this = $(arguments[0]);
+                if (isNode($this[0])) {
+                    if (arguments.length > 1) {
+                        options = arguments[1];
+                    }
+                } else {
+                    // $.print(options)
+                    options = arguments[0];
+                    $this = $("html");
+                }
+            } else {
+                // $.print()
+                $this = $("html");
+            }
+        }
+        // Default options
+        var defaults = {
+            globalStyles: true,
+            mediaPrint: false,
+            stylesheet: null,
+            noPrintSelector: ".no-print",
+            iframe: true,
+            append: null,
+            prepend: null,
+            manuallyCopyFormValues: true,
+            deferred: $.Deferred()
+        };
+        // Merge with user-options
+        options = $.extend({}, defaults, (options || {}));
+        var $styles = $("");
+        if (options.globalStyles) {
+            // Apply the stlyes from the current sheet to the printed page
+            $styles = $("style, link, meta, title");
+        } else if (options.mediaPrint) {
+            // Apply the media-print stylesheet
+            $styles = $("link[media=print]");
+        }
+        if (options.stylesheet) {
+            // Add a custom stylesheet if given
+            $styles = $.merge($styles, $('<link rel="stylesheet" href="' + options.stylesheet + '">'));
+        }
+        // Create a copy of the element to print
+        var copy = $this.clone();
+        // Wrap it in a span to get the HTML markup string
+        copy = $("<span/>")
+            .append(copy);
+        // Remove unwanted elements
+        copy.find(options.noPrintSelector)
+            .remove();
+        // Add in the styles
+        copy.append($styles.clone());
+        // Appedned content
+        copy.append(getjQueryObject(options.append));
+        // Prepended content
+        copy.prepend(getjQueryObject(options.prepend));
+        if (options.manuallyCopyFormValues) {
+            // Manually copy form values into the HTML for printing user-modified input fields
+            // http://stackoverflow.com/a/26707753
+            copy.find("input")
+                .each(function () {
+                    var $field = $(this);
+                    if ($field.is("[type='radio']") || $field.is("[type='checkbox']")) {
+                        if ($field.prop("checked")) {
+                            $field.attr("checked", "checked");
+                        }
+                    } else {
+                        $field.attr("value", $field.val());
+                    }
+                });
+            copy.find("select").each(function () {
+                var $field = $(this);
+                $field.find(":selected").attr("selected", "selected");
+            });
+            copy.find("textarea").each(function () {
+                // Fix for https://github.com/DoersGuild/jQuery.print/issues/18#issuecomment-96451589
+                var $field = $(this);
+                $field.text($field.val());
+            });
+        }
+        // Get the HTML markup string
+        var content = copy.html();
+        // Notify with generated markup & cloned elements - useful for logging, etc
+        try {
+            options.deferred.notify('generated_markup', content, copy);
+        } catch (err) {
+            console.warn('Error notifying deferred', err);
+        }
+        // Destroy the copy
+        copy.remove();
+        if (options.iframe) {
+            // Use an iframe for printing
+            try {
+                var $iframe = $(options.iframe + "");
+                var iframeCount = $iframe.length;
+                if (iframeCount === 0) {
+                    // Create a new iFrame if none is given
+                    $iframe = $('<iframe height="0" width="0" border="0" wmode="Opaque"/>')
+                        .prependTo('body')
+                        .css({
+                            "position": "absolute",
+                            "top": -999,
+                            "left": -999
+                        });
+                }
+                var w, wdoc;
+                w = $iframe.get(0);
+                w = w.contentWindow || w.contentDocument || w;
+                wdoc = w.document || w.contentDocument || w;
+                wdoc.open();
+                wdoc.write(content);
+                wdoc.close();
+                printFrame(w)
+                    .done(function () {
+                        // Success
+                        setTimeout(function () {
+                            // Wait for IE
+                            if (iframeCount === 0) {
+                                // Destroy the iframe if created here
+                                $iframe.remove();
+                            }
+                        }, 100);
+                    })
+                    .fail(function (err) {
+                        // Use the pop-up method if iframe fails for some reason
+                        console.error("Failed to print from iframe", err);
+                        printContentInNewWindow(content);
+                    })
+                    .always(function () {
+                        try {
+                            options.deferred.resolve();
+                        } catch (err) {
+                            console.warn('Error notifying deferred', err);
+                        }
+                    });
+            } catch (e) {
+                // Use the pop-up method if iframe fails for some reason
+                console.error("Failed to print from iframe", e.stack, e.message);
+                printContentInNewWindow(content)
+                    .always(function () {
+                        try {
+                            options.deferred.resolve();
+                        } catch (err) {
+                            console.warn('Error notifying deferred', err);
+                        }
+                    });
+            }
+        } else {
+            // Use a new window for printing
+            printContentInNewWindow(content)
+                .always(function () {
+                    try {
+                        options.deferred.resolve();
+                    } catch (err) {
+                        console.warn('Error notifying deferred', err);
+                    }
+                });
+        }
+        return this;
+    };
+})($);

+ 225 - 59
src/js/jquery.PrintArea.js

@@ -1,71 +1,237 @@
-// -----------------------------------------------------------------------
-// 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
-//------------------------------------------------------------------------
+/* @license 
+ * jQuery.print, version 1.3.2
+ *  (c) Sathvik Ponangi, Doers' Guild
+ * Licence: CC-By (http://creativecommons.org/licenses/by/3.0/)
+ *--------------------------------------------------------------------------*/
 const $ = require("jquery");
 (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();
+  "use strict";
+  // A nice closure for our definitions
+  function getjQueryObject(string) {
+    // Make string a vaild jQuery thing
+    var jqObj = $("");
+    try {
+      jqObj = $(string)
+        .clone();
+    } catch (e) {
+      jqObj = $("<span />")
+        .html(string);
+    }
+    return jqObj;
+  }
 
-      var doc = tab.document;
+  function printFrame(frameWindow) {
+    // Print the selected window/iframe
+    var def = $.Deferred();
+    try {
+      setTimeout(function () {
+        // Fix for IE : Allow it to render the iframe
+        frameWindow.focus();
+        try {
+          // Fix for IE11 - printng the whole page instead of the iframe content
+          if (!frameWindow.document.execCommand('print', false, null)) {
+            // document.execCommand returns false if it failed -http://stackoverflow.com/a/21336448/937891
+            frameWindow.print();
+          }
+        } catch (e) {
+          frameWindow.print();
+        }
+        frameWindow.close();
+        def.resolve();
+      }, 250);
+    } catch (err) {
+      def.reject(err);
     }
-    else {
-      var $iframe = $("<iframe  />");
+    return def;
+  }
 
-      if (!opt.debug) { $iframe.css({ position: "absolute", width: "0px", height: "0px", left: "-600px", top: "-600px" }); }
+  function printContentInNewWindow(content) {
+    // Open a new window and print selected content
+    var w = window.open();
+    w.document.write(content);
+    w.document.close();
+    return printFrame(w);
+  }
 
-      $iframe.appendTo("body");
-      var doc = $iframe[0].contentWindow.document;
+  function isNode(o) {
+    /* http://stackoverflow.com/a/384380/937891 */
+    return !!(typeof Node === "object" ? o instanceof Node : o && typeof o === "object" && typeof o.nodeType === "number" && typeof o.nodeName === "string");
+  }
+  $.print = $.fn.print = function () {
+    // Print a given set of elements
+    var options, $this, self = this;
+    // console.log("Printing", this, arguments);
+    if (self instanceof $) {
+      // Get the node if it is a jQuery object
+      self = self.get(0);
     }
-
-    if (opt.importCSS) {
-      if ($("link[media=print]").length > 0) {
-        $("link[media=print]").each(function () {
-          doc.write("<link type='text/css' rel='stylesheet' href='" + $(this).attr("href") + "' media='print' />");
-        });
+    if (isNode(self)) {
+      // If `this` is a HTML element, i.e. for
+      // $(selector).print()
+      $this = $(self);
+      if (arguments.length > 0) {
+        options = arguments[0];
+      }
+    } else {
+      if (arguments.length > 0) {
+        // $.print(selector,options)
+        $this = $(arguments[0]);
+        if (isNode($this[0])) {
+          if (arguments.length > 1) {
+            options = arguments[1];
+          }
+        } else {
+          // $.print(options)
+          options = arguments[0];
+          $this = $("html");
+        }
+      } else {
+        // $.print()
+        $this = $("html");
       }
-      else {
-        $("link").each(function () {
-          doc.write("<link type='text/css' rel='stylesheet' href='" + $(this).attr("href") + "' />");
+    }
+    // Default options
+    var defaults = {
+      globalStyles: true,
+      mediaPrint: false,
+      stylesheet: null,
+      noPrintSelector: ".no-print",
+      iframe: true,
+      append: null,
+      prepend: null,
+      manuallyCopyFormValues: true,
+      deferred: $.Deferred()
+    };
+    // Merge with user-options
+    options = $.extend({}, defaults, (options || {}));
+    var $styles = $("");
+    if (options.globalStyles) {
+      // Apply the stlyes from the current sheet to the printed page
+      $styles = $("style, link, meta, title");
+    } else if (options.mediaPrint) {
+      // Apply the media-print stylesheet
+      $styles = $("link[media=print]");
+    }
+    if (options.stylesheet) {
+      // Add a custom stylesheet if given
+      $styles = $.merge($styles, $('<link rel="stylesheet" href="' + options.stylesheet + '">'));
+    }
+    // Create a copy of the element to print
+    var copy = $this.clone();
+    // Wrap it in a span to get the HTML markup string
+    copy = $("<span/>")
+      .append(copy);
+    // Remove unwanted elements
+    copy.find(options.noPrintSelector)
+      .remove();
+    // Add in the styles
+    copy.append($styles.clone());
+    // Appedned content
+    copy.append(getjQueryObject(options.append));
+    // Prepended content
+    copy.prepend(getjQueryObject(options.prepend));
+    if (options.manuallyCopyFormValues) {
+      // Manually copy form values into the HTML for printing user-modified input fields
+      // http://stackoverflow.com/a/26707753
+      copy.find("input")
+        .each(function () {
+          var $field = $(this);
+          if ($field.is("[type='radio']") || $field.is("[type='checkbox']")) {
+            if ($field.prop("checked")) {
+              $field.attr("checked", "checked");
+            }
+          } else {
+            $field.attr("value", $field.val());
+          }
         });
+      copy.find("select").each(function () {
+        var $field = $(this);
+        $field.find(":selected").attr("selected", "selected");
+      });
+      copy.find("textarea").each(function () {
+        // Fix for https://github.com/DoersGuild/jQuery.print/issues/18#issuecomment-96451589
+        var $field = $(this);
+        $field.text($field.val());
+      });
+    }
+    // Get the HTML markup string
+    var content = copy.html();
+    // Notify with generated markup & cloned elements - useful for logging, etc
+    try {
+      options.deferred.notify('generated_markup', content, copy);
+    } catch (err) {
+      console.warn('Error notifying deferred', err);
+    }
+    // Destroy the copy
+    copy.remove();
+    if (options.iframe) {
+      // Use an iframe for printing
+      try {
+        var $iframe = $(options.iframe + "");
+        var iframeCount = $iframe.length;
+        if (iframeCount === 0) {
+          // Create a new iFrame if none is given
+          $iframe = $('<iframe height="0" width="0" border="0" wmode="Opaque"/>')
+            .prependTo('body')
+            .css({
+              "position": "absolute",
+              "top": -999,
+              "left": -999
+            });
+        }
+        var w, wdoc;
+        w = $iframe.get(0);
+        w = w.contentWindow || w.contentDocument || w;
+        wdoc = w.document || w.contentDocument || w;
+        wdoc.open();
+        wdoc.write(content);
+        wdoc.close();
+        printFrame(w)
+          .done(function () {
+            // Success
+            setTimeout(function () {
+              // Wait for IE
+              if (iframeCount === 0) {
+                // Destroy the iframe if created here
+                $iframe.remove();
+              }
+            }, 100);
+          })
+          .fail(function (err) {
+            // Use the pop-up method if iframe fails for some reason
+            console.error("Failed to print from iframe", err);
+            printContentInNewWindow(content);
+          })
+          .always(function () {
+            try {
+              options.deferred.resolve();
+            } catch (err) {
+              console.warn('Error notifying deferred', err);
+            }
+          });
+      } catch (e) {
+        // Use the pop-up method if iframe fails for some reason
+        console.error("Failed to print from iframe", e.stack, e.message);
+        printContentInNewWindow(content)
+          .always(function () {
+            try {
+              options.deferred.resolve();
+            } catch (err) {
+              console.warn('Error notifying deferred', err);
+            }
+          });
       }
+    } else {
+      // Use a new window for printing
+      printContentInNewWindow(content)
+        .always(function () {
+          try {
+            options.deferred.resolve();
+          } catch (err) {
+            console.warn('Error notifying deferred', err);
+          }
+        });
     }
-
-    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
+    return this;
   };
-
-  // Thanks to 9__, found at http://users.livejournal.com/9__/380664.html
-  $.fn.outer = function () {
-    return $($('<div></div>').html(this.clone())).html();
-  }
-})($);
+})($);

Fichier diff supprimé car celui-ci est trop grand
+ 4 - 0
src/js/jquery.min.js


+ 17 - 30
src/js/staticInfo.js

@@ -7,7 +7,7 @@ if (!Promise) {
   })
 }
 require('../css/staticInfo.less')
-
+require('../css/print.css')
 const {
   post,
   throttle,
@@ -18,9 +18,8 @@ const {
   Toast
 } = require('./promise.js');
 const $ = require("jquery");
-require("./jquery-migrate");
 
-const jqprint = require("../js/jquery.PrintArea")
+const print = require("../js/jQuery.print")
 let printing = require('./../images/printing.png');
 let printing2 = require('./../images/printing2.png');
 let recommend = require('./../images/recommend.png');
@@ -123,10 +122,9 @@ function renderContent(list, contentWrapClassName) {
 
 function renderContentscale(list, contentWrapClassName, name) {
   var pushInfo = []
-  var textType = []
+  $('.scaletitle').html(name);
   for (var i = 0; i < list[0].detailList.length; i++) {
     var item = list[0].detailList[i];
-    textType.push(item.textType)
     if (item.textType == 11) {
       item.content = item.content && item.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
       str = '<div class="infoBox scaleBox" data-id="' + item.id + '"><div class="title"> <h2 class="titleH2" id="' + contentWrapClassName + i +
@@ -187,7 +185,7 @@ function renderContentscale(list, contentWrapClassName, name) {
           var it = items.detailList[k];
           it.content = it.content && it.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
           str = '<div class="contentList" data-id="' + it.parentId + '-' + it.groupNum + '"><div class="item-list">';
-          str += '<p class="item-title">' + it.content + '</p>'
+          str += it.content
           str += '<div class="item-content" data-id="' + it.id + '">'
           str += '</div></div></div>'
           $(".scale .infos .infos-box .infoWrapper .infoBox[data-id=" + it.parentId + "]").append(str);
@@ -212,8 +210,6 @@ function renderContentscale(list, contentWrapClassName, name) {
   str += `<div class="result"><div class="result_box"><div class="result_left"><img src="./../images/icon-hel.png" class="hel"/><span>结果:</span></div><p id="result_title" class="result_title"></p><textarea id="inputs"></textarea></div></div>`
   str += `<div class="foot"><div class="foot_box"><div class="printing"><img src="./../images/printing.png" class="slideImg"/>打印</div><div class="copy">确认并复制结果</div></div></div>`
   $(`.${contentWrapClassName} .infos .infos-box`).append(str);
-  // str = `<div class="foot"><div class="foot_box"><div class="printing"><img src=${printing} class="slideImg"/>打印</div><div class="copy">确认并复制结果</div></div></div>`
-  // $(`.${contentWrapClassName} .infos`).after(str);
   function addScrollEvent() {
     var scrollTop = $(`.${contentWrapClassName} .infos .infos-box`).scrollTop()
     var divHeight = 0;
@@ -227,37 +223,24 @@ function renderContentscale(list, contentWrapClassName, name) {
     }
   }
   $(`.${contentWrapClassName} .infos .infos-box`).scroll(throttle(addScrollEvent, 200));
-  // var mb = myBrowser();
-  // if ("IE" == mb) {
-  //   $('.result_left').css({
-  //     'position': 'relative', //高度自动
-  //   })
-  //   $('.result_title').css({
-  //     'margin-left': '0', //高度自动
-  //   })
-  // }
   addLinkClickEvent(contentWrapClassName);
   adjustHeight();
   adjustWidth()
   getcheck()
-  getResult(pushInfo, textType)
+  getResult(pushInfo)
   copy(name)
   getprinting()
 
 }
-
 function getprinting() {
   $('.printing').click(function () {
     $('.foot').hide()
-    // $('.hel').hide()
+    $('.scalebot').hide()
     $('#Print').css({
       'height': 'auto', //高度自动
-    }).jqprint();
+    }).print(); 
     $('.foot').show()
-    // $('.hel').show()
-    $('#Print').css({
-      'height': '100%', //高度自动
-    });
+    $('.scalebot').show()
   })
 }
 
@@ -349,7 +332,7 @@ function getchecks() {
     }
   });
 }
-function getResult(pushInfo, textType) {
+function getResult(pushInfo) {
   $(".but").click(function () {
     let arr = [];
     let multarr = []
@@ -359,6 +342,7 @@ function getResult(pushInfo, textType) {
     let key = false
     let proposal = ''
     let proposals = []
+    let scrollTop = []
     isclick = true
     $(".contentList").each(function (i) {
       if ($(this).find('input[type="radio"]:checked').val() == undefined && $(this).find('.radio_type').attr('disabled') == undefined) {
@@ -371,7 +355,12 @@ function getResult(pushInfo, textType) {
       } else {
         $(this).find(".item-titles").removeClass('chColor');
       }
+      scrollTop.push($(this).eq(0).find(".chColor").offset())
     });
+    var v = scrollTop.find(value => value != undefined);
+    if(v){
+      $(`.scale .infos`).scrollTop(v.top + 346)
+    }
     if (!$(".contentList").find(".item-title").hasClass('chColor') && !$(".contentList").find(".item-titles").hasClass('chColor')) {
       $('input[type="radio"]:checked').each(function () {
         if ($(this).attr("resultType") == 1) {
@@ -418,8 +407,7 @@ function getResult(pushInfo, textType) {
         proposal = proposals.join(";");
       }
       if (result == undefined) {
-        
-        if ($.inArray(13, textType) > 0) {
+        if (num > 0) {
           $(".score").html('总分:' + num + '分');
         }
         $(".score").css('display', 'block')
@@ -429,9 +417,8 @@ function getResult(pushInfo, textType) {
         $(".hel").attr({
           "title": proposal
         });
-        console.log(textType)
         $(".result_title").html(result);
-        if ($.inArray(13, textType) > 0) {
+        if (num > 0) {
           $(".score").html('总分:' + num + '分');
         }
         $(".result").css('display', 'block')