Ignore:
Timestamp:
2012-01-12T11:03:59+13:00 (12 years ago)
Author:
davidb
Message:

Work on converting CSS style attributes to Expeditee attributes

File:
1 edited

Legend:

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

    r24939 r24941  
    5252}
    5353
    54 function getStyle(node,styleProp)
    55 {
     54function hyphenToInitialCapReplacer(str, p1, offset, s) 
     55
     56    return p1.toUpperCase();
     57
     58
     59function getStyle(node,style_prop)
     60{
     61    var prop_val;
    5662    if (node.currentStyle) {
    57     var y = node.currentStyle[styleProp];
     63    /* IE */
     64    style_prop = strCssRule.replace(/\-(\w)/g, hyphenToInitialCapReplacer);
     65    prop_val = node.currentStyle[style_prop];
    5866    }
    5967    else if (window.getComputedStyle) {
    60     var y = document.defaultView.getComputedStyle(node,null).getPropertyValue(styleProp);
    61     }
    62     return y;
     68    /* Firefox */
     69    var computed_style = document.defaultView.getComputedStyle(node,null)
     70    prop_val = computed_style.getPropertyValue(style_prop);
     71    }
     72    else {
     73    /* try for inline value */
     74    prop_val = el.style[style_prop];
     75    }
     76
     77    return prop_val;
     78
    6379}
    6480
     
    110126        jsonNode.text = node.nodeValue;
    111127
    112         jsonNode.x = pxl;
    113         jsonNode.y = pyt;
     128        jsonNode.xl = pxl;
     129        jsonNode.yt = pyt;
     130        jsonNode.xr = pxr;
     131        jsonNode.yb = pyb;
    114132
    115133    }
     
    119137    /* need to handle: img, a, li */
    120138        /* need to dig out: text size, l/r/justified, font-face, type, colour */
     139
     140    if (getStyle(node,"visibility").match("hidden")
     141        || getStyle(node,"display").match("none")) {
     142
     143        return null;
     144    }
    121145
    122146        var elemName = node.nodeName.toLowerCase();
     
    137161        jsonNode.rect = rect;
    138162   
     163        if (elemName.match("img")) {
     164        jsonNode.img = node.src;
     165        }
    139166
    140167        var style = {};
    141168
    142         style["font-family"] = getStyle(node,"font-family");
     169        style["font-family"]      = getStyle(node,"font-family");
     170        style["font-size"]        = getStyle(node,"font-size");
    143171        style["background-color"] = getStyle(node,"background-color");
    144172
     173        // console.log("font size = " + style["font-size"]);
     174 
    145175        jsonNode.style = style
    146176
Note: See TracChangeset for help on using the changeset viewer.