jquery-lazy-images 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module JqueryLazyImages
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
Binary file
@@ -0,0 +1,7 @@
1
+ //=require jquery.lazyload
2
+
3
+ $(window).load(lazy_load_images);
4
+
5
+ function lazy_load_images() {
6
+ $("img.lazy").show().lazyload();
7
+ }
@@ -0,0 +1,227 @@
1
+ /*
2
+ * Lazy Load - jQuery plugin for lazy loading images
3
+ *
4
+ * Copyright (c) 2007-2012 Mika Tuupola
5
+ *
6
+ * Licensed under the MIT license:
7
+ * http://www.opensource.org/licenses/mit-license.php
8
+ *
9
+ * Project home:
10
+ * http://www.appelsiini.net/projects/lazyload
11
+ *
12
+ * Version: 1.8.2
13
+ *
14
+ */
15
+ (function($, window, document, undefined) {
16
+ var $window = $(window);
17
+
18
+ $.fn.lazyload = function(options) {
19
+ var elements = this;
20
+ var $container;
21
+ var settings = {
22
+ threshold : 0,
23
+ failure_limit : 0,
24
+ event : "scroll",
25
+ effect : "show",
26
+ container : window,
27
+ data_attribute : "original",
28
+ skip_invisible : true,
29
+ appear : null,
30
+ load : null
31
+ };
32
+
33
+ function update() {
34
+ var counter = 0;
35
+
36
+ elements.each(function() {
37
+ var $this = $(this);
38
+ if (settings.skip_invisible && !$this.is(":visible")) {
39
+ return;
40
+ }
41
+ if ($.abovethetop(this, settings) ||
42
+ $.leftofbegin(this, settings)) {
43
+ /* Nothing. */
44
+ } else if (!$.belowthefold(this, settings) &&
45
+ !$.rightoffold(this, settings)) {
46
+ $this.trigger("appear");
47
+ /* if we found an image we'll load, reset the counter */
48
+ counter = 0;
49
+ } else {
50
+ if (++counter > settings.failure_limit) {
51
+ return false;
52
+ }
53
+ }
54
+ });
55
+
56
+ }
57
+
58
+ if(options) {
59
+ /* Maintain BC for a couple of versions. */
60
+ if (undefined !== options.failurelimit) {
61
+ options.failure_limit = options.failurelimit;
62
+ delete options.failurelimit;
63
+ }
64
+ if (undefined !== options.effectspeed) {
65
+ options.effect_speed = options.effectspeed;
66
+ delete options.effectspeed;
67
+ }
68
+
69
+ $.extend(settings, options);
70
+ }
71
+
72
+ /* Cache container as jQuery as object. */
73
+ $container = (settings.container === undefined ||
74
+ settings.container === window) ? $window : $(settings.container);
75
+
76
+ /* Fire one scroll event per scroll. Not one scroll event per image. */
77
+ if (0 === settings.event.indexOf("scroll")) {
78
+ $container.bind(settings.event, function(event) {
79
+ return update();
80
+ });
81
+ }
82
+
83
+ this.each(function() {
84
+ var self = this;
85
+ var $self = $(self);
86
+
87
+ self.loaded = false;
88
+
89
+ /* When appear is triggered load original image. */
90
+ $self.one("appear", function() {
91
+ if (!this.loaded) {
92
+ if (settings.appear) {
93
+ var elements_left = elements.length;
94
+ settings.appear.call(self, elements_left, settings);
95
+ }
96
+ $("<img />")
97
+ .bind("load", function() {
98
+ $self
99
+ .hide()
100
+ .attr("src", $self.data(settings.data_attribute))
101
+ [settings.effect](settings.effect_speed);
102
+ self.loaded = true;
103
+
104
+ /* Remove image from array so it is not looped next time. */
105
+ var temp = $.grep(elements, function(element) {
106
+ return !element.loaded;
107
+ });
108
+ elements = $(temp);
109
+
110
+ if (settings.load) {
111
+ var elements_left = elements.length;
112
+ settings.load.call(self, elements_left, settings);
113
+ }
114
+ })
115
+ .attr("src", $self.data(settings.data_attribute));
116
+ }
117
+ });
118
+
119
+ /* When wanted event is triggered load original image */
120
+ /* by triggering appear. */
121
+ if (0 !== settings.event.indexOf("scroll")) {
122
+ $self.bind(settings.event, function(event) {
123
+ if (!self.loaded) {
124
+ $self.trigger("appear");
125
+ }
126
+ });
127
+ }
128
+ });
129
+
130
+ /* Check if something appears when window is resized. */
131
+ $window.bind("resize", function(event) {
132
+ update();
133
+ });
134
+
135
+ /* With IOS5 force loading images when navigating with back button. */
136
+ /* Non optimal workaround. */
137
+ if ((/iphone|ipod|ipad.*os 5/gi).test(navigator.appVersion)) {
138
+ $window.bind("pageshow", function(event) {
139
+ if (event.originalEvent.persisted) {
140
+ elements.each(function() {
141
+ $(this).trigger("appear");
142
+ });
143
+ }
144
+ });
145
+ }
146
+
147
+ /* Force initial check if images should appear. */
148
+ $(document).ready(function() {
149
+ update();
150
+ });
151
+
152
+ return this;
153
+ };
154
+
155
+ /* Convenience methods in jQuery namespace. */
156
+ /* Use as $.belowthefold(element, {threshold : 100, container : window}) */
157
+
158
+ $.belowthefold = function(element, settings) {
159
+ var fold;
160
+
161
+ if (settings.container === undefined || settings.container === window) {
162
+ fold = $window.height() + $window.scrollTop();
163
+ } else {
164
+ fold = $(settings.container).offset().top + $(settings.container).height();
165
+ }
166
+
167
+ return fold <= $(element).offset().top - settings.threshold;
168
+ };
169
+
170
+ $.rightoffold = function(element, settings) {
171
+ var fold;
172
+
173
+ if (settings.container === undefined || settings.container === window) {
174
+ fold = $window.width() + $window.scrollLeft();
175
+ } else {
176
+ fold = $(settings.container).offset().left + $(settings.container).width();
177
+ }
178
+
179
+ return fold <= $(element).offset().left - settings.threshold;
180
+ };
181
+
182
+ $.abovethetop = function(element, settings) {
183
+ var fold;
184
+
185
+ if (settings.container === undefined || settings.container === window) {
186
+ fold = $window.scrollTop();
187
+ } else {
188
+ fold = $(settings.container).offset().top;
189
+ }
190
+
191
+ return fold >= $(element).offset().top + settings.threshold + $(element).height();
192
+ };
193
+
194
+ $.leftofbegin = function(element, settings) {
195
+ var fold;
196
+
197
+ if (settings.container === undefined || settings.container === window) {
198
+ fold = $window.scrollLeft();
199
+ } else {
200
+ fold = $(settings.container).offset().left;
201
+ }
202
+
203
+ return fold >= $(element).offset().left + settings.threshold + $(element).width();
204
+ };
205
+
206
+ $.inviewport = function(element, settings) {
207
+ return !$.rightoffold(element, settings) && !$.leftofbegin(element, settings) &&
208
+ !$.belowthefold(element, settings) && !$.abovethetop(element, settings);
209
+ };
210
+
211
+ /* Custom selectors for your convenience. */
212
+ /* Use as $("img:below-the-fold").something() or */
213
+ /* $("img").filter(":below-the-fold").something() which is faster */
214
+
215
+ $.extend($.expr[':'], {
216
+ "below-the-fold" : function(a) { return $.belowthefold(a, {threshold : 0}); },
217
+ "above-the-top" : function(a) { return !$.belowthefold(a, {threshold : 0}); },
218
+ "right-of-screen": function(a) { return $.rightoffold(a, {threshold : 0}); },
219
+ "left-of-screen" : function(a) { return !$.rightoffold(a, {threshold : 0}); },
220
+ "in-viewport" : function(a) { return $.inviewport(a, {threshold : 0}); },
221
+ /* Maintain BC for couple of versions. */
222
+ "above-the-fold" : function(a) { return !$.belowthefold(a, {threshold : 0}); },
223
+ "right-of-fold" : function(a) { return $.rightoffold(a, {threshold : 0}); },
224
+ "left-of-fold" : function(a) { return !$.rightoffold(a, {threshold : 0}); }
225
+ });
226
+
227
+ })(jQuery, window, document);
@@ -0,0 +1,15 @@
1
+ /*
2
+ * Lazy Load - jQuery plugin for lazy loading images
3
+ *
4
+ * Copyright (c) 2007-2012 Mika Tuupola
5
+ *
6
+ * Licensed under the MIT license:
7
+ * http://www.opensource.org/licenses/mit-license.php
8
+ *
9
+ * Project home:
10
+ * http://www.appelsiini.net/projects/lazyload
11
+ *
12
+ * Version: 1.8.2
13
+ *
14
+ */
15
+ (function(a,b,c,d){var e=a(b);a.fn.lazyload=function(f){function j(){var b=0;g.each(function(){var c=a(this);if(i.skip_invisible&&!c.is(":visible"))return;if(!a.abovethetop(this,i)&&!a.leftofbegin(this,i))if(!a.belowthefold(this,i)&&!a.rightoffold(this,i))c.trigger("appear"),b=0;else if(++b>i.failure_limit)return!1})}var g=this,h,i={threshold:0,failure_limit:0,event:"scroll",effect:"show",container:b,data_attribute:"original",skip_invisible:!0,appear:null,load:null};return f&&(d!==f.failurelimit&&(f.failure_limit=f.failurelimit,delete f.failurelimit),d!==f.effectspeed&&(f.effect_speed=f.effectspeed,delete f.effectspeed),a.extend(i,f)),h=i.container===d||i.container===b?e:a(i.container),0===i.event.indexOf("scroll")&&h.bind(i.event,function(a){return j()}),this.each(function(){var b=this,c=a(b);b.loaded=!1,c.one("appear",function(){if(!this.loaded){if(i.appear){var d=g.length;i.appear.call(b,d,i)}a("<img />").bind("load",function(){c.hide().attr("src",c.data(i.data_attribute))[i.effect](i.effect_speed),b.loaded=!0;var d=a.grep(g,function(a){return!a.loaded});g=a(d);if(i.load){var e=g.length;i.load.call(b,e,i)}}).attr("src",c.data(i.data_attribute))}}),0!==i.event.indexOf("scroll")&&c.bind(i.event,function(a){b.loaded||c.trigger("appear")})}),e.bind("resize",function(a){j()}),/iphone|ipod|ipad.*os 5/gi.test(navigator.appVersion)&&e.bind("pageshow",function(b){b.originalEvent.persisted&&g.each(function(){a(this).trigger("appear")})}),a(c).ready(function(){j()}),this},a.belowthefold=function(c,f){var g;return f.container===d||f.container===b?g=e.height()+e.scrollTop():g=a(f.container).offset().top+a(f.container).height(),g<=a(c).offset().top-f.threshold},a.rightoffold=function(c,f){var g;return f.container===d||f.container===b?g=e.width()+e.scrollLeft():g=a(f.container).offset().left+a(f.container).width(),g<=a(c).offset().left-f.threshold},a.abovethetop=function(c,f){var g;return f.container===d||f.container===b?g=e.scrollTop():g=a(f.container).offset().top,g>=a(c).offset().top+f.threshold+a(c).height()},a.leftofbegin=function(c,f){var g;return f.container===d||f.container===b?g=e.scrollLeft():g=a(f.container).offset().left,g>=a(c).offset().left+f.threshold+a(c).width()},a.inviewport=function(b,c){return!a.rightoffold(b,c)&&!a.leftofbegin(b,c)&&!a.belowthefold(b,c)&&!a.abovethetop(b,c)},a.extend(a.expr[":"],{"below-the-fold":function(b){return a.belowthefold(b,{threshold:0})},"above-the-top":function(b){return!a.belowthefold(b,{threshold:0})},"right-of-screen":function(b){return a.rightoffold(b,{threshold:0})},"left-of-screen":function(b){return!a.rightoffold(b,{threshold:0})},"in-viewport":function(b){return a.inviewport(b,{threshold:0})},"above-the-fold":function(b){return!a.belowthefold(b,{threshold:0})},"right-of-fold":function(b){return a.rightoffold(b,{threshold:0})},"left-of-fold":function(b){return!a.rightoffold(b,{threshold:0})}})})(jQuery,window,document)
@@ -0,0 +1,3 @@
1
+ img.lazy {
2
+ display: none;
3
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jquery-lazy-images
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-19 00:00:00.000000000 Z
12
+ date: 2013-03-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -138,6 +138,11 @@ files:
138
138
  - lib/jquery-lazy-images/version.rb
139
139
  - lib/jquery-lazy-images.rb
140
140
  - lib/tasks/jquery-lazy-images_tasks.rake
141
+ - vendor/assets/images/grey.gif
142
+ - vendor/assets/javascripts/jquery.lazy-images.js
143
+ - vendor/assets/javascripts/jquery.lazyload.js
144
+ - vendor/assets/javascripts/jquery.lazyload.min.js
145
+ - vendor/assets/stylesheets/jquery.lazy-images.css
141
146
  - MIT-LICENSE
142
147
  - Rakefile
143
148
  homepage: https://github.com/singlebrook/jquery-lazy-images