mercury-rails 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/app/assets/images/mercury/toolbar/{snippetable → snippets}/buttons.png +0 -0
  2. data/app/assets/javascripts/mercury.js +58 -84
  3. data/app/assets/javascripts/mercury/lightview.js.coffee +1 -1
  4. data/app/assets/javascripts/mercury/mercury.js.coffee +1 -1
  5. data/app/assets/javascripts/mercury/modal.js.coffee +1 -1
  6. data/app/assets/javascripts/mercury/modals/insertmedia.js.coffee +13 -9
  7. data/app/assets/javascripts/mercury/native_extensions.js.coffee +0 -6
  8. data/app/assets/javascripts/mercury/page_editor.js.coffee +19 -19
  9. data/app/assets/javascripts/mercury/region.js.coffee +11 -10
  10. data/app/assets/javascripts/mercury/regions/{editable.js.coffee → full.coffee} +18 -18
  11. data/app/assets/javascripts/mercury/regions/image.js.coffee +13 -34
  12. data/app/assets/javascripts/mercury/regions/{markupable.js.coffee → markdown.coffee} +21 -22
  13. data/app/assets/javascripts/mercury/regions/simple.js.coffee +10 -39
  14. data/app/assets/javascripts/mercury/regions/{snippetable.js.coffee → snippets.js.coffee} +8 -7
  15. data/app/assets/javascripts/mercury/snippet.js.coffee +1 -1
  16. data/app/assets/javascripts/mercury/snippet_toolbar.js.coffee +3 -2
  17. data/app/assets/javascripts/mercury/toolbar.button.js.coffee +2 -2
  18. data/app/assets/javascripts/mercury/toolbar.button_group.js.coffee +2 -2
  19. data/app/assets/javascripts/mercury/toolbar.js.coffee +2 -2
  20. data/app/assets/javascripts/mercury/uploader.js.coffee +2 -1
  21. data/app/assets/stylesheets/mercury/all_images.css.erb +2 -2
  22. data/app/assets/stylesheets/mercury/dialog.css +2 -2
  23. data/app/assets/stylesheets/mercury/lightview.css +14 -14
  24. data/app/assets/stylesheets/mercury/modal.css +1 -1
  25. data/app/assets/stylesheets/mercury/toolbar.css +1 -1
  26. data/features/generators/install.feature +1 -1
  27. data/features/loading/loading.feature +2 -2
  28. data/features/regions/{editable → full}/advanced_editing.feature +0 -0
  29. data/features/regions/full/basic_editing.feature +196 -0
  30. data/features/regions/{editable → full}/inserting_links.feature +12 -12
  31. data/features/regions/{editable → full}/inserting_media.feature +15 -15
  32. data/features/regions/{editable → full}/inserting_snippets.feature +15 -15
  33. data/features/regions/{editable → full}/inserting_special_characters.feature +2 -2
  34. data/features/regions/full/inserting_tables.feature +109 -0
  35. data/features/regions/{editable → full}/pasting.feature +0 -0
  36. data/features/regions/{editable → full}/uploading_images.feature +0 -0
  37. data/features/regions/{markupable → markdown}/advanced_editing.feature +0 -0
  38. data/features/regions/{markupable → markdown}/basic_editing.feature +0 -0
  39. data/features/regions/{markupable → markdown}/inserting_links.feature +0 -0
  40. data/features/regions/{markupable → markdown}/inserting_media.feature +0 -0
  41. data/features/regions/{markupable → markdown}/inserting_snippets.feature +0 -0
  42. data/features/regions/{markupable → markdown}/inserting_special_characters.feature +0 -0
  43. data/features/regions/{markupable → markdown}/inserting_tables.feature +0 -0
  44. data/features/regions/{markupable → markdown}/uploading_images.feature +0 -0
  45. data/features/regions/{snippetable → snippets}/advanced_editing.feature +0 -0
  46. data/features/regions/{snippetable → snippets}/basic_editing.feature +0 -0
  47. data/features/regions/{snippetable → snippets}/inserting_snippets.feature +0 -0
  48. data/features/saving/saving.feature +8 -8
  49. data/features/step_definitions/mercury_steps.rb +13 -13
  50. data/features/support/mercury_selectors.rb +3 -3
  51. data/lib/generators/mercury/install/images/images_generator.rb +3 -0
  52. data/lib/generators/mercury/install/install_generator.rb +5 -5
  53. data/lib/mercury/version.rb +1 -1
  54. data/spec/dummy/app/assets/javascripts/application.js +0 -15
  55. data/spec/dummy/{public → app/assets/javascripts}/prototype.js +0 -0
  56. data/spec/dummy/app/assets/stylesheets/application.css.scss +110 -0
  57. data/spec/dummy/public/frame.html +1 -1
  58. data/spec/dummy/public/index.html +92 -216
  59. data/spec/javascripts/mercury/lightview_spec.js.coffee +1 -1
  60. data/spec/javascripts/mercury/modal_spec.js.coffee +1 -1
  61. data/spec/javascripts/mercury/modals/insertmedia_spec.js.coffee +41 -2
  62. data/spec/javascripts/mercury/page_editor_spec.js.coffee +19 -18
  63. data/spec/javascripts/mercury/region_spec.js.coffee +12 -14
  64. data/spec/javascripts/mercury/regions/{editable_spec.js.coffee → full_spec.js.coffee} +16 -16
  65. data/spec/javascripts/mercury/regions/image_spec.js.coffee +3 -3
  66. data/spec/javascripts/mercury/regions/{markupable_spec.js.coffee → markdown_spec.js.coffee} +18 -18
  67. data/spec/javascripts/mercury/regions/simple_spec.js.coffee +3 -3
  68. data/spec/javascripts/mercury/regions/{snippetable_spec.js.coffee → snippets_spec.js.coffee} +53 -53
  69. data/spec/javascripts/mercury/snippet_spec.js.coffee +1 -1
  70. data/spec/javascripts/mercury/snippet_toolbar_spec.js.coffee +2 -2
  71. data/spec/javascripts/mercury/toolbar.button_group_spec.js.coffee +5 -5
  72. data/spec/javascripts/mercury/toolbar.button_spec.js.coffee +6 -6
  73. data/spec/javascripts/mercury/toolbar_spec.js.coffee +4 -4
  74. data/spec/javascripts/mercury/uploader_spec.js.coffee +5 -5
  75. data/spec/javascripts/templates/mercury/page_editor.html +4 -4
  76. data/spec/javascripts/templates/mercury/region.html +1 -1
  77. data/spec/javascripts/templates/mercury/regions/full.html +1 -0
  78. data/spec/javascripts/templates/mercury/regions/image.html +1 -1
  79. data/spec/javascripts/templates/mercury/regions/markdown.html +1 -0
  80. data/spec/javascripts/templates/mercury/regions/simple.html +1 -3
  81. data/spec/javascripts/templates/mercury/regions/snippets.html +4 -0
  82. metadata +65 -75
  83. data/app/assets/javascripts/mercury_loader.js +0 -193
  84. data/app/assets/javascripts/mercury_overrides.js +0 -6
  85. data/app/assets/stylesheets/mercury_overrides.css +0 -17
  86. data/features/regions/editable/basic_editing.feature +0 -196
  87. data/features/regions/editable/inserting_tables.feature +0 -109
  88. data/spec/dummy/app/assets/stylesheets/application.css +0 -13
  89. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  90. data/spec/dummy/public/404.html +0 -26
  91. data/spec/dummy/public/422.html +0 -26
  92. data/spec/dummy/public/canvastest.html +0 -103
  93. data/spec/javascripts/templates/mercury/regions/editable.html +0 -3
  94. data/spec/javascripts/templates/mercury/regions/snippetable.html +0 -4
