mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
Merge pull request #131 from hbrunn/8.0-web_hide_menu
[ADD] web_menu_autohide
This commit is contained in:
45
web_menu_autohide/README.rst
Normal file
45
web_menu_autohide/README.rst
Normal file
@@ -0,0 +1,45 @@
|
||||
Hide menus
|
||||
==========
|
||||
|
||||
This addon hides the top and left menu bars. They become visible again when you move the mouse towards the border of the screen (the distance is configurable). Moving the mouse out of a menu causes it to disappear after a configurable delay.
|
||||
|
||||
Configuration
|
||||
=============
|
||||
|
||||
To configure this module, you need to:
|
||||
|
||||
* go to Settings / Technical / Parameters / System Parameters
|
||||
* adjust `web_menu_autohide.show_bar_threshold_navbar` and `web_menu_autohide.show_bar_threshold_leftbar` to set the distance in pixels from the border from which the menu appears (default is 10 pixels, a value of `0` disables hiding)
|
||||
* adjust `web_menu_autohide.hide_delay_navbar` and `web_menu_autohide.hide_delay_leftbar` to set the amount of milliseconds after which the menu disappears if the mouse left it (default is 10 seconds)
|
||||
|
||||
Known issues / Roadmap
|
||||
======================
|
||||
|
||||
* This module heavily relies on mouse events, so it probably messes things up for touchscreens
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
* Holger Brunn <hbrunn@therp.nl>
|
||||
|
||||
Icon
|
||||
----
|
||||
|
||||
* http://commons.wikimedia.org/wiki/File:VisualEditor_-_Icon_-_Menu.svg
|
||||
* http://commons.wikimedia.org/wiki/File:ProhibitionSign2.svg
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
||||
.. image:: http://odoo-community.org/logo.png
|
||||
:alt: Odoo Community Association
|
||||
:target: http://odoo-community.org
|
||||
|
||||
This module is maintained by the OCA.
|
||||
|
||||
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.
|
||||
|
||||
To contribute to this module, please visit http://odoo-community.org.
|
||||
20
web_menu_autohide/__init__.py
Normal file
20
web_menu_autohide/__init__.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# This module copyright (C) 2015 Therp BV <http://therp.nl>.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
41
web_menu_autohide/__openerp__.py
Normal file
41
web_menu_autohide/__openerp__.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# This module copyright (C) 2015 Therp BV <http://therp.nl>.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
{
|
||||
"name": "Hide menus",
|
||||
"version": "1.0",
|
||||
"author": "Therp BV",
|
||||
"license": "AGPL-3",
|
||||
"category": "Tools",
|
||||
"summary": "Hide top and left menu bar",
|
||||
"depends": [
|
||||
'web',
|
||||
],
|
||||
"data": [
|
||||
"data/ir_config_parameter.xml",
|
||||
'views/templates.xml',
|
||||
],
|
||||
"auto_install": False,
|
||||
"installable": True,
|
||||
"application": False,
|
||||
"external_dependencies": {
|
||||
'python': [],
|
||||
},
|
||||
}
|
||||
21
web_menu_autohide/data/ir_config_parameter.xml
Normal file
21
web_menu_autohide/data/ir_config_parameter.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<openerp>
|
||||
<data noupdate="1">
|
||||
<record id="param_show_bar_threshold_navbar" model="ir.config_parameter">
|
||||
<field name="key">web_menu_autohide.show_bar_threshold_navbar</field>
|
||||
<field name="value">10</field>
|
||||
</record>
|
||||
<record id="param_show_bar_threshold_leftbar" model="ir.config_parameter">
|
||||
<field name="key">web_menu_autohide.show_bar_threshold_leftbar</field>
|
||||
<field name="value">10</field>
|
||||
</record>
|
||||
<record id="param_hide_delay_navbar" model="ir.config_parameter">
|
||||
<field name="key">web_menu_autohide.hide_delay_navbar</field>
|
||||
<field name="value">10000</field>
|
||||
</record>
|
||||
<record id="param_hide_delay_leftbar" model="ir.config_parameter">
|
||||
<field name="key">web_menu_autohide.hide_delay_leftbar</field>
|
||||
<field name="value">10000</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
BIN
web_menu_autohide/static/description/icon.png
Normal file
BIN
web_menu_autohide/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.3 KiB |
213
web_menu_autohide/static/src/js/web_menu_autohide.js
Normal file
213
web_menu_autohide/static/src/js/web_menu_autohide.js
Normal file
@@ -0,0 +1,213 @@
|
||||
//-*- coding: utf-8 -*-
|
||||
//############################################################################
|
||||
//
|
||||
// OpenERP, Open Source Management Solution
|
||||
// This module copyright (C) 2015 Therp BV <http://therp.nl>.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
//############################################################################
|
||||
|
||||
openerp.web_menu_autohide = function(instance)
|
||||
{
|
||||
instance.web.WebClient.include({
|
||||
show_bar_threshold_navbar: 10,
|
||||
show_bar_threshold_leftbar: 10,
|
||||
hide_delay_navbar: 10000,
|
||||
hide_delay_leftbar: 10000,
|
||||
leftbar_hide_timeout_id: null,
|
||||
main_menu_hide_timeout_id: null,
|
||||
navbar_query: '#oe_main_menu_navbar',
|
||||
leftbar_query: '.oe_leftbar',
|
||||
start: function()
|
||||
{
|
||||
var self = this,
|
||||
addon_name = 'web_menu_autohide',
|
||||
parameters = _.map(
|
||||
['show_bar_threshold_navbar', 'hide_delay_navbar',
|
||||
'show_bar_threshold_leftbar', 'hide_delay_leftbar',
|
||||
],
|
||||
function(a) { return addon_name + '.' + a });
|
||||
return (new openerp.web.Model('ir.config_parameter'))
|
||||
.query(['key', 'value'])
|
||||
.filter([['key', 'in', parameters]])
|
||||
.all()
|
||||
.then(function(params)
|
||||
{
|
||||
_.each(params, function(param)
|
||||
{
|
||||
self[param.key.replace(addon_name + '.', '')] =
|
||||
parseInt(param.value);
|
||||
});
|
||||
})
|
||||
.then(this.proxy(this._super))
|
||||
.then(function()
|
||||
{
|
||||
if(self.hide_delay_navbar)
|
||||
{
|
||||
jQuery('.openerp.openerp_webclient_container')
|
||||
.css('height', '100%');
|
||||
jQuery(self.navbar_query)
|
||||
.css({
|
||||
position: 'absolute',
|
||||
left: '0px',
|
||||
right: '0px',
|
||||
top: '0px',
|
||||
'z-index': 1110
|
||||
});
|
||||
}
|
||||
if(self.hide_delay_leftbar)
|
||||
{
|
||||
jQuery(self.leftbar_query)
|
||||
.css({
|
||||
display: 'block',
|
||||
position: 'absolute',
|
||||
left: '0px',
|
||||
top: '0px',
|
||||
bottom: '0px',
|
||||
'z-index': 1110,
|
||||
width: 'auto',
|
||||
});
|
||||
jQuery('.openerp .oe_leftbar > div')
|
||||
.css('width', 'auto');
|
||||
}
|
||||
if(self.hide_delay_navbar || self.hide_delay_leftbar)
|
||||
{
|
||||
self.$el
|
||||
.bind('mousemove', _.bind(self.on_mousemove, self))
|
||||
.bind('click', _.bind(self.on_click, self));
|
||||
}
|
||||
})
|
||||
},
|
||||
show_application: function()
|
||||
{
|
||||
this._super.apply(this, arguments);
|
||||
openerp.client.toggle_main_menu(false, this.hide_delay_navbar);
|
||||
},
|
||||
toggle_bars: function(hide)
|
||||
{
|
||||
this.toggle_main_menu(hide);
|
||||
this.toggle_left_bar(hide);
|
||||
},
|
||||
toggle_menu_element: function(selector, timeout_id, show, delay)
|
||||
{
|
||||
if(this[timeout_id])
|
||||
{
|
||||
clearTimeout(this[timeout_id]);
|
||||
this[timeout_id] = null;
|
||||
}
|
||||
if(delay)
|
||||
{
|
||||
this[timeout_id] = setTimeout(
|
||||
_.bind(
|
||||
this.toggle_menu_element, this,
|
||||
selector, timeout_id, show),
|
||||
delay);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.$(selector).toggle(show);
|
||||
}
|
||||
},
|
||||
toggle_main_menu: function(show, delay)
|
||||
{
|
||||
if(!this.hide_delay_navbar)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.toggle_menu_element(
|
||||
this.navbar_query, 'main_menu_hide_timeout_id', show,
|
||||
delay);
|
||||
},
|
||||
toggle_left_bar: function(show, delay)
|
||||
{
|
||||
if(!this.hide_delay_leftbar)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.toggle_menu_element(
|
||||
this.leftbar_query, 'leftbar_hide_timeout_id', show, delay);
|
||||
},
|
||||
on_click: function(e)
|
||||
{
|
||||
var on_main_menu = jQuery(e.target)
|
||||
.parents(this.navbar_query).length > 0,
|
||||
on_left_bar = jQuery(e.target)
|
||||
.parents(this.leftbar_query).length > 0;
|
||||
if(!on_left_bar && !on_main_menu)
|
||||
{
|
||||
this.toggle_left_bar(false);
|
||||
}
|
||||
},
|
||||
on_mousemove: function(e)
|
||||
{
|
||||
var on_main_menu = jQuery(e.target)
|
||||
.parents(this.navbar_query).length > 0,
|
||||
on_left_bar = jQuery(e.target)
|
||||
.parents(this.leftbar_query).length > 0;
|
||||
if(on_left_bar && openerp.client.leftbar_hide_timeout_id)
|
||||
{
|
||||
clearTimeout(openerp.client.leftbar_hide_timeout_id);
|
||||
openerp.client.leftbar_hide_timeout_id = null;
|
||||
}
|
||||
if(on_main_menu && openerp.client.main_menu_hide_timeout_id)
|
||||
{
|
||||
clearTimeout(openerp.client.main_menu_hide_timeout_id);
|
||||
openerp.client.main_menu_hide_timeout_id = null;
|
||||
}
|
||||
if(!on_left_bar && !openerp.client.leftbar_hide_timeout_id)
|
||||
{
|
||||
this.toggle_left_bar(false, openerp.client.hide_delay_leftbar);
|
||||
}
|
||||
if(!on_main_menu && !openerp.client.main_menu_hide_timeout_id)
|
||||
{
|
||||
this.toggle_main_menu(false);
|
||||
}
|
||||
if(e.pageX < this.show_bar_threshold_leftbar)
|
||||
{
|
||||
this.toggle_left_bar(true);
|
||||
}
|
||||
if(e.pageY < this.show_bar_threshold_navbar)
|
||||
{
|
||||
this.toggle_main_menu(true);
|
||||
}
|
||||
},
|
||||
});
|
||||
instance.web.Menu.include({
|
||||
close_leftbar: false,
|
||||
start: function()
|
||||
{
|
||||
this.on('menu_click', this, this.on_menu_click_with_action);
|
||||
openerp.client.toggle_left_bar(false, openerp.client.hide_delay_leftbar);
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
on_menu_click_with_action: function(menu, $element)
|
||||
{
|
||||
//close if it's not a menu containing other menus
|
||||
this.close_leftbar = (
|
||||
$element.parents(openerp.client.navbar_query).length == 0 &&
|
||||
$element.parent().children('ul').length == 0
|
||||
);
|
||||
},
|
||||
open_menu: function()
|
||||
{
|
||||
this._super.apply(this, arguments);
|
||||
if(this.close_leftbar)
|
||||
{
|
||||
openerp.client.toggle_left_bar(false);
|
||||
}
|
||||
this.close_leftbar = false;
|
||||
},
|
||||
});
|
||||
}
|
||||
10
web_menu_autohide/views/templates.xml
Normal file
10
web_menu_autohide/views/templates.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<template id="assets_backend" name="web_hide_menu assets" inherit_id="web.assets_backend">
|
||||
<xpath expr="." position="inside">
|
||||
<script type="text/javascript" src="/web_menu_autohide/static/src/js/web_menu_autohide.js"></script>
|
||||
</xpath>
|
||||
</template>
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user