Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
MetaGer
Commits
27a83eff
Commit
27a83eff
authored
Aug 07, 2019
by
Aria Givi
Browse files
changed the way currently focused element is stored
parent
251bb8bf
Changes
2
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
27a83eff
...
...
@@ -8,6 +8,7 @@ Homestead.yaml
.orig
.vscode
langfiles.zip
npm-debug.log
# The Files created by Webpack in the build process
/public/**/*.css
!/public/fonts/arimo/stylesheet.css
...
...
@@ -19,4 +20,4 @@ langfiles.zip
/.buildpath
/.project
composer.lock
\ No newline at end of file
composer.lock
resources/js/keyboardNavigation.js
View file @
27a83eff
var
ctrlInfo
=
false
;
// Flag used for checking if the user was shown the keyboard control information
/*
var current
Element = [
["Results", false]
];
*/
var
currentResultIndex
=
1
;
// stores result which was focused last
var
current
ResultIndex
=
1
;
// stores index of result which was focused last
var
currentElementData
=
{
// Object used for storing currently focused element and element type (e.g. anchor tag or result div)
element
:
$
(
"
div.result
"
).
first
(),
selector
:
"
div.result
"
,
type
:
"
result
"
};
$
(
document
).
on
(
'
keydown
'
,
function
(
e
)
{
e
=
e
||
window
.
event
;
...
...
@@ -12,51 +12,54 @@ $(document).on('keydown', function(e) {
if
(
e
.
keyCode
==
'
9
'
)
{
e
.
preventDefault
();
tabKeyPressed
();
// Check for ENTER keypress
}
else
if
(
e
.
keyCode
==
'
13
'
)
{
e
.
preventDefault
();
enterKeyPressed
();
}
});
function
setFocus
(
e
,
selector
,
type
)
{
currentElementData
.
element
=
e
;
currentElementData
.
selector
=
selector
;
currentElementData
.
type
=
type
;
currentElementData
.
element
.
focus
();
console
.
log
(
currentElementData
);
}
function
tabKeyPressed
()
{
if
(
!
ctrlInfo
)
{
ctrlInfo
=
true
;
showInfoBox
();
}
else
{
focusNextElement
(
$
(
"
:focus
"
)
);
focusNextElement
();
}
}
function
enterKeyPressed
()
{
if
(
$
(
"
:focus
"
).
hasClass
(
"
result
"
))
{
//$(":focus").children("a").focus();
console
.
log
(
$
(
"
:focus
"
).
children
(
"
a
"
));
}
if
(
currentElementData
.
type
=
"
result
"
)
{
// setFocus(currentElementData.element, "link")
}
}
function
showInfoBox
()
{
infoBox
=
$
(
"
#keyboard-ctrl-info
"
);
infoBox
.
show
();
infoBox
.
focus
();
$
(
"
#keyboard-ctrl-info
"
).
show
();
setFocus
(
$
(
"
#keyboard-ctrl-info
"
),
"
#keyboard-ctrl-info
"
,
"
infobox
"
);
}
function
focusNextElement
(
currentFocus
)
{
if
(
current
Focus
.
hasClass
(
"
result
"
)
)
{
focusNextResult
(
currentFocus
);
function
focusNextElement
()
{
if
(
current
ElementData
.
type
===
"
result
"
)
{
focusNextResult
();
}
else
{
focusResult
(
);
setFocus
(
$
(
"
div.result
"
).
not
(
'
.ad
'
).
first
(),
"
div.result
"
,
"
result
"
);
}
}
function
focusResult
()
{
$
(
"
div[data-index='
"
+
currentResultIndex
+
"
'
"
).
focus
();
n
=
$
(
"
.result
"
).
length
;
currentResultIndex
=
1
+
currentResultIndex
%
n
;
console
.
log
(
currentResultIndex
+
"
-
"
+
n
);
}
function
focusNextResult
(
currentFocus
)
{
if
(
currentFocus
.
next
().
length
>
0
)
{
currentFocus
.
next
().
focus
();
function
focusNextResult
()
{
if
(
currentElementData
.
element
.
next
().
length
>
0
)
{
setFocus
(
currentElementData
.
element
.
next
(),
''
,
"
result
"
);
}
else
{
$
(
"
div
[
.result
]
"
).
first
().
focus
(
);
setFocus
(
$
(
"
div.result
"
).
not
(
'
.ad
'
).
first
(),
"
div.result
"
,
"
result
"
);
}
}
\ No newline at end of file
}
Write
Preview
Supports
Markdown
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