diff --git a/spec/jasmine-test-runner.coffee b/spec/jasmine-test-runner.coffee index b75e90d12..a245379e2 100644 --- a/spec/jasmine-test-runner.coffee +++ b/spec/jasmine-test-runner.coffee @@ -3,7 +3,6 @@ _ = require 'underscore-plus' fs = require 'fs-plus' path = require 'path' ipc = require 'ipc' -StylesElement = require '../src/styles-element' module.exports = ({logFile, headless, testPaths, buildAtomEnvironment}) -> window.atom = buildAtomEnvironment() @@ -26,10 +25,7 @@ module.exports = ({logFile, headless, testPaths, buildAtomEnvironment}) -> jasmineContent = document.createElement('div') jasmineContent.setAttribute('id', 'jasmine-content') - stylesElement = new StylesElement - stylesElement.initialize(atom) - - document.head.appendChild(stylesElement) + document.head.appendChild(atom.styles.buildStylesElement()) document.body.appendChild(jasmineContent) atom.commands.attach(window) diff --git a/spec/styles-element-spec.coffee b/spec/styles-element-spec.coffee index ae2648644..b1a57938c 100644 --- a/spec/styles-element-spec.coffee +++ b/spec/styles-element-spec.coffee @@ -6,7 +6,7 @@ describe "StylesElement", -> beforeEach -> element = new StylesElement - element.initialize(atom) + element.initialize(atom.styles) document.querySelector('#jasmine-content').appendChild(element) addedStyleElements = [] removedStyleElements = [] @@ -100,7 +100,7 @@ describe "StylesElement", -> it "defers selector upgrade until the element is attached", -> element = new StylesElement - element.initialize(atom) + element.initialize(atom.styles) element.setAttribute('context', 'atom-text-editor') atom.styles.addStyleSheet ".editor {background: black;}", context: 'atom-text-editor' diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index b3e0eabfe..e398df1f9 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -585,10 +585,7 @@ class AtomEnvironment extends Model @config.load() @setBodyPlatformClass() - stylesElement = new StylesElement - stylesElement.initialize(this) - - document.head.appendChild(stylesElement) + document.head.appendChild(@styles.buildStylesElement()) @windowEventHandler = new WindowEventHandler(this) @packages.loadPackages() diff --git a/src/style-manager.coffee b/src/style-manager.coffee index 11dc4b97f..8b3349b7a 100644 --- a/src/style-manager.coffee +++ b/src/style-manager.coffee @@ -1,6 +1,7 @@ fs = require 'fs-plus' path = require 'path' {Emitter, Disposable} = require 'event-kit' +StylesElement = require './styles-element' # Extended: A singleton instance of this class available via `atom.styles`, # which you can use to globally query and observe the set of active style @@ -154,6 +155,11 @@ class StyleManager return + buildStylesElement: -> + stylesElement = new StylesElement + stylesElement.initialize(this) + stylesElement + ### Section: Paths ### diff --git a/src/styles-element.coffee b/src/styles-element.coffee index e5ab9884e..d1e6bf3d9 100644 --- a/src/styles-element.coffee +++ b/src/styles-element.coffee @@ -32,19 +32,19 @@ class StylesElement extends HTMLElement attributeChangedCallback: (attrName, oldVal, newVal) -> @contextChanged() if attrName is 'context' - initialize: ({@styles}) -> - throw new Error("Must pass a styles parameter when initializing TextEditorElements") unless @styles? + initialize: (@styleManager) -> + throw new Error("Must pass a styleManager parameter when initializing a StylesElement") unless @styleManager? - @subscriptions.add @styles.observeStyleElements(@styleElementAdded.bind(this)) - @subscriptions.add @styles.onDidRemoveStyleElement(@styleElementRemoved.bind(this)) - @subscriptions.add @styles.onDidUpdateStyleElement(@styleElementUpdated.bind(this)) + @subscriptions.add @styleManager.observeStyleElements(@styleElementAdded.bind(this)) + @subscriptions.add @styleManager.onDidRemoveStyleElement(@styleElementRemoved.bind(this)) + @subscriptions.add @styleManager.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 @styles.getStyleElements() + @styleElementAdded(styleElement) for styleElement in @styleManager.getStyleElements() return styleElementAdded: (styleElement) -> diff --git a/src/text-editor-element.coffee b/src/text-editor-element.coffee index fc2d2c7e9..9fe0e9091 100644 --- a/src/text-editor-element.coffee +++ b/src/text-editor-element.coffee @@ -49,7 +49,7 @@ class TextEditorElement extends HTMLElement @shadowRoot.appendChild(ShadowStyleSheet.cloneNode(true)) @stylesElement = new StylesElement - @stylesElement.initialize({@styles}) + @stylesElement.initialize(@styles) @stylesElement.setAttribute('context', 'atom-text-editor') @rootElement = document.createElement('div')