mercury-rails 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. data/app/assets/javascripts/mercury.js +1 -0
  2. data/app/assets/javascripts/mercury/lightview.js.coffee +26 -12
  3. data/app/assets/javascripts/mercury/locales/ar.locale.js.coffee +3 -5
  4. data/app/assets/javascripts/mercury/locales/da.locale.js.coffee +3 -5
  5. data/app/assets/javascripts/mercury/locales/de.locale.js.coffee +4 -6
  6. data/app/assets/javascripts/mercury/locales/es.locale.js.coffee +3 -5
  7. data/app/assets/javascripts/mercury/locales/example.local.js.coffee +3 -1
  8. data/app/assets/javascripts/mercury/locales/fr.locale.js.coffee +3 -5
  9. data/app/assets/javascripts/mercury/locales/it.locale.js.coffee +3 -5
  10. data/app/assets/javascripts/mercury/locales/ko.local.js.coffee +4 -6
  11. data/app/assets/javascripts/mercury/locales/nl.locale.js.coffee +3 -5
  12. data/app/assets/javascripts/mercury/locales/pt.locale.js.coffee +3 -5
  13. data/app/assets/javascripts/mercury/locales/sv.local.js.coffee +3 -5
  14. data/app/assets/javascripts/mercury/locales/swedish_chef.locale.js.coffee +3 -5
  15. data/app/assets/javascripts/mercury/locales/zh.local.js.coffee +3 -5
  16. data/app/assets/javascripts/mercury/mercury.js.coffee +1 -1
  17. data/app/assets/javascripts/mercury/modal.js.coffee +38 -23
  18. data/app/assets/javascripts/mercury/modals/htmleditor.js.coffee +1 -0
  19. data/app/assets/javascripts/mercury/modals/insertcharacter.js.coffee +1 -0
  20. data/app/assets/javascripts/mercury/modals/insertlink.js.coffee +111 -60
  21. data/app/assets/javascripts/mercury/modals/insertmedia.js.coffee +80 -35
  22. data/app/assets/javascripts/mercury/modals/insertsnippet.js.coffee +1 -0
  23. data/app/assets/javascripts/mercury/modals/inserttable.js.coffee +59 -51
  24. data/app/assets/javascripts/mercury/page_editor.js.coffee +1 -1
  25. data/app/assets/javascripts/mercury/regions/full.coffee +1 -1
  26. data/app/assets/javascripts/mercury/regions/image.js.coffee +1 -1
  27. data/app/assets/javascripts/mercury/regions/markdown.coffee +1 -1
  28. data/app/assets/javascripts/mercury/regions/simple.js.coffee +1 -1
  29. data/app/assets/javascripts/mercury/regions/snippets.js.coffee +1 -1
  30. data/app/assets/javascripts/mercury/table_editor.js.coffee +16 -0
  31. data/app/assets/javascripts/mercury/toolbar.js.coffee +2 -2
  32. data/app/assets/stylesheets/mercury.css +0 -5
  33. data/app/assets/stylesheets/mercury/bootstrap-ish.css +1367 -0
  34. data/app/assets/stylesheets/mercury/bootstrap-overrides.css +60 -0
  35. data/app/assets/stylesheets/mercury/lightview.css +2 -52
  36. data/app/assets/stylesheets/mercury/mercury.css +2 -2
  37. data/app/assets/stylesheets/mercury/modal.css +13 -31
  38. data/app/assets/stylesheets/mercury/uploader.css +3 -3
  39. data/app/views/mercury/modals/htmleditor.html +2 -6
  40. data/app/views/mercury/modals/link.html +70 -64
  41. data/app/views/mercury/modals/media.html +80 -71
  42. data/app/views/mercury/modals/table.html +79 -73
  43. data/app/views/mercury/snippets/example/options.html.erb +11 -30
  44. data/features/loading/loading.feature +1 -1
  45. data/features/regions/full/inserting_links.feature +4 -4
  46. data/features/regions/full/inserting_media.feature +3 -3
  47. data/features/step_definitions/mercury_steps.rb +5 -5
  48. data/features/support/env.rb +1 -1
  49. data/lib/mercury/version.rb +1 -1
  50. data/spec/javascripts/mercury/lightview_spec.js.coffee +136 -129
  51. data/spec/javascripts/mercury/modal_spec.js.coffee +143 -139
  52. data/spec/javascripts/mercury/modals/insertlink_spec.js.coffee +105 -31
  53. data/spec/javascripts/mercury/modals/insertmedia_spec.js.coffee +76 -38
  54. data/spec/javascripts/mercury/modals/inserttable_spec.js.coffee +32 -35
  55. data/spec/javascripts/mercury/toolbar_spec.js.coffee +8 -0
  56. data/spec/javascripts/templates/mercury/modals/insertlink.html +58 -21
  57. data/spec/javascripts/templates/mercury/modals/insertmedia.html +69 -27
  58. data/spec/javascripts/templates/mercury/modals/inserttable.html +66 -20
  59. metadata +5 -5
  60. data/app/assets/stylesheets/mercury/buttons.css +0 -73
  61. data/app/assets/stylesheets/mercury/form.css +0 -125
