kuji-mercury-rails 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (231) hide show
  1. data/LICENSE +25 -0
  2. data/POST_INSTALL +15 -0
  3. data/app/controllers/mercury/images_controller.rb +19 -0
  4. data/app/controllers/mercury_controller.rb +34 -0
  5. data/app/models/mercury/image.rb +16 -0
  6. data/app/views/layouts/mercury.html.erb +33 -0
  7. data/app/views/mercury/lightviews/about.html +11 -0
  8. data/app/views/mercury/modals/character.html +255 -0
  9. data/app/views/mercury/modals/htmleditor.html +13 -0
  10. data/app/views/mercury/modals/link.html +75 -0
  11. data/app/views/mercury/modals/media.html +82 -0
  12. data/app/views/mercury/modals/table.html +84 -0
  13. data/app/views/mercury/palettes/backcolor.html +73 -0
  14. data/app/views/mercury/palettes/forecolor.html +73 -0
  15. data/app/views/mercury/panels/history.html +3 -0
  16. data/app/views/mercury/panels/notes.html +3 -0
  17. data/app/views/mercury/panels/snippets.html +12 -0
  18. data/app/views/mercury/selects/formatblock.html +11 -0
  19. data/app/views/mercury/selects/style.html +5 -0
  20. data/app/views/mercury/snippets/example/options.html.erb +34 -0
  21. data/app/views/mercury/snippets/example/preview.html.erb +1 -0
  22. data/config/engine.rb +41 -0
  23. data/db/migrate/20110526035601_create_mercury_images.rb +11 -0
  24. data/features/loading/loading.feature +22 -0
  25. data/features/loading/navigating.feature +77 -0
  26. data/features/loading/user_interface.feature +67 -0
  27. data/features/regions/editable/advanced_editing.feature +0 -0
  28. data/features/regions/editable/basic_editing.feature +195 -0
  29. data/features/regions/editable/inserting_links.feature +98 -0
  30. data/features/regions/editable/inserting_media.feature +110 -0
  31. data/features/regions/editable/inserting_snippets.feature +102 -0
  32. data/features/regions/editable/inserting_special_characters.feature +24 -0
  33. data/features/regions/editable/inserting_tables.feature +109 -0
  34. data/features/regions/editable/pasting.feature +0 -0
  35. data/features/regions/editable/uploading_images.feature +0 -0
  36. data/features/regions/image/uploading_images.feature +0 -0
  37. data/features/regions/markupable/advanced_editing.feature +0 -0
  38. data/features/regions/markupable/basic_editing.feature +0 -0
  39. data/features/regions/markupable/inserting_links.feature +0 -0
  40. data/features/regions/markupable/inserting_media.feature +0 -0
  41. data/features/regions/markupable/inserting_snippets.feature +0 -0
  42. data/features/regions/markupable/inserting_special_characters.feature +0 -0
  43. data/features/regions/markupable/inserting_tables.feature +0 -0
  44. data/features/regions/markupable/uploading_images.feature +0 -0
  45. data/features/regions/simple/basic_editing.feature +5 -0
  46. data/features/regions/snippetable/advanced_editing.feature +0 -0
  47. data/features/regions/snippetable/basic_editing.feature +0 -0
  48. data/features/regions/snippetable/inserting_snippets.feature +0 -0
  49. data/features/saving/saving.feature +33 -0
  50. data/features/step_definitions/debug_steps.rb +14 -0
  51. data/features/step_definitions/mercury_steps.rb +438 -0
  52. data/features/step_definitions/web_steps.rb +211 -0
  53. data/features/support/env.rb +46 -0
  54. data/features/support/mercury_contents.rb +25 -0
  55. data/features/support/mercury_selectors.rb +148 -0
  56. data/features/support/paths.rb +38 -0
  57. data/features/support/selectors.rb +44 -0
  58. data/lib/generators/mercury/install/install_generator.rb +49 -0
  59. data/lib/generators/mercury/install/templates/mongoid_paperclip_image.rb +17 -0
  60. data/lib/mercury-rails.rb +3 -0
  61. data/lib/mercury/authentication.rb +8 -0
  62. data/spec/javascripts/mercury/dialog_spec.js.coffee +281 -0
  63. data/spec/javascripts/mercury/dialogs/backcolor_spec.js.coffee +37 -0
  64. data/spec/javascripts/mercury/dialogs/forecolor_spec.js.coffee +37 -0
  65. data/spec/javascripts/mercury/dialogs/formatblock_spec.js.coffee +25 -0
  66. data/spec/javascripts/mercury/dialogs/snippetpanel_spec.js.coffee +30 -0
  67. data/spec/javascripts/mercury/dialogs/style_spec.js.coffee +25 -0
  68. data/spec/javascripts/mercury/history_buffer_spec.js.coffee +76 -0
  69. data/spec/javascripts/mercury/lightview_spec.js.coffee +497 -0
  70. data/spec/javascripts/mercury/mercury_spec.js.coffee +132 -0
  71. data/spec/javascripts/mercury/modal_spec.js.coffee +504 -0
  72. data/spec/javascripts/mercury/modals/htmleditor_spec.js.coffee +30 -0
  73. data/spec/javascripts/mercury/modals/insertcharacter_spec.js.coffee +29 -0
  74. data/spec/javascripts/mercury/modals/insertlink_spec.js.coffee +220 -0
  75. data/spec/javascripts/mercury/modals/insertmedia_spec.js.coffee +167 -0
  76. data/spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee +52 -0
  77. data/spec/javascripts/mercury/modals/inserttable_spec.js.coffee +160 -0
  78. data/spec/javascripts/mercury/native_extensions_spec.js.coffee +60 -0
  79. data/spec/javascripts/mercury/page_editor_spec.js.coffee +757 -0
  80. data/spec/javascripts/mercury/palette_spec.js.coffee +49 -0
  81. data/spec/javascripts/mercury/panel_spec.js.coffee +183 -0
  82. data/spec/javascripts/mercury/region_spec.js.coffee +298 -0
  83. data/spec/javascripts/mercury/regions/editable_spec.js.coffee +561 -0
  84. data/spec/javascripts/mercury/regions/image_spec.js.coffee +34 -0
  85. data/spec/javascripts/mercury/regions/markupable_spec.js.coffee +367 -0
  86. data/spec/javascripts/mercury/regions/simple_spec.js.coffee +33 -0
  87. data/spec/javascripts/mercury/regions/snippetable_spec.js.coffee +370 -0
  88. data/spec/javascripts/mercury/select_spec.js.coffee +49 -0
  89. data/spec/javascripts/mercury/snippet_spec.js.coffee +253 -0
  90. data/spec/javascripts/mercury/snippet_toolbar_spec.js.coffee +184 -0
  91. data/spec/javascripts/mercury/statusbar_spec.js.coffee +150 -0
  92. data/spec/javascripts/mercury/table_editor_spec.js.coffee +194 -0
  93. data/spec/javascripts/mercury/toolbar.button_group_spec.js.coffee +90 -0
  94. data/spec/javascripts/mercury/toolbar.button_spec.js.coffee +360 -0
  95. data/spec/javascripts/mercury/toolbar.expander_spec.js.coffee +118 -0
  96. data/spec/javascripts/mercury/toolbar_spec.js.coffee +222 -0
  97. data/spec/javascripts/mercury/tooltip_spec.js.coffee +186 -0
  98. data/spec/javascripts/mercury/uploader_spec.js.coffee +530 -0
  99. data/spec/javascripts/spec_helper.js +513 -0
  100. data/spec/javascripts/templates/mercury/dialog.html +2 -0
  101. data/spec/javascripts/templates/mercury/dialogs/backcolor.html +5 -0
  102. data/spec/javascripts/templates/mercury/dialogs/forecolor.html +5 -0
  103. data/spec/javascripts/templates/mercury/dialogs/formatblock.html +3 -0
  104. data/spec/javascripts/templates/mercury/dialogs/snippetpanel.html +16 -0
  105. data/spec/javascripts/templates/mercury/dialogs/style.html +3 -0
  106. data/spec/javascripts/templates/mercury/lightview.html +13 -0
  107. data/spec/javascripts/templates/mercury/modal.html +13 -0
  108. data/spec/javascripts/templates/mercury/modals/htmleditor.html +5 -0
  109. data/spec/javascripts/templates/mercury/modals/insertcharacter.html +5 -0
  110. data/spec/javascripts/templates/mercury/modals/insertlink.html +30 -0
  111. data/spec/javascripts/templates/mercury/modals/insertmedia.html +35 -0
  112. data/spec/javascripts/templates/mercury/modals/insertsnippet.html +6 -0
  113. data/spec/javascripts/templates/mercury/modals/inserttable.html +27 -0
  114. data/spec/javascripts/templates/mercury/page_editor.html +35 -0
  115. data/spec/javascripts/templates/mercury/palette.html +16 -0
  116. data/spec/javascripts/templates/mercury/panel.html +16 -0
  117. data/spec/javascripts/templates/mercury/region.html +2 -0
  118. data/spec/javascripts/templates/mercury/regions/editable.html +3 -0
  119. data/spec/javascripts/templates/mercury/regions/image.html +1 -0
  120. data/spec/javascripts/templates/mercury/regions/simple.html +3 -0
  121. data/spec/javascripts/templates/mercury/regions/snippetable.html +4 -0
  122. data/spec/javascripts/templates/mercury/select.html +16 -0
  123. data/spec/javascripts/templates/mercury/snippet.html +1 -0
  124. data/spec/javascripts/templates/mercury/snippet_toolbar.html +16 -0
  125. data/spec/javascripts/templates/mercury/statusbar.html +8 -0
  126. data/spec/javascripts/templates/mercury/table_editor.html +65 -0
  127. data/spec/javascripts/templates/mercury/toolbar.button.html +64 -0
  128. data/spec/javascripts/templates/mercury/toolbar.button_group.html +9 -0
  129. data/spec/javascripts/templates/mercury/toolbar.expander.html +18 -0
  130. data/spec/javascripts/templates/mercury/toolbar.html +11 -0
  131. data/spec/javascripts/templates/mercury/tooltip.html +12 -0
  132. data/spec/javascripts/templates/mercury/uploader.html +11 -0
  133. data/vendor/assets/images/mercury/button.png +0 -0
  134. data/vendor/assets/images/mercury/close.png +0 -0
  135. data/vendor/assets/images/mercury/default-snippet.png +0 -0
  136. data/vendor/assets/images/mercury/loading-dark.gif +0 -0
  137. data/vendor/assets/images/mercury/loading-light.gif +0 -0
  138. data/vendor/assets/images/mercury/missing-image.png +0 -0
  139. data/vendor/assets/images/mercury/search-icon.png +0 -0
  140. data/vendor/assets/images/mercury/temp-logo.png +0 -0
  141. data/vendor/assets/images/mercury/toolbar/editable/buttons.png +0 -0
  142. data/vendor/assets/images/mercury/toolbar/primary/_expander.png +0 -0
  143. data/vendor/assets/images/mercury/toolbar/primary/_pressed.png +0 -0
  144. data/vendor/assets/images/mercury/toolbar/primary/historypanel.png +0 -0
  145. data/vendor/assets/images/mercury/toolbar/primary/insertcharacter.png +0 -0
  146. data/vendor/assets/images/mercury/toolbar/primary/insertlink.png +0 -0
  147. data/vendor/assets/images/mercury/toolbar/primary/insertmedia.png +0 -0
  148. data/vendor/assets/images/mercury/toolbar/primary/inserttable.png +0 -0
  149. data/vendor/assets/images/mercury/toolbar/primary/inspectorpanel.png +0 -0
  150. data/vendor/assets/images/mercury/toolbar/primary/notespanel.png +0 -0
  151. data/vendor/assets/images/mercury/toolbar/primary/preview.png +0 -0
  152. data/vendor/assets/images/mercury/toolbar/primary/redo.png +0 -0
  153. data/vendor/assets/images/mercury/toolbar/primary/save.png +0 -0
  154. data/vendor/assets/images/mercury/toolbar/primary/snippetpanel.png +0 -0
  155. data/vendor/assets/images/mercury/toolbar/primary/undo.png +0 -0
  156. data/vendor/assets/images/mercury/toolbar/snippetable/buttons.png +0 -0
  157. data/vendor/assets/javascripts/mercury.js +479 -0
  158. data/vendor/assets/javascripts/mercury/dependencies/jquery-1.7.js +9300 -0
  159. data/vendor/assets/javascripts/mercury/dependencies/jquery-ui-1.8.13.custom.js +1328 -0
  160. data/vendor/assets/javascripts/mercury/dependencies/jquery.additions.js +206 -0
  161. data/vendor/assets/javascripts/mercury/dependencies/jquery.htmlClean.js +527 -0
  162. data/vendor/assets/javascripts/mercury/dependencies/liquidmetal.js +88 -0
  163. data/vendor/assets/javascripts/mercury/dependencies/showdown.js +1340 -0
  164. data/vendor/assets/javascripts/mercury/dialog.js.coffee +159 -0
  165. data/vendor/assets/javascripts/mercury/dialogs/backcolor.js.coffee +6 -0
  166. data/vendor/assets/javascripts/mercury/dialogs/forecolor.js.coffee +6 -0
  167. data/vendor/assets/javascripts/mercury/dialogs/formatblock.js.coffee +4 -0
  168. data/vendor/assets/javascripts/mercury/dialogs/snippetpanel.js.coffee +10 -0
  169. data/vendor/assets/javascripts/mercury/dialogs/style.js.coffee +4 -0
  170. data/vendor/assets/javascripts/mercury/finalize.js.coffee +3 -0
  171. data/vendor/assets/javascripts/mercury/history_buffer.js.coffee +30 -0
  172. data/vendor/assets/javascripts/mercury/lightview.js.coffee +205 -0
  173. data/vendor/assets/javascripts/mercury/locales/ar.locale.js.coffee +207 -0
  174. data/vendor/assets/javascripts/mercury/locales/da.locale.js.coffee +211 -0
  175. data/vendor/assets/javascripts/mercury/locales/de.locale.js.coffee +206 -0
  176. data/vendor/assets/javascripts/mercury/locales/es.locale.js.coffee +211 -0
  177. data/vendor/assets/javascripts/mercury/locales/example.local.js.coffee +211 -0
  178. data/vendor/assets/javascripts/mercury/locales/fr.locale.js.coffee +211 -0
  179. data/vendor/assets/javascripts/mercury/locales/it.locale.js.coffee +208 -0
  180. data/vendor/assets/javascripts/mercury/locales/ko.local.js.coffee +206 -0
  181. data/vendor/assets/javascripts/mercury/locales/nl.locale.js.coffee +206 -0
  182. data/vendor/assets/javascripts/mercury/locales/pt.locale.js.coffee +211 -0
  183. data/vendor/assets/javascripts/mercury/locales/sv.local.js.coffee +209 -0
  184. data/vendor/assets/javascripts/mercury/locales/swedish_chef.locale.js.coffee +213 -0
  185. data/vendor/assets/javascripts/mercury/mercury.js.coffee +109 -0
  186. data/vendor/assets/javascripts/mercury/modal.js.coffee +198 -0
  187. data/vendor/assets/javascripts/mercury/modals/htmleditor.js.coffee +11 -0
  188. data/vendor/assets/javascripts/mercury/modals/insertcharacter.js.coffee +4 -0
  189. data/vendor/assets/javascripts/mercury/modals/insertlink.js.coffee +92 -0
  190. data/vendor/assets/javascripts/mercury/modals/insertmedia.js.coffee +81 -0
  191. data/vendor/assets/javascripts/mercury/modals/insertsnippet.js.coffee +12 -0
  192. data/vendor/assets/javascripts/mercury/modals/inserttable.js.coffee +54 -0
  193. data/vendor/assets/javascripts/mercury/native_extensions.js.coffee +55 -0
  194. data/vendor/assets/javascripts/mercury/page_editor.js.coffee +225 -0
  195. data/vendor/assets/javascripts/mercury/palette.js.coffee +29 -0
  196. data/vendor/assets/javascripts/mercury/panel.js.coffee +115 -0
  197. data/vendor/assets/javascripts/mercury/plugins/save_as_xml/mercury/page_editor.js.coffee +28 -0
  198. data/vendor/assets/javascripts/mercury/plugins/save_as_xml/plugin.js +9 -0
  199. data/vendor/assets/javascripts/mercury/region.js.coffee +107 -0
  200. data/vendor/assets/javascripts/mercury/regions/editable.js.coffee +600 -0
  201. data/vendor/assets/javascripts/mercury/regions/image.js.coffee +114 -0
  202. data/vendor/assets/javascripts/mercury/regions/markupable.js.coffee +398 -0
  203. data/vendor/assets/javascripts/mercury/regions/simple.js.coffee +325 -0
  204. data/vendor/assets/javascripts/mercury/regions/snippetable.js.coffee +124 -0
  205. data/vendor/assets/javascripts/mercury/select.js.coffee +44 -0
  206. data/vendor/assets/javascripts/mercury/snippet.js.coffee +106 -0
  207. data/vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee +72 -0
  208. data/vendor/assets/javascripts/mercury/statusbar.js.coffee +51 -0
  209. data/vendor/assets/javascripts/mercury/support/history.js +1 -0
  210. data/vendor/assets/javascripts/mercury/table_editor.js.coffee +265 -0
  211. data/vendor/assets/javascripts/mercury/toolbar.button.js.coffee +173 -0
  212. data/vendor/assets/javascripts/mercury/toolbar.button_group.js.coffee +42 -0
  213. data/vendor/assets/javascripts/mercury/toolbar.expander.js.coffee +56 -0
  214. data/vendor/assets/javascripts/mercury/toolbar.js.coffee +86 -0
  215. data/vendor/assets/javascripts/mercury/tooltip.js.coffee +74 -0
  216. data/vendor/assets/javascripts/mercury/uploader.js.coffee +244 -0
  217. data/vendor/assets/javascripts/mercury_loader.js +193 -0
  218. data/vendor/assets/javascripts/mercury_overrides.js +6 -0
  219. data/vendor/assets/stylesheets/mercury.css +28 -0
  220. data/vendor/assets/stylesheets/mercury/all_images.css.erb +89 -0
  221. data/vendor/assets/stylesheets/mercury/dialog.css +212 -0
  222. data/vendor/assets/stylesheets/mercury/form.css +118 -0
  223. data/vendor/assets/stylesheets/mercury/lightview.css +151 -0
  224. data/vendor/assets/stylesheets/mercury/mercury.css +37 -0
  225. data/vendor/assets/stylesheets/mercury/modal.css +183 -0
  226. data/vendor/assets/stylesheets/mercury/statusbar.css +32 -0
  227. data/vendor/assets/stylesheets/mercury/toolbar.css +304 -0
  228. data/vendor/assets/stylesheets/mercury/tooltip.css +26 -0
  229. data/vendor/assets/stylesheets/mercury/uploader.css +111 -0
  230. data/vendor/assets/stylesheets/mercury_overrides.css +17 -0
  231. metadata +572 -0
