Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhue committed Aug 30, 2017
0 parents commit 6e065b6
Show file tree
Hide file tree
Showing 17 changed files with 655 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/issue_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### Expected behavior
Tell us what should happen

### Actual behavior
Tell us what happens instead

### Steps to reproduce
Show a way to reproduce
21 changes: 21 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
### Summary

Provide a general description of the code changes in your pull
request... were there any bugs you had fixed? If so, mention them. If
these bugs have open GitHub issues, be sure to tag them here as well,
to keep the conversation linked together.

### Other Information

If there's anything else that's important and relevant to your pull
request, mention that information here. This could include
benchmarks, or other information.

If you are updating any of the CHANGELOG files or are asked to update the
CHANGELOG files by reviewers, please add the CHANGELOG entry at the top of the file.

Finally, if your pull request affects documentation or any non-code
changes, guidelines for those changes are [available
here](https://github.com/slooob/blurry.js/blob/master/CONTRIBUTING.md)

Thanks for contributing to Blurry.js!
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
yarn-error.log
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: node_js
node_js: 8.1.1
script:
- COVERAGE=true BROWSERS=SLChrome,SLInternetExplorer10,SLFirefox,SLInternetExplorer11,SLiOS9 BUNDLESIZE=true travis_retry npm run test
- BROWSERS=SLEdge,SLSafari travis_retry npm run test
after_success:
- npm install -g codeclimate-test-reporter lcov-result-merger
- lcov-result-merger "packages/**/.tmp/coverage/report-lcov/lcov.info" > coverage.info
- codeclimate-test-reporter < coverage.info/DNCg+4NC6vTNT9htny9KBAKn70JNFZrKcfHWgv8cnyhhS9sJKjuyvYz1IF8eQ4CHX9klG1N1JGwFKAfSToySIcBs1ra1m+jG9c3zdJwLc+sfPKnfvF5t4kTLRpM3oENsFR2oIBsV0Tu2npb5wUVZ+YWIBVgLMj0xNaI="
cache:
yarn: true
directories:
- node_modules
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog

### master

* nothing yet

### 1.0.0 - 2017-08-30

* initial release
46 changes: 46 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected]. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Contributing
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 Slooob

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.
103 changes: 103 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Blurry.js - Blurred image loading with [StackBlur](https://github.com/flozz/StackBlur)

[![NPM Version](https://img.shields.io/npm/v/blurry.svg)][pkg-npm]
<img src="https://travis-ci.org/slooob/blurry.js.svg?branch=master" />

---

## Table of Contents

* [Information](#information)
* [Usage](#usage)
* [Options](#options)
* [To Do](#to-do)
* [Contributing](#contributing)
* [Contributors](#contributors)
* [Semantic Versioning](#semantic-versioning)
* [License](#license)

---

## Information

**Size:** Blurry.js takes < 1kb gzipped.

**Dependencies:** [StackBlur](https://github.com/flozz/StackBlur)

---

## Usage

Blurry.js is simple to use:

```javascript
window.onload = function() {
blurry();
};
```

```html
<div class="blurry-media">
<div class="aspect-ratio-fill"></div>
<div class="blurry-media--wrapper">
<img class="blurry-media--thumbnail" src="image.jpeg?quality=20">
<canvas class="blurry-media--canvas"></canvas>
<img class="blurry-media--image" src="image.jpeg">
</div>
</div>
```

### Options

You have some configuration options:

* `blur`: Blur radius as defined by [StackBlur](https://github.com/flozz/StackBlur). Accepts an a float value. Defaults to `100`. To find a value you like check out the [StackBlur demo](http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html).
* `delay`: Milliseconds to wait before removing the blur effect. Accepts an integer. Defaults to `1000`.

---

## To Do

* Leave your suggestions [here](https://github.com/slooob/blurry.js/issues/new)

---

## Contributing

We hope that you will consider contributing to Blurry.js. Please read this short overview for some information about how to get started:

[Learn more about contributing to this repository](https://github.com/slooob/blurry.js/blob/master/CONTRIBUTING.md), [Code of Conduct](https://github.com/slooob/blurry.js/blob/master/CODE_OF_CONDUCT.md)

### Contributors

Give the people some :heart: who are working on this project. See them all at:

https://github.com/slooob/blurry.js/graphs/contributors

### Semantic Versioning

Blurry.js follows Semantic Versioning 2.0 as defined at http://semver.org.

## License

MIT License

Copyright (c) 2017 Slooob

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.
93 changes: 93 additions & 0 deletions blurry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**!
* @fileOverview Blurry.js - Blurred image loading with StackBlur
* @version 1.0.0
* @license
* MIT License
*
* Copyright (c) 2017 Slooob
*
* 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.
*/
'use strict';

var StackBlur = require("stackblur-canvas");

function blurry(options) {

// Default options
var defaults = {
blur: 100,
delay: 1000
};

// Merge options with defaults
options = extend( {}, defaults, options );
function extend() {
for ( var i=1; i<arguments.length; i++ )
for ( var key in arguments[i] )
if ( arguments[i].hasOwnProperty(key) )
arguments[0][key] = arguments[i][key];
return arguments[0];
}

var _typeof = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol' ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === 'function' && obj.constructor === Symbol ? 'symbol' : typeof obj; };

// Main funtionality
function main() {

// Variable definitions
var blurRadius = options['blur'],
initialDelay = options['delay'],
component = document.getElementsByClassName('blurry-media--wrapper'),
image = document.getElementsByClassName('blurry-media--image'),
canvas = document.getElementsByClassName('blurry-media--canvas'),
thumbnail = document.getElementsByClassName('blurry-media--thumbnail'),
context = canvas.getContext('2d');

// Setting aspect-ratio-fill padding
var aspectRatioFill = document.querySelector('.aspect-ratio-fill');
var percentage = thumbnail.naturalHeight / thumbnail.naturalWidth * 100;
aspectRatioFill.style.paddingBottom = percentage + '%';

// Draw the thumbnail onto the canvas, then blur it
drawThumbnail(blurRadius);

// Load the image in. Once it's loaded, add a class to the component wrapper that fades in the image and fades out the canvas element.
image.src = image.dataset.src;
image.addEventListener('load', function onImageLoaded() {
image.removeEventListener('load', onImageLoaded);

// This delay is only set so the we can see the blur effect more clearly on page load
setTimeout(function () {
component.classList.add('blurry-media--loaded');
}, initialDelay);
});

// Draws the thumbnail into the canvas and blurs it
function drawThumbnail(blur) {
context.drawImage(thumbnail, 0, 0, thumbnail.naturalWidth, thumbnail.naturalHeight, 0, 0, canvas.width, canvas.height);
StackBlur.canvasRGBA(canvas, 0, 0, canvas.width, canvas.height, blur);
}

};

// Set a timeout so we make sure StackBlur is defined
setTimeout(main, 0);

};
27 changes: 27 additions & 0 deletions blurry.min.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**!
* @fileOverview Blurry.js - Blurred image loading with StackBlur
* @version 1.0.0
* @license
* MIT License
*
* Copyright (c) 2017 Slooob
*
* 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.
*/
.blurry-media{position:relative}.blurry-media>.aspect-ratio-fill{position:relative;display:block}.blurry-media>.blurry-media--wrapper{background-color:#e7edf2;display:block;position:absolute;top:0;left:0;bottom:0;width:100%;height:100%}.blurry-media>.blurry-media--wrapper.blurry-media--loaded>.blurry-media--image{opacity:1}.blurry-media>.blurry-media--wrapper>.blurry-media--thumbnail{display:none}.blurry-media>.blurry-media--wrapper>.blurry-media--image,.blurry-media>.blurry-media--wrapper>.blurry-media--canvas{border-radius:3px;display:block;position:absolute;top:0;left:0;bottom:0;width:100%;height:100%}.blurry-media>.blurry-media--wrapper>.blurry-media--image{z-index:1;opacity:0;transition:opacity .6s ease-out}
27 changes: 27 additions & 0 deletions blurry.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**!
* @fileOverview Blurry.js - Blurred image loading with StackBlur
* @version 1.0.0
* @license
* MIT License
*
* Copyright (c) 2017 Slooob
*
* 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.
*/
"use strict";function blurry(e){function t(){var t=e.blur,a=e.delay,r=document.getElementsByClassName("blurry-media--wrapper"),n=document.getElementsByClassName("blurry-media--image"),l=document.getElementsByClassName("blurry-media--canvas"),i=document.getElementsByClassName("blurry-media--thumbnail"),u=l.getContext("2d"),s=document.querySelector(".aspect-ratio-fill"),o=i.naturalHeight/i.naturalWidth*100;s.style.paddingBottom=o+"%",function(e){u.drawImage(i,0,0,i.naturalWidth,i.naturalHeight,0,0,l.width,l.height),StackBlur.canvasRGBA(l,0,0,l.width,l.height,e)}(t),n.src=n.dataset.src,n.addEventListener("load",function e(){n.removeEventListener("load",e),setTimeout(function(){r.classList.add("blurry-media--loaded")},a)})}var a={blur:100,delay:1e3};e=function(){for(var e=1;e<arguments.length;e++)for(var t in arguments[e])arguments[e].hasOwnProperty(t)&&(arguments[0][t]=arguments[e][t]);return arguments[0]}({},a,e);"function"==typeof Symbol&&Symbol.iterator;setTimeout(t,0)}var StackBlur=require("stackblur-canvas");
Loading

0 comments on commit 6e065b6

Please sign in to comment.