Create valid DOM ids for stylesheets

This commit is contained in:
Matt Colyer
2013-11-04 16:21:50 -08:00
parent c9eebcf00a
commit e312050163

View File

@@ -159,19 +159,23 @@ class ThemeManager
#{e.message}
"""
# Internal-only:
stringToId: (string) ->
string.replace(/\\/g, '')
# Internal-only:
removeStylesheet: (stylesheetPath) ->
unless fullPath = @resolveStylesheet(stylesheetPath)
throw new Error("Could not find a file at path '#{stylesheetPath}'")
@stylesheetElementForId(fullPath).remove()
@stylesheetElementForId(@stringToId(fullPath)).remove()
# Internal-only:
applyStylesheet: (id, text, ttype = 'bundled') ->
styleElement = @stylesheetElementForId(id)
applyStylesheet: (path, text, ttype = 'bundled') ->
styleElement = @stylesheetElementForId(@stringToId(path))
if styleElement.length
styleElement.text(text)
else
if $("head style.#{ttype}").length
$("head style.#{ttype}:last").after "<style class='#{ttype}' id='#{id}'>#{text}</style>"
$("head style.#{ttype}:last").after "<style class='#{ttype}' id='#{@stringToId(path)}'>#{text}</style>"
else
$("head").append "<style class='#{ttype}' id='#{id}'>#{text}</style>"
$("head").append "<style class='#{ttype}' id='#{@stringToId(path)}'>#{text}</style>"