Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / html / ellipsis.js @ 12

History | View | Annotate | Download (3.15 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.ellipsis"]){
9
dojo._hasResource["dojox.html.ellipsis"]=true;
10
dojo.provide("dojox.html.ellipsis");
11
(function(d){
12
if(d.isMoz){
13
var _1=1;
14
if("dojoxFFEllipsisDelay" in d.config){
15
_1=Number(d.config.dojoxFFEllipsisDelay);
16
if(isNaN(_1)){
17
_1=1;
18
}
19
}
20
var _2="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
21
var _3=document.createElementNS(_2,"window");
22
var _4=document.createElementNS(_2,"description");
23
_4.setAttribute("crop","end");
24
_3.appendChild(_4);
25
var _5=function(n){
26
var x=_3.cloneNode(true);
27
x.firstChild.setAttribute("value",n.textContent);
28
n.innerHTML="";
29
n.appendChild(x);
30
};
31
var _6=d.create;
32
var dd=d.doc;
33
var dp=d.place;
34
var _7=_6("iframe",{className:"dojoxEllipsisIFrame",src:"javascript:'<html><head><script>if(\"loadFirebugConsole\" in window){window.loadFirebugConsole();}</script></head><body></body></html>'"});
35
var _8=function(r,_9){
36
if(r.collapsed){
37
return;
38
}
39
if(_9>0){
40
do{
41
_8(r);
42
_9--;
43
}while(_9);
44
return;
45
}
46
if(r.endContainer.nodeType==3&&r.endOffset>0){
47
r.setEnd(r.endContainer,r.endOffset-1);
48
}else{
49
if(r.endContainer.nodeType==3){
50
r.setEndBefore(r.endContainer);
51
_8(r);
52
return;
53
}else{
54
if(r.endOffset&&r.endContainer.childNodes.length>=r.endOffset){
55
var _a=r.endContainer.childNodes[r.endOffset-1];
56
if(_a.nodeType==3){
57
r.setEnd(_a,_a.length-1);
58
}else{
59
if(_a.childNodes.length){
60
r.setEnd(_a,_a.childNodes.length);
61
_8(r);
62
return;
63
}else{
64
r.setEndBefore(_a);
65
_8(r);
66
return;
67
}
68
}
69
}else{
70
r.setEndBefore(r.endContainer);
71
_8(r);
72
return;
73
}
74
}
75
}
76
};
77
var _b=function(n){
78
var c=_6("div",{className:"dojoxEllipsisContainer"});
79
var e=_6("div",{className:"dojoxEllipsisShown",style:{display:"none"}});
80
n.parentNode.replaceChild(c,n);
81
c.appendChild(n);
82
c.appendChild(e);
83
var i=_7.cloneNode(true);
84
var ns=n.style;
85
var es=e.style;
86
var _c;
87
var _d=function(){
88
ns.display="";
89
es.display="none";
90
if(n.scrollWidth<=n.offsetWidth){
91
return;
92
}
93
var r=dd.createRange();
94
r.selectNodeContents(n);
95
ns.display="none";
96
es.display="";
97
var _e=false;
98
do{
99
var _f=1;
100
dp(r.cloneContents(),e,"only");
101
var sw=e.scrollWidth,ow=e.offsetWidth;
102
_e=(sw<=ow);
103
var pct=(1-((ow*1)/sw));
104
if(pct>0){
105
_f=Math.max(Math.round(e.textContent.length*pct)-1,1);
106
}
107
_8(r,_f);
108
}while(!r.collapsed&&!_e);
109
};
110
i.onload=function(){
111
i.contentWindow.onresize=_d;
112
_d();
113
};
114
c.appendChild(i);
115
};
116
var hc=d.hasClass;
117
var doc=d.doc;
118
var s,fn,opt;
119
if(doc.querySelectorAll){
120
s=doc;
121
fn="querySelectorAll";
122
opt=".dojoxEllipsis";
123
}else{
124
if(doc.getElementsByClassName){
125
s=doc;
126
fn="getElementsByClassName";
127
opt="dojoxEllipsis";
128
}else{
129
s=d;
130
fn="query";
131
opt=".dojoxEllipsis";
132
}
133
}
134
fx=function(){
135
d.forEach(s[fn].apply(s,[opt]),function(n){
136
if(!n||n._djx_ellipsis_done){
137
return;
138
}
139
n._djx_ellipsis_done=true;
140
if(n.textContent==n.innerHTML&&!hc(n,"dojoxEllipsisSelectable")){
141
_5(n);
142
}else{
143
_b(n);
144
}
145
});
146
};
147
d.addOnLoad(function(){
148
var t=null;
149
var c=null;
150
var _10=function(){
151
if(c){
152
d.disconnect(c);
153
c=null;
154
}
155
if(t){
156
clearTimeout(t);
157
}
158
t=setTimeout(function(){
159
t=null;
160
fx();
161
c=d.connect(d.body(),"DOMSubtreeModified",_10);
162
},_1);
163
};
164
_10();
165
});
166
}
167
})(dojo);
168
}