Skip to content

Commit

Permalink
bumb version to 0.4.0 and move all of readme to index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
sjwilliams committed Jun 1, 2014
1 parent 8941661 commit d4e4700
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 192 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014 Josh Williams

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.
188 changes: 2 additions & 186 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,187 +1,3 @@
#LaziestLoader
###A responsive-aware jQuery plugin to smartly lazy load images and other elements.
LaziestLoader is a responsive and retina-aware lazy loader for jQuery.

Speed up page load times by delaying the load of images and other elements until they enter -- or are about to enter -- the viewport. You can specify an single image source, or a range of source images for responsive applications. Additionally, the source can dynamically change on browser resize.

This project is based heavily on Luís Almeida's [unveil] (http://luis-almeida.github.com/unveil/).

###Demo
Visit the [project page](http://sjwilliams.github.io/laziestloader/) to see responsive and non-responsive image examples, and examples using videos, iframes and customized behavior.

####Usage

#####1. Non-responsive
Use a placeholder image in the src attribute - something to be displayed while the original image loads - and include the actual image source in a "data-src" attribute.
If you want to serve high-resolution images to devices with retina displays, you just have to include the source for those images in a "data-src-retina" attribute.
You don't need to include a "data-src-retina" attribute in all the image tags, laziestloader is smart enough to fallback to "data-src" or even do nothing in case there isn't any "data-src" specified.
```html
<img src="transparent.gif" data-src="img1.jpg">
<img src="transparent.gif" data-src="img2.jpg" data-src-retina="img2-retina.jpg">
```
If you care about users without javascript enabled, you can include the original image inside a ```noscript``` tag:
```html
<noscript>
<img src="img1.jpg" />
</noscript>
```
Run the script on document ready:
```javascript
$(document).ready(function() {
$("img").laziestloader();
});
```
#####2a. Responsive, by file width
If you have different versions of your image with the width as part of the image name or path, you can specify an array of sizes that correspond to the available files.

```html
<img src="transparent.gif" data-pattern="path/to/yourimages/image-{{size}}.jpg" data-pattern-retina="path/to/yourimages/image-{{size}}@2x.jpg" data-widths="[320, 640, 900, 1564]">
<img src="transparent.gif" data-pattern="path/to/yourimages/{{size}}/image.jpg" data-pattern-retina="path/to/yourimages/{{size}}/[email protected]" data-widths="[320, 640, 900, 1564]">
```
```javascript
$("img").laziestloader();
```

The result would be along these lines:
```html
<img src="path/to/yourimages/image-900.jpg">
<img src="path/to/yourimages/900/image.jpg">
```

**_Note:_** LaziestLoader uses the calculated width of the element to detect the best size from `data-widths`. It's important to ensure your element, especially inline elements like images that don't automatically assume 100% of their parent's width, are given a width before LaziestLoader is called the first time, otherwise the calculation will be wrong, and probably too small. [More details.](https://github.com/sjwilliams/laziestloader/issues/10)

#####2b. Responsive, by file slug
If you have different versions of your image with width represented by a slug, you can specify an array of sizes and corresponding slugs.
```html
<img src="transparent.gif"
data-pattern="path/to/yourimages/image-{{size}}.jpg"
data-widths='[{"size":1024,"slug":"big"}, {"size":2000,"slug":"huge"}]'>
```
```javascript
$("img").laziestloader();
```

The result would be one of these:
```html
<img src="path/to/yourimages/image-big.jpg">
<img src="path/to/yourimages/image-huge.jpg">
```

#####3. Custom
Need fancier logic to determine the source path? You can write your own `getSource` method in the options object.
```html
<img src="transparent.gif">
```
```javascript
$("img").laziestloader({
getSource: function($el) {
var width = $el.width();
var height = Math.round(width * 0.5625);
return 'http://placekitten.com/'+width+'/'+height;
}
});
```
####Set Element Height
Often in responsive applications it's useful to set the height of an element before the source is loaded so the element will pre-fill the correct amount of space. If the `data-ratio` attribute contains a number, the element will have its CSS height set to the width of the element multiplied by the `data-ratio`.
```html
<img src="transparent.gif" data-src="img1.jpg" data-ratio="0.5625">
```
```javascript
$("img").laziestloader();
```

###Callback
As a second parameter you can specify a callback function that will fire after an element as been loaded.
Inside the callback function ```this``` refers to the element's DOM node.
```css
img {
opacity: 0;
transition: opacity .3s ease-in;
}
```
```javascript
$("img").laziestloader({}, function() {
this.style.opacity = 1;
});
```

### Options
In addition to the "Custom" `getSource` example above, there are other optional behaviors that can be configured in the options object.

####threshold
By default, images are only loaded when the user scrolls to them and they became visible on the screen.
If you want your images to load earlier than that, lets say 200px before they appear on the screen, specify the threshold in the options object.
```javascript
$("img").laziestloader({threshold: 200});
```

####scrollThrottle
To increase performance, the position of lazy loading elements are only checked every 250ms while scrolling. If you need to perform the check more often, lower the number. If scroll performance is an issue -- likely if there are lots of elements -- increase the number.
```javascript
$("img").laziestloader({scrollThrottle: 300});
```

####sizeOffsetPercent
The crop selection logic works by picking the image that is greater than or equal to the size of the current element. If you prefer to scale smaller images into larger elements, set this between 0 and 100, where the value is the percent width of the containing element you want to subtract from the math logic. The bigger the number, the smaller the image that'll be selected.
```javascript
$("img").laziestloader({sizeOffsetPercent: 10});
```

####sizePattern
The regular expression used to search your string, to be replaced by the width number or slug. The default is `/{{SIZE}}/ig`, which finds the string `size`, regardless of case, inside of '{' style double brackets. Example: `/path/name-{{size}}.jpg`. Changing this option is useful if, for example, you have Mustache-style templates rendered on the server that would also match the default laziestloader.js pattern and be rendered blank before our client code runs. Many characters have special meaning and can't be used. A nice alternal pattern is:
```javascript
$("img").laziestloader({sizePattern: /%size%/ig});
```

#####setSourceMode
In most cases, the plugin needs to set the source attribute of the element. If you want to use the plugin in ways that don't involve simply setting a source attribute, set `setSourceMode` to false and use the callback to completely manage the behavior of the element on trigger.

```html
<div><p>Replace me</p></div>
```
```js
$('div').laziestloader({
setSourceMode: false
}, function(){
$(this).html('<p>New content</p>')
});
```

###Trigger
You can trigger element loading whenever you need, without needed to scroll the element into view.
```javascript
$("img").trigger("laziestloader");
```

## Release History
*0.3.0*

* Exposed `bestFit` method so it can be used in callbacks. See [Issue 4](https://github.com/sjwilliams/laziestloader/issues/4).

*0.2.0*

* Added a scrollThrottle option, and set a reasonable default. See [Issue 5](https://github.com/sjwilliams/laziestloader/issues/5).
* Changed data-height-multiplier to data-ratio, and deprecated original. See [Issue 6](https://github.com/sjwilliams/laziestloader/issues/6).

*0.1.2*

* Fixed [Issue 1](https://github.com/sjwilliams/laziestloader/issues/1), bug with non-sorted input.

*0.1.1*

* Added `sizePattern` option.

*0.1.0*

* Added `sizeOffsetPercent` option.

*0.0.2*

* AMD module
* Enforce style with .editorconfig, .jshintrc and .jsbeautifyrc

*0.0.1*

* Initial release.

###License
LaziestLoader is licensed under the [MIT license](http://opensource.org/licenses/MIT).
Documenation and examples at [http://sjwilliams.github.io/laziestloader/](http://sjwilliams.github.io/laziestloader/)
80 changes: 78 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,24 @@
box-shadow:3px 4px 10px rgba(0, 0, 0, 0.8);
}
}

#releasehistory h4{
margin: 0 0 3px 0;
}

#releasehistory ul{
margin: 0 0 11px 0;
padding: 0px;
}

#releasehistory li{
font-size: 13px;
line-height: 15px;
margin: 0 0 3px 0;
padding: 0;
list-style-type: none;
}

</style>

<body>
Expand Down Expand Up @@ -555,7 +573,7 @@ <h3>Completely Custom Behavior /w Callback</h3>
</div>
</section>

<section class="options">
<section>
<h2>Options</h2>
<p>In addition to the "Custom Source Function" using `getSource` example above, there are other optional behaviors that can be configured in the options object.</p>

Expand Down Expand Up @@ -600,14 +618,72 @@ <h3>setSourceMode</h3>
</pre>
</section>

<section class="trigger">
<section>
<h2>Trigger</h2>
<p>You can trigger element loading without scrolling the element into view.</p>
<code>
$("img.lazy").trigger("laziestloader");
</code>
</section>

<section id="releasehistory">
<h2>Release History</h2>
<h4>0.4.0</h4>
<ul>
<li>Added minified version and npm build task to generate it.</li>
<li>Moved all documentation from README.md to redesigned project page.</li>
</ul>

<h4>0.3.0</h4>
<ul>
<li>Exposed `bestFit` method so it can be used in callbacks. See <a href="https://github.com/sjwilliams/laziestloader/issues/4">Issue 4</a>).</li>
</ul>

<h4>0.2.0</h4>
<ul>
<li>Added a scrollThrottle option, and set a reasonable default. See <a href="https://github.com/sjwilliams/laziestloader/issues/5">Issue 5</a>).</li>
<li>Changed data-height-multiplier to data-ratio, and deprecated original. See <a href="https://github.com/sjwilliams/laziestloader/issues/6">Issue 6</a>)</li>
</ul>

<h4>0.1.2</h4>
<ul>
<li>Fixed <a href="https://github.com/sjwilliams/laziestloader/issues/1">Issue 1</a>), bug with non-sorted input.</li>
</ul>

<h4>0.1.1</h4>
<ul>
<li>Added `sizePattern` option.</li>
</ul>

<h4>0.1.0</h4>
<ul>
<li>Added `sizeOffsetPercent` option.</li>
</ul>

<h4>0.0.2</h4>
<ul>
<li>AMD module</li>
<li>Enforce style with .editorconfig, .jshintrc and .jsbeautifyrc</li>
</ul>

<h4>0.0.1</h4>
<ul>
<li>Initial release.</li>
</ul>

</section>


<section>
<h2>Credits</h2>
<p>This project is based heavily on Luís Almeida's <a href="http://luis-almeida.github.com/unveil/">unveil</a></p>
</section>

<section>
<h2>License</h2>
<p>LaziestLoader is licensed under the <a href="https://raw.githubusercontent.com/sjwilliams/laziestloader/master/LICENSE">MIT license</a></p>
</section>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="jquery-1.9.1.min.js"><\/script>')
Expand Down
2 changes: 1 addition & 1 deletion jquery.laziestloader-min.js

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

2 changes: 1 addition & 1 deletion jquery.laziestloader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! LaziestLoader - v0.3.0 - 2014-03-28
/** LaziestLoader - v0.4.0 - 2014-03-28
* A responsive-aware jQuery plugin to smartly lazy load images and other elements.
* https://github.com/sjwilliams/laziestloader
* Thanks to Luís Almeida for 'unveil,' on which this project is based.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "laziestloader",
"version": "0.3.0",
"version": "0.4.0",
"author": "Josh Williams <[email protected]>",
"description": "A responsive-aware jQuery plugin to smartly lazy load images and other elements.",
"repository": {
Expand All @@ -18,6 +18,6 @@
"uglify-js": "^2.4.13"
},
"scripts": {
"build": "uglifyjs jquery.laziestloader.js -c -o jquery.laziestloader-min.js"
"build": "uglifyjs jquery.laziestloader.js -c --comments -o jquery.laziestloader-min.js"
}
}

0 comments on commit d4e4700

Please sign in to comment.