Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
EBI-Framework
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
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
ebiwd
EBI-Framework
Commits
3f7519bf
Commit
3f7519bf
authored
8 years ago
by
khawkins
Browse files
Options
Downloads
Patches
Plain Diff
Allow restoration of menu items, destruction of empty dropdown
parent
aaf7a07f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
js/foundationExtendEBI.js
+29
-14
29 additions, 14 deletions
js/foundationExtendEBI.js
with
29 additions
and
14 deletions
js/foundationExtendEBI.js
+
29
−
14
View file @
3f7519bf
...
...
@@ -16,32 +16,30 @@
function
localNavSpilloverMenu
(
changeDirection
)
{
var
localMenuWidthUsed
=
0
;
var
localMenuWidthNotUsed
=
localMenuWidthAvail
;
var
localMenuRightSideWidth
=
$
(
'
#local-masthead .masthead > nav ul.float-right.menu
'
).
width
();
// width of any right-side nav, this could change on browser resize
localMenuRightSideWidth
=
localMenuRightSideWidth
+
5
;
// padding
localMenuRightSideWidth
=
localMenuRightSideWidth
+
5
;
// padding
, eleminate NaN
// Calculate how much space we
need, if any
// Calculate how much space we
've used
$
(
localMenuClass
+
'
> li
'
).
each
(
function
()
{
localMenuWidthUsed
=
localMenuWidthUsed
+
$
(
this
).
width
();
});
// account for any float-right menu
// to do: account for any float-right menu
localMenuWidthNotUsed
=
localMenuWidthNotUsed
-
localMenuRightSideWidth
;
localMenuWidthUsed
=
localMenuWidthUsed
+
localMenuRightSideWidth
;
// do we need to make space?
if
(
changeDirection
!
=
'
increase
'
)
{
if
(
localMenuWidthUsed
>
localMenuWidth
NotUsed
)
{
if
(
(
changeDirection
=
=
'
in
it
'
)
||
(
changeDirection
==
'
de
crease
'
)
)
{
if
(
localMenuWidthUsed
>
localMenuWidth
Avail
)
{
// create dropdown if needed
if
(
$
(
localMenuClass
+
'
li.extra-items-menu
'
).
length
==
0
)
{
$
(
localMenuClass
).
append
(
'
<li class="extra-items-menu"><a href="#">Also in this section</a><ul class="menu"></ul></li>
'
);
// to do:
should we be
invok
ing
foundation to create/destroy the dropdown functionality when we add/remove the menu
?
// to do: invok foundation to create/destroy the dropdown functionality when we add/remove the menu
localMenuWidthUsed
=
localMenuWidthUsed
+
$
(
localMenuClass
+
'
li.extra-items-menu
'
).
width
();
}
// loop through each menu item in reverse, and slice off the first as it's the dropdown
$
(
$
(
localMenuClass
+
'
> li
'
).
get
().
reverse
().
slice
(
1
)).
each
(
function
()
{
if
(
localMenuWidthUsed
>
localMenuWidth
NotUsed
)
{
// do we need to hide more items?
if
(
localMenuWidthUsed
>
localMenuWidth
Avail
)
{
// do we need to hide more items?
localMenuWidthUsed
=
localMenuWidthUsed
-
$
(
this
).
width
();
$
(
this
).
detach
().
prependTo
(
localMenuClass
+
'
li.extra-items-menu ul.menu
'
);
}
// we could break when <= but this should be pretty fast
...
...
@@ -55,14 +53,31 @@
if
(
$
(
localMenuClass
+
'
li.extra-items-menu
'
).
length
>
0
)
{
// if the menu is shorter than full width, we can perhaps restore some menu items from the dropdown
var
spaceToWorkWith
=
localMenuWidthAvail
-
localMenuWidthUsed
;
// as the dropdown menu is the width of longest menu item, it's not practical to get the length of each,
// so if the longest item could fit, we'll restore an item
while
(
spaceToWorkWith
>
$
(
localMenuClass
+
'
li.extra-items-menu ul.menu li:first-child
'
).
width
())
{
spaceToWorkWith
=
spaceToWorkWith
-
$
(
localMenuClass
+
'
li.extra-items-menu ul.menu li:first-child
'
).
width
();
$
(
localMenuClass
+
'
li.extra-items-menu ul.menu li:first-child
'
).
detach
().
insertBefore
(
localMenuClass
+
'
li.extra-items-menu
'
);
if
(
$
(
localMenuClass
+
'
li.extra-items-menu li
'
).
length
==
1
)
{
// exit if just 1 item left in menu
break
;
}
}
// if we delete the menu
localMenuWidthNotUsed
=
localMenuWidthNotUsed
+
$
(
localMenuClass
+
'
li.extra-items-menu
'
).
width
();
// console.log('if delete drop down, we have free space of',localMenuWidthNotUsed);
// if there's just one item left, perhaps we should delete the dropdown menu
if
(
$
(
localMenuClass
+
'
li.extra-items-menu li
'
).
length
==
1
)
{
spaceToWorkWith
=
spaceToWorkWith
+
$
(
localMenuClass
+
'
li.extra-items-menu
'
).
width
();
if
(
spaceToWorkWith
>
$
(
localMenuClass
+
'
li.extra-items-menu ul.menu li:first-child
'
).
width
())
{
// ok, we should move item up from dropdwon, this will leave us with 0 items and we'll delete in next if
$
(
localMenuClass
+
'
li.extra-items-menu ul.menu li:first-child
'
).
detach
().
insertBefore
(
localMenuClass
+
'
li.extra-items-menu
'
);
}
}
if
(
$
(
localMenuClass
+
'
li.extra-items-menu li
'
).
length
==
0
)
{
// if the dropdown is empty, remove it
// to do: invok foundation to create/destroy the dropdown functionality when we add/remove the menu
$
(
localMenuClass
+
'
li.extra-items-menu
'
).
remove
();
}
}
...
...
@@ -77,7 +92,7 @@
if
(
widthChangeAmount
!=
0
)
localMenuWidthAvail
=
$
(
'
#local-masthead .masthead > nav
'
).
width
();
// we look for changes of more than 1 to reduce jitter
if
(
widthChangeAmount
>
1
)
localNavSpilloverMenu
(
'
increase
'
);
if
(
widthChangeAmount
<
1
)
localNavSpilloverMenu
(
'
decrease
'
);
if
(
widthChangeAmount
<
-
1
)
localNavSpilloverMenu
(
'
decrease
'
);
});
// Clearable text inputs
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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