lazy_images-rails 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e04e640737f6513419b155d720398f6dd061f33
4
- data.tar.gz: 37ba112b2864c07d38b8f72a94024d619695194d
3
+ metadata.gz: 643784a2611cce70c7c98b03f5a657ae3349d796
4
+ data.tar.gz: 2390a7ba3d54ffc12fca143cd1165d738d54a368
5
5
  SHA512:
6
- metadata.gz: 00c11f340c027d65af7a266153a5314018c1e7923058c02115bbef6fb2f2af761641f5a54f9a7e9daf3eaa4499ce59e8a58a7f5168724abf5ad4fa459ce53852
7
- data.tar.gz: 29725e238fba4fa4c7dfb75248d5489dfd9f5b19118c448e16575d689e7301be52fd0e2667cdf65e79f6745536657fd3f5f16186741f10748046babaa99dbcc1
6
+ metadata.gz: 7b5e9c27a5dc052d0a3d2176b8e2558239bb8d33bf90d3550f6b249fa6c0ac19b0d8b29794e29b936977fc4a70037cb21c5a4f1bdefbddc3ffb5402f355c1589
7
+ data.tar.gz: 68121f9b1988c0278563fa6690379e1573f7b83c2eb0dc7cc88a59c9d2954f6f3a7aecb5d874d36ff2367394cdbd53646b75bb1df642505978af5cb09983b8a0
@@ -1,7 +1,17 @@
1
1
  class @LazyImagesRails
2
2
  @init: (all_replaced) ->
3
3
  replace_with_image = (placeholder) =>
4
- img = new Image()
4
+ svg = placeholder.querySelector('svg')
5
+
6
+ width = svg.attributes.width
7
+ height = svg.attributes.height
8
+ img = null
9
+
10
+ if width? && height?
11
+ img = new Image(parseInt(width.value, 10), parseInt(height.value, 10))
12
+ else
13
+ img = new Image()
14
+
5
15
  img.onload = =>
6
16
  placeholder.parentNode.replaceChild(img, placeholder)
7
17
  if all_replaced? && --@placeholder_count == 0
@@ -1,3 +1,5 @@
1
+ require 'nokogiri'
2
+
1
3
  module LazyImages
2
4
  module Rails
3
5
  mattr_accessor :placeholder
@@ -10,9 +12,23 @@ module LazyImages
10
12
  def image_tag_with_lazy_images(source, options={})
11
13
  src = path_to_image(source)
12
14
  data = { rli_image_src: src, rli_placeholder: true }
15
+ placeholder = LazyImages::Rails.placeholder.dup
16
+
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))
22
+
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
13
29
 
14
30
  content_tag(:div, data: data, class: 'rli-wrapper') do
15
- LazyImages::Rails.placeholder.html_safe + content_tag(:noscript) do
31
+ placeholder.html_safe + content_tag(:noscript) do
16
32
  options[:src] = src
17
33
  options[:class] = "#{options[:class]} rli-image"
18
34
  image_tag_without_lazy_images(source, options)
@@ -1,5 +1,5 @@
1
1
  module LazyImages
2
2
  module Rails
3
- VERSION = "1.1.0"
3
+ VERSION = "1.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazy_images-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - René Hansen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-19 00:00:00.000000000 Z
11
+ date: 2015-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 4.2.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.6.6
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.6.6
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: sqlite3
29
43
  requirement: !ruby/object:Gem::Requirement