Ignore:
Timestamp:
2012-01-11T10:05:58+13:00 (12 years ago)
Author:
davidb
Message:

Introduction of new Perl module to handle taking the JSON version of the traversed HTML tree and output it as an expeditee frame

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/html-to-expeditee/trunk/src/src/js/html-to-expeditee.js

    r24925 r24934  
    3131    return elem.clip.width;
    3232    } else {
    33     if (elem.style.pixelWidth) {
     33    if (elem.style && elem.style.pixelWidth) {
    3434        return elem.style.pixelWidth;
    3535    } else {
     
    4444    return elem.clip.height;
    4545    } else {
    46     if (elem.style.pixelHeight) {
     46    if (elem.style && elem.style.pixelHeight) {
    4747        return elem.style.pixelHeight;
    4848    } else {
     
    8484
    8585
     86function htmlToExpeditee(node)
     87{
     88    var nodePos = getElementPosition(node);
     89    var pxl = nodePos.xl;
     90    var pyt = nodePos.yt;
     91    var pxr = nodePos.xr;
     92    var pyb = nodePos.yb;
    8693
    87 function htmlToExpeditee(node,depth)
     94    return htmlToExpediteeRec(node, pxl,pyt, pxl,pyt,pxr,pyb, 0);
     95}
     96
     97
     98function htmlToExpediteeRec(node,baseX,baseY, pxl,pyt,pxr,pyb, depth)
    8899{
    89100    depth = (depth) ? depth : 0;
    90101
    91102    //var expSyntax = "";
    92     var jsonNode = {};
     103    var jsonNode = null;
    93104
    94105    if (node.nodeType == 3) { /* text node */
     
    99110        //expSyntax += "Text item: " + node.nodeValue + "\n";
    100111
     112            jsonNode = {};
     113
    101114        jsonNode.type = "text";
    102115        jsonNode.text = node.nodeValue;
     116
     117        jsonNode.x = pxl;
     118        jsonNode.y = pyt;
     119
    103120    }
    104121    }
     
    108125        /* need to dig out: text size, l/r/justified, font-face, type, colour */
    109126
    110         var elemName = node.Name;
    111     if (elemName != "SCRIPT") {
     127        var elemName = node.nodeName.toLowerCase();
    112128
    113        
     129    if (!elemName.match(/script/)) {
     130   
    114131        var nodePos = getElementPosition(node);
    115132        var xl = nodePos.xl;
     
    129146*/
    130147
    131         var rect = { "xl":xl, "yt":yt, "xr":xr, "yb":yb };
    132 
     148            jsonNode = {};
    133149        jsonNode.type = "rect";
    134150            jsonNode.elem = node.nodeName;
     151
     152        var rect = { "xl":xl, "yt":yt, "xr":xr, "yb":yb };
    135153        jsonNode.rect = rect;
    136154   
     
    139157        var cnode = node.firstChild;
    140158        while (cnode != null) {
    141         //expSyntax += htmlToExpeditee(cnode,depth+1); 
    142159
    143             var jsonChildNode = htmlToExpeditee(cnode,depth+1);
    144         jsonChildNodes.push(jsonChildNode); 
     160            var jsonChildNode
     161            = htmlToExpediteeRec(cnode,baseX,baseY,xl,yt,xr,yb,depth+1);
     162
     163            if (jsonChildNode != null) {
     164            jsonChildNodes.push(jsonChildNode); 
     165            }
    145166       
    146167        cnode = cnode.nextSibling;
Note: See TracChangeset for help on using the changeset viewer.