@@ -1,84 +1,90 @@
1
- <form id="mercury_table" class="mercury-form" style="width:700px">
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
- <div id="table_display">
7
- <table border="1" cellspacing="0">
8
- <tr>
9
- <td>&nbsp;</td>
10
- <td>&nbsp;</td>
11
- <td>&nbsp;</td>
12
- </tr>
13
- <tr>
14
- <td>&nbsp;</td>
15
- <td>&nbsp;</td>
16
- <td>&nbsp;</td>
17
- </tr>
18
- </table>
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>&nbsp;</td>
11
+ <td>&nbsp;</td>
12
+ <td>&nbsp;</td>
13
+ </tr>
14
+ <tr>
15
+ <td>&nbsp;</td>
16
+ <td>&nbsp;</td>
17
+ <td>&nbsp;</td>
18
+ </tr>
19
+ </table>
20
+ </div>
19
21
  </div>
22
+ </fieldset>
20
23
 
21
- <div id="table_options">
22
- <fieldset class="inputs">
23
- <ol>
24
- <li id="table_rows_input" class="select input optional">
25
- <label for="table_rows">Rows</label>
26
- <input type="button" class="action" value="Add Before" name="insertRowBefore"/>
27
- <input type="button" class="action" value="Add After" name="insertRowAfter"/>
28
- <input type="button" class="action" value="Remove" name="deleteRow"/>
29
- </li>
30
- <li id="table_columns_input" class="select input optional">
31
- <label for="table_columns">Columns</label>
32
- <input type="button" class="action" value="Add Before" name="insertColumnBefore"/>
33
- <input type="button" class="action" value="Add After" name="insertColumnAfter"/>
34
- <input type="button" class="action" value="Remove" name="deleteColumn"/>
35
- </li>
36
- <hr/>
37
- <li id="table_row_adjust_input" class="select input optional">
38
- <label for="table_row_adjust">Row Span</label>
39
- <input type="button" class="action" value="+" name="increaseRowspan"/>
40
- <input type="button" class="action" value="-" name="decreaseRowspan"/>
41
- </li>
42
- <li id="table_column_adjust_input" class="select input optional">
43
- <label for="table_column_adjust">Column Span</label>
44
- <input type="button" class="action" value="+" name="increaseColspan"/>
45
- <input type="button" class="action" value="-" name="decreaseColspan"/>
46
- </li>
47
- </ol>
48
- </fieldset>
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
- <fieldset class="inputs">
51
- <legend><span>Options</span></legend>
52
- <ol>
53
- <li id="table_alignment_input" class="select input optional">
54
- <label class="label" for="table_alignment">Alignment</label>
55
- <select id="table_alignment" name="table[alignment]">
56
- <option value="">None</option>
57
- <option value="left">Left</option>
58
- <option value="right">Right</option>
59
- </select>
60
- </li>
61
- <li id="table_border_input" class="string input optional stringish">
62
- <label class="label" for="table_border">Border</label>
63
- <input id="table_border" name="table[border]" type="text" value="1"/>
64
- </li>
65
- <li id="table_spacing_input" class="string input optional stringish">
66
- <label class="label" for="table_spacing">Spacing</label>
67
- <input id="table_spacing" name="table[spacing]" type="text" value="0"/>
68
- </li>
69
- </ol>
70
- </fieldset>
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
- <fieldset class="buttons">
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', { :html => { :class => 'mercury-form', :style => 'width:600px' } } do |f| %>
2
-
3
- <div class="mercury-display-pane-container">
4
- <div class="mercury-display-pane">
5
- <fieldset class="inputs">
6
- <ol>
7
- <li class="string input optional stringish" id="options_first_name_input">
8
- <label class="label" for="options_first_name">First Name</label>
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.6.0" within the statusbar
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
- Scenario: A user can insert and edit a link to an external site
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
- Scenario: A user can insert and edit a link with a target set
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
- Scenario: A user can insert a link to an external site and open it in a popup
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
- Scenario: A user can insert a bookmark and then link to it
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 Share URL"
73
- And fill in "YouTube Share URL" with "http://youtu.be/Pny4hoN8eII"
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 Share URL" with "http://youtu.be/Pny4hoN8eI"
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 = "insert_#{row_or_column}_#{before_or_after}".camelcase(:lower)
180
- step(%Q{I click on ".mercury-modal-content input[name=#{name}]"})
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 = "delete_#{row_or_column}".camelcase(:lower)
185
- step(%Q{I click on ".mercury-modal-content input[name=#{name}]"})
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 input[name=#{name}]"})
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|
@@ -6,7 +6,7 @@
6
6
 
7
7
  ENV["RAILS_ROOT"] = File.expand_path('../../../spec/dummy', __FILE__)
8
8
  require 'cucumber/rails'
9
- # require 'capybara/firebug'
9
+ require 'capybara/firebug'
10
10
  require 'aruba/cucumber'
11
11
 
12
12
  # You can enable firebug in your tests by tagging them @firebug.
@@ -1,3 +1,3 @@
1
1
  module Mercury
2
- VERSION = '0.6.0'
2
+ VERSION = '0.7.0'
3
3
  end
@@ -11,8 +11,7 @@ describe "Mercury.lightview", ->
11
11
 
12
12
  afterEach ->
13
13
  Mercury.config.localization.enabled = false
14
- Mercury.lightview.initialized = false
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.lightview, 'show').andCallFake(=>)
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 the function object", ->
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.lightview, 'initialize').andCallFake(=>)
38
- @updateSpy = spyOn(Mercury.lightview, 'update').andCallFake(=>)
39
- @appearSpy = spyOn(Mercury.lightview, 'appear').andCallFake(=>)
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.lightview.show()
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.lightview.show()
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
- Mercury.lightview.visible = true
55
- Mercury.lightview.show()
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.lightview.show()
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 "#initialize", ->
68
+ describe "#initializeLightview", ->
66
69
 
