kiteditor 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +25 -0
- data/app/controllers/mercury/images_controller.rb +5 -0
- data/app/controllers/mercury_controller.rb +34 -0
- data/app/models/mercury/image.rb +17 -0
- data/app/views/layouts/mercury.html.erb +33 -0
- data/app/views/layouts/popup.html.haml +9 -0
- data/app/views/mercury/images/_list.html.haml +22 -0
- data/app/views/mercury/images/index.html.haml +4 -0
- data/app/views/mercury/images/index.js.erb +2 -0
- data/app/views/mercury/lightviews/about.html +11 -0
- data/app/views/mercury/modals/character.html +255 -0
- data/app/views/mercury/modals/htmleditor.html +13 -0
- data/app/views/mercury/modals/link.html +94 -0
- data/app/views/mercury/modals/media.html +1 -0
- data/app/views/mercury/modals/table.html +84 -0
- data/app/views/mercury/palettes/backcolor.html +73 -0
- data/app/views/mercury/palettes/forecolor.html +73 -0
- data/app/views/mercury/panels/history.html +3 -0
- data/app/views/mercury/panels/notes.html +3 -0
- data/app/views/mercury/panels/snippets.html +12 -0
- data/app/views/mercury/selects/formatblock.html +11 -0
- data/app/views/mercury/selects/style.html +5 -0
- data/app/views/mercury/snippets/example/options.html.erb +34 -0
- data/app/views/mercury/snippets/example/preview.html.erb +1 -0
- data/config/engine.rb +44 -0
- data/db/migrate/20110526035601_create_mercury_images.rb +11 -0
- data/features/loading/loading.feature +22 -0
- data/features/loading/navigating.feature +77 -0
- data/features/loading/user_interface.feature +67 -0
- data/features/regions/editable/advanced_editing.feature +0 -0
- data/features/regions/editable/basic_editing.feature +195 -0
- data/features/regions/editable/inserting_links.feature +98 -0
- data/features/regions/editable/inserting_media.feature +110 -0
- data/features/regions/editable/inserting_snippets.feature +102 -0
- data/features/regions/editable/inserting_special_characters.feature +24 -0
- data/features/regions/editable/inserting_tables.feature +109 -0
- data/features/regions/editable/pasting.feature +0 -0
- data/features/regions/editable/uploading_images.feature +0 -0
- data/features/regions/markupable/advanced_editing.feature +0 -0
- data/features/regions/markupable/basic_editing.feature +0 -0
- data/features/regions/markupable/inserting_links.feature +0 -0
- data/features/regions/markupable/inserting_media.feature +0 -0
- data/features/regions/markupable/inserting_snippets.feature +0 -0
- data/features/regions/markupable/inserting_special_characters.feature +0 -0
- data/features/regions/markupable/inserting_tables.feature +0 -0
- data/features/regions/markupable/uploading_images.feature +0 -0
- data/features/regions/snippetable/advanced_editing.feature +0 -0
- data/features/regions/snippetable/basic_editing.feature +0 -0
- data/features/regions/snippetable/inserting_snippets.feature +0 -0
- data/features/saving/saving.feature +33 -0
- data/features/step_definitions/debug_steps.rb +14 -0
- data/features/step_definitions/mercury_steps.rb +438 -0
- data/features/step_definitions/web_steps.rb +211 -0
- data/features/support/env.rb +46 -0
- data/features/support/mercury_contents.rb +25 -0
- data/features/support/mercury_selectors.rb +148 -0
- data/features/support/paths.rb +38 -0
- data/features/support/selectors.rb +44 -0
- data/lib/generators/mercury/install/install_generator.rb +49 -0
- data/lib/generators/mercury/install/templates/mongoid_paperclip_image.rb +17 -0
- data/lib/mercury/authentication.rb +8 -0
- data/lib/mercury-rails.rb +3 -0
- data/spec/javascripts/mercury/dialog_spec.js.coffee +281 -0
- data/spec/javascripts/mercury/dialogs/backcolor_spec.js.coffee +37 -0
- data/spec/javascripts/mercury/dialogs/forecolor_spec.js.coffee +37 -0
- data/spec/javascripts/mercury/dialogs/formatblock_spec.js.coffee +25 -0
- data/spec/javascripts/mercury/dialogs/snippetpanel_spec.js.coffee +30 -0
- data/spec/javascripts/mercury/dialogs/style_spec.js.coffee +25 -0
- data/spec/javascripts/mercury/history_buffer_spec.js.coffee +76 -0
- data/spec/javascripts/mercury/lightview_spec.js.coffee +497 -0
- data/spec/javascripts/mercury/mercury_spec.js.coffee +132 -0
- data/spec/javascripts/mercury/modal_spec.js.coffee +504 -0
- data/spec/javascripts/mercury/modals/htmleditor_spec.js.coffee +30 -0
- data/spec/javascripts/mercury/modals/insertcharacter_spec.js.coffee +29 -0
- data/spec/javascripts/mercury/modals/insertlink_spec.js.coffee +220 -0
- data/spec/javascripts/mercury/modals/insertmedia_spec.js.coffee +167 -0
- data/spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee +52 -0
- data/spec/javascripts/mercury/modals/inserttable_spec.js.coffee +160 -0
- data/spec/javascripts/mercury/native_extensions_spec.js.coffee +60 -0
- data/spec/javascripts/mercury/page_editor_spec.js.coffee +750 -0
- data/spec/javascripts/mercury/palette_spec.js.coffee +49 -0
- data/spec/javascripts/mercury/panel_spec.js.coffee +185 -0
- data/spec/javascripts/mercury/region_spec.js.coffee +298 -0
- data/spec/javascripts/mercury/regions/editable_spec.js.coffee +561 -0
- data/spec/javascripts/mercury/regions/markupable_spec.js.coffee +367 -0
- data/spec/javascripts/mercury/regions/snippetable_spec.js.coffee +370 -0
- data/spec/javascripts/mercury/select_spec.js.coffee +49 -0
- data/spec/javascripts/mercury/snippet_spec.js.coffee +245 -0
- data/spec/javascripts/mercury/snippet_toolbar_spec.js.coffee +184 -0
- data/spec/javascripts/mercury/statusbar_spec.js.coffee +150 -0
- data/spec/javascripts/mercury/table_editor_spec.js.coffee +194 -0
- data/spec/javascripts/mercury/toolbar.button_group_spec.js.coffee +90 -0
- data/spec/javascripts/mercury/toolbar.button_spec.js.coffee +360 -0
- data/spec/javascripts/mercury/toolbar.expander_spec.js.coffee +118 -0
- data/spec/javascripts/mercury/toolbar_spec.js.coffee +222 -0
- data/spec/javascripts/mercury/tooltip_spec.js.coffee +186 -0
- data/spec/javascripts/mercury/uploader_spec.js.coffee +514 -0
- data/spec/javascripts/spec_helper.js +513 -0
- data/spec/javascripts/templates/mercury/dialog.html +2 -0
- data/spec/javascripts/templates/mercury/dialogs/backcolor.html +5 -0
- data/spec/javascripts/templates/mercury/dialogs/forecolor.html +5 -0
- data/spec/javascripts/templates/mercury/dialogs/formatblock.html +3 -0
- data/spec/javascripts/templates/mercury/dialogs/snippetpanel.html +16 -0
- data/spec/javascripts/templates/mercury/dialogs/style.html +3 -0
- data/spec/javascripts/templates/mercury/lightview.html +13 -0
- data/spec/javascripts/templates/mercury/modal.html +13 -0
- data/spec/javascripts/templates/mercury/modals/htmleditor.html +5 -0
- data/spec/javascripts/templates/mercury/modals/insertcharacter.html +5 -0
- data/spec/javascripts/templates/mercury/modals/insertlink.html +30 -0
- data/spec/javascripts/templates/mercury/modals/insertmedia.html +35 -0
- data/spec/javascripts/templates/mercury/modals/insertsnippet.html +6 -0
- data/spec/javascripts/templates/mercury/modals/inserttable.html +27 -0
- data/spec/javascripts/templates/mercury/page_editor.html +35 -0
- data/spec/javascripts/templates/mercury/palette.html +16 -0
- data/spec/javascripts/templates/mercury/panel.html +16 -0
- data/spec/javascripts/templates/mercury/region.html +2 -0
- data/spec/javascripts/templates/mercury/regions/editable.html +3 -0
- data/spec/javascripts/templates/mercury/regions/snippetable.html +4 -0
- data/spec/javascripts/templates/mercury/select.html +16 -0
- data/spec/javascripts/templates/mercury/snippet.html +1 -0
- data/spec/javascripts/templates/mercury/snippet_toolbar.html +16 -0
- data/spec/javascripts/templates/mercury/statusbar.html +8 -0
- data/spec/javascripts/templates/mercury/table_editor.html +65 -0
- data/spec/javascripts/templates/mercury/toolbar.button.html +64 -0
- data/spec/javascripts/templates/mercury/toolbar.button_group.html +9 -0
- data/spec/javascripts/templates/mercury/toolbar.expander.html +18 -0
- data/spec/javascripts/templates/mercury/toolbar.html +11 -0
- data/spec/javascripts/templates/mercury/tooltip.html +12 -0
- data/spec/javascripts/templates/mercury/uploader.html +11 -0
- data/vendor/assets/images/mercury/button.png +0 -0
- data/vendor/assets/images/mercury/close.png +0 -0
- data/vendor/assets/images/mercury/default-snippet.png +0 -0
- data/vendor/assets/images/mercury/loading-dark.gif +0 -0
- data/vendor/assets/images/mercury/loading-light.gif +0 -0
- data/vendor/assets/images/mercury/missing-image.png +0 -0
- data/vendor/assets/images/mercury/search-icon.png +0 -0
- data/vendor/assets/images/mercury/temp-logo.png +0 -0
- data/vendor/assets/images/mercury/toolbar/editable/buttons.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/_expander.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/_pressed.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/historypanel.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/insertcharacter.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/insertlink.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/insertmedia.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/inserttable.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/inspectorpanel.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/notespanel.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/preview.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/redo.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/save.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/snippetpanel.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/undo.png +0 -0
- data/vendor/assets/images/mercury/toolbar/snippetable/buttons.png +0 -0
- data/vendor/assets/javascripts/mercury/dependencies/jquery-1.7.js +9300 -0
- data/vendor/assets/javascripts/mercury/dependencies/jquery-ui-1.8.13.custom.js +1328 -0
- data/vendor/assets/javascripts/mercury/dependencies/jquery-ui-1.8.18.custom.min.js +356 -0
- data/vendor/assets/javascripts/mercury/dependencies/jquery-ui.1.8.13.custom.min.js +356 -0
- data/vendor/assets/javascripts/mercury/dependencies/jquery.additions.js +206 -0
- data/vendor/assets/javascripts/mercury/dependencies/jquery.htmlClean.js +527 -0
- data/vendor/assets/javascripts/mercury/dependencies/liquidmetal.js +88 -0
- data/vendor/assets/javascripts/mercury/dependencies/showdown.js +1340 -0
- data/vendor/assets/javascripts/mercury/dialog.js.coffee +159 -0
- data/vendor/assets/javascripts/mercury/dialogs/backcolor.js.coffee +6 -0
- data/vendor/assets/javascripts/mercury/dialogs/forecolor.js.coffee +6 -0
- data/vendor/assets/javascripts/mercury/dialogs/formatblock.js.coffee +4 -0
- data/vendor/assets/javascripts/mercury/dialogs/snippetpanel.js.coffee +10 -0
- data/vendor/assets/javascripts/mercury/dialogs/style.js.coffee +4 -0
- data/vendor/assets/javascripts/mercury/finalize.js.coffee +3 -0
- data/vendor/assets/javascripts/mercury/history_buffer.js.coffee +30 -0
- data/vendor/assets/javascripts/mercury/lightview.js.coffee +205 -0
- data/vendor/assets/javascripts/mercury/locales/da.locale.js.coffee +0 -0
- data/vendor/assets/javascripts/mercury/locales/de.locale.js.coffee +206 -0
- data/vendor/assets/javascripts/mercury/locales/es.locale.js.coffee +211 -0
- data/vendor/assets/javascripts/mercury/locales/example.local.js.coffee +211 -0
- data/vendor/assets/javascripts/mercury/locales/fr.locale.js.coffee +211 -0
- data/vendor/assets/javascripts/mercury/locales/it.locale.js.coffee +208 -0
- data/vendor/assets/javascripts/mercury/locales/ko.local.js.coffee +206 -0
- data/vendor/assets/javascripts/mercury/locales/nl.locale.js.coffee +206 -0
- data/vendor/assets/javascripts/mercury/locales/pt.locale.js.coffee +211 -0
- data/vendor/assets/javascripts/mercury/locales/sv.local.js.coffee +209 -0
- data/vendor/assets/javascripts/mercury/locales/swedish_chef.locale.js.coffee +213 -0
- data/vendor/assets/javascripts/mercury/mercury.js.coffee +109 -0
- data/vendor/assets/javascripts/mercury/modal.js.coffee +204 -0
- data/vendor/assets/javascripts/mercury/modals/htmleditor.js.coffee +11 -0
- data/vendor/assets/javascripts/mercury/modals/insertcharacter.js.coffee +4 -0
- data/vendor/assets/javascripts/mercury/modals/insertlink.js.coffee +95 -0
- data/vendor/assets/javascripts/mercury/modals/insertmedia.js.coffee +107 -0
- data/vendor/assets/javascripts/mercury/modals/insertsnippet.js.coffee +12 -0
- data/vendor/assets/javascripts/mercury/modals/inserttable.js.coffee +54 -0
- data/vendor/assets/javascripts/mercury/native_extensions.js.coffee +55 -0
- data/vendor/assets/javascripts/mercury/page_editor.js.coffee +241 -0
- data/vendor/assets/javascripts/mercury/palette.js.coffee +29 -0
- data/vendor/assets/javascripts/mercury/panel.js.coffee +115 -0
- data/vendor/assets/javascripts/mercury/plugins/save_as_xml/mercury/page_editor.js.coffee +28 -0
- data/vendor/assets/javascripts/mercury/plugins/save_as_xml/plugin.js +9 -0
- data/vendor/assets/javascripts/mercury/region.js.coffee +107 -0
- data/vendor/assets/javascripts/mercury/regions/editable.js.coffee +600 -0
- data/vendor/assets/javascripts/mercury/regions/markupable.js.coffee +398 -0
- data/vendor/assets/javascripts/mercury/regions/simple.js.coffee +339 -0
- data/vendor/assets/javascripts/mercury/regions/snippetable.js.coffee +124 -0
- data/vendor/assets/javascripts/mercury/select.js.coffee +44 -0
- data/vendor/assets/javascripts/mercury/snippet.js.coffee +104 -0
- data/vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee +72 -0
- data/vendor/assets/javascripts/mercury/statusbar.js.coffee +51 -0
- data/vendor/assets/javascripts/mercury/support/history.js +1 -0
- data/vendor/assets/javascripts/mercury/table_editor.js.coffee +265 -0
- data/vendor/assets/javascripts/mercury/toolbar.button.js.coffee +173 -0
- data/vendor/assets/javascripts/mercury/toolbar.button_group.js.coffee +42 -0
- data/vendor/assets/javascripts/mercury/toolbar.expander.js.coffee +56 -0
- data/vendor/assets/javascripts/mercury/toolbar.js.coffee +86 -0
- data/vendor/assets/javascripts/mercury/tooltip.js.coffee +74 -0
- data/vendor/assets/javascripts/mercury/uploader.js.coffee +227 -0
- data/vendor/assets/javascripts/mercury.js +479 -0
- data/vendor/assets/javascripts/mercury_loader.js +193 -0
- data/vendor/assets/javascripts/mercury_overrides.js +6 -0
- data/vendor/assets/javascripts/popup.js +8 -0
- data/vendor/assets/stylesheets/mercury/all_images.css.erb +89 -0
- data/vendor/assets/stylesheets/mercury/dialog.css +208 -0
- data/vendor/assets/stylesheets/mercury/lightview.css +151 -0
- data/vendor/assets/stylesheets/mercury/mercury.css +151 -0
- data/vendor/assets/stylesheets/mercury/modal.css +183 -0
- data/vendor/assets/stylesheets/mercury/statusbar.css +32 -0
- data/vendor/assets/stylesheets/mercury/toolbar.css +304 -0
- data/vendor/assets/stylesheets/mercury/tooltip.css +26 -0
- data/vendor/assets/stylesheets/mercury/uploader.css +111 -0
- data/vendor/assets/stylesheets/mercury.css +28 -0
- data/vendor/assets/stylesheets/mercury_overrides.css +17 -0
- data/vendor/assets/stylesheets/popup.css.erb +37 -0
- metadata +634 -0
@@ -0,0 +1,339 @@
|
|
1
|
+
# todo:
|
2
|
+
|
3
|
+
# how to handle context for buttons? if the cursor is within a bold area (**bo|ld**), or selecting it -- it would be
|
4
|
+
# nice if we could activate the bold button for instance.
|
5
|
+
|
6
|
+
class @Mercury.Regions.Simple extends Mercury.Region
|
7
|
+
@supported: document.getElementById
|
8
|
+
@supportedText: "IE 7+, Chrome 10+, Firefox 4+, Safari 5+, Opera 8+"
|
9
|
+
|
10
|
+
type = 'simple'
|
11
|
+
|
12
|
+
constructor: (@element, @window, @options = {}) ->
|
13
|
+
@type = 'simple'
|
14
|
+
super
|
15
|
+
|
16
|
+
|
17
|
+
build: ->
|
18
|
+
if @element.css('display') == 'block'
|
19
|
+
width = '100%'
|
20
|
+
height = @element.height()
|
21
|
+
else
|
22
|
+
width = @element.width()
|
23
|
+
height = @element.height() # 'auto'
|
24
|
+
|
25
|
+
value = @element.text()
|
26
|
+
@element.removeClass(Mercury.config.regions.className)
|
27
|
+
@textarea = jQuery('<textarea>', @document).val(value)
|
28
|
+
@textarea.attr('class', @element.attr('class')).addClass('mercury-textarea')
|
29
|
+
@textarea.css
|
30
|
+
border: 0
|
31
|
+
background: 'transparent'
|
32
|
+
'overflow-y': 'hidden'
|
33
|
+
width: width
|
34
|
+
height: height
|
35
|
+
fontFamily: 'inherit'
|
36
|
+
fontSize: 'inherit'
|
37
|
+
fontWeight: 'inherit'
|
38
|
+
fontStyle: 'inherit'
|
39
|
+
color: 'inherit'
|
40
|
+
'min-height': 0
|
41
|
+
padding: '0'
|
42
|
+
margin: 0
|
43
|
+
'border-radius': 0
|
44
|
+
display: 'inherit'
|
45
|
+
lineHeight: 'inherit'
|
46
|
+
textAlign: 'inherit'
|
47
|
+
@element.addClass(Mercury.config.regions.className)
|
48
|
+
@element.empty().append(@textarea)
|
49
|
+
|
50
|
+
@container = @element
|
51
|
+
@container.data('region', @)
|
52
|
+
@element = @textarea
|
53
|
+
@resize()
|
54
|
+
|
55
|
+
|
56
|
+
bindEvents: ->
|
57
|
+
Mercury.on 'mode', (event, options) => @togglePreview() if options.mode == 'preview'
|
58
|
+
Mercury.on 'focus:frame', => @focus() if !@previewing && Mercury.region == @
|
59
|
+
|
60
|
+
Mercury.on 'action', (event, options) =>
|
61
|
+
return if @previewing || Mercury.region != @
|
62
|
+
@execCommand(options.action, options) if options.action
|
63
|
+
|
64
|
+
Mercury.on 'unfocus:regions', =>
|
65
|
+
return if @previewing || Mercury.region != @
|
66
|
+
@element.blur()
|
67
|
+
@container.removeClass('focus')
|
68
|
+
Mercury.trigger('region:blurred', {region: @})
|
69
|
+
|
70
|
+
@element.on 'dragenter', (event) =>
|
71
|
+
return if @previewing
|
72
|
+
event.preventDefault()
|
73
|
+
event.originalEvent.dataTransfer.dropEffect = 'copy'
|
74
|
+
|
75
|
+
@element.on 'dragover', (event) =>
|
76
|
+
return if @previewing
|
77
|
+
event.preventDefault()
|
78
|
+
event.originalEvent.dataTransfer.dropEffect = 'copy'
|
79
|
+
|
80
|
+
@element.on 'drop', (event) =>
|
81
|
+
return if @previewing
|
82
|
+
|
83
|
+
# handle dropping snippets
|
84
|
+
if Mercury.snippet
|
85
|
+
event.preventDefault()
|
86
|
+
@focus()
|
87
|
+
Mercury.Snippet.displayOptionsFor(Mercury.snippet)
|
88
|
+
|
89
|
+
# handle any files that were dropped
|
90
|
+
if event.originalEvent.dataTransfer.files.length
|
91
|
+
event.preventDefault()
|
92
|
+
@focus()
|
93
|
+
Mercury.uploader(event.originalEvent.dataTransfer.files[0])
|
94
|
+
|
95
|
+
@element.on 'focus', =>
|
96
|
+
return if @previewing
|
97
|
+
Mercury.region = @
|
98
|
+
@container.addClass('focus')
|
99
|
+
Mercury.trigger('region:focused', {region: @})
|
100
|
+
|
101
|
+
@element.on 'keydown', (event) =>
|
102
|
+
return if @previewing
|
103
|
+
@resize()
|
104
|
+
switch event.keyCode
|
105
|
+
when 90 # undo / redo
|
106
|
+
return unless event.metaKey
|
107
|
+
event.preventDefault()
|
108
|
+
if event.shiftKey then @execCommand('redo') else @execCommand('undo')
|
109
|
+
return
|
110
|
+
|
111
|
+
when 13 # enter or return
|
112
|
+
selection = @selection()
|
113
|
+
text = @element.val()
|
114
|
+
start = text.lastIndexOf('\n', selection.start)
|
115
|
+
end = text.indexOf('\n', selection.end)
|
116
|
+
end = text.length if end < start
|
117
|
+
start = text.lastIndexOf('\n', selection.start - 1) if text[start] == '\n'
|
118
|
+
if text[start + 1] == '-'
|
119
|
+
selection.replace('\n- ', false, true)
|
120
|
+
if /\d/.test(text[start + 1])
|
121
|
+
lineText = text.substring(start, end)
|
122
|
+
if /(\d+)\./.test(lineText)
|
123
|
+
number = parseInt(RegExp.$1)
|
124
|
+
selection.replace("\n#{number += 1}. ", false, true)
|
125
|
+
# Never allow return. Newlines won't survive the
|
126
|
+
# change-over to HTML, so just don't encourage their
|
127
|
+
# use.
|
128
|
+
event.preventDefault()
|
129
|
+
|
130
|
+
when 9 # tab
|
131
|
+
event.preventDefault()
|
132
|
+
@execCommand('insertHTML', {value: ' '})
|
133
|
+
|
134
|
+
if event.metaKey
|
135
|
+
switch event.keyCode
|
136
|
+
when 66 # b
|
137
|
+
@execCommand('bold')
|
138
|
+
event.preventDefault()
|
139
|
+
|
140
|
+
when 73 # i
|
141
|
+
@execCommand('italic')
|
142
|
+
event.preventDefault()
|
143
|
+
|
144
|
+
when 85 # u
|
145
|
+
@execCommand('underline')
|
146
|
+
event.preventDefault()
|
147
|
+
|
148
|
+
@pushHistory(event.keyCode)
|
149
|
+
|
150
|
+
@element.on 'keyup', =>
|
151
|
+
return if @previewing
|
152
|
+
Mercury.changes = true
|
153
|
+
@resize()
|
154
|
+
Mercury.trigger('region:update', {region: @})
|
155
|
+
|
156
|
+
@element.on 'mouseup', =>
|
157
|
+
return if @previewing
|
158
|
+
@focus()
|
159
|
+
Mercury.trigger('region:focused', {region: @})
|
160
|
+
|
161
|
+
@element.on 'paste', (event) =>
|
162
|
+
return if @previewing || Mercury.region != @
|
163
|
+
if @specialContainer
|
164
|
+
event.preventDefault()
|
165
|
+
return
|
166
|
+
return if @pasting
|
167
|
+
Mercury.changes = true
|
168
|
+
@handlePaste(event.originalEvent)
|
169
|
+
|
170
|
+
|
171
|
+
handlePaste: (event) ->
|
172
|
+
# get the text content from the clipboard and fall back to using the sanitizer if unavailable
|
173
|
+
@execCommand('insertHTML', {value: event.clipboardData.getData('text/plain').replace(/\n/g, ' ')})
|
174
|
+
event.preventDefault()
|
175
|
+
return
|
176
|
+
|
177
|
+
|
178
|
+
path: ->
|
179
|
+
[@container.get(0)]
|
180
|
+
|
181
|
+
|
182
|
+
focus: ->
|
183
|
+
@element.focus()
|
184
|
+
|
185
|
+
|
186
|
+
content: (value = null, filterSnippets = true) ->
|
187
|
+
if value != null
|
188
|
+
if jQuery.type(value) == 'string'
|
189
|
+
@element.val(value)
|
190
|
+
else
|
191
|
+
@element.val(value.html)
|
192
|
+
@selection().select(value.selection.start, value.selection.end)
|
193
|
+
else
|
194
|
+
return @element.val()
|
195
|
+
|
196
|
+
|
197
|
+
contentAndSelection: ->
|
198
|
+
return {html: @content(null, false), selection: @selection().serialize()}
|
199
|
+
|
200
|
+
|
201
|
+
togglePreview: ->
|
202
|
+
if @previewing
|
203
|
+
@previewing = false
|
204
|
+
@element = @container
|
205
|
+
@build()
|
206
|
+
@focus() if Mercury.region == @
|
207
|
+
# @container.addClass(Mercury.config.regions.className).removeClass("#{Mercury.config.regions.className}-preview")
|
208
|
+
# @previewElement.hide()
|
209
|
+
# @element.show()
|
210
|
+
else
|
211
|
+
@previewing = true
|
212
|
+
@container.addClass("#{Mercury.config.regions.className}-preview").removeClass(Mercury.config.regions.className)
|
213
|
+
value = jQuery('<div></div>').text(@element.val()).html()
|
214
|
+
@container.html(value)
|
215
|
+
Mercury.trigger('region:blurred', {region: @})
|
216
|
+
|
217
|
+
|
218
|
+
execCommand: (action, options = {}) ->
|
219
|
+
super
|
220
|
+
|
221
|
+
handler.call(@, @selection(), options) if handler = Mercury.Regions.Simple.actions[action]
|
222
|
+
@resize()
|
223
|
+
|
224
|
+
|
225
|
+
pushHistory: (keyCode) ->
|
226
|
+
# when pressing return, delete or backspace it should push to the history
|
227
|
+
# all other times it should store if there's a 1 second pause
|
228
|
+
keyCodes = [13, 46, 8]
|
229
|
+
waitTime = 2.5
|
230
|
+
knownKeyCode = keyCodes.indexOf(keyCode) if keyCode
|
231
|
+
|
232
|
+
# clear any pushes to the history
|
233
|
+
clearTimeout(@historyTimeout)
|
234
|
+
|
235
|
+
# if the key code was return, delete, or backspace store now -- unless it was the same as last time
|
236
|
+
if knownKeyCode >= 0 && knownKeyCode != @lastKnownKeyCode # || !keyCode
|
237
|
+
@history.push(@contentAndSelection())
|
238
|
+
else if keyCode
|
239
|
+
# set a timeout for pushing to the history
|
240
|
+
@historyTimeout = setTimeout(waitTime * 1000, => @history.push(@contentAndSelection()))
|
241
|
+
else
|
242
|
+
# push to the history immediately
|
243
|
+
@history.push(@contentAndSelection())
|
244
|
+
|
245
|
+
@lastKnownKeyCode = knownKeyCode
|
246
|
+
|
247
|
+
|
248
|
+
selection: ->
|
249
|
+
return new Mercury.Regions.Simple.Selection(@element)
|
250
|
+
|
251
|
+
|
252
|
+
resize: ->
|
253
|
+
@element.css({height: @element.get(0).scrollHeight - 100})
|
254
|
+
@element.css({height: @element.get(0).scrollHeight});
|
255
|
+
|
256
|
+
|
257
|
+
snippets: ->
|
258
|
+
|
259
|
+
|
260
|
+
# Actions
|
261
|
+
@actions: {
|
262
|
+
|
263
|
+
undo: -> @content(@history.undo())
|
264
|
+
|
265
|
+
redo: -> @content(@history.redo())
|
266
|
+
|
267
|
+
insertHTML: (selection, options) ->
|
268
|
+
if options.value.get && element = options.value.get(0)
|
269
|
+
options.value = jQuery('<div>').html(element).html()
|
270
|
+
selection.replace(options.value, false, true)
|
271
|
+
|
272
|
+
}
|
273
|
+
|
274
|
+
|
275
|
+
# Helper class for managing selection and getting information from it
|
276
|
+
class Mercury.Regions.Simple.Selection
|
277
|
+
|
278
|
+
constructor: (@element) ->
|
279
|
+
@el = @element.get(0)
|
280
|
+
@getDetails()
|
281
|
+
|
282
|
+
|
283
|
+
serialize: ->
|
284
|
+
return {start: @start, end: @end}
|
285
|
+
|
286
|
+
|
287
|
+
getDetails: ->
|
288
|
+
@length = @el.selectionEnd - @el.selectionStart
|
289
|
+
@start = @el.selectionStart
|
290
|
+
@end = @el.selectionEnd
|
291
|
+
@text = @element.val().substr(@start, @length)
|
292
|
+
|
293
|
+
|
294
|
+
replace: (text, select = false, placeCursor = false) ->
|
295
|
+
@getDetails()
|
296
|
+
val = @element.val()
|
297
|
+
savedVal = @element.val()
|
298
|
+
@element.val(val.substr(0, @start) + text + val.substr(@end, val.length))
|
299
|
+
changed = @element.val() != savedVal
|
300
|
+
@select(@start, @start + text.length) if select
|
301
|
+
@select(@start + text.length, @start + text.length) if placeCursor
|
302
|
+
return changed
|
303
|
+
|
304
|
+
|
305
|
+
select: (@start, @end) ->
|
306
|
+
@element.focus()
|
307
|
+
@el.selectionStart = @start
|
308
|
+
@el.selectionEnd = @end
|
309
|
+
@getDetails()
|
310
|
+
|
311
|
+
|
312
|
+
wrap: (left, right) ->
|
313
|
+
@getDetails()
|
314
|
+
@deselectNewLines()
|
315
|
+
@replace(left + @text + right, @text != '')
|
316
|
+
@select(@start + left.length, @start + left.length) if @text == ''
|
317
|
+
|
318
|
+
|
319
|
+
deselectNewLines: ->
|
320
|
+
text = @text
|
321
|
+
length = text.replace(/\n+$/g, '').length
|
322
|
+
@select(@start, @start + length)
|
323
|
+
|
324
|
+
|
325
|
+
placeMarker: ->
|
326
|
+
@wrap('[mercury-marker]', '[mercury-marker]')
|
327
|
+
|
328
|
+
|
329
|
+
removeMarker: ->
|
330
|
+
val = @element.val()
|
331
|
+
start = val.indexOf('[mercury-marker]')
|
332
|
+
return unless start > -1
|
333
|
+
end = val.indexOf('[mercury-marker]', start + 1) - '[mercury-marker]'.length
|
334
|
+
@element.val(@element.val().replace(/\[mercury-marker\]/g, ''))
|
335
|
+
@select(start, end)
|
336
|
+
|
337
|
+
|
338
|
+
textContent: ->
|
339
|
+
return @text
|
@@ -0,0 +1,124 @@
|
|
1
|
+
class @Mercury.Regions.Snippetable extends Mercury.Region
|
2
|
+
@supported: document.getElementById
|
3
|
+
@supportedText: "IE 7+, Chrome 10+, Firefox 4+, Safari 5+, Opera 8+"
|
4
|
+
|
5
|
+
type = 'snippetable'
|
6
|
+
|
7
|
+
constructor: (@element, @window, @options = {}) ->
|
8
|
+
@type = 'snippetable'
|
9
|
+
super
|
10
|
+
@makeSortable()
|
11
|
+
|
12
|
+
|
13
|
+
build: ->
|
14
|
+
@element.css({minHeight: 20}) if @element.css('minHeight') == '0px'
|
15
|
+
|
16
|
+
|
17
|
+
bindEvents: ->
|
18
|
+
super
|
19
|
+
|
20
|
+
Mercury.on 'unfocus:regions', (event) =>
|
21
|
+
return if @previewing
|
22
|
+
if Mercury.region == @
|
23
|
+
@element.removeClass('focus')
|
24
|
+
@element.sortable('destroy')
|
25
|
+
Mercury.trigger('region:blurred', {region: @})
|
26
|
+
|
27
|
+
Mercury.on 'focus:window', (event) =>
|
28
|
+
return if @previewing
|
29
|
+
if Mercury.region == @
|
30
|
+
@element.removeClass('focus')
|
31
|
+
@element.sortable('destroy')
|
32
|
+
Mercury.trigger('region:blurred', {region: @})
|
33
|
+
|
34
|
+
@element.on 'mouseup', =>
|
35
|
+
return if @previewing
|
36
|
+
@focus()
|
37
|
+
Mercury.trigger('region:focused', {region: @})
|
38
|
+
|
39
|
+
@element.on 'dragover', (event) =>
|
40
|
+
return if @previewing
|
41
|
+
event.preventDefault()
|
42
|
+
event.originalEvent.dataTransfer.dropEffect = 'copy'
|
43
|
+
|
44
|
+
@element.on 'drop', (event) =>
|
45
|
+
return if @previewing || ! Mercury.snippet
|
46
|
+
@focus()
|
47
|
+
event.preventDefault()
|
48
|
+
Mercury.Snippet.displayOptionsFor(Mercury.snippet)
|
49
|
+
|
50
|
+
jQuery(@document).on 'keydown', (event) =>
|
51
|
+
return if @previewing || Mercury.region != @
|
52
|
+
switch event.keyCode
|
53
|
+
when 90 # undo / redo
|
54
|
+
return unless event.metaKey
|
55
|
+
event.preventDefault()
|
56
|
+
if event.shiftKey then @execCommand('redo') else @execCommand('undo')
|
57
|
+
|
58
|
+
jQuery(@document).on 'keyup', =>
|
59
|
+
return if @previewing || Mercury.region != @
|
60
|
+
Mercury.changes = true
|
61
|
+
|
62
|
+
|
63
|
+
focus: ->
|
64
|
+
Mercury.region = @
|
65
|
+
@makeSortable()
|
66
|
+
@element.addClass('focus')
|
67
|
+
|
68
|
+
|
69
|
+
togglePreview: ->
|
70
|
+
if @previewing
|
71
|
+
@makeSortable()
|
72
|
+
else
|
73
|
+
@element.sortable('destroy')
|
74
|
+
@element.removeClass('focus')
|
75
|
+
super
|
76
|
+
|
77
|
+
|
78
|
+
execCommand: (action, options = {}) ->
|
79
|
+
super
|
80
|
+
handler.call(@, options) if handler = Mercury.Regions.Snippetable.actions[action]
|
81
|
+
|
82
|
+
|
83
|
+
makeSortable: ->
|
84
|
+
@element.sortable('destroy').sortable {
|
85
|
+
document: @document,
|
86
|
+
scroll: false, #scrolling is buggy
|
87
|
+
containment: 'parent',
|
88
|
+
items: '.mercury-snippet',
|
89
|
+
opacity: 0.4,
|
90
|
+
revert: 100,
|
91
|
+
tolerance: 'pointer',
|
92
|
+
beforeStop: =>
|
93
|
+
Mercury.trigger('hide:toolbar', {type: 'snippet', immediately: true})
|
94
|
+
return true
|
95
|
+
stop: =>
|
96
|
+
setTimeout(100, => @pushHistory())
|
97
|
+
return true
|
98
|
+
}
|
99
|
+
|
100
|
+
|
101
|
+
# Actions
|
102
|
+
@actions: {
|
103
|
+
|
104
|
+
undo: -> @content(@history.undo())
|
105
|
+
|
106
|
+
redo: -> @content(@history.redo())
|
107
|
+
|
108
|
+
insertSnippet: (options) ->
|
109
|
+
snippet = options.value
|
110
|
+
if (existing = @element.find("[data-snippet=#{snippet.identity}]")).length
|
111
|
+
existing.replaceWith(snippet.getHTML(@document, => @pushHistory()))
|
112
|
+
else
|
113
|
+
@element.append(snippet.getHTML(@document, => @pushHistory()))
|
114
|
+
|
115
|
+
editSnippet: ->
|
116
|
+
return unless @snippet
|
117
|
+
snippet = Mercury.Snippet.find(@snippet.data('snippet'))
|
118
|
+
snippet.displayOptions()
|
119
|
+
|
120
|
+
removeSnippet: ->
|
121
|
+
@snippet.remove() if @snippet
|
122
|
+
Mercury.trigger('hide:toolbar', {type: 'snippet', immediately: true})
|
123
|
+
|
124
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class @Mercury.Select extends Mercury.Dialog
|
2
|
+
|
3
|
+
constructor: (@url, @name, @options = {}) ->
|
4
|
+
super
|
5
|
+
|
6
|
+
|
7
|
+
build: ->
|
8
|
+
@element = jQuery('<div>', {class: "mercury-select mercury-#{@name}-select loading", style: 'display:none'})
|
9
|
+
@element.appendTo(jQuery(@options.appendTo).get(0) ? 'body')
|
10
|
+
|
11
|
+
|
12
|
+
bindEvents: ->
|
13
|
+
Mercury.on 'hide:dialogs', (event, dialog) => @hide() unless dialog == @
|
14
|
+
|
15
|
+
@element.on 'mousedown', (event) =>
|
16
|
+
event.preventDefault()
|
17
|
+
|
18
|
+
super
|
19
|
+
|
20
|
+
|
21
|
+
position: (keepVisible) ->
|
22
|
+
@element.css({top: 0, left: 0, display: 'block', visibility: 'hidden'})
|
23
|
+
position = @button.offset()
|
24
|
+
elementWidth = @element.width()
|
25
|
+
elementHeight = @element.height()
|
26
|
+
documentHeight = jQuery(document).height()
|
27
|
+
|
28
|
+
top = position.top + (@button.height() / 2) - (elementHeight / 2)
|
29
|
+
top = position.top - 100 if top < position.top - 100
|
30
|
+
top = 20 if top < 20
|
31
|
+
|
32
|
+
height = if @loaded then 'auto' else elementHeight
|
33
|
+
height = documentHeight - top - 20 if top + elementHeight >= documentHeight - 20
|
34
|
+
|
35
|
+
left = position.left
|
36
|
+
left = left - elementWidth + @button.width() if left + elementWidth > jQuery(window).width()
|
37
|
+
|
38
|
+
@element.css {
|
39
|
+
top: top
|
40
|
+
left: left
|
41
|
+
height: height
|
42
|
+
display: if keepVisible then 'block' else 'none'
|
43
|
+
visibility: 'visible'
|
44
|
+
}
|
@@ -0,0 +1,104 @@
|
|
1
|
+
class @Mercury.Snippet
|
2
|
+
|
3
|
+
@all: []
|
4
|
+
|
5
|
+
@displayOptionsFor: (name) ->
|
6
|
+
Mercury.modal Mercury.config.snippets.optionsUrl.replace(':name', name), {
|
7
|
+
title: 'Block Options'
|
8
|
+
handler: 'insertSnippet'
|
9
|
+
snippetName: name
|
10
|
+
}
|
11
|
+
Mercury.snippet = null
|
12
|
+
|
13
|
+
|
14
|
+
@create: (name, options) ->
|
15
|
+
identity = "block_#{@all.length}"
|
16
|
+
instance = new Mercury.Snippet(name, identity, options)
|
17
|
+
@all.push(instance)
|
18
|
+
return instance
|
19
|
+
|
20
|
+
|
21
|
+
@find: (identity) ->
|
22
|
+
for snippet in @all
|
23
|
+
return snippet if snippet.identity == identity
|
24
|
+
return null
|
25
|
+
|
26
|
+
|
27
|
+
@load: (snippets) ->
|
28
|
+
for own identity, details of snippets
|
29
|
+
instance = new Mercury.Snippet(details.name, identity, details.options)
|
30
|
+
@all.push(instance)
|
31
|
+
|
32
|
+
|
33
|
+
constructor: (@name, @identity, options = {}) ->
|
34
|
+
@version = 0
|
35
|
+
@data = ''
|
36
|
+
@history = new Mercury.HistoryBuffer()
|
37
|
+
@setOptions(options)
|
38
|
+
|
39
|
+
|
40
|
+
getHTML: (context, callback = null) ->
|
41
|
+
element = jQuery('<div class="mercury-snippet" contenteditable="false">', context)
|
42
|
+
element.attr({'data-snippet': @identity})
|
43
|
+
element.attr({'data-version': @version})
|
44
|
+
element.html("[#{@identity}]")
|
45
|
+
@loadPreview(element, callback)
|
46
|
+
return element
|
47
|
+
|
48
|
+
|
49
|
+
getText: (callback) ->
|
50
|
+
return "[--#{@identity}--]"
|
51
|
+
|
52
|
+
|
53
|
+
loadPreview: (element, callback = null) ->
|
54
|
+
# @options_to_save = @options
|
55
|
+
save_data = jQuery.extend({}, @options)
|
56
|
+
save_data['identity'] = @identity
|
57
|
+
console.debug("Using identity: " + @identity)
|
58
|
+
jQuery.ajax Mercury.config.snippets.previewUrl.replace(':name', @name), {
|
59
|
+
headers: Mercury.ajaxHeaders()
|
60
|
+
type: Mercury.config.snippets.method
|
61
|
+
data: save_data
|
62
|
+
success: (data) =>
|
63
|
+
@data = data
|
64
|
+
element.html(data)
|
65
|
+
callback() if callback
|
66
|
+
error: =>
|
67
|
+
Mercury.notify('Error loading the preview for the \"%s\" snippet.', @name)
|
68
|
+
}
|
69
|
+
|
70
|
+
|
71
|
+
displayOptions: ->
|
72
|
+
Mercury.snippet = @
|
73
|
+
# @options = @options_to_save if @options_to_save
|
74
|
+
Mercury.modal Mercury.config.snippets.optionsUrl.replace(':name', @name), {
|
75
|
+
title: 'Block Options',
|
76
|
+
handler: 'insertSnippet',
|
77
|
+
loadType: Mercury.config.snippets.method,
|
78
|
+
loadData: @options
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
setOptions: (@options) ->
|
83
|
+
delete(@options['authenticity_token'])
|
84
|
+
delete(@options['utf8'])
|
85
|
+
@version += 1
|
86
|
+
@history.push(@options)
|
87
|
+
Mercury.log("Set Options: ", @options)
|
88
|
+
|
89
|
+
|
90
|
+
setVersion: (version = null) ->
|
91
|
+
version = parseInt(version)
|
92
|
+
if version && @history.stack[version - 1]
|
93
|
+
@version = version - 1
|
94
|
+
@options = @history.stack[@version]
|
95
|
+
return true
|
96
|
+
return false
|
97
|
+
|
98
|
+
|
99
|
+
serialize: ->
|
100
|
+
# Mercury.log("Serialising options: " , @options_to_save)
|
101
|
+
return {
|
102
|
+
name: @name
|
103
|
+
options: @options
|
104
|
+
}
|
@@ -0,0 +1,72 @@
|
|
1
|
+
class @Mercury.SnippetToolbar extends Mercury.Toolbar
|
2
|
+
|
3
|
+
constructor: (@document, @options = {}) ->
|
4
|
+
super(@options)
|
5
|
+
|
6
|
+
|
7
|
+
build: ->
|
8
|
+
@element = jQuery('<div>', {class: 'mercury-toolbar mercury-snippet-toolbar', style: 'display:none'})
|
9
|
+
@element.appendTo(jQuery(@options.appendTo).get(0) ? 'body')
|
10
|
+
|
11
|
+
for own buttonName, options of Mercury.config.toolbars.snippetable
|
12
|
+
button = @buildButton(buttonName, options)
|
13
|
+
button.appendTo(@element) if button
|
14
|
+
|
15
|
+
|
16
|
+
bindEvents: ->
|
17
|
+
Mercury.on 'show:toolbar', (event, options) =>
|
18
|
+
return unless options.snippet
|
19
|
+
options.snippet.mouseout => @hide()
|
20
|
+
@show(options.snippet)
|
21
|
+
|
22
|
+
Mercury.on 'hide:toolbar', (event, options) =>
|
23
|
+
return unless options.type && options.type == 'snippet'
|
24
|
+
@hide(options.immediately)
|
25
|
+
|
26
|
+
@element.mousemove =>
|
27
|
+
clearTimeout(@hideTimeout)
|
28
|
+
|
29
|
+
@element.mouseout =>
|
30
|
+
@hide()
|
31
|
+
|
32
|
+
jQuery(@document).on 'scroll', =>
|
33
|
+
@position() if @visible
|
34
|
+
|
35
|
+
|
36
|
+
show: (@snippet) ->
|
37
|
+
Mercury.tooltip.hide()
|
38
|
+
@position()
|
39
|
+
@appear()
|
40
|
+
|
41
|
+
|
42
|
+
position: ->
|
43
|
+
offset = @snippet.offset()
|
44
|
+
|
45
|
+
top = offset.top + Mercury.displayRect.top - jQuery(@document).scrollTop() - @height() + 10
|
46
|
+
left = offset.left - jQuery(@document).scrollLeft()
|
47
|
+
|
48
|
+
@element.css {
|
49
|
+
top: top
|
50
|
+
left: left
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
appear: ->
|
55
|
+
clearTimeout(@hideTimeout)
|
56
|
+
return if @visible
|
57
|
+
@visible = true
|
58
|
+
@element.css({display: 'block', opacity: 0})
|
59
|
+
@element.stop().animate({opacity: 1}, 200, 'easeInOutSine')
|
60
|
+
|
61
|
+
|
62
|
+
hide: (immediately = false) ->
|
63
|
+
clearTimeout(@hideTimeout)
|
64
|
+
if immediately
|
65
|
+
@element.hide()
|
66
|
+
@visible = false
|
67
|
+
else
|
68
|
+
@hideTimeout = setTimeout 500, =>
|
69
|
+
@element.stop().animate {opacity: 0}, 300, 'easeInOutSine', =>
|
70
|
+
@element.hide()
|
71
|
+
@visible = false
|
72
|
+
|