]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/_base/html.js
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
8 if(!dojo
._hasResource
["dojo._base.html"]){
9 dojo
._hasResource
["dojo._base.html"]=true;
10 dojo
.require("dojo._base.lang");
11 dojo
.provide("dojo._base.html");
13 document
.execCommand("BackgroundImageCache",false,true);
17 if(dojo
.isIE
||dojo
.isOpera
){
18 dojo
.byId=function(id
,_1
){
19 if(typeof id
!="string"){
22 var _2
=_1
||dojo
.doc
,te
=_2
.getElementById(id
);
23 if(te
&&(te
.attributes
.id
.value
==id
||te
.id
==id
)){
32 if((te
.attributes
&&te
.attributes
.id
&&te
.attributes
.id
.value
==id
)||te
.id
==id
){
39 dojo
.byId=function(id
,_4
){
40 return (typeof id
=="string")?(_4
||dojo
.doc
).getElementById(id
):id
;
47 d
.addOnWindowUnload(function(){
50 dojo
._destroyElement
=dojo
.destroy=function(_8
){
53 var _9
=_8
.ownerDocument
;
55 _6
=_9
.createElement("div");
58 _6
.appendChild(_8
.parentNode
?_8
.parentNode
.removeChild(_8
):_8
);
64 dojo
.isDescendant=function(_a
,_b
){
79 dojo
.setSelectable=function(_c
,_d
){
82 _c
.style
.MozUserSelect
=_d
?"":"none";
84 if(d
.isKhtml
||d
.isWebKit
){
85 _c
.style
.KhtmlUserSelect
=_d
?"auto":"none";
88 var v
=(_c
.unselectable
=_d
?"":"on");
89 d
.query("*",_c
).forEach("item.unselectable = '"+v
+"'");
94 var _e=function(_f
,ref
){
95 var _10
=ref
.parentNode
;
97 _10
.insertBefore(_f
,ref
);
100 var _11=function(_12
,ref
){
101 var _13
=ref
.parentNode
;
103 if(_13
.lastChild
==ref
){
104 _13
.appendChild(_12
);
106 _13
.insertBefore(_12
,ref
.nextSibling
);
110 dojo
.place=function(_14
,_15
,_16
){
112 if(typeof _14
=="string"){
113 _14
=_14
.charAt(0)=="<"?d
._toDom(_14
,_15
.ownerDocument
):_5(_14
);
115 if(typeof _16
=="number"){
116 var cn
=_15
.childNodes
;
117 if(!cn
.length
||cn
.length
<=_16
){
118 _15
.appendChild(_14
);
120 _e(_14
,cn
[_16
<0?0:_16
]);
131 _15
.parentNode
.replaceChild(_14
,_15
);
135 _15
.appendChild(_14
);
139 _e(_14
,_15
.firstChild
);
143 _15
.appendChild(_14
);
148 dojo
.boxModel
="content-box";
150 d
.boxModel
=document
.compatMode
=="BackCompat"?"border-box":"content-box";
157 var dv
=_17
.ownerDocument
.defaultView
;
158 s
=dv
.getComputedStyle(_17
,null);
160 _17
.style
.display
="";
161 s
=dv
.getComputedStyle(_17
,null);
169 return _18
.nodeType
==1?_18
.currentStyle
:{};
173 return _19
.nodeType
==1?_19
.ownerDocument
.defaultView
.getComputedStyle(_19
,null):{};
177 dojo
.getComputedStyle
=gcs
;
179 d
._toPixelValue=function(_1a
,_1b
){
180 return parseFloat(_1b
)||0;
183 d
._toPixelValue=function(_1c
,_1d
){
190 if(_1d
.slice
&&_1d
.slice(-2)=="px"){
191 return parseFloat(_1d
);
195 var _1f
=runtimeStyle
.left
;
196 runtimeStyle
.left
=currentStyle
.left
;
205 runtimeStyle
.left
=_1f
;
210 var px
=d
._toPixelValue
;
211 var _20
="DXImageTransform.Microsoft.Alpha";
212 var af=function(n
,f
){
214 return n
.filters
.item(_20
);
220 dojo
._getOpacity
=d
.isIE
?function(_21
){
222 return af(_21
).Opacity
/100;
228 return gcs(_22
).opacity
;
230 dojo
._setOpacity
=d
.isIE
?function(_23
,_24
){
231 var ov
=_24
*100,_25
=_24
==1;
232 _23
.style
.zoom
=_25
?"":1;
237 _23
.style
.filter
+=" progid:"+_20
+"(Opacity="+ov
+")";
239 af(_23
,1).Opacity
=ov
;
241 af(_23
,1).Enabled
=!_25
;
242 if(_23
.nodeName
.toLowerCase()=="tr"){
243 d
.query("> td",_23
).forEach(function(i
){
244 d
._setOpacity(i
,_24
);
249 return _26
.style
.opacity
=_27
;
251 var _28
={left
:true,top
:true};
252 var _29
=/margin|padding|width|height|max|min|offset/;
253 var _2a=function(_2b
,_2c
,_2d
){
254 _2c
=_2c
.toLowerCase();
258 return _2b
.offsetHeight
;
261 return _2b
.offsetWidth
;
264 if(_2c
=="fontweight"){
275 _28
[_2c
]=_29
.test(_2c
);
277 return _28
[_2c
]?px(_2b
,_2d
):_2d
;
279 var _2e
=d
.isIE
?"styleFloat":"cssFloat",_2f
={"cssFloat":_2e
,"styleFloat":_2e
,"float":_2e
};
280 dojo
.style=function(_30
,_31
,_32
){
281 var n
=_5(_30
),_33
=arguments
.length
,op
=(_31
=="opacity");
284 return op
?d
._setOpacity(n
,_32
):n
.style
[_31
]=_32
;
287 return d
._getOpacity(n
);
290 if(_33
==2&&typeof _31
!="string"){
292 d
.style(_30
,x
,_31
[x
]);
296 return (_33
==1)?s
:_2a(n
,_31
,s
[_31
]||n
.style
[_31
]);
298 dojo
._getPadExtents=function(n
,_34
){
299 var s
=_34
||gcs(n
),l
=px(n
,s
.paddingLeft
),t
=px(n
,s
.paddingTop
);
300 return {l
:l
,t
:t
,w
:l
+px(n
,s
.paddingRight
),h
:t
+px(n
,s
.paddingBottom
)};
302 dojo
._getBorderExtents=function(n
,_35
){
303 var ne
="none",s
=_35
||gcs(n
),bl
=(s
.borderLeftStyle
!=ne
?px(n
,s
.borderLeftWidth
):0),bt
=(s
.borderTopStyle
!=ne
?px(n
,s
.borderTopWidth
):0);
304 return {l
:bl
,t
:bt
,w
:bl
+(s
.borderRightStyle
!=ne
?px(n
,s
.borderRightWidth
):0),h
:bt
+(s
.borderBottomStyle
!=ne
?px(n
,s
.borderBottomWidth
):0)};
306 dojo
._getPadBorderExtents=function(n
,_36
){
307 var s
=_36
||gcs(n
),p
=d
._getPadExtents(n
,s
),b
=d
._getBorderExtents(n
,s
);
308 return {l
:p
.l
+b
.l
,t
:p
.t
+b
.t
,w
:p
.w
+b
.w
,h
:p
.h
+b
.h
};
310 dojo
._getMarginExtents=function(n
,_37
){
311 var s
=_37
||gcs(n
),l
=px(n
,s
.marginLeft
),t
=px(n
,s
.marginTop
),r
=px(n
,s
.marginRight
),b
=px(n
,s
.marginBottom
);
312 if(d
.isWebKit
&&(s
.position
!="absolute")){
315 return {l
:l
,t
:t
,w
:l
+r
,h
:t
+b
};
317 dojo
._getMarginBox=function(_38
,_39
){
318 var s
=_39
||gcs(_38
),me
=d
._getMarginExtents(_38
,s
);
319 var l
=_38
.offsetLeft
-me
.l
,t
=_38
.offsetTop
-me
.t
,p
=_38
.parentNode
;
321 var sl
=parseFloat(s
.left
),st
=parseFloat(s
.top
);
322 if(!isNaN(sl
)&&!isNaN(st
)){
327 if(pcs
.overflow
!="visible"){
328 var be
=d
._getBorderExtents(p
,pcs
);
334 if(d
.isOpera
||(d
.isIE
>7&&!d
.isQuirks
)){
336 be
=d
._getBorderExtents(p
);
342 return {l
:l
,t
:t
,w
:_38
.offsetWidth
+me
.w
,h
:_38
.offsetHeight
+me
.h
};
344 dojo
._getContentBox=function(_3a
,_3b
){
345 var s
=_3b
||gcs(_3a
),pe
=d
._getPadExtents(_3a
,s
),be
=d
._getBorderExtents(_3a
,s
),w
=_3a
.clientWidth
,h
;
347 w
=_3a
.offsetWidth
,h
=_3a
.offsetHeight
;
349 h
=_3a
.clientHeight
,be
.w
=be
.h
=0;
355 return {l
:pe
.l
,t
:pe
.t
,w
:w
-pe
.w
-be
.w
,h
:h
-pe
.h
-be
.h
};
357 dojo
._getBorderBox=function(_3c
,_3d
){
358 var s
=_3d
||gcs(_3c
),pe
=d
._getPadExtents(_3c
,s
),cb
=d
._getContentBox(_3c
,s
);
359 return {l
:cb
.l
-pe
.l
,t
:cb
.t
-pe
.t
,w
:cb
.w
+pe
.w
,h
:cb
.h
+pe
.h
};
361 dojo
._setBox=function(_3e
,l
,t
,w
,h
,u
){
377 dojo
._isButtonTag=function(_3f
){
378 return _3f
.tagName
=="BUTTON"||_3f
.tagName
=="INPUT"&&(_3f
.getAttribute("type")||"").toUpperCase()=="BUTTON";
380 dojo
._usesBorderBox=function(_40
){
382 return d
.boxModel
=="border-box"||n
=="TABLE"||d
._isButtonTag(_40
);
384 dojo
._setContentSize=function(_41
,_42
,_43
,_44
){
385 if(d
._usesBorderBox(_41
)){
386 var pb
=d
._getPadBorderExtents(_41
,_44
);
394 d
._setBox(_41
,NaN
,NaN
,_42
,_43
);
396 dojo
._setMarginBox=function(_45
,_46
,_47
,_48
,_49
,_4a
){
397 var s
=_4a
||gcs(_45
),bb
=d
._usesBorderBox(_45
),pb
=bb
?_4b
:d
._getPadBorderExtents(_45
,s
);
399 if(d
._isButtonTag(_45
)){
401 if(_48
>=0&&!ns
.width
){
404 if(_49
>=0&&!ns
.height
){
409 var mb
=d
._getMarginExtents(_45
,s
);
411 _48
=Math
.max(_48
-pb
.w
-mb
.w
,0);
414 _49
=Math
.max(_49
-pb
.h
-mb
.h
,0);
416 d
._setBox(_45
,_46
,_47
,_48
,_49
);
418 var _4b
={l
:0,t
:0,w
:0,h
:0};
419 dojo
.marginBox=function(_4c
,box
){
420 var n
=_5(_4c
),s
=gcs(n
),b
=box
;
421 return !b
?d
._getMarginBox(n
,s
):d
._setMarginBox(n
,b
.l
,b
.t
,b
.w
,b
.h
,s
);
423 dojo
.contentBox=function(_4d
,box
){
424 var n
=_5(_4d
),s
=gcs(n
),b
=box
;
425 return !b
?d
._getContentBox(n
,s
):d
._setContentSize(n
,b
.w
,b
.h
,s
);
427 var _4e=function(_4f
,_50
){
428 if(!(_4f
=(_4f
||0).parentNode
)){
431 var val
,_51
=0,_52
=d
.body();
432 while(_4f
&&_4f
.style
){
433 if(gcs(_4f
).position
=="fixed"){
447 dojo
._docScroll=function(){
449 return "pageXOffset" in n
?{x
:n
.pageXOffset
,y
:n
.pageYOffset
}:(n
=d
.doc
.documentElement
,n
.clientHeight
?{x
:d
._fixIeBiDiScrollLeft(n
.scrollLeft
),y
:n
.scrollTop
}:(n
=d
.body(),{x
:n
.scrollLeft
||0,y
:n
.scrollTop
||0}));
451 dojo
._isBodyLtr=function(){
452 return "_bodyLtr" in d
?d
._bodyLtr
:d
._bodyLtr
=(d
.body().dir
||d
.doc
.documentElement
.dir
||"ltr").toLowerCase()=="ltr";
454 dojo
._getIeDocumentElementOffset=function(){
455 var de
=d
.doc
.documentElement
;
457 var r
=de
.getBoundingClientRect();
458 var l
=r
.left
,t
=r
.top
;
463 return {x
:l
<0?0:l
,y
:t
<0?0:t
};
468 dojo
._fixIeBiDiScrollLeft=function(_53
){
470 if(d
.isIE
<8&&!d
._isBodyLtr()){
471 var de
=d
.isQuirks
?dd
.body
:dd
.documentElement
;
472 return _53
+de
.clientWidth
-de
.scrollWidth
;
476 dojo
._abs
=dojo
.position=function(_54
,_55
){
477 var db
=d
.body(),dh
=db
.parentNode
,ret
;
479 if(_54
["getBoundingClientRect"]){
480 ret
=_54
.getBoundingClientRect();
481 ret
={x
:ret
.left
,y
:ret
.top
,w
:ret
.right
-ret
.left
,h
:ret
.bottom
-ret
.top
};
483 var _56
=d
._getIeDocumentElementOffset();
484 ret
.x
-=_56
.x
+(d
.isQuirks
?db
.clientLeft
+db
.offsetLeft
:0);
485 ret
.y
-=_56
.y
+(d
.isQuirks
?db
.clientTop
+db
.offsetTop
:0);
489 ret
.x
-=px(dh
,cs
.marginLeft
)+px(dh
,cs
.borderLeftWidth
);
490 ret
.y
-=px(dh
,cs
.marginTop
)+px(dh
,cs
.borderTopWidth
);
494 ret
={x
:0,y
:0,w
:_54
.offsetWidth
,h
:_54
.offsetHeight
};
495 if(_54
["offsetParent"]){
496 ret
.x
-=_4e(_54
,"scrollLeft");
497 ret
.y
-=_4e(_54
,"scrollTop");
500 var n
=_57
.offsetLeft
,t
=_57
.offsetTop
;
506 ret
.x
+=2*px(_57
,cs
.borderLeftWidth
);
507 ret
.y
+=2*px(_57
,cs
.borderTopWidth
);
509 ret
.x
+=px(_57
,cs
.borderLeftWidth
);
510 ret
.y
+=px(_57
,cs
.borderTopWidth
);
513 if(d
.isMoz
&&cs
.position
=="static"){
514 var _58
=_57
.parentNode
;
515 while(_58
!=_57
.offsetParent
){
517 if(pcs
.position
=="static"){
518 ret
.x
+=px(_57
,pcs
.borderLeftWidth
);
519 ret
.y
+=px(_57
,pcs
.borderTopWidth
);
524 _57
=_57
.offsetParent
;
525 }while((_57
!=dh
)&&_57
);
528 ret
.x
+=isNaN(_54
.x
)?0:_54
.x
;
529 ret
.y
+=isNaN(_54
.y
)?0:_54
.y
;
534 var _59
=d
._docScroll();
540 dojo
.coords=function(_5a
,_5b
){
541 var n
=_5(_5a
),s
=gcs(n
),mb
=d
._getMarginBox(n
,s
);
542 var abs
=d
.position(n
,_5b
);
547 var _5c
={"class":"className","for":"htmlFor",tabindex
:"tabIndex",readonly
:"readOnly",colspan
:"colSpan",frameborder
:"frameBorder",rowspan
:"rowSpan",valuetype
:"valueType"},_5d
={classname
:"class",htmlfor
:"for",tabindex
:"tabIndex",readonly
:"readOnly"},_5e
={innerHTML
:1,className
:1,htmlFor
:d
.isIE
,value
:1};
548 var _5f=function(_60
){
549 return _5d
[_60
.toLowerCase()]||_60
;
551 var _61=function(_62
,_63
){
552 var _64
=_62
.getAttributeNode
&&_62
.getAttributeNode(_63
);
553 return _64
&&_64
.specified
;
555 dojo
.hasAttr=function(_65
,_66
){
556 var lc
=_66
.toLowerCase();
557 return _5e
[_5c
[lc
]||_66
]||_61(_5(_65
),_5d
[lc
]||_66
);
559 var _67
={},_68
=0,_69
=dojo
._scopeName
+"attrid",_6a
={col
:1,colgroup
:1,table
:1,tbody
:1,tfoot
:1,thead
:1,tr
:1,title
:1};
560 dojo
.attr=function(_6b
,_6c
,_6d
){
562 var _6e
=arguments
.length
,_6f
;
563 if(_6e
==2&&typeof _6c
!="string"){
565 d
.attr(_6b
,x
,_6c
[x
]);
569 var lc
=_6c
.toLowerCase(),_70
=_5c
[lc
]||_6c
,_71
=_5e
[_70
],_72
=_5d
[lc
]||_6c
;
572 if(_70
=="style"&&typeof _6d
!="string"){
576 if(_70
=="innerHTML"){
577 if(d
.isIE
&&_6b
.tagName
.toLowerCase() in _6a
){
579 _6b
.appendChild(d
._toDom(_6d
,_6b
.ownerDocument
));
585 if(d
.isFunction(_6d
)){
586 var _73
=d
.attr(_6b
,_69
);
604 _67
[_73
][_70
]=d
.connect(_6b
,_70
,_6d
);
607 if(_71
||typeof _6d
=="boolean"){
611 _6b
.setAttribute(_72
,_6d
);
616 if(_71
&&typeof _6d
!="undefined"){
619 if(_70
!="href"&&(typeof _6d
=="boolean"||d
.isFunction(_6d
))){
622 return _61(_6b
,_72
)?_6b
.getAttribute(_72
):null;
624 dojo
.removeAttr=function(_74
,_75
){
625 _5(_74
).removeAttribute(_5f(_75
));
627 dojo
.getNodeProp=function(_76
,_77
){
629 var lc
=_77
.toLowerCase(),_78
=_5c
[lc
]||_77
;
630 if((_78
in _76
)&&_78
!="href"){
633 var _79
=_5d
[lc
]||_77
;
634 return _61(_76
,_79
)?_76
.getAttribute(_79
):null;
636 dojo
.create=function(tag
,_7a
,_7b
,pos
){
640 doc
=_7b
.ownerDocument
;
642 if(typeof tag
=="string"){
643 tag
=doc
.createElement(tag
);
649 d
.place(tag
,_7b
,pos
);
653 d
.empty
=d
.isIE
?function(_7c
){
655 for(var c
;c
=_7c
.lastChild
;){
659 _5(_7d
).innerHTML
="";
661 var _7e
={option
:["select"],tbody
:["table"],thead
:["table"],tfoot
:["table"],tr
:["table","tbody"],td
:["table","tbody","tr"],th
:["table","thead","tr"],legend
:["fieldset"],caption
:["table"],colgroup
:["table"],col
:["table","colgroup"],li
:["ul"]},_7f
=/<\s*([\w\:]+)/,_80
={},_81
=0,_82
="__"+d
._scopeName
+"ToDomId";
664 tw
.pre
=_83
=="option"?"<select multiple=\"multiple\">":"<"+tw
.join("><")+">";
665 tw
.post
="</"+tw
.reverse().join("></")+">";
667 d
._toDom=function(_84
,doc
){
671 doc
[_82
]=_85
=++_81
+"";
672 _80
[_85
]=doc
.createElement("div");
675 var _86
=_84
.match(_7f
),tag
=_86
?_86
[1].toLowerCase():"",_87
=_80
[_85
],_88
,i
,fc
,df
;
678 _87
.innerHTML
=_88
.pre
+_84
+_88
.post
;
679 for(i
=_88
.length
;i
;--i
){
685 if(_87
.childNodes
.length
==1){
686 return _87
.removeChild(_87
.firstChild
);
688 df
=doc
.createDocumentFragment();
689 while(fc
=_87
.firstChild
){
695 dojo
.hasClass=function(_8a
,_8b
){
696 return ((" "+_5(_8a
)[_89
]+" ").indexOf(" "+_8b
+" ")>=0);
698 var _8c
=/\s+/,a1
=[""],_8d=function(s
){
699 if(typeof s
=="string"||s
instanceof String
){
700 if(s
.indexOf(" ")<0){
709 dojo
.addClass=function(_8e
,_8f
){
712 var cls
=_8e
[_89
],_90
;
713 cls
=cls
?" "+cls
+" ":" ";
715 for(var i
=0,len
=_8f
.length
,c
;i
<len
;++i
){
717 if(c
&&cls
.indexOf(" "+c
+" ")<0){
722 _8e
[_89
]=cls
.substr(1,cls
.length
-2);
725 dojo
.removeClass=function(_91
,_92
){
730 cls
=" "+_91
[_89
]+" ";
731 for(var i
=0,len
=_92
.length
;i
<len
;++i
){
732 cls
=cls
.replace(" "+_92
[i
]+" "," ");
742 dojo
.toggleClass=function(_93
,_94
,_95
){
744 _95
=!d
.hasClass(_93
,_94
);
746 d
[_95
?"addClass":"removeClass"](_93
,_94
);