loadergif 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6870ef2f316bbb9f8ae05eb650ce3862ae60cb859b7d7a20cde973b73cd329f
4
- data.tar.gz: 7f44db22b7a3da9c9c78ed9a83ee960e0d4d6074ef33f3a0c13ef6f9561060b5
3
+ metadata.gz: 1a5818d1de9da97c95ef79dedd0f4d5c5ef5668a22a52b717679d98d6d6bb238
4
+ data.tar.gz: bcfa64bc59d8d9a1b2b542a06b1c8acd61de9abac128c899b63218e317c2474d
5
5
  SHA512:
6
- metadata.gz: d18c12a11ac26bc221f305d55266ccb23c538a2eb534ecb37d1d97a8914dd9506ca11d66184a202338482ea189a6fcc65c5be6d6bbf5db784ddee5989a09e491
7
- data.tar.gz: 97f8fdcc1d392bf7d174fcbf2a72fe07dec7324741bd092c526791f56501062267114e752074463b403c3e02aaec17f0f019f8c59873fb8ea6dd0a7df19e1484
6
+ metadata.gz: 96737ed51347077009f6e7762b6aa33c16bc9be5db529eceac36fdcddc33abf9568688a6a3196002b3ab7a739011ee38d91fd7b92044536c6bd10fcec1a59d89
7
+ data.tar.gz: a1e23ef8c12a97df27acef0dd7dd23074a70c1d860875c74d80057e1485ab691a962a5195e322938281622e3481908098fe09e0083a501ca26864dc86a62c602
data/README.md CHANGED
@@ -50,33 +50,17 @@ Or install it yourself as:
50
50
 
51
51
  $ gem install loadergif
52
52
 
