forked from GetmeUK/ContentTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnamespace.coffee
More file actions
196 lines (162 loc) · 5.81 KB
/
Copy pathnamespace.coffee
File metadata and controls
196 lines (162 loc) · 5.81 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
window.ContentTools =
# Secondary namespace to store a common set of tools
Tools: {}
# Global settings
# The message displayed to user's when we want them to confirm there changes
# are cancelled.
CANCEL_MESSAGE: '''
Your changes have not been saved, do you really want to lose them?
'''.trim()
# The default tool configuration for the editor
DEFAULT_TOOLS: [
[
'bold',
'italic',
'link',
'align-left',
'align-center',
'align-right'
], [
'heading',
'subheading',
'paragraph',
'unordered-list',
'ordered-list',
'table',
'indent',
'unindent',
'line-break'
], [
'image',
'video',
'preformatted'
], [
'undo',
'redo',
'remove'
]
]
# Default sizes for new videos when inserted into a region
DEFAULT_VIDEO_HEIGHT: 300
DEFAULT_VIDEO_WIDTH: 400
# If the user holds down the shift key for an extended period of time the
# editor app will highlight the editable regions on the page (if there are
# any). This setting determines how long the user must hold down the shift
# key to activate highlighting.
HIGHLIGHT_HOLD_DURATION: 2000
# A list of element class names ignored by the inspector, typically because
# attributes cannot be safely set against them.
INSPECTOR_IGNORED_ELEMENTS: [
'ListItemText',
'Region',
'TableCellText'
]
# If specified this should be a function that accepts an
# `ContentTools.ImageDialog` instance, typically the function then binds a
# set of handlers to specific dialog events to implement support for
# uploading images asynchronously.
IMAGE_UPLOADER: null
# The minimum region that can be selected when cropping an image (in pixels)
MIN_CROP: 10
# A map of restricted attributes (attributes which can't be viewed or
# modified in the properties dialog) in the form:
#
# `{tagName: [attributeNames], ...}`
#
# Attribute and tag names must be specified in lower case.
#
# '*' is a special case tag name any attributes defined against it will be
# restricted for all tags.
#
RESTRICTED_ATTRIBUTES: {
'*': ['style'],
'img': [
'height',
'src',
'width',
'data-ce-max-width',
'data-ce-min-width'
],
'iframe': ['height', 'width']
}
# Utility functions
getEmbedVideoURL: (url) ->
# Utility method to validate/parse video URLs and return a valid embed
# URL. Supports YouTube and Vimeo URLs.
domains = {
'www.youtube.com': 'youtube',
'youtu.be': 'youtube',
'vimeo.com': 'vimeo',
'player.vimeo.com': 'vimeo'
}
# Parse the URL into components
parser = document.createElement('a')
parser.href = url
netloc = parser.hostname.toLowerCase()
path = parser.pathname
# Fix for paths in IE
if path != null && path.substr(0, 1) != "/"
path = "/" + path
params = {}
paramsStr = parser.search[1...]
for kv in paramsStr.split('&')
kv = kv.split("=")
if kv[0]
params[kv[0]] = kv[1]
# Convert the URL to a valid embed URL
switch domains[netloc]
when 'youtube'
if path.toLowerCase() == '/watch'
if not params['v']
return null
id = params['v']
delete params['v']
else
m = path.match(/\/([A-Za-z0-9_-]+)$/i)
if not m
return null
id = m[1]
url = "https://www.youtube.com/embed/#{ id }"
# Add back any parameters for the URL
paramStr = ("#{ k }=#{ v }" for k, v of params).join('&')
if paramStr
url += "?#{ paramStr }"
return url
when 'vimeo'
m = path.match(/\/(\w+\/\w+\/){0,1}(\d+)/i)
if not m
return null
url = "https://player.vimeo.com/video/#{ m[2] }"
# Add back any parameters for the URL
paramStr = ("#{ k }=#{ v }" for k, v of params).join('&')
if paramStr
url += "?#{ paramStr }"
return url
return null
getRestrictedAtributes: (tagName) ->
# Return a list of restricted attributes for the given `tagName`. This
# will include restricted attributes defined against all tags using '*'
# as the tag name.
restricted = []
if ContentTools.RESTRICTED_ATTRIBUTES[tagName]
restricted = restricted.concat(
ContentTools.RESTRICTED_ATTRIBUTES[tagName]
)
if ContentTools.RESTRICTED_ATTRIBUTES['*']
restricted = restricted.concat(
ContentTools.RESTRICTED_ATTRIBUTES['*']
)
return restricted
getScrollPosition: () ->
# Return the current scroll position in a cross-browser compatible way
supportsPageOffset = window.pageXOffset != undefined
isCSS1Compat = (document.compatMode || 4) == 4
if supportsPageOffset
return [window.pageXOffset, window.pageYOffset]
else if isCSS1Compat
return [
document.documentElement.scrollLeft,
document.documentElement.scrollTop
]
else
return [document.body.scrollLeft, document.body.scrollTop]