@@ -1,10 +1,7 @@
1
1
  class @Mercury.Region
2
- type = 'region'
3
2
 
4
3
  constructor: (@element, @window, @options = {}) ->
5
- @type = 'region' unless @type
6
- Mercury.log("building #{@type}", @element, @options)
7
-
4
+ Mercury.log("building #{@type()}", @element, @options)
8
5
  @document = @window.document
9
6
  @name = @element.attr(Mercury.config.regions.identifier)
10
7
  @history = new Mercury.HistoryBuffer()
@@ -14,6 +11,9 @@ class @Mercury.Region
14
11
  @element.data('region', @)
15
12
 
16
13
 
14
+ type: -> 'unknown'
15
+
16
+
17
17
  build: ->
18
18
 
19
19
 
@@ -33,10 +33,10 @@ class @Mercury.Region
33
33
 
34
34
  @element.on 'mousemove', (event) =>
35
35
  return if @previewing || Mercury.region != @
36
- snippet = jQuery(event.target).closest('.mercury-snippet')
36
+ snippet = jQuery(event.target).closest('[data-snippet]')
37
37
  if snippet.length
38
38
  @snippet = snippet
39
- Mercury.trigger('show:toolbar', {type: 'snippet', snippet: @snippet})
39
+ Mercury.trigger('show:toolbar', {type: 'snippet', snippet: @snippet}) if @snippet.data('snippet')
40
40
 
