* Sets up scrolls array, determines if frames are involved.
()
| 218 | * Sets up scrolls array, determines if frames are involved. |
| 219 | */ |
| 220 | function init() { |
| 221 | if (initDone || isExcluded || !document.body) { |
| 222 | return; |
| 223 | } |
| 224 | initDone = true; |
| 225 | let body = document.body; |
| 226 | let html = document.documentElement; |
| 227 | let windowHeight = window.innerHeight; |
| 228 | let scrollHeight = body.scrollHeight; |
| 229 | // check compat mode for root element |
| 230 | root = document.compatMode.indexOf("CSS") >= 0 ? html : body; |
| 231 | activeElement = body; |
| 232 | // Checks if this script is running in a frame |
| 233 | if (top != self) { |
| 234 | isFrame = true; |
| 235 | } |
| 236 | // TODO: check if clearfix is still needed |
| 237 | else if ( |
| 238 | scrollHeight > windowHeight && |
| 239 | body.clientHeight + 1 < body.scrollHeight && |
| 240 | html.clientHeight + 1 < html.scrollHeight |
| 241 | ) { |
| 242 | if (root.offsetHeight <= windowHeight) { |
| 243 | let clearfix = document.createElement("div"); |
| 244 | clearfix.style.clear = "both"; |
| 245 | body.appendChild(clearfix); |
| 246 | } |
| 247 | } |
| 248 | // disable fixed background |
| 249 | if (!options.fixedBackground && !isExcluded) { |
| 250 | body.style.backgroundAttachment = "scroll"; |
| 251 | html.style.backgroundAttachment = "scroll"; |
| 252 | } |
| 253 | if (!isFrame) { |
| 254 | addEvent("message", function (e) { |
| 255 | if (e.data.SS == "SmoothScroll") { |
| 256 | let wheelEvent = e.data; |
| 257 | wheelEvent.target = getFrameByEvent(e); |
| 258 | wheel(wheelEvent); |
| 259 | } |
| 260 | }); |
| 261 | } |
| 262 | } |
| 263 | function getFrameByEvent(event) { |
| 264 | let iframes = document.getElementsByTagName("iframe"); |
| 265 | return [].filter.call(iframes, function (iframe) { |
no test coverage detected