mercury-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +152 -0
  3. data/VERSION +1 -0
  4. data/app/assets/images/mercury/button.png +0 -0
  5. data/app/assets/images/mercury/clippy.png +0 -0
  6. data/app/assets/images/mercury/default-snippet.png +0 -0
  7. data/app/assets/images/mercury/loading-dark.gif +0 -0
  8. data/app/assets/images/mercury/loading-light.gif +0 -0
  9. data/app/assets/images/mercury/search-icon.png +0 -0
  10. data/app/assets/images/mercury/toolbar/editable/buttons.png +0 -0
  11. data/app/assets/images/mercury/toolbar/markupable/buttons.png +0 -0
  12. data/app/assets/images/mercury/toolbar/primary/_expander.png +0 -0
  13. data/app/assets/images/mercury/toolbar/primary/_pressed.png +0 -0
  14. data/app/assets/images/mercury/toolbar/primary/historypanel.png +0 -0
  15. data/app/assets/images/mercury/toolbar/primary/insertcharacter.png +0 -0
  16. data/app/assets/images/mercury/toolbar/primary/insertlink.png +0 -0
  17. data/app/assets/images/mercury/toolbar/primary/insertmedia.png +0 -0
  18. data/app/assets/images/mercury/toolbar/primary/inserttable.png +0 -0
  19. data/app/assets/images/mercury/toolbar/primary/inspectorpanel.png +0 -0
  20. data/app/assets/images/mercury/toolbar/primary/notespanel.png +0 -0
  21. data/app/assets/images/mercury/toolbar/primary/objectspanel.png +0 -0
  22. data/app/assets/images/mercury/toolbar/primary/preview.png +0 -0
  23. data/app/assets/images/mercury/toolbar/primary/redo.png +0 -0
  24. data/app/assets/images/mercury/toolbar/primary/save.png +0 -0
  25. data/app/assets/images/mercury/toolbar/primary/todospanel.png +0 -0
  26. data/app/assets/images/mercury/toolbar/primary/undo.png +0 -0
  27. data/app/assets/images/mercury/toolbar/snippetable/buttons.png +0 -0
  28. data/app/assets/javascripts/mercury.js +30 -0
  29. data/app/assets/javascripts/mercury/dialog.js.coffee +75 -0
  30. data/app/assets/javascripts/mercury/dialogs/backcolor.js.coffee +6 -0
  31. data/app/assets/javascripts/mercury/dialogs/forecolor.js.coffee +6 -0
  32. data/app/assets/javascripts/mercury/dialogs/formatblock.js.coffee +4 -0
  33. data/app/assets/javascripts/mercury/dialogs/objectspanel.js.coffee +10 -0
  34. data/app/assets/javascripts/mercury/dialogs/style.js.coffee +4 -0
  35. data/app/assets/javascripts/mercury/history_buffer.js.coffee +30 -0
  36. data/app/assets/javascripts/mercury/mercury.js.coffee +293 -0
  37. data/app/assets/javascripts/mercury/modal.js.coffee +177 -0
  38. data/app/assets/javascripts/mercury/modals/htmleditor.js.coffee +10 -0
  39. data/app/assets/javascripts/mercury/modals/insertcharacter.js.coffee +4 -0
  40. data/app/assets/javascripts/mercury/modals/insertlink.js.coffee +92 -0
  41. data/app/assets/javascripts/mercury/modals/insertmedia.js.coffee +72 -0
  42. data/app/assets/javascripts/mercury/modals/insertsnippet.js.coffee +11 -0
  43. data/app/assets/javascripts/mercury/modals/inserttable.js.coffee +56 -0
  44. data/app/assets/javascripts/mercury/native_extensions.js.coffee +47 -0
  45. data/app/assets/javascripts/mercury/page_editor.js.coffee +139 -0
  46. data/app/assets/javascripts/mercury/palette.js.coffee +29 -0
  47. data/app/assets/javascripts/mercury/panel.js.coffee +97 -0
  48. data/app/assets/javascripts/mercury/region.js.coffee +103 -0
  49. data/app/assets/javascripts/mercury/regions/editable.js.coffee +546 -0
  50. data/app/assets/javascripts/mercury/regions/markupable.js.coffee +380 -0
  51. data/app/assets/javascripts/mercury/regions/snippetable.js.coffee +127 -0
  52. data/app/assets/javascripts/mercury/select.js.coffee +40 -0
  53. data/app/assets/javascripts/mercury/snippet.js.coffee +92 -0
  54. data/app/assets/javascripts/mercury/snippet_toolbar.js.coffee +69 -0
  55. data/app/assets/javascripts/mercury/statusbar.js.coffee +25 -0
  56. data/app/assets/javascripts/mercury/table_editor.js.coffee +266 -0
  57. data/app/assets/javascripts/mercury/toolbar.button.js.coffee +152 -0
  58. data/app/assets/javascripts/mercury/toolbar.button_group.js.coffee +42 -0
  59. data/app/assets/javascripts/mercury/toolbar.expander.js.coffee +56 -0
  60. data/app/assets/javascripts/mercury/toolbar.js.coffee +72 -0
  61. data/app/assets/javascripts/mercury/tooltip.js.coffee +67 -0
  62. data/app/assets/javascripts/mercury/uploader.js.coffee +213 -0
  63. data/app/assets/javascripts/mercury/websocket.js.coffee +34 -0
  64. data/app/assets/stylesheets/mercury.css +31 -0
  65. data/app/assets/stylesheets/mercury/dialog.scss +178 -0
  66. data/app/assets/stylesheets/mercury/mercury.scss +119 -0
  67. data/app/assets/stylesheets/mercury/modal.scss +192 -0
  68. data/app/assets/stylesheets/mercury/statusbar.scss +23 -0
  69. data/app/assets/stylesheets/mercury/toolbar.scss +417 -0
  70. data/app/assets/stylesheets/mercury/tooltip.scss +26 -0
  71. data/app/assets/stylesheets/mercury/uploader.scss +109 -0
  72. data/app/controllers/images_controller.rb +19 -0
  73. data/app/controllers/mercury_controller.rb +20 -0
  74. data/app/models/image.rb +14 -0
  75. data/app/views/layouts/mercury.html.haml +12 -0
  76. data/app/views/mercury/modals/character.html.haml +252 -0
  77. data/app/views/mercury/modals/htmleditor.html.haml +8 -0
  78. data/app/views/mercury/modals/link.html.haml +31 -0
  79. data/app/views/mercury/modals/media.html.haml +33 -0
  80. data/app/views/mercury/modals/sanitizer.html.haml +4 -0
  81. data/app/views/mercury/modals/table.html.haml +49 -0
  82. data/app/views/mercury/palettes/backcolor.html.haml +79 -0
  83. data/app/views/mercury/palettes/forecolor.html.haml +79 -0
  84. data/app/views/mercury/panels/history.html.haml +0 -0
  85. data/app/views/mercury/panels/notes.html.haml +0 -0
  86. data/app/views/mercury/panels/snippets.html.haml +10 -0
  87. data/app/views/mercury/selects/formatblock.html.haml +10 -0
  88. data/app/views/mercury/selects/style.html.haml +4 -0
  89. data/app/views/mercury/snippets/example.html.haml +2 -0
  90. data/app/views/mercury/snippets/example_options.html.haml +16 -0
  91. data/config/engine.rb +6 -0
  92. data/config/routes.rb +15 -0
  93. data/db/migrate/20110526035601_create_images.rb +11 -0
  94. data/features/editing/basic.feature +11 -0
  95. data/features/step_definitions/debug_steps.rb +14 -0
  96. data/features/step_definitions/web_steps.rb +211 -0
  97. data/features/support/env.rb +46 -0
  98. data/features/support/paths.rb +35 -0
  99. data/features/support/selectors.rb +42 -0
  100. data/lib/mercury-rails.rb +4 -0
  101. data/log/.gitkeep +0 -0
  102. data/mercury-rails.gemspec +230 -0
  103. data/spec/javascripts/mercury/dialog_spec.js.coffee +258 -0
  104. data/spec/javascripts/mercury/history_buffer_spec.js.coffee +79 -0
  105. data/spec/javascripts/mercury/mercury_spec.js.coffee +52 -0
  106. data/spec/javascripts/mercury/native_extensions_spec.js.coffee +66 -0
  107. data/spec/javascripts/mercury/page_editor_spec.js.coffee +435 -0
  108. data/spec/javascripts/mercury/palette_spec.js.coffee +51 -0
  109. data/spec/javascripts/mercury/panel_spec.js.coffee +147 -0
  110. data/spec/javascripts/mercury/region_spec.js.coffee +261 -0
  111. data/spec/javascripts/mercury/regions/_editable_.js.coffee +0 -0
  112. data/spec/javascripts/mercury/regions/_markupable_.js.coffee +0 -0
  113. data/spec/javascripts/mercury/regions/snippetable_spec.js.coffee +368 -0
  114. data/spec/javascripts/mercury/select_spec.js.coffee +51 -0
  115. data/spec/javascripts/mercury/snippet_spec.js.coffee +246 -0
  116. data/spec/javascripts/mercury/snippet_toolbar_spec.js.coffee +186 -0
  117. data/spec/javascripts/mercury/statusbar_spec.js.coffee +78 -0
  118. data/spec/javascripts/mercury/table_editor_spec.js.coffee +192 -0
  119. data/spec/javascripts/mercury/toolbar.button_group_spec.js.coffee +92 -0
  120. data/spec/javascripts/mercury/toolbar.button_spec.js.coffee +341 -0
  121. data/spec/javascripts/mercury/toolbar.expander_spec.js.coffee +120 -0
  122. data/spec/javascripts/mercury/toolbar_spec.js.coffee +152 -0
  123. data/spec/javascripts/mercury/tooltip_spec.js.coffee +188 -0
  124. data/spec/javascripts/mercury/uploader_spec.js.coffee +512 -0
  125. data/spec/javascripts/responses/blank.html +1 -0
  126. data/spec/javascripts/spec_helper.js +513 -0
  127. data/spec/javascripts/templates/mercury/dialog.html +2 -0
  128. data/spec/javascripts/templates/mercury/page_editor.html +24 -0
  129. data/spec/javascripts/templates/mercury/palette.html +16 -0
  130. data/spec/javascripts/templates/mercury/panel.html +16 -0
  131. data/spec/javascripts/templates/mercury/region.html +2 -0
  132. data/spec/javascripts/templates/mercury/regions/snippetable.html +4 -0
  133. data/spec/javascripts/templates/mercury/select.html +16 -0
  134. data/spec/javascripts/templates/mercury/snippet.html +1 -0
  135. data/spec/javascripts/templates/mercury/snippet_toolbar.html +16 -0
  136. data/spec/javascripts/templates/mercury/statusbar.html +7 -0
  137. data/spec/javascripts/templates/mercury/table_editor.html +65 -0
  138. data/spec/javascripts/templates/mercury/toolbar.button.html +64 -0
  139. data/spec/javascripts/templates/mercury/toolbar.button_group.html +9 -0
  140. data/spec/javascripts/templates/mercury/toolbar.expander.html +18 -0
  141. data/spec/javascripts/templates/mercury/toolbar.html +10 -0
  142. data/spec/javascripts/templates/mercury/tooltip.html +12 -0
  143. data/spec/javascripts/templates/mercury/uploader.html +11 -0
  144. data/vendor/assets/javascripts/jquery-1.6.js +8865 -0
  145. data/vendor/assets/javascripts/jquery-ui-1.8.13.custom.min.js +249 -0
  146. data/vendor/assets/javascripts/jquery-ui-1.8.13.sortable.custom.js +1078 -0
  147. data/vendor/assets/javascripts/jquery.easing.js +173 -0
  148. data/vendor/assets/javascripts/jquery.json2.js +178 -0
  149. data/vendor/assets/javascripts/jquery.serialize_object.js +16 -0
  150. data/vendor/assets/javascripts/jquery.ujs.js +289 -0
  151. data/vendor/assets/javascripts/liquidmetal.js +88 -0
  152. data/vendor/assets/javascripts/showdown.js +1362 -0
  153. metadata +364 -0
