Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Casey O'Hara committed Apr 14, 2012
2 parents e583bf2 + 3592ec7 commit ff2cf90
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
43 changes: 41 additions & 2 deletions build/retina.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion src/retina.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
if window.devicePixelRatio > 1
window.onload = ->

# Function to test if image is external
is_external = (href) ->
!!( href.match(/^https?\:/i) and !href.match(document.domain) )

# Grab all of the <img> elements on the page and loop over them
for image in document.getElementsByTagName("img")

Expand All @@ -36,6 +40,13 @@ if window.devicePixelRatio > 1
setTimeout load, 5

else

# Get image src
path = image.getAttribute("src")

# Return early if image has external path
if is_external(path)
return

# Grab the image's in-place dimensions.
width = image.offsetWidth
Expand All @@ -44,7 +55,7 @@ if window.devicePixelRatio > 1
# Split the file extension off the image path,
# and put it back together with @2x before the extension.
# "/path/to/image.png" => "/path/to/image@2x.png"
path_segments = image.getAttribute("src").split('.')
path_segments = path.split('.')
path_without_extension = path_segments.slice(0, (path_segments.length - 1)).join(".")
extension = path_segments[path_segments.length - 1]
at_2x_path = "#{path_without_extension}@2x.#{extension}"
Expand Down

0 comments on commit ff2cf90

Please sign in to comment.