53
- 2. Download the [jQuery Lazy Load Plugin](https://raw.githubusercontent.com/cis-neelam/loder/master/jquery.loader.js)
54
- into your `vendor/assets/javascripts` directory.
55
-
56
- 3. Include it however you prefer. For example, in your application.js you could add:
53
+ 2. Include it however you prefer. For example, in your application.js you could add:
57
54
 
58
55
  //= require jquery.lazyload
59
56
 
60
- 4. In your JavaScript code do:
57
+ 3. In your JavaScript code do:
61
58
 
62
59
  $("img").lazyload();
63
60
 
64
61
  *__Important__: Remember that the Lazy Load Plugin depends on jQuery.*
65
62
 
66
- ## Configuration
67
-
68
- ```ruby
69
- # config/initializers/lazyload.rb
70
- Loadergif::Rails.configure do |config|
71
- # By default, a 1x1 grey gif is used as placeholder ("data:image/gif;base64,...").
72
- # This can be easily customized:
73
- config.placeholder = "/public/img/grey.gif"
74
63
 
75
- # image_tag can return lazyload-friendly images by default,
76
- # no need to pass the { lazy: true } option
77
- config.lazy_by_default = true
78
- end
79
- ```
80
64
 
81
65
  ## Development
82
66
 
data/lib/loadergif.rb CHANGED
@@ -2,6 +2,7 @@ require "nokogiri"
2
2
  require "action_view"
3
3
  require "loadergif/version"
4
4
  require "loadergif/config"
5
+ require "loadergif/loader"
5
6
 
6
7
  module Loadergif
7
8
  class Error < StandardError; end
@@ -22,7 +22,7 @@ module Loadergif
22
22
 
23
23
  # When set to true every image_tag will include { lazy: true } by default
24
24
  def lazy_by_default=(lazy_by_default)
25
- @lazy_by_default = !!lazy_by_default
25
+ @lazy_by_default = true
26
26
  end
27
27
  def lazy_by_default
28
28
  @lazy_by_default
@@ -0,0 +1,244 @@
1
+ /*!
2
+ * Lazy Load - jQuery plugin for lazy loading images
3
+ * Version: 1.9.7
4
+ */
5
+
6
+ (function($, window, document, undefined) {
7
+ var $window = $(window);
8
+
9
+ $.fn.lazyload = function(options) {
10
+ var elements = this;
11
+ var $container;
12
+ var settings = {
13
+ threshold : 0,
14
+ failure_limit : 0,
15
+ event : "scroll.lazyload",
16
+ effect : "show",
17
+ container : window,
18
+ data_attribute : "original",
19
+ data_srcset : "srcset",
20
+ skip_invisible : false,
21
+ appear : null,
22
+ load : null,
23
+ placeholder : "https://ihatetomatoes.net/wp-content/uploads/2014/07/img_css3-spinning-preloader-01.png"
24
+ };
25
+
26
+ function update() {
27
+ var counter = 0;
28
+
29
+ elements.each(function() {
30
+ var $this = $(this);
31
+ if (settings.skip_invisible && !$this.is(":visible")) {
32
+ return;
33
+ }
34
+ if ($.abovethetop(this, settings) ||
35
+ $.leftofbegin(this, settings)) {
36
+ /* Nothing. */
37
+ } else if (!$.belowthefold(this, settings) &&
38
+ !$.rightoffold(this, settings)) {
39
+ $this.trigger("appear");
40
+ /* if we found an image we'll load, reset the counter */
41
+ counter = 0;
42
+ } else {
43
+ if (++counter > settings.failure_limit) {
44
+ return false;
45
+ }
46
+ }
47
+ });
48
+
49
+ }
50
+
51
+ if(options) {
52
+ /* Maintain BC for a couple of versions. */
53
+ if (undefined !== options.failurelimit) {
54
+ options.failure_limit = options.failurelimit;
55
+ delete options.failurelimit;
56
+ }
57
+ if (undefined !== options.effectspeed) {
58
+ options.effect_speed = options.effectspeed;
59
+ delete options.effectspeed;
60
+ }
61
+
62
+ $.extend(settings, options);
63
+ }
64
+
65
+ /* Cache container as jQuery as object. */
66
+ $container = (settings.container === undefined ||
67
+ settings.container === window) ? $window : $(settings.container);
68
+
69
+ /* Fire one scroll event per scroll. Not one scroll event per image. */
70
+ if (0 === settings.event.indexOf("scroll")) {
71
+ $container.off(settings.event).on(settings.event, function() {
72
+ return update();
73
+ });
74
+ }
75
+
76
+ this.each(function() {
77
+ var self = this;
78
+ var $self = $(self);
79
+
80
+ self.loaded = false;
81
+
82
+ /* If no src attribute given use data:uri. */
83
+ if ($self.attr("src") === undefined || $self.attr("src") === false) {
84
+ if ($self.is("img")) {
85
+ $self.attr("src", settings.placeholder);
86
+ }
87
+ }
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
+ .one("load", function() {
98
+ var original = $self.attr("data-" + settings.data_attribute);
99
+ var srcset = $self.attr("data-" + settings.data_srcset);
100
+
101
+ if (original != $self.attr("src")) {
102
+ $self.hide();
103
+ if ($self.is("img")) {
104
+ $self.attr("src", original);
105
+ if (srcset != null) {
106
+ $self.attr("srcset", srcset);
107
+ }
108
+ } if ($self.is("video")) {
109
+ $self.attr("poster", original);
110
+ } else {
111
+ $self.css("background-image", "url('" + original + "')");
112
+ }
113
+ $self[settings.effect](settings.effect_speed);
114
+ }
115
+
116
+ self.loaded = true;
117
+
118
+ /* Remove image from array so it is not looped next time. */
119
+ var temp = $.grep(elements, function(element) {
120
+ return !element.loaded;
121
+ });
122
+ elements = $(temp);
123
+
124
+ if (settings.load) {
125
+ var elements_left = elements.length;
126
+ settings.load.call(self, elements_left, settings);
127
+ }
128
+ })
129
+ .attr({
130
+ "src": $self.attr("data-" + settings.data_attribute),
131
+ "srcset": $self.attr("data-" + settings.data_srcset) || ""
132
+ });
133
+ }
134
+ });
135
+
136
+ /* When wanted event is triggered load original image */
137
+ /* by triggering appear. */
138
+ if (0 !== settings.event.indexOf("scroll")) {
139
+ $self.off(settings.event).on(settings.event, function() {
140
+ if (!self.loaded) {
141
+ $self.trigger("appear");
142
+ }
143
+ });
144
+ }
145
+ });
146
+
147
+ /* Check if something appears when window is resized. */
148
+ $window.off("resize.lazyload").bind("resize.lazyload", function() {
149
+ update();
150
+ });
151
+
152
+ /* With IOS5 force loading images when navigating with back button. */
153
+ /* Non optimal workaround. */
154
+ if ((/(?:iphone|ipod|ipad).*os 5/gi).test(navigator.appVersion)) {
155
+ $window.on("pageshow", function(event) {
156
+ if (event.originalEvent && event.originalEvent.persisted) {
157
+ elements.each(function() {
158
+ $(this).trigger("appear");
159
+ });
160
+ }
161
+ });
162
+ }
163
+
164
+ /* Force initial check if images should appear. */
165
+ $(function() {
166
+ update();
167
+ });
168
+
169
+ return this;
170
+ };
171
+
172
+ /* Convenience methods in jQuery namespace. */
173
+ /* Use as $.belowthefold(element, {threshold : 100, container : window}) */
174
+
175
+ $.belowthefold = function(element, settings) {
176
+ var fold;
177
+
178
+ if (settings.container === undefined || settings.container === window) {
179
+ fold = (window.innerHeight ? window.innerHeight : $window.height()) + $window.scrollTop();
180
+ } else {
181
+ fold = $(settings.container).offset().top + $(settings.container).height();
182
+ }
183
+
184
+ return fold <= $(element).offset().top - settings.threshold;
185
+ };
186
+
187
+ $.rightoffold = function(element, settings) {
188
+ var fold;
189
+
190
+ if (settings.container === undefined || settings.container === window) {
191
+ fold = $window.width() + $window.scrollLeft();
192
+ } else {
193
+ fold = $(settings.container).offset().left + $(settings.container).width();
194
+ }
195
+
196
+ return fold <= $(element).offset().left - settings.threshold;
197
+ };
198
+
199
+ $.abovethetop = function(element, settings) {
200
+ var fold;
201
+
202
+ if (settings.container === undefined || settings.container === window) {
203
+ fold = $window.scrollTop();
204
+ } else {
205
+ fold = $(settings.container).offset().top;
206
+ }
207
+
208
+ return fold >= $(element).offset().top + settings.threshold + $(element).height();
209
+ };
210
+
211
+ $.leftofbegin = function(element, settings) {
212
+ var fold;
213
+
214
+ if (settings.container === undefined || settings.container === window) {
215
+ fold = $window.scrollLeft();
216
+ } else {
217
+ fold = $(settings.container).offset().left;
218
+ }
219
+
220
+ return fold >= $(element).offset().left + settings.threshold + $(element).width();
221
+ };
222
+
223
+ $.inviewport = function(element, settings) {
224
+ return !$.rightoffold(element, settings) && !$.leftofbegin(element, settings) &&
225
+ !$.belowthefold(element, settings) && !$.abovethetop(element, settings);
226
+ };
227
+
228
+ /* Custom selectors for your convenience. */
229
+ /* Use as $("img:below-the-fold").something() or */
230
+ /* $("img").filter(":below-the-fold").something() which is faster */
231
+
232
+ $.extend($.expr[":"], {
233
+ "below-the-fold" : function(a) { return $.belowthefold(a, {threshold : 0}); },
234
+ "above-the-top" : function(a) { return !$.belowthefold(a, {threshold : 0}); },
235
+ "right-of-screen": function(a) { return $.rightoffold(a, {threshold : 0}); },
236
+ "left-of-screen" : function(a) { return !$.rightoffold(a, {threshold : 0}); },
237
+ "in-viewport" : function(a) { return $.inviewport(a, {threshold : 0}); },
238
+ /* Maintain BC for couple of versions. */
239
+ "above-the-fold" : function(a) { return !$.belowthefold(a, {threshold : 0}); },
240
+ "right-of-fold" : function(a) { return $.rightoffold(a, {threshold : 0}); },
241
+ "left-of-fold" : function(a) { return !$.rightoffold(a, {threshold : 0}); }
242
+ });
243
+
244
+ })(jQuery, window, document);
@@ -1,3 +1,3 @@
1
1
  module Loadergif
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
Binary file
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at neelam.j@cisinlabs.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/loadergif/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in loadergif.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 cis-neelam
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # Loadergif
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/loadergif`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'loadergif'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install loadergif
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/loadergif. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Loadergif project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/loadergif/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "loadergif"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ require "loadergif/version"
2
+
3
+ module Loadergif
4
+ class Error < StandardError; end
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,3 @@
1
+ module Loadergif
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,41 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "loadergif/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "loadergif"
8
+ spec.version = Loadergif::VERSION
9
+ spec.authors = ["cis-neelam"]
10
+ spec.email = ["neelam.j@cisinlabs.com"]
11
+
12
+ spec.summary = %q{TODO: Write a short summary, because RubyGems requires one.}
13
+ spec.description = %q{TODO: Write a longer description or delete this line.}
14
+ spec.homepage = "TODO: Put your gem's website or public repo URL here."
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
24
+ spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_development_dependency "bundler", "~> 2.0"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loadergif
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - cis-neelam
@@ -55,10 +55,23 @@ files:
55
55
  - bin/setup
56
56
  - lib/loadergif.rb
57
57
  - lib/loadergif/config.rb
58
+ - lib/loadergif/loader.js
58
59
  - lib/loadergif/version.rb
59
60
  - loadergif-0.1.0.gem
60
61
  - loadergif-0.1.1.gem
62
+ - loadergif-0.1.2.gem
61
63
  - loadergif.gemspec
64
+ - loadergif/.gitignore
65
+ - loadergif/CODE_OF_CONDUCT.md
66
+ - loadergif/Gemfile
67
+ - loadergif/LICENSE.txt
68
+ - loadergif/README.md
69
+ - loadergif/Rakefile
70
+ - loadergif/bin/console
71
+ - loadergif/bin/setup
72
+ - loadergif/lib/loadergif.rb
73
+ - loadergif/lib/loadergif/version.rb
74
+ - loadergif/loadergif.gemspec
62
75
  homepage: http://rubygems.org/gems/loadergif
63
76
  licenses:
64
77
  - MIT