67
70
  beforeEach ->
68
- @buildSpy = spyOn(Mercury.lightview, 'build').andCallFake(=>)
69
- @bindEventsSpy = spyOn(Mercury.lightview, 'bindEvents').andCallFake(=>)
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
- Mercury.lightview.initialize()
76
+ @lightview.initializeLightview()
73
77
  expect(@buildSpy.callCount).toEqual(1)
74
78
 
75
79
  it "calls bindEvents", ->
76
- Mercury.lightview.initialize()
80
+ @lightview.initializeLightview()
77
81
  expect(@bindEventsSpy.callCount).toEqual(1)
78
82
 
79
83
  it "does nothing if already initialized", ->
80
- Mercury.lightview.initialized = true
81
- Mercury.lightview.initialize()
84
+ @lightview.initialized = true
85
+ @lightview.initializeLightview()
82
86
  expect(@buildSpy.callCount).toEqual(0)
83
87
 
84
88
  it "sets initialized to true", ->
85
- Mercury.lightview.initialize()
86
- expect(Mercury.lightview.initialized).toEqual(true)
89
+ @lightview.initializeLightview()
90
+ expect(@lightview.initialized).toEqual(true)
87
91
 
88
92
 
89
93
  describe "#build", ->
90
94
 
91
95
  beforeEach ->
