Clarify the various cases and pave the way to merging with global.js

This commit is contained in:
Alexandre Aubin 2019-02-22 21:07:12 +01:00
parent 2646db9ea2
commit 85d59c5e77
2 changed files with 41 additions and 3 deletions

View file

@ -199,9 +199,34 @@ function make_element_draggable(id) {
---------------------------------------------------------- */ ---------------------------------------------------------- */
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
// Don't do this in iframe // 3 different cases :
if (window.self !== window.top) {return false;} // - this script is loaded from inside an app
// - this script is loaded inside the portal, inside an iframe/overlay activated by clicking the portal button inside an app
// - this script is loaded inside the "regular" portal when going to /yunohost/sso.
var in_app = ! document.body.classList.contains('ynh-user-portal');
var in_overlay_iframe = (window.self === window.top);
if (in_app)
{
init_portal_button_and_overlay();
}
else
{
init_portal();
if (in_overlay_iframe) { tweak_portal_when_in_iframe(); }
}
}
//
// This function is called when ynhpanel.js is included in an app
//
// It will create the small yunohost "portal button" usually in the bottom
// right corner and initialize the portal overlay, shown when clicking the
// portal button meant to make it easier to switch between apps.
//
function init_portal_button_and_overlay()
{
// Set and store meta viewport // Set and store meta viewport
var meta_viewport = document.querySelector('meta[name="viewport"]'); var meta_viewport = document.querySelector('meta[name="viewport"]');
if (meta_viewport === null) { if (meta_viewport === null) {
@ -259,3 +284,16 @@ document.addEventListener('DOMContentLoaded', function() {
}); });
}); });
//
// This function is called to initialize elements like the app tile colors and other things ...
//
function init_portal()
{
// Import stuff from global.js ...
}
function tweak_portal_when_in_iframe()
{
// Import stuff from global.js ...
}

View file

@ -33,7 +33,7 @@
<meta name="msapplication-TileColor" content="#41444f"> <meta name="msapplication-TileColor" content="#41444f">
<meta name="msapplication-TileImage" content="/mstile-144x144.png"> <meta name="msapplication-TileImage" content="/mstile-144x144.png">
</head> </head>
<body class="{{#connected}}logged{{/connected}}"> <body class="ynh-user-portal {{#connected}}logged{{/connected}}">
<h1 id="logo" class="logo"> <h1 id="logo" class="logo">
<img src="assets/img/logo-ynh-white.svg"/><span class="element-invisible">Yunohost</span> <img src="assets/img/logo-ynh-white.svg"/><span class="element-invisible">Yunohost</span>