mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Don't use atom globals in StylesElement
This commit is contained in:
committed by
Nathan Sobo
parent
8686b2009e
commit
2532a9cd59
@@ -25,7 +25,11 @@ module.exports = ({logFile, headless, testPaths, buildAtomEnvironment}) ->
|
||||
|
||||
jasmineContent = document.createElement('div')
|
||||
jasmineContent.setAttribute('id', 'jasmine-content')
|
||||
document.head.appendChild(new StylesElement)
|
||||
|
||||
stylesElement = new StylesElement
|
||||
stylesElement.initialize(atom)
|
||||
|
||||
document.head.appendChild(stylesElement)
|
||||
document.body.appendChild(jasmineContent)
|
||||
|
||||
jasmineEnv.execute()
|
||||
|
||||
@@ -6,6 +6,7 @@ describe "StylesElement", ->
|
||||
|
||||
beforeEach ->
|
||||
element = new StylesElement
|
||||
element.initialize(atom)
|
||||
document.querySelector('#jasmine-content').appendChild(element)
|
||||
addedStyleElements = []
|
||||
removedStyleElements = []
|
||||
@@ -99,8 +100,8 @@ describe "StylesElement", ->
|
||||
|
||||
it "defers selector upgrade until the element is attached", ->
|
||||
element = new StylesElement
|
||||
element.initialize(atom)
|
||||
element.setAttribute('context', 'atom-text-editor')
|
||||
element.initialize()
|
||||
|
||||
atom.styles.addStyleSheet ".editor {background: black;}", context: 'atom-text-editor'
|
||||
expect(element.firstChild.sheet).toBeNull()
|
||||
|
||||
@@ -547,7 +547,10 @@ class AtomEnvironment extends Model
|
||||
|
||||
@config.load()
|
||||
@setBodyPlatformClass()
|
||||
document.head.appendChild(new StylesElement)
|
||||
|
||||
stylesElement = new StylesElement
|
||||
stylesElement.initialize(this)
|
||||
document.head.appendChild(stylesElement)
|
||||
@windowEventHandler = new WindowEventHandler(this)
|
||||
|
||||
@packages.loadPackages()
|
||||
|
||||
@@ -14,6 +14,7 @@ class StylesElement extends HTMLElement
|
||||
@emitter.on 'did-update-style-element', callback
|
||||
|
||||
createdCallback: ->
|
||||
@subscriptions = new CompositeDisposable
|
||||
@emitter = new Emitter
|
||||
@styleElementClonesByOriginalElement = new WeakMap
|
||||
|
||||
@@ -21,31 +22,29 @@ class StylesElement extends HTMLElement
|
||||
if @context is 'atom-text-editor'
|
||||
for styleElement in @children
|
||||
@upgradeDeprecatedSelectors(styleElement)
|
||||
@initialize()
|
||||
|
||||
@context = @getAttribute('context') ? undefined
|
||||
|
||||
detachedCallback: ->
|
||||
@subscriptions.dispose()
|
||||
@subscriptions = null
|
||||
@subscriptions = new CompositeDisposable
|
||||
|
||||
attributeChangedCallback: (attrName, oldVal, newVal) ->
|
||||
@contextChanged() if attrName is 'context'
|
||||
|
||||
initialize: ->
|
||||
return if @subscriptions?
|
||||
initialize: ({@styles}) ->
|
||||
throw new Error("Must pass a styles parameter when initializing TextEditorElements") unless @styles?
|
||||
|
||||
@subscriptions = new CompositeDisposable
|
||||
@context = @getAttribute('context') ? undefined
|
||||
|
||||
@subscriptions.add atom.styles.observeStyleElements(@styleElementAdded.bind(this))
|
||||
@subscriptions.add atom.styles.onDidRemoveStyleElement(@styleElementRemoved.bind(this))
|
||||
@subscriptions.add atom.styles.onDidUpdateStyleElement(@styleElementUpdated.bind(this))
|
||||
@subscriptions.add @styles.observeStyleElements(@styleElementAdded.bind(this))
|
||||
@subscriptions.add @styles.onDidRemoveStyleElement(@styleElementRemoved.bind(this))
|
||||
@subscriptions.add @styles.onDidUpdateStyleElement(@styleElementUpdated.bind(this))
|
||||
|
||||
contextChanged: ->
|
||||
return unless @subscriptions?
|
||||
|
||||
@styleElementRemoved(child) for child in Array::slice.call(@children)
|
||||
@context = @getAttribute('context')
|
||||
@styleElementAdded(styleElement) for styleElement in atom.styles.getStyleElements()
|
||||
@styleElementAdded(styleElement) for styleElement in @styles.getStyleElements()
|
||||
return
|
||||
|
||||
styleElementAdded: (styleElement) ->
|
||||
|
||||
@@ -4,6 +4,7 @@ Path = require 'path'
|
||||
TextBuffer = require 'text-buffer'
|
||||
TextEditor = require './text-editor'
|
||||
TextEditorComponent = require './text-editor-component'
|
||||
StylesElement = require './styles-element'
|
||||
|
||||
ShadowStyleSheet = null
|
||||
|
||||
@@ -25,6 +26,7 @@ class TextEditorElement extends HTMLElement
|
||||
@workspace = atom.workspace
|
||||
@assert = atom.assert
|
||||
@views = atom.views
|
||||
@styles = atom.styles
|
||||
|
||||
@emitter = new Emitter
|
||||
@subscriptions = new CompositeDisposable
|
||||
@@ -46,9 +48,9 @@ class TextEditorElement extends HTMLElement
|
||||
@createShadowRoot()
|
||||
|
||||
@shadowRoot.appendChild(ShadowStyleSheet.cloneNode(true))
|
||||
@stylesElement = document.createElement('atom-styles')
|
||||
@stylesElement = new StylesElement
|
||||
@stylesElement.initialize({@styles})
|
||||
@stylesElement.setAttribute('context', 'atom-text-editor')
|
||||
@stylesElement.initialize()
|
||||
|
||||
@rootElement = document.createElement('div')
|
||||
@rootElement.classList.add('editor--private')
|
||||
@@ -84,12 +86,13 @@ class TextEditorElement extends HTMLElement
|
||||
@subscriptions.add @component.onDidChangeScrollLeft =>
|
||||
@emitter.emit("did-change-scroll-left", arguments...)
|
||||
|
||||
initialize: (model, {@views, @config, @themes, @workspace, @assert}) ->
|
||||
initialize: (model, {@views, @config, @themes, @workspace, @assert, @styles}) ->
|
||||
throw new Error("Must pass a config parameter when initializing TextEditorElements") unless @views?
|
||||
throw new Error("Must pass a config parameter when initializing TextEditorElements") unless @config?
|
||||
throw new Error("Must pass a themes parameter when initializing TextEditorElements") unless @themes?
|
||||
throw new Error("Must pass a workspace parameter when initializing TextEditorElements") unless @workspace?
|
||||
throw new Error("Must pass a assert parameter when initializing TextEditorElements") unless @assert?
|
||||
throw new Error("Must pass a styles parameter when initializing TextEditorElements") unless @styles?
|
||||
|
||||
@setModel(model)
|
||||
this
|
||||
|
||||
Reference in New Issue
Block a user