41
41
  @element.on 'mouseout', =>
42
42
  return if @previewing
@@ -52,7 +52,7 @@ class @Mercury.Region
52
52
  container.html(@element.html().replace(/^\s+|\s+$/g, ''))
53
53
 
54
54
  # replace snippet contents to be an identifier
55
- if filterSnippets then for snippet in container.find('.mercury-snippet')
55
+ if filterSnippets then for snippet in container.find('[data-snippet]')
56
56
  snippet = jQuery(snippet)
57
57
  snippet.attr({contenteditable: null, 'data-version': null})
58
58
  snippet.html("[#{snippet.data('snippet')}]")
@@ -63,11 +63,11 @@ class @Mercury.Region
63
63
  togglePreview: ->
64
64
  if @previewing
65
65
  @previewing = false
66
- @element.addClass(Mercury.config.regions.className).removeClass("#{Mercury.config.regions.className}-preview")
66
+ @element.attr(Mercury.config.regions.attribute, @type())
67
67
  @focus() if Mercury.region == @
68
68
  else
69
69
  @previewing = true
70
- @element.addClass("#{Mercury.config.regions.className}-preview").removeClass(Mercury.config.regions.className)
70
+ @element.removeAttr(Mercury.config.regions.attribute)
71
71
  Mercury.trigger('region:blurred', {region: @})
72
72
 
73
73
 
@@ -87,6 +87,7 @@ class @Mercury.Region
87
87
  snippets = {}
88
88
  for element in @element.find('[data-snippet]')
89
89
  snippet = Mercury.Snippet.find(jQuery(element).data('snippet'))
90
+ continue unless snippet
90
91
  snippet.setVersion(jQuery(element).data('version'))
91
92
  snippets[snippet.identity] = snippet.serialize()
92
93
  return snippets
@@ -100,7 +101,7 @@ class @Mercury.Region
100
101
 
101
102
  serialize: ->