@@ -0,0 +1,106 @@
1
+ class @Mercury.Snippet
2
+
3
+ @all: []
4
+
5
+ @displayOptionsFor: (name) ->
6
+ Mercury.modal Mercury.config.snippets.optionsUrl.replace(':name', name), {
7
+ title: 'Snippet Options'
8
+ handler: 'insertSnippet'
9
+ snippetName: name
10
+ }
11
+ Mercury.snippet = null
12
+
13
+
14
+ @create: (name, options) ->
15
+ if @all.length > 0
16
+ identity = "snippet_0"
17
+ for snippet, i in @all
18
+ identity = "snippet_#{i+1}" if snippet.identity == identity
19
+ else
20
+ identity = "snippet_#{@all.length}"
21
+
22
+ instance = new Mercury.Snippet(name, identity, options)
23
+ @all.push(instance)
24
+ return instance
25
+
26
+
27
+ @find: (identity) ->
28
+ for snippet in @all
29
+ return snippet if snippet.identity == identity
30
+ return null
31
+
32
+
33
+ @load: (snippets) ->
34
+ for own identity, details of snippets
35
+ instance = new Mercury.Snippet(details.name, identity, details.options)
36
+ @all.push(instance)
37
+
38
+
39
+ constructor: (@name, @identity, options = {}) ->
40
+ @version = 0
41
+ @data = ''
42
+ @history = new Mercury.HistoryBuffer()
43
+ @setOptions(options)
44
+
45
+
46
+ getHTML: (context, callback = null) ->
47
+ element = jQuery('<div>', {
48
+ class: "mercury-snippet #{@name}-snippet"
49
+ contenteditable: "false"
50
+ 'data-snippet': @identity
51
+ 'data-version': @version
52
+ }, context)
53
+ element.html("[#{@identity}]")
54
+ @loadPreview(element, callback)
55
+ return element
56
+
57
+
58
+ getText: (callback) ->
59
+ return "[--#{@identity}--]"
60
+
61
+
62
+ loadPreview: (element, callback = null) ->
63
+ jQuery.ajax Mercury.config.snippets.previewUrl.replace(':name', @name), {
64
+ headers: Mercury.ajaxHeaders()
65
+ type: Mercury.config.snippets.method
66
+ data: @options
67
+ success: (data) =>
68
+ @data = data
69
+ element.html(data)
70
+ callback() if callback
71
+ error: =>
72
+ Mercury.notify('Error loading the preview for the \"%s\" snippet.', @name)
73
+ }
74
+
75
+
76
+ displayOptions: ->
77
+ Mercury.snippet = @
78
+ Mercury.modal Mercury.config.snippets.optionsUrl.replace(':name', @name), {
79
+ title: 'Snippet Options',
80
+ handler: 'insertSnippet',
81
+ loadType: Mercury.config.snippets.method,
82
+ loadData: @options
83
+ }
84
+
85
+
86
+ setOptions: (@options) ->
87
+ delete(@options['authenticity_token'])
88
+ delete(@options['utf8'])
89
+ @version += 1
90
+ @history.push(@options)
91
+
92
+
93
+ setVersion: (version = null) ->
94
+ version = parseInt(version)
95
+ if version && @history.stack[version - 1]
96
+ @version = version - 1
97
+ @options = @history.stack[@version]
98
+ return true
99
+ return false
100
+
101
+
102
+ serialize: ->
103
+ return {
104
+ name: @name
105
+ options: @options
106
+ }
@@ -0,0 +1,72 @@
1
+ class @Mercury.SnippetToolbar extends Mercury.Toolbar
2
+
3
+ constructor: (@document, @options = {}) ->
4
+ super(@options)
5
+
6
+
7
+ build: ->
8
+ @element = jQuery('<div>', {class: 'mercury-toolbar mercury-snippet-toolbar', style: 'display:none'})
9
+ @element.appendTo(jQuery(@options.appendTo).get(0) ? 'body')
10
+
11
+ for own buttonName, options of Mercury.config.toolbars.snippetable
12
+ button = @buildButton(buttonName, options)
13
+ button.appendTo(@element) if button
14
+
15
+
16
+ bindEvents: ->
17
+ Mercury.on 'show:toolbar', (event, options) =>
18
+ return unless options.snippet
19
+ options.snippet.mouseout => @hide()
20
+ @show(options.snippet)
21
+
22
+ Mercury.on 'hide:toolbar', (event, options) =>
23
+ return unless options.type && options.type == 'snippet'
24
+ @hide(options.immediately)
25
+
26
+ @element.mousemove =>
27
+ clearTimeout(@hideTimeout)
28
+
29
+ @element.mouseout =>
30
+ @hide()
31
+
32
+ jQuery(@document).on 'scroll', =>
33
+ @position() if @visible
34
+
35
+
36
+ show: (@snippet) ->
37
+ Mercury.tooltip.hide()
38
+ @position()
39
+ @appear()
40
+
41
+
42
+ position: ->
43
+ offset = @snippet.offset()
44
+
45
+ top = offset.top + Mercury.displayRect.top - jQuery(@document).scrollTop() - @height() + 10
46
+ left = offset.left - jQuery(@document).scrollLeft()
47
+
48
+ @element.css {
49
+ top: top
50
+ left: left
51
+ }
52
+
53
+
54
+ appear: ->
55
+ clearTimeout(@hideTimeout)
56
+ return if @visible
57
+ @visible = true
58
+ @element.css({display: 'block', opacity: 0})
59
+ @element.stop().animate({opacity: 1}, 200, 'easeInOutSine')
60
+
61
+
62
+ hide: (immediately = false) ->
63
+ clearTimeout(@hideTimeout)
64
+ if immediately
65
+ @element.hide()
66
+ @visible = false
67
+ else
68
+ @hideTimeout = setTimeout 500, =>
69
+ @element.stop().animate {opacity: 0}, 300, 'easeInOutSine', =>
70
+ @element.hide()
71
+ @visible = false
72
+
@@ -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.on 'region:update', (event, options) =>
20
+ @setPath(options.region.path()) if options.region && jQuery.type(options.region.path) == 'function'
21
+
22
+ @aboutElement.on 'click', =>
23
+ Mercury.lightview('/mercury/lightviews/about.html', {title: "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>#{Mercury.I18n('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'})
@@ -0,0 +1 @@
1
+ (function(a,b){"use strict";var c=a.History=a.History||{};if(typeof c.Adapter!="undefined")throw new Error("History.js Adapter has already been loaded...");c.Adapter={handlers:{},_uid:1,uid:function(a){return a._uid||(a._uid=c.Adapter._uid++)},bind:function(a,b,d){var e=c.Adapter.uid(a);c.Adapter.handlers[e]=c.Adapter.handlers[e]||{},c.Adapter.handlers[e][b]=c.Adapter.handlers[e][b]||[],c.Adapter.handlers[e][b].push(d),a["on"+b]=function(a,b){return function(d){c.Adapter.trigger(a,b,d)}}(a,b)},trigger:function(a,b,d){d=d||{};var e=c.Adapter.uid(a),f,g;c.Adapter.handlers[e]=c.Adapter.handlers[e]||{},c.Adapter.handlers[e][b]=c.Adapter.handlers[e][b]||[];for(f=0,g=c.Adapter.handlers[e][b].length;f<g;++f)c.Adapter.handlers[e][b][f].apply(this,[d])},extractEventData:function(a,c){var d=c&&c[a]||b;return d},onDomLoad:function(b){var c=a.setTimeout(function(){b()},2e3);a.onload=function(){clearTimeout(c),b()}}},typeof c.init!="undefined"&&c.init()})(window),function(a,b){"use strict";var c=a.console||b,d=a.document,e=a.navigator,f=a.sessionStorage||!1,g=a.setTimeout,h=a.clearTimeout,i=a.setInterval,j=a.clearInterval,k=a.JSON,l=a.alert,m=a.History=a.History||{},n=a.history;k.stringify=k.stringify||k.encode,k.parse=k.parse||k.decode;if(typeof m.init!="undefined")throw new Error("History.js Core has already been loaded...");m.init=function(){return typeof m.Adapter=="undefined"?!1:(typeof m.initCore!="undefined"&&m.initCore(),typeof m.initHtml4!="undefined"&&m.initHtml4(),!0)},m.initCore=function(){if(typeof m.initCore.initialized!="undefined")return!1;m.initCore.initialized=!0,m.options=m.options||{},m.options.hashChangeInterval=m.options.hashChangeInterval||100,m.options.safariPollInterval=m.options.safariPollInterval||500,m.options.doubleCheckInterval=m.options.doubleCheckInterval||500,m.options.storeInterval=m.options.storeInterval||1e3,m.options.busyDelay=m.options.busyDelay||250,m.options.debug=m.options.debug||!1,m.options.initialTitle=m.options.initialTitle||d.title,m.intervalList=[],m.clearAllIntervals=function(){var a,b=m.intervalList;if(typeof b!="undefined"&&b!==null){for(a=0;a<b.length;a++)j(b[a]);m.intervalList=null}},m.debug=function(){(m.options.debug||!1)&&m.log.apply(m,arguments)},m.log=function(){var a=typeof c!="undefined"&&typeof c.log!="undefined"&&typeof c.log.apply!="undefined",b=d.getElementById("log"),e,f,g,h,i;a?(h=Array.prototype.slice.call(arguments),e=h.shift(),typeof c.debug!="undefined"?c.debug.apply(c,[e,h]):c.log.apply(c,[e,h])):e="\n"+arguments[0]+"\n";for(f=1,g=arguments.length;f<g;++f){i=arguments[f];if(typeof i=="object"&&typeof k!="undefined")try{i=k.stringify(i)}catch(j){}e+="\n"+i+"\n"}return b?(b.value+=e+"\n-----\n",b.scrollTop=b.scrollHeight-b.clientHeight):a||l(e),!0},m.getInternetExplorerMajorVersion=function(){var a=m.getInternetExplorerMajorVersion.cached=typeof m.getInternetExplorerMajorVersion.cached!="undefined"?m.getInternetExplorerMajorVersion.cached:function(){var a=3,b=d.createElement("div"),c=b.getElementsByTagName("i");while((b.innerHTML="<!--[if gt IE "+ ++a+"]><i></i><![endif]-->")&&c[0]);return a>4?a:!1}();return a},m.isInternetExplorer=function(){var a=m.isInternetExplorer.cached=typeof m.isInternetExplorer.cached!="undefined"?m.isInternetExplorer.cached:Boolean(m.getInternetExplorerMajorVersion());return a},m.emulated={pushState:!Boolean(a.history&&a.history.pushState&&a.history.replaceState&&!/ Mobile\/([1-7][a-z]|(8([abcde]|f(1[0-8]))))/i.test(e.userAgent)&&!/AppleWebKit\/5([0-2]|3[0-2])/i.test(e.userAgent)),hashChange:Boolean(!("onhashchange"in a||"onhashchange"in d)||m.isInternetExplorer()&&m.getInternetExplorerMajorVersion()<8)},m.enabled=!m.emulated.pushState,m.bugs={setHash:Boolean(!m.emulated.pushState&&e.vendor==="Apple Computer, Inc."&&/AppleWebKit\/5([0-2]|3[0-3])/.test(e.userAgent)),safariPoll:Boolean(!m.emulated.pushState&&e.vendor==="Apple Computer, Inc."&&/AppleWebKit\/5([0-2]|3[0-3])/.test(e.userAgent)),ieDoubleCheck:Boolean(m.isInternetExplorer()&&m.getInternetExplorerMajorVersion()<8),hashEscape:Boolean(m.isInternetExplorer()&&m.getInternetExplorerMajorVersion()<7)},m.isEmptyObject=function(a){for(var b in a)return!1;return!0},m.cloneObject=function(a){var b,c;return a?(b=k.stringify(a),c=k.parse(b)):c={},c},m.getRootUrl=function(){var a=d.location.protocol+"//"+(d.location.hostname||d.location.host);if(d.location.port||!1)a+=":"+d.location.port;return a+="/",a},m.getBaseHref=function(){var a=d.getElementsByTagName("base"),b=null,c="";return a.length===1&&(b=a[0],c=b.href.replace(/[^\/]+$/,"")),c=c.replace(/\/+$/,""),c&&(c+="/"),c},m.getBaseUrl=function(){var a=m.getBaseHref()||m.getBasePageUrl()||m.getRootUrl();return a},m.getPageUrl=function(){var a=m.getState(!1,!1),b=(a||{}).url||d.location.href,c;return c=b.replace(/\/+$/,"").replace(/[^\/]+$/,function(a,b,c){return/\./.test(a)?a:a+"/"}),c},m.getBasePageUrl=function(){var a=d.location.href.replace(/[#\?].*/,"").replace(/[^\/]+$/,function(a,b,c){return/[^\/]$/.test(a)?"":a}).replace(/\/+$/,"")+"/";return a},m.getFullUrl=function(a,b){var c=a,d=a.substring(0,1);return b=typeof b=="undefined"?!0:b,/[a-z]+\:\/\//.test(a)||(d==="/"?c=m.getRootUrl()+a.replace(/^\/+/,""):d==="#"?c=m.getPageUrl().replace(/#.*/,"")+a:d==="?"?c=m.getPageUrl().replace(/[\?#].*/,"")+a:b?c=m.getBaseUrl()+a.replace(/^(\.\/)+/,""):c=m.getBasePageUrl()+a.replace(/^(\.\/)+/,"")),c.replace(/\#$/,"")},m.getShortUrl=function(a){var b=a,c=m.getBaseUrl(),d=m.getRootUrl();return m.emulated.pushState&&(b=b.replace(c,"")),b=b.replace(d,"/"),m.isTraditionalAnchor(b)&&(b="./"+b),b=b.replace(/^(\.\/)+/g,"./").replace(/\#$/,""),b},m.store={},m.idToState=m.idToState||{},m.stateToId=m.stateToId||{},m.urlToId=m.urlToId||{},m.storedStates=m.storedStates||[],m.savedStates=m.savedStates||[],m.normalizeStore=function(){m.store.idToState=m.store.idToState||{},m.store.urlToId=m.store.urlToId||{},m.store.stateToId=m.store.stateToId||{}},m.getState=function(a,b){typeof a=="undefined"&&(a=!0),typeof b=="undefined"&&(b=!0);var c=m.getLastSavedState();return!c&&b&&(c=m.createStateObject()),a&&(c=m.cloneObject(c),c.url=c.cleanUrl||c.url),c},m.getIdByState=function(a){var b=m.extractId(a.url),c;if(!b){c=m.getStateString(a);if(typeof m.stateToId[c]!="undefined")b=m.stateToId[c];else if(typeof m.store.stateToId[c]!="undefined")b=m.store.stateToId[c];else{for(;;){b=(new Date).getTime()+String(Math.random()).replace(/\D/g,"");if(typeof m.idToState[b]=="undefined"&&typeof m.store.idToState[b]=="undefined")break}m.stateToId[c]=b,m.idToState[b]=a}}return b},m.normalizeState=function(a){var b,c;if(!a||typeof a!="object")a={};if(typeof a.normalized!="undefined")return a;if(!a.data||typeof a.data!="object")a.data={};b={},b.normalized=!0,b.title=a.title||"",b.url=m.getFullUrl(m.unescapeString(a.url||d.location.href)),b.hash=m.getShortUrl(b.url),b.data=m.cloneObject(a.data),b.id=m.getIdByState(b),b.cleanUrl=b.url.replace(/\??\&_suid.*/,""),b.url=b.cleanUrl,c=!m.isEmptyObject(b.data);if(b.title||c)b.hash=m.getShortUrl(b.url).replace(/\??\&_suid.*/,""),/\?/.test(b.hash)||(b.hash+="?"),b.hash+="&_suid="+b.id;return b.hashedUrl=m.getFullUrl(b.hash),(m.emulated.pushState||m.bugs.safariPoll)&&m.hasUrlDuplicate(b)&&(b.url=b.hashedUrl),b},m.createStateObject=function(a,b,c){var d={data:a,title:b,url:c};return d=m.normalizeState(d),d},m.getStateById=function(a){a=String(a);var c=m.idToState[a]||m.store.idToState[a]||b;return c},m.getStateString=function(a){var b,c,d;return b=m.normalizeState(a),c={data:b.data,title:a.title,url:a.url},d=k.stringify(c),d},m.getStateId=function(a){var b,c;return b=m.normalizeState(a),c=b.id,c},m.getHashByState=function(a){var b,c;return b=m.normalizeState(a),c=b.hash,c},m.extractId=function(a){var b,c,d;return c=/(.*)\&_suid=([0-9]+)$/.exec(a),d=c?c[1]||a:a,b=c?String(c[2]||""):"",b||!1},m.isTraditionalAnchor=function(a){var b=!/[\/\?\.]/.test(a);return b},m.extractState=function(a,b){var c=null,d,e;return b=b||!1,d=m.extractId(a),d&&(c=m.getStateById(d)),c||(e=m.getFullUrl(a),d=m.getIdByUrl(e)||!1,d&&(c=m.getStateById(d)),!c&&b&&!m.isTraditionalAnchor(a)&&(c=m.createStateObject(null,null,e))),c},m.getIdByUrl=function(a){var c=m.urlToId[a]||m.store.urlToId[a]||b;return c},m.getLastSavedState=function(){return m.savedStates[m.savedStates.length-1]||b},m.getLastStoredState=function(){return m.storedStates[m.storedStates.length-1]||b},m.hasUrlDuplicate=function(a){var b=!1,c;return c=m.extractState(a.url),b=c&&c.id!==a.id,b},m.storeState=function(a){return m.urlToId[a.url]=a.id,m.storedStates.push(m.cloneObject(a)),a},m.isLastSavedState=function(a){var b=!1,c,d,e;return m.savedStates.length&&(c=a.id,d=m.getLastSavedState(),e=d.id,b=c===e),b},m.saveState=function(a){return m.isLastSavedState(a)?!1:(m.savedStates.push(m.cloneObject(a)),!0)},m.getStateByIndex=function(a){var b=null;return typeof a=="undefined"?b=m.savedStates[m.savedStates.length-1]:a<0?b=m.savedStates[m.savedStates.length+a]:b=m.savedStates[a],b},m.getHash=function(){var a=m.unescapeHash(d.location.hash);return a},m.unescapeString=function(b){var c=b,d;for(;;){d=a.unescape(c);if(d===c)break;c=d}return c},m.unescapeHash=function(a){var b=m.normalizeHash(a);return b=m.unescapeString(b),b},m.normalizeHash=function(a){var b=a.replace(/[^#]*#/,"").replace(/#.*/,"");return b},m.setHash=function(a,b){var c,e,f;return b!==!1&&m.busy()?(m.pushQueue({scope:m,callback:m.setHash,args:arguments,queue:b}),!1):(c=m.escapeHash(a),m.busy(!0),e=m.extractState(a,!0),e&&!m.emulated.pushState?m.pushState(e.data,e.title,e.url,!1):d.location.hash!==c&&(m.bugs.setHash?(f=m.getPageUrl(),m.pushState(null,null,f+"#"+c,!1)):d.location.hash=c),m)},m.escapeHash=function(b){var c=m.normalizeHash(b);return c=a.escape(c),m.bugs.hashEscape||(c=c.replace(/\%21/g,"!").replace(/\%26/g,"&").replace(/\%3D/g,"=").replace(/\%3F/g,"?")),c},m.getHashByUrl=function(a){var b=String(a).replace(/([^#]*)#?([^#]*)#?(.*)/,"$2");return b=m.unescapeHash(b),b},m.setTitle=function(a){var b=a.title,c;b||(c=m.getStateByIndex(0),c&&c.url===a.url&&(b=c.title||m.options.initialTitle));try{d.getElementsByTagName("title")[0].innerHTML=b.replace("<","&lt;").replace(">","&gt;").replace(" & "," &amp; ")}catch(e){}return d.title=b,m},m.queues=[],m.busy=function(a){typeof a!="undefined"?m.busy.flag=a:typeof m.busy.flag=="undefined"&&(m.busy.flag=!1);if(!m.busy.flag){h(m.busy.timeout);var b=function(){var a,c,d;if(m.busy.flag)return;for(a=m.queues.length-1;a>=0;--a){c=m.queues[a];if(c.length===0)continue;d=c.shift(),m.fireQueueItem(d),m.busy.timeout=g(b,m.options.busyDelay)}};m.busy.timeout=g(b,m.options.busyDelay)}return m.busy.flag},m.busy.flag=!1,m.fireQueueItem=function(a){return a.callback.apply(a.scope||m,a.args||[])},m.pushQueue=function(a){return m.queues[a.queue||0]=m.queues[a.queue||0]||[],m.queues[a.queue||0].push(a),m},m.queue=function(a,b){return typeof a=="function"&&(a={callback:a}),typeof b!="undefined"&&(a.queue=b),m.busy()?m.pushQueue(a):m.fireQueueItem(a),m},m.clearQueue=function(){return m.busy.flag=!1,m.queues=[],m},m.stateChanged=!1,m.doubleChecker=!1,m.doubleCheckComplete=function(){return m.stateChanged=!0,m.doubleCheckClear(),m},m.doubleCheckClear=function(){return m.doubleChecker&&(h(m.doubleChecker),m.doubleChecker=!1),m},m.doubleCheck=function(a){return m.stateChanged=!1,m.doubleCheckClear(),m.bugs.ieDoubleCheck&&(m.doubleChecker=g(function(){return m.doubleCheckClear(),m.stateChanged||a(),!0},m.options.doubleCheckInterval)),m},m.safariStatePoll=function(){var b=m.extractState(d.location.href),c;if(!m.isLastSavedState(b))c=b;else return;return c||(c=m.createStateObject()),m.Adapter.trigger(a,"popstate"),m},m.back=function(a){return a!==!1&&m.busy()?(m.pushQueue({scope:m,callback:m.back,args:arguments,queue:a}),!1):(m.busy(!0),m.doubleCheck(function(){m.back(!1)}),n.go(-1),!0)},m.forward=function(a){return a!==!1&&m.busy()?(m.pushQueue({scope:m,callback:m.forward,args:arguments,queue:a}),!1):(m.busy(!0),m.doubleCheck(function(){m.forward(!1)}),n.go(1),!0)},m.go=function(a,b){var c;if(a>0)for(c=1;c<=a;++c)m.forward(b);else{if(!(a<0))throw new Error("History.go: History.go requires a positive or negative integer passed.");for(c=-1;c>=a;--c)m.back(b)}return m};if(m.emulated.pushState){var o=function(){};m.pushState=m.pushState||o,m.replaceState=m.replaceState||o}else m.onPopState=function(b,c){var e=!1,f=!1,g,h;return m.doubleCheckComplete(),g=m.getHash(),g?(h=m.extractState(g||d.location.href,!0),h?m.replaceState(h.data,h.title,h.url,!1):(m.Adapter.trigger(a,"anchorchange"),m.busy(!1)),m.expectedStateId=!1,!1):(e=m.Adapter.extractEventData("state",b,c)||!1,e?f=m.getStateById(e):m.expectedStateId?f=m.getStateById(m.expectedStateId):f=m.extractState(d.location.href),f||(f=m.createStateObject(null,null,d.location.href)),m.expectedStateId=!1,m.isLastSavedState(f)?(m.busy(!1),!1):(m.storeState(f),m.saveState(f),m.setTitle(f),m.Adapter.trigger(a,"statechange"),m.busy(!1),!0))},m.Adapter.bind(a,"popstate",m.onPopState),m.pushState=function(b,c,d,e){if(m.getHashByUrl(d)&&m.emulated.pushState)throw new Error("History.js does not support states with fragement-identifiers (hashes/anchors).");if(e!==!1&&m.busy())return m.pushQueue({scope:m,callback:m.pushState,args:arguments,queue:e}),!1;m.busy(!0);var f=m.createStateObject(b,c,d);return m.isLastSavedState(f)?m.busy(!1):(m.storeState(f),m.expectedStateId=f.id,n.pushState(f.id,f.title,f.url),m.Adapter.trigger(a,"popstate")),!0},m.replaceState=function(b,c,d,e){if(m.getHashByUrl(d)&&m.emulated.pushState)throw new Error("History.js does not support states with fragement-identifiers (hashes/anchors).");if(e!==!1&&m.busy())return m.pushQueue({scope:m,callback:m.replaceState,args:arguments,queue:e}),!1;m.busy(!0);var f=m.createStateObject(b,c,d);return m.isLastSavedState(f)?m.busy(!1):(m.storeState(f),m.expectedStateId=f.id,n.replaceState(f.id,f.title,f.url),m.Adapter.trigger(a,"popstate")),!0};if(f){try{m.store=k.parse(f.getItem("History.store"))||{}}catch(p){m.store={}}m.normalizeStore()}else m.store={},m.normalizeStore();m.Adapter.bind(a,"beforeunload",m.clearAllIntervals),m.Adapter.bind(a,"unload",m.clearAllIntervals),m.saveState(m.storeState(m.extractState(d.location.href,!0))),f&&(m.onUnload=function(){var a,b;try{a=k.parse(f.getItem("History.store"))||{}}catch(c){a={}}a.idToState=a.idToState||{},a.urlToId=a.urlToId||{},a.stateToId=a.stateToId||{};for(b in m.idToState){if(!m.idToState.hasOwnProperty(b))continue;a.idToState[b]=m.idToState[b]}for(b in m.urlToId){if(!m.urlToId.hasOwnProperty(b))continue;a.urlToId[b]=m.urlToId[b]}for(b in m.stateToId){if(!m.stateToId.hasOwnProperty(b))continue;a.stateToId[b]=m.stateToId[b]}m.store=a,m.normalizeStore(),f.setItem("History.store",k.stringify(a))},m.intervalList.push(i(m.onUnload,m.options.storeInterval)),m.Adapter.bind(a,"beforeunload",m.onUnload),m.Adapter.bind(a,"unload",m.onUnload));if(!m.emulated.pushState){m.bugs.safariPoll&&m.intervalList.push(i(m.safariStatePoll,m.options.safariPollInterval));if(e.vendor==="Apple Computer, Inc."||(e.appCodeName||"")==="Mozilla")m.Adapter.bind(a,"hashchange",function(){m.Adapter.trigger(a,"popstate")}),m.getHash()&&m.Adapter.onDomLoad(function(){m.Adapter.trigger(a,"hashchange")})}},m.init()}(window)
@@ -0,0 +1,265 @@
1
+ @Mercury.tableEditor = (table, cell, cellContent) ->
2
+ Mercury.tableEditor.load(table, cell, cellContent)
3
+ return Mercury.tableEditor
4
+
5
+ jQuery.extend Mercury.tableEditor,
6
+
7
+ load: (@table, @cell, @cellContent = '') ->
8
+ @row = @cell.parent('tr')
9
+ @columnCount = @getColumnCount()
10
+ @rowCount = @getRowCount()
11
+
12
+
13
+ addColumn: (position = 'after') ->
14
+ sig = @cellSignatureFor(@cell)
15
+
16
+ for row, i in @table.find('tr')
17
+ rowSpan = 1
18
+ matchOptions = if position == 'after' then {right: sig.right} else {left: sig.left}
19
+ if matching = @findCellByOptionsFor(row, matchOptions)
20
+ newCell = jQuery("<#{matching.cell.get(0).tagName}>").html(@cellContent)
21
+ @setRowspanFor(newCell, matching.height)
22
+ if position == 'before' then matching.cell.before(newCell) else matching.cell.after(newCell)
23
+ i += matching.height - 1
24
+ else if intersecting = @findCellByIntersectionFor(row, sig)
25
+ @setColspanFor(intersecting.cell, intersecting.width + 1)
26
+
27
+
28
+ removeColumn: ->
29
+ sig = @cellSignatureFor(@cell)
30
+ return if sig.width > 1
31
+
32
+ removing = []
33
+ adjusting = []
34
+ for row, i in @table.find('tr')
35
+ if matching = @findCellByOptionsFor(row, {left: sig.left, width: sig.width})
36
+ removing.push(matching.cell)
37
+ i += matching.height - 1
38
+ else if intersecting = @findCellByIntersectionFor(row, sig)
39
+ adjusting.push(intersecting.cell)
40
+
41
+ jQuery(cell).remove() for cell in removing
42
+ @setColspanFor(cell, @colspanFor(cell) - 1) for cell in adjusting
43
+
44
+
45
+ addRow: (position = 'after') ->
46
+ newRow = jQuery('<tr>')
47
+
48
+ if (rowspan = @rowspanFor(@cell)) > 1 && position == 'after'
49
+ @row = jQuery(@row.nextAll('tr')[rowspan - 2])
50
+
51
+ cellCount = 0
52
+ for cell in @row.find('th, td')
53
+ colspan = @colspanFor(cell)
54
+ newCell = jQuery("<#{cell.tagName}>").html(@cellContent)
55
+ @setColspanFor(newCell, colspan)
56
+ cellCount += colspan
57
+ if (rowspan = @rowspanFor(cell)) > 1 && position == 'after'
58
+ @setRowspanFor(cell, rowspan + 1)
59
+ continue
60
+
61
+ newRow.append(newCell)
62
+
63
+ if cellCount < @columnCount
64
+ rowCount = 0
65
+ for previousRow in @row.prevAll('tr')
66
+ rowCount += 1
67
+ for cell in jQuery(previousRow).find('td[rowspan], th[rowspan]')
68
+ rowspan = @rowspanFor(cell)
69
+ if rowspan - 1 >= rowCount && position == 'before'
70
+ @setRowspanFor(cell, rowspan + 1)
71
+ else if rowspan - 1 >= rowCount && position == 'after'
72
+ if rowspan - 1 == rowCount
73
+ newCell = jQuery("<#{cell.tagName}>").html(@cellContent)
74
+ @setColspanFor(newCell, @colspanFor(cell))
75
+ newRow.append(newCell)
76
+ else
77
+ @setRowspanFor(cell, rowspan + 1)
78
+
79
+ if position == 'before' then @row.before(newRow) else @row.after(newRow)
80
+
81
+
82
+ removeRow: ->
83
+ # check to see that all cells have the same rowspan, and figure out the minimum rowspan
84
+ rowspansMatch = true
85
+ prevRowspan = 0
86
+ minRowspan = 0
87
+ for cell in @row.find('td, th')
88
+ rowspan = @rowspanFor(cell)
89
+ rowspansMatch = false if prevRowspan && rowspan != prevRowspan
90
+ minRowspan = rowspan if rowspan < minRowspan || !minRowspan
91
+ prevRowspan = rowspan
92
+
93
+ return if !rowspansMatch && @rowspanFor(@cell) > minRowspan
94
+
95
+ # remove any emtpy rows below
96
+ if minRowspan > 1
97
+ jQuery(@row.nextAll('tr')[i]).remove() for i in [0..minRowspan - 2]
98
+
99
+ # find and move down any cells that have a larger rowspan
100
+ for cell in @row.find('td[rowspan], th[rowspan]')
101
+ sig = @cellSignatureFor(cell)
102
+ continue if sig.height == minRowspan
103
+ if match = @findCellByOptionsFor(@row.nextAll('tr')[minRowspan - 1], {left: sig.left, forceAdjacent: true})
104
+ @setRowspanFor(cell, @rowspanFor(cell) - @rowspanFor(@cell))
105
+ if match.direction == 'before' then match.cell.before(jQuery(cell).clone()) else match.cell.after(jQuery(cell).clone())
106
+
107
+ if @columnsFor(@row.find('td, th')) < @columnCount
108
+ # move up rows looking for cells with rowspans that might intersect
109
+ rowsAbove = 0
110
+ for aboveRow in @row.prevAll('tr')
111
+ rowsAbove += 1
112
+ for cell in jQuery(aboveRow).find('td[rowspan], th[rowspan]')
113
+ # if the cell intersects with the row we're trying to calculate on, and it's index is less than where we've
114
+ # gotten so far, add it
115
+ rowspan = @rowspanFor(cell)
116
+ @setRowspanFor(cell, rowspan - @rowspanFor(@cell)) if rowspan > rowsAbove
117
+
118
+ @row.remove()
119
+
120
+
121
+ increaseColspan: ->
122
+ cell = @cell.next('td, th')
123
+ return unless cell.length
124
+ return if @rowspanFor(cell) != @rowspanFor(@cell)
125
+ return if @cellIndexFor(cell) > @cellIndexFor(@cell) + @colspanFor(@cell)
126
+ @setColspanFor(@cell, @colspanFor(@cell) + @colspanFor(cell))
127
+ cell.remove()
128
+
129
+
130
+ decreaseColspan: ->
131
+ return if @colspanFor(@cell) == 1
132
+ @setColspanFor(@cell, @colspanFor(@cell) - 1)
133
+ newCell = jQuery("<#{@cell.get(0).tagName}>").html(@cellContent)
134
+ @setRowspanFor(newCell, @rowspanFor(@cell))
135
+ @cell.after(newCell)
136
+
137
+
138
+ increaseRowspan: ->
139
+ sig = @cellSignatureFor(@cell)
140
+ nextRow = @row.nextAll('tr')[sig.height - 1]
141
+ if nextRow && match = @findCellByOptionsFor(nextRow, {left: sig.left, width: sig.width})
142
+ @setRowspanFor(@cell, sig.height + match.height)
143
+ match.cell.remove()
144
+
145
+ decreaseRowspan: ->
146
+ sig = @cellSignatureFor(@cell)
147
+ return if sig.height == 1
148
+ nextRow = @row.nextAll('tr')[sig.height - 2]
149
+ if match = @findCellByOptionsFor(nextRow, {left: sig.left, forceAdjacent: true})
150
+ newCell = jQuery("<#{@cell.get(0).tagName}>").html(@cellContent)
151
+ @setColspanFor(newCell, @colspanFor(@cell))
152
+ @setRowspanFor(@cell, sig.height - 1)
153
+ if match.direction == 'before' then match.cell.before(newCell) else match.cell.after(newCell)
154
+
155
+ # Counts the columns of the first row (alpha row) in the table. We can safely rely on the first row always being
156
+ # comprised of a full set of cells or cells with colspans.
157
+ getColumnCount: ->
158
+ return @columnsFor(@table.find('thead tr:first-child, tbody tr:first-child, tfoot tr:first-child').first().find('td, th'))
159
+
160
+
161
+ # Counts the rows of the table.
162
+ getRowCount: ->
163
+ return @table.find('tr').length
164
+
165
+
166
+ # Gets the index for a given cell, taking into account that rows above it can have cells that have rowspans.
167
+ cellIndexFor: (cell) ->
168
+ cell = jQuery(cell)
169
+
170
+ # get the row for the cell and calculate all the columns in it
171
+ row = cell.parent('tr')
172
+ columns = @columnsFor(row.find('td, th'))
173
+ index = @columnsFor(cell.prevAll('td, th'))
174
+
175
+ # if the columns is less than expected, we need to look above for rowspans
176
+ if columns < @columnCount
177
+ # move up rows looking for cells with rowspans that might intersect
178
+ rowsAbove = 0
179
+ for aboveRow in row.prevAll('tr')
180
+ rowsAbove += 1
181
+ for aboveCell in jQuery(aboveRow).find('td[rowspan], th[rowspan]')
182
+ # if the cell intersects with the row we're trying to calculate on, and it's index is less than where we've
183
+ # gotten so far, add it
184
+ if @rowspanFor(aboveCell) > rowsAbove && @cellIndexFor(aboveCell) <= index
185
+ index += @colspanFor(aboveCell)
186
+
187
+ return index
188
+
189
+ # Creates a signature for a given cell, which is made up if it's size, and itself.
190
+ cellSignatureFor: (cell) ->
191
+ sig = {cell: jQuery(cell)}
192
+ sig.left = @cellIndexFor(cell)
193
+ sig.width = @colspanFor(cell)
194
+ sig.height = @rowspanFor(cell)
195
+ sig.right = sig.left + sig.width
196
+ return sig
197
+
198
+ # Find a cell based on options. Options can be:
199
+ # right
200
+ # or
201
+ # left, [width], [forceAdjacent]
202
+ # eg. findCellByOptionsFor(@row, {left: 1, width: 2, forceAdjacent: true})
203
+ findCellByOptionsFor: (row, options) ->
204
+ for cell in jQuery(row).find('td, th')
205
+ sig = @cellSignatureFor(cell)
206
+ if typeof(options.right) != 'undefined'
207
+ return sig if sig.right == options.right
208
+ if typeof(options.left) != 'undefined'
209
+
210
+ if options.width
211
+ return sig if sig.left == options.left && sig.width == options.width
212
+ else if !options.forceAdjacent
213
+ return sig if sig.left == options.left
214
+ else if options.forceAdjacent
215
+ if sig.left > options.left
216
+ prev = jQuery(cell).prev('td, th')
217
+ if prev.length
218
+ sig = @cellSignatureFor(prev)
219
+ sig.direction = 'after'
220
+ else
221
+ sig.direction = 'before'
222
+ return sig
223
+
224
+ if options.forceAdjacent
225
+ sig.direction = 'after'
226
+ return sig
227
+
228
+ return null
229
+
230
+ # Finds a cell that intersects with the current signature
231
+ findCellByIntersectionFor: (row, signature) ->
232
+ for cell in jQuery(row).find('td, th')
233
+ sig = @cellSignatureFor(cell)
234
+ return sig if sig.right - signature.left >= 0 && sig.right > signature.left
235
+ return null
236
+
237
+
238
+ # Counts all the columns in a given array of columns, taking colspans into
239
+ # account.
240
+ columnsFor: (cells) ->
241
+ count = 0
242
+ count += @colspanFor(cell) for cell in cells
243
+ return count
244
+
245
+
246
+ # Tries to get the colspan of a cell, falling back to 1 if there's none
247
+ # specified.
248
+ colspanFor: (cell) ->
249
+ return parseInt(jQuery(cell).attr('colspan')) || 1
250
+
251
+
252
+ # Tries to get the rowspan of a cell, falling back to 1 if there's none
253
+ # specified.
254
+ rowspanFor: (cell) ->
255
+ return parseInt(jQuery(cell).attr('rowspan')) || 1
256
+
257
+
258
+ # Sets the colspan of a cell, removing it if it's 1.
259
+ setColspanFor: (cell, value) ->
260
+ jQuery(cell).attr('colspan', if value > 1 then value else null)
261
+
262
+
263
+ # Sets the rowspan of a cell, removing it if it's 1
264
+ setRowspanFor: (cell, value) ->
265
+ jQuery(cell).attr('rowspan', if value > 1 then value else null)