Skip to content

Commit

Permalink
Item14699: don't return false in static context
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed May 28, 2018
1 parent cc0a5fd commit f0cdf39
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 31 deletions.
14 changes: 7 additions & 7 deletions .gitignore
Expand Up @@ -4,10 +4,10 @@
pub/System/LazyLoadPlugin/git
pub/System/LazyLoadPlugin/jquery.lazyload.init.js
pub/System/LazyLoadPlugin/jquery.lazyload.js
LazyLoadPlugin.md5
LazyLoadPlugin.sha1
LazyLoadPlugin.tgz
LazyLoadPlugin.txt
LazyLoadPlugin.zip
LazyLoadPlugin_installer
LazyLoadPlugin_installer.pl
/LazyLoadPlugin.md5
/LazyLoadPlugin.sha1
/LazyLoadPlugin.tgz
/LazyLoadPlugin.txt
/LazyLoadPlugin.zip
/LazyLoadPlugin_installer
/LazyLoadPlugin_installer.pl
7 changes: 4 additions & 3 deletions data/System/LazyLoadPlugin.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="autosave" date="1356278775" format="1.1" version="3"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1527516589" format="1.1" version="1"}%
---+!! %TOPIC%
%FORMFIELD{"Description"}%

Expand Down Expand Up @@ -37,10 +37,11 @@ Note that you won't need to surround an %IMAGEGALLERY tag of Foswiki:Extensions/

---++ Copyright
* © 2007-2012 Mika Tuupola http://www.appelsiini.net/ (jQuery plugin)
* © 2011-2016 Michael Daum http://michaeldaumconsulting.com (Foswiki integration)
* © 2011-2018 Michael Daum http://michaeldaumconsulting.com (Foswiki integration)

---++ Change History
%TABLE{columnwidths="7em" tablewidth="100%"}%
| 28 May 2018: | don't return false in static context |
| 27 May 2016: | upgraded to lazyload 1.9.7; disable itself in static content such as print-outs |
| 28 Aug 2014: | upgraded to lazyload 1.9.3 |
| 14 Mar 2013: | upgraded to lazyload 1.8.2 |
Expand All @@ -49,7 +50,7 @@ Note that you won't need to surround an %IMAGEGALLERY tag of Foswiki:Extensions/

%META:FORM{name="PackageForm"}%
%META:FIELD{name="Author" title="Author" value="Michael Daum"}%
%META:FIELD{name="Copyright" title="Copyright" value=""}%
%META:FIELD{name="Copyright" title="Copyright" value="2013-2018 Michael Daum http://michaeldaumconsulting.com"}%
%META:FIELD{name="Description" title="Description" value="%25$SHORTDESCRIPTION%25"}%
%META:FIELD{name="Home" title="Home" value="Foswiki:Extensions/%TOPIC%"}%
%META:FIELD{name="License" title="License" value="MIT license http://www.opensource.org/licenses/mit-license.php"}%
Expand Down
11 changes: 5 additions & 6 deletions lib/Foswiki/Plugins/LazyLoadPlugin.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# LazyLoadPlugin is Copyright (C) 2011-2016 Michael Daum http://michaeldaumconsulting.com
# LazyLoadPlugin is Copyright (C) 2011-2018 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -21,21 +21,20 @@ use warnings;
use Foswiki::Func ();
use Foswiki::Plugins::JQueryPlugin ();

our $VERSION = '1.40';
our $RELEASE = '25 May 2016';
our $VERSION = '1.41';
our $RELEASE = '25 May 2018';
our $SHORTDESCRIPTION = 'deferred loading of images';
our $NO_PREFS_IN_TOPIC = 1;
our $doneInit;
our $translationToken;
our $translationToken = "\2";
our $placeholder;

sub initPlugin {

if (Foswiki::Func::getContext()->{static}) {
return 0;
return 1;
}

$translationToken = "\2";
$placeholder = "$Foswiki::cfg{PubUrlPath}/$Foswiki::cfg{SystemWebName}/LazyLoadPlugin/img/white.gif";
$doneInit = 0;

Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/LazyLoadPlugin/Core.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# LazyLoadPlugin is Copyright (C) 2011-2016 Michael Daum http://michaeldaumconsulting.com
# LazyLoadPlugin is Copyright (C) 2011-2018 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down
1 change: 1 addition & 0 deletions lib/Foswiki/Plugins/LazyLoadPlugin/MANIFEST
@@ -1,3 +1,4 @@
!noci
data/System/LazyLoadPlugin.txt 0644
lib/Foswiki/Plugins/LazyLoadPlugin/Core.pm 0644
lib/Foswiki/Plugins/LazyLoadPlugin.pm 0644
Expand Down
Expand Up @@ -3,7 +3,8 @@ jQuery(function($) {

var defaults = {
effect: "fadeIn",
skip_invisible: false
skip_invisible: false,
threshold: 200
};

$(".jqLazyLoad:not(.jqInitedLazyLoad)").livequery(function() {
Expand Down
39 changes: 26 additions & 13 deletions pub/System/LazyLoadPlugin/jquery.lazyload.uncompressed.js
Expand Up @@ -22,14 +22,15 @@
var settings = {
threshold : 0,
failure_limit : 0,
event : "scroll",
event : "scroll.lazyload",
effect : "show",
container : window,
data_attribute : "original",
data_srcset : "srcset",
skip_invisible : false,
appear : null,
load : null,
placeholder : "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC"
placeholder : "data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs="
};

function update() {
Expand Down Expand Up @@ -77,7 +78,7 @@

/* Fire one scroll event per scroll. Not one scroll event per image. */
if (0 === settings.event.indexOf("scroll")) {
$container.on(settings.event, function() {
$container.off(settings.event).on(settings.event, function() {
return update();
});
}
Expand Down Expand Up @@ -105,13 +106,22 @@
$("<img />")
.one("load", function() {
var original = $self.attr("data-" + settings.data_attribute);
$self.hide();
if ($self.is("img")) {
$self.attr("src", original);
} else {
$self.css("background-image", "url('" + original + "')");
var srcset = $self.attr("data-" + settings.data_srcset);

if (original != $self.attr("src")) {
$self.hide();
if ($self.is("img")) {
$self.attr("src", original);
if (srcset != null) {
$self.attr("srcset", srcset);
}
} if ($self.is("video")) {
$self.attr("poster", original);
} else {
$self.css("background-image", "url('" + original + "')");
}
$self[settings.effect](settings.effect_speed);
}
$self[settings.effect](settings.effect_speed);

self.loaded = true;

Expand All @@ -126,14 +136,17 @@
settings.load.call(self, elements_left, settings);
}
})
.attr("src", $self.attr("data-" + settings.data_attribute));
.attr({
"src": $self.attr("data-" + settings.data_attribute),
"srcset": $self.attr("data-" + settings.data_srcset) || ""
});
}
});

/* When wanted event is triggered load original image */
/* by triggering appear. */
if (0 !== settings.event.indexOf("scroll")) {
$self.on(settings.event, function() {
$self.off(settings.event).on(settings.event, function() {
if (!self.loaded) {
$self.trigger("appear");
}
Expand All @@ -142,7 +155,7 @@
});

/* Check if something appears when window is resized. */
$window.on("resize", function() {
$window.off("resize.lazyload").bind("resize.lazyload", function() {
update();
});

Expand All @@ -159,7 +172,7 @@
}

/* Force initial check if images should appear. */
$(document).ready(function() {
$(function() {
update();
});

Expand Down

0 comments on commit f0cdf39

Please sign in to comment.