]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/window.js.uncompressed.js
1 define ( "dojo/window" , [ "./_base/lang" , "./_base/sniff" , "./_base/window" , "./dom" , "./dom-geometry" , "./dom-style" ],
2 function ( lang
, has
, baseWindow
, dom
, geom
, style
) {
9 var window
= lang
. getObject ( "dojo.window" , true );
19 window
. getBox = function (){
21 // Returns the dimensions and scroll position of the viewable area of a browser window
24 scrollRoot
= ( baseWindow
. doc
. compatMode
== 'BackCompat' ) ? baseWindow
. body () : baseWindow
. doc
. documentElement
,
25 // get scroll position
26 scroll
= geom
. docScroll (), // scrollRoot.scrollTop/Left should work
29 if ( has ( "touch" )){ // if(scrollbars not supported)
30 var uiWindow
= baseWindow
. doc
. parentWindow
|| baseWindow
. doc
. defaultView
; // use UI window, not dojo.global window. baseWindow.doc.parentWindow probably not needed since it's not defined for webkit
31 // on mobile, scrollRoot.clientHeight <= uiWindow.innerHeight <= scrollRoot.offsetHeight, return uiWindow.innerHeight
32 w
= uiWindow
. innerWidth
|| scrollRoot
. clientWidth
; // || scrollRoot.clientXXX probably never evaluated
33 h
= uiWindow
. innerHeight
|| scrollRoot
. clientHeight
;
35 // on desktops, scrollRoot.clientHeight <= scrollRoot.offsetHeight <= uiWindow.innerHeight, return scrollRoot.clientHeight
36 // uiWindow.innerWidth/Height includes the scrollbar and cannot be used
37 w
= scrollRoot
. clientWidth
;
38 h
= scrollRoot
. clientHeight
;
48 window
. get = function ( doc
){
50 // Get window object associated with document doc
52 // In some IE versions (at least 6.0), document.parentWindow does not return a
53 // reference to the real window object (maybe a copy), so we must fix it as well
54 // We use IE specific execScript to attach the real window reference to
55 // document._parentWindow for later use
56 if ( has ( "ie" ) && window
!== document
. parentWindow
){
58 In IE 6, only the variable "window" can be used to connect events (others
61 doc
. parentWindow
. execScript ( "document._parentWindow = window;" , "Javascript" );
62 //to prevent memory leak, unset it after use
63 //another possibility is to add an onUnload handler which seems overkill to me (liucougar)
64 var win
= doc
. _parentWindow
;
65 doc
. _parentWindow
= null ;
69 return doc
. parentWindow
|| doc
. defaultView
; // Window
72 window
. scrollIntoView = function ( /*DomNode*/ node
, /*Object?*/ pos
){
74 // Scroll the passed node into view, if it is not already.
76 // don't rely on node.scrollIntoView working just because the function is there
78 try { // catch unexpected/unrecreatable errors (#7808) since we can recover using a semi-acceptable native method
79 node
= dom
. byId ( node
);
80 var doc
= node
. ownerDocument
|| baseWindow
. doc
,
81 body
= doc
. body
|| baseWindow
. body (),
82 html
= doc
. documentElement
|| body
. parentNode
,
83 isIE
= has ( "ie" ), isWK
= has ( "webkit" );
84 // if an untested browser, then use the native method
85 if ((!( has ( "mozilla" ) || isIE
|| isWK
|| has ( "opera" )) || node
== body
|| node
== html
) && ( typeof node
. scrollIntoView
!= "undefined" )){
86 node
. scrollIntoView ( false ); // short-circuit to native if possible
89 var backCompat
= doc
. compatMode
== 'BackCompat' ,
90 clientAreaRoot
= ( isIE
>= 9 && node
. ownerDocument
. parentWindow
. frameElement
)
91 ? (( html
. clientHeight
> 0 && html
. clientWidth
> 0 && ( body
. clientHeight
== 0 || body
. clientWidth
== 0 || body
. clientHeight
> html
. clientHeight
|| body
. clientWidth
> html
. clientWidth
)) ? html
: body
)
92 : ( backCompat
? body
: html
),
93 scrollRoot
= isWK
? body
: clientAreaRoot
,
94 rootWidth
= clientAreaRoot
. clientWidth
,
95 rootHeight
= clientAreaRoot
. clientHeight
,
96 rtl
= ! geom
. isBodyLtr (),
97 nodePos
= pos
|| geom
. position ( node
),
99 isFixed = function ( el
){
100 return (( isIE
<= 6 || ( isIE
&& backCompat
))? false : ( style
. get ( el
, 'position' ). toLowerCase () == "fixed" ));
102 if ( isFixed ( node
)){ return ; } // nothing to do
105 if ( el
== body
){ el
= scrollRoot
; }
106 var elPos
= geom
. position ( el
),
107 fixedPos
= isFixed ( el
);
109 if ( el
== scrollRoot
){
110 elPos
. w
= rootWidth
; elPos
. h
= rootHeight
;
111 if ( scrollRoot
== html
&& isIE
&& rtl
){ elPos
. x
+= scrollRoot
. offsetWidth
- elPos
. w
; } // IE workaround where scrollbar causes negative x
112 if ( elPos
. x
< 0 || ! isIE
){ elPos
. x
= 0 ; } // IE can have values > 0
113 if ( elPos
. y
< 0 || ! isIE
){ elPos
. y
= 0 ; }
115 var pb
= geom
. getPadBorderExtents ( el
);
116 elPos
. w
-= pb
. w
; elPos
. h
-= pb
. h
; elPos
. x
+= pb
. l
; elPos
. y
+= pb
. t
;
117 var clientSize
= el
. clientWidth
,
118 scrollBarSize
= elPos
. w
- clientSize
;
119 if ( clientSize
> 0 && scrollBarSize
> 0 ){
120 elPos
. w
= clientSize
;
121 elPos
. x
+= ( rtl
&& ( isIE
|| el
. clientLeft
> pb
. l
/*Chrome*/ )) ? scrollBarSize
: 0 ;
123 clientSize
= el
. clientHeight
;
124 scrollBarSize
= elPos
. h
- clientSize
;
125 if ( clientSize
> 0 && scrollBarSize
> 0 ){
126 elPos
. h
= clientSize
;
129 if ( fixedPos
){ // bounded by viewport, not parents
131 elPos
. h
+= elPos
. y
; elPos
. y
= 0 ;
134 elPos
. w
+= elPos
. x
; elPos
. x
= 0 ;
136 if ( elPos
. y
+ elPos
. h
> rootHeight
){
137 elPos
. h
= rootHeight
- elPos
. y
;
139 if ( elPos
. x
+ elPos
. w
> rootWidth
){
140 elPos
. w
= rootWidth
- elPos
. x
;
143 // calculate overflow in all 4 directions
144 var l
= nodePos
. x
- elPos
. x
, // beyond left: < 0
145 t
= nodePos
. y
- Math
. max ( elPos
. y
, 0 ), // beyond top: < 0
146 r
= l
+ nodePos
. w
- elPos
. w
, // beyond right: > 0
147 bot
= t
+ nodePos
. h
- elPos
. h
; // beyond bottom: > 0
149 var s
= Math
[ l
< 0 ? "max" : "min" ]( l
, r
);
150 if ( rtl
&& (( isIE
== 8 && ! backCompat
) || isIE
>= 9 )){ s
= - s
; }
151 nodePos
. x
+= el
. scrollLeft
;
153 nodePos
. x
-= el
. scrollLeft
;
156 nodePos
. y
+= el
. scrollTop
;
157 el
. scrollTop
+= Math
[ t
< 0 ? "max" : "min" ]( t
, bot
);
158 nodePos
. y
-= el
. scrollTop
;
160 el
= ( el
!= scrollRoot
) && ! fixedPos
&& el
. parentNode
;
163 console
. error ( 'scrollIntoView: ' + error
);
164 node
. scrollIntoView ( false );