mirror of
https://github.com/atom/atom.git
synced 2026-02-14 16:45:14 -05:00
Load stylesheets from package stylesheets directory
This commit is contained in:
@@ -10,8 +10,9 @@ class AtomPackage extends Package
|
||||
|
||||
load: ->
|
||||
try
|
||||
rootView.activatePackage(@module)
|
||||
@loadKeymaps()
|
||||
@loadStylesheets()
|
||||
rootView.activatePackage(@module)
|
||||
catch e
|
||||
console.error "Failed to load package named '#{@name}'", e.stack
|
||||
|
||||
@@ -25,3 +26,14 @@ class AtomPackage extends Package
|
||||
fs.list keymapsDirPath
|
||||
else
|
||||
[]
|
||||
|
||||
loadStylesheets: ->
|
||||
for stylesheetPath in @getStylesheetPaths()
|
||||
requireStylesheet(stylesheetPath)
|
||||
|
||||
getStylesheetPaths: ->
|
||||
stylesheetDirPath = fs.join(@path, 'stylesheets')
|
||||
if fs.exists stylesheetDirPath
|
||||
fs.list stylesheetDirPath
|
||||
else
|
||||
[]
|
||||
|
||||
@@ -61,6 +61,9 @@ windowAdditions =
|
||||
@_handleKeyEvent = (e) => @keymap.handleKeyEvent(e)
|
||||
$(document).on 'keydown', @_handleKeyEvent
|
||||
|
||||
stylesheetElementForId: (id) ->
|
||||
$("head style[id='#{id}']")
|
||||
|
||||
requireStylesheet: (path) ->
|
||||
unless fullPath = require.resolve(path)
|
||||
throw new Error("Could not find a file at path '#{path}'")
|
||||
@@ -69,10 +72,10 @@ windowAdditions =
|
||||
removeStylesheet: (path) ->
|
||||
unless fullPath = require.resolve(path)
|
||||
throw new Error("Could not find a file at path '#{path}'")
|
||||
$("head style[id='#{fullPath}']").remove()
|
||||
window.stylesheetElementForId(fullPath).remove()
|
||||
|
||||
applyStylesheet: (id, text) ->
|
||||
unless $("head style[id='#{id}']").length
|
||||
unless window.stylesheetElementForId(id).length
|
||||
$('head').append "<style id='#{id}'>#{text}</style>"
|
||||
|
||||
reload: ->
|
||||
|
||||
Reference in New Issue
Block a user