kiteditor 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +25 -0
- data/app/controllers/mercury/images_controller.rb +5 -0
- data/app/controllers/mercury_controller.rb +34 -0
- data/app/models/mercury/image.rb +17 -0
- data/app/views/layouts/mercury.html.erb +33 -0
- data/app/views/layouts/popup.html.haml +9 -0
- data/app/views/mercury/images/_list.html.haml +22 -0
- data/app/views/mercury/images/index.html.haml +4 -0
- data/app/views/mercury/images/index.js.erb +2 -0
- data/app/views/mercury/lightviews/about.html +11 -0
- data/app/views/mercury/modals/character.html +255 -0
- data/app/views/mercury/modals/htmleditor.html +13 -0
- data/app/views/mercury/modals/link.html +94 -0
- data/app/views/mercury/modals/media.html +1 -0
- data/app/views/mercury/modals/table.html +84 -0
- data/app/views/mercury/palettes/backcolor.html +73 -0
- data/app/views/mercury/palettes/forecolor.html +73 -0
- data/app/views/mercury/panels/history.html +3 -0
- data/app/views/mercury/panels/notes.html +3 -0
- data/app/views/mercury/panels/snippets.html +12 -0
- data/app/views/mercury/selects/formatblock.html +11 -0
- data/app/views/mercury/selects/style.html +5 -0
- data/app/views/mercury/snippets/example/options.html.erb +34 -0
- data/app/views/mercury/snippets/example/preview.html.erb +1 -0
- data/config/engine.rb +44 -0
- data/db/migrate/20110526035601_create_mercury_images.rb +11 -0
- data/features/loading/loading.feature +22 -0
- data/features/loading/navigating.feature +77 -0
- data/features/loading/user_interface.feature +67 -0
- data/features/regions/editable/advanced_editing.feature +0 -0
- data/features/regions/editable/basic_editing.feature +195 -0
- data/features/regions/editable/inserting_links.feature +98 -0
- data/features/regions/editable/inserting_media.feature +110 -0
- data/features/regions/editable/inserting_snippets.feature +102 -0
- data/features/regions/editable/inserting_special_characters.feature +24 -0
- data/features/regions/editable/inserting_tables.feature +109 -0
- data/features/regions/editable/pasting.feature +0 -0
- data/features/regions/editable/uploading_images.feature +0 -0
- data/features/regions/markupable/advanced_editing.feature +0 -0
- data/features/regions/markupable/basic_editing.feature +0 -0
- data/features/regions/markupable/inserting_links.feature +0 -0
- data/features/regions/markupable/inserting_media.feature +0 -0
- data/features/regions/markupable/inserting_snippets.feature +0 -0
- data/features/regions/markupable/inserting_special_characters.feature +0 -0
- data/features/regions/markupable/inserting_tables.feature +0 -0
- data/features/regions/markupable/uploading_images.feature +0 -0
- data/features/regions/snippetable/advanced_editing.feature +0 -0
- data/features/regions/snippetable/basic_editing.feature +0 -0
- data/features/regions/snippetable/inserting_snippets.feature +0 -0
- data/features/saving/saving.feature +33 -0
- data/features/step_definitions/debug_steps.rb +14 -0
- data/features/step_definitions/mercury_steps.rb +438 -0
- data/features/step_definitions/web_steps.rb +211 -0
- data/features/support/env.rb +46 -0
- data/features/support/mercury_contents.rb +25 -0
- data/features/support/mercury_selectors.rb +148 -0
- data/features/support/paths.rb +38 -0
- data/features/support/selectors.rb +44 -0
- data/lib/generators/mercury/install/install_generator.rb +49 -0
- data/lib/generators/mercury/install/templates/mongoid_paperclip_image.rb +17 -0
- data/lib/mercury/authentication.rb +8 -0
- data/lib/mercury-rails.rb +3 -0
- data/spec/javascripts/mercury/dialog_spec.js.coffee +281 -0
- data/spec/javascripts/mercury/dialogs/backcolor_spec.js.coffee +37 -0
- data/spec/javascripts/mercury/dialogs/forecolor_spec.js.coffee +37 -0
- data/spec/javascripts/mercury/dialogs/formatblock_spec.js.coffee +25 -0
- data/spec/javascripts/mercury/dialogs/snippetpanel_spec.js.coffee +30 -0
- data/spec/javascripts/mercury/dialogs/style_spec.js.coffee +25 -0
- data/spec/javascripts/mercury/history_buffer_spec.js.coffee +76 -0
- data/spec/javascripts/mercury/lightview_spec.js.coffee +497 -0
- data/spec/javascripts/mercury/mercury_spec.js.coffee +132 -0
- data/spec/javascripts/mercury/modal_spec.js.coffee +504 -0
- data/spec/javascripts/mercury/modals/htmleditor_spec.js.coffee +30 -0
- data/spec/javascripts/mercury/modals/insertcharacter_spec.js.coffee +29 -0
- data/spec/javascripts/mercury/modals/insertlink_spec.js.coffee +220 -0
- data/spec/javascripts/mercury/modals/insertmedia_spec.js.coffee +167 -0
- data/spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee +52 -0
- data/spec/javascripts/mercury/modals/inserttable_spec.js.coffee +160 -0
- data/spec/javascripts/mercury/native_extensions_spec.js.coffee +60 -0
- data/spec/javascripts/mercury/page_editor_spec.js.coffee +750 -0
- data/spec/javascripts/mercury/palette_spec.js.coffee +49 -0
- data/spec/javascripts/mercury/panel_spec.js.coffee +185 -0
- data/spec/javascripts/mercury/region_spec.js.coffee +298 -0
- data/spec/javascripts/mercury/regions/editable_spec.js.coffee +561 -0
- data/spec/javascripts/mercury/regions/markupable_spec.js.coffee +367 -0
- data/spec/javascripts/mercury/regions/snippetable_spec.js.coffee +370 -0
- data/spec/javascripts/mercury/select_spec.js.coffee +49 -0
- data/spec/javascripts/mercury/snippet_spec.js.coffee +245 -0
- data/spec/javascripts/mercury/snippet_toolbar_spec.js.coffee +184 -0
- data/spec/javascripts/mercury/statusbar_spec.js.coffee +150 -0
- data/spec/javascripts/mercury/table_editor_spec.js.coffee +194 -0
- data/spec/javascripts/mercury/toolbar.button_group_spec.js.coffee +90 -0
- data/spec/javascripts/mercury/toolbar.button_spec.js.coffee +360 -0
- data/spec/javascripts/mercury/toolbar.expander_spec.js.coffee +118 -0
- data/spec/javascripts/mercury/toolbar_spec.js.coffee +222 -0
- data/spec/javascripts/mercury/tooltip_spec.js.coffee +186 -0
- data/spec/javascripts/mercury/uploader_spec.js.coffee +514 -0
- data/spec/javascripts/spec_helper.js +513 -0
- data/spec/javascripts/templates/mercury/dialog.html +2 -0
- data/spec/javascripts/templates/mercury/dialogs/backcolor.html +5 -0
- data/spec/javascripts/templates/mercury/dialogs/forecolor.html +5 -0
- data/spec/javascripts/templates/mercury/dialogs/formatblock.html +3 -0
- data/spec/javascripts/templates/mercury/dialogs/snippetpanel.html +16 -0
- data/spec/javascripts/templates/mercury/dialogs/style.html +3 -0
- data/spec/javascripts/templates/mercury/lightview.html +13 -0
- data/spec/javascripts/templates/mercury/modal.html +13 -0
- data/spec/javascripts/templates/mercury/modals/htmleditor.html +5 -0
- data/spec/javascripts/templates/mercury/modals/insertcharacter.html +5 -0
- data/spec/javascripts/templates/mercury/modals/insertlink.html +30 -0
- data/spec/javascripts/templates/mercury/modals/insertmedia.html +35 -0
- data/spec/javascripts/templates/mercury/modals/insertsnippet.html +6 -0
- data/spec/javascripts/templates/mercury/modals/inserttable.html +27 -0
- data/spec/javascripts/templates/mercury/page_editor.html +35 -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/editable.html +3 -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 +8 -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 +11 -0
- data/spec/javascripts/templates/mercury/tooltip.html +12 -0
- data/spec/javascripts/templates/mercury/uploader.html +11 -0
- data/vendor/assets/images/mercury/button.png +0 -0
- data/vendor/assets/images/mercury/close.png +0 -0
- data/vendor/assets/images/mercury/default-snippet.png +0 -0
- data/vendor/assets/images/mercury/loading-dark.gif +0 -0
- data/vendor/assets/images/mercury/loading-light.gif +0 -0
- data/vendor/assets/images/mercury/missing-image.png +0 -0
- data/vendor/assets/images/mercury/search-icon.png +0 -0
- data/vendor/assets/images/mercury/temp-logo.png +0 -0
- data/vendor/assets/images/mercury/toolbar/editable/buttons.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/_expander.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/_pressed.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/historypanel.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/insertcharacter.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/insertlink.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/insertmedia.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/inserttable.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/inspectorpanel.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/notespanel.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/preview.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/redo.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/save.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/snippetpanel.png +0 -0
- data/vendor/assets/images/mercury/toolbar/primary/undo.png +0 -0
- data/vendor/assets/images/mercury/toolbar/snippetable/buttons.png +0 -0
- data/vendor/assets/javascripts/mercury/dependencies/jquery-1.7.js +9300 -0
- data/vendor/assets/javascripts/mercury/dependencies/jquery-ui-1.8.13.custom.js +1328 -0
- data/vendor/assets/javascripts/mercury/dependencies/jquery-ui-1.8.18.custom.min.js +356 -0
- data/vendor/assets/javascripts/mercury/dependencies/jquery-ui.1.8.13.custom.min.js +356 -0
- data/vendor/assets/javascripts/mercury/dependencies/jquery.additions.js +206 -0
- data/vendor/assets/javascripts/mercury/dependencies/jquery.htmlClean.js +527 -0
- data/vendor/assets/javascripts/mercury/dependencies/liquidmetal.js +88 -0
- data/vendor/assets/javascripts/mercury/dependencies/showdown.js +1340 -0
- data/vendor/assets/javascripts/mercury/dialog.js.coffee +159 -0
- data/vendor/assets/javascripts/mercury/dialogs/backcolor.js.coffee +6 -0
- data/vendor/assets/javascripts/mercury/dialogs/forecolor.js.coffee +6 -0
- data/vendor/assets/javascripts/mercury/dialogs/formatblock.js.coffee +4 -0
- data/vendor/assets/javascripts/mercury/dialogs/snippetpanel.js.coffee +10 -0
- data/vendor/assets/javascripts/mercury/dialogs/style.js.coffee +4 -0
- data/vendor/assets/javascripts/mercury/finalize.js.coffee +3 -0
- data/vendor/assets/javascripts/mercury/history_buffer.js.coffee +30 -0
- data/vendor/assets/javascripts/mercury/lightview.js.coffee +205 -0
- data/vendor/assets/javascripts/mercury/locales/da.locale.js.coffee +0 -0
- data/vendor/assets/javascripts/mercury/locales/de.locale.js.coffee +206 -0
- data/vendor/assets/javascripts/mercury/locales/es.locale.js.coffee +211 -0
- data/vendor/assets/javascripts/mercury/locales/example.local.js.coffee +211 -0
- data/vendor/assets/javascripts/mercury/locales/fr.locale.js.coffee +211 -0
- data/vendor/assets/javascripts/mercury/locales/it.locale.js.coffee +208 -0
- data/vendor/assets/javascripts/mercury/locales/ko.local.js.coffee +206 -0
- data/vendor/assets/javascripts/mercury/locales/nl.locale.js.coffee +206 -0
- data/vendor/assets/javascripts/mercury/locales/pt.locale.js.coffee +211 -0
- data/vendor/assets/javascripts/mercury/locales/sv.local.js.coffee +209 -0
- data/vendor/assets/javascripts/mercury/locales/swedish_chef.locale.js.coffee +213 -0
- data/vendor/assets/javascripts/mercury/mercury.js.coffee +109 -0
- data/vendor/assets/javascripts/mercury/modal.js.coffee +204 -0
- data/vendor/assets/javascripts/mercury/modals/htmleditor.js.coffee +11 -0
- data/vendor/assets/javascripts/mercury/modals/insertcharacter.js.coffee +4 -0
- data/vendor/assets/javascripts/mercury/modals/insertlink.js.coffee +95 -0
- data/vendor/assets/javascripts/mercury/modals/insertmedia.js.coffee +107 -0
- data/vendor/assets/javascripts/mercury/modals/insertsnippet.js.coffee +12 -0
- data/vendor/assets/javascripts/mercury/modals/inserttable.js.coffee +54 -0
- data/vendor/assets/javascripts/mercury/native_extensions.js.coffee +55 -0
- data/vendor/assets/javascripts/mercury/page_editor.js.coffee +241 -0
- data/vendor/assets/javascripts/mercury/palette.js.coffee +29 -0
- data/vendor/assets/javascripts/mercury/panel.js.coffee +115 -0
- data/vendor/assets/javascripts/mercury/plugins/save_as_xml/mercury/page_editor.js.coffee +28 -0
- data/vendor/assets/javascripts/mercury/plugins/save_as_xml/plugin.js +9 -0
- data/vendor/assets/javascripts/mercury/region.js.coffee +107 -0
- data/vendor/assets/javascripts/mercury/regions/editable.js.coffee +600 -0
- data/vendor/assets/javascripts/mercury/regions/markupable.js.coffee +398 -0
- data/vendor/assets/javascripts/mercury/regions/simple.js.coffee +339 -0
- data/vendor/assets/javascripts/mercury/regions/snippetable.js.coffee +124 -0
- data/vendor/assets/javascripts/mercury/select.js.coffee +44 -0
- data/vendor/assets/javascripts/mercury/snippet.js.coffee +104 -0
- data/vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee +72 -0
- data/vendor/assets/javascripts/mercury/statusbar.js.coffee +51 -0
- data/vendor/assets/javascripts/mercury/support/history.js +1 -0
- data/vendor/assets/javascripts/mercury/table_editor.js.coffee +265 -0
- data/vendor/assets/javascripts/mercury/toolbar.button.js.coffee +173 -0
- data/vendor/assets/javascripts/mercury/toolbar.button_group.js.coffee +42 -0
- data/vendor/assets/javascripts/mercury/toolbar.expander.js.coffee +56 -0
- data/vendor/assets/javascripts/mercury/toolbar.js.coffee +86 -0
- data/vendor/assets/javascripts/mercury/tooltip.js.coffee +74 -0
- data/vendor/assets/javascripts/mercury/uploader.js.coffee +227 -0
- data/vendor/assets/javascripts/mercury.js +479 -0
- data/vendor/assets/javascripts/mercury_loader.js +193 -0
- data/vendor/assets/javascripts/mercury_overrides.js +6 -0
- data/vendor/assets/javascripts/popup.js +8 -0
- data/vendor/assets/stylesheets/mercury/all_images.css.erb +89 -0
- data/vendor/assets/stylesheets/mercury/dialog.css +208 -0
- data/vendor/assets/stylesheets/mercury/lightview.css +151 -0
- data/vendor/assets/stylesheets/mercury/mercury.css +151 -0
- data/vendor/assets/stylesheets/mercury/modal.css +183 -0
- data/vendor/assets/stylesheets/mercury/statusbar.css +32 -0
- data/vendor/assets/stylesheets/mercury/toolbar.css +304 -0
- data/vendor/assets/stylesheets/mercury/tooltip.css +26 -0
- data/vendor/assets/stylesheets/mercury/uploader.css +111 -0
- data/vendor/assets/stylesheets/mercury.css +28 -0
- data/vendor/assets/stylesheets/mercury_overrides.css +17 -0
- data/vendor/assets/stylesheets/popup.css.erb +37 -0
- metadata +634 -0
@@ -0,0 +1,49 @@
|
|
1
|
+
describe "Mercury.Palette", ->
|
2
|
+
|
3
|
+
template 'mercury/palette.html'
|
4
|
+
|
5
|
+
beforeEach ->
|
6
|
+
$.fx.off = true
|
7
|
+
|
8
|
+
afterEach ->
|
9
|
+
@palette = null
|
10
|
+
delete(@palette)
|
11
|
+
|
12
|
+
describe "#build", ->
|
13
|
+
|
14
|
+
it "builds an element", ->
|
15
|
+
@palette = new Mercury.Palette('/blank.html', 'foo', {appendTo: '#test', for: $('#button')})
|
16
|
+
html = $('<div>').html(@palette.element).html()
|
17
|
+
expect(html).toContain('class="mercury-palette mercury-foo-palette loading"')
|
18
|
+
expect(html).toContain('style="display:none"')
|
19
|
+
|
20
|
+
it "appends to any element", ->
|
21
|
+
@palette = new Mercury.Palette('/blank.html', 'foo', {appendTo: '#palette_container', for: $('#button')})
|
22
|
+
expect($('#palette_container .mercury-palette').length).toEqual(1)
|
23
|
+
|
24
|
+
|
25
|
+
describe "observed events", ->
|
26
|
+
|
27
|
+
beforeEach ->
|
28
|
+
@palette = new Mercury.Palette('/blank.html', 'foo', {appendTo: '#test', for: $('#button')})
|
29
|
+
|
30
|
+
it "hides", ->
|
31
|
+
@palette.element.css({display: 'block'})
|
32
|
+
Mercury.trigger('hide:dialogs')
|
33
|
+
expect(@palette.element.css('display')).toEqual('none')
|
34
|
+
|
35
|
+
it "doesn't hide if it's the same dialog", ->
|
36
|
+
@palette.element.css({display: 'block'})
|
37
|
+
Mercury.trigger('hide:dialogs', @palette)
|
38
|
+
expect(@palette.element.css('display')).toEqual('block')
|
39
|
+
|
40
|
+
|
41
|
+
describe "#position", ->
|
42
|
+
|
43
|
+
beforeEach ->
|
44
|
+
@palette = new Mercury.Palette('/blank.html', 'foo', {appendTo: '#test', for: $('#button')})
|
45
|
+
|
46
|
+
it "positions based on it's button", ->
|
47
|
+
@palette.element.css({display: 'block'})
|
48
|
+
@palette.position(true)
|
49
|
+
expect(@palette.element.offset()).toEqual({top: 62, left: 42})
|
@@ -0,0 +1,185 @@
|
|
1
|
+
describe "Mercury.Panel", ->
|
2
|
+
|
3
|
+
template 'mercury/panel.html'
|
4
|
+
|
5
|
+
beforeEach ->
|
6
|
+
Mercury.displayRect = {top: 20, left: 20, width: 200, height: 200}
|
7
|
+
$.fx.off = true
|
8
|
+
Mercury.determinedLocale =
|
9
|
+
top: {'hello world!': 'bork! bork!'}
|
10
|
+
sub: {'foo': 'Bork!'}
|
11
|
+
|
12
|
+
afterEach ->
|
13
|
+
Mercury.config.localization.enabled = false
|
14
|
+
delete(@panel)
|
15
|
+
$(window).unbind('mercury:resize')
|
16
|
+
$(window).unbind('mercury:hide:panels')
|
17
|
+
|
18
|
+
describe "#build", ->
|
19
|
+
|
20
|
+
it "builds an element", ->
|
21
|
+
@panel = new Mercury.Panel('/evergreen/resources/panel.html', 'foo', {appendTo: '#test', title: 'foo panel'})
|
22
|
+
html = $('<div>').html(@panel.element).html()
|
23
|
+
expect(html).toContain('class="mercury-panel loading"')
|
24
|
+
expect(html).toContain('style="display:none;"')
|
25
|
+
expect(html).toContain('<h1>foo panel</h1><div class="mercury-panel-pane"></div>')
|
26
|
+
expect(html).not.toContain('class="mercury-panel-close"')
|
27
|
+
|
28
|
+
it "appends to any element", ->
|
29
|
+
@panel = new Mercury.Panel('/evergreen/resources/panel.html', 'foo', {appendTo: '#panel_container', title: 'foo panel'})
|
30
|
+
expect($('#panel_container .mercury-panel').length).toEqual(1)
|
31
|
+
|
32
|
+
it "creates a close button if it should", ->
|
33
|
+
@panel = new Mercury.Panel('/evergreen/resources/panel.html', 'foo', {appendTo: '#test', title: 'foo panel', closeButton: true})
|
34
|
+
html = $('<div>').html(@panel.element).html()
|
35
|
+
expect(html).toContain('class="mercury-panel-close"')
|
36
|
+
expect(@panel.element.find('.mercury-panel-close').css('opacity')).toEqual('0')
|
37
|
+
|
38
|
+
|
39
|
+
describe "observed events", ->
|
40
|
+
|
41
|
+
beforeEach ->
|
42
|
+
@panel = new Mercury.Panel('/evergreen/resources/panel.html', 'foo', {appendTo: '#test', title: 'foo panel', for: $('#button'), closeButton: true})
|
43
|
+
|
44
|
+
describe "custom event: resize", ->
|
45
|
+
|
46
|
+
it "calls position", ->
|
47
|
+
spy = spyOn(Mercury.Panel.prototype, 'position').andCallFake(=>)
|
48
|
+
Mercury.trigger('resize')
|
49
|
+
expect(spy.callCount).toEqual(1)
|
50
|
+
|
51
|
+
describe "custom event: hide:panels", ->
|
52
|
+
|
53
|
+
it "hides", ->
|
54
|
+
@panel.element.css({display: 'block'})
|
55
|
+
Mercury.trigger('hide:panels')
|
56
|
+
expect(@panel.element.css('display')).toEqual('none')
|
57
|
+
|
58
|
+
it "doesn't hide if it's the same dialog", ->
|
59
|
+
@panel.element.css({display: 'block'})
|
60
|
+
Mercury.trigger('hide:panels', @panel)
|
61
|
+
expect(@panel.element.css('display')).toEqual('block')
|
62
|
+
|
63
|
+
describe "ajax:beforeSend", ->
|
64
|
+
|
65
|
+
it "sets a success that will load the contents of the response", ->
|
66
|
+
options = {}
|
67
|
+
loadContentSpy = spyOn(Mercury.Panel.prototype, 'loadContent').andCallFake(=>)
|
68
|
+
resizeSpy = spyOn(Mercury.Panel.prototype, 'resize').andCallFake(=>)
|
69
|
+
@panel.element.trigger('ajax:beforeSend', [null, options])
|
70
|
+
expect(options.success).toBeDefined()
|
71
|
+
options.success('new content')
|
72
|
+
expect(loadContentSpy.callCount).toEqual(1)
|
73
|
+
expect(loadContentSpy.argsForCall[0]).toEqual(['new content'])
|
74
|
+
expect(resizeSpy.callCount).toEqual(1)
|
75
|
+
|
76
|
+
describe "clicking on the close button", ->
|
77
|
+
|
78
|
+
it "calls hide:panels", ->
|
79
|
+
spy = spyOn(Mercury, 'trigger').andCallFake(=>)
|
80
|
+
jasmine.simulate.click(@panel.element.find('.mercury-panel-close').get(0))
|
81
|
+
expect(spy.callCount).toEqual(1)
|
82
|
+
expect(spy.argsForCall[0]).toEqual(['hide:panels'])
|
83
|
+
|
84
|
+
|
85
|
+
describe "#show", ->
|
86
|
+
|
87
|
+
beforeEach ->
|
88
|
+
@panel = new Mercury.Panel('/evergreen/resources/panel.html', 'foo', {appendTo: '#test', title: 'foo panel'})
|
89
|
+
|
90
|
+
it "hides other panels and dialogs", ->
|
91
|
+
spyOn(Mercury.Panel.prototype, 'position')
|
92
|
+
spyOn(Mercury.Panel.prototype, 'appear')
|
93
|
+
spy = spyOn(Mercury, 'trigger').andCallFake(=>)
|
94
|
+
@panel.show()
|
95
|
+
expect(spy.callCount).toEqual(2)
|
96
|
+
expect(spy.argsForCall[0]).toEqual(['hide:panels', @panel])
|
97
|
+
expect(spy.argsForCall[1]).toEqual(['hide:dialogs', @panel])
|
98
|
+
|
99
|
+
|
100
|
+
describe "#resize", ->
|
101
|
+
|
102
|
+
beforeEach ->
|
103
|
+
@panel = new Mercury.Panel('/evergreen/resources/panel.html', 'foo', {appendTo: '#panel_container', title: 'foo panel'})
|
104
|
+
@panel.element.css({display: 'block'})
|
105
|
+
@panel.visible = true
|
106
|
+
|
107
|
+
it "figures out what size it should be and resizes", ->
|
108
|
+
@panel.resize()
|
109
|
+
expect(@panel.element.offset()).toEqual({top: 42, left: 84})
|
110
|
+
expect(@panel.element.css('display')).toEqual('block')
|
111
|
+
|
112
|
+
it "calls makeDraggable", ->
|
113
|
+
spy = spyOn(Mercury.Panel.prototype, 'makeDraggable').andCallFake(=>)
|
114
|
+
@panel.resize()
|
115
|
+
expect(spy.callCount).toEqual(1)
|
116
|
+
|
117
|
+
it "keeps it hidden if it's not supposed to be visible", ->
|
118
|
+
@panel.visible = false
|
119
|
+
@panel.resize()
|
120
|
+
expect(@panel.element.css('display')).toEqual('none')
|
121
|
+
|
122
|
+
|
123
|
+
describe "#position", ->
|
124
|
+
|
125
|
+
beforeEach ->
|
126
|
+
@panel = new Mercury.Panel('/evergreen/resources/panel.html', 'foo', {appendTo: '#panel_container', title: 'foo panel'})
|
127
|
+
@panel.element.css({display: 'block'})
|
128
|
+
@panel.visible = true
|
129
|
+
|
130
|
+
it "positions based on the display rectangle", ->
|
131
|
+
@panel.position(true)
|
132
|
+
expect(@panel.element.offset()).toEqual({top: 70, left: 122})
|
133
|
+
expect(@panel.element.css('display')).toEqual('block')
|
134
|
+
|
135
|
+
it "calls makeDraggable", ->
|
136
|
+
spy = spyOn(Mercury.Panel.prototype, 'makeDraggable').andCallFake(=>)
|
137
|
+
@panel.position()
|
138
|
+
expect(spy.callCount).toEqual(1)
|
139
|
+
|
140
|
+
it "keeps it hidden if it's not supposed to be visible", ->
|
141
|
+
@panel.visible = false
|
142
|
+
@panel.position()
|
143
|
+
expect(@panel.element.css('display')).toEqual('none')
|
144
|
+
|
145
|
+
|
146
|
+
describe "#loadContent", ->
|
147
|
+
|
148
|
+
beforeEach ->
|
149
|
+
@panel = new Mercury.Panel('/evergreen/resources/panel.html', 'foo', {appendTo: '#test', title: 'foo panel'})
|
150
|
+
|
151
|
+
it "sets loaded to be true", ->
|
152
|
+
@panel.loadContent()
|
153
|
+
expect(@panel.loaded).toEqual(true)
|
154
|
+
|
155
|
+
it "removes the loading class from the element", ->
|
156
|
+
@panel.loadContent()
|
157
|
+
expect(@panel.element.hasClass('loading')).toEqual(false)
|
158
|
+
|
159
|
+
it "sets the element html to be the data passed to it", ->
|
160
|
+
@panel.loadContent('<span>hello world!</span>')
|
161
|
+
html = @panel.element.html()
|
162
|
+
expect(html).toContain('<h1>foo panel</h1>')
|
163
|
+
expect(html).toContain('class="mercury-panel-pane"')
|
164
|
+
expect(html).toContain('style="visibility: hidden;')
|
165
|
+
expect(html).toContain('hello world!')
|
166
|
+
|
167
|
+
it "sets the element html to be the data passed to it", ->
|
168
|
+
Mercury.config.localization.enabled = true
|
169
|
+
@panel.loadContent('<span>hello world!</span>')
|
170
|
+
html = @panel.element.html()
|
171
|
+
expect(html).toContain('<h1>foo panel</h1>')
|
172
|
+
expect(html).toContain('class="mercury-panel-pane"')
|
173
|
+
expect(html).toContain('style="visibility: hidden;')
|
174
|
+
expect(html).toContain('bork! bork!')
|
175
|
+
|
176
|
+
|
177
|
+
describe "#makesDraggable", ->
|
178
|
+
|
179
|
+
beforeEach ->
|
180
|
+
@panel = new Mercury.Panel('/evergreen/resources/panel.html', 'foo', {appendTo: '#test', title: 'foo panel'})
|
181
|
+
|
182
|
+
it "makes the element draggable", ->
|
183
|
+
spy = spyOn($.fn, 'draggable').andCallFake(=>)
|
184
|
+
@panel.makeDraggable()
|
185
|
+
expect(spy.callCount).toEqual(1)
|
@@ -0,0 +1,298 @@
|
|
1
|
+
describe "Mercury.Region", ->
|
2
|
+
|
3
|
+
template 'mercury/region.html'
|
4
|
+
|
5
|
+
beforeEach ->
|
6
|
+
Mercury.config.regions.className = 'custom-region-class'
|
7
|
+
Mercury.config.regions.dataAttributes = []
|
8
|
+
|
9
|
+
afterEach ->
|
10
|
+
@region = null
|
11
|
+
delete(@region)
|
12
|
+
$(window).unbind('mercury:mode')
|
13
|
+
$(window).unbind('mercury:focus:frame')
|
14
|
+
$(window).unbind('mercury:action')
|
15
|
+
|
16
|
+
describe "constructor", ->
|
17
|
+
|
18
|
+
beforeEach ->
|
19
|
+
@buildSpy = spyOn(Mercury.Region.prototype, 'build').andCallFake(=>)
|
20
|
+
@bindEventsSpy = spyOn(Mercury.Region.prototype, 'bindEvents').andCallFake(=>)
|
21
|
+
@pushHistorySpy = spyOn(Mercury.Region.prototype, 'pushHistory').andCallFake(=>)
|
22
|
+
|
23
|
+
it "expects an element and window (for context)", ->
|
24
|
+
@region = new Mercury.Region($('#region'), window)
|
25
|
+
expect(@region.element.get(0)).toEqual($('#region').get(0))
|
26
|
+
|
27
|
+
it "accepts options", ->
|
28
|
+
@region = new Mercury.Region($('#region'), window, {foo: 'bar'})
|
29
|
+
expect(@region.options).toEqual({foo: 'bar'})
|
30
|
+
|
31
|
+
it "sets variables we need", ->
|
32
|
+
@region = new Mercury.Region($('#region'), window, {foo: 'bar'})
|
33
|
+
expect(@region.name).toEqual('region')
|
34
|
+
expect(@region.history).toBeDefined()
|
35
|
+
|
36
|
+
it "sets name based on configuration", ->
|
37
|
+
Mercury.config.regions.identifier = 'data-scope'
|
38
|
+
@region = new Mercury.Region($('#region'), window, {foo: 'bar'})
|
39
|
+
expect(@region.name).toEqual('scope')
|
40
|
+
|
41
|
+
it "calls build", ->
|
42
|
+
@region = new Mercury.Region($('#region'), window, {foo: 'bar'})
|
43
|
+
expect(@buildSpy.callCount).toEqual(1)
|
44
|
+
|
45
|
+
it "calls bindEvents", ->
|
46
|
+
@region = new Mercury.Region($('#region'), window, {foo: 'bar'})
|
47
|
+
expect(@bindEventsSpy.callCount).toEqual(1)
|
48
|
+
|
49
|
+
it "pushes the initial state to the history buffer", ->
|
50
|
+
@region = new Mercury.Region($('#region'), window, {foo: 'bar'})
|
51
|
+
expect(@pushHistorySpy.callCount).toEqual(1)
|
52
|
+
|
53
|
+
it "sets the instance of the region into data for the element", ->
|
54
|
+
@region = new Mercury.Region($('#region'), window, {foo: 'bar'})
|
55
|
+
expect(@region.element.data('region')).toEqual(@region)
|
56
|
+
|
57
|
+
|
58
|
+
describe "#build", ->
|
59
|
+
|
60
|
+
it "does nothing and is there as an interface"
|
61
|
+
|
62
|
+
|
63
|
+
describe "#focus", ->
|
64
|
+
|
65
|
+
it "does nothing and is there as an interface"
|
66
|
+
|
67
|
+
|
68
|
+
describe "observed events", ->
|
69
|
+
|
70
|
+
beforeEach ->
|
71
|
+
@region = new Mercury.Region($('#region_with_snippet'), window)
|
72
|
+
|
73
|
+
describe "custom event: mode", ->
|
74
|
+
|
75
|
+
it "calls togglePreview if the mode is preview", ->
|
76
|
+
spy = spyOn(Mercury.Region.prototype, 'togglePreview').andCallFake(=>)
|
77
|
+
Mercury.trigger('mode', {mode: 'foo'})
|
78
|
+
expect(spy.callCount).toEqual(0)
|
79
|
+
Mercury.trigger('mode', {mode: 'preview'})
|
80
|
+
expect(spy.callCount).toEqual(1)
|
81
|
+
|
82
|
+
describe "custom event: focus:frame", ->
|
83
|
+
|
84
|
+
beforeEach ->
|
85
|
+
@focusSpy = spyOn(Mercury.Region.prototype, 'focus').andCallFake(=>)
|
86
|
+
|
87
|
+
it "does nothing if in preview mode", ->
|
88
|
+
@region.previewing = true
|
89
|
+
Mercury.trigger('focus:frame', {region: @region})
|
90
|
+
expect(@focusSpy.callCount).toEqual(0)
|
91
|
+
|
92
|
+
it "does nothing if it's not active region", ->
|
93
|
+
Mercury.region = {}
|
94
|
+
Mercury.trigger('focus:frame', {region: @region})
|
95
|
+
expect(@focusSpy.callCount).toEqual(0)
|
96
|
+
|
97
|
+
it "calls focus", ->
|
98
|
+
Mercury.region = @region
|
99
|
+
Mercury.trigger('focus:frame', {region: @region})
|
100
|
+
expect(@focusSpy.callCount).toEqual(1)
|
101
|
+
|
102
|
+
describe "custom event: action", ->
|
103
|
+
|
104
|
+
beforeEach ->
|
105
|
+
@execCommandSpy = spyOn(Mercury.Region.prototype, 'execCommand').andCallFake(=>)
|
106
|
+
|
107
|
+
it "does nothing if in preview mode", ->
|
108
|
+
@region.previewing = true
|
109
|
+
Mercury.trigger('action', {action: 'foo', value: 'bar'})
|
110
|
+
expect(@execCommandSpy.callCount).toEqual(0)
|
111
|
+
|
112
|
+
it "does nothing if it's not active region", ->
|
113
|
+
Mercury.region = {}
|
114
|
+
Mercury.trigger('action', {action: 'foo', value: 'bar'})
|
115
|
+
expect(@execCommandSpy.callCount).toEqual(0)
|
116
|
+
|
117
|
+
it "calls execCommand with the action and options", ->
|
118
|
+
Mercury.region = @region
|
119
|
+
Mercury.trigger('action', {action: 'foo', value: 'bar'})
|
120
|
+
expect(@execCommandSpy.callCount).toEqual(1)
|
121
|
+
expect(@execCommandSpy.argsForCall[0]).toEqual(['foo', {action: 'foo', value: 'bar'}])
|
122
|
+
|
123
|
+
describe "mouseover", ->
|
124
|
+
|
125
|
+
beforeEach ->
|
126
|
+
@triggerSpy = spyOn(Mercury, 'trigger').andCallFake(=>)
|
127
|
+
|
128
|
+
it "does nothing if in preview mode", ->
|
129
|
+
@region.previewing = true
|
130
|
+
jasmine.simulate.mousemove($('#region_with_snippet .mercury-snippet').get(0))
|
131
|
+
expect(@triggerSpy.callCount).toEqual(0)
|
132
|
+
|
133
|
+
it "does nothing if it's not the active region", ->
|
134
|
+
Mercury.region = {}
|
135
|
+
jasmine.simulate.mousemove($('#region_with_snippet .mercury-snippet').get(0))
|
136
|
+
expect(@triggerSpy.callCount).toEqual(0)
|
137
|
+
|
138
|
+
it "shows the snippet toolbar if a snippet was moused over", ->
|
139
|
+
Mercury.region = @region
|
140
|
+
jasmine.simulate.mousemove($('#region_with_snippet .mercury-snippet').get(0))
|
141
|
+
expect(@triggerSpy.callCount).toEqual(1)
|
142
|
+
expect(@triggerSpy.argsForCall[0][0]).toEqual('show:toolbar')
|
143
|
+
|
144
|
+
describe "mouseout", ->
|
145
|
+
|
146
|
+
beforeEach ->
|
147
|
+
@triggerSpy = spyOn(Mercury, 'trigger').andCallFake(=>)
|
148
|
+
|
149
|
+
it "does nothing if previewing", ->
|
150
|
+
@region.previewing = true
|
151
|
+
jasmine.simulate.mouseout(@region.element.get(0))
|
152
|
+
expect(@triggerSpy.callCount).toEqual(0)
|
153
|
+
|
154
|
+
it "hides the snippet toolbar", ->
|
155
|
+
jasmine.simulate.mouseout(@region.element.get(0))
|
156
|
+
expect(@triggerSpy.callCount).toEqual(1)
|
157
|
+
expect(@triggerSpy.argsForCall[0]).toEqual(['hide:toolbar', {type: 'snippet', immediately: false}])
|
158
|
+
|
159
|
+
|
160
|
+
describe "#html", ->
|
161
|
+
|
162
|
+
beforeEach ->
|
163
|
+
@region = new Mercury.Region($('#region_with_snippet'), window)
|
164
|
+
|
165
|
+
describe "getting html", ->
|
166
|
+
|
167
|
+
it "returns the html of the element", ->
|
168
|
+
content = @region.content()
|
169
|
+
expect(content).toEqual('contents<div class="mercury-snippet" data-snippet="snippet_1" data-version="1">snippet</div>')
|
170
|
+
|
171
|
+
it "replaces snippet content with an indentifier if asked", ->
|
172
|
+
content = @region.content(null, true)
|
173
|
+
expect(content).toEqual('contents<div class="mercury-snippet" data-snippet="snippet_1">[snippet_1]</div>')
|
174
|
+
|
175
|
+
describe "setting html", ->
|
176
|
+
|
177
|
+
it "sets the value of the html", ->
|
178
|
+
@region.content('new html')
|
179
|
+
expect($('#region_with_snippet').html()).toEqual('new html')
|
180
|
+
|
181
|
+
|
182
|
+
describe "#togglePreview", ->
|
183
|
+
|
184
|
+
beforeEach ->
|
185
|
+
@region = new Mercury.Region($('#region'), window)
|
186
|
+
Mercury.region = @region
|
187
|
+
@focusSpy = spyOn(Mercury.Region.prototype, 'focus').andCallFake(=>)
|
188
|
+
@triggerSpy = spyOn(Mercury, 'trigger').andCallFake(=>)
|
189
|
+
|
190
|
+
describe "when not previewing", ->
|
191
|
+
|
192
|
+
beforeEach ->
|
193
|
+
@region.togglePreview()
|
194
|
+
|
195
|
+
it "sets previewing to true", ->
|
196
|
+
expect(@region.previewing).toEqual(true)
|
197
|
+
|
198
|
+
it "swaps classes on the element", ->
|
199
|
+
expect(@region.element.hasClass('custom-region-class')).toEqual(false)
|
200
|
+
expect(@region.element.hasClass('custom-region-class-preview')).toEqual(true)
|
201
|
+
|
202
|
+
it "triggers a blur event", ->
|
203
|
+
expect(@triggerSpy.callCount).toEqual(1)
|
204
|
+
expect(@triggerSpy.argsForCall[0]).toEqual(['region:blurred', {region: @region}])
|
205
|
+
|
206
|
+
describe "when previewing", ->
|
207
|
+
|
208
|
+
beforeEach ->
|
209
|
+
@region.previewing = true
|
210
|
+
@region.togglePreview()
|
211
|
+
|
212
|
+
it "sets previewing to false", ->
|
213
|
+
expect(@region.previewing).toEqual(false)
|
214
|
+
|
215
|
+
it "swaps classes on the element", ->
|
216
|
+
expect(@region.element.hasClass('custom-region-class-preview')).toEqual(false)
|
217
|
+
expect(@region.element.hasClass('custom-region-class')).toEqual(true)
|
218
|
+
|
219
|
+
it "calls focus if it's the active region", ->
|
220
|
+
expect(@focusSpy.callCount).toEqual(1)
|
221
|
+
|
222
|
+
|
223
|
+
describe "#execCommand", ->
|
224
|
+
|
225
|
+
beforeEach ->
|
226
|
+
Mercury.changes = false
|
227
|
+
@region = new Mercury.Region($('#region'), window)
|
228
|
+
|
229
|
+
it "calls focus", ->
|
230
|
+
spy = spyOn(Mercury.Region.prototype, 'focus').andCallFake(=>)
|
231
|
+
@region.execCommand('foo')
|
232
|
+
expect(spy.callCount).toEqual(1)
|
233
|
+
|
234
|
+
it "pushes to the history (unless the action is redo)", ->
|
235
|
+
spy = spyOn(Mercury.Region.prototype, 'pushHistory').andCallFake(=>)
|
236
|
+
@region.execCommand('redo')
|
237
|
+
expect(spy.callCount).toEqual(0)
|
238
|
+
@region.execCommand('foo')
|
239
|
+
expect(spy.callCount).toEqual(1)
|
240
|
+
|
241
|
+
it "tells Mercury that changes have been made", ->
|
242
|
+
@region.execCommand('foo')
|
243
|
+
expect(Mercury.changes).toEqual(true)
|
244
|
+
|
245
|
+
|
246
|
+
describe "#pushHistory", ->
|
247
|
+
|
248
|
+
beforeEach ->
|
249
|
+
Mercury.changes = false
|
250
|
+
@region = new Mercury.Region($('#region'), window)
|
251
|
+
|
252
|
+
it "pushes the current content (html) of the region to the history buffer", ->
|
253
|
+
spy = spyOn(@region.history, 'push').andCallFake(=>)
|
254
|
+
@region.pushHistory('foo')
|
255
|
+
expect(spy.callCount).toEqual(1)
|
256
|
+
|
257
|
+
|
258
|
+
describe "#snippets", ->
|
259
|
+
|
260
|
+
it "does nothing and is there as an interface", ->
|
261
|
+
|
262
|
+
|
263
|
+
describe "#dataAttributes", ->
|
264
|
+
|
265
|
+
beforeEach ->
|
266
|
+
Mercury.config.regions.dataAttributes = ['scope', 'version']
|
267
|
+
@region = new Mercury.Region($('#region'), window)
|
268
|
+
|
269
|
+
it "returns an object of data attributes based on configuration", ->
|
270
|
+
@region.element.attr('data-version', 2)
|
271
|
+
expect(@region.dataAttributes()).toEqual({scope: 'scope', version: '2'})
|
272
|
+
|
273
|
+
|
274
|
+
describe "#serialize", ->
|
275
|
+
|
276
|
+
beforeEach ->
|
277
|
+
@region = new Mercury.Region($('#region'), window)
|
278
|
+
|
279
|
+
describe "without data attributes configured", ->
|
280
|
+
|
281
|
+
it "returns an object with it's type, value, and snippets", ->
|
282
|
+
serialized = @region.serialize()
|
283
|
+
expect(serialized.type).toEqual('region')
|
284
|
+
expect(serialized.value).toEqual('contents')
|
285
|
+
expect(serialized.snippets).toEqual({})
|
286
|
+
expect(serialized.data).toEqual({})
|
287
|
+
|
288
|
+
describe "with data attributes configured", ->
|
289
|
+
|
290
|
+
beforeEach ->
|
291
|
+
Mercury.config.regions.dataAttributes = ['scope', 'version']
|
292
|
+
|
293
|
+
it "returns an object with it's type, value, data and snippets", ->
|
294
|
+
serialized = @region.serialize()
|
295
|
+
expect(serialized.type).toEqual('region')
|
296
|
+
expect(serialized.value).toEqual('contents')
|
297
|
+
expect(serialized.snippets).toEqual({})
|
298
|
+
expect(serialized.data).toEqual({scope: 'scope', version: '1'})
|