102
103
  return {
103
- type: @type
104
+ type: @type()
104
105
  data: @dataAttributes()
105
106
  value: @content(null, true)
106
107
  snippets: @snippets()
@@ -1,12 +1,11 @@
1
- class @Mercury.Regions.Editable extends Mercury.Region
1
+ class @Mercury.Regions.Full extends Mercury.Region
2
2
  # No IE support yet because it doesn't follow the W3C standards for HTML5 contentEditable (aka designMode).
3
3
  @supported: document.designMode && !jQuery.browser.konqueror && !jQuery.browser.msie
4
4
  @supportedText: "Chrome 10+, Firefox 4+, Safari 5+"
5
-
6
- type = 'editable'
5
+ type = 'full'
6
+ type: -> type
7
7
 
8
8
  constructor: (@element, @window, @options = {}) ->
9
- @type = 'editable'
10
9
  super
11
10
 
12
11
 
@@ -26,7 +25,7 @@ class @Mercury.Regions.Editable extends Mercury.Region
26
25
  @element.get(0).contentEditable = true
27
26
 
28
27
  # make all snippets not editable, and set their versions to 1
29
- for element in @element.find('.mercury-snippet')
28
+ for element in @element.find('[data-snippet]')
30
29
  element.contentEditable = false
31
30
  jQuery(element).attr('data-version', '1')
32
31
 
@@ -47,7 +46,7 @@ class @Mercury.Regions.Editable extends Mercury.Region
47
46
 
48
47
  Mercury.on 'region:update', =>
49
48
  return if @previewing || Mercury.region != @
50
- setTimeout(1, => @selection().forceSelection(@element.get(0)))
49
+ setTimeout((=> @selection().forceSelection(@element.get(0))), 1)
51
50
  currentElement = @currentElement()
52
51
  if currentElement.length
53
52
  # setup the table editor if we're inside a table
@@ -71,14 +70,14 @@ class @Mercury.Regions.Editable extends Mercury.Region
71
70
  event.originalEvent.dataTransfer.dropEffect = 'copy'
72
71
  if jQuery.browser.webkit
73
72
  clearTimeout(@dropTimeout)
74
- @dropTimeout = setTimeout(10, => @element.trigger('possible:drop'))
73
+ @dropTimeout = setTimeout((=> @element.trigger('possible:drop')), 10)
75
74
 
76
75
  @element.on 'drop', (event) =>
77
76
  return if @previewing
78
77
 
79
78
  # handle dropping snippets
80
79
  clearTimeout(@dropTimeout)
81
- @dropTimeout = setTimeout(1, => @element.trigger('possible:drop'))
80
+ @dropTimeout = setTimeout((=> @element.trigger('possible:drop')), 1)
82
81
 
83
82
  # handle any files that were dropped
84
83
  return unless event.originalEvent.dataTransfer.files.length
@@ -115,7 +114,7 @@ class @Mercury.Regions.Editable extends Mercury.Region
115
114
  @element.on 'focus', =>
116
115
  return if @previewing
117
116
  Mercury.region = @
118
- setTimeout(1, => @selection().forceSelection(@element.get(0)))
117
+ setTimeout((=> @selection().forceSelection(@element.get(0))), 1)
119
118
  Mercury.trigger('region:focused', {region: @})
120
119
 
121
120
  @element.on 'blur', =>
@@ -194,13 +193,13 @@ class @Mercury.Regions.Editable extends Mercury.Region
194
193
 
195
194
  focus: ->
196
195
  if Mercury.region != @
197
- setTimeout(10, => @element.focus())
196
+ setTimeout((=> @element.focus()), 10)
198
197
  try
199
198
  @selection().selection.collapseToStart()
200
199
  catch e
201
200
  # intentially do nothing
202
201
  else
203
- setTimeout(10, => @element.focus())
202
+ setTimeout((=> @element.focus()), 10)
204
203
 
205
204
  Mercury.trigger('region:focused', {region: @})
206
205
  Mercury.trigger('region:update', {region: @})
@@ -277,7 +276,7 @@ class @Mercury.Regions.Editable extends Mercury.Region
277
276
  super
278
277
 
279
278
  # use a custom handler if there's one, otherwise use execCommand
280
- if handler = Mercury.config.behaviors[action] || Mercury.Regions.Editable.actions[action]
279
+ if handler = Mercury.config.behaviors[action] || Mercury.Regions.Full.actions[action]
281
280
  handler.call(@, @selection(), options)
282
281
  else
283
282
  sibling = @element.get(0).previousSibling if action == 'indent'
@@ -308,7 +307,7 @@ class @Mercury.Regions.Editable extends Mercury.Region
308
307
  @history.push(@content(null, false, true))
309
308
  else if keyCode
310
309
  # set a timeout for pushing to the history
311
- @historyTimeout = setTimeout(waitTime * 1000, => @history.push(@content(null, false, true)))
310
+ @historyTimeout = setTimeout((=> @history.push(@content(null, false, true))), waitTime * 1000)
312
311
  else
313
312
  # push to the history immediately
314
313
  @history.push(@content(null, false, true))
@@ -317,7 +316,7 @@ class @Mercury.Regions.Editable extends Mercury.Region
317
316
 
318
317
 
319
318
  selection: ->
320
- return new Mercury.Regions.Editable.Selection(@window.getSelection(), @document)
319
+ return new Mercury.Regions.Full.Selection(@window.getSelection(), @document)
321
320
 
322
321
 
323
322
  path: ->
@@ -349,7 +348,7 @@ class @Mercury.Regions.Editable extends Mercury.Region
349
348
  sanitizer = jQuery('#mercury_sanitizer', @document).focus()
350
349
 
351
350
  # set 1ms timeout to allow paste event to complete
352
- setTimeout 1, =>
351
+ setTimeout =>
353
352
  # sanitize the content
354
353
  content = @sanitize(sanitizer)
355
354
 
@@ -360,11 +359,12 @@ class @Mercury.Regions.Editable extends Mercury.Region
360
359
  # paste sanitized content
361
360
  @element.focus()
362
361
  @execCommand('insertHTML', {value: content})
362
+ , 1
363
363
 
364
364
 
365
365
  sanitize: (sanitizer) ->
366
366
  # always remove nested regions
367
- sanitizer.find(".#{Mercury.config.regions.className}").remove()
367
+ sanitizer.find("[#{Mercury.config.regions.attribute}]").remove()
368
368
 
369
369
  if Mercury.config.pasting.sanitize
370
370
  switch Mercury.config.pasting.sanitize
@@ -466,7 +466,7 @@ class @Mercury.Regions.Editable extends Mercury.Region
466
466
 
467
467
 
468
468
  # Helper class for managing selection and getting information from it
469
- class Mercury.Regions.Editable.Selection
469
+ class Mercury.Regions.Full.Selection
470
470
 
471
471
  constructor: (@selection, @context) ->
472
472
  return unless @selection.rangeCount >= 1
@@ -508,7 +508,7 @@ class Mercury.Regions.Editable.Selection
508
508
  range = @context.createRange()
509
509
 
510
510
  if @range
511
- if @commonAncestor(true).closest('.mercury-snippet').length
511
+ if @commonAncestor(true).closest('[data-snippet]').length
512
512
  lastChild = @context.createTextNode("\x00")
513
513
  element.appendChild(lastChild)
514
514
  else
@@ -1,30 +1,16 @@
1
- # The image region is designed for a single, stand-along image. It
2
- # allows drag & drop uploading of a replacement right into the page,
3
- # but no editing of other DOM attributes at this time.
4
- #
1
+ # The image region is designed for a single, stand-along image and allows drag & drop uploading of a replacement right
2
+ # into the page, but provides no editing of other DOM attributes at this time.
5
3
  class @Mercury.Regions.Image extends Mercury.Region
6
4
  @supported: document.getElementById
7
5
  @supportedText: "IE 7+, Chrome 10+, Firefox 4+, Safari 5+, Opera 8+"
8
-
9
6
  type = 'image'
7
+ type: -> type
10
8
 
11
9
  constructor: (@element, @window, @options = {}) ->
12
- @type = 'image'
13
10
  super
14
11
 
15
- build: ->
16
- # We've going to drive all the interaction with events
17
- # in bindEvent. Here we just highlight the elements to it
18
- # appears "changeable" to the user.
19
- @element.
20
- addClass( Mercury.config.regions.className ).
21
- removeClass( "#{Mercury.config.regions.className}-preview" )
22
12
 
23
13
  bindEvents: ->
24
- # This is standard stuff, take from the region parent
25
- # class. We copy it instead of super() to avoid the snippet
26
- # code.
27
- #
28
14
  Mercury.on 'mode', (event, options) => @togglePreview() if options.mode == 'preview'
29
15
 
30
16
  Mercury.on 'focus:frame', =>
@@ -35,8 +21,6 @@ class @Mercury.Regions.Image extends Mercury.Region
35
21
  return if @previewing || Mercury.region != @
36
22
  @execCommand(options.action, options) if options.action
37
23
 
38
- # The meat. D&D uploading similar to the editable class.
39
- #
40
24
  @element.on 'dragenter', (event) =>
41
25
  return if @previewing
42
26
  event.preventDefault()
@@ -49,60 +33,55 @@ class @Mercury.Regions.Image extends Mercury.Region
49
33
 
50
34
  @element.on 'drop', (event) =>
51
35
  return if @previewing
52
- # handle any files that were dropped
53
36
  if event.originalEvent.dataTransfer.files.length
54
37
  event.preventDefault()
55
- # Mercury.uploader will call a Mercury action of insertImage
56
- # as a callback. If this region is the currently focused one,
57
- # then we process the callback. Focus, then fire the upload.
58
- #
59
38
  @focus()
60
39
  Mercury.uploader(event.originalEvent.dataTransfer.files[0])
61
40
 
62
41
  @element.on 'focus', =>
63
42
  @focus()
64
43
 
44
+
65
45
  togglePreview: ->
66
46
  if @previewing
67
47
  @previewing = false
48
+ @element.attr(Mercury.config.regions.attribute, type)
68
49
  @build()
69
50
  else
70
51
  @previewing = true
71
- @element.
72
- addClass( "#{Mercury.config.regions.className}-preview" ).
73
- removeClass( Mercury.config.regions.className )
52
+ @element.removeAttr(Mercury.config.regions.attribute)
74
53
  Mercury.trigger('region:blurred', {region: @})
75
54
 
55
+
76
56
  focus: ->
77
57
  return if @previewing
78
58
  Mercury.region = @
79
59
  Mercury.trigger('region:focused', {region: @})
80
60
  Mercury.trigger('region:update', {region: @})
81
61
 
62
+
82
63
  execCommand: (action, options = {}) ->
83
- # Our history is pushed in the parent.
84
- #
85
64
  super
86
65
  handler.call(@, options) if handler = Mercury.Regions.Image.actions[action]
87
66
 
67
+
88
68
  pushHistory: () ->
89
- # Store the current image src
90
- #
91
69
  @history.push(src: @element.attr('src'))
92
70
 
71
+
93
72
  updateSrc: (src) ->
94
73
  @element.attr('src', src)
95
74
 
75
+
96
76
  serialize: ->
97
77
  return {
98
- type: @type
78
+ type: type
99
79
  data: @dataAttributes()
100
80
  attributes:
101
81
  src: @element.attr('src')
102
82
  }
103
83
 
104
- # Actions. These are all fired by execCommand.
105
- #
84
+
106
85
  @actions: {
107
86
 
108
87
  undo: -> if prev = @history.undo() then @updateSrc(prev.src)
@@ -1,16 +1,10 @@
1
- # todo:
2
- # context for the toolbar buttons and groups needs to change so we can do the following:
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.Markupable extends Mercury.Region
1
+ class @Mercury.Regions.Markdown extends Mercury.Region
7
2
  @supported: document.getElementById
8
3
  @supportedText: "IE 7+, Chrome 10+, Firefox 4+, Safari 5+, Opera 8+"
9
-
10
- type = 'markupable'
4
+ type = 'markdown'
5
+ type: -> type
11
6
 
12
7
  constructor: (@element, @window, @options = {}) ->
13
- @type = 'markupable'
14
8
  super
15
9
  @converter = new Showdown.converter()
16
10
 
@@ -18,13 +12,18 @@ class @Mercury.Regions.Markupable extends Mercury.Region
18
12
  build: ->
19
13
  width = '100%'
20
14
  height = @element.height()
21
-
22
15
  value = @element.html().replace(/^\s+|\s+$/g, '').replace('>', '>')
23
- @element.removeClass(Mercury.config.regions.className)
24
- @textarea = jQuery('<textarea>', @document).val(value)
25
- @textarea.attr('class', @element.attr('class')).addClass('mercury-textarea')
26
- @textarea.css({border: 0, background: 'transparent', display: 'block', 'overflow-y': 'hidden', width: width, height: height, fontFamily: '"Courier New", Courier, monospace'})
27
- @element.addClass(Mercury.config.regions.className)
16
+
17
+ @textarea = jQuery('<textarea>', @document).val(value).addClass('mercury-textarea')
18
+ @textarea.css
19
+ border: 0
20
+ background: 'transparent'
21
+ display: 'block'
22
+ 'overflow-y': 'hidden'
23
+ width: width
24
+ height: height
25
+ fontFamily: '"Courier New", Courier, monospace'
26
+
28
27
  @element.empty().append(@textarea)
29
28
 
30
29
  @previewElement = jQuery('<div>', @document)
@@ -164,13 +163,13 @@ class @Mercury.Regions.Markupable extends Mercury.Region
164
163
  togglePreview: ->
165
164
  if @previewing
166
165
  @previewing = false
167
- @container.addClass(Mercury.config.regions.className).removeClass("#{Mercury.config.regions.className}-preview")
166
+ @container.attr(Mercury.config.regions.attribute, type)
168
167
  @previewElement.hide()
169
168
  @element.show()
170
169
  @focus() if Mercury.region == @
171
170
  else
172
171
  @previewing = true
173
- @container.addClass("#{Mercury.config.regions.className}-preview").removeClass(Mercury.config.regions.className)
172
+ @container.removeAttr(Mercury.config.regions.attribute)
174
173
  value = @converter.makeHtml(@element.val())
175
174
  @previewElement.html(value)
176
175
  @previewElement.show()
@@ -181,7 +180,7 @@ class @Mercury.Regions.Markupable extends Mercury.Region
181
180
  execCommand: (action, options = {}) ->
182
181
  super
183
182
 
184
- handler.call(@, @selection(), options) if handler = Mercury.Regions.Markupable.actions[action]
183
+ handler.call(@, @selection(), options) if handler = Mercury.Regions.Markdown.actions[action]
185
184
  @resize()
186
185
 
187
186
 
@@ -200,7 +199,7 @@ class @Mercury.Regions.Markupable extends Mercury.Region
200
199
  @history.push(@contentAndSelection())
201
200
  else if keyCode
202
201
  # set a timeout for pushing to the history
203
- @historyTimeout = setTimeout(waitTime * 1000, => @history.push(@contentAndSelection()))
202
+ @historyTimeout = setTimeout((=> @history.push(@contentAndSelection())), waitTime * 1000)
204
203
  else
205
204
  # push to the history immediately
206
205
  @history.push(@contentAndSelection())
@@ -209,7 +208,7 @@ class @Mercury.Regions.Markupable extends Mercury.Region
209
208
 
210
209
 
211
210
  selection: ->
212
- return new Mercury.Regions.Markupable.Selection(@element)
211
+ return new Mercury.Regions.Markdown.Selection(@element)
213
212
 
214
213
 
215
214
  resize: ->
@@ -261,7 +260,7 @@ class @Mercury.Regions.Markupable extends Mercury.Region
261
260
  }
262
261
  selection.unWrapLine("#{wrapper[0]}", "#{wrapper[1]}") for wrapperName, wrapper of wrappers
263
262
  if options.value == 'blockquote'
264
- Mercury.Regions.Markupable.actions.indent.call(@, selection, options)
263
+ Mercury.Regions.Markdown.actions.indent.call(@, selection, options)
265
264
  return
266
265
  selection.wrapLine("#{wrappers[options.value][0]}", "#{wrappers[options.value][1]}")
267
266
 
@@ -289,7 +288,7 @@ class @Mercury.Regions.Markupable extends Mercury.Region
289
288
 
290
289
 
291
290
  # Helper class for managing selection and getting information from it
292
- class Mercury.Regions.Markupable.Selection
291
+ class Mercury.Regions.Markdown.Selection
293
292
 
294
293
  constructor: (@element) ->
295
294
  @el = @element.get(0)
@@ -1,16 +1,11 @@
1
- # todo:
2
- # context for the toolbar buttons and groups needs to change so we can do the following:
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
1
  class @Mercury.Regions.Simple extends Mercury.Region
7
2
  @supported: document.getElementById
8
3
  @supportedText: "IE 7+, Chrome 10+, Firefox 4+, Safari 5+, Opera 8+"
9
-
10
4
  type = 'simple'
5
+ type: -> type
11
6
 
12
7
  constructor: (@element, @window, @options = {}) ->
13
- @type = 'simple'
8
+ Mercury.log("building #{type}", @element, @options)
14
9
  super
15
10
 
16
11
 
@@ -23,9 +18,7 @@ class @Mercury.Regions.Simple extends Mercury.Region
23
18
  height = @element.height() # 'auto'
24
19
 
25
20
  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')
21
+ @textarea = jQuery('<textarea>', @document).val(value).addClass('mercury-textarea')
29
22
  @textarea.css
30
23
  border: 0
31
24
  background: 'transparent'
@@ -44,7 +37,7 @@ class @Mercury.Regions.Simple extends Mercury.Region
44
37
  display: 'inherit'
45
38
  lineHeight: 'inherit'
46
39
  textAlign: 'inherit'
47
- @element.addClass(Mercury.config.regions.className)
40
+
48
41
  @element.empty().append(@textarea)
49
42
 
50
43
  @container = @element
@@ -67,31 +60,10 @@ class @Mercury.Regions.Simple extends Mercury.Region
67
60
  @container.removeClass('focus')
68
61
  Mercury.trigger('region:blurred', {region: @})
69
62
 
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'
63
+ @bindElementEvents()
79
64
 
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
65
 
66
+ bindElementEvents: ->
95
67
  @element.on 'focus', =>
96
68
  return if @previewing
97
69
  Mercury.region = @
@@ -188,15 +160,14 @@ class @Mercury.Regions.Simple extends Mercury.Region
188
160
  if @previewing
189
161
  @previewing = false
190
162
  @element = @container
163
+ @container.attr(Mercury.config.regions.attribute, type)
191
164
  @build()
165
+ @bindElementEvents()
192
166
  @focus() if Mercury.region == @
193
- # @container.addClass(Mercury.config.regions.className).removeClass("#{Mercury.config.regions.className}-preview")
194
- # @previewElement.hide()
195
- # @element.show()
196
167
  else
197
168
  @previewing = true
198
- @container.addClass("#{Mercury.config.regions.className}-preview").removeClass(Mercury.config.regions.className)
199
169
  value = jQuery('<div></div>').text(@element.val()).html()
170
+ @container.removeAttr(Mercury.config.regions.attribute)
200
171
  @container.html(value)
201
172
  Mercury.trigger('region:blurred', {region: @})
202
173
 
@@ -223,7 +194,7 @@ class @Mercury.Regions.Simple extends Mercury.Region
223
194
  @history.push(@contentAndSelection())
224
195
  else if keyCode
225
196
  # set a timeout for pushing to the history
226
- @historyTimeout = setTimeout(waitTime * 1000, => @history.push(@contentAndSelection()))
197
+ @historyTimeout = setTimeout((=> @history.push(@contentAndSelection())), waitTime * 1000)
227
198
  else
228
199
  # push to the history immediately
229
200
  @history.push(@contentAndSelection())