Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
layout_paragraphs
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
layout_paragraphs
Commits
3460c27a
Commit
3460c27a
authored
4 years ago
by
Justin Toupin
Browse files
Options
Downloads
Patches
Plain Diff
Keyboard movements now seem porformant / stable. Needs a little more testing.
parent
5677a200
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
js/layout-paragraphs-widget.js
+30
-9
30 additions, 9 deletions
js/layout-paragraphs-widget.js
with
30 additions
and
9 deletions
js/layout-paragraphs-widget.js
+
30
−
9
View file @
3460c27a
...
...
@@ -428,7 +428,7 @@
* @param {Array} item The current item.
* @return {Object} The massaged results.
*/
function
massagePositions
Down
(
results
,
item
)
{
function
massagePositions
(
results
,
item
)
{
const
level
=
$
(
item
).
parents
(
"
.layout-paragraphs-layout
"
).
length
;
if
(
level
<
results
.
level
)
{
results
.
positions
.
push
(
results
.
layouts
.
pop
());
...
...
@@ -444,6 +444,11 @@
results
.
level
=
level
;
return
results
;
}
/**
* Return the direction to move based on what key was pressed.
* @param {String} keycode The keycode that was pressed.
* @return {String} Returns the move direction: up, down, or stop.
*/
function
getMoveDirection
(
keycode
)
{
switch
(
keycode
)
{
case
37
:
...
...
@@ -456,6 +461,11 @@
return
"
stop
"
;
}
}
/**
* Stops keyboard movement, unbinds the move event and restores UI to main state.
* @param {jQuery} $widget The widget object.
* @param {function} func The event handler to unbind.
*/
function
stopMove
(
$widget
,
func
)
{
$
(
document
).
unbind
(
"
keydown
"
,
func
);
$widget
...
...
@@ -465,11 +475,16 @@
$widget
.
find
(
"
.layout-controls, .layout-paragraphs-actions
"
).
show
();
updateWidget
(
$widget
);
}
/**
* Event handler for keyboard movement.
* @param {Event} e The keydown event.
* @return {Boolean} Returns false to prevent further event propogation.
*/
function
move
(
e
)
{
const
{
$moveItem
,
$widget
,
widgetSettings
}
=
e
.
data
;
const
spacer
=
'
<div class="layout-paragraphs-item layout-paragraphs-temp js-hide"></div>
'
;
$widget
.
find
(
"
.layout-paragraphs-temp
"
).
remove
();
'
<div class="layout-paragraphs-item
js-
layout-paragraphs-temp js-hide"></div>
'
;
$widget
.
find
(
"
.
js-
layout-paragraphs-temp
"
).
remove
();
$widget
.
find
(
"
.layout-paragraphs-moving-message
"
).
remove
();
const
dir
=
getMoveDirection
(
e
.
keyCode
);
if
(
dir
===
"
stop
"
)
{
...
...
@@ -488,10 +503,11 @@
const
positions
=
$
(
"
.layout-paragraphs-item
"
,
$widget
)
.
toArray
()
.
filter
(
i
=>
!
$
.
contains
(
$moveItem
[
0
],
i
));
// If moving down, the positions need to be massaged to adjust the position of layouts.
const
filteredPositions
=
// If moving down, the positions need to be reordered
// to adjust the position of layouts.
const
reorderedPositions
=
dir
===
"
down
"
?
positions
.
reduce
(
massagePositions
Down
,
{
?
positions
.
reduce
(
massagePositions
,
{
positions
:
[],
layouts
:
[],
level
:
0
,
...
...
@@ -499,16 +515,16 @@
}).
positions
:
positions
;
// Get the position (index) of the current item we are moving.
const
pos
=
filt
eredPositions
.
findIndex
(
el
=>
el
===
$moveItem
[
0
]);
const
pos
=
reord
eredPositions
.
findIndex
(
el
=>
el
===
$moveItem
[
0
]);
// Loop through all possible positons, attempting to move to the next in line.
// If a move if not valid, we continue looping until we reach a valid move.
// Usually this results in simply bumping one position forward/backward.
for
(
let
i
=
pos
+
(
dir
===
"
up
"
?
-
1
:
1
);
filt
eredPositions
[
i
]
!==
undefined
;
reord
eredPositions
[
i
]
!==
undefined
;
i
+=
dir
===
"
up
"
?
-
1
:
1
)
{
const
$next
=
$
(
filt
eredPositions
[
i
]);
const
$next
=
$
(
reord
eredPositions
[
i
]);
const
method
=
dir
===
"
up
"
?
"
before
"
:
"
after
"
;
let
valid
=
true
;
// Check for compliance with widget settings.
...
...
@@ -540,6 +556,11 @@
}
}
}
/**
* Event handler for starting keyboard movement.
* @param {Event} e The button press event.
* @return {Boolean} Returns false to prevent further event propogation.
*/
function
startMove
(
e
)
{
const
$moveItem
=
$
(
e
.
currentTarget
).
closest
(
"
.layout-paragraphs-item
"
);
const
$widget
=
$moveItem
.
closest
(
"
.layout-paragraphs-field
"
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment