Skip to content

Commit

Permalink
update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
aFarkas committed Apr 28, 2015
1 parent cad4cbd commit 5fae00a
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 49 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ window.lazySizesConfig.customMedia = {
</picture>
```
* ``lazySizesConfig.expFactor`` (default: ``2``): The ``expFactor`` is used to calculate the "preload expand", by multiplying the normal ``expand`` with the ``expFactor``, which is used to preload assets while the browser is idling (no important network traffic and no scrolling). (Reasonable values are between ``1.5`` and ``10`` depending on the ``expand`` option).
* ``lazySizesConfig.loadMode`` (default: ``2``): The ``loadMode`` can be used to constrain the allowed loading mode. Possible values are 0 = don't load anything, 1 = only load visible elements, 2 = load also very near view elements (``expand`` option) and 3 = load also not so near elements (``expand`` * ``expFactor`` option). This value is automatically set to ``3`` after onload. Change this value to ``1`` if you (also) optimize for the onload event or change it to ``3`` if your onload event is already heavily delayed.
* ``lazySizesConfig.loadMode`` (default: ``2``): The ``loadMode`` can be used to constrain the allowed loading mode. Possible values are 0 = don't load anything, 1 = only load visible elements, 2 = load also very near view elements (``expand`` option) and 3 = load also not so near elements (``expand`` * ``expFactor`` option). This value is automatically set to ``3`` after onload. Change this value to ``1`` if you (also) optimize for the onload event (often recommended) or change it to ``3`` if your onload event is already heavily delayed.
* ``lazySizesConfig.init`` (default: ``true``): By default lazysizes initializes itself as soon as possible, to load inview assets as soon as possible. In the unlikely case you need to setup/configure something with a later script you can set this option to ``false`` and call ``lazySizes.init();`` later explicitly.

####JS API - events
Expand Down Expand Up @@ -333,7 +333,7 @@ document.addEventListener('lazybeforeunveil', function(e){
<div class="chart lazyload" data-expand="-10"></div>
```

* ``lazybeforesizes``: This event will be fired on each element with the ``data-sizes="auto"`` attribute right before the calculated ``sizes`` attribute will be set. The ``event.details.width`` property is set to the calculated width of the element and can be changed to any number. In case the event is ``defaultPrevented`` the ``sizes`` attribute won't be set. (Note: With version 1.1.0 the ``details`` property will be renamed to ``detail``.)
* ``lazybeforesizes``: This event will be fired on each element with the ``data-sizes="auto"`` attribute right before the calculated ``sizes`` attribute will be set. The ``event.detail.width`` property is set to the calculated width of the element and can be changed to any number. In case the event is ``defaultPrevented`` the ``sizes`` attribute won't be set.

####JS API - methods
#####``lazySizes.loader.unveil(DOMNode)``
Expand Down
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@
</style>

<script>
window.lazySizesConfig = window.lazySizesConfig || {};

//window.lazySizesConfig.preloadAfterLoad = true;
//window.lazySizesConfig.expand = 80;
window.lazySizesConfig = window.lazySizesConfig || {};
window.lazySizesConfig.loadMode = 1;
//window.lazySizesConfig.preloadAfterLoad = true;
//window.lazySizesConfig.expand = 80;
</script>

<script src="plugins/unveilhooks/ls.unveilhooks.min.js" async=""></script>
Expand Down
33 changes: 10 additions & 23 deletions lazysizes.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
var polyfill;
if(!window.HTMLPictureElement){
if( ( polyfill = (window.picturefill || window.respimage || lazySizesConfig.pf) ) ){
polyfill({reevaluate: true, reparse: true, elements: [el]});
polyfill({reevaluate: true, elements: [el]});
} else if(full && full.src){
el.src = full.src;
}
Expand All @@ -93,6 +93,7 @@
var throttle = function(fn){
var running;
var lastTime = 0;
var Date = window.Date;
var run = function(){
running = false;
lastTime = Date.now();
Expand Down Expand Up @@ -142,7 +143,6 @@
var lowRuns = 0;

var isLoading = 0;
var checkElementsIndex = 0;

var resetPreloading = function(e){
isLoading--;
Expand Down Expand Up @@ -182,12 +182,11 @@
};

var checkElements = function() {
var eLlen, i, start, rect, autoLoadElem, loadedSomething, elemExpand, elemNegativeExpand, elemExpandVal, beforeExpandVal;
var eLlen, i, rect, autoLoadElem, loadedSomething, elemExpand, elemNegativeExpand, elemExpandVal, beforeExpandVal;

if((loadMode = lazySizesConfig.loadMode) && isLoading < 8 && (eLlen = lazyloadElems.length)){

start = Date.now();
i = checkElementsIndex;
i = 0;

lowRuns++;

Expand All @@ -200,7 +199,7 @@
currentExpand = shrinkExpand;
}

for(; i < eLlen; i++, checkElementsIndex++){
for(; i < eLlen; i++){

if(!lazyloadElems[i] || lazyloadElems[i]._lazyRace){continue;}

Expand All @@ -226,29 +225,19 @@
(eLbottom || eLright || eLleft || eLtop) &&
((isCompleted && isLoading < 3 && lowRuns < 4 && !elemExpandVal && loadMode > 2) || isNestedVisible(lazyloadElems[i], elemExpand))){
unveilElement(lazyloadElems[i], false, rect.width);
checkElementsIndex--;
start++;
loadedSomething = true;
} else {
if(lowRuns && Date.now() - start > 3){
checkElementsIndex++;
throttledCheckElements();
return;
}
if(!loadedSomething && isCompleted && !autoLoadElem &&
isLoading < 3 && lowRuns < 4 && loadMode > 2 &&
(preloadElems[0] || lazySizesConfig.preloadAfterLoad) &&
(preloadElems[0] || (!elemExpandVal && ((eLbottom || eLright || eLleft || eLtop) || lazyloadElems[i].getAttribute(lazySizesConfig.sizesAttr) != 'auto')))){
autoLoadElem = preloadElems[0] || lazyloadElems[i];
}
} else if(!loadedSomething && isCompleted && !autoLoadElem &&
isLoading < 3 && lowRuns < 4 && loadMode > 2 &&
(preloadElems[0] || lazySizesConfig.preloadAfterLoad) &&
(preloadElems[0] || (!elemExpandVal && ((eLbottom || eLright || eLleft || eLtop) || lazyloadElems[i].getAttribute(lazySizesConfig.sizesAttr) != 'auto')))){
autoLoadElem = preloadElems[0] || lazyloadElems[i];
}
}

if(autoLoadElem && !loadedSomething){
unveilElement(autoLoadElem);
}
}
checkElementsIndex = 0;
};

var throttledCheckElements = throttle(checkElements);
Expand Down Expand Up @@ -373,8 +362,6 @@
}
switchLoadingClass(event);
}

elem = null;
});
};

Expand Down
2 changes: 1 addition & 1 deletion lazysizes.min.js

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

4 changes: 4 additions & 0 deletions no-src.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@
</style>
<script src="plugins/unveilhooks/ls.unveilhooks.min.js" async=""></script>

<script>
window.lazySizesConfig = window.lazySizesConfig || {};
window.lazySizesConfig.loadMode = 1;
</script>
<script src="lazysizes.min.js" async=""></script>

</head>
Expand Down
5 changes: 4 additions & 1 deletion optimumx/child.html
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,10 @@
});
})();
</script>

<script>
window.lazySizesConfig = window.lazySizesConfig || {};
window.lazySizesConfig.loadMode = 1;
</script>
<script src="../lazysizes.min.js"></script>
<script src="../plugins/optimumx/ls.optimumx.min.js"></script>
<script>
Expand Down
Loading

0 comments on commit 5fae00a

Please sign in to comment.