@@ -0,0 +1,177 @@
1
+ @Mercury.modal = (url, options = {}) ->
2
+ Mercury.modal.show(url, options)
3
+ return Mercury.modal
4
+
5
+ $.extend Mercury.modal, {
6
+
7
+ minWidth: 400
8
+
9
+ show: (@url, @options = {}) ->
10
+ Mercury.trigger('focus:window')
11
+ @initialize()
12
+ if @visible then @update() else @appear()
13
+
14
+
15
+ initialize: ->
16
+ return if @initialized
17
+ @build()
18
+ @bindEvents()
19
+ @initialized = true
20
+
21
+
22
+ build: ->
23
+ @element = $('<div>', {class: 'mercury-modal loading'})
24
+ @element.html('<h1 class="mercury-modal-title"><span></span><a>&times;</a></h1>')
25
+ @element.append('<div class="mercury-modal-content-container"><div class="mercury-modal-content"></div></div>')
26
+
27
+ @overlay = $('<div>', {class: 'mercury-modal-overlay'})
28
+
29
+ @titleElement = @element.find('.mercury-modal-title')
30
+ @contentContainerElement = @element.find('.mercury-modal-content-container')
31
+ @contentElement = @element.find('.mercury-modal-content')
32
+
33
+ @element.appendTo($(@options.appendTo).get(0) ? 'body')
34
+ @overlay.appendTo($(@options.appendTo).get(0) ? 'body')
35
+
36
+ @titleElement.find('span').html(@options.title)
37
+
38
+
39
+ bindEvents: ->
40
+ Mercury.bind 'refresh', => @resize(true)
41
+ Mercury.bind 'resize', => @position()
42
+
43
+ @overlay.click => @hide()
44
+
45
+ @titleElement.find('a').click => @hide()
46
+
47
+
48
+ appear: ->
49
+ @position()
50
+
51
+ @overlay.show()
52
+ @overlay.animate {opacity: 1}, 200, 'easeInOutSine', =>
53
+ @element.css({top: -@element.height()})
54
+ @setTitle()
55
+ @element.show()
56
+ @element.animate {top: 0}, 200, 'easeInOutSine', =>
57
+ @visible = true
58
+ @load()
59
+
60
+
61
+ resize: (keepVisible) ->
62
+ # TODO: resizing is a bit shitty when the modal has panes and is scrollable
63
+ visibility = if keepVisible then 'visible' else 'hidden'
64
+
65
+ viewportHeight = $(window).height()
66
+ titleHeight = @titleElement.outerHeight()
67
+
68
+ width = @contentElement.outerWidth()
69
+
70
+ @contentPane.css({height: 'auto'}) if @contentPane
71
+ @contentElement.css({height: 'auto', visibility: visibility, display: 'block'})
72
+
73
+ height = @contentElement.outerHeight() + titleHeight
74
+
75
+ width = @minWidth if width < @minWidth
76
+ height = viewportHeight - 20 if height > viewportHeight - 20 || @options.fullHeight
77
+
78
+ @element.stop().animate {left: ($(window).width() - width) / 2, width: width, height: height}, 200, 'easeInOutSine', =>
79
+ @contentElement.css({visibility: 'visible', display: 'block'})
80
+ if @contentPane.length
81
+ @contentElement.css({height: height - titleHeight, overflow: 'visible'})
82
+ controlHeight = if @contentControl.length then @contentControl.outerHeight() else 0
83
+ @contentPane.css({height: height - titleHeight - controlHeight - 40})
84
+ @contentPane.find('.mercury-modal-pane').css({width: width - 40})
85
+ else
86
+ @contentElement.css({height: height - titleHeight, overflow: 'auto'})
87
+
88
+
89
+ position: ->
90
+ viewportWidth = $(window).width()
91
+ viewportHeight = $(window).height()
92
+
93
+ @contentPane.css({height: 'auto'}) if @contentPane
94
+ @contentElement.css({height: 'auto'})
95
+ @element.css({width: 'auto', height: 'auto', display: 'block', visibility: 'hidden'})
96
+
97
+ width = @element.width()
98
+ height = @element.height()
99
+
100
+ width = @minWidth if width < @minWidth
101
+ height = viewportHeight - 20 if height > viewportHeight - 20 || @options.fullHeight
102
+
103
+ titleHeight = @titleElement.outerHeight()
104
+ if @contentPane && @contentPane.length
105
+ @contentElement.css({height: height - titleHeight, overflow: 'visible'})
106
+ controlHeight = if @contentControl.length then @contentControl.outerHeight() else 0
107
+ @contentPane.css({height: height - titleHeight - controlHeight - 40})
108
+ @contentPane.find('.mercury-modal-pane').css({width: width - 40})
109
+ else
110
+ @contentElement.css({height: height - titleHeight, overflow: 'auto'})
111
+
112
+ @element.css {
113
+ left: (viewportWidth - width) / 2
114
+ width: width,
115
+ height: height,
116
+ display: if @visible then 'block' else 'none',
117
+ visibility: 'visible'
118
+ }
119
+
120
+
121
+ update: ->
122
+ @reset()
123
+ @resize()
124
+ @load()
125
+
126
+
127
+ load: ->
128
+ @element.addClass('loading')
129
+ @setTitle()
130
+ $.ajax @url, {
131
+ type: @options.loadType || 'get'
132
+ data: @options.loadData
133
+ success: (data) => @loadContent(data)
134
+ error: =>
135
+ @hide()
136
+ alert("Mercury was unable to load #{@url} for the modal.")
137
+ }
138
+
139
+
140
+ loadContent: (data, options) ->
141
+ @initialize()
142
+ @options = options || @options
143
+ @setTitle()
144
+ @loaded = true
145
+ @element.removeClass('loading')
146
+ @contentElement.html(data)
147
+ @contentElement.css({display: 'none', visibility: 'hidden'})
148
+
149
+ # for complex modal content, we provide panes and controls
150
+ @contentPane = @element.find('.mercury-modal-pane-container')
151
+ @contentControl = @element.find('.mercury-modal-controls')
152
+
153
+ @options.afterLoad.call(@) if @options.afterLoad
154
+ if @options.handler && Mercury.modalHandlers[@options.handler]
155
+ Mercury.modalHandlers[@options.handler].call(@)
156
+
157
+ @resize()
158
+
159
+
160
+ setTitle: ->
161
+ @titleElement.find('span').html(@options.title)
162
+
163
+
164
+ reset: ->
165
+ @titleElement.find('span').html('')
166
+ @contentElement.html('')
167
+
168
+
169
+ hide: ->
170
+ Mercury.trigger('focus:frame')
171
+ @element.hide()
172
+ @overlay.hide()
173
+ @reset()
174
+
175
+ @visible = false
176
+
177
+ }
@@ -0,0 +1,10 @@
1
+ @Mercury.modalHandlers.htmleditor = ->
2
+ # fill the text area with the content
3
+ @element.find('textarea').val(Mercury.region.html(null, true, false))
4
+
5
+ # replace the contents on form submit
6
+ @element.find('form').submit (event) =>
7
+ event.preventDefault()
8
+ value = @element.find('textarea').val().replace(/\n/g, '')
9
+ Mercury.trigger('action', {action: 'replaceHTML', value: value})
10
+ @hide()
@@ -0,0 +1,4 @@
1
+ @Mercury.modalHandlers.insertcharacter = ->
2
+ @element.find('.character').click ->
3
+ Mercury.trigger('action', {action: 'insertHTML', value: "&#{$(@).attr('data-entity')};"})
4
+ Mercury.modal.hide()
@@ -0,0 +1,92 @@
1
+ @Mercury.modalHandlers.insertlink = ->
2
+ # make the inputs work with the radio buttons
3
+ @element.find('label input').click (event) ->
4
+ $(@).closest('label').next('.selectable').focus()
5
+
6
+ @element.find('.selectable').focus ->
7
+ $(@).prev('label').find('input[type=radio]').prop("checked", true)
8
+
9
+ # show/hide the link target options on target change
10
+ @element.find('#link_target').change =>
11
+ @element.find(".link-target-options").hide()
12
+ @element.find("##{@element.find('#link_target').val()}_options").show()
13
+ @resize(true)
14
+
15
+ # fill the existing bookmark select
16
+ bookmarkSelect = @element.find('#link_existing_bookmark')
17
+ for link in $('a[name]', window.mercuryInstance.document)
18
+ bookmarkSelect.append($('<option>', {value: $(link).attr('name')}).text($(link).text()))
19
+
20
+ # get the selection and initialize its information into the form
21
+ if Mercury.region && Mercury.region.selection
22
+ selection = Mercury.region.selection()
23
+
24
+ # if we're editing a link prefill the information
25
+ container = selection.commonAncestor(true).closest('a') if selection.commonAncestor
26
+ if container && container.length
27
+ existingLink = container
28
+
29
+ # don't allow changing the content on edit
30
+ @element.find('#link_text_container').hide()
31
+
32
+ # fill in the external url or bookmark select based on what it looks like
33
+ if container.attr('href') && container.attr('href').indexOf('#') == 0
34
+ bookmarkSelect.val(container.attr('href').replace(/[^#]*#/, ''))
35
+ bookmarkSelect.prev('label').find('input[type=radio]').prop("checked", true)
36
+ else
37
+ @element.find('#link_external_url').val(container.attr('href'))
38
+
39
+ # if it has a name, assume it's a bookmark target
40
+ if container.attr('name')
41
+ newBookmarkInput = @element.find('#link_new_bookmark')
42
+ newBookmarkInput.val(container.attr('name'))
43
+ newBookmarkInput.prev('label').find('input[type=radio]').prop("checked", true)
44
+
45
+ # if it has a target, select it, and try to pull options out
46
+ if container.attr('target')
47
+ @element.find('#link_target').val(container.attr('target'))
48
+
49
+ # if it's a popup window
50
+ if container.attr('href') && container.attr('href').indexOf('javascript:void') == 0
51
+ href = container.attr('href')
52
+ @element.find('#link_external_url').val(href.match(/window.open\('([^']+)',/)[1])
53
+ @element.find('#link_target').val('popup')
54
+ @element.find('#link_popup_width').val(href.match(/width=(\d+),/)[1])
55
+ @element.find('#link_popup_height').val(href.match(/height=(\d+),/)[1])
56
+ @element.find('#popup_options').show()
57
+
58
+ # get the text content
59
+ @element.find('#link_text').val(selection.textContent())
60
+
61
+ # build the link on form submission
62
+ @element.find('form').submit (event) =>
63
+ event.preventDefault()
64
+
65
+ content = @element.find('#link_text').val()
66
+ target = @element.find('#link_target').val()
67
+ type = @element.find('input[name=link_type]:checked').val()
68
+
69
+ switch type
70
+ when 'existing_bookmark' then attrs = {href: "##{@element.find('#link_existing_bookmark').val()}"}
71
+ when 'new_bookmark' then attrs = {name: "##{@element.find('#link_new_bookmark').val()}"}
72
+ else attrs = {href: @element.find("#link_#{type}").val()}
73
+
74
+ switch target
75
+ when 'popup'
76
+ args = {
77
+ width: parseInt(@element.find('#link_popup_width').val()) || 500,
78
+ height: parseInt(@element.find('#link_popup_height').val()) || 500,
79
+ menubar: 'no',
80
+ toolbar: 'no'
81
+ }
82
+ attrs['href'] = "javascript:void(window.open('#{attrs['href']}', 'popup_window', '#{$.param(args).replace(/&/g, ',')}'))"
83
+ else attrs['target'] = target if target
84
+
85
+ value = {tagName: 'a', attrs: attrs, content: content}
86
+
87
+ if existingLink
88
+ Mercury.trigger('action', {action: 'replaceLink', value: value, node: existingLink.get(0)})
89
+ else
90
+ Mercury.trigger('action', {action: 'insertLink', value: value})
91
+
92
+ Mercury.modal.hide()
@@ -0,0 +1,72 @@
1
+ @Mercury.modalHandlers.insertmedia = ->
2
+ # make the inputs work with the radio buttons, and options
3
+ @element.find('label input').click (event) ->
4
+ $(@).closest('label').next('.selectable').focus()
5
+
6
+ @element.find('.selectable').focus (event) =>
7
+ element = $(event.target)
8
+ element.prev('label').find('input[type=radio]').prop("checked", true)
9
+
10
+ @element.find(".media-options").hide()
11
+ @element.find("##{element.attr('id').replace('media_', '')}").show()
12
+ @resize(true)
13
+
14
+ # get the selection and initialize its information into the form
15
+ if Mercury.region && Mercury.region.selection
16
+ selection = Mercury.region.selection()
17
+
18
+ # if we're editing an image prefill the information
19
+ if selection.is && image = selection.is('img')
20
+ @element.find('#media_image_url').val(image.attr('src'))
21
+ @element.find('#media_image_alignment').val(image.attr('align'))
22
+
23
+ # if we're editing an iframe (assume it's a video for now)
24
+ if selection.is && iframe = selection.is('iframe')
25
+ src = iframe.attr('src')
26
+ if src.indexOf('http://www.youtube.com') > -1
27
+ # it's a youtube video
28
+ @element.find('#media_youtube_url').val("http://youtu.be/#{src.match(/\/embed\/(\w+)/)[1]}")
29
+ @element.find('#media_youtube_width').val(iframe.attr('width'))
30
+ @element.find('#media_youtube_height').val(iframe.attr('height'))
31
+ @element.find('#media_youtube_url').focus()
32
+ else if src.indexOf('http://player.vimeo.com') > -1
33
+ # it's a vimeo video
34
+ @element.find('#media_vimeo_url').val("http://vimeo.com/#{src.match(/\/video\/(\w+)/)[1]}")
35
+ @element.find('#media_vimeo_width').val(iframe.attr('width'))
36
+ @element.find('#media_vimeo_height').val(iframe.attr('height'))
37
+ @element.find('#media_vimeo_url').focus()
38
+
39
+ # build the image or youtube embed on form submission
40
+ @element.find('form').submit (event) =>
41
+ event.preventDefault()
42
+
43
+ type = @element.find('input[name=media_type]:checked').val()
44
+
45
+ switch type
46
+ when 'image_url'
47
+ attrs = {src: @element.find('#media_image_url').val()}
48
+ attrs['align'] = alignment if alignment = @element.find('#media_image_alignment').val()
49
+ Mercury.trigger('action', {action: 'insertImage', value: attrs})
50
+
51
+ when 'youtube_url'
52
+ code = @element.find('#media_youtube_url').val().replace('http://youtu.be/', '')
53
+ value = $('<iframe>', {
54
+ width: @element.find('#media_youtube_width').val() || 560,
55
+ height: @element.find('#media_youtube_height').val() || 349,
56
+ src: "http://www.youtube.com/embed/#{code}?wmode=transparent",
57
+ frameborder: 0,
58
+ allowfullscreen: 'true'
59
+ })
60
+ Mercury.trigger('action', {action: 'insertHTML', value: value})
61
+
62
+ when 'vimeo_url'
63
+ code = @element.find('#media_vimeo_url').val().replace('http://vimeo.com/', '')
64
+ value = $('<iframe>', {
65
+ width: @element.find('#media_vimeo_width').val() || 400,
66
+ height: @element.find('#media_vimeo_height').val() || 225,
67
+ src: "http://player.vimeo.com/video/#{code}?title=1&amp;byline=1&amp;portrait=0&amp;color=ffffff",
68
+ frameborder: 0,
69
+ })
70
+ Mercury.trigger('action', {action: 'insertHTML', value: value})
71
+
72
+ Mercury.modal.hide()
@@ -0,0 +1,11 @@
1
+ @Mercury.modalHandlers.insertsnippet = ->
2
+ @element.find('form').submit (event) =>
3
+ event.preventDefault()
4
+ if Mercury.snippet
5
+ snippet = Mercury.snippet
6
+ snippet.setOptions(@element.find('form').serializeObject())
7
+ Mercury.snippet = null
8
+ else
9
+ snippet = Mercury.Snippet.create('example', @element.find('form').serializeObject())
10
+ Mercury.trigger('action', {action: 'insertsnippet', value: snippet})
11
+ @hide()
@@ -0,0 +1,56 @@
1
+ @Mercury.modalHandlers.inserttable = ->
2
+ table = @element.find('#table_display table')
3
+ # make td's selectable
4
+ table.click (event) =>
5
+ cell = $(event.target)
6
+ table = cell.closest('table')
7
+ table.find('.selected').removeClass('selected')
8
+ cell.addClass('selected')
9
+ @tableEditor = Mercury.tableEditor(table, cell)
10
+
11
+ # select the first td
12
+ firstCell = table.find('td, th').first()
13
+ firstCell.addClass('selected')
14
+ Mercury.tableEditor(table, firstCell)
15
+
16
+ # make the buttons work
17
+ @element.find('input.action').click (event) =>
18
+ action = $(event.target).attr('name')
19
+ switch action
20
+
21
+ when 'insertrowbefore' then Mercury.tableEditor.addRow('before')
22
+ when 'insertrowafter' then Mercury.tableEditor.addRow('after')
23
+ when 'deleterow' then Mercury.tableEditor.removeRow()
24
+ when 'insertcolumnbefore' then Mercury.tableEditor.addColumn('before')
25
+ when 'insertcolumnafter' then Mercury.tableEditor.addColumn('after')
26
+ when 'deletecolumn' then Mercury.tableEditor.removeColumn()
27
+ when 'increasecolspan' then Mercury.tableEditor.increaseColspan()
28
+ when 'decreasecolspan' then Mercury.tableEditor.decreaseColspan()
29
+ when 'increaserowspan' then Mercury.tableEditor.increaseRowspan()
30
+ when 'decreaserowspan' then Mercury.tableEditor.decreaseRowspan()
31
+
32
+ # set the alignment
33
+ @element.find('#table_alignment').change =>
34
+ table.attr({align: @element.find('#table_alignment').val()})
35
+
36
+ # set the border
37
+ @element.find('#table_border').change =>
38
+ table.attr({border: parseInt(@element.find('#table_border').val())})
39
+
40
+ # set the cellspacing
41
+ @element.find('#table_spacing').change =>
42
+ table.attr({cellspacing: parseInt(@element.find('#table_spacing').val())})
43
+
44
+ # build the table on form submission
45
+ @element.find('form').submit (event) =>
46
+ event.preventDefault()
47
+ table.find('.selected').removeClass('selected')
48
+ table.find('td, th').html('&nbsp;')
49
+
50
+ tableHTML = $('<div>').html(table).html()
51
+ tableHTML = tableHTML.replace(/^\s+|\n/gm, '')
52
+ tableHTML = tableHTML.replace(/(<\/.*?>|<table.*?>|<tbody>|<tr>)/g, '$1\n')
53
+
54
+ Mercury.trigger('action', {action: 'insertHTML', value: tableHTML})
55
+ Mercury.modal.hide()
56
+
@@ -0,0 +1,47 @@
1
+ String::titleize = ->
2
+ @[0].toUpperCase() + @slice(1)
3
+
4
+
5
+ String::toHex = ->
6
+ # todo: we should handle alpha as well
7
+ return @ if @[0] == '#'
8
+ @replace /rgba?\((\d+)[\s|\,]?\s(\d+)[\s|\,]?\s(\d+)\)/gi, (a, r, g, b) ->
9
+ "##{parseInt(r).toHex()}#{parseInt(g).toHex()}#{parseInt(b).toHex()}"
10
+
11
+
12
+ String::singleDiff = (that) ->
13
+ diff = ''
14
+ for char, index in that
15
+ if char != @[index]
16
+ re = new RegExp(@substr(index).regExpEscape().replace(/^\s+|^(&nbsp;)+/g, '') + '$', 'm')
17
+ diff = that.substr(index).replace(re, '')
18
+ break
19
+ return diff
20
+
21
+
22
+ String::regExpEscape = ->
23
+ specials = ['/','.','*','+','?','|','(',')','[',']','{','}','\\']
24
+ escaped = new RegExp('(\\' + specials.join('|\\') + ')', 'g')
25
+ return @replace(escaped, '\\$1')
26
+
27
+
28
+ String::sanitizeHTML = ->
29
+ element = $('<div>').html(@.toString())
30
+ element.find('style').remove()
31
+ content = element.text()
32
+ content = content.replace(/\n+/g, '<br/>').replace(/.*<!--.*-->/g, '').replace(/^(<br\/>)+|(<br\/>\s*)+$/g, '')
33
+ return content
34
+
35
+
36
+ Number::toHex = ->
37
+ result = @toString(16).toUpperCase()
38
+ return if result[1] then result else "0#{result}"
39
+
40
+
41
+ Number::toBytes = ->
42
+ bytes = parseInt(@)
43
+ i = 0
44
+ while 1023 < bytes
45
+ bytes /= 1024
46
+ i += 1
47
+ return if i then "#{bytes.toFixed(2)}#{['', ' kb', ' Mb', ' Gb', ' Tb', ' Pb', ' Eb'][i]}" else "#{bytes} bytes"