9 | | var $body, $window, $sidebar, adminbarOffset, top = false, |
10 | | bottom = false, windowWidth, windowHeight, lastWindowPos = 0, |
11 | | topOffset = 0, bodyHeight, sidebarHeight, resizeTimer, |
12 | | secondary, button; |
| 9 | var $body, $window, $sidebar, resizeTimer, |
| 10 | secondary, button; |
107 | | function scroll() { |
108 | | var windowPos = $window.scrollTop(); |
109 | | |
110 | | if ( 955 > windowWidth ) { |
111 | | return; |
112 | | } |
113 | | |
114 | | sidebarHeight = $sidebar.height(); |
115 | | windowHeight = $window.height(); |
116 | | bodyHeight = $body.height(); |
117 | | |
118 | | if ( sidebarHeight + adminbarOffset > windowHeight ) { |
119 | | if ( windowPos > lastWindowPos ) { |
120 | | if ( top ) { |
121 | | top = false; |
122 | | topOffset = ( $sidebar.offset().top > 0 ) ? $sidebar.offset().top - adminbarOffset : 0; |
123 | | $sidebar.attr( 'style', 'top: ' + topOffset + 'px;' ); |
124 | | } else if ( ! bottom && windowPos + windowHeight > sidebarHeight + $sidebar.offset().top && sidebarHeight + adminbarOffset < bodyHeight ) { |
125 | | bottom = true; |
126 | | $sidebar.attr( 'style', 'position: fixed; bottom: 0;' ); |
127 | | } |
128 | | } else if ( windowPos < lastWindowPos ) { |
129 | | if ( bottom ) { |
130 | | bottom = false; |
131 | | topOffset = ( $sidebar.offset().top > 0 ) ? $sidebar.offset().top - adminbarOffset : 0; |
132 | | $sidebar.attr( 'style', 'top: ' + topOffset + 'px;' ); |
133 | | } else if ( ! top && windowPos + adminbarOffset < $sidebar.offset().top ) { |
134 | | top = true; |
135 | | $sidebar.attr( 'style', 'position: fixed;' ); |
136 | | } |
137 | | } else { |
138 | | top = bottom = false; |
139 | | topOffset = ( $sidebar.offset().top > 0 ) ? $sidebar.offset().top - adminbarOffset : 0; |
140 | | $sidebar.attr( 'style', 'top: ' + topOffset + 'px;' ); |
141 | | } |
142 | | } else if ( ! top ) { |
143 | | top = true; |
144 | | $sidebar.attr( 'style', 'position: fixed;' ); |
145 | | } |
146 | | |
147 | | lastWindowPos = windowPos; |
148 | | } |
149 | | |
150 | | function resizeAndScroll() { |
151 | | resize(); |
152 | | scroll(); |
153 | | } |
154 | | |