mercury-rails 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/mercury.js +1 -0
- data/app/assets/javascripts/mercury/lightview.js.coffee +26 -12
- data/app/assets/javascripts/mercury/locales/ar.locale.js.coffee +3 -5
- data/app/assets/javascripts/mercury/locales/da.locale.js.coffee +3 -5
- data/app/assets/javascripts/mercury/locales/de.locale.js.coffee +4 -6
- data/app/assets/javascripts/mercury/locales/es.locale.js.coffee +3 -5
- data/app/assets/javascripts/mercury/locales/example.local.js.coffee +3 -1
- data/app/assets/javascripts/mercury/locales/fr.locale.js.coffee +3 -5
- data/app/assets/javascripts/mercury/locales/it.locale.js.coffee +3 -5
- data/app/assets/javascripts/mercury/locales/ko.local.js.coffee +4 -6
- data/app/assets/javascripts/mercury/locales/nl.locale.js.coffee +3 -5
- data/app/assets/javascripts/mercury/locales/pt.locale.js.coffee +3 -5
- data/app/assets/javascripts/mercury/locales/sv.local.js.coffee +3 -5
- data/app/assets/javascripts/mercury/locales/swedish_chef.locale.js.coffee +3 -5
- data/app/assets/javascripts/mercury/locales/zh.local.js.coffee +3 -5
- data/app/assets/javascripts/mercury/mercury.js.coffee +1 -1
- data/app/assets/javascripts/mercury/modal.js.coffee +38 -23
- data/app/assets/javascripts/mercury/modals/htmleditor.js.coffee +1 -0
- data/app/assets/javascripts/mercury/modals/insertcharacter.js.coffee +1 -0
- data/app/assets/javascripts/mercury/modals/insertlink.js.coffee +111 -60
- data/app/assets/javascripts/mercury/modals/insertmedia.js.coffee +80 -35
- data/app/assets/javascripts/mercury/modals/insertsnippet.js.coffee +1 -0
- data/app/assets/javascripts/mercury/modals/inserttable.js.coffee +59 -51
- data/app/assets/javascripts/mercury/page_editor.js.coffee +1 -1
- data/app/assets/javascripts/mercury/regions/full.coffee +1 -1
- data/app/assets/javascripts/mercury/regions/image.js.coffee +1 -1
- data/app/assets/javascripts/mercury/regions/markdown.coffee +1 -1
- data/app/assets/javascripts/mercury/regions/simple.js.coffee +1 -1
- data/app/assets/javascripts/mercury/regions/snippets.js.coffee +1 -1
- data/app/assets/javascripts/mercury/table_editor.js.coffee +16 -0
- data/app/assets/javascripts/mercury/toolbar.js.coffee +2 -2
- data/app/assets/stylesheets/mercury.css +0 -5
- data/app/assets/stylesheets/mercury/bootstrap-ish.css +1367 -0
- data/app/assets/stylesheets/mercury/bootstrap-overrides.css +60 -0
- data/app/assets/stylesheets/mercury/lightview.css +2 -52
- data/app/assets/stylesheets/mercury/mercury.css +2 -2
- data/app/assets/stylesheets/mercury/modal.css +13 -31
- data/app/assets/stylesheets/mercury/uploader.css +3 -3
- data/app/views/mercury/modals/htmleditor.html +2 -6
- data/app/views/mercury/modals/link.html +70 -64
- data/app/views/mercury/modals/media.html +80 -71
- data/app/views/mercury/modals/table.html +79 -73
- data/app/views/mercury/snippets/example/options.html.erb +11 -30
- data/features/loading/loading.feature +1 -1
- data/features/regions/full/inserting_links.feature +4 -4
- data/features/regions/full/inserting_media.feature +3 -3
- data/features/step_definitions/mercury_steps.rb +5 -5
- data/features/support/env.rb +1 -1
- data/lib/mercury/version.rb +1 -1
- data/spec/javascripts/mercury/lightview_spec.js.coffee +136 -129
- data/spec/javascripts/mercury/modal_spec.js.coffee +143 -139
- data/spec/javascripts/mercury/modals/insertlink_spec.js.coffee +105 -31
- data/spec/javascripts/mercury/modals/insertmedia_spec.js.coffee +76 -38
- data/spec/javascripts/mercury/modals/inserttable_spec.js.coffee +32 -35
- data/spec/javascripts/mercury/toolbar_spec.js.coffee +8 -0
- data/spec/javascripts/templates/mercury/modals/insertlink.html +58 -21
- data/spec/javascripts/templates/mercury/modals/insertmedia.html +69 -27
- data/spec/javascripts/templates/mercury/modals/inserttable.html +66 -20
- metadata +5 -5
- data/app/assets/stylesheets/mercury/buttons.css +0 -73
- data/app/assets/stylesheets/mercury/form.css +0 -125
@@ -1,84 +1,90 @@
|
|
1
|
-
<form id="mercury_table" class="
|
1
|
+
<form id="mercury_table" class="form-horizontal" style="width:700px">
|
2
2
|
|
3
|
-
<div class="mercury-display-pane-container">
|
4
|
-
<div class="mercury-display-pane">
|
3
|
+
<div class="form-inputs mercury-display-pane-container">
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
<
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
<
|
16
|
-
|
17
|
-
|
18
|
-
|
5
|
+
<fieldset id="table_display">
|
6
|
+
<div class="control-group optional">
|
7
|
+
<div class="controls">
|
8
|
+
<table border="1" cellspacing="0">
|
9
|
+
<tr>
|
10
|
+
<td> </td>
|
11
|
+
<td> </td>
|
12
|
+
<td> </td>
|
13
|
+
</tr>
|
14
|
+
<tr>
|
15
|
+
<td> </td>
|
16
|
+
<td> </td>
|
17
|
+
<td> </td>
|
18
|
+
</tr>
|
19
|
+
</table>
|
20
|
+
</div>
|
19
21
|
</div>
|
22
|
+
</fieldset>
|
20
23
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
24
|
+
<fieldset>
|
25
|
+
<div class="control-group buttons optional">
|
26
|
+
<label class="buttons optional control-label">Rows</label>
|
27
|
+
<div class="controls btn-group">
|
28
|
+
<button class="btn" data-action="addRowBefore">Add Before</button>
|
29
|
+
<button class="btn" data-action="addRowAfter">Add After</button>
|
30
|
+
<button class="btn" data-action="removeRow">Remove</button>
|
31
|
+
</div>
|
32
|
+
</div>
|
33
|
+
<div class="control-group buttons optional">
|
34
|
+
<label class="buttons optional control-label">Columns</label>
|
35
|
+
<div class="controls btn-group">
|
36
|
+
<button class="btn" data-action="addColumnBefore">Add Before</button>
|
37
|
+
<button class="btn" data-action="addColumnAfter">Add After</button>
|
38
|
+
<button class="btn" data-action="removeColumn">Remove</button>
|
39
|
+
</div>
|
40
|
+
</div>
|
41
|
+
<hr/>
|
42
|
+
<div class="control-group buttons optional">
|
43
|
+
<label class="buttons optional control-label">Row Span</label>
|
44
|
+
<div class="controls btn-group">
|
45
|
+
<button class="btn" data-action="increaseRowspan">+</button>
|
46
|
+
<button class="btn" data-action="decreaseRowspan">-</button>
|
47
|
+
</div>
|
48
|
+
</div>
|
49
|
+
<div class="control-group buttons optional">
|
50
|
+
<label class="buttons optional control-label">Column Span</label>
|
51
|
+
<div class="controls btn-group">
|
52
|
+
<button class="btn" data-action="increaseColspan">+</button>
|
53
|
+
<button class="btn" data-action="decreaseColspan">-</button>
|
54
|
+
</div>
|
55
|
+
</div>
|
56
|
+
</fieldset>
|
49
57
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
58
|
+
<fieldset>
|
59
|
+
<legend>Options</legend>
|
60
|
+
<div class="control-group select optional">
|
61
|
+
<label class="select optional control-label" for="table_alignment">Alignment</label>
|
62
|
+
<div class="controls">
|
63
|
+
<select class="select optional" id="table_alignment" name="table[alignment]">
|
64
|
+
<option value="">None</option>
|
65
|
+
<option value="right">Right</option>
|
66
|
+
<option value="left">Left</option>
|
67
|
+
</select>
|
68
|
+
</div>
|
69
|
+
</div>
|
70
|
+
<div class="control-group number optional">
|
71
|
+
<label class="number optional control-label" for="table_border">Border</label>
|
72
|
+
<div class="controls">
|
73
|
+
<input class="span1 number optional" id="table_border" name="table[border]" size="50" type="number" value="1">
|
74
|
+
</div>
|
75
|
+
</div>
|
76
|
+
<div class="control-group number optional">
|
77
|
+
<label class="number optional control-label" for="table_spacing">Spacing</label>
|
78
|
+
<div class="controls">
|
79
|
+
<input class="span1 number optional" id="table_spacing" name="table[spacing]" size="50" type="number" value="0">
|
80
|
+
</div>
|
71
81
|
</div>
|
82
|
+
</fieldset>
|
72
83
|
|
73
|
-
</div>
|
74
84
|
</div>
|
75
85
|
|
76
|
-
<div class="mercury-display-controls">
|
77
|
-
<
|
78
|
-
<ol>
|
79
|
-
<li class="commit button"><input class="submit" name="commit" type="submit" value="Insert Table" /></li>
|
80
|
-
</ol>
|
81
|
-
</fieldset>
|
86
|
+
<div class="form-actions mercury-display-controls">
|
87
|
+
<input class="btn btn-primary" name="commit" type="submit" value="Insert Table"/>
|
82
88
|
</div>
|
83
89
|
|
84
|
-
</form>
|
90
|
+
</form>
|
@@ -1,34 +1,15 @@
|
|
1
|
-
<%= form_for 'options', {
|
2
|
-
|
3
|
-
|
4
|
-
<
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
<input id="options_first_name" name="options[first_name]" type="text" value="<%= @options[:first_name] %>"/>
|
10
|
-
</li>
|
11
|
-
</ol>
|
12
|
-
</fieldset>
|
13
|
-
|
14
|
-
<fieldset class="inputs">
|
15
|
-
<legend><span>Options</span></legend>
|
16
|
-
<ol>
|
17
|
-
<li class="string input optional stringish" id="options_favorite_beer_input">
|
18
|
-
<label class="label" for="options_favorite_beer">Favorite Beer</label>
|
19
|
-
<input id="options_favorite_beer" name="options[favorite_beer]" type="text" value="<%= @options[:favorite_beer] %>"/>
|
20
|
-
</li>
|
21
|
-
</ol>
|
22
|
-
</fieldset>
|
23
|
-
</div>
|
24
|
-
</div>
|
25
|
-
|
26
|
-
<div class="mercury-display-controls">
|
27
|
-
<fieldset class="buttons">
|
28
|
-
<ol>
|
29
|
-
<li class="commit button"><input class="submit" name="commit" type="submit" value="Insert Snippet"/></li>
|
30
|
-
</ol>
|
1
|
+
<%= form_for 'options', {html: {class: 'form-horizontal', style: 'width:600px'}} do |f| %>
|
2
|
+
<div class="form-inputs">
|
3
|
+
<label for="options_first_name">First Name</label>
|
4
|
+
<input id="options_first_name" name="options[first_name]" type="text" value="<%= @options[:first_name] %>"/>
|
5
|
+
<fieldset>
|
6
|
+
<legend>Options</legend>
|
7
|
+
<label class="label" for="options_favorite_beer">Favorite Beer</label>
|
8
|
+
<input id="options_favorite_beer" name="options[favorite_beer]" type="text" value="<%= @options[:favorite_beer] %>"/>
|
31
9
|
</fieldset>
|
32
10
|
</div>
|
33
11
|
|
12
|
+
<div class="form-actions">
|
13
|
+
<input name="commit" type="submit" value="Insert Snippet"/>
|
14
|
+
</div>
|
34
15
|
<% end %>
|
@@ -21,5 +21,5 @@ Feature:
|
|
21
21
|
# Latest selenium webdriver seems to consider the lightview hidden
|
22
22
|
@use_hidden_elements
|
23
23
|
Scenario: A user can expect to see the status bar
|
24
|
-
Then I should see "Mercury Editor v0.
|
24
|
+
Then I should see "Mercury Editor v0.7.0" within the statusbar
|
25
25
|
|
@@ -11,7 +11,7 @@ Feature:
|
|
11
11
|
# Scenario: A user can expect all this!
|
12
12
|
|
13
13
|
|
14
|
-
|
14
|
+
Scenario: A user can insert and edit a link to an external site
|
15
15
|
Given the content of the full region is simple content
|
16
16
|
And I make a selection
|
17
17
|
|
@@ -32,7 +32,7 @@ Feature:
|
|
32
32
|
Then the contents of the full region should be "this is <a href='http://cnn.com'>simple</a> <b>content</b>"
|
33
33
|
|
34
34
|
|
35
|
-
|
35
|
+
Scenario: A user can insert and edit a link with a target set
|
36
36
|
Given the content of the full region is simple content
|
37
37
|
And I make a selection
|
38
38
|
|
@@ -48,7 +48,7 @@ Feature:
|
|
48
48
|
Then the contents of the full region should be "this is <a target='_top' href='http://google.com'>simple</a> <b>content</b>"
|
49
49
|
|
50
50
|
|
51
|
-
|
51
|
+
Scenario: A user can insert a link to an external site and open it in a popup
|
52
52
|
Given the content of the full region is simple content
|
53
53
|
And I make a selection
|
54
54
|
|
@@ -65,7 +65,7 @@ Feature:
|
|
65
65
|
And the "Popup Height" field should contain "200"
|
66
66
|
|
67
67
|
|
68
|
-
|
68
|
+
Scenario: A user can insert a bookmark and then link to it
|
69
69
|
Given the content of the full region is simple content
|
70
70
|
And I make a selection
|
71
71
|
|
@@ -69,8 +69,8 @@ Feature:
|
|
69
69
|
And I make a selection
|
70
70
|
|
71
71
|
When I click on the "Insert Media" button
|
72
|
-
And choose "YouTube
|
73
|
-
And fill in "YouTube
|
72
|
+
And choose "YouTube URL"
|
73
|
+
And fill in "YouTube URL" with "http://youtu.be/Pny4hoN8eII"
|
74
74
|
And fill in "Width" with "400"
|
75
75
|
And fill in "Height" with "200"
|
76
76
|
And press "Insert Media"
|
@@ -80,7 +80,7 @@ Feature:
|
|
80
80
|
And click on the "Insert Media" button
|
81
81
|
Then the "media_youtube_url" field should contain "http://youtu.be/Pny4hoN8eII"
|
82
82
|
|
83
|
-
When I fill in "YouTube
|
83
|
+
When I fill in "YouTube URL" with "http://youtu.be/Pny4hoN8eI"
|
84
84
|
And fill in "Width" with "500"
|
85
85
|
And fill in "Height" with "300"
|
86
86
|
And press "Insert Media"
|
@@ -176,18 +176,18 @@ end
|
|
176
176
|
#------------------------------------------------------------------------------
|
177
177
|
# in the modal window
|
178
178
|
When /^(?:|I )(?:add|insert) a (row|column) (before|after)(?: it)?$/ do |row_or_column, before_or_after|
|
179
|
-
name = "
|
180
|
-
step(%Q{I click on ".mercury-modal-content
|
179
|
+
name = "add_#{row_or_column}_#{before_or_after}".camelcase(:lower)
|
180
|
+
step(%Q{I click on ".mercury-modal-content button[data-action='#{name}']"})
|
181
181
|
end
|
182
182
|
|
183
183
|
When /^(?:|I )delete the(?: current)? (row|column)$/ do |row_or_column|
|
184
|
-
name = "
|
185
|
-
step(%Q{I click on ".mercury-modal-content
|
184
|
+
name = "remove_#{row_or_column}".camelcase(:lower)
|
185
|
+
step(%Q{I click on ".mercury-modal-content button[data-action='#{name}']"})
|
186
186
|
end
|
187
187
|
|
188
188
|
When /^(?:|I )(increase|decrease) the (rowspan|colspan)$/ do |increase_or_decrease, rowspan_or_colspan|
|
189
189
|
name = "#{increase_or_decrease}_#{rowspan_or_colspan}".camelcase(:lower)
|
190
|
-
step(%Q{I click on ".mercury-modal-content
|
190
|
+
step(%Q{I click on ".mercury-modal-content button[data-action=#{name}]"})
|
191
191
|
end
|
192
192
|
|
193
193
|
Then /^the selected cell should be (.*?)$/ do |locator|
|
data/features/support/env.rb
CHANGED
data/lib/mercury/version.rb
CHANGED
@@ -11,8 +11,7 @@ describe "Mercury.lightview", ->
|
|
11
11
|
|
12
12
|
afterEach ->
|
13
13
|
Mercury.config.localization.enabled = false
|
14
|
-
Mercury.lightview.
|
15
|
-
Mercury.lightview.visible = false
|
14
|
+
Mercury.lightview.instance = null
|
16
15
|
$(window).unbind('mercury:refresh')
|
17
16
|
$(window).unbind('mercury:resize')
|
18
17
|
$(document).unbind('keydown')
|
@@ -20,122 +19,127 @@ describe "Mercury.lightview", ->
|
|
20
19
|
describe "singleton method", ->
|
21
20
|
|
22
21
|
beforeEach ->
|
23
|
-
@showSpy = spyOn(Mercury.
|
22
|
+
@showSpy = spyOn(Mercury.Lightview.prototype, 'show').andCallFake(=>)
|
24
23
|
|
25
24
|
it "calls show", ->
|
26
25
|
Mercury.lightview('/foo')
|
27
26
|
expect(@showSpy.callCount).toEqual(1)
|
28
27
|
|
29
|
-
it "returns
|
28
|
+
it "returns an instance", ->
|
30
29
|
ret = Mercury.lightview('/foo')
|
31
|
-
expect(ret).toEqual(Mercury.lightview)
|
30
|
+
expect(ret).toEqual(Mercury.lightview.instance)
|
31
|
+
expect(ret).toEqual(new Mercury.Lightview('/foo'))
|
32
32
|
|
33
33
|
|
34
34
|
describe "#show", ->
|
35
35
|
|
36
36
|
beforeEach ->
|
37
|
-
@initializeSpy = spyOn(Mercury.
|
38
|
-
@updateSpy = spyOn(Mercury.
|
39
|
-
@appearSpy = spyOn(Mercury.
|
37
|
+
@initializeSpy = spyOn(Mercury.Lightview.prototype, 'initializeLightview').andCallFake(=>)
|
38
|
+
@updateSpy = spyOn(Mercury.Lightview.prototype, 'update').andCallFake(=>)
|
39
|
+
@appearSpy = spyOn(Mercury.Lightview.prototype, 'appear').andCallFake(=>)
|
40
40
|
|
41
41
|
it "triggers the focus:window event", ->
|
42
42
|
spy = spyOn(Mercury, 'trigger').andCallFake(=>)
|
43
|
-
Mercury.
|
43
|
+
new Mercury.Lightview().show()
|
44
44
|
expect(spy.callCount).toEqual(1)
|
45
45
|
expect(spy.argsForCall[0]).toEqual(['focus:window'])
|
46
46
|
|
47
47
|
it "calls initialize", ->
|
48
|
-
Mercury.
|
48
|
+
new Mercury.Lightview().show()
|
49
49
|
expect(@initializeSpy.callCount).toEqual(1)
|
50
50
|
|
51
51
|
describe "if already visible", ->
|
52
52
|
|
53
53
|
it "calls update", ->
|
54
|
-
|
55
|
-
|
54
|
+
lightview = new Mercury.Lightview()
|
55
|
+
lightview.visible = true
|
56
|
+
lightview.show()
|
56
57
|
expect(@updateSpy.callCount).toEqual(1)
|
57
58
|
|
58
59
|
describe "if not visible", ->
|
59
60
|
|
60
61
|
it "calls appear", ->
|
61
|
-
Mercury.
|
62
|
+
lightview = new Mercury.Lightview()
|
63
|
+
lightview.visible = false
|
64
|
+
lightview.show()
|
62
65
|
expect(@appearSpy.callCount).toEqual(1)
|
63
66
|
|
64
67
|
|
65
|
-
describe "#
|
68
|
+
describe "#initializeLightview", ->
|
66
69
|
|
67
70
|
beforeEach ->
|
68
|
-
@buildSpy = spyOn(Mercury.
|
69
|
-
@bindEventsSpy = spyOn(Mercury.
|
71
|
+
@buildSpy = spyOn(Mercury.Lightview.prototype, 'build').andCallFake(=>)
|
72
|
+
@bindEventsSpy = spyOn(Mercury.Lightview.prototype, 'bindEvents').andCallFake(=>)
|
73
|
+
@lightview = new Mercury.Lightview()
|
70
74
|
|
71
75
|
it "calls build", ->
|
72
|
-
|
76
|
+
@lightview.initializeLightview()
|
73
77
|
expect(@buildSpy.callCount).toEqual(1)
|
74
78
|
|
75
79
|
it "calls bindEvents", ->
|
76
|
-
|
80
|
+
@lightview.initializeLightview()
|
77
81
|
expect(@bindEventsSpy.callCount).toEqual(1)
|
78
82
|
|
79
83
|
it "does nothing if already initialized", ->
|
80
|
-
|
81
|
-
|
84
|
+
@lightview.initialized = true
|
85
|
+
@lightview.initializeLightview()
|
82
86
|
expect(@buildSpy.callCount).toEqual(0)
|
83
87
|
|
84
88
|
it "sets initialized to true", ->
|
85
|
-
|
86
|
-
expect(
|
89
|
+
@lightview.initializeLightview()
|
90
|
+
expect(@lightview.initialized).toEqual(true)
|
87
91
|
|
88
92
|
|
89
93
|
describe "#build", ->
|
90
94
|
|
91
95
|
beforeEach ->
|
92
|
-
|
96
|
+
@lightview = new Mercury.Lightview('', {appendTo: $('#test')})
|
93
97
|
|
94
98
|
it "builds an element", ->
|
95
|
-
|
99
|
+
@lightview.build()
|
96
100
|
expect($('#test .mercury-lightview').length).toEqual(1)
|
97
101
|
|
98
102
|
it "builds an overlay element", ->
|
99
|
-
|
103
|
+
@lightview.build()
|
100
104
|
expect($('#test .mercury-lightview-overlay').length).toEqual(1)
|
101
105
|
|
102
106
|
it "creates a titleElement", ->
|
103
|
-
|
107
|
+
@lightview.build()
|
104
108
|
expect($('#test .mercury-lightview-title').length).toEqual(1)
|
105
109
|
expect($('#test .mercury-lightview-title').html()).toEqual("<span><\/span>")
|
106
|
-
expect(
|
110
|
+
expect(@lightview.titleElement).toBeDefined()
|
107
111
|
|
108
112
|
it "creates a contentElement", ->
|
109
|
-
|
113
|
+
@lightview.build()
|
110
114
|
expect($('#test .mercury-lightview-content').length).toEqual(1)
|
111
|
-
expect(
|
115
|
+
expect(@lightview.contentElement).toBeDefined()
|
112
116
|
|
113
117
|
it "appends to any element", ->
|
114
|
-
|
115
|
-
|
118
|
+
@lightview.options = {appendTo: $('#lightview_container')}
|
119
|
+
@lightview.build()
|
116
120
|
expect($('#lightview_container .mercury-lightview').length).toEqual(1)
|
117
121
|
expect($('#lightview_container .mercury-lightview-overlay').length).toEqual(1)
|
118
122
|
|
119
123
|
it "creates a close button if asked to in the options", ->
|
120
|
-
|
121
|
-
|
124
|
+
@lightview.options.closeButton = true
|
125
|
+
@lightview.build()
|
122
126
|
expect($('#test .mercury-lightview-close').length).toEqual(1)
|
123
127
|
|
124
128
|
|
125
129
|
describe "observed events", ->
|
126
130
|
|
127
131
|
beforeEach ->
|
128
|
-
spyOn(Mercury.
|
132
|
+
spyOn(Mercury.Lightview.prototype, 'appear').andCallFake(=>)
|
129
133
|
|
130
134
|
describe "without a close button", ->
|
131
135
|
|
132
136
|
beforeEach ->
|
133
|
-
Mercury.lightview('/foo', {appendTo: $('#test')})
|
137
|
+
@lightview = Mercury.lightview('/foo', {appendTo: $('#test')})
|
134
138
|
|
135
139
|
describe "custom event: refresh", ->
|
136
140
|
|
137
141
|
it "calls resize telling it stay visible", ->
|
138
|
-
spy = spyOn(
|
142
|
+
spy = spyOn(@lightview, 'resize').andCallFake(=>)
|
139
143
|
Mercury.trigger('refresh')
|
140
144
|
expect(spy.callCount).toEqual(1)
|
141
145
|
expect(spy.argsForCall[0]).toEqual([true])
|
@@ -143,46 +147,46 @@ describe "Mercury.lightview", ->
|
|
143
147
|
describe "custom event: resize", ->
|
144
148
|
|
145
149
|
beforeEach ->
|
146
|
-
|
150
|
+
@lightview.visible = true
|
147
151
|
|
148
152
|
it "calls position", ->
|
149
|
-
spy = spyOn(
|
153
|
+
spy = spyOn(@lightview, 'position').andCallFake(=>)
|
150
154
|
Mercury.trigger('resize')
|
151
155
|
expect(spy.callCount).toEqual(1)
|
152
156
|
|
153
157
|
describe "clicking on the overlay", ->
|
154
158
|
|
155
159
|
it "calls hide", ->
|
156
|
-
spy = spyOn(
|
160
|
+
spy = spyOn(@lightview, 'hide').andCallFake(=>)
|
157
161
|
jasmine.simulate.click($('.mercury-lightview-overlay').get(0))
|
158
162
|
expect(spy.callCount).toEqual(1)
|
159
163
|
|
160
164
|
describe "pressing esc on document", ->
|
161
165
|
|
162
166
|
beforeEach ->
|
163
|
-
|
167
|
+
@lightview.visible = true
|
164
168
|
|
165
169
|
it "calls hide", ->
|
166
|
-
spy = spyOn(
|
170
|
+
spy = spyOn(@lightview, 'hide').andCallFake(=>)
|
167
171
|
jasmine.simulate.keydown(document, {keyCode: 27})
|
168
172
|
expect(spy.callCount).toEqual(1)
|
169
173
|
|
170
174
|
describe "with a close button", ->
|
171
175
|
|
172
176
|
beforeEach ->
|
173
|
-
Mercury.lightview('/foo', {appendTo: $('#test'), closeButton: true})
|
177
|
+
@lightview = Mercury.lightview('/foo', {appendTo: $('#test'), closeButton: true})
|
174
178
|
|
175
179
|
describe "clicking on the close button", ->
|
176
180
|
|
177
181
|
it "calls hide", ->
|
178
|
-
spy = spyOn(
|
182
|
+
spy = spyOn(@lightview, 'hide').andCallFake(=>)
|
179
183
|
jasmine.simulate.click($('.mercury-lightview-close').get(0))
|
180
184
|
expect(spy.callCount).toEqual(1)
|
181
185
|
|
182
186
|
describe "clicking on the overlay", ->
|
183
187
|
|
184
188
|
it "doesn't call hide", ->
|
185
|
-
spy = spyOn(
|
189
|
+
spy = spyOn(@lightview, 'hide').andCallFake(=>)
|
186
190
|
jasmine.simulate.click($('.mercury-lightview-overlay').get(0))
|
187
191
|
expect(spy.callCount).toEqual(0)
|
188
192
|
|
@@ -190,8 +194,8 @@ describe "Mercury.lightview", ->
|
|
190
194
|
|
191
195
|
it "sets a success that will load the contents of the response", ->
|
192
196
|
options = {}
|
193
|
-
spy = spyOn(
|
194
|
-
|
197
|
+
spy = spyOn(@lightview, 'loadContent').andCallFake(=>)
|
198
|
+
@lightview.element.trigger('ajax:beforeSend', [null, options])
|
195
199
|
expect(options.success).toBeDefined()
|
196
200
|
options.success('new content')
|
197
201
|
expect(spy.callCount).toEqual(1)
|
@@ -201,74 +205,76 @@ describe "Mercury.lightview", ->
|
|
201
205
|
describe "#appear", ->
|
202
206
|
|
203
207
|
beforeEach ->
|
204
|
-
Mercury.
|
205
|
-
|
206
|
-
|
207
|
-
@
|
208
|
-
|
208
|
+
@lightview = new Mercury.Lightview('/blank.html', {appendTo: $('#test')})
|
209
|
+
@lightview.visible = true
|
210
|
+
spyOn(@lightview, 'update').andCallFake(=>)
|
211
|
+
@loadSpy = spyOn(@lightview, 'load').andCallFake(=>)
|
212
|
+
@positionSpy = spyOn(@lightview, 'position').andCallFake(=>)
|
213
|
+
@lightview.show()
|
209
214
|
|
210
215
|
it "calls position", ->
|
211
|
-
|
216
|
+
@lightview.appear()
|
212
217
|
expect(@positionSpy.callCount).toEqual(1)
|
213
218
|
|
214
219
|
it "shows the overlay", ->
|
215
220
|
expect($('.mercury-lightview-overlay').css('display')).toEqual('none')
|
216
|
-
|
221
|
+
@lightview.appear()
|
217
222
|
expect($('.mercury-lightview-overlay').css('display')).toEqual('block')
|
218
223
|
|
219
224
|
it "animates the overlay to full opacity", ->
|
220
225
|
expect($('.mercury-lightview-overlay').css('opacity')).toEqual('0')
|
221
|
-
|
226
|
+
@lightview.appear()
|
222
227
|
expect($('.mercury-lightview-overlay').css('opacity')).toEqual('1')
|
223
228
|
|
224
229
|
it "calls setTitle", ->
|
225
|
-
spy = spyOn(
|
226
|
-
|
230
|
+
spy = spyOn(@lightview, 'setTitle').andCallFake(=>)
|
231
|
+
@lightview.appear()
|
227
232
|
expect(spy.callCount).toEqual(1)
|
228
233
|
|
229
234
|
it "shows the element", ->
|
230
235
|
expect($('.mercury-lightview').css('display')).toEqual('none')
|
231
|
-
|
236
|
+
@lightview.appear()
|
232
237
|
expect($('.mercury-lightview').css('display')).toEqual('block')
|
233
238
|
|
234
239
|
it "animates the element opacity", ->
|
235
240
|
expect($('.mercury-lightview').css('opacity')).toEqual('0')
|
236
|
-
|
241
|
+
@lightview.appear()
|
237
242
|
expect($('.mercury-lightview').css('opacity')).toEqual('1')
|
238
243
|
|
239
244
|
it "sets visible to true", ->
|
240
|
-
|
241
|
-
|
242
|
-
expect(
|
245
|
+
@lightview.visible = false
|
246
|
+
@lightview.appear()
|
247
|
+
expect(@lightview.visible).toEqual(true)
|
243
248
|
|
244
249
|
it "calls load", ->
|
245
|
-
|
250
|
+
@lightview.appear()
|
246
251
|
expect(@loadSpy.callCount).toEqual(1)
|
247
252
|
|
248
253
|
|
249
254
|
describe "#resize", ->
|
250
255
|
|
251
256
|
beforeEach ->
|
252
|
-
|
253
|
-
|
254
|
-
|
257
|
+
@lightview = new Mercury.Lightview('/blank.html', {appendTo: $('#test')})
|
258
|
+
spyOn(@lightview, 'appear').andCallFake(=>)
|
259
|
+
@lightview.show()
|
260
|
+
@lightview.contentPane = $()
|
255
261
|
|
256
262
|
it "will keep the content element visible if asked to do so", ->
|
257
263
|
$('.mercury-lightview-content').css('visibility', 'visible')
|
258
|
-
|
264
|
+
@lightview.resize(true)
|
259
265
|
expect($('.mercury-lightview-content').css('visibility')).toEqual('visible')
|
260
266
|
|
261
267
|
it "resizes the element and adjusts it's position when empty", ->
|
262
268
|
$('.mercury-lightview').css({display: 'block', visibility: 'visible', top: 0})
|
263
|
-
|
269
|
+
@lightview.resize()
|
264
270
|
expect($('.mercury-lightview').width()).toEqual(300)
|
265
271
|
expect($('.mercury-lightview').offset()).toEqual({top: 35, left: 350})
|
266
272
|
expect($('.mercury-lightview').height()).toEqual(150)
|
267
273
|
|
268
274
|
it "resizes the element and adjusts it's position when it has content", ->
|
269
|
-
|
275
|
+
@lightview.loadContent('<div style="width:600px;height:400px"></div>')
|
270
276
|
$('.mercury-lightview').css({display: 'block', visibility: 'visible', top: 0})
|
271
|
-
|
277
|
+
@lightview.resize()
|
272
278
|
expect($('.mercury-lightview').width()).toEqual(300)
|
273
279
|
expect($('.mercury-lightview').offset()).toEqual({top: 20, left: 350})
|
274
280
|
expect($('.mercury-lightview').height()).toEqual(180)
|
@@ -277,7 +283,7 @@ describe "Mercury.lightview", ->
|
|
277
283
|
describe "#position", ->
|
278
284
|
|
279
285
|
beforeEach ->
|
280
|
-
spyOn(Mercury.
|
286
|
+
spyOn(Mercury.Lightview.prototype, 'appear').andCallFake(=>)
|
281
287
|
|
282
288
|
# todo: test this
|
283
289
|
it "positions the element", ->
|
@@ -286,10 +292,11 @@ describe "Mercury.lightview", ->
|
|
286
292
|
describe "#update", ->
|
287
293
|
|
288
294
|
beforeEach ->
|
289
|
-
@
|
290
|
-
@
|
291
|
-
@
|
292
|
-
|
295
|
+
@lightview = new Mercury.Lightview()
|
296
|
+
@resetSpy = spyOn(@lightview, 'reset').andCallFake(=>)
|
297
|
+
@resizeSpy = spyOn(@lightview, 'resize').andCallFake(=>)
|
298
|
+
@loadSpy = spyOn(@lightview, 'load').andCallFake(=>)
|
299
|
+
@lightview.update()
|
293
300
|
|
294
301
|
it "calls reset", ->
|
295
302
|
expect(@resetSpy.callCount).toEqual(1)
|
@@ -304,23 +311,23 @@ describe "Mercury.lightview", ->
|
|
304
311
|
describe "#load", ->
|
305
312
|
|
306
313
|
beforeEach ->
|
307
|
-
spyOn(Mercury.
|
314
|
+
spyOn(Mercury.Lightview.prototype, 'appear').andCallFake(=>)
|
308
315
|
@ajaxSpy = spyOn($, 'ajax')
|
309
|
-
Mercury.lightview('/blank.html', {appendTo: $('#test')})
|
316
|
+
@lightview = Mercury.lightview('/blank.html', {appendTo: $('#test')})
|
310
317
|
|
311
318
|
it "does nothing if there's no url", ->
|
312
|
-
|
319
|
+
@lightview.url = null
|
313
320
|
$('.mercury-lightview').removeClass('loading')
|
314
|
-
|
321
|
+
@lightview.load()
|
315
322
|
expect($('.mercury-lightview').hasClass('loading')).toEqual(false)
|
316
323
|
|
317
324
|
it "sets the loading class on the element", ->
|
318
|
-
|
325
|
+
@lightview.load()
|
319
326
|
expect($('.mercury-lightview').hasClass('loading')).toEqual(true)
|
320
327
|
|
321
328
|
it "calls setTitle", ->
|
322
|
-
spy = spyOn(
|
323
|
-
|
329
|
+
spy = spyOn(@lightview, 'setTitle').andCallFake(=>)
|
330
|
+
@lightview.load()
|
324
331
|
expect(spy.callCount).toEqual(1)
|
325
332
|
|
326
333
|
describe "on a preloaded view", ->
|
@@ -333,8 +340,8 @@ describe "Mercury.lightview", ->
|
|
333
340
|
Mercury.preloadedViews = {}
|
334
341
|
|
335
342
|
it "calls loadContent with the content in the preloaded view", ->
|
336
|
-
spy = spyOn(
|
337
|
-
|
343
|
+
spy = spyOn(@lightview, 'loadContent').andCallFake(=>)
|
344
|
+
@lightview.load()
|
338
345
|
expect(@setTimeoutSpy.callCount).toEqual(1)
|
339
346
|
expect(spy.callCount).toEqual(1)
|
340
347
|
|
@@ -343,7 +350,7 @@ describe "Mercury.lightview", ->
|
|
343
350
|
it "makes an ajax request", ->
|
344
351
|
@ajaxSpy.andCallFake(=>)
|
345
352
|
spyOn(Mercury, 'ajaxHeaders').andCallFake(=> {'X-CSRFToken': 'f00'})
|
346
|
-
|
353
|
+
@lightview.load()
|
347
354
|
expect(@ajaxSpy.callCount).toEqual(1)
|
348
355
|
expect(@ajaxSpy.argsForCall[0][1]['headers']).toEqual({'X-CSRFToken': 'f00'})
|
349
356
|
|
@@ -353,8 +360,8 @@ describe "Mercury.lightview", ->
|
|
353
360
|
@ajaxSpy.andCallFake((url, options) => options.success('return value'))
|
354
361
|
|
355
362
|
it "calls loadContent and passes the returned data", ->
|
356
|
-
spy = spyOn(
|
357
|
-
|
363
|
+
spy = spyOn(@lightview, 'loadContent').andCallFake(=>)
|
364
|
+
@lightview.load()
|
358
365
|
expect(spy.callCount).toEqual(1)
|
359
366
|
expect(spy.argsForCall[0]).toEqual(['return value'])
|
360
367
|
|
@@ -365,14 +372,14 @@ describe "Mercury.lightview", ->
|
|
365
372
|
|
366
373
|
it "calls hide", ->
|
367
374
|
spyOn(window, 'alert').andCallFake(=>)
|
368
|
-
spy = spyOn(
|
369
|
-
|
375
|
+
spy = spyOn(@lightview, 'hide').andCallFake(=>)
|
376
|
+
@lightview.load()
|
370
377
|
expect(spy.callCount).toEqual(1)
|
371
378
|
|
372
379
|
it "alerts an error message", ->
|
373
|
-
spyOn(
|
380
|
+
spyOn(@lightview, 'hide').andCallFake(=>)
|
374
381
|
spy = spyOn(window, 'alert').andCallFake(=>)
|
375
|
-
|
382
|
+
@lightview.load()
|
376
383
|
expect(spy.callCount).toEqual(1)
|
377
384
|
expect(spy.argsForCall[0]).toEqual(['Mercury was unable to load /blank.html for the lightview.'])
|
378
385
|
|
@@ -380,86 +387,86 @@ describe "Mercury.lightview", ->
|
|
380
387
|
describe "#loadContent", ->
|
381
388
|
|
382
389
|
beforeEach ->
|
383
|
-
spyOn(Mercury.
|
384
|
-
@resizeSpy = spyOn(Mercury.
|
385
|
-
Mercury.lightview('/blank.html', {appendTo: $('#test'), title: 'title'})
|
390
|
+
spyOn(Mercury.Lightview.prototype, 'appear').andCallFake(=>)
|
391
|
+
@resizeSpy = spyOn(Mercury.Lightview.prototype, 'resize').andCallFake(=>)
|
392
|
+
@lightview = Mercury.lightview('/blank.html', {appendTo: $('#test'), title: 'title'})
|
386
393
|
|
387
394
|
it "accepts options and sets them to the instance options", ->
|
388
|
-
|
389
|
-
expect(
|
395
|
+
@lightview.loadContent('content', {title: 'title'})
|
396
|
+
expect(@lightview.options).toEqual({title: 'title'})
|
390
397
|
|
391
|
-
it "calls
|
392
|
-
spy = spyOn(
|
393
|
-
|
398
|
+
it "calls initializeLightview", ->
|
399
|
+
spy = spyOn(@lightview, 'initializeLightview').andCallFake(=>)
|
400
|
+
@lightview.loadContent('content')
|
394
401
|
expect(spy.callCount).toEqual(1)
|
395
402
|
|
396
403
|
it "calls setTitle", ->
|
397
|
-
spy = spyOn(
|
398
|
-
|
404
|
+
spy = spyOn(@lightview, 'setTitle').andCallFake(=>)
|
405
|
+
@lightview.loadContent('content')
|
399
406
|
expect(spy.callCount).toEqual(1)
|
400
407
|
|
401
408
|
it "sets loaded to true", ->
|
402
|
-
|
403
|
-
|
404
|
-
expect(
|
409
|
+
@lightview.loaded = false
|
410
|
+
@lightview.loadContent('content')
|
411
|
+
expect(@lightview.loaded).toEqual(true)
|
405
412
|
|
406
413
|
it "removes the loading class", ->
|
407
414
|
$('.mercury-lightview').addClass('loading')
|
408
|
-
|
415
|
+
@lightview.loadContent('content')
|
409
416
|
expect($('.mercury-lightview').hasClass('loading')).toEqual(false)
|
410
417
|
|
411
418
|
it "sets the content elements html to whatever was passed", ->
|
412
|
-
|
419
|
+
@lightview.loadContent('<span>content</span>')
|
413
420
|
expect($('.mercury-lightview-content').html()).toEqual('<span>content</span>')
|
414
421
|
|
415
422
|
it "hides the contentElement", ->
|
416
423
|
$('.mercury-lightview-content').css('display', 'block')
|
417
|
-
|
424
|
+
@lightview.loadContent('content')
|
418
425
|
expect($('.mercury-lightview-content').css('display')).toEqual('none')
|
419
426
|
expect($('.mercury-lightview-content').css('visibility')).toEqual('hidden')
|
420
427
|
|
421
428
|
it "calls an afterLoad callback (if provided in options)", ->
|
422
429
|
callCount = 0
|
423
|
-
|
430
|
+
@lightview.loadContent('content', {afterLoad: => callCount += 1})
|
424
431
|
expect(callCount).toEqual(1)
|
425
432
|
|
426
433
|
it "calls a handler method if one is set in lightviewHandlers", ->
|
427
434
|
callCount = 0
|
428
435
|
Mercury.lightviewHandlers['foo'] = => callCount += 1
|
429
|
-
|
436
|
+
@lightview.loadContent('content', {handler: 'foo'})
|
430
437
|
expect(callCount).toEqual(1)
|
431
438
|
|
432
439
|
it "translates the content if configured", ->
|
433
440
|
Mercury.config.localization.enabled = true
|
434
|
-
|
441
|
+
@lightview.loadContent('<span>foo</span>')
|
435
442
|
expect($('.mercury-lightview-content').html()).toEqual('<span>Bork!</span>')
|
436
443
|
|
437
444
|
it "calls resize", ->
|
438
|
-
|
445
|
+
@lightview.loadContent('content')
|
439
446
|
expect(@resizeSpy.callCount).toEqual(1)
|
440
447
|
|
441
448
|
|
442
449
|
describe "#setTitle", ->
|
443
450
|
|
444
451
|
beforeEach ->
|
445
|
-
spyOn(Mercury.
|
446
|
-
Mercury.lightview('/blank.html', {appendTo: $('#test'), title: 'title'})
|
452
|
+
spyOn(Mercury.Lightview.prototype, 'appear').andCallFake(=>)
|
453
|
+
@lightview = Mercury.lightview('/blank.html', {appendTo: $('#test'), title: 'title'})
|
447
454
|
|
448
455
|
it "sets the the title contents to what was provided in the options", ->
|
449
|
-
|
450
|
-
|
456
|
+
@lightview.options = {title: 'new title'}
|
457
|
+
@lightview.setTitle()
|
451
458
|
expect($('.mercury-lightview-title span').html()).toEqual('new title')
|
452
459
|
|
453
460
|
|
454
461
|
describe "#reset", ->
|
455
462
|
|
456
463
|
beforeEach ->
|
457
|
-
spyOn(Mercury.
|
458
|
-
Mercury.lightview('/blank.html', {appendTo: $('#test'), title: 'title'})
|
464
|
+
spyOn(Mercury.Lightview.prototype, 'appear').andCallFake(=>)
|
465
|
+
@lightview = Mercury.lightview('/blank.html', {appendTo: $('#test'), title: 'title'})
|
459
466
|
|
460
467
|
it "clears the title and content elements", ->
|
461
468
|
$('.mercury-lightview-content').html('content')
|
462
|
-
|
469
|
+
@lightview.reset()
|
463
470
|
expect($('.mercury-lightview-content').html()).toEqual('')
|
464
471
|
expect($('.mercury-lightview-title span').html()).toEqual('')
|
465
472
|
|
@@ -467,31 +474,31 @@ describe "Mercury.lightview", ->
|
|
467
474
|
describe "#hide", ->
|
468
475
|
|
469
476
|
beforeEach ->
|
470
|
-
spyOn(Mercury.
|
471
|
-
Mercury.lightview('/blank.html', {appendTo: $('#test')})
|
477
|
+
spyOn(Mercury.Lightview.prototype, 'appear').andCallFake(=>)
|
478
|
+
@lightview = Mercury.lightview('/blank.html', {appendTo: $('#test')})
|
472
479
|
|
473
480
|
it "triggers the focus:frame event", ->
|
474
481
|
spy = spyOn(Mercury, 'trigger').andCallFake(=>)
|
475
|
-
|
482
|
+
@lightview.hide()
|
476
483
|
expect(spy.callCount).toEqual(1)
|
477
484
|
expect(spy.argsForCall[0]).toEqual(['focus:frame'])
|
478
485
|
|
479
486
|
it "hides the element", ->
|
480
|
-
|
481
|
-
|
487
|
+
@lightview.element.css('display:block')
|
488
|
+
@lightview.hide()
|
482
489
|
expect($('.mercury-lightview').css('display')).toEqual('none')
|
483
490
|
|
484
491
|
it "hides the overlay element", ->
|
485
|
-
|
486
|
-
|
492
|
+
@lightview.overlay.css('display:block')
|
493
|
+
@lightview.hide()
|
487
494
|
expect($('.mercury-lightview-overlay').css('display')).toEqual('none')
|
488
495
|
|
489
496
|
it "calls reset", ->
|
490
|
-
spy = spyOn(
|
491
|
-
|
497
|
+
spy = spyOn(@lightview, 'reset').andCallFake(=>)
|
498
|
+
@lightview.hide()
|
492
499
|
expect(spy.callCount).toEqual(1)
|
493
500
|
|
494
501
|
it "sets visible to false", ->
|
495
|
-
|
496
|
-
|
497
|
-
expect(
|
502
|
+
@lightview.visible = true
|
503
|
+
@lightview.hide()
|
504
|
+
expect(@lightview.visible).toEqual(false)
|