92
- Mercury.lightview.options = {appendTo: $('#test')}
96
+ @lightview = new Mercury.Lightview('', {appendTo: $('#test')})
93
97
 
94
98
  it "builds an element", ->
95
- Mercury.lightview.build()
99
+ @lightview.build()
96
100
  expect($('#test .mercury-lightview').length).toEqual(1)
97
101
 
98
102
  it "builds an overlay element", ->
99
- Mercury.lightview.build()
103
+ @lightview.build()
100
104
  expect($('#test .mercury-lightview-overlay').length).toEqual(1)
101
105
 
102
106
  it "creates a titleElement", ->
103
- Mercury.lightview.build()
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(Mercury.lightview.titleElement).toBeDefined()
110
+ expect(@lightview.titleElement).toBeDefined()
107
111
 
108
112
  it "creates a contentElement", ->
109
- Mercury.lightview.build()
113
+ @lightview.build()
110
114
  expect($('#test .mercury-lightview-content').length).toEqual(1)
111
- expect(Mercury.lightview.contentElement).toBeDefined()
115
+ expect(@lightview.contentElement).toBeDefined()
112
116
 
113
117
  it "appends to any element", ->
114
- Mercury.lightview.options = {appendTo: $('#lightview_container')}
115
- Mercury.lightview.build()
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
- Mercury.lightview.options.closeButton = true
121
- Mercury.lightview.build()
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.lightview, 'appear').andCallFake(=>)
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(Mercury.lightview, 'resize').andCallFake(=>)
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
- Mercury.lightview.visible = true
150
+ @lightview.visible = true
147
151
 
148
152
  it "calls position", ->
149
- spy = spyOn(Mercury.lightview, 'position').andCallFake(=>)
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(Mercury.lightview, 'hide').andCallFake(=>)
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
- Mercury.lightview.visible = true
167
+ @lightview.visible = true
164
168
 
165
169
  it "calls hide", ->
166
- spy = spyOn(Mercury.lightview, 'hide').andCallFake(=>)
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(Mercury.lightview, 'hide').andCallFake(=>)
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(Mercury.lightview, 'hide').andCallFake(=>)
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(Mercury.lightview, 'loadContent').andCallFake(=>)
194
- Mercury.lightview.element.trigger('ajax:beforeSend', [null, options])
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.lightview.visible = true
205
- spyOn(Mercury.lightview, 'update').andCallFake(=>)
206
- @loadSpy = spyOn(Mercury.lightview, 'load').andCallFake(=>)
207
- @positionSpy = spyOn(Mercury.lightview, 'position').andCallFake(=>)
208
- Mercury.lightview('/blank.html', {appendTo: $('#test')})
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
- Mercury.lightview.appear()
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
- Mercury.lightview.appear()
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
- Mercury.lightview.appear()
226
+ @lightview.appear()
222
227
  expect($('.mercury-lightview-overlay').css('opacity')).toEqual('1')
223
228
 
224
229
  it "calls setTitle", ->
225
- spy = spyOn(Mercury.lightview, 'setTitle').andCallFake(=>)
226
- Mercury.lightview.appear()
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
- Mercury.lightview.appear()
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
- Mercury.lightview.appear()
241
+ @lightview.appear()
237
242
  expect($('.mercury-lightview').css('opacity')).toEqual('1')
238
243
 
239
244
  it "sets visible to true", ->
240
- Mercury.lightview.visible = false
241
- Mercury.lightview.appear()
242
- expect(Mercury.lightview.visible).toEqual(true)
245
+ @lightview.visible = false
246
+ @lightview.appear()
247
+ expect(@lightview.visible).toEqual(true)
243
248
 
244
249
  it "calls load", ->
245
- Mercury.lightview.appear()
250
+ @lightview.appear()
246
251
  expect(@loadSpy.callCount).toEqual(1)
247
252
 
248
253
 
249
254
  describe "#resize", ->
250
255
 
251
256
  beforeEach ->
