forked from GetmeUK/ContentTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstyles.coffee
More file actions
67 lines (48 loc) · 1.93 KB
/
Copy pathstyles.coffee
File metadata and controls
67 lines (48 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class ContentTools.StylePalette
# The `StylesPalette` class stores a list of styles available to the content
# editor application. A list of styles is usually defined and added to the
# palette as part of initializing the application.
@_styles = []
# Class methods
@add: (styles) ->
# Add a list of styles to the palette
@_styles = @_styles.concat(styles)
@styles: (element) ->
# Return the styles (optional only those applicable for the specified
# tag name).
tagName = element.tagName()
# If no element is specified return a copy of the stlyes list
if element is undefined
return @_styles.slice()
# Filter the styles
return @_styles.filter (style) ->
if not style._applicableTo
return true
return style._applicableTo.indexOf(tagName) != -1
class ContentTools.Style
# The `Style` class is used to define styles (CSS classes) for use in the
# editor.
constructor: (name, cssClass, applicableTo) ->
# A user friendly name
@_name = name
# The CSS class name
@_cssClass = cssClass
# The `applicableTo` value by default will contain a list of class names
# the style can be applied to however if the `StylePalette.styles`
# method is overridden then the value of applicable to maybe any
# construct required to support the overridden styles method.
if applicableTo
@_applicableTo = applicableTo
else
@_applicableTo = null
# Read-only properties
applicableTo: () ->
# Return the tag names this style is applicable to, no value means the
# style is applicable to any tag.
return @_applicableTo
cssClass: () ->
# Return the CSS class name for the style
return @_cssClass
name: () ->
# Return the name of the style
return @_name