Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OLAT CI-CD Testing Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Oliver Dam
OLAT CI-CD Testing Project
Commits
352b0e1d
Commit
352b0e1d
authored
10 years ago
by
Michael Enz
Browse files
Options
Downloads
Patches
Plain Diff
OO-1261: navbar tabs are collapsed into offcanvas nav one by one
parent
e27cd7be
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/webapp/static/js/jquery/openolat/jquery.navbar.js
+118
-53
118 additions, 53 deletions
src/main/webapp/static/js/jquery/openolat/jquery.navbar.js
with
118 additions
and
53 deletions
src/main/webapp/static/js/jquery/openolat/jquery.navbar.js
+
118
−
53
View file @
352b0e1d
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
+
function
(
$
)
{
+
function
(
$
)
{
'
use strict
'
;
'
use strict
'
;
var
Navbar
=
function
()
{
var
Navbar
=
function
()
{
var
tabsExist
=
!!
$
(
'
#o_navbar_container .o_navbar_tabs li:last-child
'
).
length
;
this
.
state
=
{
this
.
state
=
{
rightVisible
:
false
,
rightVisible
:
false
,
toggleVisible
:
false
,
toggleVisible
:
false
,
...
@@ -40,7 +41,8 @@
...
@@ -40,7 +41,8 @@
sitesExtended
:
true
,
sitesExtended
:
true
,
sitesDirty
:
false
,
sitesDirty
:
false
,
tabsW
:
0
,
tabsW
:
0
,
tabsOffCanvas
:
false
,
tabsCollapsed
:
!
tabsExist
,
tabsExtended
:
tabsExist
,
tabsDirty
:
false
,
tabsDirty
:
false
,
personalToolsW
:
0
,
personalToolsW
:
0
,
personalToolsOffCanvas
:
false
,
personalToolsOffCanvas
:
false
,
...
@@ -103,8 +105,9 @@
...
@@ -103,8 +105,9 @@
Navbar
.
prototype
.
onDOMreplacementCallback
=
function
()
{
Navbar
.
prototype
.
onDOMreplacementCallback
=
function
()
{
if
(
!
this
.
state
.
busy
&&
(
this
.
state
.
staticDirty
||
this
.
state
.
sitesDirty
||
this
.
state
.
tabsDirty
||
this
.
state
.
personalToolsDirty
))
{
if
(
!
this
.
state
.
busy
&&
(
this
.
state
.
staticDirty
||
this
.
state
.
sitesDirty
||
this
.
state
.
tabsDirty
||
this
.
state
.
personalToolsDirty
))
{
this
.
state
.
busy
=
true
;
this
.
state
.
busy
=
true
;
//offcanvas sites need to be cleared, otherwise they are duplicated
//offcanvas sites
and tabs
need to be cleared, otherwise they are duplicated
$
(
'
.o_sites_offcanvas
'
).
empty
();
$
(
'
.o_sites_offcanvas
'
).
empty
();
$
(
'
.o_tabs_offcanvas
'
).
empty
();
this
.
calculateWidth
();
this
.
calculateWidth
();
this
.
optimize
();
this
.
optimize
();
this
.
state
.
sitesDirty
=
false
;
this
.
state
.
sitesDirty
=
false
;
...
@@ -128,10 +131,8 @@
...
@@ -128,10 +131,8 @@
if
(
!
this
.
state
.
staticOffCanvas
)
{
if
(
!
this
.
state
.
staticOffCanvas
)
{
this
.
state
.
staticW
=
$
(
'
.o_navbar_static
'
).
outerWidth
(
true
);
this
.
state
.
staticW
=
$
(
'
.o_navbar_static
'
).
outerWidth
(
true
);
}
}
this
.
state
.
sitesW
=
$
(
'
.o_navbar_sites
'
).
outerWidth
(
true
);
this
.
state
.
sitesW
=
$
(
'
#o_navbar_container .o_navbar_sites
'
).
outerWidth
(
true
);
if
(
!
this
.
state
.
tabsOffCanvas
)
{
this
.
state
.
tabsW
=
$
(
'
#o_navbar_container .o_navbar_tabs
'
).
outerWidth
(
true
);
this
.
state
.
tabsW
=
$
(
'
.o_navbar_tabs
'
).
outerWidth
(
true
);
}
if
(
!
this
.
state
.
personalToolsOffCanvas
)
{
if
(
!
this
.
state
.
personalToolsOffCanvas
)
{
//don't include margin, because left and right margins on this element are negative
//don't include margin, because left and right margins on this element are negative
this
.
state
.
personalToolsW
=
$
(
'
#o_navbar_tools_personal
'
).
outerWidth
(
false
);
this
.
state
.
personalToolsW
=
$
(
'
#o_navbar_tools_personal
'
).
outerWidth
(
false
);
...
@@ -147,37 +148,37 @@
...
@@ -147,37 +148,37 @@
o
-=
this
.
state
.
staticW
;
o
-=
this
.
state
.
staticW
;
}
}
o
-=
this
.
state
.
sitesW
;
o
-=
this
.
state
.
sitesW
;
if
(
!
this
.
state
.
tabsOffCanvas
)
{
o
-=
this
.
state
.
tabsW
;
o
-=
this
.
state
.
tabsW
;
}
if
(
!
this
.
state
.
personalToolsOffCanvas
)
{
if
(
!
this
.
state
.
personalToolsOffCanvas
)
{
o
-=
this
.
state
.
personalToolsW
;
o
-=
this
.
state
.
personalToolsW
;
}
}
if
(
this
.
state
.
personalToolsOffCanvas
||
this
.
state
.
ta
bs
OffCanvas
||
this
.
state
.
s
taticOffCanvas
)
{
if
(
this
.
state
.
personalToolsOffCanvas
||
this
.
state
.
s
ta
tic
OffCanvas
||
!
this
.
state
.
s
itesExtended
||
!
this
.
state
.
tabsExtended
)
{
// subtract the space used for toggle only when toggle is actually used
// subtract the space used for toggle only when toggle is actually used
o
-=
this
.
state
.
toggleW
;
o
-=
this
.
state
.
toggleW
;
}
}
// always subtract the space used by brand and the permanent tools
// always subtract the space used by brand and the permanent tools
o
-=
this
.
state
.
brandW
;
o
-=
this
.
state
.
brandW
;
o
-=
this
.
state
.
permanentToolW
;
o
-=
this
.
state
.
permanentToolW
;
//element widths can sometimes be off by 1px, so we need a small buffer on o
o
-=
20
;
return
-
o
;
return
-
o
;
}
}
Navbar
.
prototype
.
optimize
=
function
(
e
)
{
Navbar
.
prototype
.
optimize
=
function
(
e
)
{
var
o
=
this
.
getOverflow
();
var
o
=
this
.
getOverflow
();
// console.log('optimize o:' + o);
// console.log('optimize o:' + o);
// Move from toolbar to offcanvas
// Move from toolbar to offcanvas
//outerWidth can be off by 1px, so we need a small buffer on o
while
(
o
>
0
&&
(
!
this
.
state
.
personalToolsOffCanvas
||
!
this
.
state
.
tabsCollapsed
||
!
this
.
state
.
sitesCollapsed
||
!
this
.
state
.
staticOffCanvas
))
{
while
(
o
+
20
>
0
&&
(
!
this
.
state
.
personalToolsOffCanvas
||
!
this
.
state
.
tabsOffCanvas
||
!
this
.
state
.
sitesCollapsed
||
!
this
.
state
.
staticOffCanvas
))
{
if
(
!
this
.
state
.
personalToolsOffCanvas
)
{
if
(
!
this
.
state
.
personalToolsOffCanvas
)
{
// console.log('collapse tools ' + o);
// console.log('collapse tools ' + o);
$
(
'
#o_navbar_tools_personal
'
).
prependTo
(
'
#o_offcanvas_right_container
'
);
$
(
'
#o_navbar_tools_personal
'
).
prependTo
(
'
#o_offcanvas_right_container
'
);
this
.
state
.
personalToolsOffCanvas
=
true
;
this
.
state
.
personalToolsOffCanvas
=
true
;
}
}
else
if
(
!
this
.
state
.
tabs
OffCanvas
)
{
else
if
(
!
this
.
state
.
tabs
Collapsed
)
{
// console.log('collapse tabs ' + o);
// console.log('collapse tabs ' + o);
$
(
'
.o_navbar_tabs
'
).
prependTo
(
'
#o_offcanvas_right_container
'
);
this
.
collapseTabs
();
this
.
state
.
tabsOffCanvas
=
true
;
}
}
else
if
(
!
this
.
state
.
sitesCollapsed
)
{
else
if
(
!
this
.
state
.
sitesCollapsed
)
{
// console.log('collapse sites ' + o);
// console.log('collapse sites ' + o);
...
@@ -193,7 +194,7 @@
...
@@ -193,7 +194,7 @@
o
=
this
.
getOverflow
();
o
=
this
.
getOverflow
();
}
}
// Move from offcanvas to toolbar
// Move from offcanvas to toolbar
while
(
o
<
0
&&
(
this
.
state
.
personalToolsOffCanvas
||
this
.
state
.
tabs
OffCanvas
||
!
this
.
state
.
sitesExtended
||
this
.
state
.
staticOffCanvas
))
{
while
(
o
<
0
&&
(
this
.
state
.
personalToolsOffCanvas
||
!
this
.
state
.
tabs
Extended
||
!
this
.
state
.
sitesExtended
||
this
.
state
.
staticOffCanvas
))
{
if
(
this
.
state
.
staticOffCanvas
)
{
if
(
this
.
state
.
staticOffCanvas
)
{
if
(
-
o
<
this
.
state
.
staticW
)
{
if
(
-
o
<
this
.
state
.
staticW
)
{
break
;
break
;
...
@@ -204,22 +205,18 @@
...
@@ -204,22 +205,18 @@
this
.
state
.
staticOffCanvas
=
false
;
this
.
state
.
staticOffCanvas
=
false
;
}
}
else
if
(
!
this
.
state
.
sitesExtended
)
{
else
if
(
!
this
.
state
.
sitesExtended
)
{
if
(
triedToExtend
){
// console.log('extend sites ' + o);
var
siteFit
=
this
.
extendSites
();
if
(
!
siteFit
){
break
;
break
;
}
}
// console.log('extend sites ' + o);
this
.
extendSites
();
var
triedToExtend
=
true
;
}
}
else
if
(
this
.
state
.
tabsOffCanvas
)
{
else
if
(
!
this
.
state
.
tabsExtended
)
{
if
(
-
o
<
this
.
state
.
tabsW
)
{
// console.log('extend tabs ' + o);
var
tabFit
=
this
.
extendTabs
();
if
(
!
tabFit
)
{
break
;
break
;
}
}
// console.log('uncollapse tabs ' + o);
$
(
'
.o_navbar_tabs
'
).
appendTo
(
'
#o_navbar_container .o_navbar-collapse
'
);
this
.
state
.
tabsOffCanvas
=
false
;
}
}
else
if
(
this
.
state
.
personalToolsOffCanvas
)
{
else
if
(
this
.
state
.
personalToolsOffCanvas
)
{
if
(
-
o
<
this
.
state
.
personalToolsW
)
{
if
(
-
o
<
this
.
state
.
personalToolsW
)
{
...
@@ -235,7 +232,7 @@
...
@@ -235,7 +232,7 @@
o
=
this
.
getOverflow
();
o
=
this
.
getOverflow
();
}
}
if
(
this
.
state
.
personalToolsOffCanvas
||
this
.
state
.
tabs
OffCanvas
||
!
this
.
state
.
sitesExtended
)
{
if
(
this
.
state
.
personalToolsOffCanvas
||
!
this
.
state
.
tabs
Extended
||
!
this
.
state
.
sitesExtended
)
{
this
.
showToggle
();
this
.
showToggle
();
}
else
{
}
else
{
this
.
hideToggle
();
this
.
hideToggle
();
...
@@ -248,32 +245,23 @@
...
@@ -248,32 +245,23 @@
* Collapse sites into 'more' one by one
* Collapse sites into 'more' one by one
*/
*/
Navbar
.
prototype
.
collapseSites
=
function
(
e
)
{
Navbar
.
prototype
.
collapseSites
=
function
(
e
)
{
var
sites
=
$
(
'
.o_navbar_sites
'
);
var
sites
=
$
(
'
#o_navbar_container
.o_navbar_sites
'
);
var
sitesOffcanvas
=
$
(
'
.o_sites_offcanvas
'
);
var
sitesOffcanvas
=
$
(
'
.o_sites_offcanvas
'
);
var
more
=
$
(
'
.o_site_more
'
);
if
(
more
.
length
==
0
){
/* as long as 'more' has no function, don't display it
*/
more
=
$
(
'
<li class=" o_site_more" style="display:none;"><a href=""><span>More</span></a></li>
'
);
more
.
appendTo
(
sites
);
more
.
bind
(
'
click
'
,
this
.
showMoreSites
);
}
if
(
sitesOffcanvas
.
length
==
0
){
if
(
sitesOffcanvas
.
length
==
0
){
sitesOffcanvas
=
$
(
'
<ul>
'
,
{
sitesOffcanvas
=
$
(
'
<ul>
'
,
{
'
class
'
:
'
nav o_navbar-nav o_sites_offcanvas
'
'
class
'
:
'
nav o_navbar-nav
o_navbar_sites
o_sites_offcanvas
'
});
});
sitesOffcanvas
.
prependTo
(
'
#o_offcanvas_right_container
'
);
sitesOffcanvas
.
prependTo
(
'
#o_offcanvas_right_container
'
);
}
}
var
s
econdLast
=
sites
.
find
(
'
li:
nth-
last-child
(2)
'
);
var
s
ite
=
sites
.
find
(
'
li:last-child
'
);
if
(
s
econdLast
.
length
){
if
(
s
ite
.
length
){
// console.log('collapsing site '+s
econdLast
.attr('class').match('o_site_[a-z]*'));
// console.log('collapsing site '+s
ite
.attr('class').match('o_site_[a-z]*'));
s
econdLast
.
appendTo
(
sitesOffcanvas
);
s
ite
.
appendTo
(
sitesOffcanvas
);
}
}
if
(
sites
.
children
().
length
==
1
){
if
(
sites
.
children
().
length
==
0
){
//only 'more' button left
this
.
state
.
sitesCollapsed
=
true
;
this
.
state
.
sitesCollapsed
=
true
;
}
}
...
@@ -284,33 +272,110 @@
...
@@ -284,33 +272,110 @@
* Extend sites by taking them out of 'more' one by one
* Extend sites by taking them out of 'more' one by one
*/
*/
Navbar
.
prototype
.
extendSites
=
function
(
e
)
{
Navbar
.
prototype
.
extendSites
=
function
(
e
)
{
var
sites
=
$
(
'
.o_navbar_sites
'
);
var
sites
=
$
(
'
#o_navbar_container
.o_navbar_sites
'
);
var
sitesOffcanvas
=
$
(
'
.o_sites_offcanvas
'
);
var
sitesOffcanvas
=
$
(
'
.o_sites_offcanvas
'
);
var
more
=
$
(
'
.o_site_more
'
)
;
var
siteFit
=
true
;
var
site
=
sitesOffcanvas
.
find
(
'
li:last-child
'
);
var
site
=
sitesOffcanvas
.
find
(
'
li:last-child
'
);
if
(
site
.
length
){
if
(
site
.
length
){
// console.log('extending site '+site.attr('class').match('o_site_[a-z]*'));
site
.
appendTo
(
sites
);
site
.
insertBefore
(
more
);
//if site doesn't fit move it back
//if site doesn't fit move it back
var
o
=
this
.
getOverflow
();
var
o
=
this
.
getOverflow
();
if
(
-
o
<
site
.
outerWidth
(
true
)){
if
(
-
o
<
site
.
outerWidth
(
true
)){
// console.log('site doesn\'t fit');
site
.
appendTo
(
sitesOffcanvas
);
site
.
appendTo
(
sitesOffcanvas
);
siteFit
=
false
;
}
else
{
// console.log('extending site '+site.attr('class').match('o_site_[a-z]*'));
}
}
}
}
if
(
sitesOffcanvas
.
children
().
length
==
0
){
if
(
sitesOffcanvas
.
children
().
length
==
0
){
this
.
state
.
sitesExtended
=
true
;
this
.
state
.
sitesExtended
=
true
;
sitesOffcanvas
.
remove
();
sitesOffcanvas
.
remove
();
more
.
remove
();
}
}
this
.
state
.
sitesCollapsed
=
false
;
this
.
state
.
sitesCollapsed
=
false
;
return
siteFit
;
}
}
Navbar
.
prototype
.
showMoreSites
=
function
(
e
)
{
/*
* Collapse tabs one by one
*/
Navbar
.
prototype
.
collapseTabs
=
function
(
e
)
{
var
tabs
=
$
(
'
#o_navbar_container .o_navbar_tabs
'
);
var
tabsOffcanvas
=
$
(
'
.o_tabs_offcanvas
'
);
if
(
tabsOffcanvas
.
length
==
0
){
tabsOffcanvas
=
$
(
'
<ul>
'
,
{
'
class
'
:
'
nav o_navbar-nav o_navbar_tabs o_tabs_offcanvas
'
});
tabsOffcanvas
.
prependTo
(
'
#o_offcanvas_right_container
'
);
}
var
tab
=
tabs
.
find
(
'
li:last-child
'
);
if
(
tab
.
length
){
// console.log('collapsing tab '+tab.children(0).attr('title'));
tab
.
appendTo
(
tabsOffcanvas
);
}
if
(
tabs
.
children
().
length
==
0
){
this
.
state
.
tabsCollapsed
=
true
;
}
this
.
state
.
tabsExtended
=
false
;
}
/*
* Extend tabs one by one
*/
Navbar
.
prototype
.
extendTabs
=
function
(
e
)
{
var
tabs
=
$
(
'
#o_navbar_container .o_navbar_tabs
'
);
var
tabsOffcanvas
=
$
(
'
.o_tabs_offcanvas
'
);
var
tabFit
=
true
;
var
tab
=
tabsOffcanvas
.
find
(
'
li:last-child
'
);
if
(
tab
.
length
){
tab
.
appendTo
(
tabs
);
//if tab doesn't fit move it back
var
o
=
this
.
getOverflow
();
if
(
-
o
<
tab
.
outerWidth
(
true
)){
tab
.
appendTo
(
tabsOffcanvas
);
tabFit
=
false
;
}
else
{
// console.log('extending tab '+tab.children(0).attr('title'));
}
}
if
(
tabsOffcanvas
.
children
().
length
==
0
){
this
.
state
.
tabsExtended
=
true
;
tabsOffcanvas
.
remove
();
}
this
.
state
.
tabsCollapsed
=
false
;
return
tabFit
;
}
/*
* Get or create the 'more' navbar element.
* A button to display collapsed elements.
*/
Navbar
.
prototype
.
getOrCreateMoreButton
=
function
()
{
var
collapse
=
$
(
'
#o_navbar_container .o_navbar-collapse
'
);
var
more
=
$
(
'
.o_navbar_more
'
);
if
(
more
.
length
==
0
){
/* as long as 'more' has no function, don't display it:
* style="display:none;"
*/
more
=
$
(
'
<ul class="o_navbar_more nav o_navbar-nav" style="display:none;"><li><a href="">more</a></li></ul>
'
);
more
.
appendTo
(
collapse
);
more
.
bind
(
'
click
'
,
this
.
showMoreSites
);
}
}
Navbar
.
prototype
.
showMoreSites
=
function
(
e
)
{
console
.
log
(
'
more
'
);
}
}
Navbar
.
prototype
.
showToggle
=
function
()
{
Navbar
.
prototype
.
showToggle
=
function
()
{
...
...
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