[
  {
    "path": "LICENSE",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2015 Mees Boeijen\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n"
  },
  {
    "path": "README.md",
    "content": "# slimScroller.js\n![](http://forthebadge.com/images/badges/built-with-love.svg)\n\nSmoothly scroll to positions on your website, under 350 bytes, no dependencies.\n\n## Two versions\n### [SlimScroller Base](https://github.com/ameesme/SlimScroller.js/blob/master/dist/slimScroller.min.js)\n    343 bytes gzipped\n    580 bytes uncompressed\n\nThe base version includes support for one type of scroll-target:\n- CSS selector ( eg. `slimScroller.scroll(\"p:first-of-type\")` )\n\n### [SlimScroller Full](https://github.com/ameesme/SlimScroller.js/blob/master/dist/slimScroller.full.min.js)\n    570  bytes gzipped\n    1030 bytes uncompressed\nThe full version includes support for three types of scroll-targets:\n- Position in pixels ( eg. `slimScroller.scroll(200)` )\n- CSS selector ( eg. `slimScroller.scroll(\"p:first-of-type\")` )\n- Direct JavaScript HTML-element ( eg. `slimScroller.scroll(document.querySelector(p#hi))` )\n\n### Hasthags\nWant to bind SlimScroller to all anchor-tags on a page? Run `slimScroller.bind()` when the dom finishes loading. Only supported on [SlimScroller Full](https://github.com/ameesme/SlimScroller.js/blob/master/dist/slimScroller.full.min.js).\n\n## How to use\nJust use the `slimScroller.scroll`-function with the following parameters.\n- `Required` Scroll-target (according to SlimScroller-version)\n- `Optional` Scroll-duration (`ms`)\n- `Optional` Horizontal-scrolling instead of vertical (`boolean`)\n- `Optional` Callback-function with final scroll-position as parameter\n\n### NPM\nRun `npm install slimscroller`.\n\n### Hosted\n#### Base\n```<script src=\"https://amees.me/files/public/SlimScroller.js/dist/slimScroller.min.js\"></script>```\n\n#### Full\n```<script src=\"https://amees.me/files/public/SlimScroller.js/dist/slimScroller.full.min.js\"></script>```\n\n## Demo\n[View here](https://amees.me/files/public/SlimScroller.js/demo.html).\n\n## NPM\nRun `npm install slimscroller`.\n\n##License (MIT)\nCopyright © 2016 Mees Boeijen\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "demo.html",
    "content": "<html>\n\t<head>\n\t\t<title>slimScroller.js Demo</title>\n\t\t<!-- These styles are not required for the actual plugin. Just for the demo. -->\n\t\t<style>\n\t\t\tbody{\n\t\t\t\tpadding: 0;\n\t\t\t\tmargin: 0;\n\t\t\t}\n\t\t\tp{\n\t\t\t\tfont-family: sans-serif;\n\t\t\t\tline-height: 25px;\n\t\t\t}\n\t\t</style>\n\t</head>\n\t<body>\n\t\t<button onclick='slimScroller.scroll(300)'>Scroll to 300px</button>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<a href='#testPar'>Scroll to a paragraph via an anchor-tag.</a>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<button onclick='slimScroller.scroll(\"p:last-of-type\")'>Scroll to last paragraph selector</button>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p id='testPar'>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<p>This is a line of text that does not serve any actual purpose but to waste some of your energy.</p>\n\t\t<button onclick='slimScroller.scroll(document.querySelector(\"button:first-of-type\"))'>Scroll to first button JS-element</button>\n\n\t\t<script src='src/slimScroller.full.js'></script>\n\t\t<script>\n\t\t\twindow.addEventListener('load', function (){\n\t\t\t\treturn slimScroller.bind(false, function (position){\n\t\t\t\t\tconsole.log('The current position is '+position);\n\t\t\t\t});\n\t\t\t});\n\t\t</script>\n\t</body>\n</html>"
  },
  {
    "path": "dist/init.js",
    "content": "// This script is only used for installation via Eager.\ndocument.addEventListener(\"DOMContentLoaded\", function(event) { \n\tslimScroller.bind();\n});"
  },
  {
    "path": "install.json",
    "content": "{\n\t\"resources\": {\n\t\t\"body\": [\n\t\t\t{\n\t\t\t\t\"type\": \"script\",\n\t\t\t\t\"src\": \"dist/slimScroller.min.js\"\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"type\": \"script\",\n\t\t\t\t\"src\": \"dist/init.js\"\n\t\t\t}\n\t\t]\n\t}\n}"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"slimscroller\",\n  \"version\": \"2.0.4\",\n  \"description\": \"Slim smooth-scrolling under 350 bytes (gzipped), with no other dependencies.\",\n  \"main\": \"dist/slimScroller.full.min.js\",\n  \"author\": \"Mees Boeijen <mees@amees.me> (https://amees.me)\",\n  \"license\": \"MIT\",\n  \"homepage\": \"https://github.com/ameesme/SlimScroller.js\",\n  \"repository\": \"https://github.com/ameesme/SlimScroller.js\",\n  \"keywords\": [\"tiny\", \"smooth scroll\", \"no dependencies\"]\n}\n"
  },
  {
    "path": "src/slimScroller.full.js",
    "content": "var slimScroller = function (){\n    'use strict';\n\n    var elapsed, horizontal;\n    var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame;\n\n    var scroll = function (target, horizontal, durationTime, callbackFunction, scrollTarget) {\n        var scrollTargetReference = (scrollTarget && scrollTarget instanceof Element) || window;\n        var duration = durationTime || 500;\n        var horizontal = horizontal || false;\n        var callback = callbackFunction || false;\n        var startPosition = (horizontal) ? window.pageXOffset : window.pageYOffset;\n        var total = (horizontal) ? pageXOffset.scrollWidth : pageXOffset.scrollHeight;\n        var targetPosition = (parsePosition(target) > total) ? total : parsePosition(target);\n\n        var clock = Date.now();\n        step(duration, horizontal, callback, startPosition, total, targetPosition, scrollTarget, clock)();\n    };\n    var easeInOutCubic = function (time) {\n        return (time < 0.5) ? 4 * time * time * time : (time - 1) * (2 * time - 2) * (2 * time - 2) + 1;\n    };\n    var calculatePosition = function (elapsed, duration, targetPosition, startPosition) {\n        return (elapsed > duration) ? targetPosition : startPosition + (targetPosition - startPosition) * easeInOutCubic(elapsed / duration);\n    };\n    var parsePosition = function (target){\n        var parseNumber = parseInt(target);\n        var parseElement = target.offsetLeft;\n        var parseSelector;\n        try{\n            parseSelector = document.querySelector(target);\n        }catch(e){}\n\n        if (parseNumber) {\n            // Target is pixel value\n            return parseNumber;\n        }else if(parseSelector){\n            // Target is CSS-selector\n            return (horizontal) ? document.querySelector(target).offsetLeft : document.querySelector(target).offsetTop;\n        }else if(parseElement !== undefined){\n            // Target is HTML-element\n            return (horizontal) ? parseElement : target.offsetTop;\n        }else{\n            // Unknown type\n            throw new Error('Unknown type as target');\n        }\n    };\n    var step = function (duration, horizontal, callback, startPosition, total, targetPosition, scrollTarget, clock) {\n        return function() {\n            elapsed = Date.now() - clock;\n            var stepPosition = calculatePosition(elapsed, duration, targetPosition, startPosition);\n            var scrollTargetReference = (scrollTarget && scrollTarget instanceof Element) || window;\n    \n            if (horizontal){\n                scrollTargetReference.scroll(stepPosition, 0);\n            }else{\n                scrollTargetReference.scroll(0, stepPosition);\n            }\n            if (elapsed > duration) {\n                if (callback) {\n                    callback([window.scrollX,window.scrollY]);\n                }\n            } else {\n                requestAnimationFrame(step(duration, horizontal, callback, startPosition, total, targetPosition, scrollTarget, clock));\n            }\n        }\n    };\n    var bind = function (time, callbackFunction) {\n        var allAnchors = document.querySelectorAll('a');\n        var i;\n        for (i = 0; i < allAnchors.length; i++) {\n            if (allAnchors[i].href == window.location.href.split('#')[0] + '#' + allAnchors[i].href.split('#')[1]) {\n                allAnchors[i].addEventListener('click', function (event) {\n                    event.preventDefault();\n                    slimScroller.scroll('#'+event.target.href.split('#')[1], null, time, callbackFunction);\n                    window.location.href = event.target.href;\n                    return;\n                });\n            }\n        }\n    };\n    return {\n        scroll: scroll,\n        bind: bind\n    };\n}();\n"
  },
  {
    "path": "src/slimScroller.js",
    "content": "var slimScroller = function (){\n    'use strict';\n\n    var targetPosition,horizontal,clock,elapsed,duration,startPosition,total,callback,elementPosition;\n    var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame;\n\n    var scroll = function (target, horizontal, durationTime, callbackFunction) {\n        duration = durationTime || 500;\n        horizontal = horizontal || false;\n        callback = callbackFunction || false;\n        startPosition = (horizontal) ? window.pageXOffset : window.pageYOffset;\n        total = (horizontal) ? document.body.scrollWidth : document.body.scrollHeight;\n        elementPosition =(horizontal) ? document.querySelector(target).offsetLeft : document.querySelector(target).offsetTop;\n        targetPosition = (elementPosition > total) ? total : elementPosition;\n\n        clock = Date.now();\n        step();\n    };\n    var easeInOutCubic = function (time) {\n        return (time < 0.5) ? 4 * time * time * time : (time - 1) * (2 * time - 2) * (2 * time - 2) + 1;\n    };\n    var calculatePosition = function () {\n        return (elapsed > duration) ? targetPosition : startPosition + (targetPosition - startPosition) * easeInOutCubic(elapsed / duration);\n    };\n    var step = function () {\n        elapsed = Date.now() - clock;\n        var stepPosition = calculatePosition();\n\n        if (horizontal){\n            window.scroll(stepPosition, 0);\n        }else{\n            window.scroll(0, stepPosition);\n        }\n        if (elapsed > duration) {\n            if (callback) {\n                callback([window.scrollX,window.scrollY]);\n            }\n        } else {\n            requestAnimationFrame(step);\n        }\n    };\n    return {\n        scroll: scroll\n    };\n}();\n"
  }
]