Permalink
Browse files

Fixing interference

this is getting hairy
  • Loading branch information...
nvh committed Jul 21, 2017
1 parent f1e64b9 commit 37d64cf2172843989e12ec1d4ee9cbc44303b402
Showing with 33 additions and 24 deletions.
  1. +32 −23 framer/Utils.coffee
  2. +1 −1 test/tests/UtilsTest.coffee
View
@@ -541,45 +541,54 @@ Utils.loadWebFontConfig = (config) ->
customFontactive = config.fontactive
customFontinactive = config.fontinactive
config.fontloading = (font) ->
console.log "loading", font
resolvePromise = ->
promise.resolve?()
promise.resolved = true
rejectPromise = (error) ->
promise.reject?(error)
promise.error = error
config.fontactive = (font) ->
console.log "active", font
_isFontLoadedResults[font] = true
customFontactive?()
customFontactive?(font)
if fonts.length is 1
f = resolvePromise
resolvePromise = null
f()
config.fontinactive = (font) ->
console.log "inactive", font
_isFontLoadedResults[font] = false
customFontinactive?()
customFontinactive?(font)
if fonts.length is 1
f = rejectPromise
rejectPromise = null
error = new Error("#{font} failed to load")
f(error)
config.active = ->
console.log "allactive", fonts
promise.resolve?()
promise.resolved = true
customActive?()
resolvePromise?()
config.inactive = ->
console.log "allinactive", fonts
error = new Error("#{fonts.join(', ')} failed to load")
promise.reject?(error)
promise.error = error
customInactive?()
error = new Error("#{fonts.join(', ')} failed to load")
rejectPromise?(error)
WebFont.load config
return promise
Utils.loadWebFont = (font, weight, source = "google") ->
delete _isFontLoadedResults[font]
config = {}
if source is "google"
fontToLoad = font
fontToLoad += ":#{weight}" if weight?
config.google =
families: [fontToLoad]
Utils.loadWebFontConfig config
if not _isFontLoadedResults[font]? or _isFontLoadedResults[font] is false
delete _isFontLoadedResults[font]
config = {}
if source is "google"
fontToLoad = font
fontToLoad += ":#{weight}" if weight?
config.google =
families: [fontToLoad]
Utils.loadWebFontConfig config
return {fontFamily: font, fontWeight: weight}
######################################################
@@ -335,7 +335,7 @@ describe "Utils", ->
done()
return
it.skip "should not interfere with each other", (done) ->
it "should not interfere with each other", (done) ->
Utils.loadWebFont("Raleway")
roboto = Utils.loadWebFontConfig
google:

0 comments on commit 37d64cf

Please sign in to comment.