Upgrade existing selectors after attaching atom-styles element

Style elements don’t have a .sheet property until they are actually
attached to the DOM.

Signed-off-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
Nathan Sobo
2014-11-13 13:35:08 -07:00
committed by Ben Ogle
parent 3546f21af7
commit 7f326421d7
2 changed files with 20 additions and 3 deletions

View File

@@ -18,6 +18,9 @@ class StylesElement extends HTMLElement
@styleElementClonesByOriginalElement = new WeakMap
attachedCallback: ->
if @context is 'atom-text-editor'
for styleElement in @children
@upgradeDeprecatedSelectors(styleElement)
@initialize()
detachedCallback: ->
@@ -48,6 +51,7 @@ class StylesElement extends HTMLElement
return unless @styleElementMatchesContext(styleElement)
styleElementClone = styleElement.cloneNode(true)
styleElementClone.sourcePath = styleElement.sourcePath
styleElementClone.context = styleElement.context
@styleElementClonesByOriginalElement.set(styleElement, styleElementClone)
@@ -61,7 +65,7 @@ class StylesElement extends HTMLElement
@insertBefore(styleElementClone, insertBefore)
if @context is 'atom-text-editor'
@upgradeDeprecatedSelectors(styleElementClone, styleElement.sourcePath)
@upgradeDeprecatedSelectors(styleElementClone)
@emitter.emit 'did-add-style-element', styleElementClone
@@ -82,7 +86,9 @@ class StylesElement extends HTMLElement
styleElementMatchesContext: (styleElement) ->
not @context? or styleElement.context is @context
upgradeDeprecatedSelectors: (styleElement, sourcePath) ->
upgradeDeprecatedSelectors: (styleElement) ->
return unless styleElement.sheet?
upgradedSelectors = []
for rule in styleElement.sheet.cssRules
@@ -99,7 +105,7 @@ class StylesElement extends HTMLElement
upgradedSelectors.push({inputSelector, outputSelector})
if upgradedSelectors.length > 0
warning = "Upgraded the following syntax theme selectors in `#{sourcePath}` for shadow DOM compatibility:\n\n"
warning = "Upgraded the following syntax theme selectors in `#{styleElement.sourcePath}` for shadow DOM compatibility:\n\n"
for {inputSelector, outputSelector} in upgradedSelectors
warning += "`#{inputSelector}` => `#{outputSelector}`\n"