root / trunk / web / dojo / dojox / html / metrics.js @ 9
History | View | Annotate | Download (3.33 KB)
1 |
/*
|
---|---|
2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
4 |
see: http://dojotoolkit.org/license for details
|
5 |
*/
|
6 |
|
7 |
|
8 |
if(!dojo._hasResource["dojox.html.metrics"]){ |
9 |
dojo._hasResource["dojox.html.metrics"]=true; |
10 |
dojo.provide("dojox.html.metrics");
|
11 |
(function(){
|
12 |
var _1=dojox.html.metrics;
|
13 |
_1.getFontMeasurements=function(){ |
14 |
var _2={"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}; |
15 |
if(dojo.isIE){
|
16 |
dojo.doc.documentElement.style.fontSize="100%";
|
17 |
} |
18 |
var _3=dojo.doc.createElement("div"); |
19 |
var ds=_3.style;
|
20 |
ds.position="absolute";
|
21 |
ds.left="-100px";
|
22 |
ds.top="0";
|
23 |
ds.width="30px";
|
24 |
ds.height="1000em";
|
25 |
ds.borderWidth="0";
|
26 |
ds.margin="0";
|
27 |
ds.padding="0";
|
28 |
ds.outline="0";
|
29 |
ds.lineHeight="1";
|
30 |
ds.overflow="hidden";
|
31 |
dojo.body().appendChild(_3); |
32 |
for(var p in _2){ |
33 |
ds.fontSize=p; |
34 |
_2[p]=Math.round(_3.offsetHeight*12/16)*16/12/1000; |
35 |
} |
36 |
dojo.body().removeChild(_3); |
37 |
_3=null;
|
38 |
return _2;
|
39 |
}; |
40 |
var _4=null; |
41 |
_1.getCachedFontMeasurements=function(_5){ |
42 |
if(_5||!_4){
|
43 |
_4=_1.getFontMeasurements(); |
44 |
} |
45 |
return _4;
|
46 |
}; |
47 |
var _6=null,_7={}; |
48 |
_1.getTextBox=function(_8,_9,_a){ |
49 |
var m,s;
|
50 |
if(!_6){
|
51 |
m=_6=dojo.doc.createElement("div");
|
52 |
var c=dojo.doc.createElement("div"); |
53 |
c.appendChild(m); |
54 |
s=c.style; |
55 |
s.overflow="scroll";
|
56 |
s.position="absolute";
|
57 |
s.left="0px";
|
58 |
s.top="-10000px";
|
59 |
s.width="1px";
|
60 |
s.height="1px";
|
61 |
s.visibility="hidden";
|
62 |
s.borderWidth="0";
|
63 |
s.margin="0";
|
64 |
s.padding="0";
|
65 |
s.outline="0";
|
66 |
dojo.body().appendChild(c); |
67 |
}else{
|
68 |
m=_6; |
69 |
} |
70 |
m.className="";
|
71 |
s=m.style; |
72 |
s.borderWidth="0";
|
73 |
s.margin="0";
|
74 |
s.padding="0";
|
75 |
s.outline="0";
|
76 |
if(arguments.length>1&&_9){ |
77 |
for(var i in _9){ |
78 |
if(i in _7){ |
79 |
continue;
|
80 |
} |
81 |
s[i]=_9[i]; |
82 |
} |
83 |
} |
84 |
if(arguments.length>2&&_a){ |
85 |
m.className=_a; |
86 |
} |
87 |
m.innerHTML=_8; |
88 |
var _b=dojo.position(m);
|
89 |
_b.w=m.parentNode.scrollWidth; |
90 |
return _b;
|
91 |
}; |
92 |
var _c={w:16,h:16}; |
93 |
_1.getScrollbar=function(){ |
94 |
return {w:_c.w,h:_c.h}; |
95 |
}; |
96 |
_1._fontResizeNode=null;
|
97 |
_1.initOnFontResize=function(_d){ |
98 |
var f=_1._fontResizeNode=dojo.doc.createElement("iframe"); |
99 |
var fs=f.style;
|
100 |
fs.position="absolute";
|
101 |
fs.width="5em";
|
102 |
fs.height="10em";
|
103 |
fs.top="-10000px";
|
104 |
if(dojo.isIE){
|
105 |
f.onreadystatechange=function(){ |
106 |
if(f.contentWindow.document.readyState=="complete"){ |
107 |
f.onresize=f.contentWindow.parent[dojox._scopeName].html.metrics._fontresize; |
108 |
} |
109 |
}; |
110 |
}else{
|
111 |
f.onload=function(){ |
112 |
f.contentWindow.onresize=f.contentWindow.parent[dojox._scopeName].html.metrics._fontresize; |
113 |
}; |
114 |
} |
115 |
f.setAttribute("src","javascript:'<html><head><script>if(\"loadFirebugConsole\" in window){window.loadFirebugConsole();}</script></head><body></body></html>'"); |
116 |
dojo.body().appendChild(f); |
117 |
_1.initOnFontResize=function(){ |
118 |
}; |
119 |
}; |
120 |
_1.onFontResize=function(){ |
121 |
}; |
122 |
_1._fontresize=function(){ |
123 |
_1.onFontResize(); |
124 |
}; |
125 |
dojo.addOnUnload(function(){
|
126 |
var f=_1._fontResizeNode;
|
127 |
if(f){
|
128 |
if(dojo.isIE&&f.onresize){
|
129 |
f.onresize=null;
|
130 |
}else{
|
131 |
if(f.contentWindow&&f.contentWindow.onresize){
|
132 |
f.contentWindow.onresize=null;
|
133 |
} |
134 |
} |
135 |
_1._fontResizeNode=null;
|
136 |
} |
137 |
}); |
138 |
dojo.addOnLoad(function(){
|
139 |
try{
|
140 |
var n=dojo.doc.createElement("div"); |
141 |
n.style.cssText="top:0;left:0;width:100px;height:100px;overflow:scroll;position:absolute;visibility:hidden;";
|
142 |
dojo.body().appendChild(n); |
143 |
_c.w=n.offsetWidth-n.clientWidth; |
144 |
_c.h=n.offsetHeight-n.clientHeight; |
145 |
dojo.body().removeChild(n); |
146 |
delete n;
|
147 |
} |
148 |
catch(e){
|
149 |
} |
150 |
if("fontSizeWatch" in dojo.config&&!!dojo.config.fontSizeWatch){ |
151 |
_1.initOnFontResize(); |
152 |
} |
153 |
}); |
154 |
})(); |
155 |
} |