kiteditor 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (229) hide show
  1. data/LICENSE +25 -0
  2. data/app/controllers/mercury/images_controller.rb +5 -0
  3. data/app/controllers/mercury_controller.rb +34 -0
  4. data/app/models/mercury/image.rb +17 -0
  5. data/app/views/layouts/mercury.html.erb +33 -0
  6. data/app/views/layouts/popup.html.haml +9 -0
  7. data/app/views/mercury/images/_list.html.haml +22 -0
  8. data/app/views/mercury/images/index.html.haml +4 -0
  9. data/app/views/mercury/images/index.js.erb +2 -0
  10. data/app/views/mercury/lightviews/about.html +11 -0
  11. data/app/views/mercury/modals/character.html +255 -0
  12. data/app/views/mercury/modals/htmleditor.html +13 -0
  13. data/app/views/mercury/modals/link.html +94 -0
  14. data/app/views/mercury/modals/media.html +1 -0
  15. data/app/views/mercury/modals/table.html +84 -0
  16. data/app/views/mercury/palettes/backcolor.html +73 -0
  17. data/app/views/mercury/palettes/forecolor.html +73 -0
  18. data/app/views/mercury/panels/history.html +3 -0
  19. data/app/views/mercury/panels/notes.html +3 -0
  20. data/app/views/mercury/panels/snippets.html +12 -0
  21. data/app/views/mercury/selects/formatblock.html +11 -0
  22. data/app/views/mercury/selects/style.html +5 -0
  23. data/app/views/mercury/snippets/example/options.html.erb +34 -0
  24. data/app/views/mercury/snippets/example/preview.html.erb +1 -0
  25. data/config/engine.rb +44 -0
  26. data/db/migrate/20110526035601_create_mercury_images.rb +11 -0
  27. data/features/loading/loading.feature +22 -0
  28. data/features/loading/navigating.feature +77 -0
  29. data/features/loading/user_interface.feature +67 -0
  30. data/features/regions/editable/advanced_editing.feature +0 -0
  31. data/features/regions/editable/basic_editing.feature +195 -0
  32. data/features/regions/editable/inserting_links.feature +98 -0
  33. data/features/regions/editable/inserting_media.feature +110 -0
  34. data/features/regions/editable/inserting_snippets.feature +102 -0
  35. data/features/regions/editable/inserting_special_characters.feature +24 -0
  36. data/features/regions/editable/inserting_tables.feature +109 -0
  37. data/features/regions/editable/pasting.feature +0 -0
  38. data/features/regions/editable/uploading_images.feature +0 -0
  39. data/features/regions/markupable/advanced_editing.feature +0 -0
  40. data/features/regions/markupable/basic_editing.feature +0 -0
  41. data/features/regions/markupable/inserting_links.feature +0 -0
  42. data/features/regions/markupable/inserting_media.feature +0 -0
  43. data/features/regions/markupable/inserting_snippets.feature +0 -0
  44. data/features/regions/markupable/inserting_special_characters.feature +0 -0
  45. data/features/regions/markupable/inserting_tables.feature +0 -0
  46. data/features/regions/markupable/uploading_images.feature +0 -0
  47. data/features/regions/snippetable/advanced_editing.feature +0 -0
  48. data/features/regions/snippetable/basic_editing.feature +0 -0
  49. data/features/regions/snippetable/inserting_snippets.feature +0 -0
  50. data/features/saving/saving.feature +33 -0
  51. data/features/step_definitions/debug_steps.rb +14 -0
  52. data/features/step_definitions/mercury_steps.rb +438 -0
  53. data/features/step_definitions/web_steps.rb +211 -0
  54. data/features/support/env.rb +46 -0
  55. data/features/support/mercury_contents.rb +25 -0
  56. data/features/support/mercury_selectors.rb +148 -0
  57. data/features/support/paths.rb +38 -0
  58. data/features/support/selectors.rb +44 -0
  59. data/lib/generators/mercury/install/install_generator.rb +49 -0
  60. data/lib/generators/mercury/install/templates/mongoid_paperclip_image.rb +17 -0
  61. data/lib/mercury/authentication.rb +8 -0
  62. data/lib/mercury-rails.rb +3 -0
  63. data/spec/javascripts/mercury/dialog_spec.js.coffee +281 -0
  64. data/spec/javascripts/mercury/dialogs/backcolor_spec.js.coffee +37 -0
  65. data/spec/javascripts/mercury/dialogs/forecolor_spec.js.coffee +37 -0
  66. data/spec/javascripts/mercury/dialogs/formatblock_spec.js.coffee +25 -0
  67. data/spec/javascripts/mercury/dialogs/snippetpanel_spec.js.coffee +30 -0
  68. data/spec/javascripts/mercury/dialogs/style_spec.js.coffee +25 -0
  69. data/spec/javascripts/mercury/history_buffer_spec.js.coffee +76 -0
  70. data/spec/javascripts/mercury/lightview_spec.js.coffee +497 -0
  71. data/spec/javascripts/mercury/mercury_spec.js.coffee +132 -0
  72. data/spec/javascripts/mercury/modal_spec.js.coffee +504 -0
  73. data/spec/javascripts/mercury/modals/htmleditor_spec.js.coffee +30 -0
  74. data/spec/javascripts/mercury/modals/insertcharacter_spec.js.coffee +29 -0
  75. data/spec/javascripts/mercury/modals/insertlink_spec.js.coffee +220 -0
  76. data/spec/javascripts/mercury/modals/insertmedia_spec.js.coffee +167 -0
  77. data/spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee +52 -0
  78. data/spec/javascripts/mercury/modals/inserttable_spec.js.coffee +160 -0
  79. data/spec/javascripts/mercury/native_extensions_spec.js.coffee +60 -0
  80. data/spec/javascripts/mercury/page_editor_spec.js.coffee +750 -0
  81. data/spec/javascripts/mercury/palette_spec.js.coffee +49 -0
  82. data/spec/javascripts/mercury/panel_spec.js.coffee +185 -0
  83. data/spec/javascripts/mercury/region_spec.js.coffee +298 -0
  84. data/spec/javascripts/mercury/regions/editable_spec.js.coffee +561 -0
  85. data/spec/javascripts/mercury/regions/markupable_spec.js.coffee +367 -0
  86. data/spec/javascripts/mercury/regions/snippetable_spec.js.coffee +370 -0
  87. data/spec/javascripts/mercury/select_spec.js.coffee +49 -0
  88. data/spec/javascripts/mercury/snippet_spec.js.coffee +245 -0
  89. data/spec/javascripts/mercury/snippet_toolbar_spec.js.coffee +184 -0
  90. data/spec/javascripts/mercury/statusbar_spec.js.coffee +150 -0
  91. data/spec/javascripts/mercury/table_editor_spec.js.coffee +194 -0
  92. data/spec/javascripts/mercury/toolbar.button_group_spec.js.coffee +90 -0
  93. data/spec/javascripts/mercury/toolbar.button_spec.js.coffee +360 -0
  94. data/spec/javascripts/mercury/toolbar.expander_spec.js.coffee +118 -0
  95. data/spec/javascripts/mercury/toolbar_spec.js.coffee +222 -0
  96. data/spec/javascripts/mercury/tooltip_spec.js.coffee +186 -0
  97. data/spec/javascripts/mercury/uploader_spec.js.coffee +514 -0
  98. data/spec/javascripts/spec_helper.js +513 -0
  99. data/spec/javascripts/templates/mercury/dialog.html +2 -0
  100. data/spec/javascripts/templates/mercury/dialogs/backcolor.html +5 -0
  101. data/spec/javascripts/templates/mercury/dialogs/forecolor.html +5 -0
  102. data/spec/javascripts/templates/mercury/dialogs/formatblock.html +3 -0
  103. data/spec/javascripts/templates/mercury/dialogs/snippetpanel.html +16 -0
  104. data/spec/javascripts/templates/mercury/dialogs/style.html +3 -0
  105. data/spec/javascripts/templates/mercury/lightview.html +13 -0
  106. data/spec/javascripts/templates/mercury/modal.html +13 -0
  107. data/spec/javascripts/templates/mercury/modals/htmleditor.html +5 -0
  108. data/spec/javascripts/templates/mercury/modals/insertcharacter.html +5 -0
  109. data/spec/javascripts/templates/mercury/modals/insertlink.html +30 -0
  110. data/spec/javascripts/templates/mercury/modals/insertmedia.html +35 -0
  111. data/spec/javascripts/templates/mercury/modals/insertsnippet.html +6 -0
  112. data/spec/javascripts/templates/mercury/modals/inserttable.html +27 -0
  113. data/spec/javascripts/templates/mercury/page_editor.html +35 -0
  114. data/spec/javascripts/templates/mercury/palette.html +16 -0
  115. data/spec/javascripts/templates/mercury/panel.html +16 -0
  116. data/spec/javascripts/templates/mercury/region.html +2 -0
  117. data/spec/javascripts/templates/mercury/regions/editable.html +3 -0
  118. data/spec/javascripts/templates/mercury/regions/snippetable.html +4 -0
  119. data/spec/javascripts/templates/mercury/select.html +16 -0
  120. data/spec/javascripts/templates/mercury/snippet.html +1 -0
  121. data/spec/javascripts/templates/mercury/snippet_toolbar.html +16 -0
  122. data/spec/javascripts/templates/mercury/statusbar.html +8 -0
  123. data/spec/javascripts/templates/mercury/table_editor.html +65 -0
  124. data/spec/javascripts/templates/mercury/toolbar.button.html +64 -0
  125. data/spec/javascripts/templates/mercury/toolbar.button_group.html +9 -0
  126. data/spec/javascripts/templates/mercury/toolbar.expander.html +18 -0
  127. data/spec/javascripts/templates/mercury/toolbar.html +11 -0
  128. data/spec/javascripts/templates/mercury/tooltip.html +12 -0
  129. data/spec/javascripts/templates/mercury/uploader.html +11 -0
  130. data/vendor/assets/images/mercury/button.png +0 -0
  131. data/vendor/assets/images/mercury/close.png +0 -0
  132. data/vendor/assets/images/mercury/default-snippet.png +0 -0
  133. data/vendor/assets/images/mercury/loading-dark.gif +0 -0
  134. data/vendor/assets/images/mercury/loading-light.gif +0 -0
  135. data/vendor/assets/images/mercury/missing-image.png +0 -0
  136. data/vendor/assets/images/mercury/search-icon.png +0 -0
  137. data/vendor/assets/images/mercury/temp-logo.png +0 -0
  138. data/vendor/assets/images/mercury/toolbar/editable/buttons.png +0 -0
  139. data/vendor/assets/images/mercury/toolbar/primary/_expander.png +0 -0
  140. data/vendor/assets/images/mercury/toolbar/primary/_pressed.png +0 -0
  141. data/vendor/assets/images/mercury/toolbar/primary/historypanel.png +0 -0
  142. data/vendor/assets/images/mercury/toolbar/primary/insertcharacter.png +0 -0
  143. data/vendor/assets/images/mercury/toolbar/primary/insertlink.png +0 -0
  144. data/vendor/assets/images/mercury/toolbar/primary/insertmedia.png +0 -0
  145. data/vendor/assets/images/mercury/toolbar/primary/inserttable.png +0 -0
  146. data/vendor/assets/images/mercury/toolbar/primary/inspectorpanel.png +0 -0
  147. data/vendor/assets/images/mercury/toolbar/primary/notespanel.png +0 -0
  148. data/vendor/assets/images/mercury/toolbar/primary/preview.png +0 -0
  149. data/vendor/assets/images/mercury/toolbar/primary/redo.png +0 -0
  150. data/vendor/assets/images/mercury/toolbar/primary/save.png +0 -0
  151. data/vendor/assets/images/mercury/toolbar/primary/snippetpanel.png +0 -0
  152. data/vendor/assets/images/mercury/toolbar/primary/undo.png +0 -0
  153. data/vendor/assets/images/mercury/toolbar/snippetable/buttons.png +0 -0
  154. data/vendor/assets/javascripts/mercury/dependencies/jquery-1.7.js +9300 -0
  155. data/vendor/assets/javascripts/mercury/dependencies/jquery-ui-1.8.13.custom.js +1328 -0
  156. data/vendor/assets/javascripts/mercury/dependencies/jquery-ui-1.8.18.custom.min.js +356 -0
  157. data/vendor/assets/javascripts/mercury/dependencies/jquery-ui.1.8.13.custom.min.js +356 -0
  158. data/vendor/assets/javascripts/mercury/dependencies/jquery.additions.js +206 -0
  159. data/vendor/assets/javascripts/mercury/dependencies/jquery.htmlClean.js +527 -0
  160. data/vendor/assets/javascripts/mercury/dependencies/liquidmetal.js +88 -0
  161. data/vendor/assets/javascripts/mercury/dependencies/showdown.js +1340 -0
  162. data/vendor/assets/javascripts/mercury/dialog.js.coffee +159 -0
  163. data/vendor/assets/javascripts/mercury/dialogs/backcolor.js.coffee +6 -0
  164. data/vendor/assets/javascripts/mercury/dialogs/forecolor.js.coffee +6 -0
  165. data/vendor/assets/javascripts/mercury/dialogs/formatblock.js.coffee +4 -0
  166. data/vendor/assets/javascripts/mercury/dialogs/snippetpanel.js.coffee +10 -0
  167. data/vendor/assets/javascripts/mercury/dialogs/style.js.coffee +4 -0
  168. data/vendor/assets/javascripts/mercury/finalize.js.coffee +3 -0
  169. data/vendor/assets/javascripts/mercury/history_buffer.js.coffee +30 -0
  170. data/vendor/assets/javascripts/mercury/lightview.js.coffee +205 -0
  171. data/vendor/assets/javascripts/mercury/locales/da.locale.js.coffee +0 -0
  172. data/vendor/assets/javascripts/mercury/locales/de.locale.js.coffee +206 -0
  173. data/vendor/assets/javascripts/mercury/locales/es.locale.js.coffee +211 -0
  174. data/vendor/assets/javascripts/mercury/locales/example.local.js.coffee +211 -0
  175. data/vendor/assets/javascripts/mercury/locales/fr.locale.js.coffee +211 -0
  176. data/vendor/assets/javascripts/mercury/locales/it.locale.js.coffee +208 -0
  177. data/vendor/assets/javascripts/mercury/locales/ko.local.js.coffee +206 -0
  178. data/vendor/assets/javascripts/mercury/locales/nl.locale.js.coffee +206 -0
  179. data/vendor/assets/javascripts/mercury/locales/pt.locale.js.coffee +211 -0
  180. data/vendor/assets/javascripts/mercury/locales/sv.local.js.coffee +209 -0
  181. data/vendor/assets/javascripts/mercury/locales/swedish_chef.locale.js.coffee +213 -0
  182. data/vendor/assets/javascripts/mercury/mercury.js.coffee +109 -0
  183. data/vendor/assets/javascripts/mercury/modal.js.coffee +204 -0
  184. data/vendor/assets/javascripts/mercury/modals/htmleditor.js.coffee +11 -0
  185. data/vendor/assets/javascripts/mercury/modals/insertcharacter.js.coffee +4 -0
  186. data/vendor/assets/javascripts/mercury/modals/insertlink.js.coffee +95 -0
  187. data/vendor/assets/javascripts/mercury/modals/insertmedia.js.coffee +107 -0
  188. data/vendor/assets/javascripts/mercury/modals/insertsnippet.js.coffee +12 -0
  189. data/vendor/assets/javascripts/mercury/modals/inserttable.js.coffee +54 -0
  190. data/vendor/assets/javascripts/mercury/native_extensions.js.coffee +55 -0
  191. data/vendor/assets/javascripts/mercury/page_editor.js.coffee +241 -0
  192. data/vendor/assets/javascripts/mercury/palette.js.coffee +29 -0
  193. data/vendor/assets/javascripts/mercury/panel.js.coffee +115 -0
  194. data/vendor/assets/javascripts/mercury/plugins/save_as_xml/mercury/page_editor.js.coffee +28 -0
  195. data/vendor/assets/javascripts/mercury/plugins/save_as_xml/plugin.js +9 -0
  196. data/vendor/assets/javascripts/mercury/region.js.coffee +107 -0
  197. data/vendor/assets/javascripts/mercury/regions/editable.js.coffee +600 -0
  198. data/vendor/assets/javascripts/mercury/regions/markupable.js.coffee +398 -0
  199. data/vendor/assets/javascripts/mercury/regions/simple.js.coffee +339 -0
  200. data/vendor/assets/javascripts/mercury/regions/snippetable.js.coffee +124 -0
  201. data/vendor/assets/javascripts/mercury/select.js.coffee +44 -0
  202. data/vendor/assets/javascripts/mercury/snippet.js.coffee +104 -0
  203. data/vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee +72 -0
  204. data/vendor/assets/javascripts/mercury/statusbar.js.coffee +51 -0
  205. data/vendor/assets/javascripts/mercury/support/history.js +1 -0
  206. data/vendor/assets/javascripts/mercury/table_editor.js.coffee +265 -0
  207. data/vendor/assets/javascripts/mercury/toolbar.button.js.coffee +173 -0
  208. data/vendor/assets/javascripts/mercury/toolbar.button_group.js.coffee +42 -0
  209. data/vendor/assets/javascripts/mercury/toolbar.expander.js.coffee +56 -0
  210. data/vendor/assets/javascripts/mercury/toolbar.js.coffee +86 -0
  211. data/vendor/assets/javascripts/mercury/tooltip.js.coffee +74 -0
  212. data/vendor/assets/javascripts/mercury/uploader.js.coffee +227 -0
  213. data/vendor/assets/javascripts/mercury.js +479 -0
  214. data/vendor/assets/javascripts/mercury_loader.js +193 -0
  215. data/vendor/assets/javascripts/mercury_overrides.js +6 -0
  216. data/vendor/assets/javascripts/popup.js +8 -0
  217. data/vendor/assets/stylesheets/mercury/all_images.css.erb +89 -0
  218. data/vendor/assets/stylesheets/mercury/dialog.css +208 -0
  219. data/vendor/assets/stylesheets/mercury/lightview.css +151 -0
  220. data/vendor/assets/stylesheets/mercury/mercury.css +151 -0
  221. data/vendor/assets/stylesheets/mercury/modal.css +183 -0
  222. data/vendor/assets/stylesheets/mercury/statusbar.css +32 -0
  223. data/vendor/assets/stylesheets/mercury/toolbar.css +304 -0
  224. data/vendor/assets/stylesheets/mercury/tooltip.css +26 -0
  225. data/vendor/assets/stylesheets/mercury/uploader.css +111 -0
  226. data/vendor/assets/stylesheets/mercury.css +28 -0
  227. data/vendor/assets/stylesheets/mercury_overrides.css +17 -0
  228. data/vendor/assets/stylesheets/popup.css.erb +37 -0
  229. metadata +634 -0
