kuji-mercury-rails 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +25 -0
- data/POST_INSTALL +15 -0
- data/app/controllers/mercury/images_controller.rb +19 -0
- data/app/controllers/mercury_controller.rb +34 -0
- data/app/models/mercury/image.rb +16 -0
- data/app/views/layouts/mercury.html.erb +33 -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 +75 -0
- data/app/views/mercury/modals/media.html +82 -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 +41 -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/image/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/simple/basic_editing.feature +5 -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-rails.rb +3 -0
- data/lib/mercury/authentication.rb +8 -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 +757 -0
- data/spec/javascripts/mercury/palette_spec.js.coffee +49 -0
- data/spec/javascripts/mercury/panel_spec.js.coffee +183 -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/image_spec.js.coffee +34 -0
- data/spec/javascripts/mercury/regions/markupable_spec.js.coffee +367 -0
- data/spec/javascripts/mercury/regions/simple_spec.js.coffee +33 -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 +253 -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 +530 -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/image.html +1 -0
- data/spec/javascripts/templates/mercury/regions/simple.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.js +479 -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.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/ar.locale.js.coffee +207 -0
- data/vendor/assets/javascripts/mercury/locales/da.locale.js.coffee +211 -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 +198 -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 +92 -0
- data/vendor/assets/javascripts/mercury/modals/insertmedia.js.coffee +81 -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 +225 -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/image.js.coffee +114 -0
- data/vendor/assets/javascripts/mercury/regions/markupable.js.coffee +398 -0
- data/vendor/assets/javascripts/mercury/regions/simple.js.coffee +325 -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 +106 -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 +244 -0
- data/vendor/assets/javascripts/mercury_loader.js +193 -0
- data/vendor/assets/javascripts/mercury_overrides.js +6 -0
- data/vendor/assets/stylesheets/mercury.css +28 -0
- data/vendor/assets/stylesheets/mercury/all_images.css.erb +89 -0
- data/vendor/assets/stylesheets/mercury/dialog.css +212 -0
- data/vendor/assets/stylesheets/mercury/form.css +118 -0
- data/vendor/assets/stylesheets/mercury/lightview.css +151 -0
- data/vendor/assets/stylesheets/mercury/mercury.css +37 -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_overrides.css +17 -0
- metadata +572 -0
@@ -0,0 +1,173 @@
|
|
1
|
+
class @Mercury.Toolbar.Button
|
2
|
+
|
3
|
+
constructor: (@name, @title, @summary = null, @types = {}, @options = {}) ->
|
4
|
+
@title = Mercury.I18n(@title) if @title
|
5
|
+
@summary = Mercury.I18n(@summary) if @summary
|
6
|
+
|
7
|
+
@build()
|
8
|
+
@bindEvents()
|
9
|
+
return @element
|
10
|
+
|
11
|
+
|
12
|
+
build: ->
|
13
|
+
@element = jQuery('<div>', {title: @summary ? @title, class: "mercury-button mercury-#{@name}-button"}).html("<em>#{@title}</em>")
|
14
|
+
@element.data('expander', "<div class=\"mercury-expander-button\" data-button=\"#{@name}\"><em></em><span>#{@title}</span></div>")
|
15
|
+
|
16
|
+
@handled = {}
|
17
|
+
|
18
|
+
for own type, mixed of @types
|
19
|
+
switch type
|
20
|
+
when 'preload' then true
|
21
|
+
|
22
|
+
when 'regions'
|
23
|
+
@element.addClass('disabled')
|
24
|
+
@handled[type] = if jQuery.isFunction(mixed) then mixed.call(@, @name) else mixed
|
25
|
+
|
26
|
+
when 'toggle'
|
27
|
+
@handled[type] = true
|
28
|
+
|
29
|
+
when 'mode'
|
30
|
+
@handled[type] = if mixed == true then @name else mixed
|
31
|
+
|
32
|
+
when 'context'
|
33
|
+
@handled[type] = if jQuery.isFunction(mixed) then mixed else Mercury.Toolbar.Button.contexts[@name]
|
34
|
+
|
35
|
+
when 'palette'
|
36
|
+
@element.addClass("mercury-button-palette")
|
37
|
+
url = if jQuery.isFunction(mixed) then mixed.call(@, @name) else mixed
|
38
|
+
@handled[type] = new Mercury.Palette(url, @name, @defaultDialogOptions())
|
39
|
+
|
40
|
+
when 'select'
|
41
|
+
@element.addClass("mercury-button-select").find('em').html(@title)
|
42
|
+
url = if jQuery.isFunction(mixed) then mixed.call(@, @name) else mixed
|
43
|
+
@handled[type] = new Mercury.Select(url, @name, @defaultDialogOptions())
|
44
|
+
|
45
|
+
when 'panel'
|
46
|
+
@element.addClass('mercury-button-panel')
|
47
|
+
url = if jQuery.isFunction(mixed) then mixed.call(@, @name) else mixed
|
48
|
+
@handled['toggle'] = true
|
49
|
+
@handled[type] = new Mercury.Panel(url, @name, @defaultDialogOptions())
|
50
|
+
|
51
|
+
when 'modal'
|
52
|
+
@handled[type] = if jQuery.isFunction(mixed) then mixed.call(@, @name) else mixed
|
53
|
+
|
54
|
+
when 'lightview'
|
55
|
+
@handled[type] = if jQuery.isFunction(mixed) then mixed.call(@, @name) else mixed
|
56
|
+
|
57
|
+
else throw Mercury.I18n('Unknown button type \"%s\" used for the \"%s\" button.', type, @name)
|
58
|
+
|
59
|
+
|
60
|
+
bindEvents: ->
|
61
|
+
Mercury.on 'button', (event, options) => @element.click() if options.action == @name
|
62
|
+
Mercury.on 'mode', (event, options) => @togglePressed() if @handled.mode == options.mode && @handled.toggle
|
63
|
+
|
64
|
+
Mercury.on 'region:update', (event, options) =>
|
65
|
+
if @handled.context && options.region && jQuery.type(options.region.currentElement) == 'function'
|
66
|
+
element = options.region.currentElement()
|
67
|
+
if element.length && @handled.context.call(@, element, options.region.element)
|
68
|
+
@element.addClass('active')
|
69
|
+
else
|
70
|
+
@element.removeClass('active')
|
71
|
+
else
|
72
|
+
@element.removeClass('active')
|
73
|
+
|
74
|
+
Mercury.on 'region:focused', (event, options) =>
|
75
|
+
if @handled.regions && options.region && options.region.type
|
76
|
+
if @handled.regions.indexOf(options.region.type) > -1
|
77
|
+
@element.removeClass('disabled')
|
78
|
+
else
|
79
|
+
@element.addClass('disabled')
|
80
|
+
|
81
|
+
Mercury.on 'region:blurred', =>
|
82
|
+
@element.addClass('disabled') if @handled.regions
|
83
|
+
|
84
|
+
@element.on 'mousedown', =>
|
85
|
+
@element.addClass('active')
|
86
|
+
|
87
|
+
@element.on 'mouseup', =>
|
88
|
+
@element.removeClass('active')
|
89
|
+
|
90
|
+
@element.on 'click', (event) =>
|
91
|
+
if @element.closest('.disabled').length then return
|
92
|
+
|
93
|
+
handled = false
|
94
|
+
for own type, mixed of @handled
|
95
|
+
switch type
|
96
|
+
when 'toggle'
|
97
|
+
@togglePressed() unless @handled.mode
|
98
|
+
|
99
|
+
when 'mode'
|
100
|
+
handled = true
|
101
|
+
Mercury.trigger('mode', {mode: mixed})
|
102
|
+
|
103
|
+
when 'modal'
|
104
|
+
handled = true
|
105
|
+
Mercury.modal(@handled.modal, {title: @summary || @title, handler: @name})
|
106
|
+
|
107
|
+
when 'lightview'
|
108
|
+
handled = true
|
109
|
+
Mercury.lightview(@handled.lightview, {title: @summary || @title, handler: @name, closeButton: true})
|
110
|
+
|
111
|
+
when 'palette', 'select', 'panel'
|
112
|
+
event.stopPropagation()
|
113
|
+
handled = true
|
114
|
+
@handled[type].toggle()
|
115
|
+
|
116
|
+
Mercury.trigger('action', {action: @name}) unless handled
|
117
|
+
Mercury.trigger('focus:frame') if @options['regions'] && @options['regions'].length
|
118
|
+
|
119
|
+
|
120
|
+
defaultDialogOptions: ->
|
121
|
+
return {
|
122
|
+
title: @summary || @title
|
123
|
+
preload: @types.preload
|
124
|
+
appendTo: @options.appendDialogsTo || 'body'
|
125
|
+
closeButton: true
|
126
|
+
for: @element
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
togglePressed: ->
|
131
|
+
@element.toggleClass('pressed')
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
# Button contexts
|
136
|
+
@Mercury.Toolbar.Button.contexts =
|
137
|
+
|
138
|
+
backColor: (node) -> @element.css('background-color', node.css('background-color'))
|
139
|
+
|
140
|
+
foreColor: (node) -> @element.css('background-color', node.css('color'))
|
141
|
+
|
142
|
+
bold: (node) ->
|
143
|
+
weight = node.css('font-weight')
|
144
|
+
weight == 'bold' || weight > 400
|
145
|
+
|
146
|
+
italic: (node) -> node.css('font-style') == 'italic'
|
147
|
+
|
148
|
+
# overline is weird because <u> and <strike> override text-decoration -- we can't always tell without checking parents
|
149
|
+
overline: (node) ->
|
150
|
+
return true if node.css('text-decoration') == 'overline'
|
151
|
+
for parent in node.parentsUntil(@element)
|
152
|
+
return true if jQuery(parent).css('text-decoration') == 'overline'
|
153
|
+
return false
|
154
|
+
|
155
|
+
strikethrough: (node, region) -> node.css('text-decoration') == 'line-through' || !!node.closest('strike', region).length
|
156
|
+
|
157
|
+
underline: (node, region) -> node.css('text-decoration') == 'underline' || !!node.closest('u', region).length
|
158
|
+
|
159
|
+
subscript: (node, region) -> !!node.closest('sub', region).length
|
160
|
+
|
161
|
+
superscript: (node, region) -> !!node.closest('sup', region).length
|
162
|
+
|
163
|
+
justifyLeft: (node) -> node.css('text-align').indexOf('left') > -1
|
164
|
+
|
165
|
+
justifyCenter: (node) -> node.css('text-align').indexOf('center') > -1
|
166
|
+
|
167
|
+
justifyRight: (node) -> node.css('text-align').indexOf('right') > -1
|
168
|
+
|
169
|
+
justifyFull: (node) -> node.css('text-align').indexOf('justify') > -1
|
170
|
+
|
171
|
+
insertOrderedList: (node, region) -> !!node.closest('ol', region.element).length
|
172
|
+
|
173
|
+
insertUnorderedList: (node, region) -> !!node.closest('ul', region.element).length
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class @Mercury.Toolbar.ButtonGroup
|
2
|
+
|
3
|
+
constructor: (@name, @options = {}) ->
|
4
|
+
@build()
|
5
|
+
@bindEvents()
|
6
|
+
@regions = @options._regions
|
7
|
+
return @element
|
8
|
+
|
9
|
+
|
10
|
+
build: ->
|
11
|
+
@element = jQuery('<div>', {class: "mercury-button-group mercury-#{@name}-group"})
|
12
|
+
if @options._context || @options._regions
|
13
|
+
@element.addClass('disabled')
|
14
|
+
|
15
|
+
|
16
|
+
bindEvents: ->
|
17
|
+
Mercury.on 'region:update', (event, options) =>
|
18
|
+
context = Mercury.Toolbar.ButtonGroup.contexts[@name]
|
19
|
+
if context
|
20
|
+
if options.region && jQuery.type(options.region.currentElement) == 'function'
|
21
|
+
element = options.region.currentElement()
|
22
|
+
if element.length && context.call(@, element, options.region.element)
|
23
|
+
@element.removeClass('disabled')
|
24
|
+
else
|
25
|
+
@element.addClass('disabled')
|
26
|
+
|
27
|
+
Mercury.on 'region:focused', (event, options) =>
|
28
|
+
if @regions && options.region && options.region.type
|
29
|
+
if @regions.indexOf(options.region.type) > -1
|
30
|
+
@element.removeClass('disabled') unless @options._context
|
31
|
+
else
|
32
|
+
@element.addClass('disabled')
|
33
|
+
|
34
|
+
Mercury.on 'region:blurred', (event, options) =>
|
35
|
+
@element.addClass('disabled') if @options.regions
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
# ButtonGroup contexts
|
40
|
+
@Mercury.Toolbar.ButtonGroup.contexts =
|
41
|
+
|
42
|
+
table: (node, region) -> !!node.closest('table', region).length
|
@@ -0,0 +1,56 @@
|
|
1
|
+
class @Mercury.Toolbar.Expander extends Mercury.Palette
|
2
|
+
|
3
|
+
constructor: (@name, @options) ->
|
4
|
+
@container = @options.for
|
5
|
+
@containerWidth = @container.outerWidth()
|
6
|
+
super(null, @name, @options)
|
7
|
+
return @element
|
8
|
+
|
9
|
+
|
10
|
+
build: ->
|
11
|
+
@container.css({whiteSpace: 'normal'})
|
12
|
+
@trigger = jQuery('<div>', {class: 'mercury-toolbar-expander'}).appendTo(jQuery(@options.appendTo).get(0) ? 'body')
|
13
|
+
@element = jQuery('<div>', {class: "mercury-palette mercury-expander mercury-#{@name}-expander", style: 'display:none'})
|
14
|
+
@windowResize()
|
15
|
+
|
16
|
+
|
17
|
+
bindEvents: ->
|
18
|
+
Mercury.on 'hide:dialogs', (event, dialog) => @hide() unless dialog == @
|
19
|
+
Mercury.on 'resize', => @windowResize()
|
20
|
+
|
21
|
+
super
|
22
|
+
|
23
|
+
@trigger.click (event) =>
|
24
|
+
event.stopPropagation()
|
25
|
+
hiddenButtons = []
|
26
|
+
for button in @container.find('.mercury-button')
|
27
|
+
button = jQuery(button)
|
28
|
+
hiddenButtons.push(button.data('expander')) if button.position().top > 5
|
29
|
+
|
30
|
+
@loadContent(hiddenButtons.join(''))
|
31
|
+
@toggle()
|
32
|
+
|
33
|
+
@element.click (event) =>
|
34
|
+
buttonName = jQuery(event.target).closest('[data-button]').data('button')
|
35
|
+
button = @container.find(".mercury-#{buttonName}-button")
|
36
|
+
button.click()
|
37
|
+
|
38
|
+
|
39
|
+
windowResize: ->
|
40
|
+
if @containerWidth > jQuery(window).width() then @trigger.show() else @trigger.hide()
|
41
|
+
@hide()
|
42
|
+
|
43
|
+
|
44
|
+
position: (keepVisible) ->
|
45
|
+
@element.css({top: 0, left: 0, display: 'block', visibility: 'hidden'})
|
46
|
+
position = @trigger.offset()
|
47
|
+
width = @element.width()
|
48
|
+
|
49
|
+
position.left = position.left - width + @trigger.width() if position.left + width > jQuery(window).width()
|
50
|
+
|
51
|
+
@element.css {
|
52
|
+
top: position.top + @trigger.height()
|
53
|
+
left: position.left
|
54
|
+
display: if keepVisible then 'block' else 'none'
|
55
|
+
visibility: 'visible'
|
56
|
+
}
|
@@ -0,0 +1,86 @@
|
|
1
|
+
class @Mercury.Toolbar
|
2
|
+
|
3
|
+
constructor: (@options = {}) ->
|
4
|
+
@visible = @options.visible
|
5
|
+
@build()
|
6
|
+
@bindEvents()
|
7
|
+
|
8
|
+
|
9
|
+
build: ->
|
10
|
+
@element = jQuery('<div>', {class: 'mercury-toolbar-container', style: 'width:10000px'})
|
11
|
+
@element.css({display: 'none'}) unless @visible
|
12
|
+
@element.appendTo(jQuery(@options.appendTo).get(0) ? 'body')
|
13
|
+
|
14
|
+
for own toolbarName, buttons of Mercury.config.toolbars
|
15
|
+
continue if buttons._custom
|
16
|
+
toolbar = jQuery('<div>', {class: "mercury-toolbar mercury-#{toolbarName}-toolbar"}).appendTo(@element)
|
17
|
+
toolbar.attr('data-regions', buttons._regions) if buttons._regions
|
18
|
+
container = jQuery('<div>', {class: 'mercury-toolbar-button-container'}).appendTo(toolbar)
|
19
|
+
|
20
|
+
for own buttonName, options of buttons
|
21
|
+
continue if buttonName == '_regions'
|
22
|
+
button = @buildButton(buttonName, options)
|
23
|
+
button.appendTo(container) if button
|
24
|
+
|
25
|
+
if container.css('white-space') == 'nowrap'
|
26
|
+
expander = new Mercury.Toolbar.Expander(toolbarName, {appendTo: toolbar, for: container})
|
27
|
+
expander.appendTo(@element)
|
28
|
+
|
29
|
+
toolbar.addClass('disabled') if Mercury.config.toolbars['primary'] && toolbarName != 'primary'
|
30
|
+
|
31
|
+
@element.css({width: '100%'})
|
32
|
+
|
33
|
+
|
34
|
+
buildButton: (name, options) ->
|
35
|
+
return false if name[0] == '_'
|
36
|
+
switch jQuery.type(options)
|
37
|
+
when 'array' # button
|
38
|
+
[title, summary, handled] = options
|
39
|
+
new Mercury.Toolbar.Button(name, title, summary, handled, {appendDialogsTo: @element})
|
40
|
+
|
41
|
+
when 'object' # button group
|
42
|
+
group = new Mercury.Toolbar.ButtonGroup(name, options)
|
43
|
+
for own action, opts of options
|
44
|
+
button = @buildButton(action, opts)
|
45
|
+
button.appendTo(group) if button
|
46
|
+
group
|
47
|
+
|
48
|
+
when 'string' # separator
|
49
|
+
jQuery('<hr>', {class: "mercury-#{if options == '-' then 'line-separator' else 'separator'}"})
|
50
|
+
|
51
|
+
else throw Mercury.I18n('Unknown button structure -- please provide an array, object, or string for "%s".', name)
|
52
|
+
|
53
|
+
|
54
|
+
bindEvents: ->
|
55
|
+
Mercury.on 'region:focused', (event, options) =>
|
56
|
+
for toolbar in @element.find(".mercury-toolbar")
|
57
|
+
toolbar = jQuery(toolbar)
|
58
|
+
if regions = toolbar.data('regions')
|
59
|
+
toolbar.removeClass('disabled') if regions.split(',').indexOf(options.region.type) > -1
|
60
|
+
|
61
|
+
Mercury.on 'region:blurred', (event, options) =>
|
62
|
+
for toolbar in @element.find(".mercury-toolbar")
|
63
|
+
toolbar = jQuery(toolbar)
|
64
|
+
if regions = toolbar.data('regions')
|
65
|
+
toolbar.addClass('disabled') if regions.split(',').indexOf(options.region.type) > -1
|
66
|
+
|
67
|
+
@element.on 'click', ->
|
68
|
+
Mercury.trigger('hide:dialogs')
|
69
|
+
|
70
|
+
@element.on 'mousedown', (event) ->
|
71
|
+
event.preventDefault()
|
72
|
+
|
73
|
+
|
74
|
+
height: ->
|
75
|
+
if @visible then @element.outerHeight() else 0
|
76
|
+
|
77
|
+
|
78
|
+
show: ->
|
79
|
+
@visible = true
|
80
|
+
@element.css({top: -@element.outerHeight(), display: 'block'})
|
81
|
+
@element.animate({top: 0}, 200, 'easeInOutSine')
|
82
|
+
|
83
|
+
|
84
|
+
hide: ->
|
85
|
+
@visible = false
|
86
|
+
@element.hide()
|
@@ -0,0 +1,74 @@
|
|
1
|
+
@Mercury.tooltip = (forElement, content, options = {}) ->
|
2
|
+
Mercury.tooltip.show(forElement, content, options)
|
3
|
+
return Mercury.tooltip
|
4
|
+
|
5
|
+
jQuery.extend Mercury.tooltip,
|
6
|
+
|
7
|
+
show: (@forElement, @content, @options = {}) ->
|
8
|
+
@document = @forElement.get(0).ownerDocument
|
9
|
+
@initialize()
|
10
|
+
if @visible then @update() else @appear()
|
11
|
+
|
12
|
+
|
13
|
+
initialize: ->
|
14
|
+
return if @initialized
|
15
|
+
@build()
|
16
|
+
@bindEvents()
|
17
|
+
@initialized = true
|
18
|
+
|
19
|
+
|
20
|
+
build: ->
|
21
|
+
@element = jQuery('<div>', {class: 'mercury-tooltip'})
|
22
|
+
@element.appendTo(jQuery(@options.appendTo).get(0) ? 'body')
|
23
|
+
|
24
|
+
|
25
|
+
bindEvents: ->
|
26
|
+
Mercury.on 'resize', => @position() if @visible
|
27
|
+
|
28
|
+
@element.on 'mousedown', (event) ->
|
29
|
+
event.preventDefault()
|
30
|
+
event.stopPropagation()
|
31
|
+
|
32
|
+
for parent in @forElement.parentsUntil(jQuery('body', @document))
|
33
|
+
continue unless parent.scrollHeight > parent.clientHeight
|
34
|
+
jQuery(parent).on 'scroll', =>
|
35
|
+
@position() if @visible
|
36
|
+
|
37
|
+
jQuery(@document).on 'scroll', =>
|
38
|
+
@position() if @visible
|
39
|
+
|
40
|
+
|
41
|
+
appear: ->
|
42
|
+
@update()
|
43
|
+
|
44
|
+
@element.show()
|
45
|
+
@element.animate {opacity: 1}, 200, 'easeInOutSine', =>
|
46
|
+
@visible = true
|
47
|
+
|
48
|
+
|
49
|
+
update: ->
|
50
|
+
@element.html(@content)
|
51
|
+
@position()
|
52
|
+
|
53
|
+
|
54
|
+
position: ->
|
55
|
+
offset = @forElement.offset()
|
56
|
+
width = @element.width()
|
57
|
+
|
58
|
+
top = offset.top + (Mercury.displayRect.top - jQuery(@document).scrollTop()) + @forElement.outerHeight()
|
59
|
+
left = offset.left - jQuery(@document).scrollLeft()
|
60
|
+
|
61
|
+
left = left - (left + width + 25) - Mercury.displayRect.width if (left + width + 25) > Mercury.displayRect.width
|
62
|
+
left = if left <= 0 then 0 else left
|
63
|
+
|
64
|
+
@element.css {
|
65
|
+
top: top
|
66
|
+
left: left
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
hide: ->
|
71
|
+
return unless @initialized
|
72
|
+
@element.hide()
|
73
|
+
@visible = false
|
74
|
+
|
@@ -0,0 +1,244 @@
|
|
1
|
+
@Mercury.uploader = (file, options) ->
|
2
|
+
Mercury.uploader.show(file, options) if Mercury.config.uploading.enabled
|
3
|
+
return Mercury.uploader
|
4
|
+
|
5
|
+
jQuery.extend Mercury.uploader,
|
6
|
+
|
7
|
+
show: (file, @options = {}) ->
|
8
|
+
@file = new Mercury.uploader.File(file)
|
9
|
+
if @file.errors
|
10
|
+
alert("Error: #{@file.errors}")
|
11
|
+
return
|
12
|
+
return unless @supported()
|
13
|
+
|
14
|
+
Mercury.trigger('focus:window')
|
15
|
+
@initialize()
|
16
|
+
@appear()
|
17
|
+
|
18
|
+
|
19
|
+
initialize: ->
|
20
|
+
return if @initialized
|
21
|
+
@build()
|
22
|
+
@bindEvents()
|
23
|
+
@initialized = true
|
24
|
+
|
25
|
+
|
26
|
+
supported: ->
|
27
|
+
xhr = new XMLHttpRequest
|
28
|
+
|
29
|
+
if window.Uint8Array && window.ArrayBuffer && !XMLHttpRequest.prototype.sendAsBinary
|
30
|
+
XMLHttpRequest::sendAsBinary = (datastr) ->
|
31
|
+
ui8a = new Uint8Array(datastr.length)
|
32
|
+
ui8a[index] = (datastr.charCodeAt(index) & 0xff) for data, index in datastr
|
33
|
+
@send(ui8a.buffer)
|
34
|
+
|
35
|
+
return !!(xhr.upload && xhr.sendAsBinary && (Mercury.uploader.fileReaderSupported() || Mercury.uploader.formDataSupported()))
|
36
|
+
|
37
|
+
fileReaderSupported: ->
|
38
|
+
!!(window.FileReader)
|
39
|
+
|
40
|
+
formDataSupported: ->
|
41
|
+
!!(window.FormData)
|
42
|
+
|
43
|
+
build: ->
|
44
|
+
@element = jQuery('<div>', {class: 'mercury-uploader', style: 'display:none'})
|
45
|
+
@element.append('<div class="mercury-uploader-preview"><b><img/></b></div>')
|
46
|
+
@element.append('<div class="mercury-uploader-details"></div>')
|
47
|
+
@element.append('<div class="mercury-uploader-progress"><span></span><div class="mercury-uploader-indicator"><div><b>0%</b></div></div></div>')
|
48
|
+
|
49
|
+
@updateStatus('Processing...')
|
50
|
+
|
51
|
+
@overlay = jQuery('<div>', {class: 'mercury-uploader-overlay', style: 'display:none'})
|
52
|
+
|
53
|
+
@element.appendTo(jQuery(@options.appendTo).get(0) ? 'body')
|
54
|
+
@overlay.appendTo(jQuery(@options.appendTo).get(0) ? 'body')
|
55
|
+
|
56
|
+
|
57
|
+
bindEvents: ->
|
58
|
+
Mercury.on 'resize', => @position()
|
59
|
+
|
60
|
+
|
61
|
+
appear: ->
|
62
|
+
@fillDisplay()
|
63
|
+
@position()
|
64
|
+
|
65
|
+
@overlay.show()
|
66
|
+
@overlay.animate {opacity: 1}, 200, 'easeInOutSine', =>
|
67
|
+
@element.show()
|
68
|
+
@element.animate {opacity: 1}, 200, 'easeInOutSine', =>
|
69
|
+
@visible = true
|
70
|
+
@loadImage()
|
71
|
+
|
72
|
+
|
73
|
+
position: ->
|
74
|
+
width = @element.outerWidth()
|
75
|
+
height = @element.outerHeight()
|
76
|
+
|
77
|
+
@element.css {
|
78
|
+
top: (Mercury.displayRect.height - height) / 2
|
79
|
+
left: (Mercury.displayRect.width - width) / 2
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
fillDisplay: ->
|
84
|
+
details = [
|
85
|
+
Mercury.I18n('Name: %s', @file.name),
|
86
|
+
Mercury.I18n('Size: %s', @file.readableSize),
|
87
|
+
Mercury.I18n('Type: %s', @file.type)
|
88
|
+
]
|
89
|
+
@element.find('.mercury-uploader-details').html(details.join('<br/>'))
|
90
|
+
|
91
|
+
|
92
|
+
loadImage: ->
|
93
|
+
if Mercury.uploader.fileReaderSupported()
|
94
|
+
@file.readAsDataURL (result) =>
|
95
|
+
@element.find('.mercury-uploader-preview b').html(jQuery('<img>', {src: result}))
|
96
|
+
@upload()
|
97
|
+
else
|
98
|
+
@upload()
|
99
|
+
|
100
|
+
|
101
|
+
upload: ->
|
102
|
+
xhr = new XMLHttpRequest
|
103
|
+
jQuery.each ['onloadstart', 'onprogress', 'onload', 'onabort', 'onerror'], (index, eventName) =>
|
104
|
+
xhr.upload[eventName] = (event) => @uploaderEvents[eventName].call(@, event)
|
105
|
+
xhr.onload = (event) =>
|
106
|
+
if (event.currentTarget.status >= 400)
|
107
|
+
@updateStatus('Error: Unable to upload the file')
|
108
|
+
Mercury.notify('Unable to process response: %s', event.currentTarget.status)
|
109
|
+
@hide()
|
110
|
+
else
|
111
|
+
try
|
112
|
+
response =
|
113
|
+
if Mercury.config.uploading.handler
|
114
|
+
Mercury.config.uploading.handler(event.target.responseText)
|
115
|
+
else
|
116
|
+
jQuery.parseJSON(event.target.responseText)
|
117
|
+
src = response.url || response.image.url
|
118
|
+
throw 'Malformed response from server.' unless src
|
119
|
+
Mercury.trigger('action', {action: 'insertImage', value: {src: src}})
|
120
|
+
@hide()
|
121
|
+
catch error
|
122
|
+
@updateStatus('Error: Unable to upload the file')
|
123
|
+
Mercury.notify('Unable to process response: %s', error)
|
124
|
+
@hide()
|
125
|
+
|
126
|
+
xhr.open('post', Mercury.config.uploading.url, true)
|
127
|
+
xhr.setRequestHeader('Accept', 'application/json, text/javascript, text/html, application/xml, text/xml, */*')
|
128
|
+
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
|
129
|
+
xhr.setRequestHeader(Mercury.config.csrfHeader, Mercury.csrfToken)
|
130
|
+
|
131
|
+
# Homespun multipart uploads. Chrome 18, Firefox 11.
|
132
|
+
#
|
133
|
+
if Mercury.uploader.fileReaderSupported()
|
134
|
+
@file.readAsBinaryString (result) =>
|
135
|
+
|
136
|
+
multipart = new Mercury.uploader.MultiPartPost(Mercury.config.uploading.inputName, @file, result)
|
137
|
+
|
138
|
+
# update the content size so we can calculate
|
139
|
+
@file.updateSize(multipart.delta)
|
140
|
+
|
141
|
+
# set the content type and send
|
142
|
+
xhr.setRequestHeader('Content-Type', 'multipart/form-data; boundary=' + multipart.boundary)
|
143
|
+
xhr.sendAsBinary(multipart.body)
|
144
|
+
|
145
|
+
# FormData based. Safari 5.1.2.
|
146
|
+
#
|
147
|
+
else
|
148
|
+
formData = new FormData()
|
149
|
+
formData.append(Mercury.config.uploading.inputName, @file.file, @file.file.name)
|
150
|
+
|
151
|
+
xhr.send(formData)
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
updateStatus: (message, loaded) ->
|
156
|
+
@element.find('.mercury-uploader-progress span').html(Mercury.I18n(message).toString())
|
157
|
+
if loaded
|
158
|
+
percent = Math.floor(loaded * 100 / @file.size) + '%'
|
159
|
+
@element.find('.mercury-uploader-indicator div').css({width: percent})
|
160
|
+
@element.find('.mercury-uploader-indicator b').html(percent).show()
|
161
|
+
|
162
|
+
|
163
|
+
hide: (delay = 0) ->
|
164
|
+
setTimeout delay * 1000, =>
|
165
|
+
@element.animate {opacity: 0}, 200, 'easeInOutSine', =>
|
166
|
+
@overlay.animate {opacity: 0}, 200, 'easeInOutSine', =>
|
167
|
+
@overlay.hide()
|
168
|
+
@element.hide()
|
169
|
+
@reset()
|
170
|
+
@visible = false
|
171
|
+
Mercury.trigger('focus:frame')
|
172
|
+
|
173
|
+
|
174
|
+
reset: ->
|
175
|
+
@element.find('.mercury-uploader-preview b').html('')
|
176
|
+
@element.find('.mercury-uploader-indicator div').css({width: 0})
|
177
|
+
@element.find('.mercury-uploader-indicator b').html('0%').hide()
|
178
|
+
@updateStatus('Processing...')
|
179
|
+
|
180
|
+
|
181
|
+
uploaderEvents:
|
182
|
+
onloadstart: -> @updateStatus('Uploading...')
|
183
|
+
|
184
|
+
onprogress: (event) -> @updateStatus('Uploading...', event.loaded)
|
185
|
+
|
186
|
+
onabort: ->
|
187
|
+
@updateStatus('Aborted')
|
188
|
+
@hide(1)
|
189
|
+
|
190
|
+
onload: ->
|
191
|
+
@updateStatus('Successfully uploaded...', @file.size)
|
192
|
+
|
193
|
+
onerror: ->
|
194
|
+
@updateStatus('Error: Unable to upload the file')
|
195
|
+
@hide(3)
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
class Mercury.uploader.File
|
200
|
+
|
201
|
+
constructor: (@file) ->
|
202
|
+
@fullSize = @size = @file.size || @file.fileSize
|
203
|
+
@readableSize = @size.toBytes()
|
204
|
+
@name = @file.name || @file.fileName
|
205
|
+
@type = @file.type || @file.fileType
|
206
|
+
|
207
|
+
# add any errors if we need to
|
208
|
+
errors = []
|
209
|
+
errors.push(Mercury.I18n('Too large')) if @size >= Mercury.config.uploading.maxFileSize
|
210
|
+
errors.push(Mercury.I18n('Unsupported format')) unless Mercury.config.uploading.allowedMimeTypes.indexOf(@type) > -1
|
211
|
+
@errors = errors.join(' / ') if errors.length
|
212
|
+
|
213
|
+
|
214
|
+
readAsDataURL: (callback = null) ->
|
215
|
+
reader = new FileReader()
|
216
|
+
reader.readAsDataURL(@file)
|
217
|
+
reader.onload = => callback(reader.result) if callback
|
218
|
+
|
219
|
+
|
220
|
+
readAsBinaryString: (callback = null) ->
|
221
|
+
reader = new FileReader()
|
222
|
+
reader.readAsBinaryString(@file)
|
223
|
+
reader.onload = => callback(reader.result) if callback
|
224
|
+
|
225
|
+
|
226
|
+
updateSize: (delta) ->
|
227
|
+
@fullSize = @size + delta
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
class Mercury.uploader.MultiPartPost
|
232
|
+
|
233
|
+
constructor: (@inputName, @file, @contents, @formInputs = {}) ->
|
234
|
+
@boundary = 'Boundaryx20072377098235644401115438165x'
|
235
|
+
@body = ''
|
236
|
+
@buildBody()
|
237
|
+
@delta = @body.length - @file.size
|
238
|
+
|
239
|
+
|
240
|
+
buildBody: ->
|
241
|
+
boundary = '--' + @boundary
|
242
|
+
for own name, value of @formInputs
|
243
|
+
@body += "#{boundary}\r\nContent-Disposition: form-data; name=\"#{name}\"\r\n\r\n#{unescape(encodeURIComponent(value))}\r\n"
|
244
|
+
@body += "#{boundary}\r\nContent-Disposition: form-data; name=\"#{@inputName}\"; filename=\"#{@file.name}\"\r\nContent-Type: #{@file.type}\r\nContent-Transfer-Encoding: binary\r\n\r\n#{@contents}\r\n#{boundary}--"
|