lazy_image_tag 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +1 -0
- data/lazy_image_tag.gemspec +24 -0
- data/lib/lazy_image_tag/engine.rb +21 -0
- data/lib/lazy_image_tag/helper_generator.rb +20 -0
- data/lib/lazy_image_tag/helpers/image_helper.rb +36 -0
- data/lib/lazy_image_tag/version.rb +3 -0
- data/lib/lazy_image_tag.rb +3 -0
- data/vendor/.DS_Store +0 -0
- data/vendor/assets/.DS_Store +0 -0
- data/vendor/assets/images/blank.png +0 -0
- data/vendor/assets/images/loader.gif +0 -0
- data/vendor/assets/javascripts/jquery.lazyload.min.js +2 -0
- data/vendor/assets/javascripts/lazy-image-tag.js.erb +23 -0
- data/vendor/assets/stylesheets/lazy-image-tag.css.erb +3 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9750f1a64993cb21944a1034ff3bb1c67b8fe07c
|
4
|
+
data.tar.gz: 65af748c1ec842e620754489688fad75bc70eefb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7f7e12a6f8db2c07305957b2fde682413abd6ecf90ae39bfbc8d187b77863ab6a247c0d0d37af26549012ee4c239cc39ba42d1260988b6a40ff084a23b83d7da
|
7
|
+
data.tar.gz: 5f1a6c5fe1e26bbbec2e12946461d92dc3710a67a3e0b213b0c677b676739ec9e6cb0d12b07aa8d1ba803d039a6a5cf6f49a742ac0a395b4102f27e5a4ac7ae9
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# LazyImageTag
|
2
|
+
|
3
|
+
Jquery lazy image loading gem.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'lazy_image_tag'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install lazy_image_tag
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
with "config.lazy_image_tag.use_default = true" configuration your all existing image_tag's will be loaded lazyly
|
21
|
+
with "config.lazy_image_tag.use_default = false" configuration you can use lazy loading with lazy_image_tag helper
|
22
|
+
|
23
|
+
## Configuration
|
24
|
+
In your application.rb file or environment(s) initializer file you can set configurations easly like the above
|
25
|
+
|
26
|
+
config.lazy_image_tag.use_default = true # with this configuration image_tag helper becomes lazy_image_tag helper
|
27
|
+
|
28
|
+
.
|
29
|
+
.
|
30
|
+
.
|
31
|
+
|
32
|
+
config.lazy_image_tag.js_disabled = :noscript # with this configuration users will see normal image tag if their browser does not support javascript or disabled manually
|
33
|
+
|
34
|
+
## Valid Config Options
|
35
|
+
|
36
|
+
:use_default => [false, true]
|
37
|
+
:js_disabled => [:none, :link, :noscript]
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'lazy_image_tag/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "lazy_image_tag"
|
8
|
+
spec.version = LazyImageTag::VERSION
|
9
|
+
spec.authors = ["Mehmet Emin İNAÇ"]
|
10
|
+
spec.email = ["mehmetemininac@gmail.com"]
|
11
|
+
spec.description = %q{This gem gives you to render lazy image ability}
|
12
|
+
spec.summary = %q{Creates new helper method which name is lazy_image_tag}
|
13
|
+
spec.homepage = "http://github.com/meinac/lazy_image_tag"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "rails", ">= 3.1.0"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module LazyImageTag
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
|
4
|
+
include HelperGenerator
|
5
|
+
config.lazy_image_tag = ActiveSupport::OrderedOptions.new
|
6
|
+
|
7
|
+
initializer "initialize config variables" do
|
8
|
+
valid_configs[:use_default].include?(config.lazy_image_tag.use_default) || config.lazy_image_tag.use_default = false
|
9
|
+
valid_configs[:js_disabled].include?(config.lazy_image_tag.js_disabled) || config.lazy_image_tag.js_disabled = :none
|
10
|
+
end
|
11
|
+
|
12
|
+
initializer "injects helper method into ActionView::Base" do
|
13
|
+
inject_helper
|
14
|
+
end
|
15
|
+
|
16
|
+
def valid_configs
|
17
|
+
{:use_default => [false, true], :js_disabled => [:none, :link, :noscript]}
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "lazy_image_tag/helpers/image_helper"
|
2
|
+
|
3
|
+
module LazyImageTag
|
4
|
+
module HelperGenerator
|
5
|
+
|
6
|
+
def inject_helper
|
7
|
+
ActionView::Base.send :include, ImageHelper
|
8
|
+
config.lazy_image_tag.use_default ? override : inject
|
9
|
+
end
|
10
|
+
|
11
|
+
def override
|
12
|
+
ActionView::Base.class_eval{ alias_method_chain :image_tag, :lazy }
|
13
|
+
end
|
14
|
+
|
15
|
+
def inject
|
16
|
+
ActionView::Base.class_eval{ alias_method :lazy_image_tag, :image_tag_with_lazy; alias_method :image_tag_without_lazy, :image_tag }
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module LazyImageTag
|
2
|
+
module ImageHelper
|
3
|
+
|
4
|
+
def image_tag_with_lazy(source, options={})
|
5
|
+
Rails.application.config.lazy_image_tag.js_disabled == :link ? link_helper(source, options) : image_helper(source, options)
|
6
|
+
end
|
7
|
+
|
8
|
+
def container_options(options)
|
9
|
+
container_options = {}
|
10
|
+
container_options[:class] = "lazy-image-container"
|
11
|
+
container_options
|
12
|
+
end
|
13
|
+
|
14
|
+
def link_helper(source, options)
|
15
|
+
options[:class].blank? ? options[:class] = "lazy-image-link" : options[:class] << " lazy-image-link"
|
16
|
+
options[:data] ||= {}
|
17
|
+
options[:data][:width] = options[:width]
|
18
|
+
options[:data][:height] = options[:height]
|
19
|
+
options[:data][:id] = options[:id]
|
20
|
+
options[:alt] = options[:width] = options[:height] = options[:id] = nil
|
21
|
+
content_tag(:div, link_to(options[:alt], path_to_image(source), options), container_options(options))
|
22
|
+
end
|
23
|
+
|
24
|
+
def image_helper(source, options)
|
25
|
+
custom_opts = options.dup
|
26
|
+
custom_opts[:data] ||= {}
|
27
|
+
custom_opts[:data][:original] = source = path_to_image(source)
|
28
|
+
custom_opts[:class].blank? ? custom_opts[:class] = "lazy" : custom_opts[:class] << " lazy"
|
29
|
+
custom_source = path_to_image("blank.png")
|
30
|
+
content = image_tag(custom_source, custom_opts)
|
31
|
+
content << content_tag(:noscript, image_tag(source, options)) if Rails.application.config.lazy_image_tag.js_disabled == :noscript
|
32
|
+
content_tag(:div, content, container_options(options))
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/vendor/.DS_Store
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,2 @@
|
|
1
|
+
/*! Lazy Load 1.9.3 - MIT license - Copyright 2010-2013 Mika Tuupola */
|
2
|
+
!function(a,b,c,d){var e=a(b);a.fn.lazyload=function(f){function g(){var b=0;i.each(function(){var c=a(this);if(!j.skip_invisible||c.is(":visible"))if(a.abovethetop(this,j)||a.leftofbegin(this,j));else if(a.belowthefold(this,j)||a.rightoffold(this,j)){if(++b>j.failure_limit)return!1}else c.trigger("appear"),b=0})}var h,i=this,j={threshold:0,failure_limit:0,event:"scroll",effect:"show",container:b,data_attribute:"original",skip_invisible:!0,appear:null,load:null,placeholder:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC"};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(j,f)),h=j.container===d||j.container===b?e:a(j.container),0===j.event.indexOf("scroll")&&h.bind(j.event,function(){return g()}),this.each(function(){var b=this,c=a(b);b.loaded=!1,(c.attr("src")===d||c.attr("src")===!1)&&c.is("img")&&c.attr("src",j.placeholder),c.one("appear",function(){if(!this.loaded){if(j.appear){var d=i.length;j.appear.call(b,d,j)}a("<img />").bind("load",function(){var d=c.attr("data-"+j.data_attribute);c.hide(),c.is("img")?c.attr("src",d):c.css("background-image","url('"+d+"')"),c[j.effect](j.effect_speed),b.loaded=!0;var e=a.grep(i,function(a){return!a.loaded});if(i=a(e),j.load){var f=i.length;j.load.call(b,f,j)}}).attr("src",c.attr("data-"+j.data_attribute))}}),0!==j.event.indexOf("scroll")&&c.bind(j.event,function(){b.loaded||c.trigger("appear")})}),e.bind("resize",function(){g()}),/(?:iphone|ipod|ipad).*os 5/gi.test(navigator.appVersion)&&e.bind("pageshow",function(b){b.originalEvent&&b.originalEvent.persisted&&i.each(function(){a(this).trigger("appear")})}),a(c).ready(function(){g()}),this},a.belowthefold=function(c,f){var g;return g=f.container===d||f.container===b?(b.innerHeight?b.innerHeight:e.height())+e.scrollTop():a(f.container).offset().top+a(f.container).height(),g<=a(c).offset().top-f.threshold},a.rightoffold=function(c,f){var g;return g=f.container===d||f.container===b?e.width()+e.scrollLeft():a(f.container).offset().left+a(f.container).width(),g<=a(c).offset().left-f.threshold},a.abovethetop=function(c,f){var g;return g=f.container===d||f.container===b?e.scrollTop():a(f.container).offset().top,g>=a(c).offset().top+f.threshold+a(c).height()},a.leftofbegin=function(c,f){var g;return g=f.container===d||f.container===b?e.scrollLeft():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,23 @@
|
|
1
|
+
//= require jquery.lazyload.min.js
|
2
|
+
|
3
|
+
$(document).ready(function(){
|
4
|
+
var image_id = 0;
|
5
|
+
$('a.lazy-image-link').each(function(){
|
6
|
+
image_id++;
|
7
|
+
var data_height = $(this).attr('data-height');
|
8
|
+
var data_width = $(this).attr('data-width');
|
9
|
+
var data_id = $(this).attr('data-id');
|
10
|
+
var id = "lazy-image" + image_id;
|
11
|
+
$(this).replaceWith('<img src="<%= asset_path("blank.png") %>" alt="' + $(this).html() + '" data-original="' + $(this).attr('href') + '" class="lazy ' + $(this).attr('class') + '" id="' + id + '"/>')
|
12
|
+
if(data_height != null)
|
13
|
+
$('#' + id).attr('height', data_height);
|
14
|
+
if(data_width != null)
|
15
|
+
$('#' + id).attr('width', data_width);
|
16
|
+
if(data_id != null)
|
17
|
+
$('#' + id).attr('id', data_id);
|
18
|
+
});
|
19
|
+
|
20
|
+
$('img.lazy').lazyload({
|
21
|
+
'effect': 'fadeIn'
|
22
|
+
});
|
23
|
+
});
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lazy_image_tag
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mehmet Emin İNAÇ
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: This gem gives you to render lazy image ability
|
56
|
+
email:
|
57
|
+
- mehmetemininac@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .DS_Store
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lazy_image_tag.gemspec
|
69
|
+
- lib/lazy_image_tag.rb
|
70
|
+
- lib/lazy_image_tag/engine.rb
|
71
|
+
- lib/lazy_image_tag/helper_generator.rb
|
72
|
+
- lib/lazy_image_tag/helpers/image_helper.rb
|
73
|
+
- lib/lazy_image_tag/version.rb
|
74
|
+
- vendor/.DS_Store
|
75
|
+
- vendor/assets/.DS_Store
|
76
|
+
- vendor/assets/images/blank.png
|
77
|
+
- vendor/assets/images/loader.gif
|
78
|
+
- vendor/assets/javascripts/jquery.lazyload.min.js
|
79
|
+
- vendor/assets/javascripts/lazy-image-tag.js.erb
|
80
|
+
- vendor/assets/stylesheets/lazy-image-tag.css.erb
|
81
|
+
homepage: http://github.com/meinac/lazy_image_tag
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.0.3
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Creates new helper method which name is lazy_image_tag
|
105
|
+
test_files: []
|