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,514 @@
1
+ describe "Mercury.uploader", ->
2
+
3
+ template 'mercury/uploader.html'
4
+
5
+ beforeEach ->
6
+ Mercury.config.uploading.enabled = true
7
+ $.fx.off = true
8
+ @mockFile = {
9
+ size: 1024
10
+ fileName: 'image.png'
11
+ type: 'image/png'
12
+ }
13
+
14
+ afterEach ->
15
+ Mercury.uploader.initialized = false
16
+
17
+ describe "singleton method", ->
18
+
19
+ beforeEach ->
20
+ @showSpy = spyOn(Mercury.uploader, 'show').andCallFake(=>)
21
+
22
+ it "calls show", ->
23
+ Mercury.uploader(@mockFile)
24
+ expect(@showSpy.callCount).toEqual(1)
25
+
26
+ it "returns the function object", ->
27
+ ret = Mercury.uploader(@mockFile)
28
+ expect(ret).toEqual(Mercury.uploader)
29
+
30
+ it "doesn't call show if disabled in configuration", ->
31
+ Mercury.config.uploading.enabled = false
32
+ Mercury.uploader(@mockFile)
33
+ expect(@showSpy.callCount).toEqual(0)
34
+
35
+
36
+ describe "#show", ->
37
+
38
+ beforeEach ->
39
+ @initializeSpy = spyOn(Mercury.uploader, 'initialize').andCallFake(=>)
40
+ @appearSpy = spyOn(Mercury.uploader, 'appear').andCallFake(=>)
41
+
42
+ it "expects a file object", ->
43
+ Mercury.uploader.show(@mockFile)
44
+ expect(Mercury.uploader.file.name).toEqual(@mockFile.fileName)
45
+
46
+ it "accepts options", ->
47
+ Mercury.uploader.show(@mockFile, {foo: 'bar'})
48
+ expect(Mercury.uploader.options).toEqual({foo: 'bar'})
49
+
50
+ it "creates a file instance from the file", ->
51
+ Mercury.uploader.show(@mockFile)
52
+ expect(Mercury.uploader.file.name).toEqual(@mockFile.fileName)
53
+ expect(Mercury.uploader.file.fullSize).toEqual(1024)
54
+
55
+ it "alerts and stops if the file has errors (too large or unsupported mimetype)", ->
56
+ @mockFile.size = 123123123123
57
+ spy = spyOn(window, 'alert').andCallFake(=>)
58
+ Mercury.uploader.show(@mockFile)
59
+ expect(spy.callCount).toEqual(1)
60
+ expect(spy.argsForCall[0]).toEqual(['Error: Too large'])
61
+
62
+ it "doesn't do anything unless xhr uploading is supported in the browser", ->
63
+ spyOn(Mercury.uploader, 'supported').andCallFake(=> false)
64
+ Mercury.uploader.show(@mockFile)
65
+ expect(@initializeSpy.callCount).toEqual(0)
66
+
67
+ it "triggers an event to focus the window", ->
68
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
69
+ Mercury.uploader.show(@mockFile)
70
+ expect(spy.callCount).toEqual(1)
71
+ expect(spy.argsForCall[0]).toEqual(['focus:window'])
72
+
73
+ it "calls initialize", ->
74
+ Mercury.uploader.show(@mockFile)
75
+ expect(@initializeSpy.callCount).toEqual(1)
76
+
77
+ it "calls appear", ->
78
+ Mercury.uploader.show(@mockFile)
79
+ expect(@appearSpy.callCount).toEqual(1)
80
+
81
+
82
+ describe "#initialize", ->
83
+
84
+ beforeEach ->
85
+ @buildSpy = spyOn(Mercury.uploader, 'build').andCallFake(=>)
86
+ @bindEventsSpy = spyOn(Mercury.uploader, 'bindEvents').andCallFake(=>)
87
+
88
+ it "calls build", ->
89
+ Mercury.uploader.initialize()
90
+ expect(@buildSpy.callCount).toEqual(1)
91
+
92
+ it "calls bindEvents", ->
93
+ Mercury.uploader.initialize()
94
+ expect(@bindEventsSpy.callCount).toEqual(1)
95
+
96
+ it "only initializes once", ->
97
+ Mercury.uploader.initialize()
98
+ expect(@buildSpy.callCount).toEqual(1)
99
+ Mercury.uploader.initialize()
100
+ expect(@buildSpy.callCount).toEqual(1)
101
+
102
+
103
+ describe "#supported", ->
104
+
105
+ it "prototypes sendAsBinary onto XMLHttpRequest if it's not already there", ->
106
+ XMLHttpRequest.prototype.sendAsBinary = null
107
+ Mercury.uploader.supported()
108
+ expect(XMLHttpRequest.prototype.sendAsBinary).toBeDefined()
109
+
110
+ it "returns true if everything needed is supported", ->
111
+ ret = Mercury.uploader.supported()
112
+ expect(ret).toEqual(true)
113
+
114
+ it "returns false if everything isn't supported", ->
115
+ window.Uint8Array = null
116
+ ret = Mercury.uploader.supported()
117
+ expect(ret).toEqual(true)
118
+
119
+
120
+ describe "#build", ->
121
+
122
+ beforeEach ->
123
+ Mercury.uploader.options = {appendTo: '#test'}
124
+
125
+ it "builds an element structure", ->
126
+ Mercury.uploader.build()
127
+ html = $('<div>').html(Mercury.uploader.element).html()
128
+ expect(html).toContain('class="mercury-uploader"')
129
+ expect(html).toContain('class="mercury-uploader-preview"')
130
+ expect(html).toContain('<b><img></b>')
131
+ expect(html).toContain('class="mercury-uploader-details"')
132
+ expect(html).toContain('<span>Processing...</span>')
133
+ expect(html).toContain('class="mercury-uploader-indicator"')
134
+ expect(html).toContain('<div><b>0%</b></div>')
135
+
136
+ it "builds an overlay", ->
137
+ Mercury.uploader.build()
138
+ html = $('<div>').html(Mercury.uploader.overlay).html()
139
+ expect(html).toContain('class="mercury-uploader-overlay"')
140
+
141
+ it "appends to any element", ->
142
+ Mercury.uploader.options = {appendTo: '#uploader_container'}
143
+ Mercury.uploader.build()
144
+ expect($('#uploader_container .mercury-uploader').length).toEqual(1)
145
+
146
+
147
+ describe "observed events", ->
148
+
149
+ describe "custom event: resize", ->
150
+
151
+ it "calls position", ->
152
+ spy = spyOn(Mercury.uploader, 'position').andCallFake(=>)
153
+ Mercury.uploader.bindEvents()
154
+ Mercury.trigger('resize')
155
+ expect(spy.callCount).toEqual(1)
156
+
157
+
158
+ describe "#appear", ->
159
+
160
+ beforeEach ->
161
+ Mercury.uploader.options = {appendTo: '#test'}
162
+ Mercury.uploader.build()
163
+ @fillDisplaySpy = spyOn(Mercury.uploader, 'fillDisplay').andCallFake(=>)
164
+ @positionSpy = spyOn(Mercury.uploader, 'position').andCallFake(=>)
165
+ @loadImageSpy = spyOn(Mercury.uploader, 'loadImage').andCallFake(=>)
166
+
167
+ it "calls fillDisplay", ->
168
+ Mercury.uploader.appear()
169
+ expect(@fillDisplaySpy.callCount).toEqual(1)
170
+
171
+ it "calls position", ->
172
+ Mercury.uploader.appear()
173
+ expect(@positionSpy.callCount).toEqual(1)
174
+
175
+ it "displays the overlay, and the element", ->
176
+ Mercury.uploader.appear()
177
+ expect($('#test .mercury-uploader').css('display')).toEqual('block')
178
+ expect($('#test .mercury-uploader-overlay').css('display')).toEqual('block')
179
+
180
+ it "sets visible to true", ->
181
+ Mercury.uploader.appear()
182
+ expect(Mercury.uploader.visible).toEqual(true)
183
+
184
+ it "calls loadImage", ->
185
+ Mercury.uploader.appear()
186
+ expect(@loadImageSpy.callCount).toEqual(1)
187
+
188
+
189
+ describe "#position", ->
190
+
191
+ beforeEach ->
192
+ Mercury.uploader.options = {appendTo: '#test'}
193
+ Mercury.uploader.build()
194
+ @fillDisplaySpy = spyOn(Mercury.uploader, 'fillDisplay').andCallFake(=>)
195
+ @positionSpy = spyOn(Mercury.uploader, 'position').andCallFake(=>)
196
+
197
+ it "centers the element in the viewport", ->
198
+ # todo: this isn't really being tested
199
+ Mercury.uploader.element.css({display: 'block'})
200
+ Mercury.uploader.position()
201
+ @expect($('#test .mercury-uploader').offset()).toEqual({top: 0, left: 0})
202
+
203
+
204
+ describe "#fillDisplay", ->
205
+
206
+ beforeEach ->
207
+ Mercury.uploader.options = {appendTo: '#test'}
208
+ Mercury.uploader.file = {name: 'image.png', size: 1024, type: 'image/png'}
209
+ Mercury.uploader.build()
210
+
211
+ it "puts the file details into the element", ->
212
+ Mercury.uploader.fillDisplay()
213
+ expect($('#test .mercury-uploader-details').html()).toEqual('Name: image.png<br>Size: undefined<br>Type: image/png')
214
+
215
+
216
+ describe "#loadImage", ->
217
+
218
+ beforeEach ->
219
+ Mercury.uploader.options = {appendTo: '#test'}
220
+ Mercury.uploader.file = new Mercury.uploader.File(@mockFile)
221
+ Mercury.uploader.build()
222
+ spyOn(FileReader.prototype, 'readAsBinaryString').andCallFake(=>)
223
+ @readAsDataURLSpy = spyOn(Mercury.uploader.File.prototype, 'readAsDataURL').andCallFake((callback) => callback('data-url'))
224
+
225
+ it "calls file.readAsDataURL", ->
226
+ Mercury.uploader.loadImage()
227
+ expect(@readAsDataURLSpy.callCount).toEqual(1)
228
+
229
+ it "sets the preview image src to the file contents", ->
230
+ Mercury.uploader.loadImage()
231
+ expect($('#test .mercury-uploader-preview img').attr('src')).toEqual('data-url')
232
+
233
+ it "calls upload", ->
234
+ spy = spyOn(Mercury.uploader, 'upload').andCallFake(=>)
235
+ Mercury.uploader.loadImage()
236
+ expect(spy.callCount).toEqual(1)
237
+
238
+
239
+ describe "#upload", ->
240
+
241
+ # todo: test this
242
+ it "should build a multipart form and submit it", ->
243
+
244
+
245
+ describe "#updateStatus", ->
246
+
247
+ beforeEach ->
248
+ Mercury.uploader.options = {appendTo: '#test'}
249
+ Mercury.uploader.build()
250
+
251
+ it "updated the message in the progress display", ->
252
+ Mercury.uploader.updateStatus('status message')
253
+ expect($('#test .mercury-uploader-progress span').html()).toEqual('status message')
254
+
255
+ it "updates the progress indicator width", ->
256
+ Mercury.uploader.updateStatus('message', 512)
257
+ expect($('#test .mercury-uploader-indicator div').css('width')).toEqual('50px')
258
+
259
+ it "updates the progress indicator value", ->
260
+ Mercury.uploader.updateStatus('message', 512)
261
+ expect($('#test .mercury-uploader-indicator b').html()).toEqual('50%')
262
+
263
+
264
+ describe "#hide", ->
265
+
266
+ beforeEach ->
267
+ @setTimeoutSpy = spyOn(window, 'setTimeout')
268
+ Mercury.uploader.options = {appendTo: '#test'}
269
+ Mercury.uploader.build()
270
+
271
+ it "accepts a delay", ->
272
+ @setTimeoutSpy.andCallFake(=>)
273
+ Mercury.uploader.hide(1)
274
+ expect(@setTimeoutSpy.callCount).toEqual(1)
275
+ expect(@setTimeoutSpy.argsForCall[0][0]).toEqual(1000)
276
+
277
+ it "hides the overlay and element", ->
278
+ @setTimeoutSpy.andCallFake((timeout, callback) => callback())
279
+ Mercury.uploader.hide()
280
+ expect($('#test .mercury-uploader').css('opacity')).toEqual('0')
281
+ expect($('#test .mercury-uploader-overlay').css('opacity')).toEqual('0')
282
+
283
+ it "calls reset", ->
284
+ @setTimeoutSpy.andCallFake((timeout, callback) => callback())
285
+ spy = spyOn(Mercury.uploader, 'reset').andCallFake(=>)
286
+ Mercury.uploader.hide()
287
+ expect(spy.callCount).toEqual(1)
288
+
289
+ it "sets visible to false", ->
290
+ @setTimeoutSpy.andCallFake((timeout, callback) => callback())
291
+ Mercury.uploader.hide()
292
+ expect(Mercury.uploader.visible).toEqual(false)
293
+
294
+ it "focuses the frame", ->
295
+ @setTimeoutSpy.andCallFake((timeout, callback) => callback())
296
+ spy = spyOn(Mercury, 'trigger').andCallFake(=>)
297
+ Mercury.uploader.hide()
298
+ expect(spy.callCount).toEqual(1)
299
+ expect(spy.argsForCall[0]).toEqual(['focus:frame'])
300
+
301
+
302
+ describe "#reset", ->
303
+
304
+ beforeEach ->
305
+ Mercury.uploader.options = {appendTo: '#test'}
306
+ Mercury.uploader.build()
307
+
308
+ it "removes the preview image", ->
309
+ $('#test .mercury-uploader-indicator div').html('foo')
310
+ Mercury.uploader.reset()
311
+ expect($('#test .mercury-uploader-preview b').html()).toEqual('')
312
+
313
+ it "resets the progress back to 0", ->
314
+ $('#test .mercury-uploader-indicator div').css({width: '50%'})
315
+ $('#test .mercury-uploader-indicator b').html('50%')
316
+ Mercury.uploader.reset()
317
+ expect($('#test .mercury-uploader-indicator div').css('width')).toEqual('0px')
318
+ expect($('#test .mercury-uploader-indicator b').html()).toEqual('0%')
319
+
320
+ it "sets the status back to 'Processing...' for next time", ->
321
+ spy = spyOn(Mercury.uploader, 'updateStatus').andCallFake(=>)
322
+ Mercury.uploader.reset()
323
+ expect(spy.callCount).toEqual(1)
324
+
325
+
326
+ describe "uploaderEvents", ->
327
+
328
+ beforeEach ->
329
+ Mercury.uploader.file = @mockFile
330
+ @updateStatusSpy = spyOn(Mercury.uploader, 'updateStatus').andCallFake(=>)
331
+ @hideSpy = spyOn(Mercury.uploader, 'hide').andCallFake(=>)
332
+ @events = Mercury.uploader.uploaderEvents
333
+
334
+ describe ".onloadstart", ->
335
+
336
+ it "updates the status to 'Uploading...'", ->
337
+ @events.onloadstart.call(Mercury.uploader)
338
+ expect(@updateStatusSpy.callCount).toEqual(1)
339
+ expect(@updateStatusSpy.argsForCall[0]).toEqual(['Uploading...'])
340
+
341
+ describe ".onprogress", ->
342
+
343
+ it "updates the status to 'Uploading...' and passes the amount sent so far", ->
344
+ @events.onprogress.call(Mercury.uploader, {loaded: 512})
345
+ expect(@updateStatusSpy.callCount).toEqual(1)
346
+ expect(@updateStatusSpy.argsForCall[0]).toEqual(['Uploading...', 512])
347
+
348
+ describe ".onabort", ->
349
+
350
+ it "updates the status to 'Aborted'", ->
351
+ @events.onabort.call(Mercury.uploader)
352
+ expect(@updateStatusSpy.callCount).toEqual(1)
353
+ expect(@updateStatusSpy.argsForCall[0]).toEqual(['Aborted'])
354
+
355
+ it "calls hide", ->
356
+ @events.onabort.call(Mercury.uploader)
357
+ expect(@hideSpy.callCount).toEqual(1)
358
+
359
+ describe ".onload", ->
360
+
361
+ it "updates the status to 'Successfully uploaded' and passes the total file size", ->
362
+ @events.onload.call(Mercury.uploader)
363
+ expect(@updateStatusSpy.callCount).toEqual(1)
364
+ expect(@updateStatusSpy.argsForCall[0]).toEqual(['Successfully uploaded...', 1024])
365
+
366
+ describe ".onerror", ->
367
+
368
+ it "updates the status to 'Error: Unable to upload the file'", ->
369
+ @events.onerror.call(Mercury.uploader)
370
+ expect(@updateStatusSpy.callCount).toEqual(1)
371
+ expect(@updateStatusSpy.argsForCall[0]).toEqual(['Error: Unable to upload the file'])
372
+
373
+ it "calls hide", ->
374
+ @events.onerror.call(Mercury.uploader)
375
+ expect(@hideSpy.callCount).toEqual(1)
376
+ expect(@hideSpy.argsForCall[0]).toEqual([3])
377
+
378
+
379
+
380
+ describe "Mercury.uploader.File", ->
381
+
382
+ beforeEach ->
383
+ @mockFile = {
384
+ size: 1024
385
+ fileName: 'image.png'
386
+ type: 'image/png'
387
+ }
388
+
389
+ afterEach ->
390
+ @file = null
391
+ delete(@file)
392
+
393
+ describe "constructor", ->
394
+
395
+ it "expects a file", ->
396
+ @file = new Mercury.uploader.File(@mockFile)
397
+ expect(@file.file).toEqual(@mockFile)
398
+
399
+ it "reads attributes of the file and sets variables", ->
400
+ @file = new Mercury.uploader.File(@mockFile)
401
+ expect(@file.size).toEqual(1024)
402
+ expect(@file.fullSize).toEqual(1024)
403
+ expect(@file.readableSize).toEqual('1.00 kb')
404
+ expect(@file.name).toEqual('image.png')
405
+ expect(@file.type).toEqual('image/png')
406
+
407
+ it "adds errors if there's any", ->
408
+ Mercury.config.uploading.maxFileSize = 100
409
+ Mercury.config.uploading.allowedMimeTypes = ['image/foo']
410
+ @file = new Mercury.uploader.File(@mockFile)
411
+ expect(@file.errors).toEqual('Too large / Unsupported format')
412
+
413
+
414
+ describe "#readAsDataURL", ->
415
+
416
+ it "it calls readAsDataURL on a FileReader object", ->
417
+ spy = spyOn(window.FileReader.prototype, 'readAsDataURL').andCallFake(=>)
418
+ @file = new Mercury.uploader.File(@mockFile)
419
+ @file.readAsDataURL()
420
+ expect(spy.callCount).toEqual(1)
421
+
422
+ it "calls a callback if one was provided", ->
423
+ spyOn(FileReader.prototype, 'readAsDataURL').andCallFake(=>)
424
+ FileReader.prototype.result = 'result'
425
+ callCount = 0
426
+ callback = (r) => callCount += 1
427
+
428
+ @file = new Mercury.uploader.File(@mockFile)
429
+ onload = @file.readAsDataURL(callback)
430
+ onload()
431
+ expect(callCount).toEqual(1)
432
+
433
+
434
+ describe "#readAsBinaryString", ->
435
+
436
+ it "it calls readAsBinaryString on a FileReader object", ->
437
+ spy = spyOn(window.FileReader.prototype, 'readAsBinaryString').andCallFake(=>)
438
+ @file = new Mercury.uploader.File(@mockFile)
439
+ @file.readAsBinaryString()
440
+ expect(spy.callCount).toEqual(1)
441
+
442
+ it "calls a callback if one was provided", ->
443
+ spyOn(FileReader.prototype, 'readAsBinaryString').andCallFake(=>)
444
+ FileReader.prototype.result = 'result'
445
+ callCount = 0
446
+ callback = (r) => callCount += 1
447
+
448
+ @file = new Mercury.uploader.File(@mockFile)
449
+ onload = @file.readAsBinaryString(callback)
450
+ onload()
451
+ expect(callCount).toEqual(1)
452
+
453
+
454
+ describe "#updateSize", ->
455
+
456
+ it "updates the size based on a delta", ->
457
+ @file = new Mercury.uploader.File(@mockFile)
458
+ @file.updateSize(20)
459
+ expect(@file.fullSize).toEqual(1044)
460
+
461
+
462
+
463
+ describe "Mercury.uploader.MultiPartPost", ->
464
+
465
+ beforeEach ->
466
+ @mockFile = {
467
+ size: 1024
468
+ name: 'image.png'
469
+ type: 'image/png'
470
+ }
471
+
472
+ afterEach ->
473
+ @multiPartPost = null
474
+ delete(@multiPartPost)
475
+
476
+ describe "constructor", ->
477
+
478
+ it "expects an inputName, file, and file contents", ->
479
+ @multiPartPost = new Mercury.uploader.MultiPartPost('foo[bar]', @mockFile, 'file contents')
480
+ expect(@multiPartPost.inputName).toEqual('foo[bar]')
481
+ expect(@multiPartPost.file).toEqual(@mockFile)
482
+ expect(@multiPartPost.contents).toEqual('file contents')
483
+
484
+ it "accepts a formInputs object", ->
485
+ @multiPartPost = new Mercury.uploader.MultiPartPost('foo[bar]', @mockFile, 'file contents', {foo: 'bar'})
486
+ expect(@multiPartPost.formInputs).toEqual({foo: 'bar'})
487
+
488
+ it "defines a boundary string", ->
489
+ @multiPartPost = new Mercury.uploader.MultiPartPost('foo[bar]', @mockFile, 'file contents')
490
+ expect(@multiPartPost.boundary).toEqual('Boundaryx20072377098235644401115438165x')
491
+
492
+ it "calls buildBody", ->
493
+ spy = spyOn(Mercury.uploader.MultiPartPost.prototype, 'buildBody').andCallFake(=>)
494
+ @multiPartPost = new Mercury.uploader.MultiPartPost('foo[bar]', @mockFile, 'file contents')
495
+ expect(spy.callCount).toEqual(1)
496
+
497
+ it "sets a delta based on the body size and file size", ->
498
+ @multiPartPost = new Mercury.uploader.MultiPartPost('foo[bar]', @mockFile, 'file contents')
499
+ expect(@multiPartPost.delta).toEqual(-790)
500
+
501
+
502
+ describe "#buildBody", ->
503
+
504
+ it "creates a multipart post body with the file information", ->
505
+ @multiPartPost = new Mercury.uploader.MultiPartPost('foo[bar]', @mockFile, 'file contents')
506
+ expect(@multiPartPost.body).toContain('--Boundaryx20072377098235644401115438165x')
507
+ expect(@multiPartPost.body).toContain('Content-Disposition: form-data; name="foo[bar]"; filename="image.png"')
508
+ expect(@multiPartPost.body).toContain('Content-Type: image/png')
509
+ expect(@multiPartPost.body).toContain('Content-Transfer-Encoding: binary')
510
+ expect(@multiPartPost.body).toContain('file contents')
511
+
512
+ it "includes form inputs if passed in", ->
513
+ @multiPartPost = new Mercury.uploader.MultiPartPost('foo[bar]', @mockFile, 'file contents', {foo: 'bar'})
514
+ expect(@multiPartPost.body).toContain('Content-Disposition: form-data; name="foo"\r\n\r\nbar')