lazy_images-rails 1.2.1 → 2.0.0

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
  SHA1:
3
- metadata.gz: 3a6aee109cdcdeee73bce95c95da80cd9767fda7
4
- data.tar.gz: 91792e4ef1fa65d8da187771641bb2173dffdfe2
3
+ metadata.gz: 13f44cb2e7e89f97c7fcffeb4ed01541822e1770
4
+ data.tar.gz: 139c313d6e07fd176e107b5420a1b40e148ff2d5
5
5
  SHA512:
6
- metadata.gz: eae3b7b80b125251fec0c751a1aecfda4b14ec121fe5aa085a42d29bf464428499b285d298b468bb1d7bb55b51609663032f4df2817cbc7d1f3b6afafbe4f59d
7
- data.tar.gz: 77c3cd1c9c09e1bd3c73f25e9b5a413bc9c3bb8382d6047e8b87ad115f37317fde1ca43ce7a94364c57e44b3f0cc35acc1d7be4a35b713131230a4f27783e31c
6
+ metadata.gz: fc8d5255274164198f8f48830ac03749eef7d343ec9523c34e66fd15a737e7b3a17bd8e41ca430650b87b9b56dcb488164e363d1c66494bc05821bf4ed18b57a
7
+ data.tar.gz: f22c1f8b90721c81820c1f2566905808570ba6a58629bfda69faf35fb83c91c3a3cd950e151d98aed6bdd2ce9fca0a58923e4cd2fb1893dcbb1be3bd29545a98
@@ -0,0 +1,35 @@
1
+ require 'nokogiri'
2
+
3
+ module LazyImages
4
+ module Rails
5
+ class Placeholder
6
+ include ActionView::Helpers::AssetTagHelper
7
+
8
+ attr_reader :svg
9
+ attr_reader :options
10
+
11
+ def initialize(svg, options)
12
+ @svg = svg
13
+ @options = options
14
+ end
15
+
16
+ def to_s
17
+ if options[:size]
18
+ # N. B. extract_dimensions is a private method from
19
+ # actionview/lib/action_view/helpers/asset_tag_helper.rb
20
+ # beware of breakage
21
+ options[:width], options[:height] =
22
+ extract_dimensions(options.delete(:size))
23
+
24
+ fragment = Nokogiri::XML::DocumentFragment.parse(svg)
25
+ fragment.first_element_child['width'] = options[:width]
26
+ fragment.first_element_child['height'] = options[:height]
27
+
28
+ fragment.to_s
29
+ else
30
+ svg
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,4 +1,4 @@
1
- require 'nokogiri'
1
+ require 'lazy_images/rails/placeholder'
2
2
 
3
3
  module LazyImages
4
4
  module Rails
@@ -10,29 +10,18 @@ module LazyImages
10
10
  end
11
11
 
12
12
  def image_tag_with_lazy_images(source, options={})
13
- src = path_to_image(source)
14
- data = { rli_image_src: src, rli_placeholder: true }
15
- placeholder = LazyImages::Rails.placeholder.dup
13
+ options.merge!(
14
+ class: "#{options[:class]} rli-image",
15
+ src: path_to_image(source)
16
+ )
16
17
 
17
- if options[:size]
18
- # N. B. extract_dimensions is a private method from
19
- # actionview/lib/action_view/helpers/asset_tag_helper.rb
20
- # beware of breakage
21
- options[:width], options[:height] = extract_dimensions(options.delete(:size))
18
+ placeholder = LazyImages::Rails::Placeholder.new(
19
+ LazyImages::Rails.placeholder, options
20
+ )
22
21
 
23
- fragment = Nokogiri::XML::DocumentFragment.parse(placeholder)
24
- fragment.first_element_child.set_attribute('width', options[:width])
25
- fragment.first_element_child.set_attribute('height', options[:height])
26
-
27
- placeholder = fragment.to_s
28
- end
29
-
30
- content_tag(:div, data: data, class: 'rli-wrapper') do
31
- placeholder.html_safe + content_tag(:noscript) do
32
- options[:src] = src
33
- options[:class] = "#{options[:class]} rli-image"
22
+ content_tag(:div, class: 'rli-wrapper') do
23
+ placeholder.to_s.html_safe +
34
24
  image_tag_without_lazy_images(source, options)
35
- end
36
25
  end
37
26
  end
38
27
  end
@@ -1,5 +1,5 @@
1
1
  module LazyImages
2
2
  module Rails
3
- VERSION = "1.2.1"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazy_images-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - René Hansen
@@ -67,8 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.5.2
69
69
  description: lazy-images-rails is a rails plugin that augments the standard image_tag
70
- helper to provide instant placeholder images while the actual image is being lazy
71
- loaded. A noscript fallback is provided along with the placeholder for non-js browsers.
70
+ helper to provide instant placeholders while theactual image is still being fetched.
72
71
  email:
73
72
  - renehh@gmail.com
74
73
  executables: []
@@ -77,11 +76,11 @@ extra_rdoc_files: []
77
76
  files:
78
77
  - MIT-LICENSE
79
78
  - app/assets/images/placeholder.svg
80
- - app/assets/javascripts/lazy_images_rails.js.coffee
81
79
  - app/assets/stylesheets/lazy_images_rails.css.scss
82
80
  - config/initializers/lazy_images-rails.rb
83
81
  - lib/lazy_images-rails.rb
84
82
  - lib/lazy_images/rails/engine.rb
83
+ - lib/lazy_images/rails/placeholder.rb
85
84
  - lib/lazy_images/rails/tag_helper.rb
86
85
  - lib/lazy_images/rails/version.rb
87
86
  - lib/tasks/lazy_images_tasks.rake
@@ -108,5 +107,5 @@ rubyforge_project:
108
107
  rubygems_version: 2.4.5
109
108
  signing_key:
110
109
  specification_version: 4
111
- summary: Lazy loaded images with placeholders and noscript fallback
110
+ summary: Simple placeholders for images
112
111
  test_files: []
@@ -1,26 +0,0 @@
1
- class @LazyImagesRails
2
- @init: (all_replaced) ->
3
- replace_with_image = (placeholder) =>
4
- noscript = placeholder.querySelector('noscript')
5
- method = if 'innerText' in noscript then 'innerText' else 'textContent'
6
- content = noscript[method]
7
-
8
- tmp = document.createElement('div')
9
- tmp.innerHTML = content # will trigger download of image
10
- img = tmp.querySelector('img')
11
-
12
- done = --@placeholder_count == 0 && all_replaced? &&
13
- typeof all_replaced == 'function'
14
-
15
- # Race condition:
16
- # Event attachment happens after the download triggers above.
17
- # If image loads before getting here, the callback never runs.
18
- img.onload = =>
19
- placeholder.parentNode.replaceChild(img, placeholder)
20
- all_replaced.call() if done
21
-
22
- placeholders = document.querySelectorAll('div[data-rli-placeholder]')
23
- @placeholder_count = placeholders.length
24
-
25
- for placeholder in placeholders
26
- replace_with_image placeholder