forked from rhardih/lazy-images-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instead of waiting for dom ready and fetching the images via JS, just insert them as is and let the browser handle the rest. The placeholder is just shown behind the image, taking up the same amount of space as the image for visual indication.
- Loading branch information
Showing
14 changed files
with
57 additions
and
353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,4 @@ gemspec | |
|
||
group :development, :test do | ||
gem 'byebug' | ||
gem 'teaspoon-jasmine' | ||
gem 'coffee-rails' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,10 @@ Gem::Specification.new do |s| | |
s.authors = ["René Hansen"] | ||
s.email = ["[email protected]"] | ||
s.homepage = "https://github.com/rhardih/lazy-images-rails" | ||
s.summary = "Lazy loaded images with placeholders and noscript fallback" | ||
s.summary = "Simple placeholders for images" | ||
s.description = "lazy-images-rails is a rails plugin that augments the " \ | ||
"standard image_tag helper to provide instant placeholder images while " \ | ||
"the actual image is being lazy loaded. A noscript fallback is provided " \ | ||
"along with the placeholder for non-js browsers." | ||
"standard image_tag helper to provide instant placeholders while the" \ | ||
"actual image is still being fetched." | ||
s.license = "MIT" | ||
|
||
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require 'nokogiri' | ||
|
||
module LazyImages | ||
module Rails | ||
class Placeholder | ||
include ActionView::Helpers::AssetTagHelper | ||
|
||
attr_reader :svg | ||
attr_reader :options | ||
|
||
def initialize(svg, options) | ||
@svg = svg | ||
@options = options | ||
end | ||
|
||
def to_s | ||
if options[:size] | ||
# N. B. extract_dimensions is a private method from | ||
# actionview/lib/action_view/helpers/asset_tag_helper.rb | ||
# beware of breakage | ||
options[:width], options[:height] = | ||
extract_dimensions(options.delete(:size)) | ||
|
||
fragment = Nokogiri::XML::DocumentFragment.parse(svg) | ||
fragment.first_element_child['width'] = options[:width] | ||
fragment.first_element_child['height'] = options[:height] | ||
|
||
fragment.to_s | ||
else | ||
svg | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.