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,109 @@
1
+ # ## Require all the dependencies
2
+ #= require mercury/dependencies/jquery-ui-1.8.18.custom.min
3
+ #= require mercury/dependencies/jquery.additions
4
+ #= require mercury/dependencies/jquery.htmlClean
5
+ #= require mercury/dependencies/liquidmetal
6
+ #= require mercury/dependencies/showdown
7
+ #
8
+ # ## Require all mercury files
9
+ #= require_self
10
+ #= require ./native_extensions
11
+ #= require ./page_editor
12
+ #= require ./history_buffer
13
+ #= require ./table_editor
14
+ #= require ./dialog
15
+ #= require ./palette
16
+ #= require ./select
17
+ #= require ./panel
18
+ #= require ./modal
19
+ #= require ./lightview
20
+ #= require ./statusbar
21
+ #= require ./toolbar
22
+ #= require ./toolbar.button
23
+ #= require ./toolbar.button_group
24
+ #= require ./toolbar.expander
25
+ #= require ./tooltip
26
+ #= require ./snippet
27
+ #= require ./snippet_toolbar
28
+ #= require ./region
29
+ #= require ./uploader
30
+ #= require_tree ./regions
31
+ #= require_tree ./dialogs
32
+ #= require_tree ./modals
33
+ #= require ./finalize
34
+ #
35
+ @Mercury ||= {}
36
+ jQuery.extend @Mercury,
37
+ version: '0.3.0'
38
+
39
+ # Mercury object namespaces
40
+ Regions: Mercury.Regions || {}
41
+ modalHandlers: Mercury.modalHandlers || {}
42
+ lightviewHandlers: Mercury.lightviewHandlers || {}
43
+ dialogHandlers: Mercury.dialogHandlers || {}
44
+ preloadedViews: Mercury.preloadedViews || {}
45
+
46
+ # Custom ajax headers
47
+ ajaxHeaders: ->
48
+ headers = {}
49
+ headers[Mercury.config.csrfHeader] = Mercury.csrfToken
50
+ return headers
51
+
52
+
53
+ # Custom event methods
54
+ on: (eventName, callback) ->
55
+ jQuery(window).on("mercury:#{eventName}", callback)
56
+
57
+
58
+ trigger: (eventName, options) ->
59
+ Mercury.log(eventName, options)
60
+ jQuery(window).trigger("mercury:#{eventName}", options)
61
+
62
+
63
+ # Alerting and logging methods
64
+ notify: (args...) ->
65
+ window.alert(Mercury.I18n.apply(@, args))
66
+
67
+
68
+ warn: (message, severity = 0) ->
69
+ if console
70
+ try console.warn(message)
71
+ catch e1
72
+ if severity >= 1
73
+ try console.debug(message) catch e2
74
+ else if severity >= 1
75
+ Mercury.notify(message)
76
+
77
+
78
+ deprecated: (message)->
79
+ message = "#{message} -- #{console.trace()}" if console && console.trace
80
+ #throw "deprecated: #{message}"
81
+ Mercury.warn("deprecated: #{message}", 1)
82
+
83
+
84
+ log: ->
85
+ if Mercury.debug && console
86
+ return if arguments[0] == 'hide:toolbar' || arguments[0] == 'show:toolbar'
87
+ try console.debug(arguments)
88
+ catch e
89
+
90
+
91
+ # I18n / Translation methods
92
+ locale: ->
93
+ return Mercury.determinedLocale if Mercury.determinedLocale
94
+ if Mercury.config.localization.enabled
95
+ locale = []
96
+ if navigator.language && (locale = navigator.language.toString().split('-')).length
97
+ topLocale = Mercury.I18n[locale[0]] || {}
98
+ subLocale = if locale.length > 1 then topLocale["_#{locale[1].toUpperCase()}_"]
99
+ if !Mercury.I18n[locale[0]]
100
+ locale = Mercury.config.localization.preferredLocale.split('-')
101
+ topLocale = Mercury.I18n[locale[0]] || {}
102
+ subLocale = if locale.length > 1 then topLocale["_#{locale[1].toUpperCase()}_"]
103
+ return Mercury.determinedLocale = {top: topLocale || {}, sub: subLocale || {}}
104
+
105
+
106
+ I18n: (sourceString, args...) ->
107
+ locale = Mercury.locale()
108
+ translation = (locale.sub[sourceString] || locale.top[sourceString] || sourceString || '').toString()
109
+ return if args.length then translation.printf.apply(translation, args) else translation
@@ -0,0 +1,204 @@
1
+ @Mercury.modal = (url, options = {}) ->
2
+ Mercury.modal.show(url, options)
3
+ return Mercury.modal
4
+
5
+ jQuery.extend Mercury.modal,
6
+ minWidth: 500
7
+
8
+ show: (@url, @options = {}) ->
9
+ Mercury.trigger('focus:window')
10
+ @initialize()
11
+ if @visible then @update() else @appear()
12
+ if @options.content
13
+ setTimeout 500, => @loadContent(@options.content)
14
+
15
+
16
+ initialize: ->
17
+ return if @initialized
18
+ @build()
19
+ @bindEvents()
20
+ @initialized = true
21
+
22
+
23
+ build: ->
24
+ @element = jQuery('<div>', {class: 'mercury-modal loading'})
25
+ @element.html('<h1 class="mercury-modal-title"><span></span><a>&times;</a></h1>')
26
+ @element.append('<div class="mercury-modal-content-container"><div class="mercury-modal-content"></div></div>')
27
+
28
+ @overlay = jQuery('<div>', {class: 'mercury-modal-overlay'})
29
+
30
+ @titleElement = @element.find('.mercury-modal-title')
31
+ @contentContainerElement = @element.find('.mercury-modal-content-container')
32
+
33
+ @contentElement = @element.find('.mercury-modal-content')
34
+
35
+ @element.appendTo(jQuery(@options.appendTo).get(0) ? 'body')
36
+ @overlay.appendTo(jQuery(@options.appendTo).get(0) ? 'body')
37
+
38
+
39
+ bindEvents: ->
40
+ Mercury.on 'refresh', => @resize(true)
41
+ Mercury.on 'resize', => @position()
42
+
43
+ @overlay.on 'click', =>
44
+ @hide() if @options.allowHideUsingOverlay
45
+
46
+ @titleElement.find('a').on 'click', =>
47
+ @hide()
48
+
49
+ @element.on 'ajax:beforeSend', (event, xhr, options) =>
50
+ options.success = (content) =>
51
+ @loadContent(content)
52
+
53
+ jQuery(document).on 'keydown', (event) =>
54
+ @hide() if event.keyCode == 27 && @visible
55
+
56
+
57
+ appear: ->
58
+ @showing = true
59
+ @position()
60
+
61
+ @overlay.show()
62
+ @overlay.animate {opacity: 1}, 200, 'easeInOutSine', =>
63
+ @element.css({top: -@element.height()})
64
+ @setTitle()
65
+ @element.show()
66
+ @element.animate {top: 0}, 200, 'easeInOutSine', =>
67
+ @visible = true
68
+ @showing = false
69
+ @load()
70
+
71
+
72
+ set_height: (height) ->
73
+ @fix_height = height
74
+ this.resize(true)
75
+
76
+ resize: (keepVisible) ->
77
+ visibility = if keepVisible then 'visible' else 'hidden'
78
+
79
+ titleHeight = @titleElement.outerHeight()
80
+
81
+ width = @contentElement.outerWidth()
82
+
83
+ @contentPane.css({height: 'auto'}) if @contentPane
84
+ @contentElement.css({height: 'auto', visibility: visibility, display: 'block'})
85
+
86
+ height = @contentElement.outerHeight() + titleHeight
87
+
88
+ width = @minWidth if width < @minWidth
89
+ height = Mercury.displayRect.fullHeight - 20 if height > Mercury.displayRect.fullHeight - 20 || @options.fullHeight
90
+ if @fix_height
91
+ height = @fix_height
92
+
93
+ @element.stop().animate {left: (Mercury.displayRect.width - width) / 2, width: width, height: height}, 200, 'easeInOutSine', =>
94
+ @contentElement.css({visibility: 'visible', display: 'block'})
95
+ if @contentPane.length
96
+ @contentElement.css({height: height - titleHeight, overflow: 'visible'})
97
+ controlHeight = if @contentControl.length then @contentControl.outerHeight() else 0
98
+ @contentPane.css({height: height - titleHeight - controlHeight - 40})
99
+ @contentPane.find('.mercury-display-pane').css({width: width - 40})
100
+ else
101
+ @contentElement.css({height: height - titleHeight, overflow: 'auto'})
102
+
103
+
104
+ position: ->
105
+ viewportWidth = Mercury.displayRect.width
106
+
107
+ @contentPane.css({height: 'auto'}) if @contentPane
108
+ @contentElement.css({height: 'auto'})
109
+ @element.css({width: 'auto', height: 'auto', display: 'block', visibility: 'hidden'})
110
+
111
+ width = @element.width()
112
+ height = @element.height()
113
+
114
+ width = @minWidth if width < @minWidth
115
+ height = Mercury.displayRect.fullHeight - 20 if height > Mercury.displayRect.fullHeight - 20 || @options.fullHeight
116
+
117
+ titleHeight = @titleElement.outerHeight()
118
+ if @contentPane && @contentPane.length
119
+ @contentElement.css({height: height - titleHeight, overflow: 'visible'})
120
+ controlHeight = if @contentControl.length then @contentControl.outerHeight() else 0
121
+ @contentPane.css({height: height - titleHeight - controlHeight - 40})
122
+ @contentPane.find('.mercury-display-pane').css({width: width - 40})
123
+ else
124
+ @contentElement.css({height: height - titleHeight, overflow: 'auto'})
125
+
126
+ @element.css {
127
+ left: (viewportWidth - width) / 2
128
+ width: width
129
+ height: height
130
+ display: if @visible then 'block' else 'none'
131
+ visibility: 'visible'
132
+ }
133
+
134
+
135
+ update: ->
136
+ @reset()
137
+ @resize()
138
+ @load()
139
+
140
+
141
+ load: ->
142
+ @setTitle()
143
+ return unless @url
144
+ @element.addClass('loading')
145
+ if Mercury.preloadedViews[@url]
146
+ setTimeout(10, => @loadContent(Mercury.preloadedViews[@url]))
147
+ else
148
+ jQuery.ajax @url, {
149
+ headers: Mercury.ajaxHeaders()
150
+ type: @options.loadType || 'GET'
151
+ data: @options.loadData
152
+ success: (data) => @loadContent(data)
153
+ error: =>
154
+ @hide()
155
+ Mercury.notify("Mercury was unable to load %s for the modal.", @url)
156
+ }
157
+
158
+
159
+ loadContent: (data, options = null) ->
160
+ @initialize()
161
+ @options = options || @options
162
+ @setTitle()
163
+ @loaded = true
164
+ @element.removeClass('loading')
165
+ @contentElement.html(data)
166
+ @contentElement.css({display: 'none', visibility: 'hidden'})
167
+
168
+ # for complex modal content, we provide panes and controls
169
+ @contentPane = @element.find('.mercury-display-pane-container')
170
+ @contentControl = @element.find('.mercury-display-controls')
171
+
172
+ @options.afterLoad.call(@) if @options.afterLoad
173
+ if @options.handler
174
+ if Mercury.modalHandlers[@options.handler]
175
+ Mercury.modalHandlers[@options.handler].call(@)
176
+ else if Mercury.lightviewHandlers[@options.handler]
177
+ Mercury.lightviewHandlers[@options.handler].call(@)
178
+
179
+ @element.localize(Mercury.locale()) if Mercury.config.localization.enabled
180
+ @resize()
181
+
182
+
183
+ setTitle: ->
184
+ @titleElement.find('span').html(Mercury.I18n(@options.title))
185
+ closeButton = @titleElement.find('a')
186
+ if @options.closeButton == false then closeButton.hide() else closeButton.show()
187
+
188
+
189
+ reset: ->
190
+ @titleElement.find('span').html('')
191
+ @contentElement.html('')
192
+
193
+
194
+ hide: ->
195
+ return if @showing
196
+ @options = {}
197
+ @initialized = false
198
+
199
+ Mercury.trigger('focus:frame')
200
+ @element.hide()
201
+ @overlay.hide()
202
+ @reset()
203
+
204
+ @visible = false
@@ -0,0 +1,11 @@
1
+ @Mercury.modalHandlers.htmlEditor = ->
2
+ # fill the text area with the content
3
+ content = Mercury.region.content(null, true, false)
4
+ @element.find('textarea').val(content)
5
+
6
+ # replace the contents on form submit
7
+ @element.find('form').on 'submit', (event) =>
8
+ event.preventDefault()
9
+ value = @element.find('textarea').val().replace(/\n/g, '')
10
+ Mercury.trigger('action', {action: 'replaceHTML', value: value})
11
+ @hide()
@@ -0,0 +1,4 @@
1
+ @Mercury.modalHandlers.insertCharacter = ->
2
+ @element.find('.character').on 'click', (event) =>
3
+ Mercury.trigger('action', {action: 'insertHTML', value: "&#{jQuery(event.target).attr('data-entity')};"})
4
+ @hide()
@@ -0,0 +1,95 @@
1
+ @Mercury.modalHandlers.insertLink = ->
2
+ # make the inputs work with the radio buttons
3
+ @element.find('label input').on 'click', ->
4
+ jQuery(@).closest('label').next('.selectable').focus()
5
+
6
+ @element.find('.selectable').on 'focus', ->
7
+ jQuery(@).prev('label').find('input[type=radio]').prop("checked", true)
8
+
9
+ # show/hide the link target options on target change
10
+ @element.find('#link_target').on 'change', =>
11
+ @element.find(".link-target-options").hide()
12
+ @element.find("##{@element.find('#link_target').val()}_options").show()
13
+ @resize(true)
14
+
15
+ # fill the existing bookmark select
16
+ bookmarkSelect = @element.find('#link_existing_bookmark')
17
+ for link in jQuery('a[name]', window.mercuryInstance.document)
18
+ bookmarkSelect.append(jQuery('<option>', {value: jQuery(link).attr('name')}).text(jQuery(link).text()))
19
+
20
+ # get the selection and initialize its information into the form
21
+ if Mercury.region && Mercury.region.selection
22
+ selection = Mercury.region.selection()
23
+
24
+ # if we're editing a link prefill the information
25
+ container = selection.commonAncestor(true).closest('a') if selection && selection.commonAncestor
26
+
27
+ if container && container.length
28
+ existingLink = container
29
+
30
+ # don't allow changing the content on edit
31
+ @element.find('#link_text_container').hide()
32
+
33
+ # fill in the external url or bookmark select based on what it looks like
34
+ if container.attr('href') && container.attr('href').indexOf('#') == 0
35
+ bookmarkSelect.val(container.attr('href').replace(/[^#]*#/, ''))
36
+ bookmarkSelect.prev('label').find('input[type=radio]').prop("checked", true)
37
+ else
38
+ @element.find('#link_external_url').val(container.attr('href'))
39
+
40
+ # if it has a name, assume it's a bookmark target
41
+ if container.attr('name')
42
+ newBookmarkInput = @element.find('#link_new_bookmark')
43
+ newBookmarkInput.val(container.attr('name'))
44
+ newBookmarkInput.prev('label').find('input[type=radio]').prop("checked", true)
45
+
46
+ # if it has a target, select it, and try to pull options out
47
+ if container.attr('target')
48
+ @element.find('#link_target').val(container.attr('target'))
49
+
50
+ # if it's a popup window
51
+ if container.attr('href') && container.attr('href').indexOf('javascript:void') == 0
52
+ href = container.attr('href')
53
+ @element.find('#link_external_url').val(href.match(/window.open\('([^']+)',/)[1])
54
+ @element.find('#link_target').val('popup')
55
+ @element.find('#link_popup_width').val(href.match(/width=(\d+),/)[1])
56
+ @element.find('#link_popup_height').val(href.match(/height=(\d+),/)[1])
57
+ @element.find('#popup_options').show()
58
+
59
+ # get the text content
60
+ @element.find('#link_text').val(selection.textContent()) if selection.textContent
61
+ selection_source = selection.fragment.firstChild.outerHTML if selection.fragment && selection.fragment.firstChild
62
+ @element.find('#link_text').val(selection_source) if selection_source
63
+
64
+ # build the link on form submission
65
+ @element.find('form').on 'submit', (event) =>
66
+ event.preventDefault()
67
+
68
+ content = @element.find('#link_text').val()
69
+ target = @element.find('#link_target').val()
70
+ type = @element.find('input[name=link_type]:checked').val()
71
+
72
+ switch type
73
+ when 'existing_bookmark' then attrs = {href: "##{@element.find('#link_existing_bookmark').val()}"}
74
+ when 'new_bookmark' then attrs = {name: "#{@element.find('#link_new_bookmark').val()}"}
75
+ else attrs = {href: @element.find("#link_#{type}").val()}
76
+
77
+ switch target
78
+ when 'popup'
79
+ args = {
80
+ width: parseInt(@element.find('#link_popup_width').val()) || 500,
81
+ height: parseInt(@element.find('#link_popup_height').val()) || 500,
82
+ menubar: 'no',
83
+ toolbar: 'no'
84
+ }
85
+ attrs['href'] = "javascript:void(window.open('#{attrs['href']}', 'popup_window', '#{jQuery.param(args).replace(/&/g, ',')}'))"
86
+ else attrs['target'] = target if target
87
+
88
+ value = {tagName: 'a', attrs: attrs, content: content}
89
+
90
+ if existingLink
91
+ Mercury.trigger('action', {action: 'replaceLink', value: value, node: existingLink.get(0)})
92
+ else
93
+ Mercury.trigger('action', {action: 'insertLink', value: value})
94
+
95
+ @hide()
@@ -0,0 +1,107 @@
1
+ @Mercury.modalHandlers.insertMedia = ->
2
+ # make the inputs work with the radio buttons, and options
3
+ @element.find('label input').on 'click', ->
4
+ jQuery(@).closest('label').next('.selectable').focus()
5
+
6
+ @element.find('.selectable').on 'focus', (event) =>
7
+ element = jQuery(event.target)
8
+ element.prev('label').find('input[type=radio]').prop("checked", true)
9
+
10
+ @element.find(".media-options").hide()
11
+ @element.find("##{element.attr('id').replace('media_', '')}").show()
12
+ @resize(true)
13
+
14
+ # get the selection and initialize its information into the form
15
+ if Mercury.region && Mercury.region.selection
16
+ selection = Mercury.region.selection()
17
+
18
+ # if we're editing an image prefill the information
19
+ if selection.is && image = selection.is('img')
20
+ @element.find('#media_image_class').val(image.attr('class'))
21
+ @element.find('#media_image_url').val(image.attr('src'))
22
+ @element.find('#media_image_alignment').val(image.attr('align'))
23
+ width = image.width()
24
+ @element.find('#media_image_width').val(width) if width && width>0
25
+ height = image.height()
26
+ @element.find('#media_image_height').val(height) if height && height>0
27
+ setTimeout 300, => @element.find('#media_image_url').focus()
28
+
29
+ # if we're editing an iframe (assume it's a video for now)
30
+ if selection.is && iframe = selection.is('iframe')
31
+ src = iframe.attr('src')
32
+ if src.indexOf('http://www.youtube.com') > -1
33
+ # it's a youtube video
34
+ @element.find('#media_youtube_url').val("http://youtu.be/#{src.match(/\/embed\/(\w+)/)[1]}")
35
+ @element.find('#media_youtube_width').val(iframe.width())
36
+ @element.find('#media_youtube_height').val(iframe.height())
37
+ setTimeout 300, => @element.find('#media_youtube_url').focus()
38
+ else if src.indexOf('http://player.vimeo.com') > -1
39
+ # it's a vimeo video
40
+ @element.find('#media_vimeo_url').val("http://vimeo.com/#{src.match(/\/video\/(\w+)/)[1]}")
41
+ @element.find('#media_vimeo_width').val(iframe.width())
42
+ @element.find('#media_vimeo_height').val(iframe.height())
43
+ setTimeout 300, => @element.find('#media_vimeo_url').focus()
44
+
45
+
46
+ # build the image or youtube embed on form submission
47
+ @element.find('form').on 'submit', (event) =>
48
+ event.preventDefault()
49
+ type = @element.find('input[name=media_type]:checked').val()
50
+
51
+ switch type
52
+ when 'image_url'
53
+ attrs = {src: @element.find('#media_image_url').val()}
54
+ attrs['align'] = alignment if alignment = @element.find('#media_image_alignment').val()
55
+ attrs['class'] = klass if klass = @element.find('#media_image_class').val()
56
+ width = @element.find('#media_image_width').val()
57
+ height = @element.find('#media_image_height').val()
58
+ attrs['width'] = width if width
59
+ attrs['height'] = height if height
60
+ size = 'original'
61
+ if width>0 || height>0
62
+ Mercury.log("Adjusting image file")
63
+ biggest = Math.max(height,width)
64
+ if biggest<=100
65
+ size = 'thumb'
66
+ else if biggest<=300
67
+ size = 'small'
68
+ else if biggest<=500
69
+ size = 'medium'
70
+ else if biggest<=800
71
+ size = 'large'
72
+
73
+ path_bits = attrs['src'].split('/')
74
+ path_bits[10] = size
75
+ attrs['src'] = path_bits.join('/')
76
+ Mercury.trigger('action', {action: 'insertImage', value: attrs})
77
+
78
+ when 'youtube_url'
79
+ url = @element.find('#media_youtube_url').val()
80
+ unless /^http:\/\/youtu.be\//.test(url)
81
+ Mercury.notify('Error: The provided youtube share url was invalid.')
82
+ return
83
+ code = url.replace('http://youtu.be/', '')
84
+ value = jQuery('<iframe>', {
85
+ width: @element.find('#media_youtube_width').val() || 560,
86
+ height: @element.find('#media_youtube_height').val() || 349,
87
+ src: "http://www.youtube.com/embed/#{code}?wmode=transparent",
88
+ frameborder: 0,
89
+ allowfullscreen: 'true'
90
+ })
91
+ Mercury.trigger('action', {action: 'insertHTML', value: value})
92
+
93
+ when 'vimeo_url'
94
+ url = @element.find('#media_vimeo_url').val()
95
+ unless /^http:\/\/vimeo.com\//.test(url)
96
+ Mercury.notify('Error: The provided vimeo url was invalid.')
97
+ return
98
+ code = url.replace('http://vimeo.com/', '')
99
+ value = jQuery('<iframe>', {
100
+ width: @element.find('#media_vimeo_width').val() || 400,
101
+ height: @element.find('#media_vimeo_height').val() || 225,
102
+ src: "http://player.vimeo.com/video/#{code}?title=1&byline=1&portrait=0&color=ffffff",
103
+ frameborder: 0
104
+ })
105
+ Mercury.trigger('action', {action: 'insertHTML', value: value})
106
+
107
+ @hide()
@@ -0,0 +1,12 @@
1
+ @Mercury.modalHandlers.insertSnippet = ->
2
+ @element.find('form').on 'submit', (event) =>
3
+ event.preventDefault()
4
+ serializedForm = @element.find('form').serializeObject()
5
+ if Mercury.snippet
6
+ snippet = Mercury.snippet
7
+ snippet.setOptions(serializedForm)
8
+ Mercury.snippet = null
9
+ else
10
+ snippet = Mercury.Snippet.create(@options.snippetName, serializedForm)
11
+ Mercury.trigger('action', {action: 'insertSnippet', value: snippet})
12
+ @hide()
@@ -0,0 +1,54 @@
1
+ @Mercury.modalHandlers.insertTable = ->
2
+ table = @element.find('#table_display table')
3
+
4
+ # make td's selectable
5
+ table.on 'click', (event) =>
6
+ cell = jQuery(event.target)
7
+ table = cell.closest('table')
8
+ table.find('.selected').removeAttr('class')
9
+ cell.addClass('selected')
10
+ Mercury.tableEditor(table, cell, '&nbsp;')
11
+
12
+ # select the first td
13
+ firstCell = table.find('td, th').first()
14
+ firstCell.addClass('selected')
15
+ Mercury.tableEditor(table, firstCell, '&nbsp;')
16
+
17
+ # make the buttons work
18
+ @element.find('input.action').on 'click', (event) =>
19
+ action = jQuery(event.target).attr('name')
20
+ switch action
21
+ when 'insertRowBefore' then Mercury.tableEditor.addRow('before')
22
+ when 'insertRowAfter' then Mercury.tableEditor.addRow('after')
23
+ when 'deleteRow' then Mercury.tableEditor.removeRow()
24
+ when 'insertColumnBefore' then Mercury.tableEditor.addColumn('before')
25
+ when 'insertColumnAfter' then Mercury.tableEditor.addColumn('after')
26
+ when 'deleteColumn' then Mercury.tableEditor.removeColumn()
27
+ when 'increaseColspan' then Mercury.tableEditor.increaseColspan()
28
+ when 'decreaseColspan' then Mercury.tableEditor.decreaseColspan()
29
+ when 'increaseRowspan' then Mercury.tableEditor.increaseRowspan()
30
+ when 'decreaseRowspan' then Mercury.tableEditor.decreaseRowspan()
31
+
32
+ # set the alignment
33
+ @element.find('#table_alignment').on 'change', =>
34
+ table.attr({align: @element.find('#table_alignment').val()})
35
+
36
+ # set the border
37
+ @element.find('#table_border').on 'keyup', =>
38
+ table.attr({border: parseInt(@element.find('#table_border').val())})
39
+
40
+ # set the cellspacing
41
+ @element.find('#table_spacing').on 'keyup', =>
42
+ table.attr({cellspacing: parseInt(@element.find('#table_spacing').val())})
43
+
44
+ # build the table on form submission
45
+ @element.find('form').on 'submit', (event) =>
46
+ event.preventDefault()
47
+ table.find('.selected').removeAttr('class')
48
+ table.find('td, th').html('<br/>')
49
+
50
+ html = jQuery('<div>').html(table).html()
51
+ value = html.replace(/^\s+|\n/gm, '').replace(/(<\/.*?>|<table.*?>|<tbody>|<tr>)/g, '$1\n')
52
+
53
+ Mercury.trigger('action', {action: 'insertTable', value: value})
54
+ @hide()
@@ -0,0 +1,55 @@
1
+ String::titleize = ->
2
+ @[0].toUpperCase() + @slice(1)
3
+
4
+
5
+ String::toHex = ->
6
+ return @ if @[0] == '#'
7
+ @replace /rgb(a)?\(([0-9|%]+)[\s|,]?\s?([0-9|%]+)[\s|,]?\s?([0-9|%]+)[\s|,]?\s?([0-9|.|%]+\s?)?\)/gi, (x, alpha, r, g, b, a) ->
8
+ "##{parseInt(r).toHex()}#{parseInt(g).toHex()}#{parseInt(b).toHex()}"
9
+
10
+
11
+ String::regExpEscape = ->
12
+ specials = ['/','.','*','+','?','|','(',')','[',']','{','}','\\']
13
+ escaped = new RegExp('(\\' + specials.join('|\\') + ')', 'g')
14
+ return @replace(escaped, '\\$1')
15
+
16
+
17
+ String::printf = ->
18
+ chunks = @split('%')
19
+ result = chunks[0]
20
+ re = /^([sdf])([\s\S%]*)$/
21
+ offset = 0
22
+ for chunk, index in chunks
23
+ p = re.exec(chunk)
24
+ if index == 0 || !p || arguments[index] == null
25
+ if index > 1
26
+ offset += 2
27
+ result += "%#{chunk}"
28
+ continue
29
+ arg = arguments[(index - 1) - offset]
30
+ switch p[1]
31
+ when 's' then result += arg
32
+ when 'd', 'i' then result += parseInt(arg.toString(), 10)
33
+ when 'f' then result += parseFloat(arg)
34
+ result += p[2]
35
+ return result
36
+
37
+
38
+ Number::toHex = ->
39
+ result = @toString(16).toUpperCase()
40
+ return if result[1] then result else "0#{result}"
41
+
42
+
43
+ Number::toBytes = ->
44
+ bytes = parseInt(@)
45
+ i = 0
46
+ while 1023 < bytes
47
+ bytes /= 1024
48
+ i += 1
49
+ return if i then "#{bytes.toFixed(2)}#{['', ' kb', ' Mb', ' Gb', ' Tb', ' Pb', ' Eb'][i]}" else "#{bytes} bytes"
50
+
51
+
52
+ # make setTimeout not suck for coffeescript
53
+ window.originalSetTimeout = window.setTimeout
54
+ window.setTimeout = (arg1, arg2) ->
55
+ if typeof(arg1) == 'number' then window.originalSetTimeout(arg2, arg1) else window.originalSetTimeout(arg1, arg2)