فهرست منبع

版式文件编辑器增加getDocumentHtml方法

huqi 5 سال پیش
والد
کامیت
3be939fe40
1فایلهای تغییر یافته به همراه46 افزوده شده و 22 حذف شده
  1. 46 22
      o2web/source/x_component_process_Xform/Documenteditor.js

+ 46 - 22
o2web/source/x_component_process_Xform/Documenteditor.js

@@ -2894,7 +2894,30 @@ debugger;
         }
         return node;
     },
-
+    getDocumentHtml: function(){
+        var tmpNode = this.contentNode.getFirst().getFirst().clone(true);
+        var htmlNode = tmpNode.getLast();
+        htmlNode = this.removeDisplayNone(htmlNode);
+        var nodes = tmpNode.querySelectorAll("[data-w-style]");
+        if (nodes.length){
+            for (var i=0; i<nodes.length; i++){
+                var n = nodes.item(i);
+                wStyle = n.dataset["wStyle"];
+                var styles = wStyle.split(/\s*\;\s*/g);
+                styles.each(function(style){
+                    if (style){
+                        try{
+                            s = style.split(/\s*\:\s*/g);
+                            n.setStyle(s[0], s[1]);
+                        }catch(e) {}
+                    }
+                });
+            }
+        }
+        var htmlStr = tmpNode.get("html");
+        tmpNode.destroy();
+        return "<html xmlns:v=\"urn:schemas-microsoft-com:vml\"><head><meta charset=\"UTF-8\" /></head><body>"+htmlStr+"</body></html>";
+    },
     toWord: function(callback, name){
         debugger;
         var docNmae = name || "";
@@ -2922,26 +2945,27 @@ debugger;
             });
 
             //var content = this.contentNode.getFirst().getFirst().get("html");
-            var tmpNode = this.contentNode.getFirst().getFirst().clone(true);
-            var htmlNode = tmpNode.getLast();
-            htmlNode = this.removeDisplayNone(htmlNode);
-            var nodes = tmpNode.querySelectorAll("[data-w-style]");
-            if (nodes.length){
-                for (var i=0; i<nodes.length; i++){
-                    var n = nodes.item(i);
-                    wStyle = n.dataset["wStyle"];
-                    var styles = wStyle.split(/\s*\;\s*/g);
-                    styles.each(function(style){
-                        if (style){
-                            try{
-                                s = style.split(/\s*\:\s*/g);
-                                n.setStyle(s[0], s[1]);
-                            }catch(e) {}
-                        }
-                    });
-                }
-            }
-            var content = "<html xmlns:v=\"urn:schemas-microsoft-com:vml\"><head><meta charset=\"UTF-8\" /></head><body>"+tmpNode.get("html")+"</body></html>";
+            // var tmpNode = this.contentNode.getFirst().getFirst().clone(true);
+            // var htmlNode = tmpNode.getLast();
+            // htmlNode = this.removeDisplayNone(htmlNode);
+            // var nodes = tmpNode.querySelectorAll("[data-w-style]");
+            // if (nodes.length){
+            //     for (var i=0; i<nodes.length; i++){
+            //         var n = nodes.item(i);
+            //         wStyle = n.dataset["wStyle"];
+            //         var styles = wStyle.split(/\s*\;\s*/g);
+            //         styles.each(function(style){
+            //             if (style){
+            //                 try{
+            //                     s = style.split(/\s*\:\s*/g);
+            //                     n.setStyle(s[0], s[1]);
+            //                 }catch(e) {}
+            //             }
+            //         });
+            //     }
+            // }
+            var content = this.getDocumentHtml();
+            //var content = "<html xmlns:v=\"urn:schemas-microsoft-com:vml\"><head><meta charset=\"UTF-8\" /></head><body>"+tmpNode.get("html")+"</body></html>";
 
             var fileName = docNmae || this.json.toWordFilename || "$doc";
             var n = fileName.lastIndexOf(".");
@@ -2966,7 +2990,7 @@ debugger;
                     }.bind(this));
                 }
             }.bind(this));
-            tmpNode.destroy();
+            //tmpNode.destroy();
 
             if (!toEdit){
                 this._readFiletext();