Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirosław Ciastek committed Sep 27, 2017
0 parents commit b22d68d
Show file tree
Hide file tree
Showing 11 changed files with 3,525 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
"es2015",
"stage-0"
]
}
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Editor configuration, see http://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false
35 changes: 35 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"extends": "airbnb-base",
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 6
},
"rules": {
"no-unused-vars": 2,
"max-len": [2, 80, 2],
"no-console": 1,
"prefer-arrow-callback": 2,
"func-style": [
2,
"expression",
{
"allowArrowFunctions": true
}
],
"arrow-body-style": [2, "as-needed"],
"array-bracket-spacing": ["error", "never"],
"computed-property-spacing": ["error", "never"],
"no-duplicate-imports": "error",
"object-curly-spacing": ["error", "always"]
},
"env": {
"node": false,
"browser": true,
"es6": true,
"jest": true
},
"globals": {
"process": 1,
"module": 1
}
}
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Numerous always-ignore extensions
*.diff
*.err
*.log
*.orig
*.rej
*.swo
*.swp
*.vi
*.zip
*~

# OS or Editor folders
._*
.cache
.DS_Store
.idea
.project
.settings
.tmproj
*.esproj
*.sublime-project
*.sublime-workspace
nbproject
Thumbs.db

# Folders to ignore
bower_components
node_modules

# Dev files to ignore
dist/*.map
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Mirosław Ciastek

Permission 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:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE 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.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Sal

Lightweight scroll animation library
1 change: 1 addition & 0 deletions dist/sal.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "sal",
"version": "0.0.1",
"description": "Lightweight scroll animation library",
"main": "dist/sal.js",
"scripts": {
"build": "webpack"
},
"author": "Mirosław Ciastek",
"license": "MIT",
"devDependencies": {
"babel-core": "^6.26.0",
"babel-eslint": "^7.2.3",
"babel-loader": "^7.1.2",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"eslint": "^4.7.2",
"eslint-config-airbnb-base": "^12.0.0",
"eslint-plugin-import": "^2.7.0",
"webpack": "^3.6.0"
}
}
44 changes: 44 additions & 0 deletions src/sal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const defaults = {
rootMargin: '0px',
threshold: 1,
animateClassName: 'animated',
};

export default function (selector = '.js-sal', options = defaults) {
const {
rootMargin,
threshold,
animateClassName,
} = options;

let intersectionObserver = null;

const animate = element => element.classList.add(animateClassName);

const isAnimated = element => element.classList.contains(animateClassName);

const onIntersection = (entries, observer) => {
entries.forEach((entry) => {
if (entry.intersectionRatio > 0) {
observer.unobserve(entry.target);
animate(entry.target);
}
});
};

if (window.IntersectionObserver) {
intersectionObserver = new IntersectionObserver(onIntersection, {
rootMargin,
threshold,
});
} else {
throw Error('Your browser does not support IntersectionObserver!');
}

const elements = [].filter.call(
document.querySelectorAll(selector),
element => !isAnimated(element),
);

elements.forEach(element => intersectionObserver.observe(element));
}
25 changes: 25 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var webpack = require('webpack');
var path = require('path')

module.exports = {
entry: './src/sal.js',
devtool: 'source-map',
output: {
path: path.join(__dirname, 'dist'),
publicPath: 'dist/',
filename: 'sal.js',
library: 'Sal',
libraryTarget: 'umd',
sourceMapFilename: '[file].map'
},
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
}]
},
plugins: [
new webpack.optimize.UglifyJsPlugin()
]
};
Loading

0 comments on commit b22d68d

Please sign in to comment.