[24917] | 1 | //javascript:
|
---|
| 2 | var expSyntaxArray = [];
|
---|
| 3 |
|
---|
| 4 | Element.prototype.getElementWidth = function() {
|
---|
| 5 | if (typeof this.clip !== "undefined") {
|
---|
| 6 | return this.clip.width;
|
---|
| 7 | } else {
|
---|
| 8 | if (this.style.pixelWidth) {
|
---|
| 9 | return this.style.pixelWidth;
|
---|
| 10 | } else {
|
---|
| 11 | return this.offsetWidth;
|
---|
| 12 | }
|
---|
| 13 | }
|
---|
| 14 | };
|
---|
| 15 |
|
---|
| 16 | Element.prototype.getElementHeight = function() {
|
---|
| 17 | if (typeof this.clip !== "undefined") {
|
---|
| 18 | return this.clip.height;
|
---|
| 19 | } else {
|
---|
| 20 | if (this.style.pixelHeight) {
|
---|
| 21 | return this.style.pixelHeight;
|
---|
| 22 | } else {
|
---|
| 23 | return this.offsetHeight;
|
---|
| 24 | }
|
---|
| 25 | }
|
---|
| 26 | };
|
---|
| 27 |
|
---|
| 28 | function getElementWidth(elem)
|
---|
| 29 | {
|
---|
| 30 | if (typeof elem.clip !== "undefined") {
|
---|
| 31 | return elem.clip.width;
|
---|
| 32 | } else {
|
---|
[24934] | 33 | if (elem.style && elem.style.pixelWidth) {
|
---|
[24917] | 34 | return elem.style.pixelWidth;
|
---|
| 35 | } else {
|
---|
| 36 | return elem.offsetWidth;
|
---|
| 37 | }
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | function getElementHeight(elem)
|
---|
| 42 | {
|
---|
| 43 | if (typeof elem.clip !== "undefined") {
|
---|
| 44 | return elem.clip.height;
|
---|
| 45 | } else {
|
---|
[24934] | 46 | if (elem.style && elem.style.pixelHeight) {
|
---|
[24917] | 47 | return elem.style.pixelHeight;
|
---|
| 48 | } else {
|
---|
| 49 | return elem.offsetHeight;
|
---|
| 50 | }
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[24941] | 54 | function hyphenToInitialCapReplacer(str, p1, offset, s)
|
---|
| 55 | {
|
---|
| 56 | return p1.toUpperCase();
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | function getStyle(node,style_prop)
|
---|
[24917] | 60 | {
|
---|
[24941] | 61 | var prop_val;
|
---|
[24939] | 62 | if (node.currentStyle) {
|
---|
[24941] | 63 | /* IE */
|
---|
| 64 | style_prop = strCssRule.replace(/\-(\w)/g, hyphenToInitialCapReplacer);
|
---|
| 65 | prop_val = node.currentStyle[style_prop];
|
---|
[24917] | 66 | }
|
---|
| 67 | else if (window.getComputedStyle) {
|
---|
[24941] | 68 | /* Firefox */
|
---|
| 69 | var computed_style = document.defaultView.getComputedStyle(node,null)
|
---|
| 70 | prop_val = computed_style.getPropertyValue(style_prop);
|
---|
[24917] | 71 | }
|
---|
[24941] | 72 | else {
|
---|
| 73 | /* try for inline value */
|
---|
| 74 | prop_val = el.style[style_prop];
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | return prop_val;
|
---|
| 78 |
|
---|
[24917] | 79 | }
|
---|
| 80 |
|
---|
| 81 | function getElementPosition(elem)
|
---|
| 82 | {
|
---|
| 83 | var origElem = elem;
|
---|
| 84 |
|
---|
| 85 | var xl_ = 0;
|
---|
| 86 | var yt_ = 0;
|
---|
| 87 |
|
---|
| 88 | while(elem && !isNaN(elem.offsetLeft) && !isNaN(elem.offsetTop)) {
|
---|
| 89 | xl_ += elem.offsetLeft - elem.scrollLeft;
|
---|
| 90 | yt_ += elem.offsetTop - elem.scrollTop;
|
---|
| 91 | elem = elem.offsetParent;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | var xr_ = xl_ + getElementWidth(origElem);
|
---|
| 95 | var yb_ = yt_ + getElementHeight(origElem);
|
---|
| 96 |
|
---|
| 97 | return { xl: xl_, yt: yt_, xr: xr_, yb: yb_ };
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 |
|
---|
[24934] | 101 | function htmlToExpeditee(node)
|
---|
| 102 | {
|
---|
| 103 | var nodePos = getElementPosition(node);
|
---|
| 104 | var pxl = nodePos.xl;
|
---|
| 105 | var pyt = nodePos.yt;
|
---|
| 106 | var pxr = nodePos.xr;
|
---|
| 107 | var pyb = nodePos.yb;
|
---|
[24917] | 108 |
|
---|
[24934] | 109 | return htmlToExpediteeRec(node, pxl,pyt, pxl,pyt,pxr,pyb, 0);
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 |
|
---|
| 113 | function htmlToExpediteeRec(node,baseX,baseY, pxl,pyt,pxr,pyb, depth)
|
---|
[24917] | 114 | {
|
---|
| 115 | depth = (depth) ? depth : 0;
|
---|
| 116 |
|
---|
[24934] | 117 | var jsonNode = null;
|
---|
[24917] | 118 |
|
---|
| 119 | if (node.nodeType == 3) { /* text node */
|
---|
| 120 | var text = node.nodeValue;
|
---|
| 121 |
|
---|
| 122 | if (text.match(/\S/)) {
|
---|
[24934] | 123 | jsonNode = {};
|
---|
| 124 |
|
---|
[24925] | 125 | jsonNode.type = "text";
|
---|
| 126 | jsonNode.text = node.nodeValue;
|
---|
[24934] | 127 |
|
---|
[24941] | 128 | jsonNode.xl = pxl;
|
---|
| 129 | jsonNode.yt = pyt;
|
---|
| 130 | jsonNode.xr = pxr;
|
---|
| 131 | jsonNode.yb = pyb;
|
---|
[24934] | 132 |
|
---|
[25057] | 133 | var parent = node.parentNode;
|
---|
| 134 | if (parent != null) {
|
---|
| 135 | var data = parent.attributes["data"];
|
---|
| 136 |
|
---|
| 137 | if (data != null) {
|
---|
| 138 | jsonNode.data = data.value;
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 |
|
---|
[24917] | 142 | }
|
---|
| 143 | }
|
---|
| 144 | else if (node.nodeType == 1) { /* element */
|
---|
| 145 |
|
---|
| 146 | /* need to handle: img, a, li */
|
---|
| 147 | /* need to dig out: text size, l/r/justified, font-face, type, colour */
|
---|
| 148 |
|
---|
[24941] | 149 | if (getStyle(node,"visibility").match("hidden")
|
---|
| 150 | || getStyle(node,"display").match("none")) {
|
---|
| 151 |
|
---|
| 152 | return null;
|
---|
| 153 | }
|
---|
| 154 |
|
---|
[24934] | 155 | var elemName = node.nodeName.toLowerCase();
|
---|
[24917] | 156 |
|
---|
[24934] | 157 | if (!elemName.match(/script/)) {
|
---|
| 158 |
|
---|
[24917] | 159 | var nodePos = getElementPosition(node);
|
---|
| 160 | var xl = nodePos.xl;
|
---|
| 161 | var xr = nodePos.xr;
|
---|
| 162 | var yt = nodePos.yt;
|
---|
| 163 | var yb = nodePos.yb;
|
---|
| 164 |
|
---|
[24934] | 165 | jsonNode = {};
|
---|
[24925] | 166 | jsonNode.type = "rect";
|
---|
| 167 | jsonNode.elem = node.nodeName;
|
---|
[24934] | 168 |
|
---|
| 169 | var rect = { "xl":xl, "yt":yt, "xr":xr, "yb":yb };
|
---|
[24925] | 170 | jsonNode.rect = rect;
|
---|
| 171 |
|
---|
[24941] | 172 | if (elemName.match("img")) {
|
---|
| 173 | jsonNode.img = node.src;
|
---|
| 174 | }
|
---|
[24939] | 175 |
|
---|
| 176 | var style = {};
|
---|
| 177 |
|
---|
[24941] | 178 | style["font-family"] = getStyle(node,"font-family");
|
---|
| 179 | style["font-size"] = getStyle(node,"font-size");
|
---|
[24939] | 180 | style["background-color"] = getStyle(node,"background-color");
|
---|
| 181 |
|
---|
[24944] | 182 | // console.log("background color = " + style["background-color"]);
|
---|
| 183 |
|
---|
[24941] | 184 | // console.log("font size = " + style["font-size"]);
|
---|
| 185 |
|
---|
[24939] | 186 | jsonNode.style = style
|
---|
| 187 |
|
---|
[24925] | 188 | var jsonChildNodes = [];
|
---|
| 189 |
|
---|
[24917] | 190 | var cnode = node.firstChild;
|
---|
| 191 | while (cnode != null) {
|
---|
[24925] | 192 |
|
---|
[24934] | 193 | var jsonChildNode
|
---|
| 194 | = htmlToExpediteeRec(cnode,baseX,baseY,xl,yt,xr,yb,depth+1);
|
---|
| 195 |
|
---|
| 196 | if (jsonChildNode != null) {
|
---|
| 197 | jsonChildNodes.push(jsonChildNode);
|
---|
| 198 | }
|
---|
[24917] | 199 |
|
---|
[24925] | 200 | cnode = cnode.nextSibling;
|
---|
[24917] | 201 | }
|
---|
| 202 |
|
---|
[24925] | 203 | jsonNode.childNodes = jsonChildNodes;
|
---|
[24917] | 204 | }
|
---|
| 205 |
|
---|
| 206 | }
|
---|
| 207 | /* currently do nothing for the other node types */
|
---|
| 208 |
|
---|
[24925] | 209 | return jsonNode;
|
---|
[24917] | 210 | }
|
---|
| 211 |
|
---|
| 212 |
|
---|
| 213 | //var body = document.body;
|
---|
| 214 | //alert(traverseDOM(body)); |
---|