@@ -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("DSC Kit Editor")
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
+ document.location = 'http://www.dsc.net'
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)
@@ -0,0 +1,173 @@
1
+ class @Mercury.Toolbar.Button
2
+
3
+ constructor: (@name, @title, @summary = null, @types = {}, @options = {}) ->
4
+ @title = Mercury.I18n(@title) if @title
5
+ @summary = Mercury.I18n(@summary) if @summary
6
+
7
+ @build()
8
+ @bindEvents()
9
+ return @element
10
+
11
+
12
+ build: ->
13
+ @element = jQuery('<div>', {title: @summary ? @title, class: "mercury-button mercury-#{@name}-button"}).html("<em>#{@title}</em>")
14
+ @element.data('expander', "<div class=\"mercury-expander-button\" data-button=\"#{@name}\"><em></em><span>#{@title}</span></div>")
15
+
16
+ @handled = {}
17
+
18
+ for own type, mixed of @types
19
+ switch type
20
+ when 'preload' then true
21
+
22
+ when 'regions'
23
+ @element.addClass('disabled')
24
+ @handled[type] = if jQuery.isFunction(mixed) then mixed.call(@, @name) else mixed
25
+
26
+ when 'toggle'
27
+ @handled[type] = true
28
+
29
+ when 'mode'
30
+ @handled[type] = if mixed == true then @name else mixed
31
+
32
+ when 'context'
33
+ @handled[type] = if jQuery.isFunction(mixed) then mixed else Mercury.Toolbar.Button.contexts[@name]
34
+
35
+ when 'palette'
36
+ @element.addClass("mercury-button-palette")
37
+ url = if jQuery.isFunction(mixed) then mixed.call(@, @name) else mixed
38
+ @handled[type] = new Mercury.Palette(url, @name, @defaultDialogOptions())
39
+
40
+ when 'select'
41
+ @element.addClass("mercury-button-select").find('em').html(@title)
42
+ url = if jQuery.isFunction(mixed) then mixed.call(@, @name) else mixed
43
+ @handled[type] = new Mercury.Select(url, @name, @defaultDialogOptions())
44
+
45
+ when 'panel'
46
+ @element.addClass('mercury-button-panel')
47
+ url = if jQuery.isFunction(mixed) then mixed.call(@, @name) else mixed
48
+ @handled['toggle'] = true
49
+ @handled[type] = new Mercury.Panel(url, @name, @defaultDialogOptions())
50
+
51
+ when 'modal'
52
+ @handled[type] = if jQuery.isFunction(mixed) then mixed.apply(@, @name) else mixed
53
+
54
+ when 'lightview'
55
+ @handled[type] = if jQuery.isFunction(mixed) then mixed.apply(@, @name) else mixed
56
+
57
+ else throw Mercury.I18n('Unknown button type \"%s\" used for the \"%s\" button.', type, @name)
58
+
59
+
60
+ bindEvents: ->
61
+ Mercury.on 'button', (event, options) => @element.click() if options.action == @name
62
+ Mercury.on 'mode', (event, options) => @togglePressed() if @handled.mode == options.mode && @handled.toggle
63
+
64
+ Mercury.on 'region:update', (event, options) =>
65
+ if @handled.context && options.region && jQuery.type(options.region.currentElement) == 'function'
66
+ element = options.region.currentElement()
67
+ if element.length && @handled.context.call(@, element, options.region.element)
68
+ @element.addClass('active')
69
+ else
70
+ @element.removeClass('active')
71
+ else
72
+ @element.removeClass('active')
73
+
74
+ Mercury.on 'region:focused', (event, options) =>
75
+ if @handled.regions && options.region && options.region.type
76
+ if @handled.regions.indexOf(options.region.type) > -1
77
+ @element.removeClass('disabled')
78
+ else
79
+ @element.addClass('disabled')
80
+
81
+ Mercury.on 'region:blurred', =>
82
+ @element.addClass('disabled') if @handled.regions
83
+
84
+ @element.on 'mousedown', =>
85
+ @element.addClass('active')
86
+
87
+ @element.on 'mouseup', =>
88
+ @element.removeClass('active')
89
+
90
+ @element.on 'click', (event) =>
91
+ if @element.closest('.disabled').length then return
92
+
93
+ handled = false
94
+ for own type, mixed of @handled
95
+ switch type
96
+ when 'toggle'
97
+ @togglePressed() unless @handled.mode
98
+
99
+ when 'mode'
100
+ handled = true
101
+ Mercury.trigger('mode', {mode: mixed})
102
+
103
+ when 'modal'
104
+ handled = true
105
+ Mercury.modal(@handled.modal, {title: @summary || @title, handler: @name})
106
+
107
+ when 'lightview'
108
+ handled = true
109
+ Mercury.lightview(@handled.lightview, {title: @summary || @title, handler: @name, closeButton: true})
110
+
111
+ when 'palette', 'select', 'panel'
112
+ event.stopPropagation()
113
+ handled = true
114
+ @handled[type].toggle()
115
+
116
+ Mercury.trigger('action', {action: @name}) unless handled
117
+ Mercury.trigger('focus:frame') if @options['regions'] && @options['regions'].length
118
+
119
+
120
+ defaultDialogOptions: ->
121
+ return {
122
+ title: @summary || @title
123
+ preload: @types.preload
124
+ appendTo: @options.appendDialogsTo || 'body'
125
+ closeButton: true
126
+ for: @element
127
+ }
128
+
129
+
130
+ togglePressed: ->
131
+ @element.toggleClass('pressed')
132
+
133
+
134
+
135
+ # Button contexts
136
+ @Mercury.Toolbar.Button.contexts =
137
+
138
+ backColor: (node) -> @element.css('background-color', node.css('background-color'))
139
+
140
+ foreColor: (node) -> @element.css('background-color', node.css('color'))
141
+
142
+ bold: (node) ->
143
+ weight = node.css('font-weight')
144
+ weight == 'bold' || weight > 400
145
+
146
+ italic: (node) -> node.css('font-style') == 'italic'
147
+
148
+ # overline is weird because <u> and <strike> override text-decoration -- we can't always tell without checking parents
149
+ overline: (node) ->
150
+ return true if node.css('text-decoration') == 'overline'
151
+ for parent in node.parentsUntil(@element)
152
+ return true if jQuery(parent).css('text-decoration') == 'overline'
153
+ return false
154
+
155
+ strikethrough: (node, region) -> node.css('text-decoration') == 'line-through' || !!node.closest('strike', region).length
156
+
157
+ underline: (node, region) -> node.css('text-decoration') == 'underline' || !!node.closest('u', region).length
158
+
159
+ subscript: (node, region) -> !!node.closest('sub', region).length
160
+
161
+ superscript: (node, region) -> !!node.closest('sup', region).length
162
+
163
+ justifyLeft: (node) -> node.css('text-align').indexOf('left') > -1
164
+
165
+ justifyCenter: (node) -> node.css('text-align').indexOf('center') > -1
166
+
167
+ justifyRight: (node) -> node.css('text-align').indexOf('right') > -1
168
+
169
+ justifyFull: (node) -> node.css('text-align').indexOf('justify') > -1
170
+
171
+ insertOrderedList: (node, region) -> !!node.closest('ol', region.element).length
172
+
173
+ insertUnorderedList: (node, region) -> !!node.closest('ul', region.element).length
@@ -0,0 +1,42 @@
1
+ class @Mercury.Toolbar.ButtonGroup
2
+
3
+ constructor: (@name, @options = {}) ->
4
+ @build()
5
+ @bindEvents()
6
+ @regions = @options._regions
7
+ return @element
8
+
9
+
10
+ build: ->
11
+ @element = jQuery('<div>', {class: "mercury-button-group mercury-#{@name}-group"})
12
+ if @options._context || @options._regions
13
+ @element.addClass('disabled')
14
+
15
+
16
+ bindEvents: ->
17
+ Mercury.on 'region:update', (event, options) =>
18
+ context = Mercury.Toolbar.ButtonGroup.contexts[@name]
19
+ if context
20
+ if options.region && jQuery.type(options.region.currentElement) == 'function'
21
+ element = options.region.currentElement()
22
+ if element.length && context.call(@, element, options.region.element)
23
+ @element.removeClass('disabled')
24
+ else
25
+ @element.addClass('disabled')
26
+
27
+ Mercury.on 'region:focused', (event, options) =>
28
+ if @regions && options.region && options.region.type
29
+ if @regions.indexOf(options.region.type) > -1
30
+ @element.removeClass('disabled') unless @options._context
31
+ else
32
+ @element.addClass('disabled')
33
+
34
+ Mercury.on 'region:blurred', (event, options) =>
35
+ @element.addClass('disabled') if @options.regions
36
+
37
+
38
+
39
+ # ButtonGroup contexts
40
+ @Mercury.Toolbar.ButtonGroup.contexts =
41
+
42
+ table: (node, region) -> !!node.closest('table', region).length
@@ -0,0 +1,56 @@
1
+ class @Mercury.Toolbar.Expander extends Mercury.Palette
2
+
3
+ constructor: (@name, @options) ->
4
+ @container = @options.for
5
+ @containerWidth = @container.outerWidth()
6
+ super(null, @name, @options)
7
+ return @element
8
+
9
+
10
+ build: ->
11
+ @container.css({whiteSpace: 'normal'})
12
+ @trigger = jQuery('<div>', {class: 'mercury-toolbar-expander'}).appendTo(jQuery(@options.appendTo).get(0) ? 'body')
13
+ @element = jQuery('<div>', {class: "mercury-palette mercury-expander mercury-#{@name}-expander", style: 'display:none'})
14
+ @windowResize()
15
+
16
+
17
+ bindEvents: ->
18
+ Mercury.on 'hide:dialogs', (event, dialog) => @hide() unless dialog == @
19
+ Mercury.on 'resize', => @windowResize()
20
+
21
+ super
22
+
23
+ @trigger.click (event) =>
24
+ event.stopPropagation()
25
+ hiddenButtons = []
26
+ for button in @container.find('.mercury-button')
27
+ button = jQuery(button)
28
+ hiddenButtons.push(button.data('expander')) if button.position().top > 5
29
+
30
+ @loadContent(hiddenButtons.join(''))
31
+ @toggle()
32
+
33
+ @element.click (event) =>
34
+ buttonName = jQuery(event.target).closest('[data-button]').data('button')
35
+ button = @container.find(".mercury-#{buttonName}-button")
36
+ button.click()
37
+
38
+
39
+ windowResize: ->
40
+ if @containerWidth > jQuery(window).width() then @trigger.show() else @trigger.hide()
41
+ @hide()
42
+
43
+
44
+ position: (keepVisible) ->
45
+ @element.css({top: 0, left: 0, display: 'block', visibility: 'hidden'})
46
+ position = @trigger.offset()
47
+ width = @element.width()
48
+
49
+ position.left = position.left - width + @trigger.width() if position.left + width > jQuery(window).width()
50
+
51
+ @element.css {
52
+ top: position.top + @trigger.height()
53
+ left: position.left
54
+ display: if keepVisible then 'block' else 'none'
55
+ visibility: 'visible'
56
+ }