mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-05 02:39:46 +02:00
Lazy load images: speed up page loading times and decrease traffic
This commit is contained in:
parent
1a4965c27a
commit
3be99ba74e
30 changed files with 3312 additions and 59 deletions
|
@ -56,7 +56,6 @@ $totalPages = ceil($total / $_POST['rowCount']);
|
||||||
<?php
|
<?php
|
||||||
include $global['systemRootPath'] . 'view/include/head.php';
|
include $global['systemRootPath'] . 'view/include/head.php';
|
||||||
?>
|
?>
|
||||||
<script src="<?php echo $global['webSiteRootURL']; ?>js/jquery.lazy/jquery.lazy.min.js" type="text/javascript"></script>
|
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
// Total Itens <?php echo $total; ?>
|
// Total Itens <?php echo $total; ?>
|
||||||
|
@ -115,12 +114,12 @@ $totalPages = ceil($total / $_POST['rowCount']);
|
||||||
$poster = $images->poster;
|
$poster = $images->poster;
|
||||||
?>
|
?>
|
||||||
<div class="aspectRatio16_9">
|
<div class="aspectRatio16_9">
|
||||||
<img src="<?php echo $poster; ?>" alt="<?php echo $video['title']; ?>" class="thumbsJPG img img-responsive " style="height: auto; width: 100%;" id="thumbsJPG<?php echo $video['id']; ?>" />
|
<img src="<?php echo $global['webSiteRootURL']; ?>img/video-placeholder.png" data-src="<?php echo $poster; ?>" alt="<?php echo $video['title']; ?>" class="thumbsJPG img img-responsive " style="height: auto; width: 100%;" id="thumbsJPG<?php echo $video['id']; ?>" />
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
if (!empty($imgGif)) {
|
if (!empty($imgGif)) {
|
||||||
?>
|
?>
|
||||||
<img src="<?php echo $imgGif; ?>" style="position: absolute; top: 0; display: none;" alt="<?php echo $video['title']; ?>" id="thumbsGIF<?php echo $video['id']; ?>" class="thumbsGIF img-responsive <?php echo @$img_portrait; ?> rotate<?php echo $video['rotation']; ?>" height="130" />
|
<img src="<?php echo $global['webSiteRootURL']; ?>img/video-placeholder.png" data-src="<?php echo $imgGif; ?>" style="position: absolute; top: 0; display: none;" alt="<?php echo $video['title']; ?>" id="thumbsGIF<?php echo $video['id']; ?>" class="thumbsGIF img-responsive <?php echo @$img_portrait; ?> rotate<?php echo $video['rotation']; ?>" height="130" />
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
<span class="duration"><?php echo Video::getCleanDuration($video['duration']); ?></span>
|
<span class="duration"><?php echo Video::getCleanDuration($video['duration']); ?></span>
|
||||||
|
@ -205,12 +204,12 @@ $totalPages = ceil($total / $_POST['rowCount']);
|
||||||
$poster = $images->thumbsJpg;
|
$poster = $images->thumbsJpg;
|
||||||
?>
|
?>
|
||||||
<div class="aspectRatio16_9">
|
<div class="aspectRatio16_9">
|
||||||
<img src="<?php echo $poster; ?>" alt="<?php echo $value['title']; ?>" class="thumbsJPG img img-responsive <?php echo $img_portrait; ?> rotate<?php echo $value['rotation']; ?>" id="thumbsJPG<?php echo $value['id']; ?>" />
|
<img src="<?php echo $global['webSiteRootURL']; ?>img/video-placeholder.png" data-src="<?php echo $poster; ?>" alt="<?php echo $value['title']; ?>" class="thumbsJPG img img-responsive <?php echo $img_portrait; ?> rotate<?php echo $value['rotation']; ?>" id="thumbsJPG<?php echo $value['id']; ?>" />
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
if (!empty($imgGif)) {
|
if (!empty($imgGif)) {
|
||||||
?>
|
?>
|
||||||
<img src="<?php echo $imgGif; ?>" style="position: absolute; top: 0; display: none;" alt="<?php echo $value['title']; ?>" id="thumbsGIF<?php echo $value['id']; ?>" class="thumbsGIF img-responsive <?php echo $img_portrait; ?> rotate<?php echo $value['rotation']; ?>" height="130" />
|
<img src="<?php echo $global['webSiteRootURL']; ?>img/video-placeholder.png" data-src="<?php echo $imgGif; ?>" style="position: absolute; top: 0; display: none;" alt="<?php echo $value['title']; ?>" id="thumbsGIF<?php echo $value['id']; ?>" class="thumbsGIF img-responsive <?php echo $img_portrait; ?> rotate<?php echo $value['rotation']; ?>" height="130" />
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
<span class="duration"><?php echo Video::getCleanDuration($value['duration']); ?></span>
|
<span class="duration"><?php echo Video::getCleanDuration($value['duration']); ?></span>
|
||||||
|
@ -303,11 +302,11 @@ $totalPages = ceil($total / $_POST['rowCount']);
|
||||||
$poster = $images->thumbsJpg;
|
$poster = $images->thumbsJpg;
|
||||||
?>
|
?>
|
||||||
<div class="aspectRatio16_9">
|
<div class="aspectRatio16_9">
|
||||||
<img src="<?php echo $poster; ?>" alt="<?php echo $value['title']; ?>" class="thumbsJPG img img-responsive <?php echo $img_portrait; ?> rotate<?php echo $value['rotation']; ?>" id="thumbsJPG<?php echo $value['id']; ?>"/>
|
<img src="<?php echo $global['webSiteRootURL']; ?>img/video-placeholder.png" data-src="<?php echo $poster; ?>" alt="<?php echo $value['title']; ?>" class="thumbsJPG img img-responsive <?php echo $img_portrait; ?> rotate<?php echo $value['rotation']; ?>" id="thumbsJPG<?php echo $value['id']; ?>"/>
|
||||||
<?php
|
<?php
|
||||||
if (!empty($imgGif)) {
|
if (!empty($imgGif)) {
|
||||||
?>
|
?>
|
||||||
<img src="<?php echo $imgGif; ?>" style="position: absolute; top: 0; display: none;" alt="<?php echo $value['title']; ?>" id="thumbsGIF<?php echo $value['id']; ?>" class="thumbsGIF img-responsive <?php echo $img_portrait; ?> rotate<?php echo $value['rotation']; ?>" height="130" />
|
<img src="<?php echo $global['webSiteRootURL']; ?>img/video-placeholder.png" data-src="<?php echo $imgGif; ?>" style="position: absolute; top: 0; display: none;" alt="<?php echo $value['title']; ?>" id="thumbsGIF<?php echo $value['id']; ?>" class="thumbsGIF img-responsive <?php echo $img_portrait; ?> rotate<?php echo $value['rotation']; ?>" height="130" />
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
<span class="duration"><?php echo Video::getCleanDuration($value['duration']); ?></span>
|
<span class="duration"><?php echo Video::getCleanDuration($value['duration']); ?></span>
|
||||||
|
@ -399,12 +398,12 @@ $totalPages = ceil($total / $_POST['rowCount']);
|
||||||
$poster = $images->thumbsJpg;
|
$poster = $images->thumbsJpg;
|
||||||
?>
|
?>
|
||||||
<div class="aspectRatio16_9">
|
<div class="aspectRatio16_9">
|
||||||
<img src="<?php echo $poster; ?>" alt="<?php echo $value['title']; ?>" class="thumbsJPG img img-responsive <?php echo $img_portrait; ?> rotate<?php echo $value['rotation']; ?>" id="thumbsJPG<?php echo $value['id']; ?>" />
|
<img src="<?php echo $global['webSiteRootURL']; ?>img/video-placeholder.png" data-src="<?php echo $poster; ?>" alt="<?php echo $value['title']; ?>" class="thumbsJPG img img-responsive <?php echo $img_portrait; ?> rotate<?php echo $value['rotation']; ?>" id="thumbsJPG<?php echo $value['id']; ?>" />
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
if (!empty($imgGif)) {
|
if (!empty($imgGif)) {
|
||||||
?>
|
?>
|
||||||
<img src="<?php echo $imgGif; ?>" style="position: absolute; top: 0; display: none;" alt="<?php echo $value['title']; ?>" id="thumbsGIF<?php echo $value['id']; ?>" class="thumbsGIF img-responsive <?php echo $img_portrait; ?> rotate<?php echo $value['rotation']; ?>" height="130" />
|
<img src="<?php echo $global['webSiteRootURL']; ?>img/video-placeholder.png" data-src="<?php echo $imgGif; ?>" style="position: absolute; top: 0; display: none;" alt="<?php echo $value['title']; ?>" id="thumbsGIF<?php echo $value['id']; ?>" class="thumbsGIF img-responsive <?php echo $img_portrait; ?> rotate<?php echo $value['rotation']; ?>" height="130" />
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
<span class="duration"><?php echo Video::getCleanDuration($value['duration']); ?></span>
|
<span class="duration"><?php echo Video::getCleanDuration($value['duration']); ?></span>
|
||||||
|
@ -494,12 +493,12 @@ $totalPages = ceil($total / $_POST['rowCount']);
|
||||||
$poster = $images->thumbsJpg;
|
$poster = $images->thumbsJpg;
|
||||||
?>
|
?>
|
||||||
<div class="aspectRatio16_9">
|
<div class="aspectRatio16_9">
|
||||||
<img src="<?php echo $poster; ?>" alt="<?php echo $value['title']; ?>" class="thumbsJPG img img-responsive <?php echo $img_portrait; ?> rotate<?php echo $value['rotation']; ?>" id="thumbsJPG<?php echo $value['id']; ?>" />
|
<img src="<?php echo $global['webSiteRootURL']; ?>img/video-placeholder.png" data-src="<?php echo $poster; ?>" alt="<?php echo $value['title']; ?>" class="thumbsJPG img img-responsive <?php echo $img_portrait; ?> rotate<?php echo $value['rotation']; ?>" id="thumbsJPG<?php echo $value['id']; ?>" />
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
if (!empty($imgGif)) {
|
if (!empty($imgGif)) {
|
||||||
?>
|
?>
|
||||||
<img src="<?php echo $imgGif; ?>" style="position: absolute; top: 0; display: none;" alt="<?php echo $value['title']; ?>" id="thumbsGIF<?php echo $value['id']; ?>" class="thumbsGIF img-responsive <?php echo $img_portrait; ?> rotate<?php echo $value['rotation']; ?>" height="130" />
|
<img src="<?php echo $global['webSiteRootURL']; ?>img/video-placeholder.png" data-src="<?php echo $imgGif; ?>" style="position: absolute; top: 0; display: none;" alt="<?php echo $value['title']; ?>" id="thumbsGIF<?php echo $value['id']; ?>" class="thumbsGIF img-responsive <?php echo $img_portrait; ?> rotate<?php echo $value['rotation']; ?>" height="130" />
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
<span class="duration"><?php echo Video::getCleanDuration($value['duration']); ?></span>
|
<span class="duration"><?php echo Video::getCleanDuration($value['duration']); ?></span>
|
||||||
|
@ -573,11 +572,6 @@ $totalPages = ceil($total / $_POST['rowCount']);
|
||||||
<?php
|
<?php
|
||||||
include 'include/footer.php';
|
include 'include/footer.php';
|
||||||
?>
|
?>
|
||||||
<script>
|
|
||||||
$(function () {
|
|
||||||
$('.thumbsJPG, .thumbsGIF').lazy();
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -55,6 +55,8 @@ if (!empty($_GET['error'])) {
|
||||||
<script src="<?php echo $global['webSiteRootURL']; ?>js/bootstrap-toggle/bootstrap-toggle.min.js" type="text/javascript"></script>
|
<script src="<?php echo $global['webSiteRootURL']; ?>js/bootstrap-toggle/bootstrap-toggle.min.js" type="text/javascript"></script>
|
||||||
<script src="<?php echo $global['webSiteRootURL']; ?>js/js-cookie/js.cookie.js" type="text/javascript"></script>
|
<script src="<?php echo $global['webSiteRootURL']; ?>js/js-cookie/js.cookie.js" type="text/javascript"></script>
|
||||||
<script src="<?php echo $global['webSiteRootURL']; ?>css/flagstrap/js/jquery.flagstrap.min.js" type="text/javascript"></script>
|
<script src="<?php echo $global['webSiteRootURL']; ?>css/flagstrap/js/jquery.flagstrap.min.js" type="text/javascript"></script>
|
||||||
|
<script src="<?php echo $global['webSiteRootURL']; ?>js/jquery.lazy/jquery.lazy.min.js" type="text/javascript"></script>
|
||||||
|
<script src="<?php echo $global['webSiteRootURL']; ?>js/jquery.lazy/jquery.lazy.plugins.min.js" type="text/javascript"></script>
|
||||||
<?php
|
<?php
|
||||||
require_once $global['systemRootPath'] . 'plugin/YouPHPTubePlugin.php';
|
require_once $global['systemRootPath'] . 'plugin/YouPHPTubePlugin.php';
|
||||||
echo YouPHPTubePlugin::getFooterCode();
|
echo YouPHPTubePlugin::getFooterCode();
|
||||||
|
|
375
view/js/jquery.lazy/LICENSE
Normal file
375
view/js/jquery.lazy/LICENSE
Normal file
|
@ -0,0 +1,375 @@
|
||||||
|
Lazy is dual-licensed under MIT and GPL-2.0 license. Please choose one of them, both are listed below.
|
||||||
|
|
||||||
|
|
||||||
|
---------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2017 Daniel 'Eisbehr' Kern, eisbehr.de
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
|
||||||
|
---------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
GPL-2.0 License
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 2, June 1991
|
||||||
|
|
||||||
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The licenses for most software are designed to take away your
|
||||||
|
freedom to share and change it. By contrast, the GNU General Public
|
||||||
|
License is intended to guarantee your freedom to share and change free
|
||||||
|
software--to make sure the software is free for all its users. This
|
||||||
|
General Public License applies to most of the Free Software
|
||||||
|
Foundation's software and to any other program whose authors commit to
|
||||||
|
using it. (Some other Free Software Foundation software is covered by
|
||||||
|
the GNU Lesser General Public License instead.) You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
this service if you wish), that you receive source code or can get it
|
||||||
|
if you want it, that you can change the software or use pieces of it
|
||||||
|
in new free programs; and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to make restrictions that forbid
|
||||||
|
anyone to deny you these rights or to ask you to surrender the rights.
|
||||||
|
These restrictions translate to certain responsibilities for you if you
|
||||||
|
distribute copies of the software, or if you modify it.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must give the recipients all the rights that
|
||||||
|
you have. You must make sure that they, too, receive or can get the
|
||||||
|
source code. And you must show them these terms so they know their
|
||||||
|
rights.
|
||||||
|
|
||||||
|
We protect your rights with two steps: (1) copyright the software, and
|
||||||
|
(2) offer you this license which gives you legal permission to copy,
|
||||||
|
distribute and/or modify the software.
|
||||||
|
|
||||||
|
Also, for each author's protection and ours, we want to make certain
|
||||||
|
that everyone understands that there is no warranty for this free
|
||||||
|
software. If the software is modified by someone else and passed on, we
|
||||||
|
want its recipients to know that what they have is not the original, so
|
||||||
|
that any problems introduced by others will not reflect on the original
|
||||||
|
authors' reputations.
|
||||||
|
|
||||||
|
Finally, any free program is threatened constantly by software
|
||||||
|
patents. We wish to avoid the danger that redistributors of a free
|
||||||
|
program will individually obtain patent licenses, in effect making the
|
||||||
|
program proprietary. To prevent this, we have made it clear that any
|
||||||
|
patent must be licensed for everyone's free use or not licensed at all.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. This License applies to any program or other work which contains
|
||||||
|
a notice placed by the copyright holder saying it may be distributed
|
||||||
|
under the terms of this General Public License. The "Program", below,
|
||||||
|
refers to any such program or work, and a "work based on the Program"
|
||||||
|
means either the Program or any derivative work under copyright law:
|
||||||
|
that is to say, a work containing the Program or a portion of it,
|
||||||
|
either verbatim or with modifications and/or translated into another
|
||||||
|
language. (Hereinafter, translation is included without limitation in
|
||||||
|
the term "modification".) Each licensee is addressed as "you".
|
||||||
|
|
||||||
|
Activities other than copying, distribution and modification are not
|
||||||
|
covered by this License; they are outside its scope. The act of
|
||||||
|
running the Program is not restricted, and the output from the Program
|
||||||
|
is covered only if its contents constitute a work based on the
|
||||||
|
Program (independent of having been made by running the Program).
|
||||||
|
Whether that is true depends on what the Program does.
|
||||||
|
|
||||||
|
1. You may copy and distribute verbatim copies of the Program's
|
||||||
|
source code as you receive it, in any medium, provided that you
|
||||||
|
conspicuously and appropriately publish on each copy an appropriate
|
||||||
|
copyright notice and disclaimer of warranty; keep intact all the
|
||||||
|
notices that refer to this License and to the absence of any warranty;
|
||||||
|
and give any other recipients of the Program a copy of this License
|
||||||
|
along with the Program.
|
||||||
|
|
||||||
|
You may charge a fee for the physical act of transferring a copy, and
|
||||||
|
you may at your option offer warranty protection in exchange for a fee.
|
||||||
|
|
||||||
|
2. You may modify your copy or copies of the Program or any portion
|
||||||
|
of it, thus forming a work based on the Program, and copy and
|
||||||
|
distribute such modifications or work under the terms of Section 1
|
||||||
|
above, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) You must cause the modified files to carry prominent notices
|
||||||
|
stating that you changed the files and the date of any change.
|
||||||
|
|
||||||
|
b) You must cause any work that you distribute or publish, that in
|
||||||
|
whole or in part contains or is derived from the Program or any
|
||||||
|
part thereof, to be licensed as a whole at no charge to all third
|
||||||
|
parties under the terms of this License.
|
||||||
|
|
||||||
|
c) If the modified program normally reads commands interactively
|
||||||
|
when run, you must cause it, when started running for such
|
||||||
|
interactive use in the most ordinary way, to print or display an
|
||||||
|
announcement including an appropriate copyright notice and a
|
||||||
|
notice that there is no warranty (or else, saying that you provide
|
||||||
|
a warranty) and that users may redistribute the program under
|
||||||
|
these conditions, and telling the user how to view a copy of this
|
||||||
|
License. (Exception: if the Program itself is interactive but
|
||||||
|
does not normally print such an announcement, your work based on
|
||||||
|
the Program is not required to print an announcement.)
|
||||||
|
|
||||||
|
These requirements apply to the modified work as a whole. If
|
||||||
|
identifiable sections of that work are not derived from the Program,
|
||||||
|
and can be reasonably considered independent and separate works in
|
||||||
|
themselves, then this License, and its terms, do not apply to those
|
||||||
|
sections when you distribute them as separate works. But when you
|
||||||
|
distribute the same sections as part of a whole which is a work based
|
||||||
|
on the Program, the distribution of the whole must be on the terms of
|
||||||
|
this License, whose permissions for other licensees extend to the
|
||||||
|
entire whole, and thus to each and every part regardless of who wrote it.
|
||||||
|
|
||||||
|
Thus, it is not the intent of this section to claim rights or contest
|
||||||
|
your rights to work written entirely by you; rather, the intent is to
|
||||||
|
exercise the right to control the distribution of derivative or
|
||||||
|
collective works based on the Program.
|
||||||
|
|
||||||
|
In addition, mere aggregation of another work not based on the Program
|
||||||
|
with the Program (or with a work based on the Program) on a volume of
|
||||||
|
a storage or distribution medium does not bring the other work under
|
||||||
|
the scope of this License.
|
||||||
|
|
||||||
|
3. You may copy and distribute the Program (or a work based on it,
|
||||||
|
under Section 2) in object code or executable form under the terms of
|
||||||
|
Sections 1 and 2 above provided that you also do one of the following:
|
||||||
|
|
||||||
|
a) Accompany it with the complete corresponding machine-readable
|
||||||
|
source code, which must be distributed under the terms of Sections
|
||||||
|
1 and 2 above on a medium customarily used for software interchange; or,
|
||||||
|
|
||||||
|
b) Accompany it with a written offer, valid for at least three
|
||||||
|
years, to give any third party, for a charge no more than your
|
||||||
|
cost of physically performing source distribution, a complete
|
||||||
|
machine-readable copy of the corresponding source code, to be
|
||||||
|
distributed under the terms of Sections 1 and 2 above on a medium
|
||||||
|
customarily used for software interchange; or,
|
||||||
|
|
||||||
|
c) Accompany it with the information you received as to the offer
|
||||||
|
to distribute corresponding source code. (This alternative is
|
||||||
|
allowed only for noncommercial distribution and only if you
|
||||||
|
received the program in object code or executable form with such
|
||||||
|
an offer, in accord with Subsection b above.)
|
||||||
|
|
||||||
|
The source code for a work means the preferred form of the work for
|
||||||
|
making modifications to it. For an executable work, complete source
|
||||||
|
code means all the source code for all modules it contains, plus any
|
||||||
|
associated interface definition files, plus the scripts used to
|
||||||
|
control compilation and installation of the executable. However, as a
|
||||||
|
special exception, the source code distributed need not include
|
||||||
|
anything that is normally distributed (in either source or binary
|
||||||
|
form) with the major components (compiler, kernel, and so on) of the
|
||||||
|
operating system on which the executable runs, unless that component
|
||||||
|
itself accompanies the executable.
|
||||||
|
|
||||||
|
If distribution of executable or object code is made by offering
|
||||||
|
access to copy from a designated place, then offering equivalent
|
||||||
|
access to copy the source code from the same place counts as
|
||||||
|
distribution of the source code, even though third parties are not
|
||||||
|
compelled to copy the source along with the object code.
|
||||||
|
|
||||||
|
4. You may not copy, modify, sublicense, or distribute the Program
|
||||||
|
except as expressly provided under this License. Any attempt
|
||||||
|
otherwise to copy, modify, sublicense or distribute the Program is
|
||||||
|
void, and will automatically terminate your rights under this License.
|
||||||
|
However, parties who have received copies, or rights, from you under
|
||||||
|
this License will not have their licenses terminated so long as such
|
||||||
|
parties remain in full compliance.
|
||||||
|
|
||||||
|
5. You are not required to accept this License, since you have not
|
||||||
|
signed it. However, nothing else grants you permission to modify or
|
||||||
|
distribute the Program or its derivative works. These actions are
|
||||||
|
prohibited by law if you do not accept this License. Therefore, by
|
||||||
|
modifying or distributing the Program (or any work based on the
|
||||||
|
Program), you indicate your acceptance of this License to do so, and
|
||||||
|
all its terms and conditions for copying, distributing or modifying
|
||||||
|
the Program or works based on it.
|
||||||
|
|
||||||
|
6. Each time you redistribute the Program (or any work based on the
|
||||||
|
Program), the recipient automatically receives a license from the
|
||||||
|
original licensor to copy, distribute or modify the Program subject to
|
||||||
|
these terms and conditions. You may not impose any further
|
||||||
|
restrictions on the recipients' exercise of the rights granted herein.
|
||||||
|
You are not responsible for enforcing compliance by third parties to
|
||||||
|
this License.
|
||||||
|
|
||||||
|
7. If, as a consequence of a court judgment or allegation of patent
|
||||||
|
infringement or for any other reason (not limited to patent issues),
|
||||||
|
conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot
|
||||||
|
distribute so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you
|
||||||
|
may not distribute the Program at all. For example, if a patent
|
||||||
|
license would not permit royalty-free redistribution of the Program by
|
||||||
|
all those who receive copies directly or indirectly through you, then
|
||||||
|
the only way you could satisfy both it and this License would be to
|
||||||
|
refrain entirely from distribution of the Program.
|
||||||
|
|
||||||
|
If any portion of this section is held invalid or unenforceable under
|
||||||
|
any particular circumstance, the balance of the section is intended to
|
||||||
|
apply and the section as a whole is intended to apply in other
|
||||||
|
circumstances.
|
||||||
|
|
||||||
|
It is not the purpose of this section to induce you to infringe any
|
||||||
|
patents or other property right claims or to contest validity of any
|
||||||
|
such claims; this section has the sole purpose of protecting the
|
||||||
|
integrity of the free software distribution system, which is
|
||||||
|
implemented by public license practices. Many people have made
|
||||||
|
generous contributions to the wide range of software distributed
|
||||||
|
through that system in reliance on consistent application of that
|
||||||
|
system; it is up to the author/donor to decide if he or she is willing
|
||||||
|
to distribute software through any other system and a licensee cannot
|
||||||
|
impose that choice.
|
||||||
|
|
||||||
|
This section is intended to make thoroughly clear what is believed to
|
||||||
|
be a consequence of the rest of this License.
|
||||||
|
|
||||||
|
8. If the distribution and/or use of the Program is restricted in
|
||||||
|
certain countries either by patents or by copyrighted interfaces, the
|
||||||
|
original copyright holder who places the Program under this License
|
||||||
|
may add an explicit geographical distribution limitation excluding
|
||||||
|
those countries, so that distribution is permitted only in or among
|
||||||
|
countries not thus excluded. In such case, this License incorporates
|
||||||
|
the limitation as if written in the body of this License.
|
||||||
|
|
||||||
|
9. The Free Software Foundation may publish revised and/or new versions
|
||||||
|
of the General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the Program
|
||||||
|
specifies a version number of this License which applies to it and "any
|
||||||
|
later version", you have the option of following the terms and conditions
|
||||||
|
either of that version or of any later version published by the Free
|
||||||
|
Software Foundation. If the Program does not specify a version number of
|
||||||
|
this License, you may choose any version ever published by the Free Software
|
||||||
|
Foundation.
|
||||||
|
|
||||||
|
10. If you wish to incorporate parts of the Program into other free
|
||||||
|
programs whose distribution conditions are different, write to the author
|
||||||
|
to ask for permission. For software which is copyrighted by the Free
|
||||||
|
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||||
|
make exceptions for this. Our decision will be guided by the two goals
|
||||||
|
of preserving the free status of all derivatives of our free software and
|
||||||
|
of promoting the sharing and reuse of software generally.
|
||||||
|
|
||||||
|
NO WARRANTY
|
||||||
|
|
||||||
|
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||||
|
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||||
|
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||||
|
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||||
|
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||||
|
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||||
|
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||||
|
REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||||
|
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||||
|
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||||
|
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||||
|
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||||
|
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||||
|
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||||
|
POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
convey the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
{description}
|
||||||
|
Copyright (C) {year} {fullname}
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program is interactive, make it output a short notice like this
|
||||||
|
when it starts in an interactive mode:
|
||||||
|
|
||||||
|
Gnomovision version 69, Copyright (C) year name of author
|
||||||
|
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, the commands you use may
|
||||||
|
be called something other than `show w' and `show c'; they could even be
|
||||||
|
mouse-clicks or menu items--whatever suits your program.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or your
|
||||||
|
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||||
|
necessary. Here is a sample; alter the names:
|
||||||
|
|
||||||
|
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||||
|
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||||
|
|
||||||
|
{signature of Ty Coon}, 1 April 1989
|
||||||
|
Ty Coon, President of Vice
|
||||||
|
|
||||||
|
This General Public License does not permit incorporating your program into
|
||||||
|
proprietary programs. If your program is a subroutine library, you may
|
||||||
|
consider it more useful to permit linking proprietary applications with the
|
||||||
|
library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License.
|
264
view/js/jquery.lazy/README.md
Normal file
264
view/js/jquery.lazy/README.md
Normal file
|
@ -0,0 +1,264 @@
|
||||||
|
### jQuery & Zepto Lazy - Delayed Content, Image and Background Loader
|
||||||
|
[](http://github.com/eisbehr-/jquery.lazy)
|
||||||
|
[](http://www.npmjs.org/package/jquery-lazy)
|
||||||
|
[](http://bower.io/search/?q=jquery-lazy)
|
||||||
|
[](https://david-dm.org/eisbehr-/jquery.lazy)
|
||||||
|
[](https://david-dm.org/eisbehr-/jquery.lazy?type=dev)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
[](https://jetbrains.com/phpstorm)
|
||||||
|
_This project is friendly supported by [JetBrains](https://jetbrains.com) & [PhpStorm](https://jetbrains.com/phpstorm)!_
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Table of Contents
|
||||||
|
* [About Lazy](#about-lazy)
|
||||||
|
* [Compatibility](#compatibility)
|
||||||
|
* [Documentation / Examples](#documentation--examples)
|
||||||
|
* [Installation](#installation)
|
||||||
|
* [CDN](#cdn)
|
||||||
|
* [Self-Hosted](#self-hosted)
|
||||||
|
* [Package Managers](#package-managers)
|
||||||
|
* [Basic Usage](#basic-usage)
|
||||||
|
* [Callbacks / Events](#callbacks--events)
|
||||||
|
* [Instances and public Functions](#instances-and-public-functions)
|
||||||
|
* [Custom Content Loaders](#custom-content-loaders)
|
||||||
|
* [Loader Plugins](#loader-plugins)
|
||||||
|
* [Configuration Parameters](#configuration-parameters)
|
||||||
|
* [Build and Validation](#build-and-validation)
|
||||||
|
* [Available gulp Tasks](#available-gulp-tasks)
|
||||||
|
* [Bugs / Feature request](#bugs--feature-request)
|
||||||
|
* [License](#license)
|
||||||
|
* [Donation](#donation)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## About Lazy
|
||||||
|
Lazy is a fast, feature-rich and lightweight delayed content loading plugin for jQuery and Zepto.
|
||||||
|
It's designed to speed up page loading times and decrease traffic to your users by only loading the content in view.
|
||||||
|
You can use Lazy in all vertical and horizontal scroll ways.
|
||||||
|
It supports images in `<img />` tags and backgrounds, supplied with css like `background-image`, by default.
|
||||||
|
On those elements Lazy can set an default image or a placeholder while loading and supports retina displays as well.
|
||||||
|
But Lazy is even able to load any other content you want by [plugins](#loader-plugins) and [custom loaders](#custom-content-loaders).
|
||||||
|
|
||||||
|
|
||||||
|
## Compatibility
|
||||||
|
Lazy will work with a wide range of browsers and support jQuery versions for years backwards and Zepto as alternative.
|
||||||
|
You can pick any version since jQuery 1.7.2 or Zepto 1.1.6 or greater.
|
||||||
|
There is no way to guarantee, that Lazy will work with all browsers, but all I've tested worked great so far.
|
||||||
|
If you find any problems in specific browsers, [please let me know](http://github.com/eisbehr-/jquery.lazy/issues).
|
||||||
|
|
||||||
|
**Tested in:** IE, Chrome (+ mobile), Firefox (+ mobile), Safari (+ mobile) and Android Browser.
|
||||||
|
|
||||||
|
|
||||||
|
## Documentation / Examples
|
||||||
|
For [documentation](http://jquery.eisbehr.de/lazy/#parameter), [examples](http://jquery.eisbehr.de/lazy/#examples) and other information take a look on the [project page](http://jquery.eisbehr.de/lazy/).
|
||||||
|
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
First of all, you will need a copy of [jQuery](http://jquery.com) or [Zepto](http://zeptojs.com) to use Lazy successfully on your project.
|
||||||
|
If you get this you can install Lazy by different ways.
|
||||||
|
Some examples below:
|
||||||
|
|
||||||
|
#### CDN
|
||||||
|
Lazy and all plugins are available over [cdnjs](http://cdnjs.com) and [jsDelivr](http://jsdelivr.com) CDN and can directly included to every page.
|
||||||
|
```HTML
|
||||||
|
<!-- jsDeliver -->
|
||||||
|
<script type="text/javascript" src="//cdn.jsdelivr.net/gh/eisbehr-/jquery.lazy@1.7.7/jquery.lazy.min.js"></script>
|
||||||
|
<script type="text/javascript" src="//cdn.jsdelivr.net/gh/eisbehr-/jquery.lazy@1.7.7/jquery.lazy.plugins.min.js"></script>
|
||||||
|
|
||||||
|
<!-- cdnjs -->
|
||||||
|
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery.lazy/1.7.7/jquery.lazy.min.js"></script>
|
||||||
|
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery.lazy/1.7.7/jquery.lazy.plugins.min.js"></script>
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Self-Hosted
|
||||||
|
[Download](https://github.com/eisbehr-/jquery.lazy/archive/master.zip) and save one of two available files to include Lazy to your page, either the [development](http://raw.githubusercontent.com/eisbehr-/jquery.lazy/master/jquery.lazy.js) or the [minified](http://raw.githubusercontent.com/eisbehr-/jquery.lazy/master/jquery.lazy.min.js) version.
|
||||||
|
```HTML
|
||||||
|
<script type="text/javascript" src="jquery.lazy.min.js"></script>
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Package Managers
|
||||||
|
Lazy is even available through [NPM](http://npmjs.org) and [Bower](http://bower.io).
|
||||||
|
Just use one of the following commands below:
|
||||||
|
|
||||||
|
[](https://nodei.co/npm/jquery-lazy/)
|
||||||
|
```sh
|
||||||
|
$ npm install jquery-lazy
|
||||||
|
$ bower install jquery-lazy
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Basic Usage
|
||||||
|
1.) The basic usage of Lazy ist pretty easy.
|
||||||
|
First of all you need to prepare all elements you want to lazy load.
|
||||||
|
By default add a `data-src` attribute to images containing the loadable image and/or a `data-loader` attribute to elements witch shall use a [plugin](#loader-plugins) or [custom loaders](#custom-content-loaders).
|
||||||
|
```HTML
|
||||||
|
<img class="lazy" data-src="path/to/image_to_load.jpg" src="" />
|
||||||
|
```
|
||||||
|
|
||||||
|
2.) Start using Lazy by calling it after page load.
|
||||||
|
You don't have to specify your elements exactly, but for better performance, or different options, load your elements over unique classes or any other selector.
|
||||||
|
```JS
|
||||||
|
$(function($) {
|
||||||
|
$("img.lazy").Lazy();
|
||||||
|
});
|
||||||
|
```
|
||||||
|
Take a look at the [documentation](http://jquery.eisbehr.de/lazy/) to get an idea what Lazy is capable of.
|
||||||
|
|
||||||
|
|
||||||
|
## Callbacks / Events
|
||||||
|
Lazy comes with a bunch of [callbacks and events](http://jquery.eisbehr.de/lazy/index.php?c=callback) you can assign to.
|
||||||
|
Just add them by initialization settings:
|
||||||
|
* `beforeLoad` - before item is about to be loaded
|
||||||
|
* `afterLoad` - after the item was loaded successfully
|
||||||
|
* `onError` - whenever an item could not be loaded
|
||||||
|
* `onFinishedAll` - after all items in instance was loaded or returned an error
|
||||||
|
|
||||||
|
|
||||||
|
## Instances and public Functions
|
||||||
|
Lazy supports multiple parallel instances.
|
||||||
|
Just initialize them with different selectors.
|
||||||
|
To access an instances public functions you can initialize them in an object oriented manner or grab the instance bind to every element by default:
|
||||||
|
```JS
|
||||||
|
// object oriented way
|
||||||
|
var instance = $("img.lazy").Lazy({chainable: false});
|
||||||
|
|
||||||
|
// grab from elements (only works well if you use same selectors)
|
||||||
|
$("img.lazy").Lazy();
|
||||||
|
var instance = $("img.lazy").data("plugin_lazy");
|
||||||
|
```
|
||||||
|
|
||||||
|
Every instance has some public available functions to control it's behavior.
|
||||||
|
There are currently six available:
|
||||||
|
```JS
|
||||||
|
instance.config(entryName[, newValue]); // get or set an configuration entry
|
||||||
|
instance.addItems(items); // add new items to current instance
|
||||||
|
instance.getItems(); // get all unhandled items left of current instance
|
||||||
|
instance.update([useThrottle]); // loads all elements in current viewport
|
||||||
|
instance.force(items); // force loading specific items, ignoring the viewport
|
||||||
|
instance.loadAll(); // loads all remaining available elements from this instance
|
||||||
|
instance.destroy(); // unbinds all events and stop execution directly
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Custom Content Loaders
|
||||||
|
With the custom loaders option there is a powerful solution to load every contents the Lazy way.
|
||||||
|
Lazy will handle everything, you just create a loading method witch got triggered whenever the element hits the visibility threshold.
|
||||||
|
It is still possible to load images and custom loaders in the same Lazy instance.
|
||||||
|
|
||||||
|
To use this just define a loader function inside the Lazy initialisation and pass the loader name to the `data-loader` attribute of the elements witch should be lazy loaded.
|
||||||
|
```HTML
|
||||||
|
<div class="lazy" data-loader="customLoaderName"></div>
|
||||||
|
<img class="lazy" data-src="path/to/image_to_load.jpg" src="" />
|
||||||
|
<div class="lazy" data-loader="customLoaderName"></div>
|
||||||
|
<div class="lazy" data-loader="asyncLoader"></div>
|
||||||
|
```
|
||||||
|
```JS
|
||||||
|
$(".lazy").Lazy({
|
||||||
|
// callback
|
||||||
|
beforeLoad: function(element) {
|
||||||
|
console.log("start loading " + element.prop("tagName"));
|
||||||
|
},
|
||||||
|
|
||||||
|
// custom loaders
|
||||||
|
customLoaderName: function(element) {
|
||||||
|
element.html("element handled by custom loader");
|
||||||
|
element.load();
|
||||||
|
},
|
||||||
|
asyncLoader: function(element, response) {
|
||||||
|
setTimeout(function() {
|
||||||
|
element.html("element handled by async loader");
|
||||||
|
response(true);
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Loader Plugins
|
||||||
|
The loader plugins can extend the functionality of Lazy, like loading other elements and data.
|
||||||
|
It is basically the same as the [custom content loaders](#custom-content-loaders), with the difference, that plugins can extend all further instances globally at once permanently and let them handle specific elements like `<video>` by default, without `data-loader` attribute set.
|
||||||
|
With custom content loaders you have to initialize each instance on setup with the loader.
|
||||||
|
With plugins you only load the plugin file and you're done for all instances from now on.
|
||||||
|
|
||||||
|
For more information and examples, take a look at the [existing plugins](https://github.com/eisbehr-/jquery.lazy/tree/master/plugins) or the [readme.md](https://github.com/eisbehr-/jquery.lazy/tree/master/plugins/README.md) in there.
|
||||||
|
|
||||||
|
|
||||||
|
## Configuration Parameters
|
||||||
|
The following configurations is available by default:
|
||||||
|
|
||||||
|
Name | Type | Default | Description
|
||||||
|
------------------ | ---------- | ------------------ | -----------
|
||||||
|
name | *string* | *'lazy'* | Internal name, used for namespaces and bindings.
|
||||||
|
chainable | *boolean* | *true* | By default Lazy is chainable and will return all elements. If set to `false` Lazy will return the created plugin instance itself for further use.
|
||||||
|
autoDestroy | *boolean* | *true* | Will automatically destroy the instance when no further elements are available to handle.
|
||||||
|
bind | *string* | *'load'* | If set to `load`' Lazy starts working directly after page load. If you want to use Lazy on own events set it to `event`'.
|
||||||
|
threshold | *integer* | *500* | Amount of pixels below the viewport, in which all images gets loaded before the user sees them.
|
||||||
|
visibleOnly | *boolean* | *false* | Determine if only visible elements should be load.
|
||||||
|
appendScroll | *integer* | *window* | An element to listen on for scroll events, useful when images are stored in a container.
|
||||||
|
scrollDirection | *string* | *'both'* | Determines the handles scroll direction. Possible values are `both`, `vertical` and `horizontal`.
|
||||||
|
imageBase | *string* | *null* | If defined this will be used as base path for all images loaded by this instance.
|
||||||
|
defaultImage | *string* | *blank image* | Base64 image string, set as default image source for every image without a predefined source attribute.
|
||||||
|
placeholder | *string* | *null* | Base64 image string, set a background on every element as loading placeholder.
|
||||||
|
delay | *integer* | *-1* | If you want to load all elements at once after page load, then you can specify a delay time in milliseconds.
|
||||||
|
combined | *boolean* | *false* | With this parameter, Lazy will combine the event driven and delayed element loading.
|
||||||
|
**attributes** | | |
|
||||||
|
attribute | *string* | *'data-src'* | Name of the image tag `src` attribute, where the image path is stored.
|
||||||
|
srcsetAttribute | *string* | *'data-srcset'* | Name of the image tag `srcset` attribute, where the source set is stored.
|
||||||
|
sizesAttribute | *string* | *'data-sizes'* | Name of the image tag `sizes` attribute, where the size definition for source set is stored.
|
||||||
|
retinaAttribute | *string* | *'data-retina'* | Name of the image tag attribute, where the path for optional retina image is stored.
|
||||||
|
loaderAttribute | *string* | *'data-loader'* | Name or the element attribute, where the identifier of the plugin or customer loader is sored.
|
||||||
|
imageBaseAttribute | *string* | *'data-imagebase'* | Name ot the image tag element, where the specific image base is stored. This will overwrite the global `imageBase` config.
|
||||||
|
removeAttribute | *boolean* | *true* | Determine if the attribute should be removed from the element after loading.
|
||||||
|
handledName | *string* | *'handled'* | Name of the element tag data attribute, to determine if element is already handled.
|
||||||
|
loadedName | *string* | *'loaded'* | Name of the element tag data attribute, to determine if element is already loaded.
|
||||||
|
**effect** | | |
|
||||||
|
effect | *string* | *'show'* | Function name of the effect you want to use to show the loaded images, like `show` or `fadeIn`.
|
||||||
|
effectTime | *integer* | *0* | Time in milliseconds the effect should use to view the image.
|
||||||
|
**throttle** | | |
|
||||||
|
enableThrottle | *boolean* | *true* | Throttle down the loading calls on scrolling event.
|
||||||
|
throttle | *integer* | *250* | Time in milliseconds the throttle will use to limit the loading calls.
|
||||||
|
**callbacks** | | |
|
||||||
|
beforeLoad | *function* | *undefined* | Callback function, which will be called before the element gets loaded. Has current element and response function as parameters. `this` is the current Lazy instance.
|
||||||
|
afterLoad | *function* | *undefined* | Callback function, which will be called after the element was loaded. Has current element and response function as parameters. `this` is the current Lazy instance.
|
||||||
|
onError | *function* | *undefined* | Callback function, which will be called if the element could not be loaded. Has current element and response function as parameters. `this` is the current Lazy instance.
|
||||||
|
onFinishedAll | *function* | *undefined* | Callback function, which will be called after all elements was loaded or returned an error. The callback has no parameters. `this` is the current Lazy instance.
|
||||||
|
|
||||||
|
|
||||||
|
## Build and Validation
|
||||||
|
This project includes an automated build script using `gulp`.
|
||||||
|
To build your own versions of Lazy you need to [install it](#package-managers) via [npm](https://www.npmjs.com/package/jquery-lazy) first.
|
||||||
|
Afterwards you can use the following command in your console to automatically generate all productive files.
|
||||||
|
While building these files everything will be checked with `jshint` for validity too.
|
||||||
|
```sh
|
||||||
|
$ gulp build
|
||||||
|
```
|
||||||
|
|
||||||
|
### Available `gulp` Tasks:
|
||||||
|
|
||||||
|
Name | Description
|
||||||
|
-------------- | -----------
|
||||||
|
build | check & build everything
|
||||||
|
build-main | check & build main project file
|
||||||
|
build-plugins | check & build single plugin files
|
||||||
|
concat-plugins | build concatenated plugins file
|
||||||
|
validate | check all files with `jshint`
|
||||||
|
watch | watches all files to check & build everything on change
|
||||||
|
|
||||||
|
|
||||||
|
## Bugs / Feature request
|
||||||
|
Please [report](http://github.com/eisbehr-/jquery.lazy/issues) bugs and feel free to [ask](http://github.com/eisbehr-/jquery.lazy/issues) for new features directly on GitHub.
|
||||||
|
|
||||||
|
|
||||||
|
## License
|
||||||
|
Lazy is dual-licensed under [MIT](http://www.opensource.org/licenses/mit-license.php) and [GPL-2.0](http://www.gnu.org/licenses/gpl-2.0.html) license.
|
||||||
|
|
||||||
|
|
||||||
|
## Donation
|
||||||
|
_You like to support me?_
|
||||||
|
_You appreciate my work?_
|
||||||
|
_You use it in commercial projects?_
|
||||||
|
|
||||||
|
Feel free to make a little [donation](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FFL6VQJCUZMXC)! :wink:
|
48
view/js/jquery.lazy/bower.json
Normal file
48
view/js/jquery.lazy/bower.json
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
{
|
||||||
|
"name": "jquery-lazy",
|
||||||
|
"description": "Lazy is a fast, feature-rich and lightweight delayed content loading plugin for jQuery and Zepto. It's designed to speed up page loading times and decrease traffic to your users by only loading the content in view. You can use Lazy in all vertical and horizontal scroll ways. It supports images in 'img' tags and backgrounds, supplied with css like 'background-image', by default. On those elements Lazy can set an default image or a placeholder while loading and supports retina displays as well. But Lazy is even able to load any other content you want by plugins and custom loaders.",
|
||||||
|
"version": "1.7.7",
|
||||||
|
"main": "jquery.lazy.min.js",
|
||||||
|
"license": [
|
||||||
|
"MIT",
|
||||||
|
"GPL-2.0"
|
||||||
|
],
|
||||||
|
"ignore": [
|
||||||
|
"*.md",
|
||||||
|
"*.json"
|
||||||
|
],
|
||||||
|
"keywords": [
|
||||||
|
"lazy",
|
||||||
|
"lazyload",
|
||||||
|
"load",
|
||||||
|
"loader",
|
||||||
|
"image",
|
||||||
|
"images",
|
||||||
|
"background",
|
||||||
|
"content",
|
||||||
|
"speed",
|
||||||
|
"delay",
|
||||||
|
"delayed",
|
||||||
|
"pageload",
|
||||||
|
"performance",
|
||||||
|
"retina",
|
||||||
|
"placeholder",
|
||||||
|
"jquery",
|
||||||
|
"jquery-plugin",
|
||||||
|
"zepto",
|
||||||
|
"zepto-plugin"
|
||||||
|
],
|
||||||
|
"authors": [{
|
||||||
|
"name": "Daniel 'Eisbehr' Kern",
|
||||||
|
"email": "jquery@eisbehr.de",
|
||||||
|
"homepage": "http://www.eisbehr.de/"
|
||||||
|
}],
|
||||||
|
"homepage": "http://jquery.eisbehr.de/lazy/",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git://github.com/eisbehr-/jquery.lazy.git"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"jquery": ">=1.7.2"
|
||||||
|
}
|
||||||
|
}
|
150
view/js/jquery.lazy/gulpfile.js
Normal file
150
view/js/jquery.lazy/gulpfile.js
Normal file
|
@ -0,0 +1,150 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var gulp = require("gulp");
|
||||||
|
var util = require("gulp-util");
|
||||||
|
var data = require("gulp-data");
|
||||||
|
var noop = require("gulp-noop");
|
||||||
|
var rename = require("gulp-rename");
|
||||||
|
var header = require("gulp-header");
|
||||||
|
var jshint = require("gulp-jshint");
|
||||||
|
var uglify = require("gulp-uglify");
|
||||||
|
var concat = require("gulp-concat-util");
|
||||||
|
var pkg = require("./package.json");
|
||||||
|
var nl = require("os").EOL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** CONFIG & PATHS
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var config = {
|
||||||
|
header : "/*! jQuery & Zepto Lazy <%= info %> - <%= pkg.homepage %> - MIT&GPL-2.0 license - Copyright 2012-<%= year %> <%= pkg.author.name %> */",
|
||||||
|
main : pkg.main,
|
||||||
|
plugins : [
|
||||||
|
"plugins/jquery.lazy.*.js",
|
||||||
|
"!plugins/jquery.lazy.*.min.js"
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** PIPES
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var pipes = {};
|
||||||
|
|
||||||
|
// check files with jshint
|
||||||
|
pipes.validateFiles = function(files) {
|
||||||
|
return gulp.src(files, {base: "./"})
|
||||||
|
.pipe(jshint())
|
||||||
|
.pipe(jshint.reporter("jshint-stylish"));
|
||||||
|
};
|
||||||
|
|
||||||
|
// check all files
|
||||||
|
pipes.validate = function() {
|
||||||
|
return pipes.validateFiles([config.main].concat(config.plugins));
|
||||||
|
};
|
||||||
|
|
||||||
|
// build main project file
|
||||||
|
pipes.buildMain = function() {
|
||||||
|
return pipes.validateFiles(config.main)
|
||||||
|
.pipe(uglify())
|
||||||
|
.pipe(header(config.header + nl, {
|
||||||
|
pkg : pkg,
|
||||||
|
info : "v" + pkg.version,
|
||||||
|
year : new Date().getFullYear()
|
||||||
|
}))
|
||||||
|
.pipe(rename(function(path) {
|
||||||
|
path.extname = ".min" + path.extname;
|
||||||
|
}))
|
||||||
|
.pipe(gulp.dest("./"));
|
||||||
|
};
|
||||||
|
|
||||||
|
// build plugin files
|
||||||
|
pipes.buildPlugins = function() {
|
||||||
|
return pipes.validateFiles(config.plugins)
|
||||||
|
.pipe(data(function(file) {
|
||||||
|
var string = String(file.contents).split("\n")[1];
|
||||||
|
var matches = string.match(/\s-\s([a-z ]+)\s-\sv([0-9.]+)/i);
|
||||||
|
|
||||||
|
return {
|
||||||
|
info: "- " + matches[1] + " v" + matches[2]
|
||||||
|
};
|
||||||
|
}))
|
||||||
|
.pipe(uglify())
|
||||||
|
.pipe(header(config.header + nl, {
|
||||||
|
pkg : pkg,
|
||||||
|
year : new Date().getFullYear()
|
||||||
|
}))
|
||||||
|
.pipe(rename(function(path) {
|
||||||
|
path.extname = ".min" + path.extname;
|
||||||
|
}))
|
||||||
|
.pipe(gulp.dest("./"));
|
||||||
|
};
|
||||||
|
|
||||||
|
// concat plugin files
|
||||||
|
pipes.concatPlugins = function() {
|
||||||
|
return gulp.src(config.plugins)
|
||||||
|
.pipe(concat(config.main.replace(".js", ".plugins.js"), {
|
||||||
|
sep: nl + nl
|
||||||
|
}))
|
||||||
|
.pipe(gulp.dest("./"))
|
||||||
|
.pipe(uglify())
|
||||||
|
.pipe(header(config.header + nl, {
|
||||||
|
pkg : pkg,
|
||||||
|
info : "- All Plugins v" + pkg.version,
|
||||||
|
year : new Date().getFullYear()
|
||||||
|
}))
|
||||||
|
.pipe(rename(function(path) {
|
||||||
|
path.extname = ".min" + path.extname;
|
||||||
|
}))
|
||||||
|
.pipe(gulp.dest("./"));
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** TASKS
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// check & build everything
|
||||||
|
gulp.task("build", ["build-main", "build-plugins", "concat-plugins"]);
|
||||||
|
|
||||||
|
// check & build main project file
|
||||||
|
gulp.task("build-main", pipes.buildMain);
|
||||||
|
|
||||||
|
// check & build single plugin files
|
||||||
|
gulp.task("build-plugins", pipes.buildPlugins);
|
||||||
|
|
||||||
|
// build concatenated plugins file
|
||||||
|
gulp.task("concat-plugins", pipes.concatPlugins);
|
||||||
|
|
||||||
|
// check all files
|
||||||
|
gulp.task("validate", pipes.validate);
|
||||||
|
|
||||||
|
// check, build & watch live changes
|
||||||
|
gulp.task("watch", ["build"], function() {
|
||||||
|
// watch main file
|
||||||
|
gulp.watch(config.main, function() {
|
||||||
|
var task = pipes.buildMain();
|
||||||
|
util.log("updated", "'" + util.colors.red("main file") + "'");
|
||||||
|
return task;
|
||||||
|
});
|
||||||
|
|
||||||
|
// watch plugins
|
||||||
|
gulp.watch(config.plugins, function() {
|
||||||
|
var task = pipes.buildPlugins();
|
||||||
|
util.log("updated", "'" + util.colors.red("plugins") + "'");
|
||||||
|
pipes.concatPlugins();
|
||||||
|
util.log("updated", "'" + util.colors.red("concatenated plugins file") + "'");
|
||||||
|
return task;
|
||||||
|
});
|
||||||
|
});
|
870
view/js/jquery.lazy/jquery.lazy.js
Normal file
870
view/js/jquery.lazy/jquery.lazy.js
Normal file
|
@ -0,0 +1,870 @@
|
||||||
|
/*!
|
||||||
|
* jQuery & Zepto Lazy - v1.7.7
|
||||||
|
* http://jquery.eisbehr.de/lazy/
|
||||||
|
*
|
||||||
|
* Copyright 2012 - 2017, Daniel 'Eisbehr' Kern
|
||||||
|
*
|
||||||
|
* Dual licensed under the MIT and GPL-2.0 licenses:
|
||||||
|
* http://www.opensource.org/licenses/mit-license.php
|
||||||
|
* http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*
|
||||||
|
* $("img.lazy").lazy();
|
||||||
|
*/
|
||||||
|
|
||||||
|
;(function(window, undefined) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
// noinspection JSUnresolvedVariable
|
||||||
|
/**
|
||||||
|
* library instance - here and not in construct to be shorter in minimization
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
var $ = window.jQuery || window.Zepto,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* unique plugin instance id counter
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
lazyInstanceId = 0,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* helper to register window load for jQuery 3
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
windowLoaded = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* make lazy available to jquery - and make it a bit more case-insensitive :)
|
||||||
|
* @access public
|
||||||
|
* @type {function}
|
||||||
|
* @param {object} settings
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
$.fn.Lazy = $.fn.lazy = function(settings) {
|
||||||
|
return new LazyPlugin(this, settings);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* helper to add plugins to lazy prototype configuration
|
||||||
|
* @access public
|
||||||
|
* @type {function}
|
||||||
|
* @param {string|Array} names
|
||||||
|
* @param {string|Array} [elements]
|
||||||
|
* @param {function} loader
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
$.Lazy = $.lazy = function(names, elements, loader) {
|
||||||
|
// make second parameter optional
|
||||||
|
if( $.isFunction(elements) ) {
|
||||||
|
loader = elements;
|
||||||
|
elements = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// exit here if parameter is not a callable function
|
||||||
|
if( !$.isFunction(loader) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// make parameters an array of names to be sure
|
||||||
|
names = $.isArray(names) ? names : [names];
|
||||||
|
elements = $.isArray(elements) ? elements : [elements];
|
||||||
|
|
||||||
|
var config = LazyPlugin.prototype.config,
|
||||||
|
forced = config._f || (config._f = {});
|
||||||
|
|
||||||
|
// add the loader plugin for every name
|
||||||
|
for( var i = 0, l = names.length; i < l; i++ ) {
|
||||||
|
if( config[names[i]] === undefined || $.isFunction(config[names[i]]) ) {
|
||||||
|
config[names[i]] = loader;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add forced elements loader
|
||||||
|
for( var c = 0, a = elements.length; c < a; c++ ) {
|
||||||
|
forced[elements[c]] = names[0];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* contains all logic and the whole element handling
|
||||||
|
* is packed in a private function outside class to reduce memory usage, because it will not be created on every plugin instance
|
||||||
|
* @access private
|
||||||
|
* @type {function}
|
||||||
|
* @param {LazyPlugin} instance
|
||||||
|
* @param {object} config
|
||||||
|
* @param {object|Array} items
|
||||||
|
* @param {object} events
|
||||||
|
* @param {string} namespace
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function _executeLazy(instance, config, items, events, namespace) {
|
||||||
|
/**
|
||||||
|
* a helper to trigger the 'onFinishedAll' callback after all other events
|
||||||
|
* @access private
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
var _awaitingAfterLoad = 0,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* visible content width
|
||||||
|
* @access private
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
_actualWidth = -1,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* visible content height
|
||||||
|
* @access private
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
_actualHeight = -1,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* determine possibly detected high pixel density
|
||||||
|
* @access private
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
_isRetinaDisplay = false,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dictionary entry for better minimization
|
||||||
|
* @access private
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
_afterLoad = "afterLoad",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dictionary entry for better minimization
|
||||||
|
* @access private
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
_load = "load",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dictionary entry for better minimization
|
||||||
|
* @access private
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
_error = "error",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dictionary entry for better minimization
|
||||||
|
* @access private
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
_img = "img",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dictionary entry for better minimization
|
||||||
|
* @access private
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
_src = "src",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dictionary entry for better minimization
|
||||||
|
* @access private
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
_srcset = "srcset",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dictionary entry for better minimization
|
||||||
|
* @access private
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
_sizes = "sizes",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dictionary entry for better minimization
|
||||||
|
* @access private
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
_backgroundImage = "background-image";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initialize plugin
|
||||||
|
* bind loading to events or set delay time to load all items at once
|
||||||
|
* @access private
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function _initialize() {
|
||||||
|
// detect actual device pixel ratio
|
||||||
|
// noinspection JSUnresolvedVariable
|
||||||
|
_isRetinaDisplay = window.devicePixelRatio > 1;
|
||||||
|
|
||||||
|
// prepare all initial items
|
||||||
|
items = _prepareItems(items);
|
||||||
|
|
||||||
|
// if delay time is set load all items at once after delay time
|
||||||
|
if( config.delay >= 0 ) {
|
||||||
|
setTimeout(function() {
|
||||||
|
_lazyLoadItems(true);
|
||||||
|
}, config.delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if no delay is set or combine usage is active bind events
|
||||||
|
if( config.delay < 0 || config.combined ) {
|
||||||
|
// create unique event function
|
||||||
|
events.e = _throttle(config.throttle, function(event) {
|
||||||
|
// reset detected window size on resize event
|
||||||
|
if( event.type === "resize" ) {
|
||||||
|
_actualWidth = _actualHeight = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// execute 'lazy magic'
|
||||||
|
_lazyLoadItems(event.all);
|
||||||
|
});
|
||||||
|
|
||||||
|
// create function to add new items to instance
|
||||||
|
events.a = function(additionalItems) {
|
||||||
|
additionalItems = _prepareItems(additionalItems);
|
||||||
|
items.push.apply(items, additionalItems);
|
||||||
|
};
|
||||||
|
|
||||||
|
// create function to get all instance items left
|
||||||
|
events.g = function() {
|
||||||
|
// filter loaded items before return in case internal filter was not running until now
|
||||||
|
return (items = $(items).filter(function() {
|
||||||
|
return !$(this).data(config.loadedName);
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
// create function to force loading elements
|
||||||
|
events.f = function(forcedItems) {
|
||||||
|
for( var i = 0; i < forcedItems.length; i++ ) {
|
||||||
|
// only handle item if available in current instance
|
||||||
|
// use a compare function, because Zepto can't handle object parameter for filter
|
||||||
|
// var item = items.filter(forcedItems[i]);
|
||||||
|
/* jshint loopfunc: true */
|
||||||
|
var item = items.filter(function() {
|
||||||
|
return this === forcedItems[i];
|
||||||
|
});
|
||||||
|
|
||||||
|
if( item.length ) {
|
||||||
|
_lazyLoadItems(false, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// load initial items
|
||||||
|
_lazyLoadItems();
|
||||||
|
|
||||||
|
// bind lazy load functions to scroll and resize event
|
||||||
|
// noinspection JSUnresolvedVariable
|
||||||
|
$(config.appendScroll).on("scroll." + namespace + " resize." + namespace, events.e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* prepare items before handle them
|
||||||
|
* @access private
|
||||||
|
* @param {Array|object|jQuery} items
|
||||||
|
* @return {Array|object|jQuery}
|
||||||
|
*/
|
||||||
|
function _prepareItems(items) {
|
||||||
|
// fetch used configurations before loops
|
||||||
|
var defaultImage = config.defaultImage,
|
||||||
|
placeholder = config.placeholder,
|
||||||
|
imageBase = config.imageBase,
|
||||||
|
srcsetAttribute = config.srcsetAttribute,
|
||||||
|
loaderAttribute = config.loaderAttribute,
|
||||||
|
forcedTags = config._f || {};
|
||||||
|
|
||||||
|
// filter items and only add those who not handled yet and got needed attributes available
|
||||||
|
items = $(items).filter(function() {
|
||||||
|
var element = $(this),
|
||||||
|
tag = _getElementTagName(this);
|
||||||
|
|
||||||
|
return !element.data(config.handledName) &&
|
||||||
|
(element.attr(config.attribute) || element.attr(srcsetAttribute) || element.attr(loaderAttribute) || forcedTags[tag] !== undefined);
|
||||||
|
})
|
||||||
|
|
||||||
|
// append plugin instance to all elements
|
||||||
|
.data("plugin_" + config.name, instance);
|
||||||
|
|
||||||
|
for( var i = 0, l = items.length; i < l; i++ ) {
|
||||||
|
var element = $(items[i]),
|
||||||
|
tag = _getElementTagName(items[i]),
|
||||||
|
elementImageBase = element.attr(config.imageBaseAttribute) || imageBase;
|
||||||
|
|
||||||
|
// generate and update source set if an image base is set
|
||||||
|
if( tag === _img && elementImageBase && element.attr(srcsetAttribute) ) {
|
||||||
|
element.attr(srcsetAttribute, _getCorrectedSrcSet(element.attr(srcsetAttribute), elementImageBase));
|
||||||
|
}
|
||||||
|
|
||||||
|
// add loader to forced element types
|
||||||
|
if( forcedTags[tag] !== undefined && !element.attr(loaderAttribute) ) {
|
||||||
|
element.attr(loaderAttribute, forcedTags[tag]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set default image on every element without source
|
||||||
|
if( tag === _img && defaultImage && !element.attr(_src) ) {
|
||||||
|
element.attr(_src, defaultImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set placeholder on every element without background image
|
||||||
|
else if( tag !== _img && placeholder && (!element.css(_backgroundImage) || element.css(_backgroundImage) === "none") ) {
|
||||||
|
element.css(_backgroundImage, "url('" + placeholder + "')");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the 'lazy magic' - check all items
|
||||||
|
* @access private
|
||||||
|
* @param {boolean} [allItems]
|
||||||
|
* @param {object} [forced]
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function _lazyLoadItems(allItems, forced) {
|
||||||
|
// skip if no items where left
|
||||||
|
if( !items.length ) {
|
||||||
|
// destroy instance if option is enabled
|
||||||
|
if( config.autoDestroy ) {
|
||||||
|
// noinspection JSUnresolvedFunction
|
||||||
|
instance.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var elements = forced || items,
|
||||||
|
loadTriggered = false,
|
||||||
|
imageBase = config.imageBase || "",
|
||||||
|
srcsetAttribute = config.srcsetAttribute,
|
||||||
|
handledName = config.handledName;
|
||||||
|
|
||||||
|
// loop all available items
|
||||||
|
for( var i = 0; i < elements.length; i++ ) {
|
||||||
|
// item is at least in loadable area
|
||||||
|
if( allItems || forced || _isInLoadableArea(elements[i]) ) {
|
||||||
|
var element = $(elements[i]),
|
||||||
|
tag = _getElementTagName(elements[i]),
|
||||||
|
attribute = element.attr(config.attribute),
|
||||||
|
elementImageBase = element.attr(config.imageBaseAttribute) || imageBase,
|
||||||
|
customLoader = element.attr(config.loaderAttribute);
|
||||||
|
|
||||||
|
// is not already handled
|
||||||
|
if( !element.data(handledName) &&
|
||||||
|
// and is visible or visibility doesn't matter
|
||||||
|
(!config.visibleOnly || element.is(":visible")) && (
|
||||||
|
// and image source or source set attribute is available
|
||||||
|
(attribute || element.attr(srcsetAttribute)) && (
|
||||||
|
// and is image tag where attribute is not equal source or source set
|
||||||
|
(tag === _img && (elementImageBase + attribute !== element.attr(_src) || element.attr(srcsetAttribute) !== element.attr(_srcset))) ||
|
||||||
|
// or is non image tag where attribute is not equal background
|
||||||
|
(tag !== _img && elementImageBase + attribute !== element.css(_backgroundImage))
|
||||||
|
) ||
|
||||||
|
// or custom loader is available
|
||||||
|
customLoader ))
|
||||||
|
{
|
||||||
|
// mark element always as handled as this point to prevent double handling
|
||||||
|
loadTriggered = true;
|
||||||
|
element.data(handledName, true);
|
||||||
|
|
||||||
|
// load item
|
||||||
|
_handleItem(element, tag, elementImageBase, customLoader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// when something was loaded remove them from remaining items
|
||||||
|
if( loadTriggered ) {
|
||||||
|
items = $(items).filter(function() {
|
||||||
|
return !$(this).data(handledName);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* load the given element the lazy way
|
||||||
|
* @access private
|
||||||
|
* @param {object} element
|
||||||
|
* @param {string} tag
|
||||||
|
* @param {string} imageBase
|
||||||
|
* @param {function} [customLoader]
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function _handleItem(element, tag, imageBase, customLoader) {
|
||||||
|
// increment count of items waiting for after load
|
||||||
|
++_awaitingAfterLoad;
|
||||||
|
|
||||||
|
// extended error callback for correct 'onFinishedAll' handling
|
||||||
|
var errorCallback = function() {
|
||||||
|
_triggerCallback("onError", element);
|
||||||
|
_reduceAwaiting();
|
||||||
|
|
||||||
|
// prevent further callback calls
|
||||||
|
errorCallback = $.noop;
|
||||||
|
};
|
||||||
|
|
||||||
|
// trigger function before loading image
|
||||||
|
_triggerCallback("beforeLoad", element);
|
||||||
|
|
||||||
|
// fetch all double used data here for better code minimization
|
||||||
|
var srcAttribute = config.attribute,
|
||||||
|
srcsetAttribute = config.srcsetAttribute,
|
||||||
|
sizesAttribute = config.sizesAttribute,
|
||||||
|
retinaAttribute = config.retinaAttribute,
|
||||||
|
removeAttribute = config.removeAttribute,
|
||||||
|
loadedName = config.loadedName,
|
||||||
|
elementRetina = element.attr(retinaAttribute);
|
||||||
|
|
||||||
|
// handle custom loader
|
||||||
|
if( customLoader ) {
|
||||||
|
// on load callback
|
||||||
|
var loadCallback = function() {
|
||||||
|
// remove attribute from element
|
||||||
|
if( removeAttribute ) {
|
||||||
|
element.removeAttr(config.loaderAttribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
// mark element as loaded
|
||||||
|
element.data(loadedName, true);
|
||||||
|
|
||||||
|
// call after load event
|
||||||
|
_triggerCallback(_afterLoad, element);
|
||||||
|
|
||||||
|
// remove item from waiting queue and possibly trigger finished event
|
||||||
|
// it's needed to be asynchronous to run after filter was in _lazyLoadItems
|
||||||
|
setTimeout(_reduceAwaiting, 1);
|
||||||
|
|
||||||
|
// prevent further callback calls
|
||||||
|
loadCallback = $.noop;
|
||||||
|
};
|
||||||
|
|
||||||
|
// bind error event to trigger callback and reduce waiting amount
|
||||||
|
element.off(_error).one(_error, errorCallback)
|
||||||
|
|
||||||
|
// bind after load callback to element
|
||||||
|
.one(_load, loadCallback);
|
||||||
|
|
||||||
|
// trigger custom loader and handle response
|
||||||
|
if( !_triggerCallback(customLoader, element, function(response) {
|
||||||
|
if( response ) {
|
||||||
|
element.off(_load);
|
||||||
|
loadCallback();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
element.off(_error);
|
||||||
|
errorCallback();
|
||||||
|
}
|
||||||
|
})) element.trigger(_error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle images
|
||||||
|
else {
|
||||||
|
// create image object
|
||||||
|
var imageObj = $(new Image());
|
||||||
|
|
||||||
|
// bind error event to trigger callback and reduce waiting amount
|
||||||
|
imageObj.one(_error, errorCallback)
|
||||||
|
|
||||||
|
// bind after load callback to image
|
||||||
|
.one(_load, function() {
|
||||||
|
// remove element from view
|
||||||
|
element.hide();
|
||||||
|
|
||||||
|
// set image back to element
|
||||||
|
// do it as single 'attr' calls, to be sure 'src' is set after 'srcset'
|
||||||
|
if( tag === _img ) {
|
||||||
|
element.attr(_sizes, imageObj.attr(_sizes))
|
||||||
|
.attr(_srcset, imageObj.attr(_srcset))
|
||||||
|
.attr(_src, imageObj.attr(_src));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
element.css(_backgroundImage, "url('" + imageObj.attr(_src) + "')");
|
||||||
|
}
|
||||||
|
|
||||||
|
// bring it back with some effect!
|
||||||
|
element[config.effect](config.effectTime);
|
||||||
|
|
||||||
|
// remove attribute from element
|
||||||
|
if( removeAttribute ) {
|
||||||
|
element.removeAttr(srcAttribute + " " + srcsetAttribute + " " + retinaAttribute + " " + config.imageBaseAttribute);
|
||||||
|
|
||||||
|
// only remove 'sizes' attribute, if it was a custom one
|
||||||
|
if( sizesAttribute !== _sizes ) {
|
||||||
|
element.removeAttr(sizesAttribute);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// mark element as loaded
|
||||||
|
element.data(loadedName, true);
|
||||||
|
|
||||||
|
// call after load event
|
||||||
|
_triggerCallback(_afterLoad, element);
|
||||||
|
|
||||||
|
// cleanup image object
|
||||||
|
imageObj.remove();
|
||||||
|
|
||||||
|
// remove item from waiting queue and possibly trigger finished event
|
||||||
|
_reduceAwaiting();
|
||||||
|
});
|
||||||
|
|
||||||
|
// set sources
|
||||||
|
// do it as single 'attr' calls, to be sure 'src' is set after 'srcset'
|
||||||
|
var imageSrc = (_isRetinaDisplay && elementRetina ? elementRetina : element.attr(srcAttribute)) || "";
|
||||||
|
imageObj.attr(_sizes, element.attr(sizesAttribute))
|
||||||
|
.attr(_srcset, element.attr(srcsetAttribute))
|
||||||
|
.attr(_src, imageSrc ? imageBase + imageSrc : null);
|
||||||
|
|
||||||
|
// call after load even on cached image
|
||||||
|
imageObj.complete && imageObj.trigger(_load); // jshint ignore : line
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check if the given element is inside the current viewport or threshold
|
||||||
|
* @access private
|
||||||
|
* @param {object} element
|
||||||
|
* @return {boolean}
|
||||||
|
*/
|
||||||
|
function _isInLoadableArea(element) {
|
||||||
|
var elementBound = element.getBoundingClientRect(),
|
||||||
|
direction = config.scrollDirection,
|
||||||
|
threshold = config.threshold,
|
||||||
|
vertical = // check if element is in loadable area from top
|
||||||
|
((_getActualHeight() + threshold) > elementBound.top) &&
|
||||||
|
// check if element is even in loadable are from bottom
|
||||||
|
(-threshold < elementBound.bottom),
|
||||||
|
horizontal = // check if element is in loadable area from left
|
||||||
|
((_getActualWidth() + threshold) > elementBound.left) &&
|
||||||
|
// check if element is even in loadable area from right
|
||||||
|
(-threshold < elementBound.right);
|
||||||
|
|
||||||
|
if( direction === "vertical" ) {
|
||||||
|
return vertical;
|
||||||
|
}
|
||||||
|
else if( direction === "horizontal" ) {
|
||||||
|
return horizontal;
|
||||||
|
}
|
||||||
|
|
||||||
|
return vertical && horizontal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* receive the current viewed width of the browser
|
||||||
|
* @access private
|
||||||
|
* @return {number}
|
||||||
|
*/
|
||||||
|
function _getActualWidth() {
|
||||||
|
return _actualWidth >= 0 ? _actualWidth : (_actualWidth = $(window).width());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* receive the current viewed height of the browser
|
||||||
|
* @access private
|
||||||
|
* @return {number}
|
||||||
|
*/
|
||||||
|
function _getActualHeight() {
|
||||||
|
return _actualHeight >= 0 ? _actualHeight : (_actualHeight = $(window).height());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get lowercase tag name of an element
|
||||||
|
* @access private
|
||||||
|
* @param {object} element
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
function _getElementTagName(element) {
|
||||||
|
return element.tagName.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* prepend image base to all srcset entries
|
||||||
|
* @access private
|
||||||
|
* @param {string} srcset
|
||||||
|
* @param {string} imageBase
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
function _getCorrectedSrcSet(srcset, imageBase) {
|
||||||
|
if( imageBase ) {
|
||||||
|
// trim, remove unnecessary spaces and split entries
|
||||||
|
var entries = srcset.split(",");
|
||||||
|
srcset = "";
|
||||||
|
|
||||||
|
for( var i = 0, l = entries.length; i < l; i++ ) {
|
||||||
|
srcset += imageBase + entries[i].trim() + (i !== l - 1 ? "," : "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return srcset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* helper function to throttle down event triggering
|
||||||
|
* @access private
|
||||||
|
* @param {number} delay
|
||||||
|
* @param {function} callback
|
||||||
|
* @return {function}
|
||||||
|
*/
|
||||||
|
function _throttle(delay, callback) {
|
||||||
|
var timeout,
|
||||||
|
lastExecute = 0;
|
||||||
|
|
||||||
|
return function(event, ignoreThrottle) {
|
||||||
|
var elapsed = +new Date() - lastExecute;
|
||||||
|
|
||||||
|
function run() {
|
||||||
|
lastExecute = +new Date();
|
||||||
|
// noinspection JSUnresolvedFunction
|
||||||
|
callback.call(instance, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
timeout && clearTimeout(timeout); // jshint ignore : line
|
||||||
|
|
||||||
|
if( elapsed > delay || !config.enableThrottle || ignoreThrottle ) {
|
||||||
|
run();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
timeout = setTimeout(run, delay - elapsed);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* reduce count of awaiting elements to 'afterLoad' event and fire 'onFinishedAll' if reached zero
|
||||||
|
* @access private
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function _reduceAwaiting() {
|
||||||
|
--_awaitingAfterLoad;
|
||||||
|
|
||||||
|
// if no items were left trigger finished event
|
||||||
|
if( !items.length && !_awaitingAfterLoad ) {
|
||||||
|
_triggerCallback("onFinishedAll");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* single implementation to handle callbacks, pass element and set 'this' to current instance
|
||||||
|
* @access private
|
||||||
|
* @param {string|function} callback
|
||||||
|
* @param {object} [element]
|
||||||
|
* @param {*} [args]
|
||||||
|
* @return {boolean}
|
||||||
|
*/
|
||||||
|
function _triggerCallback(callback, element, args) {
|
||||||
|
if( (callback = config[callback]) ) {
|
||||||
|
// jQuery's internal '$(arguments).slice(1)' are causing problems at least on old iPads
|
||||||
|
// below is shorthand of 'Array.prototype.slice.call(arguments, 1)'
|
||||||
|
callback.apply(instance, [].slice.call(arguments, 1));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if event driven or window is already loaded don't wait for page loading
|
||||||
|
if( config.bind === "event" || windowLoaded ) {
|
||||||
|
_initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
// otherwise load initial items and start lazy after page load
|
||||||
|
else {
|
||||||
|
// noinspection JSUnresolvedVariable
|
||||||
|
$(window).on(_load + "." + namespace, _initialize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* lazy plugin class constructor
|
||||||
|
* @constructor
|
||||||
|
* @access private
|
||||||
|
* @param {object} elements
|
||||||
|
* @param {object} settings
|
||||||
|
* @return {object|LazyPlugin}
|
||||||
|
*/
|
||||||
|
function LazyPlugin(elements, settings) {
|
||||||
|
/**
|
||||||
|
* this lazy plugin instance
|
||||||
|
* @access private
|
||||||
|
* @type {object|LazyPlugin|LazyPlugin.prototype}
|
||||||
|
*/
|
||||||
|
var _instance = this,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this lazy plugin instance configuration
|
||||||
|
* @access private
|
||||||
|
* @type {object}
|
||||||
|
*/
|
||||||
|
_config = $.extend({}, _instance.config, settings),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* instance generated event executed on container scroll or resize
|
||||||
|
* packed in an object to be referenceable and short named because properties will not be minified
|
||||||
|
* @access private
|
||||||
|
* @type {object}
|
||||||
|
*/
|
||||||
|
_events = {},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* unique namespace for instance related events
|
||||||
|
* @access private
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
_namespace = _config.name + "-" + (++lazyInstanceId);
|
||||||
|
|
||||||
|
// noinspection JSUndefinedPropertyAssignment
|
||||||
|
/**
|
||||||
|
* wrapper to get or set an entry from plugin instance configuration
|
||||||
|
* much smaller on minify as direct access
|
||||||
|
* @access public
|
||||||
|
* @type {function}
|
||||||
|
* @param {string} entryName
|
||||||
|
* @param {*} [value]
|
||||||
|
* @return {LazyPlugin|*}
|
||||||
|
*/
|
||||||
|
_instance.config = function(entryName, value) {
|
||||||
|
if( value === undefined ) {
|
||||||
|
return _config[entryName];
|
||||||
|
}
|
||||||
|
|
||||||
|
_config[entryName] = value;
|
||||||
|
return _instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
// noinspection JSUndefinedPropertyAssignment
|
||||||
|
/**
|
||||||
|
* add additional items to current instance
|
||||||
|
* @access public
|
||||||
|
* @param {Array|object|string} items
|
||||||
|
* @return {LazyPlugin}
|
||||||
|
*/
|
||||||
|
_instance.addItems = function(items) {
|
||||||
|
_events.a && _events.a($.type(items) === "string" ? $(items) : items); // jshint ignore : line
|
||||||
|
return _instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
// noinspection JSUndefinedPropertyAssignment
|
||||||
|
/**
|
||||||
|
* get all left items of this instance
|
||||||
|
* @access public
|
||||||
|
* @returns {object}
|
||||||
|
*/
|
||||||
|
_instance.getItems = function() {
|
||||||
|
return _events.g ? _events.g() : {};
|
||||||
|
};
|
||||||
|
|
||||||
|
// noinspection JSUndefinedPropertyAssignment
|
||||||
|
/**
|
||||||
|
* force lazy to load all items in loadable area right now
|
||||||
|
* by default without throttle
|
||||||
|
* @access public
|
||||||
|
* @type {function}
|
||||||
|
* @param {boolean} [useThrottle]
|
||||||
|
* @return {LazyPlugin}
|
||||||
|
*/
|
||||||
|
_instance.update = function(useThrottle) {
|
||||||
|
_events.e && _events.e({}, !useThrottle); // jshint ignore : line
|
||||||
|
return _instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
// noinspection JSUndefinedPropertyAssignment
|
||||||
|
/**
|
||||||
|
* force element(s) to load directly, ignoring the viewport
|
||||||
|
* @access public
|
||||||
|
* @param {Array|object|string} items
|
||||||
|
* @return {LazyPlugin}
|
||||||
|
*/
|
||||||
|
_instance.force = function(items) {
|
||||||
|
_events.f && _events.f($.type(items) === "string" ? $(items) : items); // jshint ignore : line
|
||||||
|
return _instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
// noinspection JSUndefinedPropertyAssignment
|
||||||
|
/**
|
||||||
|
* force lazy to load all available items right now
|
||||||
|
* this call ignores throttling
|
||||||
|
* @access public
|
||||||
|
* @type {function}
|
||||||
|
* @return {LazyPlugin}
|
||||||
|
*/
|
||||||
|
_instance.loadAll = function() {
|
||||||
|
_events.e && _events.e({all: true}, true); // jshint ignore : line
|
||||||
|
return _instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
// noinspection JSUndefinedPropertyAssignment
|
||||||
|
/**
|
||||||
|
* destroy this plugin instance
|
||||||
|
* @access public
|
||||||
|
* @type {function}
|
||||||
|
* @return undefined
|
||||||
|
*/
|
||||||
|
_instance.destroy = function() {
|
||||||
|
// unbind instance generated events
|
||||||
|
// noinspection JSUnresolvedFunction, JSUnresolvedVariable
|
||||||
|
$(_config.appendScroll).off("." + _namespace, _events.e);
|
||||||
|
// noinspection JSUnresolvedVariable
|
||||||
|
$(window).off("." + _namespace);
|
||||||
|
|
||||||
|
// clear events
|
||||||
|
_events = {};
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
// start using lazy and return all elements to be chainable or instance for further use
|
||||||
|
// noinspection JSUnresolvedVariable
|
||||||
|
_executeLazy(_instance, _config, elements, _events, _namespace);
|
||||||
|
return _config.chainable ? elements : _instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* settings and configuration data
|
||||||
|
* @access public
|
||||||
|
* @type {object}
|
||||||
|
*/
|
||||||
|
LazyPlugin.prototype.config = {
|
||||||
|
// general
|
||||||
|
name : "lazy",
|
||||||
|
chainable : true,
|
||||||
|
autoDestroy : true,
|
||||||
|
bind : "load",
|
||||||
|
threshold : 500,
|
||||||
|
visibleOnly : false,
|
||||||
|
appendScroll : window,
|
||||||
|
scrollDirection : "both",
|
||||||
|
imageBase : null,
|
||||||
|
defaultImage : "data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==",
|
||||||
|
placeholder : null,
|
||||||
|
delay : -1,
|
||||||
|
combined : false,
|
||||||
|
|
||||||
|
// attributes
|
||||||
|
attribute : "data-src",
|
||||||
|
srcsetAttribute : "data-srcset",
|
||||||
|
sizesAttribute : "data-sizes",
|
||||||
|
retinaAttribute : "data-retina",
|
||||||
|
loaderAttribute : "data-loader",
|
||||||
|
imageBaseAttribute : "data-imagebase",
|
||||||
|
removeAttribute : true,
|
||||||
|
handledName : "handled",
|
||||||
|
loadedName : "loaded",
|
||||||
|
|
||||||
|
// effect
|
||||||
|
effect : "show",
|
||||||
|
effectTime : 0,
|
||||||
|
|
||||||
|
// throttle
|
||||||
|
enableThrottle : true,
|
||||||
|
throttle : 250,
|
||||||
|
|
||||||
|
// callbacks
|
||||||
|
beforeLoad : undefined,
|
||||||
|
afterLoad : undefined,
|
||||||
|
onError : undefined,
|
||||||
|
onFinishedAll : undefined
|
||||||
|
};
|
||||||
|
|
||||||
|
// register window load event globally to prevent not loading elements
|
||||||
|
// since jQuery 3.X ready state is fully async and may be executed after 'load'
|
||||||
|
$(window).on("load", function() {
|
||||||
|
windowLoaded = true;
|
||||||
|
});
|
||||||
|
})(window);
|
2
view/js/jquery.lazy/jquery.lazy.min.js
vendored
Normal file
2
view/js/jquery.lazy/jquery.lazy.min.js
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/*! jQuery & Zepto Lazy v1.7.7 - http://jquery.eisbehr.de/lazy - MIT&GPL-2.0 license - Copyright 2012-2017 Daniel 'Eisbehr' Kern */
|
||||||
|
!function(t,e){"use strict";function r(r,a,i,u,l){function f(){L=t.devicePixelRatio>1,i=c(i),a.delay>=0&&setTimeout(function(){s(!0)},a.delay),(a.delay<0||a.combined)&&(u.e=v(a.throttle,function(t){"resize"===t.type&&(w=B=-1),s(t.all)}),u.a=function(t){t=c(t),i.push.apply(i,t)},u.g=function(){return i=n(i).filter(function(){return!n(this).data(a.loadedName)})},u.f=function(t){for(var e=0;e<t.length;e++){var r=i.filter(function(){return this===t[e]});r.length&&s(!1,r)}},s(),n(a.appendScroll).on("scroll."+l+" resize."+l,u.e))}function c(t){var i=a.defaultImage,o=a.placeholder,u=a.imageBase,l=a.srcsetAttribute,f=a.loaderAttribute,c=a._f||{};t=n(t).filter(function(){var t=n(this),r=m(this);return!t.data(a.handledName)&&(t.attr(a.attribute)||t.attr(l)||t.attr(f)||c[r]!==e)}).data("plugin_"+a.name,r);for(var s=0,d=t.length;s<d;s++){var A=n(t[s]),g=m(t[s]),h=A.attr(a.imageBaseAttribute)||u;g===N&&h&&A.attr(l)&&A.attr(l,b(A.attr(l),h)),c[g]===e||A.attr(f)||A.attr(f,c[g]),g===N&&i&&!A.attr(E)?A.attr(E,i):g===N||!o||A.css(O)&&"none"!==A.css(O)||A.css(O,"url('"+o+"')")}return t}function s(t,e){if(!i.length)return void(a.autoDestroy&&r.destroy());for(var o=e||i,u=!1,l=a.imageBase||"",f=a.srcsetAttribute,c=a.handledName,s=0;s<o.length;s++)if(t||e||A(o[s])){var g=n(o[s]),h=m(o[s]),b=g.attr(a.attribute),v=g.attr(a.imageBaseAttribute)||l,p=g.attr(a.loaderAttribute);g.data(c)||a.visibleOnly&&!g.is(":visible")||!((b||g.attr(f))&&(h===N&&(v+b!==g.attr(E)||g.attr(f)!==g.attr(F))||h!==N&&v+b!==g.css(O))||p)||(u=!0,g.data(c,!0),d(g,h,v,p))}u&&(i=n(i).filter(function(){return!n(this).data(c)}))}function d(t,e,r,i){++z;var o=function(){y("onError",t),p(),o=n.noop};y("beforeLoad",t);var u=a.attribute,l=a.srcsetAttribute,f=a.sizesAttribute,c=a.retinaAttribute,s=a.removeAttribute,d=a.loadedName,A=t.attr(c);if(i){var g=function(){s&&t.removeAttr(a.loaderAttribute),t.data(d,!0),y(T,t),setTimeout(p,1),g=n.noop};t.off(I).one(I,o).one(D,g),y(i,t,function(e){e?(t.off(D),g()):(t.off(I),o())})||t.trigger(I)}else{var h=n(new Image);h.one(I,o).one(D,function(){t.hide(),e===N?t.attr(C,h.attr(C)).attr(F,h.attr(F)).attr(E,h.attr(E)):t.css(O,"url('"+h.attr(E)+"')"),t[a.effect](a.effectTime),s&&(t.removeAttr(u+" "+l+" "+c+" "+a.imageBaseAttribute),f!==C&&t.removeAttr(f)),t.data(d,!0),y(T,t),h.remove(),p()});var m=(L&&A?A:t.attr(u))||"";h.attr(C,t.attr(f)).attr(F,t.attr(l)).attr(E,m?r+m:null),h.complete&&h.trigger(D)}}function A(t){var e=t.getBoundingClientRect(),r=a.scrollDirection,n=a.threshold,i=h()+n>e.top&&-n<e.bottom,o=g()+n>e.left&&-n<e.right;return"vertical"===r?i:"horizontal"===r?o:i&&o}function g(){return w>=0?w:w=n(t).width()}function h(){return B>=0?B:B=n(t).height()}function m(t){return t.tagName.toLowerCase()}function b(t,e){if(e){var r=t.split(",");t="";for(var a=0,n=r.length;a<n;a++)t+=e+r[a].trim()+(a!==n-1?",":"")}return t}function v(t,e){var n,i=0;return function(o,u){function l(){i=+new Date,e.call(r,o)}var f=+new Date-i;n&&clearTimeout(n),f>t||!a.enableThrottle||u?l():n=setTimeout(l,t-f)}}function p(){--z,i.length||z||y("onFinishedAll")}function y(t,e,n){return!!(t=a[t])&&(t.apply(r,[].slice.call(arguments,1)),!0)}var z=0,w=-1,B=-1,L=!1,T="afterLoad",D="load",I="error",N="img",E="src",F="srcset",C="sizes",O="background-image";"event"===a.bind||o?f():n(t).on(D+"."+l,f)}function a(a,o){var u=this,l=n.extend({},u.config,o),f={},c=l.name+"-"+ ++i;return u.config=function(t,r){return r===e?l[t]:(l[t]=r,u)},u.addItems=function(t){return f.a&&f.a("string"===n.type(t)?n(t):t),u},u.getItems=function(){return f.g?f.g():{}},u.update=function(t){return f.e&&f.e({},!t),u},u.force=function(t){return f.f&&f.f("string"===n.type(t)?n(t):t),u},u.loadAll=function(){return f.e&&f.e({all:!0},!0),u},u.destroy=function(){return n(l.appendScroll).off("."+c,f.e),n(t).off("."+c),f={},e},r(u,l,a,f,c),l.chainable?a:u}var n=t.jQuery||t.Zepto,i=0,o=!1;n.fn.Lazy=n.fn.lazy=function(t){return new a(this,t)},n.Lazy=n.lazy=function(t,r,i){if(n.isFunction(r)&&(i=r,r=[]),n.isFunction(i)){t=n.isArray(t)?t:[t],r=n.isArray(r)?r:[r];for(var o=a.prototype.config,u=o._f||(o._f={}),l=0,f=t.length;l<f;l++)(o[t[l]]===e||n.isFunction(o[t[l]]))&&(o[t[l]]=i);for(var c=0,s=r.length;c<s;c++)u[r[c]]=t[0]}},a.prototype.config={name:"lazy",chainable:!0,autoDestroy:!0,bind:"load",threshold:500,visibleOnly:!1,appendScroll:t,scrollDirection:"both",imageBase:null,defaultImage:"data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==",placeholder:null,delay:-1,combined:!1,attribute:"data-src",srcsetAttribute:"data-srcset",sizesAttribute:"data-sizes",retinaAttribute:"data-retina",loaderAttribute:"data-loader",imageBaseAttribute:"data-imagebase",removeAttribute:!0,handledName:"handled",loadedName:"loaded",effect:"show",effectTime:0,enableThrottle:!0,throttle:250,beforeLoad:e,afterLoad:e,onError:e,onFinishedAll:e},n(t).on("load",function(){o=!0})}(window);
|
580
view/js/jquery.lazy/jquery.lazy.plugins.js
Normal file
580
view/js/jquery.lazy/jquery.lazy.plugins.js
Normal file
|
@ -0,0 +1,580 @@
|
||||||
|
/*!
|
||||||
|
* jQuery & Zepto Lazy - AJAX Plugin - v1.2
|
||||||
|
* http://jquery.eisbehr.de/lazy/
|
||||||
|
*
|
||||||
|
* Copyright 2012 - 2017, Daniel 'Eisbehr' Kern
|
||||||
|
*
|
||||||
|
* Dual licensed under the MIT and GPL-2.0 licenses:
|
||||||
|
* http://www.opensource.org/licenses/mit-license.php
|
||||||
|
* http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
;(function($) {
|
||||||
|
// load data by ajax request and pass them to elements inner html, like:
|
||||||
|
// <div data-loader="ajax" data-src"url.html" data-method="post" data-type="html"></div>
|
||||||
|
$.lazy("ajax", function(element, response) {
|
||||||
|
ajaxRequest(this, element, response, element.attr("data-method"));
|
||||||
|
});
|
||||||
|
|
||||||
|
// load data by ajax get request and pass them to elements inner html, like:
|
||||||
|
// <div data-loader="get" data-src"url.html" data-type="html"></div>
|
||||||
|
$.lazy("get", function(element, response) {
|
||||||
|
ajaxRequest(this, element, response, "get");
|
||||||
|
});
|
||||||
|
|
||||||
|
// load data by ajax post request and pass them to elements inner html, like:
|
||||||
|
// <div data-loader="post" data-src"url.html" data-type="html"></div>
|
||||||
|
$.lazy("post", function(element, response) {
|
||||||
|
ajaxRequest(this, element, response, "post");
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* execute ajax request and handle response
|
||||||
|
* @param {object} instance
|
||||||
|
* @param {jQuery|object} element
|
||||||
|
* @param {function} response
|
||||||
|
* @param {string} [method]
|
||||||
|
*/
|
||||||
|
function ajaxRequest(instance, element, response, method) {
|
||||||
|
$.ajax({
|
||||||
|
url: element.attr("data-src"),
|
||||||
|
type: method || "get",
|
||||||
|
dataType: element.attr("data-type") || "html",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* success callback
|
||||||
|
* @access private
|
||||||
|
* @param {*} content
|
||||||
|
* @return {void}
|
||||||
|
*/
|
||||||
|
success: function(content) {
|
||||||
|
// set responded data to element's inner html
|
||||||
|
element.html(content);
|
||||||
|
|
||||||
|
// use response function for Zepto
|
||||||
|
response(true);
|
||||||
|
|
||||||
|
// remove attributes
|
||||||
|
if( instance.config("removeAttribute") )
|
||||||
|
element.removeAttr("data-src data-method data-type");
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* error callback
|
||||||
|
* @access private
|
||||||
|
* @return {void}
|
||||||
|
*/
|
||||||
|
error: function() {
|
||||||
|
// pass error state to lazy
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})(window.jQuery || window.Zepto);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* jQuery & Zepto Lazy - AV Plugin - v1.4
|
||||||
|
* http://jquery.eisbehr.de/lazy/
|
||||||
|
*
|
||||||
|
* Copyright 2012 - 2017, Daniel 'Eisbehr' Kern
|
||||||
|
*
|
||||||
|
* Dual licensed under the MIT and GPL-2.0 licenses:
|
||||||
|
* http://www.opensource.org/licenses/mit-license.php
|
||||||
|
* http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
;(function($) {
|
||||||
|
// loads audio and video tags including tracks by two ways, like:
|
||||||
|
// <audio>
|
||||||
|
// <data-src src="audio.ogg" type="video/ogg"></data-src>
|
||||||
|
// <data-src src="audio.mp3" type="video/mp3"></data-src>
|
||||||
|
// </audio>
|
||||||
|
// <video data-poster="poster.jpg">
|
||||||
|
// <data-src src="video.ogv" type="video/ogv"></data-src>
|
||||||
|
// <data-src src="video.webm" type="video/webm"></data-src>
|
||||||
|
// <data-src src="video.mp4" type="video/mp4"></data-src>
|
||||||
|
// <data-track kind="captions" src="captions.vtt" srclang="en"></data-track>
|
||||||
|
// <data-track kind="descriptions" src="descriptions.vtt" srclang="en"></data-track>
|
||||||
|
// <data-track kind="subtitles" src="subtitles.vtt" srclang="de"></data-track>
|
||||||
|
// </video>
|
||||||
|
//
|
||||||
|
// or:
|
||||||
|
// <audio data-src="audio.ogg|video/ogg,video.mp3|video/mp3"></video>
|
||||||
|
// <video data-poster="poster.jpg" data-src="video.ogv|video/ogv,video.webm|video/webm,video.mp4|video/mp4">
|
||||||
|
// <data-track kind="captions" src="captions.vtt" srclang="en"></data-track>
|
||||||
|
// <data-track kind="descriptions" src="descriptions.vtt" srclang="en"></data-track>
|
||||||
|
// <data-track kind="subtitles" src="subtitles.vtt" srclang="de"></data-track>
|
||||||
|
// </video>
|
||||||
|
$.lazy(["av", "audio", "video"], ["audio", "video"], function(element, response) {
|
||||||
|
var elementTagName = element[0].tagName.toLowerCase();
|
||||||
|
|
||||||
|
if( elementTagName === "audio" || elementTagName === "video" ) {
|
||||||
|
var srcAttr = "data-src",
|
||||||
|
sources = element.find(srcAttr),
|
||||||
|
tracks = element.find("data-track"),
|
||||||
|
sourcesInError = 0,
|
||||||
|
|
||||||
|
// create on error callback for sources
|
||||||
|
onError = function() {
|
||||||
|
if( ++sourcesInError === sources.length )
|
||||||
|
response(false);
|
||||||
|
},
|
||||||
|
|
||||||
|
// create callback to handle a source or track entry
|
||||||
|
handleSource = function() {
|
||||||
|
var source = $(this),
|
||||||
|
type = source[0].tagName.toLowerCase(),
|
||||||
|
attributes = source.prop("attributes"),
|
||||||
|
target = $(type === srcAttr ? "<source>" : "<track>");
|
||||||
|
|
||||||
|
if( type === srcAttr )
|
||||||
|
target.one("error", onError);
|
||||||
|
|
||||||
|
$.each(attributes, function(index, attribute) {
|
||||||
|
target.attr(attribute.name, attribute.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
source.replaceWith(target);
|
||||||
|
};
|
||||||
|
|
||||||
|
// create event for successfull load
|
||||||
|
element.one("loadedmetadata", function() {
|
||||||
|
response(true);
|
||||||
|
})
|
||||||
|
|
||||||
|
// remove default callbacks to ignore loading poster image
|
||||||
|
.off("load error")
|
||||||
|
|
||||||
|
// load poster image
|
||||||
|
.attr("poster", element.attr("data-poster"));
|
||||||
|
|
||||||
|
// load by child tags
|
||||||
|
if( sources.length )
|
||||||
|
sources.each(handleSource);
|
||||||
|
|
||||||
|
// load by attribute
|
||||||
|
else if( element.attr(srcAttr) ) {
|
||||||
|
// split for every entry by comma
|
||||||
|
$.each(element.attr(srcAttr).split(","), function(index, value) {
|
||||||
|
// split again for file and file type
|
||||||
|
var parts = value.split("|");
|
||||||
|
|
||||||
|
// create a source entry
|
||||||
|
element.append($("<source>")
|
||||||
|
.one("error", onError)
|
||||||
|
.attr({src: parts[0].trim(), type: parts[1].trim()}));
|
||||||
|
});
|
||||||
|
|
||||||
|
// remove now obsolete attribute
|
||||||
|
if( this.config("removeAttribute") )
|
||||||
|
element.removeAttr(srcAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
// pass error state
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// load optional tracks
|
||||||
|
if( tracks.length )
|
||||||
|
tracks.each(handleSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
// pass error state
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})(window.jQuery || window.Zepto);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* jQuery & Zepto Lazy - iFrame Plugin - v1.5
|
||||||
|
* http://jquery.eisbehr.de/lazy/
|
||||||
|
*
|
||||||
|
* Copyright 2012 - 2017, Daniel 'Eisbehr' Kern
|
||||||
|
*
|
||||||
|
* Dual licensed under the MIT and GPL-2.0 licenses:
|
||||||
|
* http://www.opensource.org/licenses/mit-license.php
|
||||||
|
* http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
;(function($) {
|
||||||
|
// load iframe content, like:
|
||||||
|
// <iframe data-src="iframe.html"></iframe>
|
||||||
|
//
|
||||||
|
// enable content error check with:
|
||||||
|
// <iframe data-src="iframe.html" data-error-detect="true"></iframe>
|
||||||
|
$.lazy(["frame", "iframe"], "iframe", function(element, response) {
|
||||||
|
var instance = this;
|
||||||
|
|
||||||
|
if( element[0].tagName.toLowerCase() === "iframe" ) {
|
||||||
|
var srcAttr = "data-src",
|
||||||
|
errorDetectAttr = "data-error-detect",
|
||||||
|
errorDetect = element.attr(errorDetectAttr);
|
||||||
|
|
||||||
|
// default way, just replace the 'src' attribute
|
||||||
|
if( errorDetect !== "true" && errorDetect !== "1" ) {
|
||||||
|
// set iframe source
|
||||||
|
element.attr("src", element.attr(srcAttr));
|
||||||
|
|
||||||
|
// remove attributes
|
||||||
|
if( instance.config("removeAttribute") )
|
||||||
|
element.removeAttr(srcAttr + " " + errorDetectAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// extended way, even check if the document is available
|
||||||
|
else {
|
||||||
|
$.ajax({
|
||||||
|
url: element.attr(srcAttr),
|
||||||
|
dataType: "html",
|
||||||
|
crossDomain: true,
|
||||||
|
xhrFields: {withCredentials: true},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* success callback
|
||||||
|
* @access private
|
||||||
|
* @param {*} content
|
||||||
|
* @return {void}
|
||||||
|
*/
|
||||||
|
success: function(content) {
|
||||||
|
// set responded data to element's inner html
|
||||||
|
element.html(content)
|
||||||
|
|
||||||
|
// change iframe src
|
||||||
|
.attr("src", element.attr(srcAttr));
|
||||||
|
|
||||||
|
// remove attributes
|
||||||
|
if( instance.config("removeAttribute") )
|
||||||
|
element.removeAttr(srcAttr + " " + errorDetectAttr);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* error callback
|
||||||
|
* @access private
|
||||||
|
* @return {void}
|
||||||
|
*/
|
||||||
|
error: function() {
|
||||||
|
// pass error state to lazy
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
// pass error state to lazy
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})(window.jQuery || window.Zepto);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* jQuery & Zepto Lazy - NOOP Plugin - v1.2
|
||||||
|
* http://jquery.eisbehr.de/lazy/
|
||||||
|
*
|
||||||
|
* Copyright 2012 - 2017, Daniel 'Eisbehr' Kern
|
||||||
|
*
|
||||||
|
* Dual licensed under the MIT and GPL-2.0 licenses:
|
||||||
|
* http://www.opensource.org/licenses/mit-license.php
|
||||||
|
* http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
;(function($) {
|
||||||
|
// will do nothing, used to disable elements or for development
|
||||||
|
// use like:
|
||||||
|
// <div data-loader="noop"></div>
|
||||||
|
|
||||||
|
// does not do anything, just a 'no-operation' helper ;)
|
||||||
|
$.lazy("noop", function() {});
|
||||||
|
|
||||||
|
// does nothing, but response a successfull loading
|
||||||
|
$.lazy("noop-success", function(element, response) {
|
||||||
|
// use response function for Zepto
|
||||||
|
response(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
// does nothing, but response a failed loading
|
||||||
|
$.lazy("noop-error", function(element, response) {
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
});
|
||||||
|
})(window.jQuery || window.Zepto);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* jQuery & Zepto Lazy - Picture Plugin - v1.3
|
||||||
|
* http://jquery.eisbehr.de/lazy/
|
||||||
|
*
|
||||||
|
* Copyright 2012 - 2017, Daniel 'Eisbehr' Kern
|
||||||
|
*
|
||||||
|
* Dual licensed under the MIT and GPL-2.0 licenses:
|
||||||
|
* http://www.opensource.org/licenses/mit-license.php
|
||||||
|
* http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
;(function($) {
|
||||||
|
var srcAttr = "data-src",
|
||||||
|
srcsetAttr = "data-srcset",
|
||||||
|
mediaAttr = "data-media",
|
||||||
|
sizesAttr = "data-sizes",
|
||||||
|
typeAttr = "data-type";
|
||||||
|
|
||||||
|
// loads picture elements like:
|
||||||
|
// <picture>
|
||||||
|
// <data-src srcset="1x.jpg 1x, 2x.jpg 2x, 3x.jpg 3x" media="(min-width: 600px)" type="image/jpeg"></data-src>
|
||||||
|
// <data-src srcset="1x.jpg 1x, 2x.jpg 2x, 3x.jpg 3x" media="(min-width: 400px)" type="image/jpeg"></data-src>
|
||||||
|
// <data-img src="default.jpg" >
|
||||||
|
// </picture>
|
||||||
|
//
|
||||||
|
// or:
|
||||||
|
// <picture data-src="default.jpg">
|
||||||
|
// <data-src srcset="1x.jpg 1x, 2x.jpg 2x, 3x.jpg 3x" media="(min-width: 600px)" type="image/jpeg"></data-src>
|
||||||
|
// <data-src srcset="1x.jpg 1x, 2x.jpg 2x, 3x.jpg 3x" media="(min-width: 400px)" type="image/jpeg"></data-src>
|
||||||
|
// </picture>
|
||||||
|
//
|
||||||
|
// or just with attributes in one line:
|
||||||
|
// <picture data-src="default.jpg" data-srcset="1x.jpg 1x, 2x.jpg 2x, 3x.jpg 3x" data-media="(min-width: 600px)" data-sizes="" data-type="image/jpeg" />
|
||||||
|
$.lazy(["pic", "picture"], ["picture"], function(element, response) {
|
||||||
|
var elementTagName = element[0].tagName.toLowerCase();
|
||||||
|
|
||||||
|
if( elementTagName === "picture" ) {
|
||||||
|
var sources = element.find(srcAttr),
|
||||||
|
image = element.find("data-img"),
|
||||||
|
imageBase = this.config("imageBase") || "";
|
||||||
|
|
||||||
|
// handle as child elements
|
||||||
|
if( sources.length ) {
|
||||||
|
sources.each(function() {
|
||||||
|
renameElementTag($(this), "source", imageBase);
|
||||||
|
});
|
||||||
|
|
||||||
|
// create img tag from child
|
||||||
|
if( image.length === 1 ) {
|
||||||
|
image = renameElementTag(image, "img", imageBase);
|
||||||
|
|
||||||
|
// bind event callbacks to new image tag
|
||||||
|
image.on("load", function() {
|
||||||
|
response(true);
|
||||||
|
}).on("error", function() {
|
||||||
|
response(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
image.attr("src", image.attr(srcAttr));
|
||||||
|
|
||||||
|
if( this.config("removeAttribute") ) {
|
||||||
|
image.removeAttr(srcAttr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// create img tag from attribute
|
||||||
|
else if( element.attr(srcAttr) ) {
|
||||||
|
// create image tag
|
||||||
|
createImageObject(element, imageBase + element.attr(srcAttr), response);
|
||||||
|
|
||||||
|
if( this.config("removeAttribute") )
|
||||||
|
element.removeAttr(srcAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// pass error state
|
||||||
|
else {
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle as attributes
|
||||||
|
else if( element.attr(srcsetAttr) ) {
|
||||||
|
// create source elements before img tag
|
||||||
|
$("<source>").attr({
|
||||||
|
media: element.attr(mediaAttr),
|
||||||
|
sizes: element.attr(sizesAttr),
|
||||||
|
type: element.attr(typeAttr),
|
||||||
|
srcset: getCorrectedSrcSet(element.attr(srcsetAttr), imageBase)
|
||||||
|
})
|
||||||
|
.appendTo(element);
|
||||||
|
|
||||||
|
// create image tag
|
||||||
|
createImageObject(element, imageBase + element.attr(srcAttr), response);
|
||||||
|
|
||||||
|
// remove attributes from parent picture element
|
||||||
|
if( this.config("removeAttribute") ) {
|
||||||
|
element.removeAttr(srcAttr + " " + srcsetAttr + " " + mediaAttr + " " + sizesAttr + " " + typeAttr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// pass error state
|
||||||
|
else {
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
// pass error state
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create a new child element and copy attributes
|
||||||
|
* @param {jQuery|object} element
|
||||||
|
* @param {string} toType
|
||||||
|
* @param {string} imageBase
|
||||||
|
* @return {jQuery|object}
|
||||||
|
*/
|
||||||
|
function renameElementTag(element, toType, imageBase) {
|
||||||
|
var attributes = element.prop("attributes"),
|
||||||
|
target = $("<" + toType + ">");
|
||||||
|
|
||||||
|
$.each(attributes, function(index, attribute) {
|
||||||
|
// build srcset with image base
|
||||||
|
if( attribute.name === "srcset" || attribute.name === srcAttr ) {
|
||||||
|
attribute.value = getCorrectedSrcSet(attribute.value, imageBase);
|
||||||
|
}
|
||||||
|
|
||||||
|
target.attr(attribute.name, attribute.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
element.replaceWith(target);
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create a new image element inside parent element
|
||||||
|
* @param {jQuery|object} parent
|
||||||
|
* @param {string} src
|
||||||
|
* @param {function} response
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function createImageObject(parent, src, response) {
|
||||||
|
// create image tag
|
||||||
|
var imageObj = $("<img>")
|
||||||
|
|
||||||
|
// create image tag an bind callbacks for correct response
|
||||||
|
.one("load", function() {
|
||||||
|
response(true);
|
||||||
|
})
|
||||||
|
.one("error", function() {
|
||||||
|
response(false);
|
||||||
|
})
|
||||||
|
|
||||||
|
// set into picture element
|
||||||
|
.appendTo(parent)
|
||||||
|
|
||||||
|
// set src attribute at last to prevent early kick-in
|
||||||
|
.attr("src", src);
|
||||||
|
|
||||||
|
// call after load even on cached image
|
||||||
|
imageObj.complete && imageObj.load(); // jshint ignore : line
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* prepend image base to all srcset entries
|
||||||
|
* @param {string} srcset
|
||||||
|
* @param {string} imageBase
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
function getCorrectedSrcSet(srcset, imageBase) {
|
||||||
|
if( imageBase ) {
|
||||||
|
// trim, remove unnecessary spaces and split entries
|
||||||
|
var entries = srcset.split(",");
|
||||||
|
srcset = "";
|
||||||
|
|
||||||
|
for( var i = 0, l = entries.length; i < l; i++ ) {
|
||||||
|
srcset += imageBase + entries[i].trim() + (i !== l - 1 ? "," : "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return srcset;
|
||||||
|
}
|
||||||
|
})(window.jQuery || window.Zepto);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* jQuery & Zepto Lazy - Script Plugin - v1.2
|
||||||
|
* http://jquery.eisbehr.de/lazy/
|
||||||
|
*
|
||||||
|
* Copyright 2012 - 2017, Daniel 'Eisbehr' Kern
|
||||||
|
*
|
||||||
|
* Dual licensed under the MIT and GPL-2.0 licenses:
|
||||||
|
* http://www.opensource.org/licenses/mit-license.php
|
||||||
|
* http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
;(function($) {
|
||||||
|
// loads javascript files for script tags, like:
|
||||||
|
// <script data-src="file.js" type="text/javascript"></script>
|
||||||
|
$.lazy(["js", "javascript", "script"], "script", function(element, response) {
|
||||||
|
if( element[0].tagName.toLowerCase() == "script" ) {
|
||||||
|
element.attr("src", element.attr("data-src"));
|
||||||
|
|
||||||
|
// remove attribute
|
||||||
|
if( this.config("removeAttribute") )
|
||||||
|
element.removeAttr("data-src");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})(window.jQuery || window.Zepto);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* jQuery & Zepto Lazy - Vimeo Plugin - v1.1
|
||||||
|
* http://jquery.eisbehr.de/lazy/
|
||||||
|
*
|
||||||
|
* Copyright 2012 - 2017, Daniel 'Eisbehr' Kern
|
||||||
|
*
|
||||||
|
* Dual licensed under the MIT and GPL-2.0 licenses:
|
||||||
|
* http://www.opensource.org/licenses/mit-license.php
|
||||||
|
* http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
;(function($) {
|
||||||
|
// load vimeo video iframe, like:
|
||||||
|
// <iframe data-loader="vimeo" data-src="176894130" width="640" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
|
||||||
|
$.lazy("vimeo", function(element, response) {
|
||||||
|
if( element[0].tagName.toLowerCase() === "iframe" ) {
|
||||||
|
// pass source to iframe
|
||||||
|
element.attr("src", "https://player.vimeo.com/video/" + element.attr("data-src"));
|
||||||
|
|
||||||
|
// remove attribute
|
||||||
|
if( this.config("removeAttribute") )
|
||||||
|
element.removeAttr("data-src");
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
// pass error state
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})(window.jQuery || window.Zepto);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* jQuery & Zepto Lazy - YouTube Plugin - v1.4
|
||||||
|
* http://jquery.eisbehr.de/lazy/
|
||||||
|
*
|
||||||
|
* Copyright 2012 - 2017, Daniel 'Eisbehr' Kern
|
||||||
|
*
|
||||||
|
* Dual licensed under the MIT and GPL-2.0 licenses:
|
||||||
|
* http://www.opensource.org/licenses/mit-license.php
|
||||||
|
* http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
;(function($) {
|
||||||
|
// load youtube video iframe, like:
|
||||||
|
// <iframe data-loader="yt" data-src="1AYGnw6MwFM" width="560" height="315" frameborder="0" allowfullscreen></iframe>
|
||||||
|
$.lazy(["yt", "youtube"], function(element, response) {
|
||||||
|
if( element[0].tagName.toLowerCase() === "iframe" ) {
|
||||||
|
// pass source to iframe
|
||||||
|
element.attr("src", "https://www.youtube.com/embed/" + element.attr("data-src") + "?rel=0&showinfo=0");
|
||||||
|
|
||||||
|
// remove attribute
|
||||||
|
if( this.config("removeAttribute") )
|
||||||
|
element.removeAttr("data-src");
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
// pass error state
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})(window.jQuery || window.Zepto);
|
2
view/js/jquery.lazy/jquery.lazy.plugins.min.js
vendored
Normal file
2
view/js/jquery.lazy/jquery.lazy.plugins.min.js
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/*! jQuery & Zepto Lazy - All Plugins v1.7.7 - http://jquery.eisbehr.de/lazy - MIT&GPL-2.0 license - Copyright 2012-2017 Daniel 'Eisbehr' Kern */
|
||||||
|
!function(t){function a(a,e,r,o){t.ajax({url:e.attr("data-src"),type:o||"get",dataType:e.attr("data-type")||"html",success:function(t){e.html(t),r(!0),a.config("removeAttribute")&&e.removeAttr("data-src data-method data-type")},error:function(){r(!1)}})}t.lazy("ajax",function(t,e){a(this,t,e,t.attr("data-method"))}),t.lazy("get",function(t,e){a(this,t,e,"get")}),t.lazy("post",function(t,e){a(this,t,e,"post")})}(window.jQuery||window.Zepto),function(t){t.lazy(["av","audio","video"],["audio","video"],function(a,e){var r=a[0].tagName.toLowerCase();if("audio"===r||"video"===r){var o=a.find("data-src"),i=a.find("data-track"),n=0,c=function(){++n===o.length&&e(!1)},s=function(){var a=t(this),e=a[0].tagName.toLowerCase(),r=a.prop("attributes"),o=t("data-src"===e?"<source>":"<track>");"data-src"===e&&o.one("error",c),t.each(r,function(t,a){o.attr(a.name,a.value)}),a.replaceWith(o)};a.one("loadedmetadata",function(){e(!0)}).off("load error").attr("poster",a.attr("data-poster")),o.length?o.each(s):a.attr("data-src")?(t.each(a.attr("data-src").split(","),function(e,r){var o=r.split("|");a.append(t("<source>").one("error",c).attr({src:o[0].trim(),type:o[1].trim()}))}),this.config("removeAttribute")&&a.removeAttr("data-src")):e(!1),i.length&&i.each(s)}else e(!1)})}(window.jQuery||window.Zepto),function(t){t.lazy(["frame","iframe"],"iframe",function(a,e){var r=this;if("iframe"===a[0].tagName.toLowerCase()){var o=a.attr("data-error-detect");"true"!==o&&"1"!==o?(a.attr("src",a.attr("data-src")),r.config("removeAttribute")&&a.removeAttr("data-src data-error-detect")):t.ajax({url:a.attr("data-src"),dataType:"html",crossDomain:!0,xhrFields:{withCredentials:!0},success:function(t){a.html(t).attr("src",a.attr("data-src")),r.config("removeAttribute")&&a.removeAttr("data-src data-error-detect")},error:function(){e(!1)}})}else e(!1)})}(window.jQuery||window.Zepto),function(t){t.lazy("noop",function(){}),t.lazy("noop-success",function(t,a){a(!0)}),t.lazy("noop-error",function(t,a){a(!1)})}(window.jQuery||window.Zepto),function(t){function a(a,e,i){var n=a.prop("attributes"),c=t("<"+e+">");return t.each(n,function(t,a){"srcset"!==a.name&&a.name!==o||(a.value=r(a.value,i)),c.attr(a.name,a.value)}),a.replaceWith(c),c}function e(a,e,r){var o=t("<img>").one("load",function(){r(!0)}).one("error",function(){r(!1)}).appendTo(a).attr("src",e);o.complete&&o.load()}function r(t,a){if(a){var e=t.split(",");t="";for(var r=0,o=e.length;r<o;r++)t+=a+e[r].trim()+(r!==o-1?",":"")}return t}var o="data-src";t.lazy(["pic","picture"],["picture"],function(i,n){if("picture"===i[0].tagName.toLowerCase()){var c=i.find(o),s=i.find("data-img"),d=this.config("imageBase")||"";c.length?(c.each(function(){a(t(this),"source",d)}),1===s.length?(s=a(s,"img",d),s.on("load",function(){n(!0)}).on("error",function(){n(!1)}),s.attr("src",s.attr(o)),this.config("removeAttribute")&&s.removeAttr(o)):i.attr(o)?(e(i,d+i.attr(o),n),this.config("removeAttribute")&&i.removeAttr(o)):n(!1)):i.attr("data-srcset")?(t("<source>").attr({media:i.attr("data-media"),sizes:i.attr("data-sizes"),type:i.attr("data-type"),srcset:r(i.attr("data-srcset"),d)}).appendTo(i),e(i,d+i.attr(o),n),this.config("removeAttribute")&&i.removeAttr(o+" data-srcset data-media data-sizes data-type")):n(!1)}else n(!1)})}(window.jQuery||window.Zepto),function(t){t.lazy(["js","javascript","script"],"script",function(t,a){"script"==t[0].tagName.toLowerCase()?(t.attr("src",t.attr("data-src")),this.config("removeAttribute")&&t.removeAttr("data-src")):a(!1)})}(window.jQuery||window.Zepto),function(t){t.lazy("vimeo",function(t,a){"iframe"===t[0].tagName.toLowerCase()?(t.attr("src","https://player.vimeo.com/video/"+t.attr("data-src")),this.config("removeAttribute")&&t.removeAttr("data-src")):a(!1)})}(window.jQuery||window.Zepto),function(t){t.lazy(["yt","youtube"],function(t,a){"iframe"===t[0].tagName.toLowerCase()?(t.attr("src","https://www.youtube.com/embed/"+t.attr("data-src")+"?rel=0&showinfo=0"),this.config("removeAttribute")&&t.removeAttr("data-src")):a(!1)})}(window.jQuery||window.Zepto);
|
68
view/js/jquery.lazy/package.json
Normal file
68
view/js/jquery.lazy/package.json
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
{
|
||||||
|
"name": "jquery-lazy",
|
||||||
|
"title": "jQuery & Zepto Lazy - Delayed Content, Image and Background Loader",
|
||||||
|
"version": "1.7.7",
|
||||||
|
"description": "Lazy is a fast, feature-rich and lightweight delayed content loading plugin for jQuery and Zepto. It's designed to speed up page loading times and decrease traffic to your users by only loading the content in view.",
|
||||||
|
"main": "jquery.lazy.js",
|
||||||
|
"homepage": "http://jquery.eisbehr.de/lazy",
|
||||||
|
"bugs": "http://github.com/eisbehr-/jquery.lazy/issues",
|
||||||
|
"author": {
|
||||||
|
"name": "Daniel 'Eisbehr' Kern",
|
||||||
|
"email": "jquery@eisbehr.de",
|
||||||
|
"url": "http://eisbehr.de/"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git@github.com:eisbehr-/jquery.lazy.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"lazy",
|
||||||
|
"lazyload",
|
||||||
|
"load",
|
||||||
|
"loader",
|
||||||
|
"image",
|
||||||
|
"images",
|
||||||
|
"background",
|
||||||
|
"content",
|
||||||
|
"speed",
|
||||||
|
"delay",
|
||||||
|
"delayed",
|
||||||
|
"pageload",
|
||||||
|
"performance",
|
||||||
|
"retina",
|
||||||
|
"placeholder",
|
||||||
|
"jquery",
|
||||||
|
"jquery-plugin",
|
||||||
|
"zepto",
|
||||||
|
"zepto-plugin"
|
||||||
|
],
|
||||||
|
"licenses": [{
|
||||||
|
"type": "MIT",
|
||||||
|
"url": "http://www.opensource.org/licenses/mit-license.php"
|
||||||
|
},{
|
||||||
|
"type": "GPL-2.0",
|
||||||
|
"url": "http://www.gnu.org/licenses/gpl-2.0.html"
|
||||||
|
}],
|
||||||
|
"dependencies": {
|
||||||
|
"jquery": ">=1.7.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"gulp": "^3.9.1",
|
||||||
|
"gulp-concat-util": "^0.5.5",
|
||||||
|
"gulp-data": "^1.2.1",
|
||||||
|
"gulp-header": "^1.8.9",
|
||||||
|
"gulp-jshint": "^2.0.4",
|
||||||
|
"gulp-noop": "^1.0.0",
|
||||||
|
"gulp-rename": "^1.2.2",
|
||||||
|
"gulp-uglify": "^2.1.2",
|
||||||
|
"gulp-util": "^3.0.8",
|
||||||
|
"jshint": "^2.9.5",
|
||||||
|
"jshint-stylish": "^2.2.1"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"validate": "gulp validate",
|
||||||
|
"start": "gulp watch",
|
||||||
|
"watch": "gulp watch",
|
||||||
|
"build": "gulp build"
|
||||||
|
}
|
||||||
|
}
|
299
view/js/jquery.lazy/plugins/README.md
Normal file
299
view/js/jquery.lazy/plugins/README.md
Normal file
|
@ -0,0 +1,299 @@
|
||||||
|
### jQuery Lazy - Loader Plugins
|
||||||
|
[](http://github.com/eisbehr-/jquery.lazy)
|
||||||
|
[](http://www.npmjs.org/package/jquery-lazy)
|
||||||
|
[](http://bower.io/search/?q=jquery-lazy)
|
||||||
|
[](https://david-dm.org/eisbehr-/jquery.lazy)
|
||||||
|
[](https://david-dm.org/eisbehr-/jquery.lazy?type=dev)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Table of Contents
|
||||||
|
* [Document Note](#document-note)
|
||||||
|
* [About Loader Plugins](#about-loader-plugins)
|
||||||
|
* [Create an own Loader Plugin](#create-an-own-loader-plugin)
|
||||||
|
* [AJAX Loader](#ajax-loader)
|
||||||
|
* [Audio / Video Loader](#audio--video-loader)
|
||||||
|
* [iFrame Loader](#iframe-loader)
|
||||||
|
* [NOOP Loader](#noop-loader)
|
||||||
|
* [Picture Loader](#picture-loader)
|
||||||
|
* [JS / Script Loader](#js--script-loader)
|
||||||
|
* [Vimeo Video Loader](#vimeo-video-loader)
|
||||||
|
* [YouTube Video Loader](#youtube-video-loader)
|
||||||
|
* [Bugs / Feature request](#bugs--feature-request)
|
||||||
|
* [License](#license)
|
||||||
|
* [Donation](#donation)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Document Note
|
||||||
|
This is not the main readme file of this project.
|
||||||
|
Please go to the [project root](https://github.com/eisbehr-/jquery.lazy) and take a look in the [README.md](https://github.com/eisbehr-/jquery.lazy/blob/master/README.md) to learn more about the basics of Lazy.
|
||||||
|
|
||||||
|
|
||||||
|
## About Loader Plugins
|
||||||
|
The loader plugins for Lazy can be used whenever you want to extend the basic functionality by default or globally for many instances of Lazy.
|
||||||
|
Just add the plugins you want to use or a combined file, containing all plugins, to your page and all instances can use the plugins from now on.
|
||||||
|
```HTML
|
||||||
|
<!-- as single plugin files -->
|
||||||
|
<script type="text/javascript" src="jquery.lazy.min.js"></script>
|
||||||
|
<script type="text/javascript" src="plugins/jquery.lazy.ajax.min.js"></script>
|
||||||
|
<script type="text/javascript" src="plugins/jquery.lazy.av.min.js"></script>
|
||||||
|
<script type="text/javascript" src="plugins/jquery.lazy.iframe.min.js"></script>
|
||||||
|
<script type="text/javascript" src="plugins/jquery.lazy.noop.min.js"></script>
|
||||||
|
<script type="text/javascript" src="plugins/jquery.lazy.picture.min.js"></script>
|
||||||
|
<script type="text/javascript" src="plugins/jquery.lazy.script.min.js"></script>
|
||||||
|
<script type="text/javascript" src="plugins/jquery.lazy.vimeo.min.js"></script>
|
||||||
|
<script type="text/javascript" src="plugins/jquery.lazy.youtube.min.js"></script>
|
||||||
|
|
||||||
|
<!-- or combined in one file -->
|
||||||
|
<script type="text/javascript" src="jquery.lazy.min.js"></script>
|
||||||
|
<script type="text/javascript" src="jquery.lazy.plugins.min.js"></script>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Create an own Loader Plugin
|
||||||
|
If you want to, you can easily create own loader plugins.
|
||||||
|
Just use jQuery or Zepto's public function `Lazy` to create and register them.
|
||||||
|
Best practice is to wrap everything by an [IIFE](https://en.wikipedia.org/wiki/Immediately-invoked_function_expression).
|
||||||
|
```JS
|
||||||
|
(function($) {
|
||||||
|
$.Lazy("pluginName", function(element, response) {
|
||||||
|
// add your logic here
|
||||||
|
|
||||||
|
// 'this' is the current instance of Lazy
|
||||||
|
// so it's possible to access all public functions, like:
|
||||||
|
var imageBase = this.config("imageBase");
|
||||||
|
});
|
||||||
|
})(window.jQuery || window.Zepto);
|
||||||
|
```
|
||||||
|
|
||||||
|
This loader can now be called on every element with the attribute `data-loader` (_by default_), like:
|
||||||
|
```HTML
|
||||||
|
<div data-loader="pluginName"></div>
|
||||||
|
```
|
||||||
|
|
||||||
|
It's possible to register a plugin with more than one name / alias.
|
||||||
|
```JS
|
||||||
|
(function($) {
|
||||||
|
$.Lazy(["pluginName", "anotherPluginName"], function(element, response) {
|
||||||
|
// the plugin is now available by 'data-loader="pluginLoaderName"'
|
||||||
|
// and 'data-loader="anotherLoaderName"'
|
||||||
|
});
|
||||||
|
})(window.jQuery || window.Zepto);
|
||||||
|
```
|
||||||
|
|
||||||
|
The optional second parameter gives you the ability to register a plugin by default to an element type.
|
||||||
|
When you do this, there is no need to set the `data-loader` attribute on each element you want to use this loader on.
|
||||||
|
|
||||||
|
But keep in mind, if you register an plugin on often used elements, like `<div>`, Lazy will try to handle each of them!
|
||||||
|
If you want to do so anyway, use a most specific selector for jQuery or Zepto.
|
||||||
|
```JS
|
||||||
|
(function($) {
|
||||||
|
$.Lazy("av", ["audio", "video"], function(element, response) {
|
||||||
|
// this plugin will automatically handle '<audio>' and '<video>' elements,
|
||||||
|
// even when no 'data-loader' attribute was set on the elements
|
||||||
|
});
|
||||||
|
})(window.jQuery || window.Zepto);
|
||||||
|
```
|
||||||
|
|
||||||
|
For more examples, take a look at the [existing plugins](https://github.com/eisbehr-/jquery.lazy/tree/master/plugins).
|
||||||
|
|
||||||
|
|
||||||
|
## AJAX Loader
|
||||||
|
**Names:** `ajax`, `get`, `post`
|
||||||
|
**Parameters:** `data-src`, `data-method`, `data-type`
|
||||||
|
**Default for:** -
|
||||||
|
|
||||||
|
The AJAX loader can receive data from a given url and paste the response to the inner html of the element.
|
||||||
|
This is useful, when you want do load a bigger amount of content.
|
||||||
|
Use `ajax` as the loader name by default.
|
||||||
|
But there are even some shorthand names for specific request types `GET` and `POST` too.
|
||||||
|
```HTML
|
||||||
|
<!-- simple GET request -->
|
||||||
|
<div data-loader="ajax" data-src="ajax.html"></div>
|
||||||
|
|
||||||
|
<!-- simple post request with configurable response type -->
|
||||||
|
<div data-loader="ajax" data-src="ajax.html" data-method="post" data-type="html"></div>
|
||||||
|
|
||||||
|
<!-- GET request -->
|
||||||
|
<div data-loader="get" data-src="ajax.html"></div>
|
||||||
|
|
||||||
|
<!-- POST request-->
|
||||||
|
<div data-loader="post" data-src="ajax.html"></div>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Audio / Video Loader
|
||||||
|
**Names:** `av`, `audio`, `video`
|
||||||
|
**Parameters:** `data-src`, `data-poster`
|
||||||
|
**Default for:** `<audio>`, `<video>`
|
||||||
|
|
||||||
|
Loads `<audio>` and `<video>` elements and attach the sources and tracks in the right order.
|
||||||
|
There are two ways you can prepare your audio and/or video tags.
|
||||||
|
First way is to add all sources by `data-src` attribute, separated by comma and type by pipe on the element.
|
||||||
|
```HTML
|
||||||
|
<audio data-src="file.ogg|audio/ogg,file.mp3|audio/mp3,file.wav|audio/wav"></audio>
|
||||||
|
<video data-src="file.ogv|video/ogv,file.mp4|video/mp4,file.webm|video/webm" data-poster="poster.jpg"></video>
|
||||||
|
```
|
||||||
|
|
||||||
|
The other way is to add the sources and tracks like default, as child elements.
|
||||||
|
```HTML
|
||||||
|
<audio>
|
||||||
|
<data-src src="file.ogg" type="audio/ogg"></data-src>
|
||||||
|
<data-src src="file.mp3" type="audio/mp3"></data-src>
|
||||||
|
<data-src src="file.wav" type="audio/wav"></data-src>
|
||||||
|
</audio>
|
||||||
|
|
||||||
|
<video data-poster="poster.jpg">
|
||||||
|
<data-src src="file.ogv" type="video/ogv"></data-src>
|
||||||
|
<data-src src="file.mp4" type="video/mp4"></data-src>
|
||||||
|
<data-src src="file.webm" type="video/webm"></data-src>
|
||||||
|
<data-track kind="captions" src="captions.vtt" srclang="en"></data-track>
|
||||||
|
<data-track kind="descriptions" src="descriptions.vtt" srclang="en"></data-track>
|
||||||
|
<data-track kind="subtitles" src="subtitles.vtt" srclang="de"></data-track>
|
||||||
|
</video>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## iFrame Loader
|
||||||
|
**Names:** `frame`, `iframe`
|
||||||
|
**Parameters:** `data-src`, `data-error-detect`
|
||||||
|
**Default for:** `<iframe>`
|
||||||
|
|
||||||
|
Loads `<iframe>` contents.
|
||||||
|
The default will return a successfull load, even if the iframe url is not reachable (_like on 404 or wrong url_), because there is no way to check the loaded content in javascript.
|
||||||
|
It might be the fastest and safest way to do that.
|
||||||
|
If you know the requested path is reachable every time or don't care about error checks, you should use this way!
|
||||||
|
```HTML
|
||||||
|
<iframe data-src="iframe.html"></iframe>
|
||||||
|
```
|
||||||
|
|
||||||
|
The second way is more professional and support error checks.
|
||||||
|
It will load the content by AJAX and checks the response.
|
||||||
|
Afterwards pass the HTML content to iframe inner and set the correct url.
|
||||||
|
This is a very secure check, but could be a bit more tricky on some use cases.
|
||||||
|
You should only use this on the same domain origin.
|
||||||
|
|
||||||
|
To enable this feature, set the attribute `data-error-detect` to `true` or `1` on the iframe element.
|
||||||
|
```HTML
|
||||||
|
<iframe data-loader="iframe" data-src="iframe.html" data-error-detect="true"></iframe>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## NOOP Loader
|
||||||
|
**Names:** `noop`, `noop-success`, `noop-error`
|
||||||
|
**Parameters:** -
|
||||||
|
**Default for:** -
|
||||||
|
|
||||||
|
The NOOP (_or no-operations_) loader will, like the name said, do nothing.
|
||||||
|
There will even be no callbacks triggered, like `beforeLoad` or `onError`, when using a NOOP` loader.
|
||||||
|
It could be useful for developers or to simple, secure and fast disable some other loaders.
|
||||||
|
It can be used with all elements.
|
||||||
|
```HTML
|
||||||
|
<div data-loader="noop"></div>
|
||||||
|
```
|
||||||
|
|
||||||
|
There are two other NOOP loaders, helping to debug your code.
|
||||||
|
The `noop-success` and `noop-error` loaders will return the current state to Lazy and trigger the right callbacks.
|
||||||
|
```HTML
|
||||||
|
<!-- triggers the 'afterLoad' and 'onFinishedAll' callback -->
|
||||||
|
<div data-loader="noop-success"></div>
|
||||||
|
|
||||||
|
<!-- triggers the 'onError' and 'onFinishedAll' callback -->
|
||||||
|
<div data-loader="noop-error"></div>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Picture Loader
|
||||||
|
**Names:** `pic`, `picture`
|
||||||
|
**Parameters:** `data-src`, `data-srcset`, `data-media`, `data-sizes`
|
||||||
|
**Default for:** `<picture>`
|
||||||
|
|
||||||
|
Loads `<picture>` elements and attach the sources.
|
||||||
|
There are two ways you can prepare your picture tags.
|
||||||
|
First way is to create all child elements from a single line:
|
||||||
|
```HTML
|
||||||
|
<picture data-src="default.jpg" data-srcset="1x.jpg 1x, 2x.jpg 2x, 3x.jpg 3x" data-media="(min-width: 600px)" data-type="image/jpeg" />
|
||||||
|
```
|
||||||
|
|
||||||
|
The other way is to add the sources like default, as child elements.
|
||||||
|
```HTML
|
||||||
|
<picture>
|
||||||
|
<data-src srcset="1x.jpg 1x, 2x.jpg 2x, 3x.jpg 3x" media="(min-width: 600px)" type="image/jpeg"></data-src>
|
||||||
|
<data-img src="default.jpg"></data-img>
|
||||||
|
</picture>
|
||||||
|
|
||||||
|
<picture data-src="default.jpg">
|
||||||
|
<data-src srcset="1x.jpg 1x, 2x.jpg 2x, 3x.jpg 3x" media="(min-width: 600px)" type="image/jpeg"></data-src>
|
||||||
|
</picture>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## JS / Script Loader
|
||||||
|
**Names:** `js`, `javascript`, `script`
|
||||||
|
**Parameters:** `data-src`
|
||||||
|
**Default for:** `<script>`
|
||||||
|
|
||||||
|
Loads javascript files on `<script>` element.
|
||||||
|
Change the element like the example below, and the files will be loaded automatically after page load.
|
||||||
|
```HTML
|
||||||
|
<script data-src="script.js" type="text/javascript"></script>
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note:**
|
||||||
|
The viewport detection is not correct in some browsers.
|
||||||
|
So it could happen, that all script files get loaded right after page load, and not when the user scrolls to them.
|
||||||
|
|
||||||
|
|
||||||
|
## Vimeo Video Loader
|
||||||
|
**Names:** `vimeo`
|
||||||
|
**Parameters:** `data-src`
|
||||||
|
**Default for:** -
|
||||||
|
|
||||||
|
Loads vimeo videos in an `<iframe>`.
|
||||||
|
This is the suggested way by vimeo itself.
|
||||||
|
You can prepare the `<iframe>` element as you would do without Lazy.
|
||||||
|
Only add the vimeo video id to the attribute `data-src` and add the loader name.
|
||||||
|
That's all.
|
||||||
|
```HTML
|
||||||
|
<iframe data-loader="vimeo" data-src="176894130" width="640" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
|
||||||
|
```
|
||||||
|
|
||||||
|
**Please keep in mind:**
|
||||||
|
Because this is an iframe and there is no feedback javascript could check on, this loader can only return success to Lazy.
|
||||||
|
There is no way to check if the video was loaded correctly or your provided video id is existing.
|
||||||
|
|
||||||
|
|
||||||
|
## YouTube Video Loader
|
||||||
|
**Names:** `yt`, `youtube`
|
||||||
|
**Parameters:** `data-src`
|
||||||
|
**Default for:** -
|
||||||
|
|
||||||
|
Loads youtube videos in an `<iframe>`.
|
||||||
|
This is the suggested way by youtube itself.
|
||||||
|
You can prepare the `<iframe>` element as you would do without Lazy.
|
||||||
|
Only add the youtube video id to the attribute `data-src` and add the loader name.
|
||||||
|
That's all.
|
||||||
|
```HTML
|
||||||
|
<iframe data-loader="youtube" data-src="1AYGnw6MwFM" width="560" height="315" frameborder="0"></iframe>
|
||||||
|
```
|
||||||
|
|
||||||
|
**Please keep in mind:**
|
||||||
|
Because this is an iframe and there is no feedback javascript could check on, this loader can only return success to Lazy.
|
||||||
|
There is no way to check if the video was loaded correctly or your provided video id is existing.
|
||||||
|
|
||||||
|
|
||||||
|
## Bugs / Feature request
|
||||||
|
Please [report](http://github.com/eisbehr-/jquery.lazy/issues) bugs and feel free to [ask](http://github.com/eisbehr-/jquery.lazy/issues) for new features and loaders directly on GitHub.
|
||||||
|
|
||||||
|
|
||||||
|
## License
|
||||||
|
Lazy plugins are dual-licensed under [MIT](http://www.opensource.org/licenses/mit-license.php) and [GPL-2.0](http://www.gnu.org/licenses/gpl-2.0.html) license.
|
||||||
|
|
||||||
|
|
||||||
|
## Donation
|
||||||
|
_You like to support me?_
|
||||||
|
_You appreciate my work?_
|
||||||
|
_You use it in commercial projects?_
|
||||||
|
|
||||||
|
Feel free to make a little [donation](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FFL6VQJCUZMXC)! :wink:
|
73
view/js/jquery.lazy/plugins/jquery.lazy.ajax.js
Normal file
73
view/js/jquery.lazy/plugins/jquery.lazy.ajax.js
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
/*!
|
||||||
|
* jQuery & Zepto Lazy - AJAX Plugin - v1.2
|
||||||
|
* http://jquery.eisbehr.de/lazy/
|
||||||
|
*
|
||||||
|
* Copyright 2012 - 2017, Daniel 'Eisbehr' Kern
|
||||||
|
*
|
||||||
|
* Dual licensed under the MIT and GPL-2.0 licenses:
|
||||||
|
* http://www.opensource.org/licenses/mit-license.php
|
||||||
|
* http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
;(function($) {
|
||||||
|
// load data by ajax request and pass them to elements inner html, like:
|
||||||
|
// <div data-loader="ajax" data-src"url.html" data-method="post" data-type="html"></div>
|
||||||
|
$.lazy("ajax", function(element, response) {
|
||||||
|
ajaxRequest(this, element, response, element.attr("data-method"));
|
||||||
|
});
|
||||||
|
|
||||||
|
// load data by ajax get request and pass them to elements inner html, like:
|
||||||
|
// <div data-loader="get" data-src"url.html" data-type="html"></div>
|
||||||
|
$.lazy("get", function(element, response) {
|
||||||
|
ajaxRequest(this, element, response, "get");
|
||||||
|
});
|
||||||
|
|
||||||
|
// load data by ajax post request and pass them to elements inner html, like:
|
||||||
|
// <div data-loader="post" data-src"url.html" data-type="html"></div>
|
||||||
|
$.lazy("post", function(element, response) {
|
||||||
|
ajaxRequest(this, element, response, "post");
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* execute ajax request and handle response
|
||||||
|
* @param {object} instance
|
||||||
|
* @param {jQuery|object} element
|
||||||
|
* @param {function} response
|
||||||
|
* @param {string} [method]
|
||||||
|
*/
|
||||||
|
function ajaxRequest(instance, element, response, method) {
|
||||||
|
$.ajax({
|
||||||
|
url: element.attr("data-src"),
|
||||||
|
type: method || "get",
|
||||||
|
dataType: element.attr("data-type") || "html",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* success callback
|
||||||
|
* @access private
|
||||||
|
* @param {*} content
|
||||||
|
* @return {void}
|
||||||
|
*/
|
||||||
|
success: function(content) {
|
||||||
|
// set responded data to element's inner html
|
||||||
|
element.html(content);
|
||||||
|
|
||||||
|
// use response function for Zepto
|
||||||
|
response(true);
|
||||||
|
|
||||||
|
// remove attributes
|
||||||
|
if( instance.config("removeAttribute") )
|
||||||
|
element.removeAttr("data-src data-method data-type");
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* error callback
|
||||||
|
* @access private
|
||||||
|
* @return {void}
|
||||||
|
*/
|
||||||
|
error: function() {
|
||||||
|
// pass error state to lazy
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})(window.jQuery || window.Zepto);
|
2
view/js/jquery.lazy/plugins/jquery.lazy.ajax.min.js
vendored
Normal file
2
view/js/jquery.lazy/plugins/jquery.lazy.ajax.min.js
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/*! jQuery & Zepto Lazy - AJAX Plugin v1.2 - http://jquery.eisbehr.de/lazy - MIT&GPL-2.0 license - Copyright 2012-2017 Daniel 'Eisbehr' Kern */
|
||||||
|
!function(t){function a(a,e,o,n){t.ajax({url:e.attr("data-src"),type:n||"get",dataType:e.attr("data-type")||"html",success:function(t){e.html(t),o(!0),a.config("removeAttribute")&&e.removeAttr("data-src data-method data-type")},error:function(){o(!1)}})}t.lazy("ajax",function(t,e){a(this,t,e,t.attr("data-method"))}),t.lazy("get",function(t,e){a(this,t,e,"get")}),t.lazy("post",function(t,e){a(this,t,e,"post")})}(window.jQuery||window.Zepto);
|
115
view/js/jquery.lazy/plugins/jquery.lazy.av.js
Normal file
115
view/js/jquery.lazy/plugins/jquery.lazy.av.js
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
/*!
|
||||||
|
* jQuery & Zepto Lazy - AV Plugin - v1.4
|
||||||
|
* http://jquery.eisbehr.de/lazy/
|
||||||
|
*
|
||||||
|
* Copyright 2012 - 2017, Daniel 'Eisbehr' Kern
|
||||||
|
*
|
||||||
|
* Dual licensed under the MIT and GPL-2.0 licenses:
|
||||||
|
* http://www.opensource.org/licenses/mit-license.php
|
||||||
|
* http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
;(function($) {
|
||||||
|
// loads audio and video tags including tracks by two ways, like:
|
||||||
|
// <audio>
|
||||||
|
// <data-src src="audio.ogg" type="video/ogg"></data-src>
|
||||||
|
// <data-src src="audio.mp3" type="video/mp3"></data-src>
|
||||||
|
// </audio>
|
||||||
|
// <video data-poster="poster.jpg">
|
||||||
|
// <data-src src="video.ogv" type="video/ogv"></data-src>
|
||||||
|
// <data-src src="video.webm" type="video/webm"></data-src>
|
||||||
|
// <data-src src="video.mp4" type="video/mp4"></data-src>
|
||||||
|
// <data-track kind="captions" src="captions.vtt" srclang="en"></data-track>
|
||||||
|
// <data-track kind="descriptions" src="descriptions.vtt" srclang="en"></data-track>
|
||||||
|
// <data-track kind="subtitles" src="subtitles.vtt" srclang="de"></data-track>
|
||||||
|
// </video>
|
||||||
|
//
|
||||||
|
// or:
|
||||||
|
// <audio data-src="audio.ogg|video/ogg,video.mp3|video/mp3"></video>
|
||||||
|
// <video data-poster="poster.jpg" data-src="video.ogv|video/ogv,video.webm|video/webm,video.mp4|video/mp4">
|
||||||
|
// <data-track kind="captions" src="captions.vtt" srclang="en"></data-track>
|
||||||
|
// <data-track kind="descriptions" src="descriptions.vtt" srclang="en"></data-track>
|
||||||
|
// <data-track kind="subtitles" src="subtitles.vtt" srclang="de"></data-track>
|
||||||
|
// </video>
|
||||||
|
$.lazy(["av", "audio", "video"], ["audio", "video"], function(element, response) {
|
||||||
|
var elementTagName = element[0].tagName.toLowerCase();
|
||||||
|
|
||||||
|
if( elementTagName === "audio" || elementTagName === "video" ) {
|
||||||
|
var srcAttr = "data-src",
|
||||||
|
sources = element.find(srcAttr),
|
||||||
|
tracks = element.find("data-track"),
|
||||||
|
sourcesInError = 0,
|
||||||
|
|
||||||
|
// create on error callback for sources
|
||||||
|
onError = function() {
|
||||||
|
if( ++sourcesInError === sources.length )
|
||||||
|
response(false);
|
||||||
|
},
|
||||||
|
|
||||||
|
// create callback to handle a source or track entry
|
||||||
|
handleSource = function() {
|
||||||
|
var source = $(this),
|
||||||
|
type = source[0].tagName.toLowerCase(),
|
||||||
|
attributes = source.prop("attributes"),
|
||||||
|
target = $(type === srcAttr ? "<source>" : "<track>");
|
||||||
|
|
||||||
|
if( type === srcAttr )
|
||||||
|
target.one("error", onError);
|
||||||
|
|
||||||
|
$.each(attributes, function(index, attribute) {
|
||||||
|
target.attr(attribute.name, attribute.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
source.replaceWith(target);
|
||||||
|
};
|
||||||
|
|
||||||
|
// create event for successfull load
|
||||||
|
element.one("loadedmetadata", function() {
|
||||||
|
response(true);
|
||||||
|
})
|
||||||
|
|
||||||
|
// remove default callbacks to ignore loading poster image
|
||||||
|
.off("load error")
|
||||||
|
|
||||||
|
// load poster image
|
||||||
|
.attr("poster", element.attr("data-poster"));
|
||||||
|
|
||||||
|
// load by child tags
|
||||||
|
if( sources.length )
|
||||||
|
sources.each(handleSource);
|
||||||
|
|
||||||
|
// load by attribute
|
||||||
|
else if( element.attr(srcAttr) ) {
|
||||||
|
// split for every entry by comma
|
||||||
|
$.each(element.attr(srcAttr).split(","), function(index, value) {
|
||||||
|
// split again for file and file type
|
||||||
|
var parts = value.split("|");
|
||||||
|
|
||||||
|
// create a source entry
|
||||||
|
element.append($("<source>")
|
||||||
|
.one("error", onError)
|
||||||
|
.attr({src: parts[0].trim(), type: parts[1].trim()}));
|
||||||
|
});
|
||||||
|
|
||||||
|
// remove now obsolete attribute
|
||||||
|
if( this.config("removeAttribute") )
|
||||||
|
element.removeAttr(srcAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
// pass error state
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// load optional tracks
|
||||||
|
if( tracks.length )
|
||||||
|
tracks.each(handleSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
// pass error state
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})(window.jQuery || window.Zepto);
|
2
view/js/jquery.lazy/plugins/jquery.lazy.av.min.js
vendored
Normal file
2
view/js/jquery.lazy/plugins/jquery.lazy.av.min.js
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/*! jQuery & Zepto Lazy - AV Plugin v1.4 - http://jquery.eisbehr.de/lazy - MIT&GPL-2.0 license - Copyright 2012-2017 Daniel 'Eisbehr' Kern */
|
||||||
|
!function(t){t.lazy(["av","audio","video"],["audio","video"],function(a,e){var r=a[0].tagName.toLowerCase();if("audio"===r||"video"===r){var o=a.find("data-src"),i=a.find("data-track"),n=0,c=function(){++n===o.length&&e(!1)},d=function(){var a=t(this),e=a[0].tagName.toLowerCase(),r=a.prop("attributes"),o=t("data-src"===e?"<source>":"<track>");"data-src"===e&&o.one("error",c),t.each(r,function(t,a){o.attr(a.name,a.value)}),a.replaceWith(o)};a.one("loadedmetadata",function(){e(!0)}).off("load error").attr("poster",a.attr("data-poster")),o.length?o.each(d):a.attr("data-src")?(t.each(a.attr("data-src").split(","),function(e,r){var o=r.split("|");a.append(t("<source>").one("error",c).attr({src:o[0].trim(),type:o[1].trim()}))}),this.config("removeAttribute")&&a.removeAttr("data-src")):e(!1),i.length&&i.each(d)}else e(!1)})}(window.jQuery||window.Zepto);
|
81
view/js/jquery.lazy/plugins/jquery.lazy.iframe.js
Normal file
81
view/js/jquery.lazy/plugins/jquery.lazy.iframe.js
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
/*!
|
||||||
|
* jQuery & Zepto Lazy - iFrame Plugin - v1.5
|
||||||
|
* http://jquery.eisbehr.de/lazy/
|
||||||
|
*
|
||||||
|
* Copyright 2012 - 2017, Daniel 'Eisbehr' Kern
|
||||||
|
*
|
||||||
|
* Dual licensed under the MIT and GPL-2.0 licenses:
|
||||||
|
* http://www.opensource.org/licenses/mit-license.php
|
||||||
|
* http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
;(function($) {
|
||||||
|
// load iframe content, like:
|
||||||
|
// <iframe data-src="iframe.html"></iframe>
|
||||||
|
//
|
||||||
|
// enable content error check with:
|
||||||
|
// <iframe data-src="iframe.html" data-error-detect="true"></iframe>
|
||||||
|
$.lazy(["frame", "iframe"], "iframe", function(element, response) {
|
||||||
|
var instance = this;
|
||||||
|
|
||||||
|
if( element[0].tagName.toLowerCase() === "iframe" ) {
|
||||||
|
var srcAttr = "data-src",
|
||||||
|
errorDetectAttr = "data-error-detect",
|
||||||
|
errorDetect = element.attr(errorDetectAttr);
|
||||||
|
|
||||||
|
// default way, just replace the 'src' attribute
|
||||||
|
if( errorDetect !== "true" && errorDetect !== "1" ) {
|
||||||
|
// set iframe source
|
||||||
|
element.attr("src", element.attr(srcAttr));
|
||||||
|
|
||||||
|
// remove attributes
|
||||||
|
if( instance.config("removeAttribute") )
|
||||||
|
element.removeAttr(srcAttr + " " + errorDetectAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// extended way, even check if the document is available
|
||||||
|
else {
|
||||||
|
$.ajax({
|
||||||
|
url: element.attr(srcAttr),
|
||||||
|
dataType: "html",
|
||||||
|
crossDomain: true,
|
||||||
|
xhrFields: {withCredentials: true},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* success callback
|
||||||
|
* @access private
|
||||||
|
* @param {*} content
|
||||||
|
* @return {void}
|
||||||
|
*/
|
||||||
|
success: function(content) {
|
||||||
|
// set responded data to element's inner html
|
||||||
|
element.html(content)
|
||||||
|
|
||||||
|
// change iframe src
|
||||||
|
.attr("src", element.attr(srcAttr));
|
||||||
|
|
||||||
|
// remove attributes
|
||||||
|
if( instance.config("removeAttribute") )
|
||||||
|
element.removeAttr(srcAttr + " " + errorDetectAttr);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* error callback
|
||||||
|
* @access private
|
||||||
|
* @return {void}
|
||||||
|
*/
|
||||||
|
error: function() {
|
||||||
|
// pass error state to lazy
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
// pass error state to lazy
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})(window.jQuery || window.Zepto);
|
2
view/js/jquery.lazy/plugins/jquery.lazy.iframe.min.js
vendored
Normal file
2
view/js/jquery.lazy/plugins/jquery.lazy.iframe.min.js
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/*! jQuery & Zepto Lazy - iFrame Plugin v1.5 - http://jquery.eisbehr.de/lazy - MIT&GPL-2.0 license - Copyright 2012-2017 Daniel 'Eisbehr' Kern */
|
||||||
|
!function(t){t.lazy(["frame","iframe"],"iframe",function(r,a){var e=this;if("iframe"===r[0].tagName.toLowerCase()){var o=r.attr("data-error-detect");"true"!==o&&"1"!==o?(r.attr("src",r.attr("data-src")),e.config("removeAttribute")&&r.removeAttr("data-src data-error-detect")):t.ajax({url:r.attr("data-src"),dataType:"html",crossDomain:!0,xhrFields:{withCredentials:!0},success:function(t){r.html(t).attr("src",r.attr("data-src")),e.config("removeAttribute")&&r.removeAttr("data-src data-error-detect")},error:function(){a(!1)}})}else a(!1)})}(window.jQuery||window.Zepto);
|
30
view/js/jquery.lazy/plugins/jquery.lazy.noop.js
Normal file
30
view/js/jquery.lazy/plugins/jquery.lazy.noop.js
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/*!
|
||||||
|
* jQuery & Zepto Lazy - NOOP Plugin - v1.2
|
||||||
|
* http://jquery.eisbehr.de/lazy/
|
||||||
|
*
|
||||||
|
* Copyright 2012 - 2017, Daniel 'Eisbehr' Kern
|
||||||
|
*
|
||||||
|
* Dual licensed under the MIT and GPL-2.0 licenses:
|
||||||
|
* http://www.opensource.org/licenses/mit-license.php
|
||||||
|
* http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
;(function($) {
|
||||||
|
// will do nothing, used to disable elements or for development
|
||||||
|
// use like:
|
||||||
|
// <div data-loader="noop"></div>
|
||||||
|
|
||||||
|
// does not do anything, just a 'no-operation' helper ;)
|
||||||
|
$.lazy("noop", function() {});
|
||||||
|
|
||||||
|
// does nothing, but response a successfull loading
|
||||||
|
$.lazy("noop-success", function(element, response) {
|
||||||
|
// use response function for Zepto
|
||||||
|
response(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
// does nothing, but response a failed loading
|
||||||
|
$.lazy("noop-error", function(element, response) {
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
});
|
||||||
|
})(window.jQuery || window.Zepto);
|
2
view/js/jquery.lazy/plugins/jquery.lazy.noop.min.js
vendored
Normal file
2
view/js/jquery.lazy/plugins/jquery.lazy.noop.min.js
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/*! jQuery & Zepto Lazy - NOOP Plugin v1.2 - http://jquery.eisbehr.de/lazy - MIT&GPL-2.0 license - Copyright 2012-2017 Daniel 'Eisbehr' Kern */
|
||||||
|
!function(o){o.lazy("noop",function(){}),o.lazy("noop-success",function(o,n){n(!0)}),o.lazy("noop-error",function(o,n){n(!1)})}(window.jQuery||window.Zepto);
|
187
view/js/jquery.lazy/plugins/jquery.lazy.picture.js
Normal file
187
view/js/jquery.lazy/plugins/jquery.lazy.picture.js
Normal file
|
@ -0,0 +1,187 @@
|
||||||
|
/*!
|
||||||
|
* jQuery & Zepto Lazy - Picture Plugin - v1.3
|
||||||
|
* http://jquery.eisbehr.de/lazy/
|
||||||
|
*
|
||||||
|
* Copyright 2012 - 2017, Daniel 'Eisbehr' Kern
|
||||||
|
*
|
||||||
|
* Dual licensed under the MIT and GPL-2.0 licenses:
|
||||||
|
* http://www.opensource.org/licenses/mit-license.php
|
||||||
|
* http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
;(function($) {
|
||||||
|
var srcAttr = "data-src",
|
||||||
|
srcsetAttr = "data-srcset",
|
||||||
|
mediaAttr = "data-media",
|
||||||
|
sizesAttr = "data-sizes",
|
||||||
|
typeAttr = "data-type";
|
||||||
|
|
||||||
|
// loads picture elements like:
|
||||||
|
// <picture>
|
||||||
|
// <data-src srcset="1x.jpg 1x, 2x.jpg 2x, 3x.jpg 3x" media="(min-width: 600px)" type="image/jpeg"></data-src>
|
||||||
|
// <data-src srcset="1x.jpg 1x, 2x.jpg 2x, 3x.jpg 3x" media="(min-width: 400px)" type="image/jpeg"></data-src>
|
||||||
|
// <data-img src="default.jpg" >
|
||||||
|
// </picture>
|
||||||
|
//
|
||||||
|
// or:
|
||||||
|
// <picture data-src="default.jpg">
|
||||||
|
// <data-src srcset="1x.jpg 1x, 2x.jpg 2x, 3x.jpg 3x" media="(min-width: 600px)" type="image/jpeg"></data-src>
|
||||||
|
// <data-src srcset="1x.jpg 1x, 2x.jpg 2x, 3x.jpg 3x" media="(min-width: 400px)" type="image/jpeg"></data-src>
|
||||||
|
// </picture>
|
||||||
|
//
|
||||||
|
// or just with attributes in one line:
|
||||||
|
// <picture data-src="default.jpg" data-srcset="1x.jpg 1x, 2x.jpg 2x, 3x.jpg 3x" data-media="(min-width: 600px)" data-sizes="" data-type="image/jpeg" />
|
||||||
|
$.lazy(["pic", "picture"], ["picture"], function(element, response) {
|
||||||
|
var elementTagName = element[0].tagName.toLowerCase();
|
||||||
|
|
||||||
|
if( elementTagName === "picture" ) {
|
||||||
|
var sources = element.find(srcAttr),
|
||||||
|
image = element.find("data-img"),
|
||||||
|
imageBase = this.config("imageBase") || "";
|
||||||
|
|
||||||
|
// handle as child elements
|
||||||
|
if( sources.length ) {
|
||||||
|
sources.each(function() {
|
||||||
|
renameElementTag($(this), "source", imageBase);
|
||||||
|
});
|
||||||
|
|
||||||
|
// create img tag from child
|
||||||
|
if( image.length === 1 ) {
|
||||||
|
image = renameElementTag(image, "img", imageBase);
|
||||||
|
|
||||||
|
// bind event callbacks to new image tag
|
||||||
|
image.on("load", function() {
|
||||||
|
response(true);
|
||||||
|
}).on("error", function() {
|
||||||
|
response(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
image.attr("src", image.attr(srcAttr));
|
||||||
|
|
||||||
|
if( this.config("removeAttribute") ) {
|
||||||
|
image.removeAttr(srcAttr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// create img tag from attribute
|
||||||
|
else if( element.attr(srcAttr) ) {
|
||||||
|
// create image tag
|
||||||
|
createImageObject(element, imageBase + element.attr(srcAttr), response);
|
||||||
|
|
||||||
|
if( this.config("removeAttribute") )
|
||||||
|
element.removeAttr(srcAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// pass error state
|
||||||
|
else {
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle as attributes
|
||||||
|
else if( element.attr(srcsetAttr) ) {
|
||||||
|
// create source elements before img tag
|
||||||
|
$("<source>").attr({
|
||||||
|
media: element.attr(mediaAttr),
|
||||||
|
sizes: element.attr(sizesAttr),
|
||||||
|
type: element.attr(typeAttr),
|
||||||
|
srcset: getCorrectedSrcSet(element.attr(srcsetAttr), imageBase)
|
||||||
|
})
|
||||||
|
.appendTo(element);
|
||||||
|
|
||||||
|
// create image tag
|
||||||
|
createImageObject(element, imageBase + element.attr(srcAttr), response);
|
||||||
|
|
||||||
|
// remove attributes from parent picture element
|
||||||
|
if( this.config("removeAttribute") ) {
|
||||||
|
element.removeAttr(srcAttr + " " + srcsetAttr + " " + mediaAttr + " " + sizesAttr + " " + typeAttr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// pass error state
|
||||||
|
else {
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
// pass error state
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create a new child element and copy attributes
|
||||||
|
* @param {jQuery|object} element
|
||||||
|
* @param {string} toType
|
||||||
|
* @param {string} imageBase
|
||||||
|
* @return {jQuery|object}
|
||||||
|
*/
|
||||||
|
function renameElementTag(element, toType, imageBase) {
|
||||||
|
var attributes = element.prop("attributes"),
|
||||||
|
target = $("<" + toType + ">");
|
||||||
|
|
||||||
|
$.each(attributes, function(index, attribute) {
|
||||||
|
// build srcset with image base
|
||||||
|
if( attribute.name === "srcset" || attribute.name === srcAttr ) {
|
||||||
|
attribute.value = getCorrectedSrcSet(attribute.value, imageBase);
|
||||||
|
}
|
||||||
|
|
||||||
|
target.attr(attribute.name, attribute.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
element.replaceWith(target);
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create a new image element inside parent element
|
||||||
|
* @param {jQuery|object} parent
|
||||||
|
* @param {string} src
|
||||||
|
* @param {function} response
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function createImageObject(parent, src, response) {
|
||||||
|
// create image tag
|
||||||
|
var imageObj = $("<img>")
|
||||||
|
|
||||||
|
// create image tag an bind callbacks for correct response
|
||||||
|
.one("load", function() {
|
||||||
|
response(true);
|
||||||
|
})
|
||||||
|
.one("error", function() {
|
||||||
|
response(false);
|
||||||
|
})
|
||||||
|
|
||||||
|
// set into picture element
|
||||||
|
.appendTo(parent)
|
||||||
|
|
||||||
|
// set src attribute at last to prevent early kick-in
|
||||||
|
.attr("src", src);
|
||||||
|
|
||||||
|
// call after load even on cached image
|
||||||
|
imageObj.complete && imageObj.load(); // jshint ignore : line
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* prepend image base to all srcset entries
|
||||||
|
* @param {string} srcset
|
||||||
|
* @param {string} imageBase
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
function getCorrectedSrcSet(srcset, imageBase) {
|
||||||
|
if( imageBase ) {
|
||||||
|
// trim, remove unnecessary spaces and split entries
|
||||||
|
var entries = srcset.split(",");
|
||||||
|
srcset = "";
|
||||||
|
|
||||||
|
for( var i = 0, l = entries.length; i < l; i++ ) {
|
||||||
|
srcset += imageBase + entries[i].trim() + (i !== l - 1 ? "," : "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return srcset;
|
||||||
|
}
|
||||||
|
})(window.jQuery || window.Zepto);
|
2
view/js/jquery.lazy/plugins/jquery.lazy.picture.min.js
vendored
Normal file
2
view/js/jquery.lazy/plugins/jquery.lazy.picture.min.js
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/*! jQuery & Zepto Lazy - Picture Plugin v1.3 - http://jquery.eisbehr.de/lazy - MIT&GPL-2.0 license - Copyright 2012-2017 Daniel 'Eisbehr' Kern */
|
||||||
|
!function(t){function e(e,a,n){var o=e.prop("attributes"),c=t("<"+a+">");return t.each(o,function(t,e){"srcset"!==e.name&&e.name!==i||(e.value=r(e.value,n)),c.attr(e.name,e.value)}),e.replaceWith(c),c}function a(e,a,r){var i=t("<img>").one("load",function(){r(!0)}).one("error",function(){r(!1)}).appendTo(e).attr("src",a);i.complete&&i.load()}function r(t,e){if(e){var a=t.split(",");t="";for(var r=0,i=a.length;r<i;r++)t+=e+a[r].trim()+(r!==i-1?",":"")}return t}var i="data-src";t.lazy(["pic","picture"],["picture"],function(n,o){if("picture"===n[0].tagName.toLowerCase()){var c=n.find(i),s=n.find("data-img"),u=this.config("imageBase")||"";c.length?(c.each(function(){e(t(this),"source",u)}),1===s.length?(s=e(s,"img",u),s.on("load",function(){o(!0)}).on("error",function(){o(!1)}),s.attr("src",s.attr(i)),this.config("removeAttribute")&&s.removeAttr(i)):n.attr(i)?(a(n,u+n.attr(i),o),this.config("removeAttribute")&&n.removeAttr(i)):o(!1)):n.attr("data-srcset")?(t("<source>").attr({media:n.attr("data-media"),sizes:n.attr("data-sizes"),type:n.attr("data-type"),srcset:r(n.attr("data-srcset"),u)}).appendTo(n),a(n,u+n.attr(i),o),this.config("removeAttribute")&&n.removeAttr(i+" data-srcset data-media data-sizes data-type")):o(!1)}else o(!1)})}(window.jQuery||window.Zepto);
|
27
view/js/jquery.lazy/plugins/jquery.lazy.script.js
Normal file
27
view/js/jquery.lazy/plugins/jquery.lazy.script.js
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/*!
|
||||||
|
* jQuery & Zepto Lazy - Script Plugin - v1.2
|
||||||
|
* http://jquery.eisbehr.de/lazy/
|
||||||
|
*
|
||||||
|
* Copyright 2012 - 2017, Daniel 'Eisbehr' Kern
|
||||||
|
*
|
||||||
|
* Dual licensed under the MIT and GPL-2.0 licenses:
|
||||||
|
* http://www.opensource.org/licenses/mit-license.php
|
||||||
|
* http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
;(function($) {
|
||||||
|
// loads javascript files for script tags, like:
|
||||||
|
// <script data-src="file.js" type="text/javascript"></script>
|
||||||
|
$.lazy(["js", "javascript", "script"], "script", function(element, response) {
|
||||||
|
if( element[0].tagName.toLowerCase() == "script" ) {
|
||||||
|
element.attr("src", element.attr("data-src"));
|
||||||
|
|
||||||
|
// remove attribute
|
||||||
|
if( this.config("removeAttribute") )
|
||||||
|
element.removeAttr("data-src");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})(window.jQuery || window.Zepto);
|
2
view/js/jquery.lazy/plugins/jquery.lazy.script.min.js
vendored
Normal file
2
view/js/jquery.lazy/plugins/jquery.lazy.script.min.js
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/*! jQuery & Zepto Lazy - Script Plugin v1.2 - http://jquery.eisbehr.de/lazy - MIT&GPL-2.0 license - Copyright 2012-2017 Daniel 'Eisbehr' Kern */
|
||||||
|
!function(t){t.lazy(["js","javascript","script"],"script",function(t,r){"script"==t[0].tagName.toLowerCase()?(t.attr("src",t.attr("data-src")),this.config("removeAttribute")&&t.removeAttr("data-src")):r(!1)})}(window.jQuery||window.Zepto);
|
30
view/js/jquery.lazy/plugins/jquery.lazy.vimeo.js
Normal file
30
view/js/jquery.lazy/plugins/jquery.lazy.vimeo.js
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/*!
|
||||||
|
* jQuery & Zepto Lazy - Vimeo Plugin - v1.1
|
||||||
|
* http://jquery.eisbehr.de/lazy/
|
||||||
|
*
|
||||||
|
* Copyright 2012 - 2017, Daniel 'Eisbehr' Kern
|
||||||
|
*
|
||||||
|
* Dual licensed under the MIT and GPL-2.0 licenses:
|
||||||
|
* http://www.opensource.org/licenses/mit-license.php
|
||||||
|
* http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
;(function($) {
|
||||||
|
// load vimeo video iframe, like:
|
||||||
|
// <iframe data-loader="vimeo" data-src="176894130" width="640" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
|
||||||
|
$.lazy("vimeo", function(element, response) {
|
||||||
|
if( element[0].tagName.toLowerCase() === "iframe" ) {
|
||||||
|
// pass source to iframe
|
||||||
|
element.attr("src", "https://player.vimeo.com/video/" + element.attr("data-src"));
|
||||||
|
|
||||||
|
// remove attribute
|
||||||
|
if( this.config("removeAttribute") )
|
||||||
|
element.removeAttr("data-src");
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
// pass error state
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})(window.jQuery || window.Zepto);
|
2
view/js/jquery.lazy/plugins/jquery.lazy.vimeo.min.js
vendored
Normal file
2
view/js/jquery.lazy/plugins/jquery.lazy.vimeo.min.js
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/*! jQuery & Zepto Lazy - Vimeo Plugin v1.1 - http://jquery.eisbehr.de/lazy - MIT&GPL-2.0 license - Copyright 2012-2017 Daniel 'Eisbehr' Kern */
|
||||||
|
!function(t){t.lazy("vimeo",function(t,e){"iframe"===t[0].tagName.toLowerCase()?(t.attr("src","https://player.vimeo.com/video/"+t.attr("data-src")),this.config("removeAttribute")&&t.removeAttr("data-src")):e(!1)})}(window.jQuery||window.Zepto);
|
30
view/js/jquery.lazy/plugins/jquery.lazy.youtube.js
Normal file
30
view/js/jquery.lazy/plugins/jquery.lazy.youtube.js
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/*!
|
||||||
|
* jQuery & Zepto Lazy - YouTube Plugin - v1.4
|
||||||
|
* http://jquery.eisbehr.de/lazy/
|
||||||
|
*
|
||||||
|
* Copyright 2012 - 2017, Daniel 'Eisbehr' Kern
|
||||||
|
*
|
||||||
|
* Dual licensed under the MIT and GPL-2.0 licenses:
|
||||||
|
* http://www.opensource.org/licenses/mit-license.php
|
||||||
|
* http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
;(function($) {
|
||||||
|
// load youtube video iframe, like:
|
||||||
|
// <iframe data-loader="yt" data-src="1AYGnw6MwFM" width="560" height="315" frameborder="0" allowfullscreen></iframe>
|
||||||
|
$.lazy(["yt", "youtube"], function(element, response) {
|
||||||
|
if( element[0].tagName.toLowerCase() === "iframe" ) {
|
||||||
|
// pass source to iframe
|
||||||
|
element.attr("src", "https://www.youtube.com/embed/" + element.attr("data-src") + "?rel=0&showinfo=0");
|
||||||
|
|
||||||
|
// remove attribute
|
||||||
|
if( this.config("removeAttribute") )
|
||||||
|
element.removeAttr("data-src");
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
// pass error state
|
||||||
|
// use response function for Zepto
|
||||||
|
response(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})(window.jQuery || window.Zepto);
|
2
view/js/jquery.lazy/plugins/jquery.lazy.youtube.min.js
vendored
Normal file
2
view/js/jquery.lazy/plugins/jquery.lazy.youtube.min.js
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/*! jQuery & Zepto Lazy - YouTube Plugin v1.4 - http://jquery.eisbehr.de/lazy - MIT&GPL-2.0 license - Copyright 2012-2017 Daniel 'Eisbehr' Kern */
|
||||||
|
!function(t){t.lazy(["yt","youtube"],function(t,e){"iframe"===t[0].tagName.toLowerCase()?(t.attr("src","https://www.youtube.com/embed/"+t.attr("data-src")+"?rel=0&showinfo=0"),this.config("removeAttribute")&&t.removeAttr("data-src")):e(!1)})}(window.jQuery||window.Zepto);
|
|
@ -55,20 +55,14 @@ $(document).ready(function () {
|
||||||
|
|
||||||
$(".thumbsImage").on("mouseenter", function () {
|
$(".thumbsImage").on("mouseenter", function () {
|
||||||
gifId = $(this).find(".thumbsGIF").attr('id');
|
gifId = $(this).find(".thumbsGIF").attr('id');
|
||||||
if(gifId!=undefined){
|
if (gifId != undefined) {
|
||||||
id = gifId.replace('thumbsGIF','');
|
id = gifId.replace('thumbsGIF', '');
|
||||||
$(this).find(".thumbsGIF").height($(this).find(".thumbsJPG").height());
|
$(this).find(".thumbsGIF").height($(this).find(".thumbsJPG").height());
|
||||||
$(this).find(".thumbsGIF").width($(this).find(".thumbsJPG").width());
|
$(this).find(".thumbsGIF").width($(this).find(".thumbsJPG").width());
|
||||||
|
|
||||||
/*
|
|
||||||
try {
|
try {
|
||||||
l1 = $('#thumbsJPG'+id).offset().left;
|
$(this).find(".thumbsGIF").lazy();
|
||||||
l2 = $('#thumbsJPG'+id).closest('.thumbsImage').offset().left;
|
} catch (e) {
|
||||||
left = l1-l2;
|
}
|
||||||
$(this).find(".thumbsGIF").css({"left": left});
|
|
||||||
} catch (e) {}
|
|
||||||
|
|
||||||
*/
|
|
||||||
$(this).find(".thumbsGIF").stop(true, true).fadeIn();
|
$(this).find(".thumbsGIF").stop(true, true).fadeIn();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -77,6 +71,13 @@ $(document).ready(function () {
|
||||||
$(this).find(".thumbsGIF").stop(true, true).fadeOut();
|
$(this).find(".thumbsGIF").stop(true, true).fadeOut();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$('.thumbsJPG, .thumbsGIF').lazy({
|
||||||
|
effect: 'fadeIn',
|
||||||
|
effectTime:500,
|
||||||
|
visibleOnly: true
|
||||||
|
});
|
||||||
|
|
||||||
mainVideoHeight = $('#videoContainer').innerHeight();
|
mainVideoHeight = $('#videoContainer').innerHeight();
|
||||||
$(window).resize(function () {
|
$(window).resize(function () {
|
||||||
mainVideoHeight = $('#videoContainer').innerHeight();
|
mainVideoHeight = $('#videoContainer').innerHeight();
|
||||||
|
@ -129,7 +130,7 @@ $(document).ready(function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function removeTracks(){
|
function removeTracks() {
|
||||||
var oldTracks = player.remoteTextTracks();
|
var oldTracks = player.remoteTextTracks();
|
||||||
var i = oldTracks.length;
|
var i = oldTracks.length;
|
||||||
while (i--) {
|
while (i--) {
|
||||||
|
@ -141,10 +142,10 @@ function changeVideoSrc(vid_obj, source) {
|
||||||
var srcs = [];
|
var srcs = [];
|
||||||
var traks = [];
|
var traks = [];
|
||||||
removeTracks();
|
removeTracks();
|
||||||
for(i=0;i<source.length;i++){
|
for (i = 0; i < source.length; i++) {
|
||||||
if(source[i].type){
|
if (source[i].type) {
|
||||||
srcs.push(source[i]);
|
srcs.push(source[i]);
|
||||||
}else if(source[i].srclang){
|
} else if (source[i].srclang) {
|
||||||
player.addRemoteTextTrack(source[i]);
|
player.addRemoteTextTrack(source[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -213,16 +214,16 @@ function subscribe(email, user_id) {
|
||||||
|
|
||||||
|
|
||||||
if (response.subscribe == "i") {
|
if (response.subscribe == "i") {
|
||||||
$('.subs'+user_id).removeClass("subscribed");
|
$('.subs' + user_id).removeClass("subscribed");
|
||||||
$('.subs'+user_id+' b.text').text("Subscribe");
|
$('.subs' + user_id + ' b.text').text("Subscribe");
|
||||||
$('b.textTotal'+user_id).text(parseInt($('b.textTotal'+user_id).first().text())-1);
|
$('b.textTotal' + user_id).text(parseInt($('b.textTotal' + user_id).first().text()) - 1);
|
||||||
} else {
|
} else {
|
||||||
$('.subs'+user_id).addClass("subscribed");
|
$('.subs' + user_id).addClass("subscribed");
|
||||||
$('.subs'+user_id+' b.text').text("Subscribed");
|
$('.subs' + user_id + ' b.text').text("Subscribed");
|
||||||
$('b.textTotal'+user_id).text(parseInt($('b.textTotal'+user_id).first().text())+1);
|
$('b.textTotal' + user_id).text(parseInt($('b.textTotal' + user_id).first().text()) + 1);
|
||||||
}
|
}
|
||||||
$('#popover-content #subscribeEmail').val(email);
|
$('#popover-content #subscribeEmail').val(email);
|
||||||
$('.subscribeButton'+user_id).popover('hide');
|
$('.subscribeButton' + user_id).popover('hide');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -250,7 +251,7 @@ function closeFloatVideo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function mouseEffect(){
|
function mouseEffect() {
|
||||||
|
|
||||||
$(".thumbsImage").on("mouseenter", function () {
|
$(".thumbsImage").on("mouseenter", function () {
|
||||||
$(this).find(".thumbsGIF").height($(this).find(".thumbsJPG").height());
|
$(this).find(".thumbsGIF").height($(this).find(".thumbsJPG").height());
|
||||||
|
@ -265,7 +266,10 @@ function mouseEffect(){
|
||||||
|
|
||||||
function isMobile() {
|
function isMobile() {
|
||||||
var check = false;
|
var check = false;
|
||||||
(function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4)))check = true})(navigator.userAgent||navigator.vendor||window.opera);
|
(function (a) {
|
||||||
|
if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4)))
|
||||||
|
check = true
|
||||||
|
})(navigator.userAgent || navigator.vendor || window.opera);
|
||||||
return check;
|
return check;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +281,7 @@ function copyToClipboard(text) {
|
||||||
$temp.remove();
|
$temp.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
function addView(videos_id){
|
function addView(videos_id) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: webSiteRootURL + 'addViewCountVideo',
|
url: webSiteRootURL + 'addViewCountVideo',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
@ -285,16 +289,16 @@ function addView(videos_id){
|
||||||
'id': videos_id
|
'id': videos_id
|
||||||
},
|
},
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
$('.view-count'+videos_id).text(response.count);
|
$('.view-count' + videos_id).text(response.count);
|
||||||
console.log(response);
|
console.log(response);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPlayerButtonIndex(name){
|
function getPlayerButtonIndex(name) {
|
||||||
var children = player.getChild('controlBar').children();
|
var children = player.getChild('controlBar').children();
|
||||||
for(i=0;i<children.length;i++){
|
for (i = 0; i < children.length; i++) {
|
||||||
if(children[i].name_ === name){
|
if (children[i].name_ === name) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,11 +98,11 @@ foreach ($videos as $key => $value) {
|
||||||
$img_portrait = "";
|
$img_portrait = "";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<img src="<?php echo $img; ?>" alt="<?php echo $value['title']; ?>" class="thumbsJPG img-responsive <?php echo $img_portrait; ?> rotate<?php echo $value['rotation']; ?>" height="130" />
|
<img src="<?php echo $global['webSiteRootURL']; ?>img/video-placeholder.png" data-src="<?php echo $img; ?>" alt="<?php echo $value['title']; ?>" class="thumbsJPG img-responsive <?php echo $img_portrait; ?> rotate<?php echo $value['rotation']; ?>" height="130" />
|
||||||
<?php
|
<?php
|
||||||
if (!empty($imgGif)) {
|
if (!empty($imgGif)) {
|
||||||
?>
|
?>
|
||||||
<img src="<?php echo $imgGif; ?>" style="position: absolute; top: 0; display: none;" alt="<?php echo $value['title']; ?>" id="thumbsGIF<?php echo $value['id']; ?>" class="thumbsGIF img-responsive <?php echo $img_portrait; ?> rotate<?php echo $value['rotation']; ?>" height="130" />
|
<img src="<?php echo $global['webSiteRootURL']; ?>img/video-placeholder.png" data-src="<?php echo $imgGif; ?>" style="position: absolute; top: 0; display: none;" alt="<?php echo $value['title']; ?>" id="thumbsGIF<?php echo $value['id']; ?>" class="thumbsGIF img-responsive <?php echo $img_portrait; ?> rotate<?php echo $value['rotation']; ?>" height="130" />
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
<meta itemprop="thumbnailUrl" content="<?php echo $img; ?>" />
|
<meta itemprop="thumbnailUrl" content="<?php echo $img; ?>" />
|
||||||
<meta itemprop="uploadDate" content="<?php echo $value['created']; ?>" />
|
<meta itemprop="uploadDate" content="<?php echo $value['created']; ?>" />
|
||||||
|
@ -212,8 +212,14 @@ foreach ($videos as $key => $value) {
|
||||||
} else {
|
} else {
|
||||||
$('#rowCount, #sortBy').selectpicker();
|
$('#rowCount, #sortBy').selectpicker();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$('.thumbsJPG, .thumbsGIF').lazy({
|
||||||
|
effect: 'fadeIn',
|
||||||
|
effectTime: 500,
|
||||||
|
visibleOnly: true
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<?php
|
<?php
|
||||||
include $global['systemRootPath'].'objects/include_end.php';
|
include $global['systemRootPath'] . 'objects/include_end.php';
|
||||||
?>
|
?>
|
Loading…
Add table
Add a link
Reference in a new issue