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,360 @@
|
|
1
|
+
describe "Mercury.Toolbar.Button", ->
|
2
|
+
|
3
|
+
template 'mercury/toolbar.button.html'
|
4
|
+
|
5
|
+
beforeEach ->
|
6
|
+
Mercury.displayRect = {0, 0, 500, 200}
|
7
|
+
Mercury.Toolbar.Button.contexts.foo = -> true
|
8
|
+
@region = {
|
9
|
+
type: 'editable'
|
10
|
+
element: $('<div class="mercury-region">')
|
11
|
+
currentElement: -> $('<div>')
|
12
|
+
}
|
13
|
+
Mercury.preloadedViews['/nothing'] = 'nothing'
|
14
|
+
|
15
|
+
afterEach ->
|
16
|
+
@button = null
|
17
|
+
delete(@button)
|
18
|
+
$(document).unbind('mercury:region:update')
|
19
|
+
$(document).unbind('mercury:button')
|
20
|
+
|
21
|
+
describe "constructor", ->
|
22
|
+
|
23
|
+
it "expects name and title values", ->
|
24
|
+
@button = new Mercury.Toolbar.Button('foo', 'title')
|
25
|
+
html = $('<div>').html(@button).html()
|
26
|
+
expect(html).toContain('title="title"')
|
27
|
+
expect(html).toContain('class="mercury-button mercury-foo-button"')
|
28
|
+
expect(html).toContain('<em>title</em>')
|
29
|
+
|
30
|
+
it "accepts summary, types and options", ->
|
31
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {palette: '/nothing'}, {appendDialogsTo: $('#test')})
|
32
|
+
html = $('<div>').html(@button).html()
|
33
|
+
expect(html).toContain('title="summary"')
|
34
|
+
expect(html).toContain('class="mercury-button mercury-foo-button mercury-button-palette"')
|
35
|
+
expect(html).toContain('<em>title</em>')
|
36
|
+
|
37
|
+
it "calls build", ->
|
38
|
+
spy = spyOn(Mercury.Toolbar.Button.prototype, 'build').andCallFake(=>)
|
39
|
+
spyOn(Mercury.Toolbar.Button.prototype, 'bindEvents').andCallFake(=>)
|
40
|
+
@button = new Mercury.Toolbar.Button('foo', 'title')
|
41
|
+
expect(spy.callCount).toEqual(1)
|
42
|
+
|
43
|
+
it "calls bindEvents", ->
|
44
|
+
spyOn(Mercury.Toolbar.Button.prototype, 'build').andCallFake(=>)
|
45
|
+
spy = spyOn(Mercury.Toolbar.Button.prototype, 'bindEvents').andCallFake(=>)
|
46
|
+
@button = new Mercury.Toolbar.Button('foo', 'title')
|
47
|
+
expect(spy.callCount).toEqual(1)
|
48
|
+
|
49
|
+
|
50
|
+
describe "#build for various button types", ->
|
51
|
+
|
52
|
+
it "attaches an element meant for the expander in button data", ->
|
53
|
+
@button = new Mercury.Toolbar.Button('foo', 'title')
|
54
|
+
expect(@button.data('expander')).toEqual('<div class="mercury-expander-button" data-button="foo"><em></em><span>title</span></div>')
|
55
|
+
|
56
|
+
it "builds toggle buttons, that when clicked toggle their state", ->
|
57
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {toggle: true})
|
58
|
+
|
59
|
+
jasmine.simulate.click(@button.get(0))
|
60
|
+
expect(@button.hasClass('pressed')).toEqual(true)
|
61
|
+
|
62
|
+
jasmine.simulate.click(@button.get(0))
|
63
|
+
expect(@button.hasClass('pressed')).toEqual(false)
|
64
|
+
|
65
|
+
it "builds mode buttons, that when clicked fire a mode event", ->
|
66
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {mode: true})
|
67
|
+
spy = spyOn(Mercury, 'trigger').andCallFake(=>)
|
68
|
+
|
69
|
+
jasmine.simulate.click(@button.get(0))
|
70
|
+
expect(spy.callCount).toEqual(1)
|
71
|
+
expect(spy.argsForCall[0]).toEqual(['mode', {mode: 'foo'}])
|
72
|
+
|
73
|
+
it "builds buttons that understand context", ->
|
74
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {context: true})
|
75
|
+
|
76
|
+
expect(@button.hasClass('active')).toEqual(false)
|
77
|
+
Mercury.trigger('region:update', {region: @region})
|
78
|
+
expect(@button.hasClass('active')).toEqual(true)
|
79
|
+
|
80
|
+
it "builds panel buttons (and assigns toggle)", ->
|
81
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {panel: '/blank.html'}, {appendDialogsTo: $('#test')})
|
82
|
+
expect($('#test .mercury-panel').length).toEqual(1)
|
83
|
+
|
84
|
+
jasmine.simulate.click(@button.get(0))
|
85
|
+
expect(@button.hasClass('pressed')).toEqual(true)
|
86
|
+
|
87
|
+
jasmine.simulate.click(@button.get(0))
|
88
|
+
expect(@button.hasClass('pressed')).toEqual(false)
|
89
|
+
|
90
|
+
it "builds palette buttons", ->
|
91
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {palette: '/blank.html'}, {appendDialogsTo: $('#test')})
|
92
|
+
expect($('#test .mercury-palette').length).toEqual(1)
|
93
|
+
|
94
|
+
it "builds select buttons", ->
|
95
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {select: '/blank.html'}, {appendDialogsTo: $('#test')})
|
96
|
+
expect($('#test .mercury-select').length).toEqual(1)
|
97
|
+
|
98
|
+
it "builds modal buttons", ->
|
99
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {modal: '/blank.html'}, {appendDialogsTo: $('#test')})
|
100
|
+
# nothing unique about this in building -- the modal is built/fired on click
|
101
|
+
|
102
|
+
it "builds lightview buttons", ->
|
103
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {lightview: '/blank.html'}, {appendDialogsTo: $('#test')})
|
104
|
+
# nothing unique about this in building -- the lightview is built/fired on click
|
105
|
+
|
106
|
+
it "throws an error when an unknown type is encountered", ->
|
107
|
+
expect(=>
|
108
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {foo: '/blank.html'})
|
109
|
+
).toThrow('Unknown button type "foo" used for the "foo" button.')
|
110
|
+
|
111
|
+
|
112
|
+
describe "observed events", ->
|
113
|
+
|
114
|
+
describe "custom event: button", ->
|
115
|
+
|
116
|
+
it "calls click on the button itself", ->
|
117
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {context: true})
|
118
|
+
spy = spyOn(@button, 'click').andCallFake(=>)
|
119
|
+
|
120
|
+
Mercury.trigger('button', {action: 'foo'})
|
121
|
+
expect(spy.callCount).toEqual(1)
|
122
|
+
|
123
|
+
describe "custom event: mode", ->
|
124
|
+
|
125
|
+
it "toggles a button when that mode is triggered and the button is toggleable", ->
|
126
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {mode: 'preview', toggle: true})
|
127
|
+
spy = spyOn(Mercury.Toolbar.Button.prototype, 'togglePressed').andCallFake(=>)
|
128
|
+
|
129
|
+
Mercury.trigger('mode', {mode: 'preview'})
|
130
|
+
expect(spy.callCount).toEqual(1)
|
131
|
+
|
132
|
+
describe "custom event: region:update", ->
|
133
|
+
|
134
|
+
it "calls contexts if one is available and set", ->
|
135
|
+
contextSpy = spyOn(Mercury.Toolbar.Button.contexts, 'foo').andCallFake(-> true)
|
136
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {context: true})
|
137
|
+
|
138
|
+
expect(@button.hasClass('active')).toEqual(false)
|
139
|
+
|
140
|
+
Mercury.trigger('region:update', {region: @region})
|
141
|
+
expect(contextSpy.callCount).toEqual(1)
|
142
|
+
expect(@button.hasClass('active')).toEqual(true)
|
143
|
+
|
144
|
+
describe "custom event: region:focused", ->
|
145
|
+
|
146
|
+
it "disables if the region type isn't supported", ->
|
147
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {context: true, regions: ['foo']})
|
148
|
+
@button.removeClass('disabled')
|
149
|
+
Mercury.trigger('region:focused', {region: @region})
|
150
|
+
expect(@button.hasClass('disabled')).toEqual(true)
|
151
|
+
|
152
|
+
it "enables if the region type is supported", ->
|
153
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {context: true, regions: ['editable']})
|
154
|
+
@button.addClass('disabled')
|
155
|
+
Mercury.trigger('region:focused', {region: @region})
|
156
|
+
expect(@button.hasClass('disabled')).toEqual(false)
|
157
|
+
|
158
|
+
describe "custom event: region:blurred", ->
|
159
|
+
|
160
|
+
it "disables if it's a button for specific region types", ->
|
161
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {context: true, regions: ['editable']})
|
162
|
+
@button.addClass('disabled')
|
163
|
+
Mercury.trigger('region:blurred', {region: @region})
|
164
|
+
expect(@button.hasClass('disabled')).toEqual(true)
|
165
|
+
|
166
|
+
describe "mousedown", ->
|
167
|
+
|
168
|
+
it "sets the active state", ->
|
169
|
+
@button = new Mercury.Toolbar.Button('foo', 'title')
|
170
|
+
|
171
|
+
expect(@button.hasClass('active')).toEqual(false)
|
172
|
+
jasmine.simulate.mousedown(@button.get(0))
|
173
|
+
expect(@button.hasClass('active')).toEqual(true)
|
174
|
+
|
175
|
+
describe "mouseup", ->
|
176
|
+
|
177
|
+
it "removes the active state", ->
|
178
|
+
@button = new Mercury.Toolbar.Button('foo', 'title')
|
179
|
+
@button.addClass('active')
|
180
|
+
|
181
|
+
jasmine.simulate.mouseup(@button.get(0))
|
182
|
+
expect(@button.hasClass('active')).toEqual(false)
|
183
|
+
|
184
|
+
describe "click for various button types", ->
|
185
|
+
|
186
|
+
it "does nothing if the button is disabled", ->
|
187
|
+
spy = spyOn(Mercury.Toolbar.Button.prototype, 'togglePressed').andCallThrough()
|
188
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {toggle: true})
|
189
|
+
|
190
|
+
jasmine.simulate.click(@button.get(0))
|
191
|
+
expect(spy.callCount).toEqual(1)
|
192
|
+
|
193
|
+
@button.addClass('disabled')
|
194
|
+
jasmine.simulate.click(@button.get(0))
|
195
|
+
expect(spy.callCount).toEqual(1)
|
196
|
+
|
197
|
+
it "triggers an action event", ->
|
198
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary')
|
199
|
+
spy = spyOn(Mercury, 'trigger').andCallFake(=>)
|
200
|
+
|
201
|
+
jasmine.simulate.click(@button.get(0))
|
202
|
+
expect(spy.argsForCall[0]).toEqual(['action', {action: 'foo'}])
|
203
|
+
|
204
|
+
it "triggers a focus:frame event", ->
|
205
|
+
spy = spyOn(Mercury, 'trigger').andCallFake(=>)
|
206
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {}, {regions: ['editable']})
|
207
|
+
|
208
|
+
jasmine.simulate.click(@button.get(0))
|
209
|
+
expect(spy.argsForCall[1]).toEqual(['focus:frame'])
|
210
|
+
|
211
|
+
it "toggles toggle button pressed state", ->
|
212
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {toggle: true})
|
213
|
+
|
214
|
+
jasmine.simulate.click(@button.get(0))
|
215
|
+
expect(@button.hasClass('pressed')).toEqual(true)
|
216
|
+
|
217
|
+
jasmine.simulate.click(@button.get(0))
|
218
|
+
expect(@button.hasClass('pressed')).toEqual(false)
|
219
|
+
|
220
|
+
it "triggers a mode event", ->
|
221
|
+
spy = spyOn(Mercury, 'trigger').andCallFake(=>)
|
222
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {mode: true})
|
223
|
+
|
224
|
+
jasmine.simulate.click(@button.get(0))
|
225
|
+
expect(spy.argsForCall[0]).toEqual(['mode', {mode: 'foo'}])
|
226
|
+
|
227
|
+
it "opens a modal window", ->
|
228
|
+
spy = spyOn(Mercury, 'modal').andCallFake(=>)
|
229
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {modal: '/blank.html'})
|
230
|
+
|
231
|
+
jasmine.simulate.click(@button.get(0))
|
232
|
+
expect(spy.argsForCall[0]).toEqual(['/blank.html', {title: 'summary', handler: 'foo'}])
|
233
|
+
|
234
|
+
it "opens a lightview window", ->
|
235
|
+
spy = spyOn(Mercury, 'lightview').andCallFake(=>)
|
236
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {lightview: '/blank.html'})
|
237
|
+
|
238
|
+
jasmine.simulate.click(@button.get(0))
|
239
|
+
expect(spy.argsForCall[0]).toEqual(['/blank.html', {title: 'summary', handler: 'foo', closeButton: true}])
|
240
|
+
|
241
|
+
it "shows and hides palettes", ->
|
242
|
+
spy = spyOn(Mercury.Palette.prototype, 'toggle').andCallFake(=>)
|
243
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {palette: '/blank.html'})
|
244
|
+
|
245
|
+
jasmine.simulate.click(@button.get(0))
|
246
|
+
expect(spy.callCount).toEqual(1)
|
247
|
+
|
248
|
+
jasmine.simulate.click(@button.get(0))
|
249
|
+
expect(spy.callCount).toEqual(2)
|
250
|
+
|
251
|
+
it "shows and hides selects", ->
|
252
|
+
spy = spyOn(Mercury.Select.prototype, 'toggle').andCallFake(=>)
|
253
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {select: '/blank.html'})
|
254
|
+
|
255
|
+
jasmine.simulate.click(@button.get(0))
|
256
|
+
expect(spy.callCount).toEqual(1)
|
257
|
+
|
258
|
+
jasmine.simulate.click(@button.get(0))
|
259
|
+
expect(spy.callCount).toEqual(2)
|
260
|
+
|
261
|
+
it "shows and hides panels, and toggles the button pressed state", ->
|
262
|
+
spy = spyOn(Mercury.Panel.prototype, 'toggle').andCallFake(=>)
|
263
|
+
@button = new Mercury.Toolbar.Button('foo', 'title', 'summary', {panel: '/blank.html'})
|
264
|
+
|
265
|
+
jasmine.simulate.click(@button.get(0))
|
266
|
+
expect(spy.callCount).toEqual(1)
|
267
|
+
|
268
|
+
jasmine.simulate.click(@button.get(0))
|
269
|
+
expect(spy.callCount).toEqual(2)
|
270
|
+
|
271
|
+
|
272
|
+
describe "Mercury.Toolbar.Button.contexts", ->
|
273
|
+
|
274
|
+
template 'mercury/toolbar.button.html'
|
275
|
+
|
276
|
+
beforeEach ->
|
277
|
+
@contexts = Mercury.Toolbar.Button.contexts
|
278
|
+
@region = $('#context_container')
|
279
|
+
@element = $('#context_button')
|
280
|
+
|
281
|
+
it "handles background color", ->
|
282
|
+
@contexts.backColor.call(@, $('#context_backcolor'), @region)
|
283
|
+
expect(@element.css('background-color')).toEqual('rgb(255, 0, 0)')
|
284
|
+
|
285
|
+
@contexts.backColor.call(@, $('#context_none'), @region)
|
286
|
+
if $.browser.mozilla
|
287
|
+
expect(@element.css('background-color')).toEqual('transparent')
|
288
|
+
else
|
289
|
+
expect(@element.css('background-color')).toEqual('rgba(0, 0, 0, 0)')
|
290
|
+
|
291
|
+
it "handles foreground color", ->
|
292
|
+
@contexts.foreColor.call(@, $('#context_forecolor'), @region)
|
293
|
+
expect(@element.css('background-color')).toEqual('rgb(0, 255, 0)')
|
294
|
+
|
295
|
+
@contexts.foreColor.call(@, $('#context_none'), @region)
|
296
|
+
expect(@element.css('background-color')).toEqual('rgb(0, 0, 0)')
|
297
|
+
|
298
|
+
it "knows when something is bold", ->
|
299
|
+
expect(@contexts.bold.call(@, $('#context_bold1 span'), @region)).toEqual(true)
|
300
|
+
expect(@contexts.bold.call(@, $('#context_bold2 span'), @region)).toEqual(true)
|
301
|
+
expect(@contexts.bold.call(@, $('#context_bold3 span'), @region)).toEqual(true)
|
302
|
+
expect(@contexts.bold.call(@, $('#context_bold4 span'), @region)).toEqual(true)
|
303
|
+
expect(@contexts.bold.call(@, $('#context_bold5 span'), @region)).toEqual(false)
|
304
|
+
expect(@contexts.bold.call(@, $('#context_bold6 span'), @region)).toEqual(true)
|
305
|
+
expect(@contexts.bold.call(@, $('#context_none'), @region)).toEqual(false)
|
306
|
+
|
307
|
+
it "knows when something is italic", ->
|
308
|
+
expect(@contexts.italic.call(@, $('#context_italic1 span'), @region)).toEqual(true)
|
309
|
+
expect(@contexts.italic.call(@, $('#context_italic2 span'), @region)).toEqual(true)
|
310
|
+
expect(@contexts.italic.call(@, $('#context_none'), @region)).toEqual(false)
|
311
|
+
|
312
|
+
it "knows when something is overlined", ->
|
313
|
+
expect(@contexts.overline.call(@, $('#context_overline'), @region)).toEqual(true)
|
314
|
+
expect(@contexts.overline.call(@, $('#context_none'), @region)).toEqual(false)
|
315
|
+
|
316
|
+
it "knows when something is striked through", ->
|
317
|
+
expect(@contexts.strikethrough.call(@, $('#context_strikethrough1 span'), @region)).toEqual(true)
|
318
|
+
expect(@contexts.strikethrough.call(@, $('#context_strikethrough2'), @region)).toEqual(true)
|
319
|
+
expect(@contexts.strikethrough.call(@, $('#context_none'), @region)).toEqual(false)
|
320
|
+
|
321
|
+
it "knows when something is underlined", ->
|
322
|
+
expect(@contexts.underline.call(@, $('#context_underline1 span'), @region)).toEqual(true)
|
323
|
+
expect(@contexts.underline.call(@, $('#context_underline2'), @region)).toEqual(true)
|
324
|
+
expect(@contexts.underline.call(@, $('#context_none'), @region)).toEqual(false)
|
325
|
+
|
326
|
+
it "knows when something is subscript", ->
|
327
|
+
expect(@contexts.subscript.call(@, $('#context_subscript span'), @region)).toEqual(true)
|
328
|
+
expect(@contexts.subscript.call(@, $('#context_none'), @region)).toEqual(false)
|
329
|
+
|
330
|
+
it "knows when something is superscript", ->
|
331
|
+
expect(@contexts.superscript.call(@, $('#context_superscript span'), @region)).toEqual(true)
|
332
|
+
expect(@contexts.superscript.call(@, $('#context_none'), @region)).toEqual(false)
|
333
|
+
|
334
|
+
it "knows when something is justified left", ->
|
335
|
+
expect(@contexts.justifyLeft.call(@, $('#context_justifyLeft span'), @region)).toEqual(true)
|
336
|
+
expect(@contexts.justifyLeft.call(@, $('#context_none'), @region)).toEqual(false)
|
337
|
+
|
338
|
+
it "knows when something is justified center", ->
|
339
|
+
expect(@contexts.justifyCenter.call(@, $('#context_justifyCenter span'), @region)).toEqual(true)
|
340
|
+
expect(@contexts.justifyCenter.call(@, $('#context_none'), @region)).toEqual(false)
|
341
|
+
|
342
|
+
it "knows when something is justified right", ->
|
343
|
+
expect(@contexts.justifyRight.call(@, $('#context_justifyRight span'), @region)).toEqual(true)
|
344
|
+
expect(@contexts.justifyRight.call(@, $('#context_none'), @region)).toEqual(false)
|
345
|
+
|
346
|
+
it "knows when something is justified fully", ->
|
347
|
+
expect(@contexts.justifyFull.call(@, $('#context_justifyFull span'), @region)).toEqual(true)
|
348
|
+
expect(@contexts.justifyFull.call(@, $('#context_none'), @region)).toEqual(false)
|
349
|
+
|
350
|
+
it "knows when something is inside an ordered list", ->
|
351
|
+
expect(@contexts.insertOrderedList.call(@, $('#context_orderedlist span'), @region)).toEqual(true)
|
352
|
+
expect(@contexts.insertOrderedList.call(@, $('#context_none'), @region)).toEqual(false)
|
353
|
+
|
354
|
+
it "knows when something is inside an unordered list", ->
|
355
|
+
expect(@contexts.insertUnorderedList.call(@, $('#context_unorderedlist span'), @region)).toEqual(true)
|
356
|
+
expect(@contexts.insertUnorderedList.call(@, $('#context_none'), @region)).toEqual(false)
|
357
|
+
|
358
|
+
# todo: fix in jquery
|
359
|
+
# it "understands nested text-decoration styles", ->
|
360
|
+
# expect(@contexts.underline.call(@, $('#context_decoration'), @region)).toEqual(true)
|
@@ -0,0 +1,118 @@
|
|
1
|
+
describe "Mercury.Toolbar.Expander", ->
|
2
|
+
|
3
|
+
template 'mercury/toolbar.expander.html'
|
4
|
+
|
5
|
+
beforeEach ->
|
6
|
+
@container = $('#expander_container')
|
7
|
+
|
8
|
+
afterEach ->
|
9
|
+
@expander = null
|
10
|
+
delete(@expander)
|
11
|
+
$(window).unbind('mercury:resize')
|
12
|
+
|
13
|
+
describe "constructor", ->
|
14
|
+
|
15
|
+
beforeEach ->
|
16
|
+
@expander = new Mercury.Toolbar.Expander('foo', {appendTo: '#test', for: @container})
|
17
|
+
|
18
|
+
it "expects a name, and options", ->
|
19
|
+
html = $('<div>').html(@expander).html()
|
20
|
+
expect(html).toContain('class="mercury-palette mercury-expander mercury-foo-expander"')
|
21
|
+
expect(html).toMatch(/style="display:\s?none/)
|
22
|
+
expect($('#test .mercury-toolbar-expander').length).toEqual(1)
|
23
|
+
|
24
|
+
|
25
|
+
describe "#build", ->
|
26
|
+
|
27
|
+
beforeEach ->
|
28
|
+
@resizeSpy = spyOn(Mercury.Toolbar.Expander.prototype, 'windowResize').andCallFake(=>)
|
29
|
+
@expander = new Mercury.Toolbar.Expander('foo', {appendTo: '#test', for: @container})
|
30
|
+
|
31
|
+
it "sets the whitespace of the container to normal", ->
|
32
|
+
expect(@container.css('whiteSpace')).toEqual('normal')
|
33
|
+
|
34
|
+
it "builds an element", ->
|
35
|
+
html = $('<div>').html(@expander).html()
|
36
|
+
expect(html).toContain('class="mercury-palette mercury-expander mercury-foo-expander"')
|
37
|
+
expect(html).toMatch(/style="display:\s?none/)
|
38
|
+
|
39
|
+
it "builds a trigger button", ->
|
40
|
+
expect($('#test .mercury-toolbar-expander').length).toEqual(1)
|
41
|
+
|
42
|
+
it "calls windowResize", ->
|
43
|
+
expect(@resizeSpy.callCount).toEqual(1)
|
44
|
+
|
45
|
+
|
46
|
+
describe "observed events", ->
|
47
|
+
|
48
|
+
beforeEach ->
|
49
|
+
$('.mercury-button').data('expander', '<div data-button="test">expander</div>')
|
50
|
+
@expander = new Mercury.Toolbar.Expander('foo', {appendTo: '#test', for: @container})
|
51
|
+
|
52
|
+
describe "custom event: hide:dialogs", ->
|
53
|
+
|
54
|
+
it "hides", ->
|
55
|
+
@expander.css({display: 'block'})
|
56
|
+
Mercury.trigger('hide:dialogs')
|
57
|
+
expect(@expander.css('display')).toEqual('none')
|
58
|
+
|
59
|
+
it "doesn't hide if it's the same dialog", ->
|
60
|
+
# there's no way to test this since we don't expose the instance -- just the element
|
61
|
+
#@expander.css({display: 'block'})
|
62
|
+
#Mercury.trigger('hide:dialogs', !instance!)
|
63
|
+
#expect(@expander.css('display')).toEqual('block')
|
64
|
+
|
65
|
+
describe "custom event: resize", ->
|
66
|
+
|
67
|
+
it "calls windowResize", ->
|
68
|
+
spy = spyOn(Mercury.Toolbar.Expander.prototype, 'windowResize').andCallFake(=>)
|
69
|
+
Mercury.trigger('resize')
|
70
|
+
expect(spy.callCount).toEqual(1)
|
71
|
+
|
72
|
+
describe "click (on trigger)", ->
|
73
|
+
|
74
|
+
it "pulls buttons into the palette", ->
|
75
|
+
jasmine.simulate.click($('.mercury-toolbar-expander').get(0))
|
76
|
+
expect(@expander.html()).toEqual('<div data-button="test">expander</div>')
|
77
|
+
|
78
|
+
describe "click", ->
|
79
|
+
|
80
|
+
it "calls click on the real button", ->
|
81
|
+
button = $('#button2')
|
82
|
+
spy = spyOn(button, 'click').andCallFake(=>)
|
83
|
+
@container.find = -> button
|
84
|
+
@expander.appendTo('#test')
|
85
|
+
|
86
|
+
jasmine.simulate.click($('.mercury-toolbar-expander').get(0))
|
87
|
+
jasmine.simulate.click($('[data-button=test]').get(0))
|
88
|
+
expect(spy.callCount).toEqual(1)
|
89
|
+
|
90
|
+
describe "#windowResize", ->
|
91
|
+
|
92
|
+
it "hides", ->
|
93
|
+
@expander = new Mercury.Toolbar.Expander('foo', {appendTo: '#test', for: @container})
|
94
|
+
@expander.css({display: 'block'})
|
95
|
+
|
96
|
+
Mercury.trigger('resize')
|
97
|
+
expect(@expander.css('display')).toEqual('none')
|
98
|
+
|
99
|
+
it "shows the trigger if the container is wider than the window", ->
|
100
|
+
@expander = new Mercury.Toolbar.Expander('foo', {appendTo: '#test', for: @container})
|
101
|
+
Mercury.trigger('resize')
|
102
|
+
expect($('.mercury-toolbar-expander').css('display')).toEqual('block')
|
103
|
+
|
104
|
+
it "hides the trigger if the container is narrower than the window", ->
|
105
|
+
@container.css({width: '1px'})
|
106
|
+
@expander = new Mercury.Toolbar.Expander('foo', {appendTo: '#test', for: @container})
|
107
|
+
Mercury.trigger('resize')
|
108
|
+
expect($('.mercury-toolbar-expander').css('display')).toEqual('none')
|
109
|
+
|
110
|
+
|
111
|
+
describe "#position", ->
|
112
|
+
|
113
|
+
it "positions the element", ->
|
114
|
+
@expander = new Mercury.Toolbar.Expander('foo', {appendTo: '#test', for: @container})
|
115
|
+
@expander.appendTo('#positioned_container')
|
116
|
+
jasmine.simulate.click($('.mercury-toolbar-expander').get(0))
|
117
|
+
|
118
|
+
expect(@expander.offset()).toEqual({top: 42, left: 42})
|