252
- spyOn(Mercury.lightview, 'appear').andCallFake(=>)
253
- Mercury.lightview('/blank.html', {appendTo: $('#test')})
254
- Mercury.lightview.contentPane = $()
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
- Mercury.lightview.resize(true)
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
- Mercury.lightview.resize()
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
- Mercury.lightview.loadContent('<div style="width:600px;height:400px"></div>')
275
+ @lightview.loadContent('<div style="width:600px;height:400px"></div>')
270
276
  $('.mercury-lightview').css({display: 'block', visibility: 'visible', top: 0})
271
- Mercury.lightview.resize()
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.lightview, 'appear').andCallFake(=>)
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
- @resetSpy = spyOn(Mercury.lightview, 'reset').andCallFake(=>)
290
- @resizeSpy = spyOn(Mercury.lightview, 'resize').andCallFake(=>)
291
- @loadSpy = spyOn(Mercury.lightview, 'load').andCallFake(=>)
292
- Mercury.lightview.update()
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.lightview, 'appear').andCallFake(=>)
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
- Mercury.lightview.url = null
319
+ @lightview.url = null
313
320
  $('.mercury-lightview').removeClass('loading')
314
- Mercury.lightview.load()
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
- Mercury.lightview.load()
325
+ @lightview.load()
319
326
  expect($('.mercury-lightview').hasClass('loading')).toEqual(true)
320
327
 
321
328
  it "calls setTitle", ->
322
- spy = spyOn(Mercury.lightview, 'setTitle').andCallFake(=>)
323
- Mercury.lightview.load()
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(Mercury.lightview, 'loadContent').andCallFake(=>)
337
- Mercury.lightview.load()
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
- Mercury.lightview.load()
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(Mercury.lightview, 'loadContent').andCallFake(=>)
357
- Mercury.lightview.load()
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(Mercury.lightview, 'hide').andCallFake(=>)
369
- Mercury.lightview.load()
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(Mercury.lightview, 'hide').andCallFake(=>)
380
+ spyOn(@lightview, 'hide').andCallFake(=>)
374
381
  spy = spyOn(window, 'alert').andCallFake(=>)
375
- Mercury.lightview.load()
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.lightview, 'appear').andCallFake(=>)
384
- @resizeSpy = spyOn(Mercury.lightview, 'resize').andCallFake(=>)
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
- Mercury.lightview.loadContent('content', {title: 'title'})
389
- expect(Mercury.lightview.options).toEqual({title: 'title'})
395
+ @lightview.loadContent('content', {title: 'title'})
396
+ expect(@lightview.options).toEqual({title: 'title'})
390
397
 
391
- it "calls initialize", ->
392
- spy = spyOn(Mercury.lightview, 'initialize').andCallFake(=>)
393
- Mercury.lightview.loadContent('content')
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(Mercury.lightview, 'setTitle').andCallFake(=>)
398
- Mercury.lightview.loadContent('content')
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
- Mercury.lightview.loaded = false
403
- Mercury.lightview.loadContent('content')
404
- expect(Mercury.lightview.loaded).toEqual(true)
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
- Mercury.lightview.loadContent('content')
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
- Mercury.lightview.loadContent('<span>content</span>')
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
- Mercury.lightview.loadContent('content')
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
- Mercury.lightview.loadContent('content', {afterLoad: => callCount += 1})
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
- Mercury.lightview.loadContent('content', {handler: 'foo'})
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
- Mercury.lightview.loadContent('<span>foo</span>')
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
- Mercury.lightview.loadContent('content')
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.lightview, 'appear').andCallFake(=>)
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
- Mercury.lightview.options = {title: 'new title'}
450
- Mercury.lightview.setTitle()
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.lightview, 'appear').andCallFake(=>)
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
- Mercury.lightview.reset()
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.lightview, 'appear').andCallFake(=>)
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
- Mercury.lightview.hide()
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
- Mercury.lightview.element.css('display:block')
481
- Mercury.lightview.hide()
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
- Mercury.lightview.overlay.css('display:block')
486
- Mercury.lightview.hide()
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(Mercury.lightview, 'reset').andCallFake(=>)
491
- Mercury.lightview.hide()
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
- Mercury.lightview.visible = true
496
- Mercury.lightview.hide()
497
- expect(Mercury.lightview.visible).toEqual(false)
502
+ @lightview.visible = true
503
+ @lightview.hide()
504
+ expect(@lightview.visible).toEqual(false)