jmeas/prevent-scroll

View on GitHub
dist/prevent-scroll.js.map

Summary

Maintainability
Test Coverage
{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap e6ec69a3d3e340ae5855","webpack:///./src/prevent-scroll.js"],"names":["disabled","currentPosition","currentOverflow","currentWidth","on","htmlEl","document","querySelector","body","bodyScrollTop","scrollTop","htmlScrollTop","style","position","overflowY","width","top","off","parseInt"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;ACVA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;;;;;;ACtCA,KAAIA,WAAW,KAAf;AACA,KAAIC,wBAAJ;AAAA,KAAqBC,wBAArB;AAAA,KAAsCC,qBAAtC;;mBAEe;AACbC,KADa,gBACR;AACH,SAAIJ,QAAJ,EAAc;AACZ;AACD;;AAEDA,gBAAW,IAAX;;AAEA,SAAMK,SAASC,SAASC,aAAT,CAAuB,MAAvB,CAAf;AACA,SAAMC,OAAOF,SAASE,IAAtB;;AAEA;AACA;AACA,SAAMC,gBAAgBD,KAAKE,SAA3B;AACA,SAAMC,gBAAgBN,OAAOK,SAA7B;AACA,SAAIA,YAAYD,gBAAgBA,aAAhB,GAAgCE,aAAhD;;AAEA;AACA;AACAV,uBAAkBI,OAAOO,KAAP,CAAaC,QAA/B;AACAX,uBAAkBG,OAAOO,KAAP,CAAaE,SAA/B;AACAX,oBAAeE,OAAOO,KAAP,CAAaG,KAA5B;;AAEA;AACA;AACAV,YAAOO,KAAP,CAAaC,QAAb,GAAwB,OAAxB;AACA;AACA;AACA;AACAR,YAAOO,KAAP,CAAaE,SAAb,GAAyB,QAAzB;AACA;AACA;AACAT,YAAOO,KAAP,CAAaG,KAAb,GAAqB,MAArB;AACA;AACA;AACAV,YAAOO,KAAP,CAAaI,GAAb,SAAuBN,SAAvB;AACD,IApCY;AAsCbO,MAtCa,iBAsCP;AACJ,SAAI,CAACjB,QAAL,EAAe;AACb;AACD;;AAEDA,gBAAW,KAAX;;AAEA,SAAMK,SAASC,SAASC,aAAT,CAAuB,MAAvB,CAAf;AACA,SAAMC,OAAOF,SAASE,IAAtB;;AAEA;AACAH,YAAOO,KAAP,CAAaC,QAAb,GAAwBZ,eAAxB;AACAI,YAAOO,KAAP,CAAaE,SAAb,GAAyBZ,eAAzB;AACAG,YAAOO,KAAP,CAAaG,KAAb,GAAqBZ,YAArB;;AAEA;AACA,SAAMO,YAAY,CAACQ,SAASb,OAAOO,KAAP,CAAaI,GAAtB,CAAnB;AACA;AACA;AACAX,YAAOK,SAAP,GAAmBA,SAAnB;AACAF,UAAKE,SAAL,GAAiBA,SAAjB;AACD;AA3DY,E","file":"prevent-scroll.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"preventScroll\"] = factory();\n\telse\n\t\troot[\"preventScroll\"] = factory();\n})(this, function() {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap e6ec69a3d3e340ae5855","let disabled = false;\nlet currentPosition, currentOverflow, currentWidth;\n\nexport default {\n  on() {\n    if (disabled) {\n      return;\n    }\n\n    disabled = true;\n\n    const htmlEl = document.querySelector('html');\n    const body = document.body;\n\n    // Determine the `scrollTop` to use. Some browsers require checking the\n    // `body`, others use `html`.\n    const bodyScrollTop = body.scrollTop;\n    const htmlScrollTop = htmlEl.scrollTop;\n    let scrollTop = bodyScrollTop ? bodyScrollTop : htmlScrollTop;\n\n    // Store the current value of the htmlEl's styles – we're about to override\n    // them.\n    currentPosition = htmlEl.style.position;\n    currentOverflow = htmlEl.style.overflowY;\n    currentWidth = htmlEl.style.width;\n\n    // Fixing the position of the `htmlEl` prevents the page from scrolling\n    // at all.\n    htmlEl.style.position = 'fixed';\n    // Setting `overflowY` to `scroll` ensures that any scrollbars that are\n    // around stick around. Otherwise, there would be a \"jump\" when the page\n    // becomes unscrollable as the bar would vanish.\n    htmlEl.style.overflowY = 'scroll';\n    // This makes sure that the page doesn't collapse (usually your CSS will\n    // prevent this, but it's best to be safe)\n    htmlEl.style.width = '100%';\n    // Scoot down the `htmlEl` to be in the same place that the user had\n    // scrolled to.\n    htmlEl.style.top = `-${scrollTop}px`;\n  },\n\n  off() {\n    if (!disabled) {\n      return;\n    }\n\n    disabled = false;\n\n    const htmlEl = document.querySelector('html');\n    const body = document.body;\n\n    // Reset `htmlEl` to the original styles.\n    htmlEl.style.position = currentPosition;\n    htmlEl.style.overflowY = currentOverflow;\n    htmlEl.style.width = currentWidth;\n\n    // Retrieve our original scrollTop from the htmlEl's top\n    const scrollTop = -parseInt(htmlEl.style.top);\n    // Return us to the original scroll position. Once again, we set this on\n    // both the `body` and the `htmlEl` to be safe.\n    htmlEl.scrollTop = scrollTop;\n    body.scrollTop = scrollTop;\n  }\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/prevent-scroll.js"],"sourceRoot":""}