This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1707 from vogdb/issue-1707
Add jquery.lazyload.
- Loading branch information
Showing
14 changed files
with
277 additions
and
126 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* 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) { | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.contentPlaceholder { | ||
position: relative; | ||
display: inline-block; | ||
max-width: 100%; | ||
|
||
.contentPlaceholder-size { | ||
max-width: 100%; | ||
max-height: 100%; | ||
} | ||
|
||
.contentPlaceholder-size + * { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
vertical-align: top; | ||
} | ||
|
||
&.stretch { | ||
display: block; | ||
max-width: none; | ||
|
||
.contentPlaceholder-size { | ||
width: 100%; | ||
} | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
class CM_Frontend_TemplateHelper_ContentPlaceholder { | ||
|
||
/** | ||
* @param string $content | ||
* @param int|null $width | ||
* @param int|null $height | ||
* @param bool|null $stretch | ||
* @return string | ||
*/ | ||
public static function create($content, $width = null, $height = null, $stretch = null) { | ||
if (null === $width) { | ||
$width = 1; | ||
} | ||
if (null === $height) { | ||
$height = 1; | ||
} | ||
$stretch = (bool) $stretch; | ||
$imageData = self::_createBlankImage($width, $height); | ||
$imageSrc = 'data:image/png;base64,' . base64_encode($imageData); | ||
|
||
$output = '<div class="contentPlaceholder' . ($stretch ? ' stretch' : '') . '">'; | ||
$output .= '<img class="contentPlaceholder-size" src="' . $imageSrc . '"/>'; | ||
$output .= $content; | ||
|
||
$output .= '</div>'; | ||
return $output; | ||
} | ||
|
||
/** | ||
* @param int $width | ||
* @param int $height | ||
* @return string | ||
*/ | ||
private static function _createBlankImage($width, $height) { | ||
$cache = CM_Cache_Local::getInstance(); | ||
return $cache->get($cache->key(__CLASS__, $width, $height), function () use ($width, $height) { | ||
$image = imagecreate($width, $height); | ||
ob_start(); | ||
imagecolorallocate($image, 255, 255, 255); | ||
imagepng($image); | ||
$imageData = ob_get_contents(); | ||
ob_end_clean(); | ||
return $imageData; | ||
}); | ||
} | ||
} |
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,11 @@ | ||
<?php | ||
|
||
require_once 'function.tag.php'; | ||
|
||
function smarty_block_contentPlaceholder($params, $content, Smarty_Internal_Template $template, $open) { | ||
if ($open) { | ||
return ''; | ||
} else { | ||
return CM_Frontend_TemplateHelper_ContentPlaceholder::create($content, $params['width'], $params['height'], (isset($params['stretch']) ? ' stretch' : false)); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.