mercury-rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +152 -0
- data/VERSION +1 -0
- data/app/assets/images/mercury/button.png +0 -0
- data/app/assets/images/mercury/clippy.png +0 -0
- data/app/assets/images/mercury/default-snippet.png +0 -0
- data/app/assets/images/mercury/loading-dark.gif +0 -0
- data/app/assets/images/mercury/loading-light.gif +0 -0
- data/app/assets/images/mercury/search-icon.png +0 -0
- data/app/assets/images/mercury/toolbar/editable/buttons.png +0 -0
- data/app/assets/images/mercury/toolbar/markupable/buttons.png +0 -0
- data/app/assets/images/mercury/toolbar/primary/_expander.png +0 -0
- data/app/assets/images/mercury/toolbar/primary/_pressed.png +0 -0
- data/app/assets/images/mercury/toolbar/primary/historypanel.png +0 -0
- data/app/assets/images/mercury/toolbar/primary/insertcharacter.png +0 -0
- data/app/assets/images/mercury/toolbar/primary/insertlink.png +0 -0
- data/app/assets/images/mercury/toolbar/primary/insertmedia.png +0 -0
- data/app/assets/images/mercury/toolbar/primary/inserttable.png +0 -0
- data/app/assets/images/mercury/toolbar/primary/inspectorpanel.png +0 -0
- data/app/assets/images/mercury/toolbar/primary/notespanel.png +0 -0
- data/app/assets/images/mercury/toolbar/primary/objectspanel.png +0 -0
- data/app/assets/images/mercury/toolbar/primary/preview.png +0 -0
- data/app/assets/images/mercury/toolbar/primary/redo.png +0 -0
- data/app/assets/images/mercury/toolbar/primary/save.png +0 -0
- data/app/assets/images/mercury/toolbar/primary/todospanel.png +0 -0
- data/app/assets/images/mercury/toolbar/primary/undo.png +0 -0
- data/app/assets/images/mercury/toolbar/snippetable/buttons.png +0 -0
- data/app/assets/javascripts/mercury.js +30 -0
- data/app/assets/javascripts/mercury/dialog.js.coffee +75 -0
- data/app/assets/javascripts/mercury/dialogs/backcolor.js.coffee +6 -0
- data/app/assets/javascripts/mercury/dialogs/forecolor.js.coffee +6 -0
- data/app/assets/javascripts/mercury/dialogs/formatblock.js.coffee +4 -0
- data/app/assets/javascripts/mercury/dialogs/objectspanel.js.coffee +10 -0
- data/app/assets/javascripts/mercury/dialogs/style.js.coffee +4 -0
- data/app/assets/javascripts/mercury/history_buffer.js.coffee +30 -0
- data/app/assets/javascripts/mercury/mercury.js.coffee +293 -0
- data/app/assets/javascripts/mercury/modal.js.coffee +177 -0
- data/app/assets/javascripts/mercury/modals/htmleditor.js.coffee +10 -0
- data/app/assets/javascripts/mercury/modals/insertcharacter.js.coffee +4 -0
- data/app/assets/javascripts/mercury/modals/insertlink.js.coffee +92 -0
- data/app/assets/javascripts/mercury/modals/insertmedia.js.coffee +72 -0
- data/app/assets/javascripts/mercury/modals/insertsnippet.js.coffee +11 -0
- data/app/assets/javascripts/mercury/modals/inserttable.js.coffee +56 -0
- data/app/assets/javascripts/mercury/native_extensions.js.coffee +47 -0
- data/app/assets/javascripts/mercury/page_editor.js.coffee +139 -0
- data/app/assets/javascripts/mercury/palette.js.coffee +29 -0
- data/app/assets/javascripts/mercury/panel.js.coffee +97 -0
- data/app/assets/javascripts/mercury/region.js.coffee +103 -0
- data/app/assets/javascripts/mercury/regions/editable.js.coffee +546 -0
- data/app/assets/javascripts/mercury/regions/markupable.js.coffee +380 -0
- data/app/assets/javascripts/mercury/regions/snippetable.js.coffee +127 -0
- data/app/assets/javascripts/mercury/select.js.coffee +40 -0
- data/app/assets/javascripts/mercury/snippet.js.coffee +92 -0
- data/app/assets/javascripts/mercury/snippet_toolbar.js.coffee +69 -0
- data/app/assets/javascripts/mercury/statusbar.js.coffee +25 -0
- data/app/assets/javascripts/mercury/table_editor.js.coffee +266 -0
- data/app/assets/javascripts/mercury/toolbar.button.js.coffee +152 -0
- data/app/assets/javascripts/mercury/toolbar.button_group.js.coffee +42 -0
- data/app/assets/javascripts/mercury/toolbar.expander.js.coffee +56 -0
- data/app/assets/javascripts/mercury/toolbar.js.coffee +72 -0
- data/app/assets/javascripts/mercury/tooltip.js.coffee +67 -0
- data/app/assets/javascripts/mercury/uploader.js.coffee +213 -0
- data/app/assets/javascripts/mercury/websocket.js.coffee +34 -0
- data/app/assets/stylesheets/mercury.css +31 -0
- data/app/assets/stylesheets/mercury/dialog.scss +178 -0
- data/app/assets/stylesheets/mercury/mercury.scss +119 -0
- data/app/assets/stylesheets/mercury/modal.scss +192 -0
- data/app/assets/stylesheets/mercury/statusbar.scss +23 -0
- data/app/assets/stylesheets/mercury/toolbar.scss +417 -0
- data/app/assets/stylesheets/mercury/tooltip.scss +26 -0
- data/app/assets/stylesheets/mercury/uploader.scss +109 -0
- data/app/controllers/images_controller.rb +19 -0
- data/app/controllers/mercury_controller.rb +20 -0
- data/app/models/image.rb +14 -0
- data/app/views/layouts/mercury.html.haml +12 -0
- data/app/views/mercury/modals/character.html.haml +252 -0
- data/app/views/mercury/modals/htmleditor.html.haml +8 -0
- data/app/views/mercury/modals/link.html.haml +31 -0
- data/app/views/mercury/modals/media.html.haml +33 -0
- data/app/views/mercury/modals/sanitizer.html.haml +4 -0
- data/app/views/mercury/modals/table.html.haml +49 -0
- data/app/views/mercury/palettes/backcolor.html.haml +79 -0
- data/app/views/mercury/palettes/forecolor.html.haml +79 -0
- data/app/views/mercury/panels/history.html.haml +0 -0
- data/app/views/mercury/panels/notes.html.haml +0 -0
- data/app/views/mercury/panels/snippets.html.haml +10 -0
- data/app/views/mercury/selects/formatblock.html.haml +10 -0
- data/app/views/mercury/selects/style.html.haml +4 -0
- data/app/views/mercury/snippets/example.html.haml +2 -0
- data/app/views/mercury/snippets/example_options.html.haml +16 -0
- data/config/engine.rb +6 -0
- data/config/routes.rb +15 -0
- data/db/migrate/20110526035601_create_images.rb +11 -0
- data/features/editing/basic.feature +11 -0
- data/features/step_definitions/debug_steps.rb +14 -0
- data/features/step_definitions/web_steps.rb +211 -0
- data/features/support/env.rb +46 -0
- data/features/support/paths.rb +35 -0
- data/features/support/selectors.rb +42 -0
- data/lib/mercury-rails.rb +4 -0
- data/log/.gitkeep +0 -0
- data/mercury-rails.gemspec +230 -0
- data/spec/javascripts/mercury/dialog_spec.js.coffee +258 -0
- data/spec/javascripts/mercury/history_buffer_spec.js.coffee +79 -0
- data/spec/javascripts/mercury/mercury_spec.js.coffee +52 -0
- data/spec/javascripts/mercury/native_extensions_spec.js.coffee +66 -0
- data/spec/javascripts/mercury/page_editor_spec.js.coffee +435 -0
- data/spec/javascripts/mercury/palette_spec.js.coffee +51 -0
- data/spec/javascripts/mercury/panel_spec.js.coffee +147 -0
- data/spec/javascripts/mercury/region_spec.js.coffee +261 -0
- data/spec/javascripts/mercury/regions/_editable_.js.coffee +0 -0
- data/spec/javascripts/mercury/regions/_markupable_.js.coffee +0 -0
- data/spec/javascripts/mercury/regions/snippetable_spec.js.coffee +368 -0
- data/spec/javascripts/mercury/select_spec.js.coffee +51 -0
- data/spec/javascripts/mercury/snippet_spec.js.coffee +246 -0
- data/spec/javascripts/mercury/snippet_toolbar_spec.js.coffee +186 -0
- data/spec/javascripts/mercury/statusbar_spec.js.coffee +78 -0
- data/spec/javascripts/mercury/table_editor_spec.js.coffee +192 -0
- data/spec/javascripts/mercury/toolbar.button_group_spec.js.coffee +92 -0
- data/spec/javascripts/mercury/toolbar.button_spec.js.coffee +341 -0
- data/spec/javascripts/mercury/toolbar.expander_spec.js.coffee +120 -0
- data/spec/javascripts/mercury/toolbar_spec.js.coffee +152 -0
- data/spec/javascripts/mercury/tooltip_spec.js.coffee +188 -0
- data/spec/javascripts/mercury/uploader_spec.js.coffee +512 -0
- data/spec/javascripts/responses/blank.html +1 -0
- data/spec/javascripts/spec_helper.js +513 -0
- data/spec/javascripts/templates/mercury/dialog.html +2 -0
- data/spec/javascripts/templates/mercury/page_editor.html +24 -0
- data/spec/javascripts/templates/mercury/palette.html +16 -0
- data/spec/javascripts/templates/mercury/panel.html +16 -0
- data/spec/javascripts/templates/mercury/region.html +2 -0
- data/spec/javascripts/templates/mercury/regions/snippetable.html +4 -0
- data/spec/javascripts/templates/mercury/select.html +16 -0
- data/spec/javascripts/templates/mercury/snippet.html +1 -0
- data/spec/javascripts/templates/mercury/snippet_toolbar.html +16 -0
- data/spec/javascripts/templates/mercury/statusbar.html +7 -0
- data/spec/javascripts/templates/mercury/table_editor.html +65 -0
- data/spec/javascripts/templates/mercury/toolbar.button.html +64 -0
- data/spec/javascripts/templates/mercury/toolbar.button_group.html +9 -0
- data/spec/javascripts/templates/mercury/toolbar.expander.html +18 -0
- data/spec/javascripts/templates/mercury/toolbar.html +10 -0
- data/spec/javascripts/templates/mercury/tooltip.html +12 -0
- data/spec/javascripts/templates/mercury/uploader.html +11 -0
- data/vendor/assets/javascripts/jquery-1.6.js +8865 -0
- data/vendor/assets/javascripts/jquery-ui-1.8.13.custom.min.js +249 -0
- data/vendor/assets/javascripts/jquery-ui-1.8.13.sortable.custom.js +1078 -0
- data/vendor/assets/javascripts/jquery.easing.js +173 -0
- data/vendor/assets/javascripts/jquery.json2.js +178 -0
- data/vendor/assets/javascripts/jquery.serialize_object.js +16 -0
- data/vendor/assets/javascripts/jquery.ujs.js +289 -0
- data/vendor/assets/javascripts/liquidmetal.js +88 -0
- data/vendor/assets/javascripts/showdown.js +1362 -0
- metadata +364 -0
@@ -0,0 +1,186 @@
|
|
1
|
+
require '/assets/mercury/mercury.js'
|
2
|
+
|
3
|
+
describe "Mercury.SnippetToolbar", ->
|
4
|
+
|
5
|
+
template 'mercury/snippet_toolbar.html'
|
6
|
+
|
7
|
+
beforeEach ->
|
8
|
+
$.fx.off = true
|
9
|
+
|
10
|
+
afterEach ->
|
11
|
+
@snippetToolbar = null
|
12
|
+
delete(@snippetToolbar)
|
13
|
+
$(document).unbind('mercury:hide:toolbar')
|
14
|
+
$(document).unbind('mercury:show:toolbar')
|
15
|
+
|
16
|
+
describe "constructor", ->
|
17
|
+
|
18
|
+
beforeEach ->
|
19
|
+
spyOn(Mercury.SnippetToolbar.prototype, 'build').andCallFake(=>)
|
20
|
+
spyOn(Mercury.SnippetToolbar.prototype, 'bindEvents').andCallFake(=>)
|
21
|
+
|
22
|
+
it "expects document", ->
|
23
|
+
@snippetToolbar = new Mercury.SnippetToolbar($('document'))
|
24
|
+
expect(@snippetToolbar.document).toEqual($('document'))
|
25
|
+
|
26
|
+
it "accepts options", ->
|
27
|
+
@snippetToolbar = new Mercury.SnippetToolbar($('document'))
|
28
|
+
expect(@snippetToolbar.document).toEqual($('document'))
|
29
|
+
|
30
|
+
|
31
|
+
describe "#build", ->
|
32
|
+
|
33
|
+
it "builds an element", ->
|
34
|
+
@snippetToolbar = new Mercury.SnippetToolbar($('document'), {appendTo: '#test'})
|
35
|
+
html = $('<div>').html(@snippetToolbar.element).html()
|
36
|
+
expect(html).toContain('class="mercury-toolbar mercury-snippet-toolbar"')
|
37
|
+
expect(html).toContain('style="display:none"')
|
38
|
+
|
39
|
+
it "appends to any element", ->
|
40
|
+
@snippetToolbar = new Mercury.SnippetToolbar($('document'), {appendTo: '#snippet_toolbar_container'})
|
41
|
+
expect($('#snippet_toolbar_container .mercury-toolbar').length).toEqual(1)
|
42
|
+
|
43
|
+
|
44
|
+
describe "observed events", ->
|
45
|
+
|
46
|
+
beforeEach ->
|
47
|
+
@snippetToolbar = new Mercury.SnippetToolbar($('document'), {appendTo: '#test'})
|
48
|
+
|
49
|
+
describe "custom event: show:toolbar", ->
|
50
|
+
|
51
|
+
it "does nothing if there's no snippet", ->
|
52
|
+
spy = spyOn(Mercury.SnippetToolbar.prototype, 'show').andCallFake(=>)
|
53
|
+
Mercury.trigger('show:toolbar', {snippet: null})
|
54
|
+
expect(spy.callCount).toEqual(0)
|
55
|
+
|
56
|
+
it "calls show", ->
|
57
|
+
spy = spyOn(Mercury.SnippetToolbar.prototype, 'show').andCallFake(=>)
|
58
|
+
Mercury.trigger('show:toolbar', {snippet: $('#snippet')})
|
59
|
+
expect(spy.callCount).toEqual(1)
|
60
|
+
|
61
|
+
describe "custom event: hide:toolbar", ->
|
62
|
+
|
63
|
+
it "does nothing if it's not for the snippet toolbar", ->
|
64
|
+
spy = spyOn(Mercury.SnippetToolbar.prototype, 'hide').andCallFake(=>)
|
65
|
+
Mercury.trigger('hide:toolbar', {type: 'foo'})
|
66
|
+
expect(spy.callCount).toEqual(0)
|
67
|
+
|
68
|
+
it "calls hide", ->
|
69
|
+
spy = spyOn(Mercury.SnippetToolbar.prototype, 'hide').andCallFake(=>)
|
70
|
+
Mercury.trigger('hide:toolbar', {type: 'snippet'})
|
71
|
+
expect(spy.callCount).toEqual(1)
|
72
|
+
|
73
|
+
describe "mousemove", ->
|
74
|
+
|
75
|
+
it "clears the hide timeout", ->
|
76
|
+
spy = spyOn(window, 'clearTimeout').andCallFake(=>)
|
77
|
+
jasmine.simulate.mousemove($('#test .mercury-snippet-toolbar').get(0))
|
78
|
+
expect(spy.callCount).toEqual(1)
|
79
|
+
|
80
|
+
describe "mouseout", ->
|
81
|
+
|
82
|
+
it "calls hide", ->
|
83
|
+
spy = spyOn(Mercury.SnippetToolbar.prototype, 'hide').andCallFake(=>)
|
84
|
+
jasmine.simulate.mouseout($('#test .mercury-snippet-toolbar').get(0))
|
85
|
+
expect(spy.callCount).toEqual(1)
|
86
|
+
|
87
|
+
|
88
|
+
describe "#show", ->
|
89
|
+
|
90
|
+
beforeEach ->
|
91
|
+
@snippetToolbar = new Mercury.SnippetToolbar($('document'), {appendTo: '#test'})
|
92
|
+
@positionSpy = spyOn(Mercury.SnippetToolbar.prototype, 'position').andCallFake(=>)
|
93
|
+
@appearSpy = spyOn(Mercury.SnippetToolbar.prototype, 'appear').andCallFake(=>)
|
94
|
+
|
95
|
+
it "expects a snippet", ->
|
96
|
+
@snippetToolbar.show({snippet: 'foo'})
|
97
|
+
expect(@snippetToolbar.snippet).toEqual({snippet: 'foo'})
|
98
|
+
|
99
|
+
it "calls position", ->
|
100
|
+
@snippetToolbar.show()
|
101
|
+
expect(@positionSpy.callCount).toEqual(1)
|
102
|
+
|
103
|
+
it "calls appear", ->
|
104
|
+
@snippetToolbar.show()
|
105
|
+
expect(@appearSpy.callCount).toEqual(1)
|
106
|
+
|
107
|
+
|
108
|
+
describe "#position", ->
|
109
|
+
|
110
|
+
beforeEach ->
|
111
|
+
Mercury.displayRect = {top: 20}
|
112
|
+
@snippetToolbar = new Mercury.SnippetToolbar($('document'), {appendTo: '#test'})
|
113
|
+
@snippetToolbar.snippet = $('#snippet')
|
114
|
+
|
115
|
+
it "positions itself based on the snippet", ->
|
116
|
+
@snippetToolbar.element.show()
|
117
|
+
@snippetToolbar.position()
|
118
|
+
if $.browser.webkit
|
119
|
+
expect(@snippetToolbar.element.offset()).toEqual({top: 18, left : 200})
|
120
|
+
else
|
121
|
+
expect(@snippetToolbar.element.offset()).toEqual({top: 14, left : 200})
|
122
|
+
|
123
|
+
|
124
|
+
describe "#appear", ->
|
125
|
+
|
126
|
+
beforeEach ->
|
127
|
+
@snippetToolbar = new Mercury.SnippetToolbar($('document'), {appendTo: '#test'})
|
128
|
+
|
129
|
+
it "clears the hide timeout", ->
|
130
|
+
spy = spyOn(window, 'clearTimeout').andCallFake(=>)
|
131
|
+
@snippetToolbar.appear()
|
132
|
+
expect(spy.callCount).toEqual(1)
|
133
|
+
|
134
|
+
it "sets visible", ->
|
135
|
+
@snippetToolbar.appear()
|
136
|
+
expect(@snippetToolbar.visible).toEqual(true)
|
137
|
+
|
138
|
+
it "shows the element", ->
|
139
|
+
@snippetToolbar.appear()
|
140
|
+
expect(@snippetToolbar.element.css('display')).toEqual('block')
|
141
|
+
|
142
|
+
|
143
|
+
describe "#hide", ->
|
144
|
+
|
145
|
+
beforeEach ->
|
146
|
+
@snippetToolbar = new Mercury.SnippetToolbar($('document'), {appendTo: '#test'})
|
147
|
+
|
148
|
+
it "it clears the hide timeout", ->
|
149
|
+
spy = spyOn(window, 'clearTimeout').andCallFake(=>)
|
150
|
+
@snippetToolbar.hide()
|
151
|
+
expect(spy.callCount).toEqual(1)
|
152
|
+
|
153
|
+
describe "immediately", ->
|
154
|
+
|
155
|
+
beforeEach ->
|
156
|
+
@snippetToolbar.element.show()
|
157
|
+
|
158
|
+
it "hides the element", ->
|
159
|
+
@snippetToolbar.hide(true)
|
160
|
+
expect(@snippetToolbar.element.css('display')).toEqual('none')
|
161
|
+
|
162
|
+
it "sets visible", ->
|
163
|
+
@snippetToolbar.visible = true
|
164
|
+
@snippetToolbar.hide(true)
|
165
|
+
expect(@snippetToolbar.visible).toEqual(false)
|
166
|
+
|
167
|
+
describe "not immediately", ->
|
168
|
+
|
169
|
+
beforeEach ->
|
170
|
+
@snippetToolbar.element.show()
|
171
|
+
@setTimeoutSpy = spyOn(window, 'setTimeout')
|
172
|
+
|
173
|
+
it "sets a timeout", ->
|
174
|
+
@setTimeoutSpy.andCallFake(=>)
|
175
|
+
@snippetToolbar.hide()
|
176
|
+
expect(@setTimeoutSpy.callCount).toEqual(1)
|
177
|
+
|
178
|
+
it "hides the element", ->
|
179
|
+
@setTimeoutSpy.andCallFake((callback) => callback())
|
180
|
+
@snippetToolbar.hide()
|
181
|
+
expect(@snippetToolbar.element.css('display')).toEqual('none')
|
182
|
+
|
183
|
+
it "sets visible", ->
|
184
|
+
@setTimeoutSpy.andCallFake((callback) => callback())
|
185
|
+
@snippetToolbar.hide()
|
186
|
+
expect(@snippetToolbar.visible).toEqual(false)
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require '/assets/mercury/mercury.js'
|
2
|
+
|
3
|
+
describe "Mercury.Statusbar", ->
|
4
|
+
|
5
|
+
template 'mercury/statusbar.html'
|
6
|
+
|
7
|
+
beforeEach ->
|
8
|
+
@region = {
|
9
|
+
path: -> [{tagName: 'A'}, {tagName: 'B'}, {tagName: 'C'}]
|
10
|
+
}
|
11
|
+
|
12
|
+
afterEach ->
|
13
|
+
@statusbar = null
|
14
|
+
delete(@statusbar)
|
15
|
+
|
16
|
+
describe "constructor", ->
|
17
|
+
|
18
|
+
beforeEach ->
|
19
|
+
@buildSpy = spyOn(Mercury.Statusbar.prototype, 'build')
|
20
|
+
@bindEventsSpy = spyOn(Mercury.Statusbar.prototype, 'bindEvents')
|
21
|
+
@statusbar = new Mercury.Statusbar({appendTo: '#test', foo: 'bar'})
|
22
|
+
|
23
|
+
it "accepts options", ->
|
24
|
+
expect(@statusbar.options.foo).toEqual('bar')
|
25
|
+
|
26
|
+
it "calls build", ->
|
27
|
+
expect(@buildSpy.callCount).toEqual(1)
|
28
|
+
|
29
|
+
it "calls bindEvents", ->
|
30
|
+
expect(@bindEventsSpy.callCount).toEqual(1)
|
31
|
+
|
32
|
+
|
33
|
+
describe "#height", ->
|
34
|
+
|
35
|
+
beforeEach ->
|
36
|
+
spyOn(Mercury.Statusbar.prototype, 'bindEvents').andCallFake(=>)
|
37
|
+
@statusbar = new Mercury.Statusbar({appendTo: '#test'})
|
38
|
+
|
39
|
+
it "knows it's own height", ->
|
40
|
+
expect(@statusbar.height()).toEqual(20) # styled with css in the template
|
41
|
+
|
42
|
+
|
43
|
+
describe "#build", ->
|
44
|
+
|
45
|
+
beforeEach ->
|
46
|
+
spyOn(Mercury.Statusbar.prototype, 'bindEvents').andCallFake(=>)
|
47
|
+
@statusbar = new Mercury.Statusbar({appendTo: '#statusbar_container'})
|
48
|
+
|
49
|
+
it "builds an element", ->
|
50
|
+
expect($('#test .mercury-statusbar').length).toEqual(1)
|
51
|
+
|
52
|
+
it "can append to any element", ->
|
53
|
+
expect($('#statusbar_container .mercury-statusbar').length).toEqual(1)
|
54
|
+
|
55
|
+
|
56
|
+
describe "observed events ", ->
|
57
|
+
|
58
|
+
beforeEach ->
|
59
|
+
spyOn(Mercury.Statusbar.prototype, 'build').andCallFake(=>)
|
60
|
+
@statusbar = new Mercury.Statusbar({appendTo: '#test'})
|
61
|
+
|
62
|
+
describe "custom event: region:update", ->
|
63
|
+
|
64
|
+
it "calls setPath if a region was provided", ->
|
65
|
+
spy = spyOn(Mercury.Statusbar.prototype, 'setPath').andCallFake(=>)
|
66
|
+
|
67
|
+
Mercury.trigger('region:update', {region: @region})
|
68
|
+
expect(spy.callCount).toEqual(1)
|
69
|
+
|
70
|
+
|
71
|
+
describe "#setPath", ->
|
72
|
+
|
73
|
+
beforeEach ->
|
74
|
+
@statusbar = new Mercury.Statusbar({appendTo: '#test'})
|
75
|
+
|
76
|
+
it "builds a path and displays it", ->
|
77
|
+
@statusbar.setPath(@region.path())
|
78
|
+
expect($('.mercury-statusbar').html()).toEqual('<span><strong>Path: </strong></span><a>c</a> » <a>b</a> » <a>a</a>')
|
@@ -0,0 +1,192 @@
|
|
1
|
+
require '/assets/mercury/mercury.js'
|
2
|
+
|
3
|
+
describe "Mercury.tableEditor", ->
|
4
|
+
|
5
|
+
template 'mercury/table_editor.html'
|
6
|
+
|
7
|
+
beforeEach ->
|
8
|
+
@table = $('#table1')
|
9
|
+
@cell = @table.find('th, td').first()
|
10
|
+
|
11
|
+
describe "singleton method", ->
|
12
|
+
|
13
|
+
beforeEach ->
|
14
|
+
@loadSpy = spyOn(Mercury.tableEditor, 'load').andCallFake(=>)
|
15
|
+
|
16
|
+
it "calls load", ->
|
17
|
+
Mercury.tableEditor(@table, @cell)
|
18
|
+
expect(@loadSpy.callCount).toEqual(1)
|
19
|
+
|
20
|
+
it "returns the function object", ->
|
21
|
+
ret = Mercury.tableEditor(@table, @cell)
|
22
|
+
expect(ret).toEqual(Mercury.tableEditor)
|
23
|
+
|
24
|
+
|
25
|
+
describe "#load", ->
|
26
|
+
|
27
|
+
it "expects a table and a table cell", ->
|
28
|
+
Mercury.tableEditor(@table, @cell)
|
29
|
+
expect(Mercury.tableEditor.table).toEqual(@table)
|
30
|
+
expect(Mercury.tableEditor.cell).toEqual(@cell)
|
31
|
+
|
32
|
+
it "sets row based on where the cell is", ->
|
33
|
+
Mercury.tableEditor(@table, @cell)
|
34
|
+
expect(Mercury.tableEditor.row.get(0)).toEqual(@table.find('tr').get(0))
|
35
|
+
|
36
|
+
it "gets the column count", ->
|
37
|
+
Mercury.tableEditor(@table, @cell)
|
38
|
+
expect(Mercury.tableEditor.columnCount).toEqual(6)
|
39
|
+
|
40
|
+
it "gets the row count", ->
|
41
|
+
Mercury.tableEditor(@table, @cell)
|
42
|
+
expect(Mercury.tableEditor.rowCount).toEqual(8)
|
43
|
+
|
44
|
+
|
45
|
+
describe "#getColumnCount", ->
|
46
|
+
|
47
|
+
it "gets the column count from the alpha row", ->
|
48
|
+
Mercury.tableEditor(@table, @cell)
|
49
|
+
expect(Mercury.tableEditor.columnCount).toEqual(6)
|
50
|
+
|
51
|
+
|
52
|
+
describe "#getRowCount", ->
|
53
|
+
|
54
|
+
it "gets the row count", ->
|
55
|
+
Mercury.tableEditor(@table, @cell)
|
56
|
+
expect(Mercury.tableEditor.rowCount).toEqual(8)
|
57
|
+
|
58
|
+
|
59
|
+
describe "#cellIndexFor", ->
|
60
|
+
|
61
|
+
it "gives the right index for different cells", ->
|
62
|
+
cell = @table.find('#row1 td:nth-child(1n)').get(0)
|
63
|
+
expect(Mercury.tableEditor.cellIndexFor(cell)).toEqual(0)
|
64
|
+
|
65
|
+
cell = @table.find('#row2 th:nth-child(2n)').get(0)
|
66
|
+
expect(Mercury.tableEditor.cellIndexFor(cell)).toEqual(1)
|
67
|
+
|
68
|
+
cell = @table.find('#row2 th:nth-child(6n)').get(0)
|
69
|
+
expect(Mercury.tableEditor.cellIndexFor(cell)).toEqual(5)
|
70
|
+
|
71
|
+
cell = @table.find('#row3 td:nth-child(4n)').get(0)
|
72
|
+
expect(Mercury.tableEditor.cellIndexFor(cell)).toEqual(5)
|
73
|
+
|
74
|
+
cell = @table.find('#row7 td:nth-child(2n)').get(0)
|
75
|
+
expect(Mercury.tableEditor.cellIndexFor(cell)).toEqual(2)
|
76
|
+
|
77
|
+
|
78
|
+
describe "#cellSignatureFor", ->
|
79
|
+
|
80
|
+
it "returns an object with cell information", ->
|
81
|
+
cell = @table.find('#row2 th:nth-child(3n)').get(0)
|
82
|
+
sig = Mercury.tableEditor.cellSignatureFor(cell)
|
83
|
+
expect(sig.width).toEqual(1)
|
84
|
+
expect(sig.height).toEqual(2)
|
85
|
+
expect(sig.right).toEqual(3)
|
86
|
+
|
87
|
+
cell = @table.find('#row2 th:nth-child(5n)').get(0)
|
88
|
+
sig = Mercury.tableEditor.cellSignatureFor(cell)
|
89
|
+
expect(sig.width).toEqual(1)
|
90
|
+
expect(sig.height).toEqual(4)
|
91
|
+
expect(sig.right).toEqual(5)
|
92
|
+
|
93
|
+
cell = @table.find('#row7 td:nth-child(1n)').get(0)
|
94
|
+
sig = Mercury.tableEditor.cellSignatureFor(cell)
|
95
|
+
expect(sig.width).toEqual(2)
|
96
|
+
expect(sig.height).toEqual(1)
|
97
|
+
expect(sig.right).toEqual(2)
|
98
|
+
|
99
|
+
describe "#findCellByOptionsFor", ->
|
100
|
+
|
101
|
+
it "finds a matching cell in a specific row, based on right", ->
|
102
|
+
row = @table.find('#row2').get(0)
|
103
|
+
sig = Mercury.tableEditor.findCellByOptionsFor(row, { right: 5 })
|
104
|
+
expect(sig.cell.get(0)).toEqual(@table.find('#row2 th:nth-child(5n)').get(0))
|
105
|
+
|
106
|
+
it "finds a cell based on left", ->
|
107
|
+
row = @table.find('#row5').get(0)
|
108
|
+
sig = Mercury.tableEditor.findCellByOptionsFor(row, { left: 5 })
|
109
|
+
expect(sig.cell.get(0)).toEqual(@table.find('#row5 th:nth-child(5n)').get(0))
|
110
|
+
|
111
|
+
it "finds a cell based on left and width", ->
|
112
|
+
row = @table.find('#row7').get(0)
|
113
|
+
sig = Mercury.tableEditor.findCellByOptionsFor(row, { left: 2, width: 4 })
|
114
|
+
expect(sig.cell.get(0)).toEqual(@table.find('#row7 td:nth-child(2n)').get(0))
|
115
|
+
|
116
|
+
describe "when a cell isn't there", ->
|
117
|
+
|
118
|
+
beforeEach ->
|
119
|
+
@row = @table.find('#row3').get(0)
|
120
|
+
|
121
|
+
it "returns null", ->
|
122
|
+
sig = Mercury.tableEditor.findCellByOptionsFor(@row, { left: 2 })
|
123
|
+
expect(sig).toEqual(null)
|
124
|
+
|
125
|
+
it "can force to an adjacent cell", ->
|
126
|
+
sig = Mercury.tableEditor.findCellByOptionsFor(@row, { left: 2, forceAdjacent: true })
|
127
|
+
expect(sig.cell.get(0)).toEqual(@table.find('#row3 td:nth-child(2n)').get(0))
|
128
|
+
expect(sig.direction).toEqual('after')
|
129
|
+
|
130
|
+
|
131
|
+
describe "#findCellByIntersectionFor", ->
|
132
|
+
|
133
|
+
it "finds cells that intersect vertically, based on the signature of another cell", ->
|
134
|
+
sig = Mercury.tableEditor.cellSignatureFor(@table.find('#row6 td:nth-child(3n)'))
|
135
|
+
intersectingSig = Mercury.tableEditor.findCellByIntersectionFor(@table.find('#row7'), sig)
|
136
|
+
expect(intersectingSig.cell.get(0)).toEqual(@table.find('#row7 td:nth-child(2n)').get(0))
|
137
|
+
|
138
|
+
|
139
|
+
describe "#columnsFor", ->
|
140
|
+
|
141
|
+
it "returns the total number of cells and colspans for a given collection of cells", ->
|
142
|
+
expect(Mercury.tableEditor.columnsFor(@table.find('#row7 td'))).toEqual(6)
|
143
|
+
|
144
|
+
|
145
|
+
describe "#colspanFor", ->
|
146
|
+
|
147
|
+
it "returns the colspan of a given cell", ->
|
148
|
+
cell = @table.find('#row7 td:nth-child(2n)')
|
149
|
+
expect(Mercury.tableEditor.colspanFor(cell)).toEqual(4)
|
150
|
+
|
151
|
+
it "defaults to 1", ->
|
152
|
+
cell = @table.find('#row6 td:first-child')
|
153
|
+
expect(Mercury.tableEditor.colspanFor(cell)).toEqual(1)
|
154
|
+
|
155
|
+
|
156
|
+
describe "#rowspanFor", ->
|
157
|
+
|
158
|
+
it "returns the rowspan of a given cell", ->
|
159
|
+
cell = @table.find('#row2 th:nth-child(5n)')
|
160
|
+
expect(Mercury.tableEditor.rowspanFor(cell)).toEqual(4)
|
161
|
+
|
162
|
+
it "defaults to 1", ->
|
163
|
+
cell = @table.find('#row6 td:first-child')
|
164
|
+
expect(Mercury.tableEditor.rowspanFor(cell)).toEqual(1)
|
165
|
+
|
166
|
+
|
167
|
+
describe "setColspanFor", ->
|
168
|
+
|
169
|
+
beforeEach ->
|
170
|
+
@cell = @table.find('#row2 th:first-child')
|
171
|
+
|
172
|
+
it "sets the colspan for a cell", ->
|
173
|
+
Mercury.tableEditor.setColspanFor(@cell, 20)
|
174
|
+
expect(@cell.attr('colspan')).toEqual('20')
|
175
|
+
|
176
|
+
it "removes the attribute if it's 1", ->
|
177
|
+
Mercury.tableEditor.setColspanFor(@cell, 1)
|
178
|
+
expect(@cell.attr('colspan')).toEqual(undefined)
|
179
|
+
|
180
|
+
|
181
|
+
describe "setRowspanFor", ->
|
182
|
+
|
183
|
+
beforeEach ->
|
184
|
+
@cell = @table.find('#row2 th:first-child')
|
185
|
+
|
186
|
+
it "sets the rowspan for a cell", ->
|
187
|
+
Mercury.tableEditor.setRowspanFor(@cell, 20)
|
188
|
+
expect(@cell.attr('rowspan')).toEqual('20')
|
189
|
+
|
190
|
+
it "removes the attribute if it's 1", ->
|
191
|
+
Mercury.tableEditor.setRowspanFor(@cell, 1)
|
192
|
+
expect(@cell.attr('rowspan')).toEqual(undefined)
|