Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kazuhiko Shiozaki
gitlab-ce
Commits
01d0926b
Commit
01d0926b
authored
Oct 05, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add "Quick Submit" JS behavior
parent
38fbfb9f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
0 deletions
+100
-0
app/assets/javascripts/behaviors/quick_submit.js.coffee
app/assets/javascripts/behaviors/quick_submit.js.coffee
+29
-0
spec/javascripts/behaviors/quick_submit_spec.js.coffee
spec/javascripts/behaviors/quick_submit_spec.js.coffee
+65
-0
spec/javascripts/fixtures/behaviors/quick_submit.html.haml
spec/javascripts/fixtures/behaviors/quick_submit.html.haml
+6
-0
No files found.
app/assets/javascripts/behaviors/quick_submit.js.coffee
0 → 100644
View file @
01d0926b
# Quick Submit behavior
#
# When an input field with the `js-quick-submit` class receives a "Meta+Enter"
# (Mac) or "Ctrl+Enter" (Linux/Windows) key combination, its parent form is
# submitted.
#
#= require extensions/jquery
#
# ### Example Markup
#
# <form action="/foo">
# <input type="text" class="js-quick-submit" />
# <textarea class="js-quick-submit"></textarea>
# </form>
#
$
(
document
).
on
'keydown.quick_submit'
,
'.js-quick-submit'
,
(
e
)
->
return
if
e
.
repeat
return
unless
e
.
keyCode
==
13
# Enter
if
navigator
.
userAgent
.
match
(
/Macintosh/
)
return
unless
(
e
.
metaKey
&&
!
e
.
altKey
&&
!
e
.
ctrlKey
&&
!
e
.
shiftKey
)
else
return
unless
(
e
.
ctrlKey
&&
!
e
.
altKey
&&
!
e
.
metaKey
&&
!
e
.
shiftKey
)
e
.
preventDefault
()
$form
=
$
(
e
.
target
).
closest
(
'form'
)
$form
.
find
(
'input[type=submit], button[type=submit]'
).
disable
()
$form
.
submit
()
spec/javascripts/behaviors/quick_submit_spec.js.coffee
0 → 100644
View file @
01d0926b
#= require behaviors/quick_submit
describe
'Quick Submit behavior'
,
->
fixture
.
preload
(
'behaviors/quick_submit.html'
)
beforeEach
->
fixture
.
load
(
'behaviors/quick_submit.html'
)
# Prevent a form submit from moving us off the testing page
$
(
'form'
).
submit
(
e
)
->
e
.
preventDefault
()
@
spies
=
{
submit
:
spyOnEvent
(
'form'
,
'submit'
)
}
it
'does not respond to other keyCodes'
,
->
$
(
'input'
).
trigger
(
keydownEvent
(
keyCode
:
32
))
expect
(
@
spies
.
submit
).
not
.
toHaveBeenTriggered
()
it
'does not respond to Enter alone'
,
->
$
(
'input'
).
trigger
(
keydownEvent
(
ctrlKey
:
false
,
metaKey
:
false
))
expect
(
@
spies
.
submit
).
not
.
toHaveBeenTriggered
()
it
'disables submit buttons'
,
->
$
(
'textarea'
).
trigger
(
keydownEvent
())
expect
(
$
(
'input[type=submit]'
)).
toBeDisabled
()
expect
(
$
(
'button[type=submit]'
)).
toBeDisabled
()
# We cannot stub `navigator.userAgent` for CI's `rake teaspoon` task, so we'll
# only run the tests that apply to the current platform
if
navigator
.
userAgent
.
match
(
/Macintosh/
)
it
'responds to Meta+Enter'
,
->
$
(
'input'
).
trigger
(
keydownEvent
())
expect
(
@
spies
.
submit
).
toHaveBeenTriggered
()
it
'excludes other modifier keys'
,
->
$
(
'input'
).
trigger
(
keydownEvent
(
altKey
:
true
))
$
(
'input'
).
trigger
(
keydownEvent
(
ctrlKey
:
true
))
$
(
'input'
).
trigger
(
keydownEvent
(
shiftKey
:
true
))
expect
(
@
spies
.
submit
).
not
.
toHaveBeenTriggered
()
else
it
'responds to Ctrl+Enter'
,
->
$
(
'input'
).
trigger
(
keydownEvent
())
expect
(
@
spies
.
submit
).
toHaveBeenTriggered
()
it
'excludes other modifier keys'
,
->
$
(
'input'
).
trigger
(
keydownEvent
(
altKey
:
true
))
$
(
'input'
).
trigger
(
keydownEvent
(
metaKey
:
true
))
$
(
'input'
).
trigger
(
keydownEvent
(
shiftKey
:
true
))
expect
(
@
spies
.
submit
).
not
.
toHaveBeenTriggered
()
keydownEvent
=
(
options
)
->
if
navigator
.
userAgent
.
match
(
/Macintosh/
)
defaults
=
{
keyCode
:
13
,
metaKey
:
true
}
else
defaults
=
{
keyCode
:
13
,
ctrlKey
:
true
}
$
.
Event
(
'keydown'
,
$
.
extend
({},
defaults
,
options
))
spec/javascripts/fixtures/behaviors/quick_submit.html.haml
0 → 100644
View file @
01d0926b
%form
{
action:
'/foo'
}
%input
.js-quick-submit
{
type:
'text'
}
%textarea
.js-quick-submit
%input
{
type:
'submit'
}
Submit
%button
.btn
{
type:
'submit'
}
Submit
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment