forked from GetmeUK/ContentTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsandbox.coffee
More file actions
72 lines (57 loc) · 2.5 KB
/
Copy pathsandbox.coffee
File metadata and controls
72 lines (57 loc) · 2.5 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
window.onload = () ->
ContentTools.IMAGE_UPLOADER = ImageUploader.createImageUploader
# Uncomment the following lines to use the cloudinary image uploader
#CloudinaryImageUploader.CLOUD_NAME = ''
#CloudinaryImageUploader.UPLOAD_PRESET = ''
#ContentTools.IMAGE_UPLOADER = (dialog) ->
# return CloudinaryImageUploader.createImageUploader(dialog)
# Build a palette of styles
ContentTools.StylePalette.add([
new ContentTools.Style('By-line', 'article__by-line', ['p']),
new ContentTools.Style('Caption', 'article__caption', ['p']),
new ContentTools.Style('Example', 'example', ['pre']),
new ContentTools.Style('Example + Good', 'example--good', ['pre']),
new ContentTools.Style('Example + Bad', 'example--bad', ['pre'])
])
editor = ContentTools.EditorApp.get()
editor.init('[data-editable], [data-fixture]', 'data-name')
editor.addEventListener 'saved', (ev) ->
# Handle the page being saved
console.log ev.detail().regions
if Object.keys(ev.detail().regions).length == 0
return
# Mark the ignition as busy while we save the page
editor.busy(true)
# Simulate saving the page
saved = () =>
# Save has completed set the app as no longer busy
editor.busy(false)
# Trigger a flash to indicate the save has been successful
new ContentTools.FlashUI('ok')
setTimeout(saved, 2000)
# Handle tools available to fixtures
FIXTURE_TOOLS = [['undo', 'redo', 'remove']]
ContentEdit.Root.get().bind 'focus', (element) ->
# Determine what tools should be available to the user
if element.isFixed()
tools = FIXTURE_TOOLS
else
tools = ContentTools.DEFAULT_TOOLS
# If the tools have changed update the toolboox
if editor.toolbox().tools() != tools
editor.toolbox().tools(tools)
# Translation example
req = new XMLHttpRequest()
req.overrideMimeType('application/json')
req.open(
'GET',
'https://raw.githubusercontent.com/GetmeUK/ContentTools/master/translations/lp.json',
true
)
req.onreadystatechange = (ev) ->
if ev.target.readyState == 4
translations = JSON.parse(ev.target.responseText)
ContentEdit.addTranslations('lp', translations)
ContentEdit.LANGUAGE = 'lp'
# Uncomment the following line to use the editor with pig latin translation
#req.send(null)