lazy_images-rails 1.0.1
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/app/assets/javascripts/lazy_images_rails.js.coffee +16 -0
- data/app/assets/stylesheets/lazy_images_rails.css.scss +19 -0
- data/lib/lazy_images-rails.rb +1 -0
- data/lib/lazy_images/rails/engine.rb +14 -0
- data/lib/lazy_images/rails/tag_helper.rb +27 -0
- data/lib/lazy_images/rails/version.rb +5 -0
- data/lib/tasks/lazy_images_tasks.rake +4 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e66aaa6e5145e030de75aaef69c851d46ca40397
|
4
|
+
data.tar.gz: 36963484361df144ffa2348ebf3462de3379d6c3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 18ebf1e4734915ae5d572b4bacc982771cfc675199d89955eb8e0c062863eeb48d36e1fa1a3dba49d168f43cbb66bd0768af7943c117ba13e90e3579f9332d6b
|
7
|
+
data.tar.gz: f92042d774b1305b5413f7e89de70fc54594f9d2659237d3c63cc7cdd46e51e6c1df111a9d046fdf6038966c34db44b9b27328f987079012a9e4c0070b19aa71
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 René Hansen
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class @LazyImagesRails
|
2
|
+
@init: (all_replaced) ->
|
3
|
+
replace_with_image = (placeholder) =>
|
4
|
+
img = new Image()
|
5
|
+
img.onload = =>
|
6
|
+
placeholder.parentNode.replaceChild(img, placeholder)
|
7
|
+
if all_replaced? && --@placeholder_count == 0
|
8
|
+
all_replaced.call()
|
9
|
+
|
10
|
+
img.src = placeholder.dataset.rliImageSrc
|
11
|
+
|
12
|
+
placeholders = document.querySelectorAll('div[data-rli-placeholder]')
|
13
|
+
@placeholder_count = placeholders.length
|
14
|
+
|
15
|
+
for placeholder in placeholders
|
16
|
+
replace_with_image placeholder
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'lazy_images/rails/engine'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rails/engine'
|
2
|
+
require 'lazy_images/rails/tag_helper'
|
3
|
+
|
4
|
+
module LazyImages
|
5
|
+
module Rails
|
6
|
+
class Engine < ::Rails::Engine
|
7
|
+
initializer :lazy_images_rails do
|
8
|
+
ActionView::Helpers::AssetTagHelper.module_eval do
|
9
|
+
include TagHelper
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module LazyImages
|
2
|
+
module Rails
|
3
|
+
module TagHelper
|
4
|
+
def self.included(base)
|
5
|
+
base.alias_method_chain :image_tag, :lazy_images
|
6
|
+
end
|
7
|
+
|
8
|
+
def image_tag_with_lazy_images(source, options={})
|
9
|
+
src = path_to_image(source)
|
10
|
+
data = { rli_image_src: src, rli_placeholder: true }
|
11
|
+
|
12
|
+
content_tag(:div, data: data, class: 'rli-wrapper') do
|
13
|
+
%(
|
14
|
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024" class="rli-placeholder">
|
15
|
+
<path class="moon" d="M832 288c0 53.020-42.98 96-96 96s-96-42.98-96-96 42.98-96 96-96 96 42.98 96 96z"></path>
|
16
|
+
<path class="mountain" d="M896 832h-768v-128l224-384 256 320h64l224-192z"></path>
|
17
|
+
</svg>
|
18
|
+
).html_safe + content_tag(:noscript) do
|
19
|
+
options[:src] = src
|
20
|
+
options[:class] = "#{options[:class]} rli-image"
|
21
|
+
image_tag_without_lazy_images(source, options)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lazy_images-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- René Hansen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-18 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: 4.2.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.2.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bump
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.5.2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.5.2
|
55
|
+
description: lazy-images-rails is a rails plugin that augments the standard image_tag
|
56
|
+
helper to provide instant placeholder images while the actual image is being lazy
|
57
|
+
loaded. A noscript fallback is provided along with the placeholder for non-js browsers.
|
58
|
+
email:
|
59
|
+
- renehh@gmail.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- MIT-LICENSE
|
65
|
+
- app/assets/javascripts/lazy_images_rails.js.coffee
|
66
|
+
- app/assets/stylesheets/lazy_images_rails.css.scss
|
67
|
+
- lib/lazy_images-rails.rb
|
68
|
+
- lib/lazy_images/rails/engine.rb
|
69
|
+
- lib/lazy_images/rails/tag_helper.rb
|
70
|
+
- lib/lazy_images/rails/version.rb
|
71
|
+
- lib/tasks/lazy_images_tasks.rake
|
72
|
+
homepage: https://github.com/rhardih/lazy-images-rails
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.4.5
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Lazy loaded images with placeholders and noscript fallback
|
96
|
+
test_files: []
|