Skip to content

Commit

Permalink
Better util function for finding out local urls
Browse files Browse the repository at this point in the history
  • Loading branch information
koenbok committed Jul 15, 2015
1 parent 8097266 commit 6438f75
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
8 changes: 2 additions & 6 deletions framer/Layer.coffee
Expand Up @@ -53,7 +53,7 @@ class exports.Layer extends BaseClass
# Special power setting for 2d rendering path. Only enable this
# if you know what you are doing. See LayerStyle for more info.
@_prefer2d = false
@_cacheImage = false
@_cacheImage = true

# We have to create the element before we set the defaults
@_createElement()
Expand Down Expand Up @@ -555,11 +555,7 @@ class exports.Layer extends BaseClass
shoudUseImageCache = false

# If this is a file url, we don't use any cache
else if Utils.isLocalUrl(imageUrl)
shoudUseImageCache = false

# If this is a locally served prototype over http (like in studio) we skip the cache
else if imageUrl.indexOf("127.0.0.1") != -1 or imageUrl.indexOf("localhost") != -1
else if Utils.isLocalAssetUrl(imageUrl)
shoudUseImageCache = false

if shoudUseImageCache is false
Expand Down
22 changes: 19 additions & 3 deletions framer/Utils.coffee
Expand Up @@ -296,11 +296,27 @@ Utils.isTablet = ->
Utils.isMobile = ->
Utils.isPhone() or Utils.isTablet()

Utils.isLocal = ->
Utils.isLocalUrl window.location.href
Utils.isFileUrl = (url) ->
return _.startsWith(url, "file://")

Utils.isRelativeUrl = (url) ->
return true if _.startsWith(url, ".")
return true if _.startsWith(url, "./")
return true if _.startsWith(url, "../")
return false

Utils.isLocalServerUrl = (url) ->
return url.indexOf("127.0.0.1") != -1 or url.indexOf("localhost") != -1

Utils.isLocalUrl = (url) ->
url[0..6] == "file://"
return true if Utils.isFileUrl(url)
return true if Utils.isLocalServerUrl(url)
return false

Utils.isLocalAssetUrl = (url) ->
return true if Utils.isLocalUrl(url)
return true if Utils.isRelativeUrl(url) and Utils.isLocalUrl(window.location.href)
return false

Utils.isFramerStudio = ->
navigator.userAgent.indexOf("FramerStudio") != -1
Expand Down

0 comments on commit 6438f75

Please sign in to comment.