Changeset 26726
- Timestamp:
- 2013-01-15T20:52:36+13:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gs3-extensions/html-to-expeditee/trunk/src/src/js/html-to-expeditee.js
r25060 r26726 1 1 //javascript: 2 2 var expSyntaxArray = []; 3 4 var font_family; 5 var font_size; 6 var font_color; 3 7 4 8 Element.prototype.getElementWidth = function() { … … 74 78 prop_val = el.style[style_prop]; 75 79 } 76 80 77 81 return prop_val; 78 82 … … 101 105 function htmlToExpeditee(node) 102 106 { 103 var nodePos = getElementPosition(node); 107 var nodePos = getElementPosition(node); 108 var parentStyle = node.getAttribute('style'); 109 110 //Use these as default values if font info can't be found for text items. 111 font_family = getStyle(node,'font-family'); 112 font_size = getStyle(node,'font-size'); 113 font_color = getStyle(node,'color'); 114 115 console.log("Retrieving node: " + node); 116 117 console.log("Retrieving font family: " + font_family); 118 console.log("Retrieving font size: " + font_size); 119 console.log("Retrieving font color: " + font_color); 120 104 121 var pxl = nodePos.xl; 105 122 var pyt = nodePos.yt; … … 116 133 117 134 var jsonNode = null; 118 135 119 136 if (node.nodeType == 3) { /* text node */ 137 138 120 139 var text = node.nodeValue; 121 140 … … 132 151 133 152 var parent = node.parentNode; 153 134 154 if (parent != null) { 135 var data = parent.attributes["data"]; 136 137 if (data != null) { 138 jsonNode.data = data.value; 139 } 140 } 141 } 155 156 //obtain font info for text nodes from their parent nodes. 157 var new_font_family = getStyle(parent,"font-family"); 158 var new_font_size = getStyle(parent,"font-size"); 159 var new_font_color = getStyle(parent,"color"); 160 161 if(new_font_family !== undefined && new_font_family !== null) 162 font_family = new_font_family; 163 164 if(new_font_size !== undefined && new_font_size !== null) 165 font_size = new_font_size; 166 167 if(new_font_color !== undefined && new_font_color !== null) 168 font_color = new_font_color; 169 170 var data = parent.attributes["data"]; 171 172 if (data != null) { 173 jsonNode.data = data.value; 174 } 175 jsonNode.style = style; 176 } 177 } 178 179 var style = {}; 180 style["font-family"] = font_family; 181 style["font-size"] = font_size; 182 style["color"] = font_color; 183 142 184 } 143 185 else if (node.nodeType == 1) { /* element */ … … 162 204 var yb = nodePos.yb; 163 205 164 206 jsonNode = {}; 165 207 jsonNode.type = "rect"; 166 jsonNode.elem = node.nodeName; 208 jsonNode.elem = node.nodeName; 209 210 if(node.getAttribute("rect") !== undefined){ 211 212 /**This is to ensure rectangles aren't drawn around "non-rectangular" items such 213 as text and empty elements such as <br/>**/ 214 if(node.getAttribute("rect") === "norect"){ 215 jsonNode.type = "norect"; 216 } 217 } 167 218 168 219 var rect = { "xl":xl, "yt":yt, "xr":xr, "yb":yb }; … … 170 221 171 222 if (elemName.match("img")) { 172 jsonNode.img = node.src;173 } 174 175 176 177 style["font-family"] = getStyle(node,"font-family");178 style["font-size"] = getStyle(node,"font-size");223 jsonNode.img = node.src; 224 } 225 226 var style = {}; 227 228 //style["font-family"] = getStyle(node,"font-family"); 229 //style["font-size"] = getStyle(node,"font-size"); 179 230 style["background-color"] = getStyle(node,"background-color"); 180 181 // console.log("background color = " + style["background-color"]); 182 183 // console.log("font size = " + style["font-size"]); 184 185 jsonNode.style = style; 231 232 jsonNode.style = style; 186 233 187 234 var attr = node.attributes["attr"];
Note:
See TracChangeset
for help on using the changeset viewer.