dojox/html/metrics.js

  • Provides:

    • dojox.html.metrics
  • dojox.html.metrics._fontResizeNode

    • summary
  • dojox.html.metrics.getFontMeasurements

    • type
      Function
    • source: [view]
      dojo.provide("dojox.html.metrics");


      (function(){
       var dhm = dojox.html.metrics;


       // derived from Morris John's emResized measurer
       dhm.getFontMeasurements = function(){
        // summary
        // Returns an object that has pixel equivilents of standard font size values.
        var heights = {
         '1em':0, '1ex':0, '100%':0, '12pt':0, '16px':0, 'xx-small':0, 'x-small':0,
         'small':0, 'medium':0, 'large':0, 'x-large':0, 'xx-large':0
        };

       
        if(dojo.isIE){
         // we do a font-size fix if and only if one isn't applied already.
         // NOTE: If someone set the fontSize on the HTML Element, this will kill it.
         dojo.doc.documentElement.style.fontSize="100%";
        }

       
        // set up the measuring node.
        var div=dojo.doc.createElement("div");
        var ds = div.style;
        ds.position="absolute";
        ds.left="-100px";
        ds.top="0";
        ds.width="30px";
        ds.height="1000em";
        ds.borderWidth="0";
        ds.margin="0";
        ds.padding="0";
        ds.outline="0";
        ds.lineHeight="1";
        ds.overflow="hidden";
        dojo.body().appendChild(div);

       
        // do the measurements.
        for(var p in heights){
         ds.fontSize = p;
         heights[p] = Math.round(div.offsetHeight * 12/16) * 16/12 / 1000;
        }

        
        dojo.body().removeChild(div);
        div = null;
        return heights;  // object
    • returns
      object
    • summary
  • dojox.html.metrics.getCachedFontMeasurements

    • type
      Function
    • parameters:
      • recalculate: (typeof )
    • source: [view]
        if(recalculate || !fontMeasurements){
         fontMeasurements = dhm.getFontMeasurements();
        }
        return fontMeasurements;
    • summary
  • dojox.html.metrics.getTextBox

    • type
      Function
    • parameters:
      • text: (typeof String)
      • style: (typeof Object)
      • className: (typeof String)
    • source: [view]
        var m, s;
        if(!measuringNode){
         m = measuringNode = dojo.doc.createElement("div");
         // Container that we can set contraints on so that it doesn't
         // trigger a scrollbar.
         var c = dojo.doc.createElement("div");
         c.appendChild(m);
         s = c.style;
         s.overflow='scroll';
         s.position = "absolute";
         s.left = "0px";
         s.top = "-10000px";
         s.width = "1px";
         s.height = "1px";
         s.visibility = "hidden";
         s.borderWidth = "0";
         s.margin = "0";
         s.padding = "0";
         s.outline = "0";
         dojo.body().appendChild(c);
        }else{
         m = measuringNode;
        }
        // reset styles
        m.className = "";
        s = m.style;
        s.borderWidth = "0";
        s.margin = "0";
        s.padding = "0";
        s.outline = "0";
        // set new style
        if(arguments.length > 1 && style){
         for(var i in style){
          if(i in empty){ continue; }
          s[i] = style[i];
         }
        }
        // set classes
        if(arguments.length > 2 && className){
         m.className = className;
        }
        // take a measure
        m.innerHTML = text;
        var box = dojo.position(m);
        // position doesn't report right (reports 1, since parent is 1)
        // So we have to look at the scrollWidth to get the real width
        // Height is right.
        box.w = m.parentNode.scrollWidth;
        return box;
    • summary
  • dojox.html.metrics.getScrollbar

    • type
      Function
    • source: [view]
       dhm.getScrollbar=function(){ return { w:scroll.w, h:scroll.h };
    • summary
  • dojox.html.metrics.initOnFontResize

    • type
      Function
    • parameters:
      • interval: (typeof )
    • source: [view]
        var f = dhm._fontResizeNode = dojo.doc.createElement("iframe");
        var fs = f.style;
        fs.position = "absolute";
        fs.width = "5em";
        fs.height = "10em";
        fs.top = "-10000px";
        if(dojo.isIE){
         f.onreadystatechange = function(){
          if(f.contentWindow.document.readyState == "complete"){
           f.onresize = f.contentWindow.parent[dojox._scopeName].html.metrics._fontresize;
          }
         };
        }else{
         f.onload = function(){
          f.contentWindow.onresize = f.contentWindow.parent[dojox._scopeName].html.metrics._fontresize;
         };
        }
        //The script tag is to work around a known firebug race condition. See comments in bug #9046
        f.setAttribute("src", "javascript:''");
        dojo.body().appendChild(f);
        dhm.initOnFontResize = function(){};
    • summary
  • dojox.html.metrics.onFontResize

    • type
      Function
    • source: [view]
      }
    • summary
  • dojox.html.metrics._fontresize

    • type
      Function
    • source: [view]
        dhm.onFontResize();
    • summary
  • dojox.html.metrics

    • type
      Object
    • summary
  • dojox.html

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary