This repository has been archived by the owner on Feb 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#1301] - transient cache in shortcodes with unveil.js for images
- Loading branch information
1 parent
6235b0e
commit f35cfd2
Showing
9 changed files
with
185 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
code/wp-content/themes/Akvo-responsive/js/jquery.unveil.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* jQuery Unveil | ||
* A very lightweight jQuery plugin to lazy load images | ||
* http://luis-almeida.github.com/unveil | ||
* | ||
* Licensed under the MIT license. | ||
* Copyright 2013 Luís Almeida | ||
* https://github.com/luis-almeida | ||
*/ | ||
|
||
;(function($) { | ||
|
||
$.fn.unveil = function(threshold, callback) { | ||
|
||
var $w = $(window), | ||
th = threshold || 0, | ||
retina = window.devicePixelRatio > 1, | ||
attrib = retina? "data-src-retina" : "data-src", | ||
images = this, | ||
loaded; | ||
|
||
this.one("unveil", function() { | ||
var source = this.getAttribute(attrib); | ||
source = source || this.getAttribute("data-src"); | ||
if (source) { | ||
if (this.tagName === 'IMG') { | ||
this.setAttribute("src", source); | ||
} | ||
else { | ||
this.style.backgroundImage = 'url('+source+')'; | ||
} | ||
|
||
|
||
//this.setAttribute("src", source); | ||
if (typeof callback === "function") callback.call(this); | ||
} | ||
}); | ||
|
||
function unveil() { | ||
var inview = images.filter(function() { | ||
var $e = $(this); | ||
if ($e.is(":hidden")) return; | ||
|
||
var wt = $w.scrollTop(), | ||
wb = wt + $w.height(), | ||
et = $e.offset().top, | ||
eb = et + $e.height(); | ||
|
||
return eb >= wt - th && et <= wb + th; | ||
}); | ||
|
||
loaded = inview.trigger("unveil"); | ||
images = images.not(loaded); | ||
} | ||
|
||
$w.on("scroll.unveil resize.unveil lookup.unveil", unveil); | ||
|
||
unveil(); | ||
|
||
return this; | ||
|
||
}; | ||
|
||
})(window.jQuery || window.Zepto); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters