mercury-rails 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. data/LICENSE +5 -0
  2. data/{README.rdoc → README.md} +150 -60
  3. data/VERSION +1 -1
  4. data/annotated_source.template +57 -0
  5. data/app/controllers/mercury_controller.rb +8 -4
  6. data/app/models/image.rb +2 -2
  7. data/app/views/layouts/mercury.html.erb +14 -0
  8. data/app/views/mercury/lightviews/about.html +7 -0
  9. data/app/views/mercury/lightviews/imageprocessor.html +3 -0
  10. data/app/views/mercury/modals/character.html +255 -0
  11. data/app/views/mercury/modals/htmleditor.html +13 -0
  12. data/app/views/mercury/modals/link.html +75 -0
  13. data/app/views/mercury/modals/media.html +82 -0
  14. data/app/views/mercury/modals/sanitizer.html +9 -0
  15. data/app/views/mercury/modals/table.html +84 -0
  16. data/app/views/mercury/palettes/backcolor.html +73 -0
  17. data/app/views/mercury/palettes/forecolor.html +73 -0
  18. data/app/views/mercury/panels/history.html +3 -0
  19. data/app/views/mercury/panels/notes.html +3 -0
  20. data/app/views/mercury/panels/snippets.html +12 -0
  21. data/app/views/mercury/selects/formatblock.html +11 -0
  22. data/app/views/mercury/selects/style.html +5 -0
  23. data/app/views/mercury/snippets/example.html.erb +1 -0
  24. data/app/views/mercury/snippets/example_options.html.erb +23 -0
  25. data/config/routes.rb +1 -1
  26. data/features/editing/basic.feature +1 -1
  27. data/features/support/paths.rb +1 -0
  28. data/lib/generators/mercury/install/install_generator.rb +14 -0
  29. data/mercury-rails.gemspec +115 -106
  30. data/spec/javascripts/mercury/dialog_spec.js.coffee +54 -38
  31. data/spec/javascripts/mercury/dialogs/backcolor_spec.js.coffee +1 -1
  32. data/spec/javascripts/mercury/dialogs/forecolor_spec.js.coffee +1 -1
  33. data/spec/javascripts/mercury/dialogs/formatblock_spec.js.coffee +1 -1
  34. data/spec/javascripts/mercury/dialogs/{objectspanel_spec.js.coffee → snippetpanel_spec.js.coffee} +4 -4
  35. data/spec/javascripts/mercury/dialogs/style_spec.js.coffee +1 -1
  36. data/spec/javascripts/mercury/history_buffer_spec.js.coffee +0 -1
  37. data/spec/javascripts/mercury/lightview_spec.js.coffee +448 -0
  38. data/spec/javascripts/mercury/mercury_spec.js.coffee +1 -1
  39. data/spec/javascripts/mercury/modal_spec.js.coffee +474 -0
  40. data/spec/javascripts/mercury/modals/htmleditor_spec.js.coffee +1 -1
  41. data/spec/javascripts/mercury/modals/insertcharacter_spec.js.coffee +1 -1
  42. data/spec/javascripts/mercury/modals/insertlink_spec.js.coffee +8 -2
  43. data/spec/javascripts/mercury/modals/insertmedia_spec.js.coffee +1 -1
  44. data/spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee +1 -1
  45. data/spec/javascripts/mercury/modals/inserttable_spec.js.coffee +1 -1
  46. data/spec/javascripts/mercury/native_extensions_spec.js.coffee +1 -1
  47. data/spec/javascripts/mercury/page_editor_spec.js.coffee +160 -20
  48. data/spec/javascripts/mercury/palette_spec.js.coffee +1 -1
  49. data/spec/javascripts/mercury/panel_spec.js.coffee +1 -1
  50. data/spec/javascripts/mercury/region_spec.js.coffee +1 -1
  51. data/spec/javascripts/mercury/regions/editable_spec.js.coffee +191 -6
  52. data/spec/javascripts/mercury/regions/markupable_spec.js.coffee +369 -0
  53. data/spec/javascripts/mercury/regions/snippetable_spec.js.coffee +1 -1
  54. data/spec/javascripts/mercury/select_spec.js.coffee +1 -1
  55. data/spec/javascripts/mercury/snippet_spec.js.coffee +3 -3
  56. data/spec/javascripts/mercury/snippet_toolbar_spec.js.coffee +2 -2
  57. data/spec/javascripts/mercury/statusbar_spec.js.coffee +91 -17
  58. data/spec/javascripts/mercury/table_editor_spec.js.coffee +5 -1
  59. data/spec/javascripts/mercury/toolbar.button_group_spec.js.coffee +1 -1
  60. data/spec/javascripts/mercury/toolbar.button_spec.js.coffee +1 -1
  61. data/spec/javascripts/mercury/toolbar.expander_spec.js.coffee +1 -1
  62. data/spec/javascripts/mercury/toolbar_spec.js.coffee +70 -15
  63. data/spec/javascripts/mercury/tooltip_spec.js.coffee +1 -1
  64. data/spec/javascripts/mercury/uploader_spec.js.coffee +9 -1
  65. data/spec/javascripts/templates/mercury/dialogs/{objectspanel.html → snippetpanel.html} +0 -0
  66. data/spec/javascripts/templates/mercury/lightview.html +13 -0
  67. data/spec/javascripts/templates/mercury/modal.html +13 -0
  68. data/spec/javascripts/templates/mercury/page_editor.html +11 -1
  69. data/spec/javascripts/templates/mercury/statusbar.html +1 -0
  70. data/spec/javascripts/templates/mercury/toolbar.html +1 -0
  71. data/{app → vendor}/assets/images/mercury/button.png +0 -0
  72. data/{app → vendor}/assets/images/mercury/clippy.png +0 -0
  73. data/{app → vendor}/assets/images/mercury/default-snippet.png +0 -0
  74. data/{app → vendor}/assets/images/mercury/loading-dark.gif +0 -0
  75. data/{app → vendor}/assets/images/mercury/loading-light.gif +0 -0
  76. data/{app → vendor}/assets/images/mercury/search-icon.png +0 -0
  77. data/vendor/assets/images/mercury/temp-logo.png +0 -0
  78. data/{app → vendor}/assets/images/mercury/toolbar/editable/buttons.png +0 -0
  79. data/{app → vendor}/assets/images/mercury/toolbar/primary/_expander.png +0 -0
  80. data/{app → vendor}/assets/images/mercury/toolbar/primary/_pressed.png +0 -0
  81. data/{app → vendor}/assets/images/mercury/toolbar/primary/historypanel.png +0 -0
  82. data/{app → vendor}/assets/images/mercury/toolbar/primary/insertcharacter.png +0 -0
  83. data/{app → vendor}/assets/images/mercury/toolbar/primary/insertlink.png +0 -0
  84. data/{app → vendor}/assets/images/mercury/toolbar/primary/insertmedia.png +0 -0
  85. data/{app → vendor}/assets/images/mercury/toolbar/primary/inserttable.png +0 -0
  86. data/{app → vendor}/assets/images/mercury/toolbar/primary/inspectorpanel.png +0 -0
  87. data/{app → vendor}/assets/images/mercury/toolbar/primary/notespanel.png +0 -0
  88. data/{app → vendor}/assets/images/mercury/toolbar/primary/preview.png +0 -0
  89. data/{app → vendor}/assets/images/mercury/toolbar/primary/redo.png +0 -0
  90. data/{app → vendor}/assets/images/mercury/toolbar/primary/save.png +0 -0
  91. data/{app/assets/images/mercury/toolbar/primary/objectspanel.png → vendor/assets/images/mercury/toolbar/primary/snippetpanel.png} +0 -0
  92. data/{app → vendor}/assets/images/mercury/toolbar/primary/undo.png +0 -0
  93. data/{app → vendor}/assets/images/mercury/toolbar/snippetable/buttons.png +0 -0
  94. data/vendor/assets/javascripts/mercury.js +302 -0
  95. data/vendor/assets/javascripts/mercury/dialog.js.coffee +157 -0
  96. data/{app → vendor}/assets/javascripts/mercury/dialogs/backcolor.js.coffee +0 -0
  97. data/{app → vendor}/assets/javascripts/mercury/dialogs/forecolor.js.coffee +0 -0
  98. data/{app → vendor}/assets/javascripts/mercury/dialogs/formatblock.js.coffee +0 -0
  99. data/{app → vendor}/assets/javascripts/mercury/dialogs/objectspanel.js.coffee +1 -1
  100. data/{app → vendor}/assets/javascripts/mercury/dialogs/style.js.coffee +0 -0
  101. data/{app → vendor}/assets/javascripts/mercury/history_buffer.js.coffee +0 -0
  102. data/vendor/assets/javascripts/mercury/lightview.js.coffee +156 -0
  103. data/vendor/assets/javascripts/mercury/lightviews/imageprocessor.js.coffee +2 -0
  104. data/vendor/assets/javascripts/mercury/mercury.js.coffee +63 -0
  105. data/{app → vendor}/assets/javascripts/mercury/modal.js.coffee +25 -17
  106. data/{app → vendor}/assets/javascripts/mercury/modals/htmleditor.js.coffee +0 -0
  107. data/{app → vendor}/assets/javascripts/mercury/modals/insertcharacter.js.coffee +0 -0
  108. data/{app → vendor}/assets/javascripts/mercury/modals/insertlink.js.coffee +3 -0
  109. data/{app → vendor}/assets/javascripts/mercury/modals/insertmedia.js.coffee +10 -2
  110. data/{app → vendor}/assets/javascripts/mercury/modals/insertsnippet.js.coffee +0 -0
  111. data/{app → vendor}/assets/javascripts/mercury/modals/inserttable.js.coffee +2 -2
  112. data/{app → vendor}/assets/javascripts/mercury/native_extensions.js.coffee +0 -0
  113. data/{app → vendor}/assets/javascripts/mercury/page_editor.js.coffee +44 -13
  114. data/{app → vendor}/assets/javascripts/mercury/palette.js.coffee +0 -0
  115. data/{app → vendor}/assets/javascripts/mercury/panel.js.coffee +0 -0
  116. data/{app → vendor}/assets/javascripts/mercury/region.js.coffee +0 -0
  117. data/{app → vendor}/assets/javascripts/mercury/regions/editable.js.coffee +58 -12
  118. data/{app → vendor}/assets/javascripts/mercury/regions/markupable.js.coffee +26 -24
  119. data/{app → vendor}/assets/javascripts/mercury/regions/snippetable.js.coffee +0 -0
  120. data/{app → vendor}/assets/javascripts/mercury/select.js.coffee +3 -0
  121. data/{app → vendor}/assets/javascripts/mercury/snippet.js.coffee +9 -5
  122. data/{app → vendor}/assets/javascripts/mercury/snippet_toolbar.js.coffee +0 -0
  123. data/vendor/assets/javascripts/mercury/statusbar.js.coffee +51 -0
  124. data/{app → vendor}/assets/javascripts/mercury/table_editor.js.coffee +9 -8
  125. data/{app → vendor}/assets/javascripts/mercury/toolbar.button.js.coffee +0 -0
  126. data/{app → vendor}/assets/javascripts/mercury/toolbar.button_group.js.coffee +0 -0
  127. data/{app → vendor}/assets/javascripts/mercury/toolbar.expander.js.coffee +0 -0
  128. data/{app → vendor}/assets/javascripts/mercury/toolbar.js.coffee +14 -1
  129. data/{app → vendor}/assets/javascripts/mercury/tooltip.js.coffee +3 -0
  130. data/{app → vendor}/assets/javascripts/mercury/uploader.js.coffee +22 -13
  131. data/vendor/assets/javascripts/{jquery-1.6.js → mercury_dependencies/jquery-1.6.js} +0 -0
  132. data/vendor/assets/javascripts/{jquery-ui-1.8.13.custom.js → mercury_dependencies/jquery-ui-1.8.13.custom.js} +0 -0
  133. data/vendor/assets/javascripts/{jquery.additions.js → mercury_dependencies/jquery.additions.js} +0 -0
  134. data/vendor/assets/javascripts/{liquidmetal.js → mercury_dependencies/liquidmetal.js} +0 -0
  135. data/vendor/assets/javascripts/{showdown.js → mercury_dependencies/showdown.js} +0 -0
  136. data/vendor/assets/javascripts/mercury_loader.js +191 -0
  137. data/{app → vendor}/assets/stylesheets/mercury.css +3 -6
  138. data/vendor/assets/stylesheets/mercury/dialog.css +199 -0
  139. data/vendor/assets/stylesheets/mercury/lightview.css +92 -0
  140. data/vendor/assets/stylesheets/mercury/mercury.css +134 -0
  141. data/vendor/assets/stylesheets/mercury/modal.css +191 -0
  142. data/{app/assets/stylesheets/mercury/statusbar.scss → vendor/assets/stylesheets/mercury/statusbar.css} +9 -1
  143. data/vendor/assets/stylesheets/mercury/toolbar.css +329 -0
  144. data/{app/assets/stylesheets/mercury/tooltip.scss → vendor/assets/stylesheets/mercury/tooltip.css} +7 -7
  145. data/vendor/assets/stylesheets/mercury/uploader.css +111 -0
  146. metadata +230 -225
  147. data/app/assets/images/mercury/toolbar/markupable/buttons.png +0 -0
  148. data/app/assets/images/mercury/toolbar/primary/todospanel.png +0 -0
  149. data/app/assets/javascripts/mercury.js +0 -30
  150. data/app/assets/javascripts/mercury/dialog.js.coffee +0 -75
  151. data/app/assets/javascripts/mercury/mercury.js.coffee +0 -286
  152. data/app/assets/javascripts/mercury/statusbar.js.coffee +0 -29
  153. data/app/assets/javascripts/mercury_loader.js +0 -98
  154. data/app/assets/stylesheets/mercury/dialog.scss +0 -179
  155. data/app/assets/stylesheets/mercury/mercury.scss +0 -127
  156. data/app/assets/stylesheets/mercury/modal.scss +0 -194
  157. data/app/assets/stylesheets/mercury/toolbar.scss +0 -415
  158. data/app/assets/stylesheets/mercury/uploader.scss +0 -109
  159. data/app/views/layouts/mercury.html.haml +0 -8
  160. data/app/views/mercury/modals/character.html.haml +0 -252
  161. data/app/views/mercury/modals/htmleditor.html.haml +0 -8
  162. data/app/views/mercury/modals/link.html.haml +0 -31
  163. data/app/views/mercury/modals/media.html.haml +0 -33
  164. data/app/views/mercury/modals/sanitizer.html.haml +0 -4
  165. data/app/views/mercury/modals/table.html.haml +0 -49
  166. data/app/views/mercury/palettes/backcolor.html.haml +0 -79
  167. data/app/views/mercury/palettes/forecolor.html.haml +0 -79
  168. data/app/views/mercury/panels/history.html.haml +0 -0
  169. data/app/views/mercury/panels/notes.html.haml +0 -0
  170. data/app/views/mercury/panels/snippets.html.haml +0 -10
  171. data/app/views/mercury/selects/formatblock.html.haml +0 -10
  172. data/app/views/mercury/selects/style.html.haml +0 -4
  173. data/app/views/mercury/snippets/example.html.haml +0 -2
  174. data/app/views/mercury/snippets/example_options.html.haml +0 -16
  175. data/log/.gitkeep +0 -0
  176. data/spec/javascripts/mercury/regions/_markupable_.js.coffee +0 -0
@@ -11,6 +11,9 @@ class @Mercury.Select extends Mercury.Dialog
11
11
 
12
12
  bindEvents: ->
13
13
  Mercury.bind 'hide:dialogs', (event, dialog) => @hide() unless dialog == @
14
+
15
+ @element.mousedown (event) => event.preventDefault()
16
+
14
17
  super
15
18
 
16
19
 
@@ -3,7 +3,11 @@ class @Mercury.Snippet
3
3
  @all: []
4
4
 
5
5
  @displayOptionsFor: (name) ->
6
- Mercury.modal("/mercury/snippets/#{name}/options", {title: 'Snippet Options', handler: 'insertSnippet', snippetName: name})
6
+ Mercury.modal Mercury.config.snippets.optionsUrl.replace(':name', name), {
7
+ title: 'Snippet Options'
8
+ handler: 'insertSnippet'
9
+ snippetName: name
10
+ }
7
11
  Mercury.snippet = null
8
12
 
9
13
 
@@ -47,8 +51,8 @@ class @Mercury.Snippet
47
51
 
48
52
 
49
53
  loadPreview: (element, callback = null) ->
50
- jQuery.ajax "/mercury/snippets/#{@name}/preview", {
51
- type: 'POST'
54
+ jQuery.ajax Mercury.config.snippets.previewUrl.replace(':name', @name), {
55
+ type: Mercury.config.snippets.method
52
56
  data: @options
53
57
  success: (data) =>
54
58
  @data = data
@@ -61,10 +65,10 @@ class @Mercury.Snippet
61
65
 
62
66
  displayOptions: ->
63
67
  Mercury.snippet = @
64
- Mercury.modal "/mercury/snippets/#{@name}/options", {
68
+ Mercury.modal Mercury.config.snippets.optionsUrl.replace(':name', @name), {
65
69
  title: 'Snippet Options',
66
70
  handler: 'insertSnippet',
67
- loadType: 'post',
71
+ loadType: Mercury.config.snippets.method,
68
72
  loadData: @options
69
73
  }
70
74
 
@@ -0,0 +1,51 @@
1
+ class @Mercury.Statusbar
2
+
3
+ constructor: (@options = {}) ->
4
+ @visible = @options.visible
5
+ @build()
6
+ @bindEvents()
7
+
8
+
9
+ build: ->
10
+ @element = jQuery('<div>', {class: 'mercury-statusbar'})
11
+ @aboutElement = jQuery('<a>', {class: "mercury-statusbar-about"}).appendTo(@element).html("Mercury Editor v#{Mercury.version}")
12
+ @pathElement = jQuery('<div>', {class: 'mercury-statusbar-path'}).appendTo(@element)
13
+
14
+ @element.css({visibility: 'hidden'}) unless @visible
15
+ @element.appendTo(jQuery(@options.appendTo).get(0) ? 'body')
16
+
17
+
18
+ bindEvents: ->
19
+ Mercury.bind 'region:update', (event, options) =>
20
+ @setPath(options.region.path()) if options.region && jQuery.type(options.region.path) == 'function'
21
+
22
+ @aboutElement.click =>
23
+ Mercury.lightview('/mercury/lightviews/about.html', {title: "About Mercury Editor v#{Mercury.version}"})
24
+
25
+
26
+ height: ->
27
+ @element.outerHeight()
28
+
29
+
30
+ top: ->
31
+ top = @element.offset().top
32
+ currentTop = if parseInt(@element.css('bottom')) < 0 then top - @element.outerHeight() else top
33
+ if @visible then currentTop else top + @element.outerHeight()
34
+
35
+
36
+ setPath: (elements) ->
37
+ path = []
38
+ path.push("<a>#{element.tagName.toLowerCase()}</a>") for element in elements
39
+
40
+ @pathElement.html("<span><strong>Path: </strong>#{path.reverse().join(' &raquo; ')}</span>")
41
+
42
+
43
+ show: ->
44
+ @visible = true
45
+ @element.css({opacity: 0, visibility: 'visible'})
46
+ @element.animate({opacity: 1}, 200, 'easeInOutSine')
47
+
48
+
49
+ hide: ->
50
+ @visible = false
51
+ @element.css({visibility: 'hidden'})
@@ -1,10 +1,10 @@
1
- @Mercury.tableEditor = (table, cell) ->
2
- Mercury.tableEditor.load(table, cell)
1
+ @Mercury.tableEditor = (table, cell, cellContent) ->
2
+ Mercury.tableEditor.load(table, cell, cellContent)
3
3
  return Mercury.tableEditor
4
4
 
5
5
  jQuery.extend Mercury.tableEditor, {
6
6
 
7
- load: (@table, @cell) ->
7
+ load: (@table, @cell, @cellContent = '') ->
8
8
  @row = @cell.parent('tr')
9
9
  @columnCount = @getColumnCount()
10
10
  @rowCount = @getRowCount()
@@ -17,7 +17,7 @@ jQuery.extend Mercury.tableEditor, {
17
17
  rowSpan = 1
18
18
  matchOptions = if position == 'after' then {right: sig.right} else {left: sig.left}
19
19
  if matching = @findCellByOptionsFor(row, matchOptions)
20
- newCell = jQuery("<#{matching.cell.get(0).tagName}>").text('')
20
+ newCell = jQuery("<#{matching.cell.get(0).tagName}>").html(@cellContent)
21
21
  @setRowspanFor(newCell, matching.height)
22
22
  if position == 'before' then matching.cell.before(newCell) else matching.cell.after(newCell)
23
23
  i += matching.height - 1
@@ -51,7 +51,7 @@ jQuery.extend Mercury.tableEditor, {
51
51
  cellCount = 0
52
52
  for cell in @row.find('th, td')
53
53
  colspan = @colspanFor(cell)
54
- newCell = jQuery("<#{cell.tagName}>").text('')
54
+ newCell = jQuery("<#{cell.tagName}>").html(@cellContent)
55
55
  @setColspanFor(newCell, colspan)
56
56
  cellCount += colspan
57
57
  if (rowspan = @rowspanFor(cell)) > 1 && position == 'after'
@@ -70,7 +70,8 @@ jQuery.extend Mercury.tableEditor, {
70
70
  @setRowspanFor(cell, rowspan + 1)
71
71
  else if rowspan - 1 >= rowCount && position == 'after'
72
72
  if rowspan - 1 == rowCount
73
- newCell = jQuery("<#{cell.tagName}>", {colspan: @colspanFor(cell)})
73
+ newCell = jQuery("<#{cell.tagName}>").html(@cellContent)
74
+ @setColspanFor(newCell, @colspanFor(cell))
74
75
  newRow.append(newCell)
75
76
  else
76
77
  @setRowspanFor(cell, rowspan + 1)
@@ -129,7 +130,7 @@ jQuery.extend Mercury.tableEditor, {
129
130
  decreaseColspan: ->
130
131
  return if @colspanFor(@cell) == 1
131
132
  @setColspanFor(@cell, @colspanFor(@cell) - 1)
132
- newCell = jQuery("<#{@cell.get(0).tagName}>").text('')
133
+ newCell = jQuery("<#{@cell.get(0).tagName}>").html(@cellContent)
133
134
  @setRowspanFor(newCell, @rowspanFor(@cell))
134
135
  @cell.after(newCell)
135
136
 
@@ -146,7 +147,7 @@ jQuery.extend Mercury.tableEditor, {
146
147
  return if sig.height == 1
147
148
  nextRow = @row.nextAll('tr')[sig.height - 2]
148
149
  if match = @findCellByOptionsFor(nextRow, {left: sig.left, forceAdjacent: true})
149
- newCell = jQuery("<#{@cell.get(0).tagName}>").text('')
150
+ newCell = jQuery("<#{@cell.get(0).tagName}>").html(@cellContent)
150
151
  @setColspanFor(newCell, @colspanFor(@cell))
151
152
  @setRowspanFor(@cell, sig.height - 1)
152
153
  if match.direction == 'before' then match.cell.before(newCell) else match.cell.after(newCell)
@@ -1,12 +1,14 @@
1
1
  class @Mercury.Toolbar
2
2
 
3
3
  constructor: (@options = {}) ->
4
+ @visible = @options.visible
4
5
  @build()
5
6
  @bindEvents()
6
7
 
7
8
 
8
9
  build: ->
9
10
  @element = jQuery('<div>', {class: 'mercury-toolbar-container', style: 'width:10000px'})
11
+ @element.css({display: 'none'}) unless @visible
10
12
  @element.appendTo(jQuery(@options.appendTo).get(0) ? 'body')
11
13
 
12
14
  for own toolbarName, buttons of Mercury.config.toolbars
@@ -68,4 +70,15 @@ class @Mercury.Toolbar
68
70
 
69
71
 
70
72
  height: ->
71
- @element.outerHeight()
73
+ if @visible then @element.outerHeight() else 0
74
+
75
+
76
+ show: ->
77
+ @visible = true
78
+ @element.css({top: -@element.outerHeight(), display: 'block'})
79
+ @element.animate({top: 0}, 200, 'easeInOutSine')
80
+
81
+
82
+ hide: ->
83
+ @visible = false
84
+ @element.hide()
@@ -25,6 +25,9 @@ jQuery.extend Mercury.tooltip, {
25
25
  bindEvents: ->
26
26
  Mercury.bind 'resize', => @position() if @visible
27
27
  @document.scroll => @position() if @visible
28
+ for parent in @forElement.parentsUntil(jQuery('body', @document))
29
+ if parent.scrollHeight > parent.clientHeight
30
+ jQuery(parent).scroll => @position() if @visible
28
31
  @element.mousedown (event) ->
29
32
  event.preventDefault()
30
33
  event.stopPropagation()
@@ -1,5 +1,5 @@
1
1
  @Mercury.uploader = (file, options) ->
2
- Mercury.uploader.show(file, options)
2
+ Mercury.uploader.show(file, options) if Mercury.config.uploading.enabled
3
3
  return Mercury.uploader
4
4
 
5
5
  jQuery.extend Mercury.uploader, {
@@ -65,15 +65,12 @@ jQuery.extend Mercury.uploader, {
65
65
 
66
66
 
67
67
  position: ->
68
- viewportWidth = jQuery(window).width()
69
- viewportHeight = jQuery(window).height()
70
-
71
68
  width = @element.outerWidth()
72
69
  height = @element.outerHeight()
73
70
 
74
71
  @element.css {
75
- top: (viewportHeight - height) / 2
76
- left: (viewportWidth - width) / 2
72
+ top: (Mercury.displayRect.height - height) / 2
73
+ left: (Mercury.displayRect.width - width) / 2
77
74
  }
78
75
 
79
76
 
@@ -93,16 +90,28 @@ jQuery.extend Mercury.uploader, {
93
90
  jQuery.each ['onloadstart', 'onprogress', 'onload', 'onabort', 'onerror'], (index, eventName) =>
94
91
  xhr.upload[eventName] = (event) => @uploaderEvents[eventName].call(@, event)
95
92
  xhr.onload = (event) =>
96
- try
97
- response = jQuery.evalJSON(event.target.responseText)
98
- Mercury.trigger('action', {action: 'insertImage', value: {src: response.url}})
99
- catch error
100
- @updateStatus('Unable to process response')
93
+ console.debug(event)
94
+ if (event.currentTarget.status >= 400)
95
+ @updateStatus('Error: Unable to upload the file')
96
+ alert("#{event.currentTarget.status}: Unable to process response")
97
+ @hide()
98
+ else
99
+ try
100
+ response =
101
+ if Mercury.config.uploading.handler
102
+ Mercury.config.uploading.handler(event.target.responseText)
103
+ else
104
+ jQuery.parseJSON(event.target.responseText)
105
+ Mercury.trigger('action', {action: 'insertImage', value: {src: response.image.url}})
106
+ catch error
107
+ @updateStatus('Error: Unable to upload the file')
108
+ alert("Unable to process response: #{error}")
109
+ @hide()
101
110
 
102
111
  xhr.open('post', Mercury.config.uploading.url, true)
103
112
  xhr.setRequestHeader('Accept', 'application/json, text/javascript, text/html, application/xml, text/xml, */*')
104
113
  xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
105
- xhr.setRequestHeader('X-CSRF-Token', Mercury.csrfToken)
114
+ xhr.setRequestHeader(Mercury.config.csrfHeader, Mercury.csrfToken)
106
115
 
107
116
  @file.readAsBinaryString (result) =>
108
117
  # build the multipart post string
@@ -158,7 +167,7 @@ jQuery.extend Mercury.uploader, {
158
167
 
159
168
  onerror: ->
160
169
  @updateStatus('Error: Unable to upload the file')
161
- @hide(1)
170
+ @hide(3)
162
171
  }
163
172
 
164
173
 
@@ -0,0 +1,191 @@
1
+ /*!
2
+ * Mercury Editor is a CoffeeScript and jQuery based WYSIWYG editor. Documentation and other useful information can be
3
+ * found at https://github.com/jejacks0n/mercury
4
+ *
5
+ * Supported browsers:
6
+ * - Firefox 4+
7
+ * - Chrome 10+
8
+ * - Safari 5+
9
+ *
10
+ * Copyright (c) 2011 Jeremy Jackson
11
+ *
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
14
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
15
+ * persons to whom the Software is furnished to do so, subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
18
+ * Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
21
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
22
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ */
26
+
27
+ // ## Default Packages
28
+ //
29
+ // Some default packages are provided for you. If you want to define your own, feel free to do so before including this
30
+ // script. These, or your own packages can be specified to the loader in query params (read below for details).
31
+ if (!window.mercuryPackages) window.mercuryPackages = {
32
+ development: {javascripts: 'mercury.js', stylesheets: 'mercury.css'},
33
+ bundled: {javascripts: 'javascripts/mercury.min.js,javascripts/mercury_dialogs.js', stylesheets: 'stylesheets/mercury.bundle.css'}
34
+ };
35
+
36
+
37
+ // ## Mercury Loader
38
+ (function() {
39
+ // Useragent detection, which we use to determine if the client is supported. We do this method instead of checking
40
+ // features because many of the features are supported in IE, but aren't implemented to the W3C spec.
41
+ var browser = {
42
+ webkit: /(webkit)[ \/]([\w.]+)/,
43
+ opera: /(opera)(?:.*version)?[ \/]([\w.]+)/,
44
+ msie: /(msie) ([\w.]+)/,
45
+ mozilla: /(mozilla)(?:.*? rv:([\w.]+))?/
46
+ };
47
+
48
+ var ua = navigator.userAgent.toLowerCase();
49
+ var match = browser.webkit.exec(ua) || browser.opera.exec(ua) || browser.msie.exec(ua) || ua.indexOf("compatible") < 0 && browser.mozilla.exec(ua) || [];
50
+ browser = {version: match[2] || "0" };
51
+ browser[match[1] || ""] = true;
52
+
53
+ // If the browser isn't supported, we don't try to do anything more. We do direct userAgent detection here because IE
54
+ // thinks it's supported but isn't -- in part because it has it's own implementation of the contentEditable spec.
55
+ if (document.getElementsByTagName && document.getElementById && document.designMode && !browser.konqueror && !browser.msie) {
56
+ // supported
57
+ } else {
58
+ return;
59
+ }
60
+
61
+ // Default options, which can be overridden by specifying them in query params to the loader script.
62
+ // You can provide any additional options to the loader, and they will be passed to the PageEditor instance when it's
63
+ // created, so for instance you could put `visible=false`, and the editor be hidden after it's created.
64
+ var options = {
65
+ // A path or url from which the javascripts and css should be loaded.
66
+ src: '/assets',
67
+ // A value defined in the packages above. Development is used by default. If you want to provide your own package
68
+ // you can just define one before including this script.
69
+ pack: 'development'
70
+ };
71
+
72
+ // Hide the document during loading so there isn't a flicker while mercury is being loaded.
73
+ var head = document.getElementsByTagName("head")[0];
74
+ if (window == top) {
75
+ var style = document.createElement('style');
76
+ var rules = document.createTextNode('body{visibility:hidden;display:none}');
77
+ style.type = 'text/css';
78
+ if (style.styleSheet) style.styleSheet.cssText = rules.nodeValue;
79
+ else style.appendChild(rules);
80
+ head.appendChild(style);
81
+ }
82
+
83
+ // Because Mercury loads the document it's going to edit into an iframe we do some tweaks to the current document to
84
+ // make that feel more seamless.
85
+ function loadMercury() {
86
+ if (document.mercuryLoaded) return;
87
+ if (timer) window.clearTimeout(timer);
88
+ document.mercuryLoaded = true;
89
+
90
+ // If the current window is the top window, it means that Mercury hasn't been loaded yet. So we load it.
91
+ if (window == top) {
92
+ var i;
93
+
94
+ // Find the loader script and determine what options were provided so the defaults can be overridden. To provide
95
+ // options just pass them in as query params (eg. `mercury_loader.js?src=/asset_path&pack=bundled`)
96
+ var scripts = document.getElementsByTagName('script');
97
+ for (i = 0; i <= scripts.length - 1; i += 1) {
98
+ var match = scripts[i].src.match(/mercury_loader\.js\??(.*)?$/);
99
+ if (!match || !match[1]) continue;
100
+
101
+ match[1].replace(/([^&=]*)=([^&=]*)/g, function (m, attr, value) {
102
+ options[attr] = value;
103
+ });
104
+ }
105
+
106
+ var pack = window.mercuryPackages[options.pack];
107
+ setTimeout(function() {
108
+ // Once we're ready to load Mercury we clear the document contents, and add in the css and javascript tags.
109
+ // Once the script has loaded we display the body again, and instantiate a new instance of Mercury.PageEditor.
110
+ document.body.innerHTML = '&nbsp;';
111
+ for (i = 0; i <= document.styleSheets.length - 1; i += 1) {
112
+ document.styleSheets[i].disabled = true
113
+ }
114
+
115
+ // Load all the stylesheets.
116
+ var stylesheets = pack.stylesheets.split(',');
117
+ for (i = 0; i <= stylesheets.length - 1; i += 1) {
118
+ var link = document.createElement('link');
119
+ link.href = options.src + '/' + stylesheets[i];
120
+ link.media = 'screen';
121
+ link.rel = 'stylesheet';
122
+ link.type = 'text/css';
123
+ head.appendChild(link);
124
+ }
125
+
126
+ // Load all the javascripts.
127
+ var javascripts = pack.javascripts.split(',');
128
+ var loaded = 0;
129
+ function loadScript(src) {
130
+ var script = document.createElement('script');
131
+ script.src = options.src + '/' + src;
132
+ script.type = 'text/javascript';
133
+ head.appendChild(script);
134
+ script.onload = function() {
135
+ loaded += 1;
136
+ if (loaded >= javascripts.length) {
137
+ document.body.style.visibility = 'visible';
138
+ document.body.style.display = 'block';
139
+ // Instantiate the PageEditor, passing in the options that were provided to the loader.
140
+ new Mercury.PageEditor(null, {visible: true});
141
+ // If there's a mercuryLoaded function available, call it. You can provide one before the loading script
142
+ // and it will be called after everything is loaded, but before everything is initialized. You can bind
143
+ // to the mercury:ready event or use Mercury.bind('ready', function() {}).
144
+ if (typeof(window.mercuryLoaded) == 'function') {
145
+ window.mercuryLoaded();
146
+ }
147
+ } else {
148
+ loadScript(javascripts[loaded]);
149
+ }
150
+ }
151
+ }
152
+ loadScript(javascripts[loaded]);
153
+ }, 1);
154
+ } else if (top.Mercury) {
155
+ // Since this file will be included in the iframe as well, we use it to tell Mercury that the document is ready to
156
+ // be worked on. By firing this event we're able to build the regions and get everything ready without having to
157
+ // wait for assets and slow javascripts to load or complete.
158
+ window.Mercury = top.Mercury;
159
+ Mercury.trigger('initialize:frame');
160
+ }
161
+ }
162
+
163
+ // This is a common technique for determining if the document has loaded yet, and is based on the methods used in
164
+ // Prototype.js. The following portions just call loadMercury once it's appropriate to do so.
165
+ //
166
+ // Support for the DOMContentLoaded event is based on work by Dan Webb, Matthias Miller, Dean Edwards, John Resig,
167
+ // and Diego Perini.
168
+ var timer;
169
+ function checkReadyState() {
170
+ if (document.readyState === 'complete') {
171
+ document.stopObserving('readystatechange', checkReadyState);
172
+ loadMercury();
173
+ }
174
+ }
175
+
176
+ function pollDoScroll() {
177
+ try { document.documentElement.doScroll('left'); }
178
+ catch(e) {
179
+ timer = pollDoScroll.defer();
180
+ return;
181
+ }
182
+ loadMercury();
183
+ }
184
+
185
+ if (document.addEventListener) {
186
+ document.addEventListener('DOMContentLoaded', loadMercury, false);
187
+ } else {
188
+ document.observe('readystatechange', checkReadyState);
189
+ if (window == top) { timer = pollDoScroll.defer(); }
190
+ }
191
+ })();